gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 02/03: fix reducer cli


From: gnunet
Subject: [taler-anastasis] 02/03: fix reducer cli
Date: Thu, 29 Oct 2020 20:52:13 +0100

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

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

commit d83454ef46f1ac14eaa11e72bc5dd72cec20b6ee
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Thu Oct 29 20:46:25 2020 +0100

    fix reducer cli
---
 src/cli/anastasis-cli-redux.c          |  18 ++---
 src/include/anastasis_redux.h          |   2 +-
 src/lib/anastasis_api_backup_redux.c   | 141 ++++++++++++++++++++++++++++++---
 src/lib/anastasis_api_recovery_redux.c |  90 +++++++++++++++++++++
 src/lib/anastasis_api_redux.c          |  86 ++++++++++----------
 5 files changed, 271 insertions(+), 66 deletions(-)

diff --git a/src/cli/anastasis-cli-redux.c b/src/cli/anastasis-cli-redux.c
index e7ab8b2..c5d749b 100644
--- a/src/cli/anastasis-cli-redux.c
+++ b/src/cli/anastasis-cli-redux.c
@@ -104,16 +104,18 @@ persist_new_state (json_t *state,
     }
     return;
   }
-  if (-1 !=
+  char *state_str = json_dumps (state, JSON_COMPACT);
+  if (-1 >=
       fprintf (stdout,
                "%s",
-               json_dumps (state,
-                           JSON_COMPACT)))
+               state_str))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Could not dump state to stdout\n");
+    GNUNET_free (state_str);
     return;
   }
+  GNUNET_free (state_str);
 }
 
 
@@ -169,16 +171,6 @@ shutdown_task (void *cls)
     GNUNET_CURL_gnunet_rc_destroy (rc);
     rc = NULL;
   }
-  if (NULL != arguments)
-  {
-    json_decref (arguments);
-    arguments = NULL;
-  }
-  if (NULL != prev_state)
-  {
-    json_decref (prev_state);
-    prev_state = NULL;
-  }
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Shutdown complete\n");
 }
diff --git a/src/include/anastasis_redux.h b/src/include/anastasis_redux.h
index 7eeada0..27de17d 100644
--- a/src/include/anastasis_redux.h
+++ b/src/include/anastasis_redux.h
@@ -92,7 +92,7 @@ extern const char *currency;
  * Returns the enum value to a string value of a state.
  *
  * @param state_string
- * @return XXX on error
+ * @return #ANASTASIS_GENERIC_STATE_ERROR on error
  */
 enum ANASTASIS_GenericState
 ANASTASIS_generic_state_from_string (const char *state_string);
diff --git a/src/lib/anastasis_api_backup_redux.c 
b/src/lib/anastasis_api_backup_redux.c
index b380009..a1d1c1e 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -140,7 +140,6 @@ ANASTASIS_backup_start (const struct 
GNUNET_CONFIGURATION_Handle *cfg)
       json_array_append_new (continents,
                              continent);
   }
