#include <assert.h>
#include <rpc/xdr.h>
-#include "wrappi.h"
-#include "internal.h"
#include "proto-xdr.h"
bool_t
return TRUE;
}
-
-void
-wrap_int_make_request_xdr (wrap_h *w, int proc_nr, const void *args, void *ret)
-{
- XDR xdr;
- xdrproc_t xdrp_args;
- xdrproc_t xdrp_ret;
- struct wrap_int_message_header hdr;
- struct wrap_int_message_error err;
-
- memset (&hdr, 0, sizeof hdr);
-
- hdr.proc = (char *) wrap_int_proc_table[proc_nr].name;
- assert (hdr.proc);
- xdrp_args = wrap_int_proc_table[proc_nr].xdr_args;
- assert (xdrp_args);
- xdrp_ret = wrap_int_proc_table[proc_nr].xdr_ret;
- assert (xdrp_ret);
-
- /* Construct the header. */
- w->serial++;
-
- hdr.magic = WRAP_INT_PROTO_MAGIC;
- hdr.protocol = WRAP_INT_PROTOCOL;
- hdr.serial = w->serial;
- hdr.type = WRAP_INT_PROTO_TYPE_REQUEST;
-
- /* Send the header. */
- xdrstdio_create (&xdr, w->wfp, XDR_ENCODE);
- if (!wrap_int_xdr_message_header (&xdr, &hdr)) {
- set_error ("error sending request header");
- xdr_destroy (&xdr);
- return;
- }
-
- /* Send the request arguments. */
- if (!xdrp_args (&xdr, (void *) args)) {
- set_error ("error sending request arguments");
- xdr_destroy (&xdr);
- return;
- }
- xdr_destroy (&xdr);
-
- /* Receive the reply header. */
- xdrstdio_create (&xdr, w->rfp, XDR_DECODE);
- memset (&hdr, 0, sizeof hdr);
- if (!wrap_int_xdr_message_header (&xdr, &hdr)) {
- set_error ("error receiving reply header");
- xdr_destroy (&xdr);
- return;
- }
-
- /* Check the reply header. */
- if (hdr.magic != WRAP_INT_PROTO_MAGIC) {
- set_error ("error in reply: unexpected magic (%x)", hdr.magic);
- xdr_destroy (&xdr);
- return;
- }
- if (hdr.protocol != WRAP_INT_PROTOCOL) {
- set_error ("error in reply: unexpected protocol number (%d)", hdr.protocol);
- xdr_destroy (&xdr);
- return;
- }
- if (hdr.serial != w->serial) {
- set_error ("error in reply: unexpected serial (%d)", hdr.serial);
- xdr_destroy (&xdr);
- return;
- }
-
- switch (hdr.type) {
- case WRAP_INT_PROTO_TYPE_REPLY:
- /* Receive the return value. */
- if (!xdrp_ret (&xdr, (void *) ret)) {
- set_error ("error receiving return value");
- xdr_destroy (&xdr);
- return;
- }
- break;
-
- case WRAP_INT_PROTO_TYPE_ERROR:
- /* Receive the error message etc. */
- memset (&err, 0, sizeof err);
- if (!wrap_int_xdr_message_error (&xdr, &err)) {
- set_error ("error receiving error message");
- xdr_destroy (&xdr);
- return;
- }
-
- /* XXX errno should be converted to an integer here */
- /* XXX func should be set, but it's not static! */
- set_error ("%s", err.error_message);
- xdr_free ((xdrproc_t) wrap_int_xdr_message_error, (void *) &err);
-
- break;
-
- default:
- set_error ("error in reply: unexpected type (%x)", hdr.type);
- xdr_destroy (&xdr);
- return;
- }
-
- xdr_destroy (&xdr);
-}