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_make_request_xdr (wrap_h *w, int proc_nr, const void *args, void *ret)
34 xdrproc_t args_xdrproc;
35 xdrproc_t ret_xdrproc;
36 struct wrap_int_message_header hdr;
37 struct wrap_int_message_error err;
39 memset (&hdr, 0, sizeof hdr);
41 hdr.proc = (char *) wrap_int_proc_table[proc_nr].name;
43 args_xdrproc = wrap_int_proc_table[proc_nr].args_xdrproc;
44 ret_xdrproc = wrap_int_proc_table[proc_nr].ret_xdrproc;
46 /* Construct the header. */
49 hdr.magic = WRAP_INT_PROTO_MAGIC;
50 hdr.protocol = WRAP_INT_PROTOCOL;
51 hdr.serial = w->serial;
52 hdr.type = WRAP_INT_PROTO_TYPE_REQUEST;
54 /* Send the header. */
55 xdrstdio_create (&xdr, w->wfp, XDR_ENCODE);
56 if (!wrap_int_xdr_message_header (&xdr, &hdr)) {
57 set_error ("error sending request header");
62 /* Send the request arguments. */
63 if (!args_xdrproc (&xdr, (void *) args)) {
64 set_error ("error sending request arguments");
70 /* Receive the reply header. */
71 xdrstdio_create (&xdr, w->rfp, XDR_DECODE);
72 memset (&hdr, 0, sizeof hdr);
73 if (!wrap_int_xdr_message_header (&xdr, &hdr)) {
74 set_error ("error receiving reply header");
79 /* Check the reply header. */
80 if (hdr.magic != WRAP_INT_PROTO_MAGIC) {
81 set_error ("error in reply: unexpected magic (%x)", hdr.magic);
83 xdr_free ((xdrproc_t) wrap_int_xdr_message_header, (void *) &hdr);
86 if (hdr.protocol != WRAP_INT_PROTOCOL) {
87 set_error ("error in reply: unexpected protocol number (%d)", hdr.protocol);
89 xdr_free ((xdrproc_t) wrap_int_xdr_message_header, (void *) &hdr);
92 if (hdr.serial != w->serial) {
93 set_error ("error in reply: unexpected serial (%d)", hdr.serial);
95 xdr_free ((xdrproc_t) wrap_int_xdr_message_header, (void *) &hdr);
100 case WRAP_INT_PROTO_TYPE_REPLY:
101 /* Receive the return value. */
102 if (!ret_xdrproc (&xdr, (void *) ret)) {
103 set_error ("error receiving return value");
105 xdr_free ((xdrproc_t) wrap_int_xdr_message_header, (void *) &hdr);
110 case WRAP_INT_PROTO_TYPE_ERROR:
111 /* Receive the error message etc. */
112 memset (&err, 0, sizeof err);
113 if (!wrap_int_xdr_message_error (&xdr, &err)) {
114 set_error ("error receiving error message");
116 xdr_free ((xdrproc_t) wrap_int_xdr_message_header, (void *) &hdr);
120 /* XXX errno should be converted to an integer here */
121 /* XXX func should be set, but it's not static! */
122 set_error ("%s", err.error_message);
123 xdr_free ((xdrproc_t) wrap_int_xdr_message_error, (void *) &err);
124 xdr_free ((xdrproc_t) wrap_int_xdr_message_header, (void *) &hdr);
129 set_error ("error in reply: unexpected type (%x)", hdr.type);
131 xdr_free ((xdrproc_t) wrap_int_xdr_message_header, (void *) &hdr);
136 xdr_free ((xdrproc_t) wrap_int_xdr_message_header, (void *) &hdr);