gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 01/03: worked on splitter


From: gnunet
Subject: [taler-anastasis] 01/03: worked on splitter
Date: Tue, 19 May 2020 14:20:01 +0200

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

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

commit 22b01fd772047c52bb2ca57cb94b6da54fb89d78
Author: Dennis Neufeld <address@hidden>
AuthorDate: Mon May 18 13:59:46 2020 +0000

    worked on splitter
---
 src/cli/Makefile.am              |   2 +-
 src/cli/anastasis-cli-splitter.c | 185 ++++++++++++++++++++++++++++++++++++---
 2 files changed, 172 insertions(+), 15 deletions(-)

diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am
index 4860ff7..f0b2d15 100644
--- a/src/cli/Makefile.am
+++ b/src/cli/Makefile.am
@@ -1,5 +1,5 @@
 # This Makefile.am is in the public domain
-AM_CPPFLAGS = -I$(top_srcdir)/src/include
+AM_CPPFLAGS = -I$(top_srcdir)/src/include 
 
 bin_PROGRAMS = \
   anastasis-splitter \
diff --git a/src/cli/anastasis-cli-splitter.c b/src/cli/anastasis-cli-splitter.c
index d7033d2..69d82d8 100644
--- a/src/cli/anastasis-cli-splitter.c
+++ b/src/cli/anastasis-cli-splitter.c
@@ -171,6 +171,39 @@ struct SaltState
   struct ANASTASIS_CRYPTO_SaltP salt;
 };
 
+/**
+ * State for a "get config" CMD.
+ */
+struct ConfigState
+{
+  /**
+   * URL of the anastasis backend.
+   */
+  const char *anastasis_url;
+
+  /**
+   * Expected status code.
+   */
+  unsigned int http_status;
+
+  /**
+   * The /config GET operation handle.
+   */
+  struct ANASTASIS_ConfigOperation *co;
+
+  /**
+   * Cost.
+   */
+  struct TALER_Amount cost;
+
+  /**
+   * Supported methods.
+   */
+  const char *methods;
+
+  // FIXME add configs
+};
+
 /**
  * Global option '--me' to import json containing details of user.
  */
@@ -243,6 +276,53 @@ salt_cb (void *cls,
 }
 
 
+/**
+ * Function called with the results of a #ANASTASIS_get_config().
+ *
+ * @param cls closure
+ * @param http_status HTTP status of the request
+ * @param cost Cost of this service
+ * @param methods supported methods by this provider
+ */
+static void
+config_cb (void *cls,
+           unsigned int http_status,
+           const char *methods,
+           const struct TALER_Amount *cost)
+{
+  struct ConfigState *cs = cls;
+
+  cs->co = NULL;
+  if (http_status != cs->http_status)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Unexpected response code %u in %s:%u\n",
+                http_status,
+                __FILE__,
+                __LINE__);
+    return;
+  }
+  if (NULL == cost)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Cost is NULL in %s:%u\n",
+                __FILE__,
+                __LINE__);
+    return;
+  }
+  if (NULL == methods)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Methods is NULL in %s:%u\n",
+                __FILE__,
+                __LINE__);
+    return;
+  }
+  cs->cost = *cost;
+  cs->methods = methods;
+}
+
+
 static void
 start_read_keyboard (void);
 
@@ -320,15 +400,13 @@ read_keyboard_command (void *cls)
       for (unsigned int i = 0; i < tu_states_length; i++)
       {
         if (NULL != tu_states[i].backend_url)
-          printf ("server#%u: %s, %s, insured up to: %s, cost: %s\n",
+          printf ("server#%u: %s %s, insured up to: %s, cost: %s\n",
                   i,
                   tu_states[i].backend_url,
                   tu_states[i].backend_methods,
-                  "test_insurance", // FIXME
-                  "test_cost" // FIXME
-                  /* FIXME
-                  TALER_amount_to_string (tu_states[i].backend_insurance),
-                  TALER_amount_to_string (tu_states[i].backend_cost)*/);
+                  "test_insurance_amount", // FIXME
+                  TALER_amount_to_string (tu_states[i].backend_cost)
+                  );
       }
     }
     else
@@ -346,14 +424,17 @@ read_keyboard_command (void *cls)
     // FIXME "server add" logic here
     struct TruthUploadState tus;
     struct SaltState *ss;
