/* wrappi * Copyright (C) 2011-2012 Red Hat Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include "wrappi.h" /* XXX XDR code should be in its own mini-library. * OR we should export a way to serialize function calls. */ #include "internal.h" static void main_loop (void); static wrap_h *w; int main (int argc, char *argv[]) { /* Command line XXX */ w = wrap_create (); if (!w) { fprintf (stderr, "could not allocate wrappi handle\n"); exit (EXIT_FAILURE); } wrap_connect (w); if (wrap_error (w)) exit (EXIT_FAILURE); main_loop (); wrap_close (w); exit (EXIT_SUCCESS); } static void main_loop (void) { XDR xdr; xdrproc_t xdrp_args; xdrproc_t xdrp_ret; struct wrap_int_message_header hdr; struct wrap_int_message_error err; size_t i; for (;;) { /* Receive the request header. */ xdrstdio_create (&xdr, stdin, XDR_DECODE); memset (&hdr, 0, sizeof hdr); if (!wrap_int_xdr_message_header (&xdr, &hdr)) { fprintf (stderr, "error receiving request header\n"); return; } if (hdr.magic != WRAP_INT_PROTO_MAGIC) { fprintf (stderr, "error in request: unexpected magic (%x)\n", hdr.magic); return; } if (hdr.protocol != WRAP_INT_PROTOCOL) { fprintf (stderr, "error in request: unexpected protocol number (%d)\n", hdr.protocol); return; } if (hdr.type != WRAP_INT_PROTO_TYPE_REQUEST) { fprintf (stderr, "error in request: unexpected type (%d)\n", hdr.type); return; } /* Convert the proc name to the internal entry point. */ /* XXX We're going to use gperf here, as we do in libguestfs. */ for (i = 0; i < wrap_int_nr_procs; ++i) { if (STREQ (wrap_int_proc_table[i].name, hdr.proc)) goto found; } fprintf (stderr, "unknown proc name in request: %s\n", hdr.proc); exit (EXIT_FAILURE); found: xdrp_args = wrap_int_proc_table[i].xdr_args; assert (xdrp_args); xdrp_ret = wrap_int_proc_table[i].xdr_ret; assert (xdrp_ret); /* Receive the arguments. */ } }