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
27 #include "../lib/proto-xdr.h"
29 static void main_loop (void);
34 main (int argc, char *argv[])
36 /* Command line XXX */
40 fprintf (stderr, "could not allocate wrappi handle\n");
59 struct wrap_int_message_header hdr;
60 struct wrap_int_message_error err;
61 xdrproc_t args_xdrproc;
62 xdrproc_t ret_xdrproc;
66 /* Receive the request header. */
67 xdrstdio_create (&xdr, stdin, XDR_DECODE);
68 memset (&hdr, 0, sizeof hdr);
69 if (!wrap_int_xdr_message_header (&xdr, &hdr)) {
70 /* No error message here, because this is the expected
71 * exit place when the connection is closed.
77 if (hdr.magic != WRAP_INT_PROTO_MAGIC) {
78 fprintf (stderr, "error in request: unexpected magic (%x)\n",
83 if (hdr.protocol != WRAP_INT_PROTOCOL) {
84 fprintf (stderr, "error in request: unexpected protocol number (%d)\n",
89 if (hdr.type != WRAP_INT_PROTO_TYPE_REQUEST) {
90 fprintf (stderr, "error in request: unexpected type (%d)\n",
96 args_xdrproc = wrap_call_get_args_xdrproc (w, hdr.proc);
101 ret_xdrproc = wrap_call_get_ret_xdrproc (w, hdr.proc);
102 if (wrap_error (w)) {
107 argsv = calloc (1, wrap_call_get_args_struct_size (w, hdr.proc));
112 retv = calloc (1, wrap_call_get_ret_struct_size (w, hdr.proc));
118 /* Receive the arguments. */
119 if (!args_xdrproc (&xdr, argsv)) {
120 fprintf (stderr, "error receiving request arguments\n");
129 /* Call the underlying API. */
130 wrap_call (w, hdr.proc, argsv, retv);
133 xdrstdio_create (&xdr, stdout, XDR_ENCODE);
135 if (! wrap_error (w)) {
136 /* Send back a normal reply. */
137 hdr.type = WRAP_INT_PROTO_TYPE_REPLY;
139 if (!wrap_int_xdr_message_header (&xdr, &hdr)) {
140 fprintf (stderr, "error sending reply header\n");
146 if (!ret_xdrproc (&xdr, retv)) {
147 fprintf (stderr, "error sending reply return value\n");
154 /* Send back an error reply. */
155 err.error_message = (char *) wrap_get_error (w);
156 err.error_func = (char *) wrap_get_error_func (w);
157 err.error_errno = (char *) ""; /* XXX set this properly */
159 hdr.type = WRAP_INT_PROTO_TYPE_ERROR;
161 if (!wrap_int_xdr_message_header (&xdr, &hdr)) {
162 fprintf (stderr, "error sending reply error header\n");
168 if (!wrap_int_xdr_message_error (&xdr, &err)) {
169 fprintf (stderr, "error sending reply error struct\n");
178 xdr_free ((xdrproc_t) wrap_int_xdr_message_header, (void *) &hdr);