gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated (e0c39ed -> 40e7b10)


From: gnunet
Subject: [taler-anastasis] branch master updated (e0c39ed -> 40e7b10)
Date: Mon, 28 Sep 2020 15:21:23 +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 e0c39ed  db changes payment
     new 9a3996b  modified config api
     new 212384e  mod/fix config api
     new 1c29911  work on initial policy
     new 40e7b10  Merge branch 'master' of ssh://git.taler.net/anastasis into 
master

The 4 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/backend/Makefile.am               |  2 -
 src/backend/anastasis-httpd.c         | 22 ++++++++-
 src/backend/anastasis-httpd.h         | 22 ++++++++-
 src/backend/anastasis-httpd_config.c  | 84 +++++++++++++++++++++++++++++++++--
 src/cli/anastasis-cli-assembler.c     | 31 +++++++++----
 src/cli/anastasis-cli-splitter.c      | 67 ++++++++++++++++++++++------
 src/include/anastasis_redux.h         |  1 +
 src/include/anastasis_service.h       | 14 ++----
 src/lib/anastasis_api_backup_redux.c  | 62 ++++++++++++++++++++++++--
 src/lib/anastasis_api_config.c        | 18 +++++---
 src/lib/anastasis_api_curl_defaults.c |  2 +
 src/lib/anastasis_api_redux.c         |  8 ++--
 12 files changed, 277 insertions(+), 56 deletions(-)

diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
index 975f2dd..c16b279 100644
--- a/src/backend/Makefile.am
+++ b/src/backend/Makefile.am
@@ -1,8 +1,6 @@
 # This Makefile.am is in the public domain
 AM_CPPFLAGS = -I$(top_srcdir)/src/include
 
-
-
 pkgcfgdir = $(prefix)/share/anastasis/config.d/
 
 pkgcfg_DATA = \
diff --git a/src/backend/anastasis-httpd.c b/src/backend/anastasis-httpd.c
index e014923..f789a00 100644
--- a/src/backend/anastasis-httpd.c
+++ b/src/backend/anastasis-httpd.c
@@ -59,11 +59,29 @@ const struct GNUNET_CONFIGURATION_Handle *AH_cfg;
 
 /**
  * Cost of authentication by question
- * FIXME: Implement a more elegant way to
- * list costs of authentication methods
  */
 struct TALER_Amount AH_question_cost;
 
+/**
+ * Cost of authentication by email
+ */
+struct TALER_Amount AH_email_cost;
+
+/**
+ * Cost of authentication by post
+ */
+struct TALER_Amount AH_post_cost;
+
+/**
+ * Cost of authentication by video
+ */
+struct TALER_Amount AH_video_cost;
+
+/**
+ * Cost of authentication by sms
+ */
+struct TALER_Amount AH_sms_cost;
+
 /**
  * Our Taler backend to process payments.
  */
diff --git a/src/backend/anastasis-httpd.h b/src/backend/anastasis-httpd.h
index c54003f..188a824 100644
--- a/src/backend/anastasis-httpd.h
+++ b/src/backend/anastasis-httpd.h
@@ -153,11 +153,29 @@ extern struct TALER_Amount AH_annual_fee;
 
 /**
  * Cost of authentication by question
- * FIXME: Implement a more elegant way to
- * list costs of authentication methods
  */
 extern struct TALER_Amount AH_question_cost;
 
+/**
+ * Cost of authentication by email
+ */
+extern struct TALER_Amount AH_email_cost;
+
+/**
+ * Cost of authentication by post
+ */
+extern struct TALER_Amount AH_post_cost;
+
+/**
+ * Cost of authentication by video
+ */
+extern struct TALER_Amount AH_video_cost;
+
+/**
+ * Cost of authentication by sms
+ */
+extern struct TALER_Amount AH_sms_cost;
+
 /**
  * Our Taler backend to process payments.
  */
diff --git a/src/backend/anastasis-httpd_config.c 
b/src/backend/anastasis-httpd_config.c
index 3340c8f..dae879a 100644
--- a/src/backend/anastasis-httpd_config.c
+++ b/src/backend/anastasis-httpd_config.c
@@ -21,6 +21,7 @@
  * @author Dominik Meister
  */
 #include "platform.h"
+#include <jansson.h>
 #include "anastasis-httpd_config.h"
 #include <taler/taler_json_lib.h>
 