-
   initial_state = json_pack ("{s:s, s:o}",
                              "backup_state",
                              ANASTASIS_generic_state_to_string (
@@ -162,15 +161,16 @@ add_authentication (json_t *state,
   json_t *method = json_object_get (arguments, "authentication_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"));
+  json_t *auth_method_arr = json_object_get (state,
+                                             "authentication_methods");
   if (NULL == auth_method_arr)
     auth_method_arr = json_array ();
   GNUNET_assert (NULL != auth_method_arr);
   GNUNET_assert (0 == json_array_append_new (auth_method_arr, method));
-  GNUNET_assert (0 == json_object_set_new (state,
-                                           "authentication_methods",
-                                           auth_method_arr));
+  GNUNET_assert (0 == json_object_set (state,
+                                       "authentication_methods",
+                                       auth_method_arr));
+
   cb (cb_cls,
       ANASTASIS_EC_NONE,
       state);
@@ -223,10 +223,6 @@ eval_provider_selection (struct PolicyBuilder *pb,
                                            prov_sel[i]);
     void *provider_obj_iter = json_object_iter (provider_obj);
     const char *provider_name = json_object_iter_key (provider_obj_iter);
-    json_t *policy_method = json_pack ("{s:i, s:s}",
-                                       "authentication_method", pb->m_idx[i],
-                                       "provider", provider_name);
-
     struct TALER_Amount method_cost;
     json_t *provider_data = json_object_get (provider_obj, provider_name);
 
@@ -264,7 +260,9 @@ eval_provider_selection (struct PolicyBuilder *pb,
 
   if (curr_diversity < pb->best_diversity)
     better = false;
-  else if (0 < TALER_amount_cmp (&curr_cost, &pb->best_cost))
+  else if ((GNUNET_YES == TALER_amount_cmp_currency (&curr_cost,
+                                                     &pb->best_cost))
+           && (0 < TALER_amount_cmp (&curr_cost, &pb->best_cost)))
     better = false;
 
   if (better)
@@ -511,6 +509,85 @@ add_policy (json_t *state,
             ANASTASIS_ActionCallback cb,
             void *cb_cls)
 {
+  // FIXME: implement
+  cb (cb_cls,
+      ANASTASIS_EC_NONE,
+      state);
+  return NULL;
+}
+
+
+static struct ANASTASIS_ReduxAction *
+del_policy (json_t *state,
+            const json_t *arguments,
+            struct GNUNET_CURL_Context *ctx,
+            ANASTASIS_ActionCallback cb,
+            void *cb_cls)
+{
+  // FIXME: implement
+  cb (cb_cls,
+      ANASTASIS_EC_NONE,
+      state);
+  return NULL;
+}
+
+
+static struct ANASTASIS_ReduxAction *
+done_policy_review (json_t *state,
+                    const json_t *arguments,
+                    struct GNUNET_CURL_Context *ctx,
+                    ANASTASIS_ActionCallback cb,
+                    void *cb_cls)
+{
+  // FIXME: implement
+  cb (cb_cls,
+      ANASTASIS_EC_NONE,
+      state);
+  return NULL;
+}
+
+
+static struct ANASTASIS_ReduxAction *
+enter_secret (json_t *state,
+              const json_t *arguments,
+              struct GNUNET_CURL_Context *ctx,
+              ANASTASIS_ActionCallback cb,
+              void *cb_cls)
+{
+  // FIXME: implement
+  cb (cb_cls,
+      ANASTASIS_EC_NONE,
+      state);
+  return NULL;
+}
+
+
+static struct ANASTASIS_ReduxAction *
+pay_policy (json_t *state,
+            const json_t *arguments,
+            struct GNUNET_CURL_Context *ctx,
+            ANASTASIS_ActionCallback cb,
+            void *cb_cls)
+{
+  // FIXME: implement
+  cb (cb_cls,
+      ANASTASIS_EC_NONE,
+      state);
+  return NULL;
+}
+
+
+static struct ANASTASIS_ReduxAction *
+back_finished (json_t *state,
+               const json_t *arguments,
+               struct GNUNET_CURL_Context *ctx,
+               ANASTASIS_ActionCallback cb,
+               void *cb_cls)
+{
+  // FIXME: implement
+  cb (cb_cls,
+      ANASTASIS_EC_NONE,
+      state);
   return NULL;
 }
 
@@ -560,7 +637,47 @@ ANASTASIS_backup_action_ (struct GNUNET_CURL_Context *ctx,
     {
       ANASTASIS_BACKUP_STATE_AUTHENTICATIONS_EDITING,
       "back",
-      &ANASTASIS_back_generic_decrement_,
+      &ANASTASIS_back_generic_decrement_
+    },
+    {
+      ANASTASIS_BACKUP_STATE_POLICIES_REVIEWING,
+      "add_policy",
+      &add_policy
+    },
+    {
+      ANASTASIS_BACKUP_STATE_POLICIES_REVIEWING,
+      "delete_policy",
+      &del_policy
+    },
+    {
+      ANASTASIS_BACKUP_STATE_POLICIES_REVIEWING,
+      "next",
+      &done_policy_review
+    },
+    {
+      ANASTASIS_BACKUP_STATE_POLICIES_REVIEWING,
+      "back",
+      &ANASTASIS_back_generic_decrement_
+    },
+    {
+      ANASTASIS_BACKUP_STATE_SECRET_EDITING,
+      "enter_secret",
+      &enter_secret
+    },
+    {
+      ANASTASIS_BACKUP_STATE_SECRET_EDITING,
+      "back",
+      &ANASTASIS_back_generic_decrement_
+    },
+    {
+      ANASTASIS_BACKUP_STATE_POLICIES_PAYING,
+      "pay",
+      &pay_policy
+    },
+    {
+      ANASTASIS_BACKUP_STATE_FINISHED,
+      "back",
+      &back_finished
     },
     { ANASTASIS_BACKUP_STATE_ERROR, NULL, NULL }
   };
diff --git a/src/lib/anastasis_api_recovery_redux.c 
b/src/lib/anastasis_api_recovery_redux.c
index f9c2649..c76aa57 100644
--- a/src/lib/anastasis_api_recovery_redux.c
+++ b/src/lib/anastasis_api_recovery_redux.c
@@ -138,6 +138,66 @@ ANASTASIS_recovery_start (const struct 
GNUNET_CONFIGURATION_Handle *cfg)
 }
 
 
+static struct ANASTASIS_ReduxAction *
+select_challenge (json_t *state,
+                  const json_t *arguments,
+                  struct GNUNET_CURL_Context *ctx,
+                  ANASTASIS_ActionCallback cb,
+                  void *cb_cls)
+{
+  // FIXME: implement
+  cb (cb_cls,
+      ANASTASIS_EC_NONE,
+      state);
+  return NULL;
+}
+
+
+static struct ANASTASIS_ReduxAction *
+pay_challenge (json_t *state,
+               const json_t *arguments,
+               struct GNUNET_CURL_Context *ctx,
+               ANASTASIS_ActionCallback cb,
+               void *cb_cls)
+{
+  // FIXME: implement
+  cb (cb_cls,
+      ANASTASIS_EC_NONE,
+      state);
+  return NULL;
+}
+
+
+static struct ANASTASIS_ReduxAction *
+solve_challenge (json_t *state,
+                 const json_t *arguments,
+                 struct GNUNET_CURL_Context *ctx,
+                 ANASTASIS_ActionCallback cb,
+                 void *cb_cls)
+{
+  // FIXME: implement
+  cb (cb_cls,
+      ANASTASIS_EC_NONE,
+      state);
+  return NULL;
+}
+
+
+static struct ANASTASIS_ReduxAction *
+back_challenge_solving (json_t *state,
+                        const json_t *arguments,
+                        struct GNUNET_CURL_Context *ctx,
+                        ANASTASIS_ActionCallback cb,
+                        void *cb_cls)
+{
+  // FIXME: implement
+  cb (cb_cls,
+      ANASTASIS_EC_NONE,
+      state);
+  return NULL;
+}
+
+
 /**
  * Operates on a recovery state depending on given #ANASTASIS_RecoveryState
  * and #ANASTASIS_RecoveryAction. The new #ANASTASIS_RecoveryState is returned
@@ -165,6 +225,36 @@ ANASTASIS_recovery_action_ (struct GNUNET_CURL_Context 
*ctx,
     const char *recovery_action;
     DispatchHandler fun;
   } dispatchers[] = {
+    {
+      ANASTASIS_RECOVERY_STATE_CHALLENGE_SELECTING,
+      "select_challenge",
+      &select_challenge
+    },
+    {
+      ANASTASIS_RECOVERY_STATE_CHALLENGE_SELECTING,
+      "back",
+      &ANASTASIS_back_generic_decrement_
+    },
+    {
+      ANASTASIS_RECOVERY_STATE_CHALLENGE_PAYING,
+      "pay",
+      &pay_challenge
+    },
+    {
+      ANASTASIS_RECOVERY_STATE_CHALLENGE_PAYING,
+      "back",
+      &ANASTASIS_back_generic_decrement_
+    },
+    {
+      ANASTASIS_RECOVERY_STATE_CHALLENGE_SOLVING,
+      "solve_challenge",
+      &solve_challenge
+    },
+    {
+      ANASTASIS_RECOVERY_STATE_CHALLENGE_SOLVING,
+      "back",
+      &back_challenge_solving
+    },
     { ANASTASIS_RECOVERY_STATE_ERROR, NULL, NULL }
   };
   const char *s = json_string_value (json_object_get (state,
diff --git a/src/lib/anastasis_api_redux.c b/src/lib/anastasis_api_redux.c
index 3561082..b362a3c 100644
--- a/src/lib/anastasis_api_redux.c
+++ b/src/lib/anastasis_api_redux.c
@@ -245,15 +245,11 @@ add_config_to_state (struct ConfigRequest *cr,
                                           method_type,
                                           ma_arr = json_array ()));
     }
-    prov = json_pack ("{s:o}",
+    prov = json_pack ("{s:o, s:o, s:s, s:s}",
+                      // FIXME: add insurance here...
                       "method_cost",
                       json_object_get (method,
-                                       "cost"));
-    GNUNET_assert (0 == json_object_set_new (ma,
-                                             cr->backend_id,
-                                             prov));
-    prov = json_pack ("{s:o, s:s, s:s}",
-                      // FIXME: add insurance here...
+                                       "cost"),
                       "annual_cost",
                       TALER_JSON_from_amount (&cr->backend_cost),
                       "provider_url",
@@ -298,7 +294,7 @@ conclude_select_country (struct SelectCountryHandle *sch)
   sch->cb (NULL,
            ANASTASIS_EC_NONE,
            sch->state);
-  free_select_country (sch);
+  // free_select_country (sch);
 }
 
 
@@ -524,7 +520,7 @@ select_country (json_t *state,
                 void *cb_cls)
 {
   json_t *root;
-  const json_t *provider_list;
+  json_t *provider_list;
   char *dn;
   json_error_t error;
   json_t *country;
@@ -599,7 +595,6 @@ select_country (json_t *state,
     json_t *provider;
     json_t *provider_arr = json_object_get (provider_list,
                                             "anastasis_provider");
-
     sch = GNUNET_new (struct SelectCountryHandle);
     sch->cb = cb;
     sch->cb_cls = cb_cls;
@@ -743,21 +738,36 @@ ANASTASIS_back_generic_decrement_ (json_t *state,
                                    ANASTASIS_ActionCallback cb,
                                    void *cb_cls)
 {
+  enum ANASTASIS_BackupState state_index;
   const char *s_mode = get_state_mode (state);
   GNUNET_assert (NULL != s_mode); // FIXME: call cb with error!
-  const char*state_string = json_string_value (json_object_get (state,
-                                                                s_mode));
+  const char *state_string = json_string_value (json_object_get (state,
+                                                                 s_mode));
   GNUNET_assert (NULL != state_string); // FIXME: call cb with error!
-  enum ANASTASIS_BackupState state_index = ANASTASIS_generic_state_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 (
-                     ANASTASIS_generic_state_to_string (state_index))));
+  if (0 == strcmp ("backup_state", s_mode))
+  {
+    state_index = ANASTASIS_backup_state_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 (
+                       ANASTASIS_generic_state_to_string (state_index))));
+  }
+  else
+  {
+    state_index = ANASTASIS_recovery_state_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 (
+                       ANASTASIS_generic_state_to_string (state_index))));
+  }
   cb (cb_cls,
       ANASTASIS_EC_NONE,
       state);
@@ -847,32 +857,28 @@ ANASTASIS_redux_action (const json_t *state,
     }
   }
   gs = ANASTASIS_generic_state_from_string (s);
-  if (ANASTASIS_GENERIC_STATE_ERROR == gs)
-  {
-    cb (cb_cls,
-        ANASTASIS_EC_INVALID, // FIXME: Define correct error code
-        NULL);
-    return NULL;
-  }
   {
     json_t *new_state;
     struct ANASTASIS_ReduxAction *ret;
 
     new_state = json_deep_copy (state);
     GNUNET_assert (NULL != new_state);
-    for (unsigned int i = 0; NULL != dispatchers[i].fun; i++)
+    if (gs != ANASTASIS_GENERIC_STATE_ERROR)
     {
-      if ( (gs == dispatchers[i].redux_state) &&
-           (0 == strcmp (action,
-                         dispatchers[i].redux_action)) )
+      for (unsigned int i = 0; NULL != dispatchers[i].fun; i++)
       {
-        ret = dispatchers[i].fun (new_state,
-                                  arguments,
-                                  ctx,
-                                  cb,
-                                  cb_cls);
-        json_decref (new_state);
-        return ret;
+        if ( (gs == dispatchers[i].redux_state) &&
+             (0 == strcmp (action,
+                           dispatchers[i].redux_action)) )
+        {
+          ret = dispatchers[i].fun (new_state,
+                                    arguments,
+                                    ctx,
+                                    cb,
+                                    cb_cls);
+          json_decref (new_state);
+          return ret;
+        }
       }
     }
     if (recovery_mode)

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