gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 01/08: fixes


From: gnunet
Subject: [taler-anastasis] 01/08: fixes
Date: Fri, 09 Oct 2020 12:03:42 +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 5433de1efe735d0e9663d655a32a8f2d89b8210d
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Tue Oct 6 16:11:50 2020 +0200

    fixes
---
 src/lib/Makefile.am                  |   1 +
 src/lib/anastasis_api_backup_redux.c | 116 ++++-----------
 src/lib/anastasis_api_redux.c        | 267 +++++++++++++----------------------
 3 files changed, 127 insertions(+), 257 deletions(-)

diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index ae4c20c..7e37ec4 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -108,6 +108,7 @@ libanastasisredux_la_LIBADD = \
   -lgnunetjson \
   -lgnunetcurl \
   -lgnunetutil \
+  -ltalerutil \
   -ljansson \
   $(XLIB)
 
diff --git a/src/lib/anastasis_api_backup_redux.c 
b/src/lib/anastasis_api_backup_redux.c
index e83e0d7..b06f257 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -23,6 +23,7 @@
 
 #include <platform.h>
 #include <jansson.h>
+#include <taler/taler_util.h>
 #include "anastasis_redux.h"
 #include "anastasis_error_codes.h"
 
@@ -83,13 +84,13 @@ ANASTASIS_backup_start (const struct 
GNUNET_CONFIGURATION_Handle *cfg)
   }
 
   initial_state = json_pack ("{s:s, s:o}",
-                             "backup-state", "ReduxInitialState",
+                             "backup-state", "ContinentSelectionState",
                              "continents", continents);
   GNUNET_assert (NULL != initial_state);
   return initial_state;
 }
 
-
+/** FIXME: Implement just one "back" action
 static void
 edit_user_attributes (const json_t *state,
                       const json_t *arguments,
@@ -132,6 +133,7 @@ edit_user_attributes (const json_t *state,
       new_state);
   json_decref (new_state);
 }
+*/
 
 
 static void
