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 fprintf (stderr, "error receiving request header\n");
75 if (hdr.magic != WRAP_INT_PROTO_MAGIC) {
76 fprintf (stderr, "error in request: unexpected magic (%x)\n",
81 if (hdr.protocol != WRAP_INT_PROTOCOL) {
82 fprintf (stderr, "error in request: unexpected protocol number (%d)\n",
87 if (hdr.type != WRAP_INT_PROTO_TYPE_REQUEST) {
88 fprintf (stderr, "error in request: unexpected type (%d)\n",
94 args_xdrproc = wrap_call_get_args_xdrproc (w, hdr.proc);
99 ret_xdrproc = wrap_call_get_ret_xdrproc (w, hdr.proc);
100 if (wrap_error (w)) {
105 argsv = calloc (1, wrap_call_get_args_struct_size (w, hdr.proc));
110 retv = calloc (1, wrap_call_get_ret_struct_size (w, hdr.proc));
116 /* Receive the arguments. */
117 if (!args_xdrproc (&xdr, argsv)) {
118 fprintf (stderr, "error receiving request arguments\n");
127 /* Call the underlying API. */
128 wrap_call (w, hdr.proc, argsv, retv);
131 xdrstdio_create (&xdr, stdout, XDR_ENCODE);
133 if (! wrap_error (w)) {
134 /* Send back a normal reply. */
135 hdr.type = WRAP_INT_PROTO_TYPE_REPLY;
137 if (!wrap_int_xdr_message_header (&xdr, &hdr)) {
138 fprintf (stderr, "error sending reply header\n");
144 if (!ret_xdrproc (&xdr, retv)) {
145 fprintf (stderr, "error sending reply return value\n");
152 /* Send back an error reply. */
153 err.error_message = (char *) wrap_get_error (w);
154 err.error_func = (char *) wrap_get_error_func (w);
155 err.error_errno = (char *) ""; /* XXX set this properly */
157 hdr.type = WRAP_INT_PROTO_TYPE_ERROR;
159 if (!wrap_int_xdr_message_header (&xdr, &hdr)) {
160 fprintf (stderr, "error sending reply error header\n");
166 if (!wrap_int_xdr_message_error (&xdr, &err)) {
167 fprintf (stderr, "error sending reply error struct\n");
176 xdr_free ((xdrproc_t) wrap_int_xdr_message_header, (void *) &hdr);