@@ -42,20 +43,95 @@ AH_handler_config (struct TMH_RequestHandler *rh,
                    const char *upload_data,
                    size_t *upload_data_size)
 {
+  json_t *methods = json_object ();
+  json_t *method_arr = json_array ();
+  if (! method_arr)
+    return MHD_HTTP_BAD_GATEWAY;
+
+  if (strstr (AH_supported_methods, "question"))
+  {
+    json_t *question = json_object ();
+
+    json_object_set_new (question,
+                         "method",
+                         json_string ("question"));
+    json_object_set_new (question,
+                         "cost",
+                         TALER_JSON_from_amount (&AH_question_cost));
+    GNUNET_assert (
+      0 ==
+      json_array_append_new (method_arr, question));
+  }
+  if (strstr (AH_supported_methods, "sms"))
+  {
+    json_t *sms = json_object ();
+
+    json_object_set_new (sms,
+                         "method",
+                         json_string ("sms"));
+    json_object_set_new (sms,
+                         "cost",
+                         TALER_JSON_from_amount (&AH_sms_cost));
+    GNUNET_assert (
+      0 ==
+      json_array_append_new (method_arr, sms));
+  }
+  if (strstr (AH_supported_methods, "email"))
+  {
+    json_t *email = json_object ();
+
+    json_object_set_new (email,
+                         "method",
+                         json_string ("email"));
+    json_object_set_new (email,
+                         "cost",
+                         TALER_JSON_from_amount (&AH_email_cost));
+    GNUNET_assert (
+      0 ==
+      json_array_append_new (method_arr, email));
+  }
+  if (strstr (AH_supported_methods, "video"))
+  {
+    json_t *video = json_object ();
+
+    json_object_set_new (video,
+                         "method",
+                         json_string ("video"));
+    json_object_set_new (video,
+                         "cost",
+                         TALER_JSON_from_amount (&AH_video_cost));
+    GNUNET_assert (
+      0 ==
+      json_array_append_new (method_arr, video));
+  }
+  if (strstr (AH_supported_methods, "post"))
+  {
+    json_t *post = json_object ();
+
+
+    json_object_set_new (post,
+                         "method",
+                         json_string ("post"));
+    json_object_set_new (post,
+                         "cost",
+                         TALER_JSON_from_amount (&AH_post_cost));
+    GNUNET_assert (
+      0 ==
+      json_array_append_new (method_arr, post));
+  }
+  json_object_set_new (methods, "methods", method_arr);
   return TALER_MHD_reply_json_pack (connection,
                                     MHD_HTTP_OK,
-                                    "{s:s, s:s, s:I, s:s, s:o, s:o, s:s}",
+                                    "{s:s, s:s, s:I, s:s, s:o, s:s}",
                                     "name", "anastasis",
                                     "methods",
-                                    (char *) AH_supported_methods,
+                                    json_dumps (methods, JSON_COMPACT),
                                     "storage_limit_in_megabytes",
                                     (json_int_t) AH_upload_limit_mb,
                                     "currency",
                                     (char *) AH_currency,
                                     "annual_fee",
                                     TALER_JSON_from_amount (&AH_annual_fee),
-                                    "question_cost",
-                                    TALER_JSON_from_amount 
(&AH_question_cost), // FIXME: implement a more elegant solution
                                     "version", "0:0:0");
 }
 
diff --git a/src/cli/anastasis-cli-assembler.c 
b/src/cli/anastasis-cli-assembler.c
index 565a524..fbd6d4b 100644
--- a/src/cli/anastasis-cli-assembler.c
+++ b/src/cli/anastasis-cli-assembler.c
@@ -48,7 +48,7 @@ static unsigned int import_recovery_version;
 static struct GNUNET_SCHEDULER_Task *keyboard_task;
 
 /**
- * Curl context for communication with taler backend
+ * Curl context for communication with anastasis backend
  */
 static struct GNUNET_CURL_Context *ctx;
 
@@ -558,17 +558,17 @@ start_read_keyboard ()
  * @param methods supported methods by this provider
  * @param conf_currency
  * @param annual_fee Annual fee of this service
