2 * Copyright (C) 2011-2012 Red Hat Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 #include "proto-xdr.h"
31 wrap_int_xdr_message_header (XDR *xdrs, struct wrap_int_message_header *hdr)
33 if (!xdr_uint32_t (xdrs, &hdr->magic)) return FALSE;
34 if (!xdr_uint32_t (xdrs, &hdr->protocol)) return FALSE;
35 if (!xdr_uint32_t (xdrs, &hdr->serial)) return FALSE;
36 if (!xdr_string (xdrs, &hdr->proc, ~0)) return FALSE;
37 if (!xdr_uint32_t (xdrs, &hdr->type)) return FALSE;
43 wrap_int_xdr_message_error (XDR *xdrs, struct wrap_int_message_error *err)
45 if (!xdr_string (xdrs, &err->error_message, ~0)) return FALSE;
46 if (!xdr_string (xdrs, &err->error_errno, 32)) return FALSE;
47 if (!xdr_string (xdrs, &err->error_func, 256)) return FALSE;
53 wrap_int_make_request_xdr (wrap_h *w, int proc_nr, const void *args, void *ret)
58 struct wrap_int_message_header hdr;
59 struct wrap_int_message_error err;
61 memset (&hdr, 0, sizeof hdr);
63 hdr.proc = (char *) wrap_int_proc_table[proc_nr].name;
65 xdrp_args = wrap_int_proc_table[proc_nr].xdr_args;
67 xdrp_ret = wrap_int_proc_table[proc_nr].xdr_ret;
70 /* Construct the header. */
73 hdr.magic = WRAP_INT_PROTO_MAGIC;
74 hdr.protocol = WRAP_INT_PROTOCOL;
75 hdr.serial = w->serial;
76 hdr.type = WRAP_INT_PROTO_TYPE_REQUEST;
78 /* Send the header. */
79 xdrstdio_create (&xdr, w->wfp, XDR_ENCODE);
80 if (!wrap_int_xdr_message_header (&xdr, &hdr)) {
81 set_error ("error sending request header");
86 /* Send the request arguments. */
87 if (!xdrp_args (&xdr, (void *) args)) {
88 set_error ("error sending request arguments");
94 /* Receive the reply header. */
95 xdrstdio_create (&xdr, w->rfp, XDR_DECODE);
96 memset (&hdr, 0, sizeof hdr);
97 if (!wrap_int_xdr_message_header (&xdr, &hdr)) {
98 set_error ("error receiving reply header");
103 /* Check the reply header. */
104 if (hdr.magic != WRAP_INT_PROTO_MAGIC) {
105 set_error ("error in reply: unexpected magic (%x)", hdr.magic);
109 if (hdr.protocol != WRAP_INT_PROTOCOL) {
110 set_error ("error in reply: unexpected protocol number (%d)", hdr.protocol);
114 if (hdr.serial != w->serial) {
115 set_error ("error in reply: unexpected serial (%d)", hdr.serial);
121 case WRAP_INT_PROTO_TYPE_REPLY:
122 /* Receive the return value. */
123 if (!xdrp_ret (&xdr, (void *) ret)) {
124 set_error ("error receiving return value");
130 case WRAP_INT_PROTO_TYPE_ERROR:
131 /* Receive the error message etc. */
132 memset (&err, 0, sizeof err);
133 if (!wrap_int_xdr_message_error (&xdr, &err)) {
134 set_error ("error receiving error message");
139 /* XXX errno should be converted to an integer here */
140 /* XXX func should be set, but it's not static! */
141 set_error ("%s", err.error_message);
142 xdr_free ((xdrproc_t) wrap_int_xdr_message_error, (void *) &err);
147 set_error ("error in reply: unexpected type (%x)", hdr.type);