More updates to RPC.
authorRichard W.M. Jones <rjones@redhat.com>
Mon, 2 Jan 2012 21:00:18 +0000 (21:00 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Mon, 2 Jan 2012 21:00:18 +0000 (21:00 +0000)
daemon/Makefile.am
daemon/wrappid.c
lib/proto-ssh.c

index c44c53b..cdbc244 100644 (file)
@@ -19,6 +19,9 @@ sbin_PROGRAMS = wrappid
 
 wrappid_SOURCES = \
        ../lib/wrappi.h \
+       ../lib/internal.h \
+       ../lib/internal-procs.h \
+       ../lib/proto-xdr.h \
        wrappid.c
 wrappid_CFLAGS = -I../lib $(WARN_CFLAGS) $(WERROR_CFLAGS)
 wrappid_LDADD = ../lib/libwrappi.la
index ea0f00f..4fb1f11 100644 (file)
 
 #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. */
+    
 
 
 
+  }
 }
index 117f772..1b505f5 100644 (file)
@@ -69,7 +69,7 @@ wrap_int_connect_ssh (wrap_h *w)
             "ssh",
             "-T", "-o", "BatchMode=yes", "-e", "none",
             w->hostname,
-            "sh", "-c", "cat",
+            "sh", "-c", /*XXX*/ "/home/rjones/d/wrappi/daemon/wrappid",
             NULL);
     perror ("ssh");
     _exit (EXIT_FAILURE);