#include <stdio.h>
#include <stdlib.h>
+#include <rpc/xdr.h>
#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)
{
- /* XXX */
+ 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. */
+
+ }
}