gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated: refactoring


From: gnunet
Subject: [taler-anastasis] branch master updated: refactoring
Date: Wed, 14 Oct 2020 13:41:07 +0200

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

grothoff pushed a commit to branch master
in repository anastasis.

The following commit(s) were added to refs/heads/master by this push:
     new 7ae4490  refactoring
7ae4490 is described below

commit 7ae4490bae611ec893d2bf5724783ac915066de2
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Oct 14 13:41:04 2020 +0200

    refactoring
---
 src/include/anastasis_redux.h        | 131 ++++++++++++++++--------
 src/lib/Makefile.am                  |   2 +-
 src/lib/anastasis_api_backup_redux.c | 130 +++++++++++++-----------
 src/lib/anastasis_api_redux.c        | 191 +++++++++++++++++------------------
 4 files changed, 256 insertions(+), 198 deletions(-)

diff --git a/src/include/anastasis_redux.h b/src/include/anastasis_redux.h
index 0955c72..84346bf 100644
--- a/src/include/anastasis_redux.h
+++ b/src/include/anastasis_redux.h
@@ -28,27 +28,52 @@
 #include "anastasis_error_codes.h"
 #include "anastasis_service.h"
 
-#define FOREACH_STATE(REDUX_STATE) \
-  REDUX_STATE (ContinentSelectionState)   \
-  REDUX_STATE (CountrySelectionState)  \
-  REDUX_STATE (UserAttributesCollectionState)   \
+#define ANASTASIS_GENERIC_STATES(REDUX_STATE) \
+  REDUX_STATE (ERROR) \
+  REDUX_STATE (CONTINENT_SELECTION)   \
+  REDUX_STATE (COUNTRY_SELECTION)  \
+  REDUX_STATE (USER_ATTRIBUTES_COLLECTION)
+
+#define GENERATE_GENERIC_ENUM(ENUM) ANASTASIS_GENERIC_STATE_ ## ENUM,
+
+enum ANASTASIS_GenericState
+{
+  ANASTASIS_GENERIC_STATES (GENERATE_GENERIC_ENUM)
+};
+
+#undef GENERATE_BACKUP_ENUM
+
+#define ANASTASIS_BACKUP_STATES(REDUX_STATE) \
+  ANASTASIS_GENERIC_STATES (REDUX_STATE) \
   REDUX_STATE (AuthenticationsEditingState)  \
   REDUX_STATE (PoliciesReviewingState)   \
   REDUX_STATE (BackupPayingState)  \
   REDUX_STATE (NoState) \
 
-#define GENERATE_ENUM(ENUM) ENUM,
-#define GENERATE_STRING(STRING) #STRING,
+#define GENERATE_BACKUP_ENUM(ENUM) ANASTASIS_BACKUP_STATE_ ## ENUM,
 
-typedef enum
+enum ANASTASIS_BackupState
 {
-  FOREACH_STATE (GENERATE_ENUM)
-} REDUX_STATE;
+  ANASTASIS_BACKUP_STATES (GENERATE_BACKUP_ENUM)
+};
+
+#undef GENERATE_BACKUP_ENUM
 
