gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-anastasis] branch master updated (92edf5d -> 2454d97)


From: gnunet
Subject: [taler-anastasis] branch master updated (92edf5d -> 2454d97)
Date: Sat, 16 May 2020 19:25:22 +0200

This is an automated email from the git hooks/post-receive script.

dennis-neufeld pushed a change to branch master
in repository anastasis.

    from 92edf5d  initial work on command line tool
     new 435cff2  cmd waiting for input
     new a5be1d4  force user to provide user details
     new 2454d97  prepared command line input reading

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/cli/anastasis-cli-splitter.c  | 201 +++++++++++++++++++++++++++++++++++++-
 src/cli/user-details-example.json |   6 ++
 2 files changed, 205 insertions(+), 2 deletions(-)
 create mode 100644 src/cli/user-details-example.json

diff --git a/src/cli/anastasis-cli-splitter.c b/src/cli/anastasis-cli-splitter.c
index f882e50..ff6dc34 100644
--- a/src/cli/anastasis-cli-splitter.c
+++ b/src/cli/anastasis-cli-splitter.c
@@ -21,9 +21,12 @@
  * @author Dominik Meister
  */
 #include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
 #include "anastasis_service.h"
 #include "anastasis.h"
 
+/* Constant, max size of keyboard input buffer */
+#define MAX_SIZE_INPUT_BUFFER 256
 
 /**
  * Global option '-me' to import json containing details of user.
@@ -46,6 +49,188 @@ static struct GNUNET_CURL_Context *ctx;
 static struct GNUNET_CURL_RescheduleContext *rc;
 
 
+static void
+start_read_keyboard (void);
+
+
+/**
+ * @brief Read the character from stdin and activate the selected task
+ *
+ * @param cls closure
+ */
+static void
+read_keyboard_command (void *cls)
+{
+  (void) cls;
+  char *buffer = NULL;
+  size_t buffer_size = MAX_SIZE_INPUT_BUFFER;
+  size_t characters;
+
+  keyboard_task = NULL;
+  buffer = (char *) GNUNET_malloc (buffer_size * sizeof (char));
+  characters = getline (&buffer,
+                        &buffer_size,
+                        stdin);
+
+  if (characters == 2 * sizeof (char))
+  {
+    if (EOF == (char) buffer[0])
+    {
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+    switch ((char) buffer[0])
+    {
+    case 'x':
+      GNUNET_SCHEDULER_shutdown ();
+      GNUNET_free (buffer);
+      buffer = NULL;
+      return;
+    case 'o':
+      printf (
+        "\nOPTIONS:\n"
+        "'x' to quit\n"
+        "'o' to show options\n"
+        "'server add' to add a provider/server\n"
+        "\n"
+        );
+      GNUNET_free (buffer);
+      buffer = NULL;
+      break;
+    default:
+      fprintf (stderr,
+               "Unknown command '%c'\n",
+               buffer[0]);
+      GNUNET_free (buffer);
+      buffer = NULL;
+      break;
+    }
+    start_read_keyboard ();
+    return;
+  }
+
+  if (0 == strncmp ("server",
+                    buffer,
+                    strlen ("server")))
+  {
+    // FIXME "server" logic here
+    start_read_keyboard ();
+    GNUNET_free (buffer);
+    buffer = NULL;
+    return;
+  }
+  if (0 == strncmp ("server add",
+                    buffer,
+                    strlen ("server add")))
+  {
+    // FIXME "server add" logic here
+    start_read_keyboard ();
+    GNUNET_free (buffer);
+    buffer = NULL;
+    return;
+  }
+
+  if (0 == strncmp ("truth",
+                    buffer,
+                    strlen ("truth")))
+  {
+    // FIXME "truth" logic here
+    start_read_keyboard ();
+    GNUNET_free (buffer);
+    buffer = NULL;
+    return;
+  }
+  if (0 == strncmp ("truth add",
+                    buffer,
+                    strlen ("truth add")))
+  {
+    // FIXME "truth add" logic here
+    start_read_keyboard ();
+    GNUNET_free (buffer);
+    buffer = NULL;
+    return;
+  }
+  if (0 == strncmp ("truth --secrets",
+                    buffer,
+                    strlen ("truth --secrets")))
+  {
+    // FIXME "truth --secrets" logic here
+    start_read_keyboard ();
+    GNUNET_free (buffer);
+    buffer = NULL;
+    return;
+  }
+
+  if (0 == strncmp ("policy",
+                    buffer,
+                    strlen ("policy")))
+  {
+    // FIXME "policy" logic here
+    start_read_keyboard ();
+    GNUNET_free (buffer);
+    buffer = NULL;
+    return;
+  }
+  if (0 == strncmp ("policy add",
+                    buffer,
+                    strlen ("policy add")))
+  {
+    // FIXME "policy add" logic here
+    start_read_keyboard ();
+    GNUNET_free (buffer);
+    buffer = NULL;
+    return;
+  }
+
+  if (0 == strncmp ("publish",
+                    buffer,
+                    strlen ("publish")))
+  {
+    // FIXME "publish" logic here
+    start_read_keyboard ();
+    GNUNET_free (buffer);
+    buffer = NULL;
+    return;
+  }
+
+  fprintf (stderr,
+           "Unknown command '%s'\n",
+           (char*) buffer);
+  GNUNET_free (buffer);
+  buffer = NULL;
+  start_read_keyboard ();
+}
+
+
+/**
+ * @brief Wait for a keyboard input
+ */
+static void
+start_read_keyboard ()
+{
+  static struct GNUNET_DISK_FileHandle fh = { STDIN_FILENO };
+
+  GNUNET_assert (NULL == keyboard_task);
+
+  if (! import_id)
+  {
+    printf ("Please provide user details with option '--me file.json'!\n");
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+
+
+
+  printf ("'x' to quit\n");
+  printf ("'o' to show options\n");
+  printf ("Waiting for keyboard input\n");
+  keyboard_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+                                                  &fh,
+                                                  &read_keyboard_command,
+                                                  NULL);
+}
+
+
 /**
  * @brief Shutdown the application.
  *
@@ -59,9 +244,14 @@ shutdown_task (void *cls)
               "Shutdown initiated\n");
 
   // FIXME shutdown routine here
+  if (NULL != ctx)
+  {
+    GNUNET_CURL_fini (ctx);
+    ctx = NULL;
+  }
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Shutdown complete (except for MDB)\n");
+              "Shutdown complete\n");
 }
 
 
@@ -81,6 +271,7 @@ run (void *cls,
 {
   (void) cls;
   (void) args;
+  (void) cfgfile;
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Starting anastasis-splitter\n");
@@ -97,14 +288,20 @@ run (void *cls,
   ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
                           &rc);
   rc = GNUNET_CURL_gnunet_rc_create (ctx);
+
+  start_read_keyboard ();
 }
 
 int
 main (int argc,
-      char*const*argv)
+      char *const *argv)
 {
   int ret;
 
+  GNUNET_log_setup ("anastasis-splitter",
+                    "DEBUG",
+                    NULL);
+
   /* the available command line options */
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_option_flag ('m',
diff --git a/src/cli/user-details-example.json 
b/src/cli/user-details-example.json
new file mode 100644
index 0000000..3eb1f7a
--- /dev/null
+++ b/src/cli/user-details-example.json
@@ -0,0 +1,6 @@
+{ 
+    "first-name":"John",
+    "last-name":"Wayne",
+    "birthdate":"01-01-1901",
+    "social-security-number":"123456789" 
+}
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]