+    struct ConfigState *cs;
     size_t url_len = characters - strlen ("server add ");
 
     ss = GNUNET_new (struct SaltState);
-    char *url_delim = &buffer[strlen ("server add ")];
+    cs = GNUNET_new (struct ConfigState);
+    char *url = &buffer[strlen ("server add ")];
     tus.backend_url = GNUNET_malloc (url_len);
     strncpy (tus.backend_url,
-             url_delim,
+             url,
              url_len);
+
     ss->anastasis_url = tus.backend_url;
     ss->http_status = MHD_HTTP_OK;
     ss->so = ANASTASIS_salt (ctx,
@@ -365,13 +446,29 @@ read_keyboard_command (void *cls)
       GNUNET_break (0);
       return;
     }
-
     tus.backend_salt = &ss->salt;
 
-    // FIXME /terms request here, DELETE next 3 lines!
-    tus.backend_methods = "Secure-Question";
-    // TALER_amount_get_zero ("KUDOS", tus.backend_insurance);
-    // TALER_amount_get_zero ("KUDOS", tus.backend_cost);
+    cs->anastasis_url = tus.backend_url;
+    cs->http_status = MHD_HTTP_OK;
+    /* FIXME: undefined reference to ANASTASIS_get_config
+    cs->co = ANASTASIS_get_config (ctx,
+                                   tus.backend_url,
+                                   config_cb,
+                                   cs); */
+    // FIXME: DELETE THIS, WHEN ABOVE IS FIXED_
+    cs->methods = "question"; // FIXME
+    TALER_string_to_amount ("EUR:3.99",
+                            &cs->cost);
+    /* FIXME: Uncomment this when aboce is fixed
+    if (NULL == cs->co)
+    {
+      GNUNET_break (0);
+      return;
+    }*/
+
+    tus.backend_methods = cs->methods;
+    tus.backend_cost = &cs->cost;
+    // FIXME add config max insurance amount
 
     GNUNET_array_append (tu_states,
                          tu_states_length,
@@ -425,6 +522,66 @@ read_keyboard_command (void *cls)
     if (NULL != tu_states)
     {
       // FIXME
+      char *truth_details = &buffer[strlen ("truth add ")];
+      char *token = strtok (truth_details, " ");
+      int server_num;
+
+      if (0 == strncmp ("server#",
+                        token,
+                        strlen ("server#")))
+      {
+        server_num = (int) token[strlen ("server#x")];
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                    "At %s:%d server is %s\n", __FILE__, __LINE__,
+                    token);
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                    "At %s:%d server number is %u\n", __FILE__, __LINE__,
+                    server_num);
+        token = strtok (NULL, " ");
+        char *method = GNUNET_malloc (strlen (token));
+        strcpy (method, token);
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                    "At %s:%d method is %s\n", __FILE__, __LINE__,
+                    method);
+
+        if (NULL != strstr (tu_states[server_num].backend_methods,
+                            method))
+        {
+          if (0 == strcmp ("question", method))
+          {
+            token = strtok (NULL, " ");
+            char *question = GNUNET_malloc (strlen (token));
+            strcpy (question, token);
+            GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                        "At %s:%d question is %s\n", __FILE__, __LINE__,
+                        question);
+
+            token = strtok (NULL, " ");
+            char *answer = GNUNET_malloc (strlen (token));
+            strcpy (answer, token);
+            GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                        "At %s:%d answer is %s\n", __FILE__, __LINE__,
+                        answer);
+
+            tu_states[server_num].method = "Secure-Question";
+            tu_states[server_num].secret_question = question;
+            tu_states[server_num].secret_answer = answer;
+          }
+          if (0 == strcmp ("sms", method))
+          {
+            char *phone = strtok (NULL, " ");
+            tu_states[server_num].method = "SMS";
+            tu_states[server_num].phone = phone;
+          }
+        }
+        else
+          printf ("Sorry, server#%u does not support '%s'\n",
+                  server_num,
+                  method);
+      }
+
+
+
     }
     else
       printf ("Please add a server before!\n");
@@ -442,7 +599,7 @@ read_keyboard_command (void *cls)
     // FIXME "truth add question" logic here
     if (NULL != tu_states)
     {
-      // FIXME
+
     }
     else
       printf ("Please add a server before!\n");

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



reply via email to

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