-static const char *STATE_STRING[] = {
-  FOREACH_STATE (GENERATE_STRING)
+#define ANASTASIS_RECOVERY_STATES(REDUX_STATE) \
+  ANASTASIS_GENERIC_STATES (REDUX_STATE) \
+  REDUX_STATE (AuthenticationsEditingState)  \
+  REDUX_STATE (PoliciesReviewingState)   \
+  REDUX_STATE (BackupPayingState)  \
+  REDUX_STATE (NoState) \
+
+#define GENERATE_RECOVERY_ENUM(ENUM) ANASTASIS_RECOVERY_STATE_ ## ENUM,
+
+enum ANASTASIS_RecoveryState
+{
+  ANASTASIS_RECOVERY_STATES (GENERATE_RECOVERY_ENUM)
 };
 
+
 /**
  * JSON containing country specific identity attributes to ask the user for.
  */
@@ -61,30 +86,70 @@ extern const char *currency;
 
 
 /**
- * Returns the integer value to a string value of a state.
+ * Returns the enum value to a string value of a state.
  *
  * @param state_string
- * @return int
+ * @return XXX on error
  */
-int get_enum_from_string (const char *state_string);
+enum ANASTASIS_GenericState
+ANASTASIS_generic_state_from_string (const char *state_string);
 
 
 /**
- * Returns an initial ANASTASIS backup state.
+ * Returns the string value of a state.
  *
- * @return NULL on failure
+ * @param state_string
+ * @return NULL on error
  */
-json_t *
-ANASTASIS_backup_start (const struct GNUNET_CONFIGURATION_Handle *cfg);
+const char *
+ANASTASIS_generic_state_to_string (enum ANASTASIS_GenericState gs);
 
 
 /**
- * Returns an initial ANASTASIS recovery state.
+ * Returns the enum value to a string value of a state.
+ *
+ * @param state_string
+ * @return #ANASTASIS_BACKUP_STATE_ERROR on error
+ */
+enum ANASTASIS_BackupState
+ANASTASIS_backup_state_from_string (const char *state_string);
+
+/**
+ * Returns the string value of a state.
+ *
+ * @param state_string
+ * @return NULL on error
+ */
+const char *
+ANASTASIS_backup_state_to_string (enum ANASTASIS_BackupState bs);
+
+
+/**
+ * Returns the enum value to a string value of a state.
+ *
+ * @param state_string
+ * @return XXX on error
+ */
+enum ANASTASIS_RecoveryState
+ANASTASIS_recovery_state_from_string (const char *state_string);
+
+/**
+ * Returns the string value of a state.
+ *
+ * @param state_string
+ * @return NULL on error
+ */
+const char *
+ANASTASIS_recovery_state_to_string (enum ANASTASIS_RecoveryState rs);
+
+
+/**
+ * Returns an initial ANASTASIS backup state.
  *
  * @return NULL on failure
  */
 json_t *
-ANASTASIS_recovery_start (const struct GNUNET_CONFIGURATION_Handle *cfg);
+ANASTASIS_backup_start (const struct GNUNET_CONFIGURATION_Handle *cfg);
 
 
 /**
@@ -97,13 +162,12 @@ ANASTASIS_recovery_start (const struct 
GNUNET_CONFIGURATION_Handle *cfg);
 
 
 /**
- * Function to load json containing all countries.
- * Returns the countries.
+ * Returns an initial ANASTASIS recovery state.
  *
- * @return json_t *
+ * @return NULL on failure
  */
 json_t *
-redux_countries_init ();
+ANASTASIS_recovery_start (const struct GNUNET_CONFIGURATION_Handle *cfg);
 
 
 /**
@@ -174,8 +238,8 @@ ANASTASIS_recovery_action (json_t *state,
  * @param state input state
  * @param action what action to perform
  * @param arguments data for the @a action
- * @param cb function to call with the result
  * @param ctx Curl context
+ * @param cb function to call with the result
  * @param cb_cls closure for @a cb
  * @return failure state or new state
  */
@@ -183,24 +247,9 @@ void
 ANASTASIS_redux_action (const json_t *state,
                         const char *action,
                         const json_t *arguments,
-                        ANASTASIS_ActionCallback cb,
                         struct GNUNET_CURL_Context *ctx,
+                        ANASTASIS_ActionCallback cb,
                         void *cb_cls);
 
 
-/**
- * Function which is called when we need to go a state backwards.
- * Sets state to previous state.
- *
- * @param[in,out] state input/output state (to be modified)
- * @param arguments normally unused
- * @param cb callback
- * @param cb_cls closure
- */
-void
-state_back (json_t *state,
-            const json_t *arguments,
-            ANASTASIS_ActionCallback cb,
-            void *cb_cls);
-
 #endif  /* _ANASTASIS_REDUX_H */
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index cb319a8..2b93137 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -101,7 +101,7 @@ libanastasisredux_la_LDFLAGS = \
   -version-info 0:0:0 \
   -no-undefined
 libanastasisredux_la_SOURCES = \
-  anastasis_api_redux.c \
+  anastasis_api_redux.c anastasis_api_redux.h \
   anastasis_api_recovery_redux.c \
   anastasis_api_backup_redux.c
 libanastasisredux_la_LIBADD = \
diff --git a/src/lib/anastasis_api_backup_redux.c 
b/src/lib/anastasis_api_backup_redux.c
index f62da4b..aadaa4f 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -27,6 +27,41 @@
 #include <taler/taler_util.h>
 #include "anastasis_redux.h"
 #include "anastasis_error_codes.h"
+#include "anastasis_api_redux.h"
+
+
+#define GENERATE_STRING(STRING) #STRING,
+static const char *backup_strings[] = {
+  ANASTASIS_BACKUP_STATES (GENERATE_STRING)
+};
+#undef GENERATE_STRING
+
+
+enum ANASTASIS_BackupState
+ANASTASIS_backup_state_from_string (const char *state_string)
+{
+  for (enum ANASTASIS_BackupState i = 0;
+       i < sizeof (backup_strings) / sizeof(*backup_strings);
+       i++)
+    if (0 == strcmp (state_string,
+                     backup_strings[i]))
+      return i;
+  return ANASTASIS_BACKUP_STATE_ERROR;
+}
+
+
+const char *
+ANASTASIS_backup_state_to_string (enum ANASTASIS_BackupState bs)
+{
+  if ( (bs < 0) ||
+       (bs >= sizeof (backup_strings) / sizeof(*backup_strings)) )
+  {
+    GNUNET_break_op (0);
+    return NULL;
+  }
+  return backup_strings[bs];
+}
+
 
 /**
  * Callback function FIXME: Description.
@@ -67,11 +102,20 @@ ANASTASIS_backup_start (const struct 
GNUNET_CONFIGURATION_Handle *cfg)
   size_t index;
   json_t *root;
   json_t *continents = json_array ();
-  json_t *redux_countries = redux_countries_init ();
+  json_t *redux_countries = ANASTASIS_redux_countries_init_ ();
 
-  GNUNET_assert (NULL != redux_countries);
-  root = json_object_get (redux_countries, "countries");
-  GNUNET_assert (NULL != root);
+  if (NULL == redux_countries)
+  {
+    GNUNET_break (0);
+    return NULL;
+  }
+  root = json_object_get (redux_countries,
+                          "countries");
+  if (NULL == root)
+  {
+    GNUNET_break (0);
+    return NULL;
+  }
 
   json_array_foreach (root, index, temp_country)
   {
@@ -79,73 +123,32 @@ ANASTASIS_backup_start (const struct 
GNUNET_CONFIGURATION_Handle *cfg)
     json_t *inner_continent;
     json_t *continent = json_object_get (json_array_get (root, index),
                                          "continent");
-
     bool existing = false;
+
     json_array_foreach (continents, inner_index, inner_continent)
     {
-      if (1 == json_equal (continent, inner_continent))
+      if (1 == json_equal (continent,
+                           inner_continent))
       {
         existing = true;
         break;
       }
     }
     if (! existing)
-      json_array_append_new (continents, continent);
+      json_array_append_new (continents,
+                             continent);
   }
 
   initial_state = json_pack ("{s:s, s:o}",
                              "backup_state",
-                             STATE_STRING[ContinentSelectionState],
-                             "continents", continents);
+                             ANASTASIS_generic_state_to_string (
+                               ContinentSelectionState),
+                             "continents",
+                             continents);
   GNUNET_assert (NULL != initial_state);
   return initial_state;
 }
 
-/** FIXME: Implement just one "back" action
-static void
-edit_user_attributes (json_t *state,
-                      const json_t *arguments,
-                      ANASTASIS_ActionCallback cb,
-                      void *cb_cls)
-{
-  json_t *new_state;
-  json_t *attributes = json_object_get (arguments, "identity");
-
-  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);
-  }
-
-  json_object_set_new (new_state,
-                       "identity_attributes",
-                       attributes);
-
-  cb (cb_cls,
-      ANASTASIS_EC_NONE,
-      new_state);
-  json_decref (new_state);
-}
-*/
-
 
 static void
 add_authentication (json_t *state,
@@ -154,7 +157,8 @@ add_authentication (json_t *state,
                     void *cb_cls)
 {
   json_t *method = json_object_get (arguments, "authentication_method");
-  GNUNET_assert (NULL != method);
+  GNUNET_assert (NULL != method); // FIXME: cb with error code (text: 
authentication_method required)
+  // FIXME: validate 'method' is well-formed!
   json_t *auth_method_arr = json_deep_copy (json_object_get (state,
                                                              
"authentication_methods"));
   if (NULL == auth_method_arr)
@@ -283,8 +287,8 @@ provider_candidate (struct PolicyBuilder *pb,
                                                     "method"));
   method_providers = json_object_get (pb->providers,
                                       method_name);
-  int num_prov = json_array_size (method_providers);
-  for (unsigned int j = 0; j < num_prov; j++)
+  size_t num_prov = json_array_size (method_providers);
+  for (size_t j = 0; j < num_prov; j++)
   {
     prov_sel[i] = j;
     if (i == pb->req_methods - 1)
@@ -542,6 +546,11 @@ ANASTASIS_backup_action (json_t *state,
       "next",
       &done_authentication
     },
+    {
+      AuthenticationsEditingState,
+      "back",
+      &ANASTASIS_back_generic_decrement_,
+    },
     { NoState, NULL, NULL }
   };
   const char *s = json_string_value (json_object_get (state,
@@ -553,10 +562,13 @@ ANASTASIS_backup_action (json_t *state,
         ANASTASIS_EC_INVALID, // FIXME: Define correct error code
         NULL);
   }
+  // FIXME: convert s to enum, if fails: call cb with error!
   for (unsigned int i = 0; NULL != dispatchers[i].fun; i++)
   {
-    if ( (0 == strcmp (s, STATE_STRING[dispatchers[i].backup_state])) &&
-         (0 == strcmp (action, dispatchers[i].backup_action)) )
+    if ( (0 == strcmp (s,
+                       STATE_STRING[dispatchers[i].backup_state])) &&
+         (0 == strcmp (action,
+                       dispatchers[i].backup_action)) )
     {
       dispatchers[i].fun (state, arguments, cb, cb_cls);
       return;
diff --git a/src/lib/anastasis_api_redux.c b/src/lib/anastasis_api_redux.c
index 847f371..dab178c 100644
--- a/src/lib/anastasis_api_redux.c
+++ b/src/lib/anastasis_api_redux.c
@@ -26,7 +26,7 @@
 #include "anastasis_redux.h"
 #include "anastasis_error_codes.h"
 #include <taler/taler_json_lib.h>
-
+#include "anastasis_api_redux.h"
 
 /**
  * Server information
@@ -176,16 +176,17 @@ config_cb (void *cls,
                 __LINE__);
     return;
   }
-  cs->server->backend_methods = methods;
+  cs->server->backend_methods = json_incref ((json_t *) methods);
   cs->server->backend_cost = *annual_fee;
   cs->server->backend_currency = GNUNET_malloc (strlen (conf_currency) + 1);
   GNUNET_strlcpy (cs->server->backend_currency,
                   conf_currency,
                   strlen (conf_currency) + 1);
 
-  if (0 == strcmp (cs->server->backend_currency,
+  if (0 != strcmp (cs->server->backend_currency,
                    json_string_value (json_object_get (cs->state,
                                                        "currency"))))
+    return;
   {
     json_t *method;
     size_t index;
@@ -274,7 +275,8 @@ config_cb (void *cls,
  * @param state_string
  * @return int
  */
-int get_enum_from_string (const char *state_string)
+int
+get_enum_from_string (const char *state_string)
 {
   for (unsigned int i = ContinentSelectionState; i != NoState; i++)
   {
@@ -289,17 +291,16 @@ int get_enum_from_string (const char *state_string)
  * Extract the mode of a state from json
  *
  * @param state the state to operate on
- * @return char*
+ * @return NULL on error
  */
-static
-char *get_state_mode (const json_t *state)
+static const 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"))
+  if (json_object_get (state, "recovery_state"))
     return "recovery_state";
-  else
-    return NULL;
+  return NULL;
 }
 
 
@@ -310,7 +311,7 @@ char *get_state_mode (const json_t *state)
  * @return json_t *
  */
 json_t *
-redux_countries_init ()
+ANASTASIS_redux_countries_init_ (void)
 {
   char *dn;
   json_error_t error;
@@ -319,14 +320,14 @@ redux_countries_init ()
   {
     char *path;
 
-    path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_PREFIX);
+    path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
     if (NULL == path)
     {
       GNUNET_break (0);
       return NULL;
     }
     GNUNET_asprintf (&dn,
-                     "%s/share/anastasis/redux.countries.json",
+                     "%s/redux.countries.json",
                      path);
     GNUNET_free (path);
   }
@@ -357,7 +358,7 @@ redux_countries_init ()
  * @return int
  */
 static int
-redux_id_attr_init (const char*country_code)
+redux_id_attr_init (const char *country_code)
 {
   char *dn;
   json_error_t error;
@@ -365,19 +366,21 @@ redux_id_attr_init (const char*country_code)
   {
     char *path;
 
-    path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_PREFIX);
+    path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
     if (NULL == path)
     {
       GNUNET_break (0);
       return GNUNET_SYSERR;
     }
     GNUNET_asprintf (&dn,
-                     "%s/share/anastasis/redux.%s.json",
+                     "%s/redux.%s.json",
                      path,
                      country_code);
     GNUNET_free (path);
   }
-  redux_id_attr = json_load_file (dn, JSON_COMPACT, &error);
+  redux_id_attr = json_load_file (dn,
+                                  JSON_COMPACT,
+                                  &error);
   if (NULL == redux_id_attr)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -452,7 +455,6 @@ select_country (json_t *state,
   const json_t *provider_list;
   char *dn;
   json_error_t error;
-  GNUNET_assert (NULL != state);
   json_t *country = json_object_get (arguments, "country_code");
   GNUNET_assert (NULL != country);
   currency = json_string_value (json_object_get (arguments,
@@ -464,23 +466,25 @@ select_country (json_t *state,
                  redux_id_attr_init (json_string_value (country)));
   root = json_object_get (redux_id_attr, "required_attributes");
   GNUNET_assert (NULL != root);
-  GNUNET_assert (0 == json_object_set_new (state,
-                                           s_mode,
-                                           json_string (
-                                             STATE_STRING[
-                                               
UserAttributesCollectionState])));
-
-  GNUNET_assert (0 == json_object_set_new (state,
-                                           "selected_country",
-                                           country));
-
-  GNUNET_assert (0 == json_object_set_new (state,
-                                           "currency",
-                                           json_string (currency)));
-
-  GNUNET_assert (0 == json_object_set_new (state,
-                                           "required_attributes",
-                                           root));
+  GNUNET_assert (0 ==
+                 json_object_set_new (
+                   state,
+                   s_mode,
+                   json_string (
+                     ANASTASIS_generic_state_to_string (
+                       ANASTASIS_GENERIC_STATE_USER_ATTRIBUTES_COLLECTION))));
+  GNUNET_assert (0 ==
+                 json_object_set_new (state,
+                                      "selected_country",
+                                      country));
+  GNUNET_assert (0 ==
+                 json_object_set_new (state,
+                                      "currency",
+                                      json_string (currency)));
+  GNUNET_assert (0 ==
+                 json_object_set_new (state,
+                                      "required_attributes",
+                                      root));
 
   // initialize provider list
   {
@@ -641,36 +645,20 @@ enter_user_attributes (json_t *state,
 }
 
 
-/**
- * Function which is called when we need to go a state backwards.
- * Sets state to previous state.
- *
- * @param[in,out] state input/output state (to be modified)
- * @param arguments normally unused
- * @param cb callback
- * @param cb_cls closure
- */
 void
-state_back (json_t *state,
-            const json_t *arguments,
-            ANASTASIS_ActionCallback cb,
-            void *cb_cls)
+ANASTASIS_back_generic_decrement_ (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 (NULL != s_mode); // FIXME: call cb with error!
   const char*state_string = json_string_value (json_object_get (state,
                                                                 s_mode));
-  GNUNET_assert (NULL != state_string);
-  int state_index = get_enum_from_string (state_string);
-  GNUNET_assert (GNUNET_SYSERR != state_index);
-
-  if (state_index == BackupPayingState + 1) // offset for recovery states
-  {
-    state_index = UserAttributesCollectionState;
-  }
-  else
-    state_index = state_index - 1;
+  GNUNET_assert (NULL != state_string); // FIXME: call cb with error!
+  enum ANASTASIS_BackupState state_index = get_enum_from_string (state_string);
+  GNUNET_assert (state_index > 0);
+  state_index = state_index - 1;
   GNUNET_assert (0 == json_object_set_new (state,
                                            s_mode,
                                            json_string (
@@ -692,8 +680,8 @@ state_back (json_t *state,
  * @param state input state
  * @param action what action to perform
  * @param arguments data for the @a action
- * @param cb function to call with the result
  * @param ctx Curl context
+ * @param cb function to call with the result
  * @param cb_cls closure for @a cb
  * @return failure state or new state
  */
@@ -701,18 +689,18 @@ void
 ANASTASIS_redux_action (const json_t *state,
                         const char *action,
                         const json_t *arguments,
-                        ANASTASIS_ActionCallback cb,
                         struct GNUNET_CURL_Context *ctx,
+                        ANASTASIS_ActionCallback cb,
                         void *cb_cls)
 {
   struct Dispatcher
   {
-    REDUX_STATE redux_state;
+    enum ANASTASIS_GenericState redux_state;
     const char *redux_action;
     DispatchHandler fun;
   } dispatchers[] = {
     {
-      ContinentSelectionState,
+      ANASTASIS_GENERIC_STATE_CONTINENT_SELECTION,
       "select_continent",
       &select_continent
     },
@@ -764,66 +752,75 @@ ANASTASIS_redux_action (const json_t *state,
     {
       AuthenticationsEditingState,
       "back",
-      &state_back
+      &ANASTASIS_back_generic_decrement_
     },
     { NoState, NULL, NULL }
   };
-  GNUNET_assert (NULL != state);
-  json_t *new_state;
-  const char *s_mode = "backup_state";
+  bool recovery_mode = false;
   const char *s = json_string_value (json_object_get (state,
                                                       "backup_state"));
+  enum ANASTASIS_GenericState gs;
+
   if (NULL == s)
   {
     s = json_string_value (json_object_get (state,
                                             "recovery_state"));
-    s_mode = "recovery_state";
+    recovery_mode = true;
     if (NULL == s)
     {
       GNUNET_break (0);
       cb (cb_cls,
           ANASTASIS_EC_INVALID, // FIXME: Define correct error code
           NULL);
-    }
-  }
-  if (NULL != ctx)
-    curl_ctx = ctx;
-  new_state = json_deep_copy (state);
-  GNUNET_assert (NULL != new_state);
-  for (unsigned int i = 0; NULL != dispatchers[i].fun; i++)
-  {
-    if ( (0 == strcmp (s, STATE_STRING[dispatchers[i].redux_state])) &&
-         (0 == strcmp (action, dispatchers[i].redux_action)) )
-    {
-      dispatchers[i].fun (new_state, arguments, cb, cb_cls);
-      json_decref (new_state);
       return;
     }
   }
-  if (0 == strcmp (s_mode, "backup_state"))
+  gs = ANASTASIS_generic_state_from_string (s);
+  if (ANASTASIS_GENERIC_STATE_ERROR == gs)
   {
-    ANASTASIS_backup_action (new_state,
-                             action,
-                             arguments,
-                             cb,
-                             NULL);
-    json_decref (new_state);
+    cb (cb_cls,
+        ANASTASIS_EC_INVALID, // FIXME: Define correct error code
+        NULL);
     return;
   }
+  if (NULL != ctx)
+    curl_ctx = ctx; // FIXME: pass as argument to 'fun'. NO GLOBALS!
 
-  if (0 == strcmp (s_mode, "recovery_state"))
   {
-    ANASTASIS_recovery_action (new_state,
+    json_t *new_state;
+
+    new_state = json_deep_copy (state);
+    GNUNET_assert (NULL != new_state);
+    for (unsigned int i = 0; NULL != dispatchers[i].fun; i++)
+    {
+      if ( (gs == dispatchers[i].redux_state) &&
+           (0 == strcmp (action,
+                         dispatchers[i].redux_action)) )
+      {
+        dispatchers[i].fun (new_state,
+                            arguments,
+                            cb,
+                            cb_cls);
+        json_decref (new_state);
+        return;
+      }
+    }
+    if (recovery_mode)
+    {
+      ANASTASIS_recovery_action (new_state, // FIXME: pass ctx!
+                                 action,
+                                 arguments,
+                                 cb,
+                                 NULL);
+    }
+    else
+    {
+      ANASTASIS_backup_action (new_state,
                                action,
                                arguments,
                                cb,
                                NULL);
+    }
     json_decref (new_state);
-    return;
   }
-  json_decref (new_state);
-  GNUNET_break (0);
-  cb (cb_cls,
-      ANASTASIS_EC_INVALID, // FIXME: Define correct error code
-      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]