@@ -151,62 +153,8 @@ add_authentication (const json_t *state,
                    methods);
 
   {
-    /** FIXME: RUBBISH :)
-    // 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) // FIXME: add individual, 
remove loop!
-    {
-      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,
@@ -260,7 +208,7 @@ eval_provider_selection (struct PolicyBuilder *pb,
             prov_sel,
             sizeof (unsigned int) * pb->req_methods);
     pb->best_diversity = curr_diversity;
-    ob->best_cost = curr_cost;
+    pb->best_cost = curr_cost;
   }
 }
 
@@ -366,7 +314,7 @@ done_authentication (const json_t *state,
   pb.methods = json_object_get (state,
                                 "authentication_methods");
   pb.policies = json_array_new ();
-  pb.num_methods = json_array_size (methods);
+  pb.num_methods = json_array_size (pb.methods);
   switch (pb.num_methods)
   {
   case 0:
@@ -374,7 +322,7 @@ done_authentication (const json_t *state,
     break;
   case 1:
   case 2:
-    pb.req_methods = num_methods;
+    pb.req_methods = pb.num_methods;
     break;
   case 3:
   case 4:
@@ -385,7 +333,7 @@ done_authentication (const json_t *state,
     break;
   }
   {
-    unsigned int m_idx[req_methods];
+    unsigned int m_idx[pb.req_methods];
 
     method_candidate (&pb,
                       m_idx,
@@ -396,19 +344,27 @@ done_authentication (const json_t *state,
 
 
   }
-
-
   json_object_set_new (state,
                        "policies",
-                       policies);
+                       pb.policies);
   set_state (state,
-             "ReduxAuthenticationAddedState");
+             "ReviewPoliciesState");
   cb (cb_cls,
       ANASTASIS_EC_NONE,
       state);
 }
 
 
+static void
+del_authentication (const json_t *state,
+                    const json_t *arguments,
+                    ANASTASIS_ActionCallback cb,
+                    void *cb_cls)
+{
+
+}
+
+
 static void
 add_policy (const json_t *state,
             const json_t *arguments,
@@ -446,37 +402,20 @@ ANASTASIS_backup_action (json_t *state,
     DispatchHandler fun;
   } dispatchers[] = {
     {
-      "ReduxUserAttributesAddedState",
-      "adding_authentication",
+      "AuthenticationsEditingState",
+      "add_authentication",
       &add_authentication
     },
-    #if 0
     {
-      "ReduxUserAttributesAddedState",
-      "deleting_authentication",
+      "AuthenticationsEditingState",
+      "delete_authentication",
       &del_authentication
     },
-    #endif
     {
-      "ReduxUserAttributesAddedState",
-      "next", // done_authentication",
+      "AuthenticationsEditingState",
+      "next",
       &done_authentication
     },
-    {
-      "ReduxUserAttributesAddedState",
-      "editing_user_attributes",
-      &edit_user_attributes
-    },
-    {
-      "ReduxAuthenticationAddedState",
-      "adding_policy",
-      &add_policy
-    },
-    {
-      "ReduxAuthenticationAddedState",
-      "back", // editing_user_attributes",
-      &edit_user_attributes
-    },
     { NULL, NULL, NULL }
   };
   const char *s = json_string_value (json_object_get (state,
@@ -501,5 +440,4 @@ ANASTASIS_backup_action (json_t *state,
   cb (cb_cls,
       ANASTASIS_EC_INVALID, // FIXME: Define correct error code
       NULL);
-
 }
diff --git a/src/lib/anastasis_api_redux.c b/src/lib/anastasis_api_redux.c
index 9245a54..60180ec 100644
--- a/src/lib/anastasis_api_redux.c
+++ b/src/lib/anastasis_api_redux.c
@@ -41,11 +41,6 @@ json_t *redux_id_attr;
  */
 json_t *provider_list;
 
-/**
- * backup or recovery mode
- */
-static char *s_mode;
-
 
 /**
  * Callback function FIXME: Description.
@@ -62,6 +57,24 @@ typedef void
                    void *cb_cls);
 
 
+/**
+ * Extract the mode of a state from json
+ *
+ * @param state the state to operate on
+ * @return char*
+ */
+static
+char *get_state_mode (const json_t *state)
+{
+  if (json_object_get (state, "backup_state"))
+    return "backup_state";
+  else if (json_object_get (state, "recovery_state"))
+    return "recovery_state";
+  else
+    return NULL;
+}
+
+
 /**
  * Function to load json containing all countries.
  * Returns #GNUNET_OK if operation succeeded, else #GNUNET_SYSERR.
@@ -154,40 +167,23 @@ redux_id_attr_init (const char*country_code)
 
 
 static void
-select_continent (const json_t *state,
+select_continent (json_t *state,
                   const json_t *arguments,
                   ANASTASIS_ActionCallback cb,
                   void *cb_cls)
 {
-  json_t *new_state;
   size_t index;
   json_t *country;
   json_t *root = json_object_get (redux_countries, "countries");
   json_t *countries = json_array ();
   json_t *continent = json_object_get (arguments, "continent");
 
-  if (NULL == state)
-  {
-    GNUNET_break (0);
-    cb (cb_cls,
-        ANASTASIS_EC_INVALID, // FIXME: Define correct error code
-        NULL);
-  }
-  if (NULL == continent)
-  {
-    GNUNET_break (0);
-    cb (cb_cls,
-        ANASTASIS_EC_INVALID, // FIXME: Define correct error code
-        NULL);
-  }
-  new_state = json_deep_copy (state);
-  if (NULL == new_state)
-  {
-    GNUNET_break (0);
-    cb (cb_cls,
-        ANASTASIS_EC_INVALID, // FIXME: Define correct error code
-        NULL);
-  }
+  GNUNET_assert (NULL != root);
+  GNUNET_assert (NULL != countries);
+  GNUNET_assert (NULL != continent);
+  GNUNET_assert (NULL != state);
+  const char *s_mode = get_state_mode (state);
+  GNUNET_assert (NULL != s_mode);
 
   json_array_foreach (root, index, country)
   {
@@ -198,22 +194,21 @@ select_continent (const json_t *state,
       json_array_append_new (countries, country);
   }
 
-  json_object_set (new_state,
-                   s_mode,
-                   json_string ("ReduxContinentSelectedState"));
+  json_object_set_new (state,
+                       s_mode,
+                       json_string ("CountrySelectionState"));
 
-  json_object_set_new (new_state,
+  json_object_set_new (state,
                        "selected_continent",
                        continent);
 
-  json_object_set_new (new_state,
+  json_object_set_new (state,
                        "countries",
                        countries);
 
   cb (cb_cls,
       ANASTASIS_EC_NONE,
-      new_state);
-  json_decref (new_state);
+      state);
 }
 
 
@@ -223,116 +218,70 @@ select_country (const json_t *state,
                 ANASTASIS_ActionCallback cb,
                 void *cb_cls)
 {
-  json_t *new_state;
   json_t *root;
   json_t *country = json_object_get (arguments, "country_code");
 
-  if (NULL == state)
-  {
-    GNUNET_break (0);
-    cb (cb_cls,
-        ANASTASIS_EC_INVALID, // FIXME: Define correct error code
-        NULL);
-  }
-  if (NULL == country)
-  {
-    GNUNET_break (0);
-    cb (cb_cls,
-        ANASTASIS_EC_INVALID, // FIXME: Define correct error code
-        NULL);
-  }
-  if (GNUNET_SYSERR ==
-      redux_id_attr_init (json_string_value (country)))
-  {
-    GNUNET_break (0);
-    return;
-  }
-  new_state = json_deep_copy (state);
-  if (NULL == new_state)
-  {
-    GNUNET_break (0);
-    cb (cb_cls,
-        ANASTASIS_EC_INVALID, // FIXME: Define correct error code
-        NULL);
-  }
+  GNUNET_assert (NULL != country);
+  GNUNET_assert (NULL != state);
+  const char *s_mode = get_state_mode (state);
+  GNUNET_assert (NULL != s_mode);
+  GNUNET_assert (GNUNET_SYSERR !=
+                 redux_id_attr_init (json_string_value (country)));
   root = json_object_get (redux_id_attr, "required_attributes");
+  GNUNET_assert (NULL != root);
+  json_object_set_new (state,
+                       s_mode,
+                       json_string ("UserAttributesCollectionState"));
 
-  json_object_set (new_state,
-                   s_mode,
-                   json_string ("ReduxCountrySelectedState"));
-
-  json_object_set_new (new_state,
+  json_object_set_new (state,
                        "selected_country",
                        country);
 
-  json_object_set_new (new_state,
+  json_object_set_new (state,
                        "required_attributes",
                        root);
 
   cb (cb_cls,
       ANASTASIS_EC_NONE,
-      new_state);
-  json_decref (new_state);
+      state);
 }
 
 
 static void
-change_country (const json_t *state,
-                const json_t *arguments,
-                ANASTASIS_ActionCallback cb,
-                void *cb_cls)
+unselect_country (const json_t *state,
+                  const json_t *arguments,
+                  ANASTASIS_ActionCallback cb,
+                  void *cb_cls)
 {
-  json_t *new_state;
-  json_t *root;
-  json_t *country = json_object_get (arguments, "country_code");
-
-  if (NULL == state)
-  {
-    GNUNET_break (0);
-    cb (cb_cls,
-        ANASTASIS_EC_INVALID, // FIXME: Define correct error code
-        NULL);
-  }
-  if (NULL == country)
-  {
-    GNUNET_break (0);
-    cb (cb_cls,
-        ANASTASIS_EC_INVALID, // FIXME: Define correct error code
-        NULL);
-  }
-  if (GNUNET_SYSERR ==
-      redux_id_attr_init (json_string_value (country)))
-  {
-    GNUNET_break (0);
-    return;
-  }
-  new_state = json_deep_copy (state);
-  if (NULL == new_state)
-  {
-    GNUNET_break (0);
-    cb (cb_cls,
-        ANASTASIS_EC_INVALID, // FIXME: Define correct error code
-        NULL);
-  }
-  root = json_object_get (redux_id_attr, "required_attributes");
-
-
-  json_object_set (new_state,
-                   s_mode,
-                   json_string ("ReduxContinentSelectedState"));
-
-  json_object_set_new (new_state,
-                       "selected_country",
-                       country);
+  GNUNET_assert (NULL != state);
+  const char *s_mode = get_state_mode (state);
+  GNUNET_assert (NULL != s_mode);
+  GNUNET_assert (0 ==
+                 json_object_set_new (state,
+                                      s_mode,
+                                      json_string ("CountrySelectionState")));
+  cb (cb_cls,
+      ANASTASIS_EC_NONE,
+      state);
+}
 
-  json_object_set_new (new_state,
-                       "required_attributes",
-                       root);
 
+static void
+unselect_continent (const json_t *state,
+                    const json_t *arguments,
+                    ANASTASIS_ActionCallback cb,
+                    void *cb_cls)
+{
+  GNUNET_assert (NULL != state);
+  const char *s_mode = get_state_mode (state);
+  GNUNET_assert (NULL != s_mode);
+  GNUNET_assert (0 ==
+                 json_object_set_new (state,
+                                      s_mode,
+                                      json_string 
("ContinentSelectionState")));
   cb (cb_cls,
       ANASTASIS_EC_NONE,
-      new_state);
-  json_decref (new_state);
+      state);
 }
 
 
@@ -342,12 +291,15 @@ enter_user_attributes (const json_t *state,
                        ANASTASIS_ActionCallback cb,
                        void *cb_cls)
 {
-  json_t *new_state;
-  json_t *attributes = json_object_get (arguments, "identity");
   json_t *root;
   char *dn;
   json_error_t error;
+  json_t *attributes = json_object_get (arguments, "identity");
 
+  GNUNET_assert (NULL != attributes);
+  GNUNET_assert (NULL != state);
+  const char *s_mode = get_state_mode (state);
+  GNUNET_assert (NULL != s_mode);
   {
     char *path;
 
@@ -375,48 +327,22 @@ enter_user_attributes (const json_t *state,
     GNUNET_free (dn);
     return;
   }
-
-  if (NULL == state)
-  {
-    GNUNET_break (0);
-    cb (cb_cls,
-        ANASTASIS_EC_INVALID, // FIXME: Define correct error code
-        NULL);
-  }
-  if (NULL == attributes)
-  {
-    GNUNET_break (0);
-    cb (cb_cls,
-        ANASTASIS_EC_INVALID, // FIXME: Define correct error code
-        NULL);
-  }
-
-  new_state = json_deep_copy (state);
-  if (NULL == new_state)
-  {
-    GNUNET_break (0);
-    cb (cb_cls,
-        ANASTASIS_EC_INVALID, // FIXME: Define correct error code
-        NULL);
-  }
   root = json_object_get (provider_list, "anastasis-provider");
-
-  json_object_set_new (new_state,
+  GNUNET_assert (NULL != root);
+  json_object_set_new (state,
                        s_mode,
-                       json_string ("ReduxUserAttributesAddedState"));
+                       json_string ("AuthenticationsEditingState"));
 
-  json_object_set_new (new_state,
+  json_object_set_new (state,
                        "identity_attributes",
                        attributes);
 
-  json_object_set_new (new_state,
+  json_object_set_new (state,
                        "provider-list",
                        root);
-
   cb (cb_cls,
       ANASTASIS_EC_NONE,
-      new_state);
-  json_decref (new_state);
+      state);
 }
 
 
@@ -449,24 +375,29 @@ ANASTASIS_redux_action (const json_t *state,
     DispatchHandler fun;
   } dispatchers[] = {
     {
-      "ReduxInitialState",
-      "selection_continent",
+      "ContinentSelectionState",
+      "select_continent",
       &select_continent
     },
     {
-      "ReduxContinentSelectedState",
-      "selection_country",
+      "CountrySelectionState",
+      "select_continent",
+      &unselect_continent
+    },
+    {
+      "CountrySelectionState",
+      "select_country",
       &select_country
     },
     {
-      "ReduxCountrySelectedState",
-      "entering_user_attributes",
-      &enter_user_attributes
+      "UserAttributesCollectionState",
+      "back",
+      &unselect_country
     },
     {
-      "ReduxUserAttributesAddedState",
-      "changing_country",
-      &change_country
+      "UserAttributesCollectionState",
+      "enter_user_attributes",
+      &enter_user_attributes
     },
     { NULL, NULL, NULL }
   };

-- 
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]