- * @param question_cost Cost for authentication by question
  */
 static void
 config_cb (void *cls,
            unsigned int http_status,
-           const char *methods,
+           const json_t *methods,
            const char *conf_currency,
-           const struct TALER_Amount *annual_fee,
-           const struct TALER_Amount *question_cost)
+           const struct TALER_Amount *annual_fee)
 {
   struct ConfigState *cs = cls;
+  size_t index;
+  json_t *method;
 
   cs->co = NULL;
   if (http_status != cs->http_status)
@@ -581,10 +581,23 @@ config_cb (void *cls,
     return;
   }
 
-  cs->ci->cost = GNUNET_new (struct TALER_Amount);
-  GNUNET_memcpy (cs->ci->cost,
-                 question_cost,
-                 sizeof (*question_cost));
+  json_t *method_arr = json_object_get (methods,
+                                        "methods");
+  json_array_foreach (method_arr, index, method)
+  {
+    if (json_object_get (method, cs->ci->method))
+    {
+      struct TALER_Amount *amount;
+      TALER_string_to_amount (json_string_value (json_object_get (
+                                                   method, "method_cost")),
+                              amount);
+      cs->ci->cost = GNUNET_new (struct TALER_Amount);
+      GNUNET_memcpy (cs->ci->cost,
+                     amount,
+                     sizeof (*amount));
+      break;
+    }
+  }
   cs->ci->currency = GNUNET_malloc (strlen (conf_currency) + 1);
   GNUNET_strlcpy (cs->ci->currency,
                   conf_currency,
diff --git a/src/cli/anastasis-cli-splitter.c b/src/cli/anastasis-cli-splitter.c
index eb37db8..9a1b80e 100644
--- a/src/cli/anastasis-cli-splitter.c
+++ b/src/cli/anastasis-cli-splitter.c
@@ -132,7 +132,7 @@ struct ServerInfo
   /**
    * supported methods of the anastasis backend.
    */
-  char *backend_methods;
+  json_t *backend_methods;
 
   /**
    * server salt of the anastasis backend.
@@ -209,7 +209,7 @@ struct ConfigState
   /**
    * Supported methods.
    */
-  char *methods;
+  json_t *methods;
 
   // FIXME add configs
 };
@@ -559,15 +559,13 @@ truth_upload_cb (void *cls,
  * @param http_status HTTP status of the request
  * @param methods supported methods by this provider
  * @param annual_fee Annual fee of this service
- * @param question_cost Cost for authentication by question
  */
 static void
 config_cb (void *cls,
            unsigned int http_status,
-           const char *methods,
+           const json_t *methods,
            const char *conf_currency,
-           const struct TALER_Amount *annual_fee,
-           const struct TALER_Amount *question_cost)
+           const struct TALER_Amount *annual_fee)
 {
   struct ConfigState *cs = cls;
   struct ANASTASIS_PaymentDetails *pd = GNUNET_new (struct
@@ -592,10 +590,7 @@ config_cb (void *cls,
   }
 
   cs->cost = *annual_fee;
-  cs->methods = GNUNET_malloc (strlen (methods) + 1);
-  GNUNET_strlcpy (cs->methods,
-                  methods,
-                  strlen (methods) + 1);
+  cs->methods = methods;
   printf ("Server #%u is available\n",
           servers_length);
 
@@ -758,14 +753,48 @@ read_keyboard_command (void *cls)
     {
       for (unsigned int i = 0; i < servers_length; i++)
       {
+        char *methods_str = "";
+        size_t index;
+        json_t *method;
+        json_t *method_arr = json_object_get (
+          servers[i].backend_methods, "methods");
+
+        json_array_foreach (method_arr,
+                            index,
+                            method)
+        {
+          char *buf = GNUNET_malloc (strlen (methods_str) + 1);
+          const char *method_str = json_string_value (
+            json_object_get (method, "method"));;
+          if (method_str)
+          {
+            if (strlen (methods_str) > 0)
+            {
+              GNUNET_strlcpy (buf,
+                              methods_str,
+                              strlen (methods_str));
+              GNUNET_free (methods_str);
+              GNUNET_asprintf (&methods_str,
+                               ", %s, %s",
+                               buf,
+                               method_str);
+            }
+            else
+              GNUNET_asprintf (&methods_str,
+                               "%s",
+                               method_str);
+            GNUNET_free (buf);
+          }
+        }
         if (NULL != servers[i].backend_url)
           printf ("server#%u: %s %s, insured up to: %s, cost: %s\n",
                   i,
                   servers[i].backend_url,
-                  servers[i].backend_methods,
+                  methods_str,
                   "test_insurance_amount", // FIXME
                   TALER_amount_to_string (servers[i].backend_cost)
                   );
+        GNUNET_free (methods_str);
       }
     }
     else
@@ -922,8 +951,20 @@ read_keyboard_command (void *cls)
         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                     "At %s:%d method is %s\n", __FILE__, __LINE__,
                     tus->method);
-        if (NULL != strstr (servers[server_num].backend_methods,
-                            tus->method))
+        bool method_supported = false;
+        size_t index;
+        json_t *method;
+        json_t *methods = json_object_get (servers[server_num].backend_methods,
+                                           "methods");
+        json_array_foreach (methods, index, method)
+        {
+          if (json_object_get (method, tus->method))
+          {
+            method_supported = true;
+            break;
+          }
+        }
+        if (method_supported)
         {
           if (0 == strcmp ("question", tus->method))
           {
diff --git a/src/include/anastasis_redux.h b/src/include/anastasis_redux.h
index 8d2cfe9..4adc474 100644
--- a/src/include/anastasis_redux.h
+++ b/src/include/anastasis_redux.h
@@ -27,6 +27,7 @@
 #include <gnunet/gnunet_util_lib.h>
 #include "anastasis_error_codes.h"
 
+
 /**
  * JSON containing all supported countries and additional data.
  */
diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index 93df99c..d192afc 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -243,10 +243,9 @@ struct ANASTASIS_UploadDetails
 typedef void
 (*ANASTASIS_ConfigCallback)(void *cls,
                             unsigned int http_status,
-                            const char *methods,
+                            const json_t *methods,
                             const char *conf_currency,
-                            const struct TALER_Amount *annual_fee,
-                            const struct TALER_Amount *question_cost);
+                            const struct TALER_Amount *annual_fee);
 
 
 struct ANASTASIS_ConfigOperation *
@@ -298,14 +297,7 @@ struct ANASTASIS_ConfigOperation
   /**
    * Supported methods.
    */
-  const char *methods;
-
-  /**
-   * Cost of authentication by question
-   * FIXME: Implement a more elegant way to
-   * list costs of authentication methods
-   */
-  struct TALER_Amount question_cost;
+  json_t *methods;
 
   /**
    * Currency of the cost;
diff --git a/src/lib/anastasis_api_backup_redux.c 
b/src/lib/anastasis_api_backup_redux.c
index 1a32f70..e4a8b0f 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -162,13 +162,69 @@ add_authentication (const json_t *state,
                    "backup-state",
                    json_string ("ReduxAuthenticationAddedState"));
 
-  json_object_set_new (new_state,
-                       "authentication_methods",
-                       methods);
+  json_object_set (new_state,
+                   "authentication_methods",
+                   methods);
+
+  {
+    // initialize policy
+    size_t index_m; // index methods array
+    size_t index_up; // index used_providers array
+    json_t *method;
+    json_t *used_providers = json_array ();
+    json_t *policy = json_array ();
+
+    // simply distribute the methods
+    json_array_foreach (methods, index_m, method)
+    {
+      size_t index_p; // index providers array
+      json_t *provider;
+      json_t *used_provider;
+      json_t *policy_element = json_object ();
+      json_t *provider_arr = json_object_get (method, "providers");
+      json_array_foreach (provider_arr, index_p, provider)
+      {
+        json_t *method_cpy = json_deep_copy (method);
+        json_object_del (method_cpy, "providers");
+        json_object_set_new (policy_element, "method", method_cpy);
+
+        bool used = false;
+        json_array_foreach (used_providers, index_up, used_provider)
+        {
+          // first, check if provider already is used for a method
+          if (json_equal (provider, used_provider))
+          {
+            used = true;
+            break;
+          }
+        }
+        if (! used)
+        {
+          // if provider is not used for a method, choose it
+          json_array_append (used_providers, provider);
+          json_object_set_new (policy_element, "provider", provider);
+          break;
+        }
+        // if all providers are used once, begin with the first again
+        if (json_array_size (provider_arr) == index_p - 1)
+        {
+          json_array_clear (used_providers);
+          provider = json_array_get (provider_arr, 0);
+          json_array_append (used_providers, provider);
+          json_object_set_new (policy_element, "provider", provider);
+        }
+      }
+      json_array_append_new (policy, policy_element);
+    }
+    json_object_set_new (new_state,
+                         "initial_policy",
+                         policy);
+  }
 
   cb (cb_cls,
       ANASTASIS_EC_NONE,
       new_state);
+  json_decref (methods);
   json_decref (new_state);
 }
 
diff --git a/src/lib/anastasis_api_config.c b/src/lib/anastasis_api_config.c
index 54c3337..ef69a69 100644
--- a/src/lib/anastasis_api_config.c
+++ b/src/lib/anastasis_api_config.c
@@ -47,6 +47,7 @@ handle_config_finished (void *cls,
 {
   struct ANASTASIS_ConfigOperation *co = cls;
   const json_t *json = response;
+  json_error_t err;
 
   co->job = NULL;
   switch (response_code)
@@ -59,10 +60,8 @@ handle_config_finished (void *cls,
   case MHD_HTTP_OK:
     {
       struct GNUNET_JSON_Specification spec[] = {
-        GNUNET_JSON_spec_string ("methods", &co->methods),
         GNUNET_JSON_spec_string ("currency", &co->currency),
         TALER_JSON_spec_amount ("annual_fee", &co->cost),
-        TALER_JSON_spec_amount ("question_cost", &co->question_cost),
         // FIXME add configs
         GNUNET_JSON_spec_end ()
       };
@@ -75,15 +74,17 @@ handle_config_finished (void *cls,
         GNUNET_break (0);
         return;
       }
+      co->methods = json_loads (json_string_value (
+                                  json_object_get (json, "methods")),
+                                JSON_DECODE_ANY, &err);
 
       co->cb (co->cb_cls,
               response_code,
               co->methods,
               co->currency,
-              &co->cost,
-              &co->question_cost
-              // FIXME add configs
+              &co->cost
               );
+      GNUNET_JSON_parse_free (spec);
       ANASTASIS_config_cancel (co);
       return;
     }
@@ -113,7 +114,6 @@ handle_config_finished (void *cls,
             response_code,
             NULL,
             NULL,
-            NULL,
             NULL);
     co->cb = NULL;
   }
@@ -143,6 +143,12 @@ ANASTASIS_get_config (struct GNUNET_CURL_Context *ctx,
                                   GNUNET_NO,
                                   &handle_config_finished,
                                   co);
+  if (NULL == co->job)
+  {
+    GNUNET_free (co->url);
+    GNUNET_free (co);
+    return NULL;
+  }
   return co;
 }
 
diff --git a/src/lib/anastasis_api_curl_defaults.c 
b/src/lib/anastasis_api_curl_defaults.c
index f70e906..5e9b200 100644
--- a/src/lib/anastasis_api_curl_defaults.c
+++ b/src/lib/anastasis_api_curl_defaults.c
@@ -34,6 +34,8 @@ ANASTASIS_curl_easy_get_ (const char *url)
   CURL *eh;
 
   eh = curl_easy_init ();
+  if (NULL == eh)
+    return NULL;
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
                                    CURLOPT_URL,
diff --git a/src/lib/anastasis_api_redux.c b/src/lib/anastasis_api_redux.c
index 3793772..3859729 100644
--- a/src/lib/anastasis_api_redux.c
+++ b/src/lib/anastasis_api_redux.c
@@ -245,7 +245,7 @@ select_country (const json_t *state,
       redux_id_attr_init (json_string_value (country)))
   {
     GNUNET_break (0);
-    return NULL;
+    return;
   }
   new_state = json_deep_copy (state);
   if (NULL == new_state)
@@ -304,7 +304,7 @@ change_country (const json_t *state,
       redux_id_attr_init (json_string_value (country)))
   {
     GNUNET_break (0);
-    return NULL;
+    return;
   }
   new_state = json_deep_copy (state);
   if (NULL == new_state)
@@ -355,7 +355,7 @@ enter_user_attributes (const json_t *state,
     if (NULL == path)
     {
       GNUNET_break (0);
-      return GNUNET_SYSERR;
+      return;
     }
     GNUNET_asprintf (&dn,
                      "%s/share/anastasis/provider-list.json",
@@ -373,7 +373,7 @@ enter_user_attributes (const json_t *state,
                 error.column,
                 error.position);
     GNUNET_free (dn);
-    return GNUNET_SYSERR;
+    return;
   }
 
   if (NULL == state)

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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