gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 03/08: reducer - better error handling


From: gnunet
Subject: [taler-anastasis] 03/08: reducer - better error handling
Date: Fri, 06 Nov 2020 18:06:28 +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 dd798ccd0e50dd5a81e111ef0b3445ba32acca12
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Tue Nov 3 14:47:48 2020 +0100

    reducer - better error handling
---
 src/lib/anastasis_api_backup_redux.c | 273 +++++++++++++++++++++++++++++++++--
 src/lib/anastasis_api_config.c       |   1 -
 2 files changed, 258 insertions(+), 16 deletions(-)

diff --git a/src/lib/anastasis_api_backup_redux.c 
b/src/lib/anastasis_api_backup_redux.c
index 070f44e..72cf67a 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -92,8 +92,9 @@ set_state (json_t *state,
 
 
 /**
- * Returns an initial ANASTASIS backup state.
+ * Returns an initial ANASTASIS backup state (CONTINENT_SELECTING).
  *
+ * @param cfg handle for gnunet configuration
  * @return NULL on failure
  */
 json_t *
@@ -151,6 +152,18 @@ ANASTASIS_backup_start (const struct 
GNUNET_CONFIGURATION_Handle *cfg)
 }
 
 
+/**
+ * DispatchHandler/Callback function which is called for a
+ * "add_authentication" action.
+ * Returns an #ANASTASIS_ReduxAction if operation is async.
+ *
+ * @param state state to operate on
+ * @param arguments arguments to use for operation on state
+ * @param ctx CURL context
+ * @param cb callback (#DispatchHandler) to call during/after operation
+ * @param cb_cls callback closure
+ * @return NULL
+ */
 static struct ANASTASIS_ReduxAction *
 add_authentication (json_t *state,
                     const json_t *arguments,
@@ -158,9 +171,52 @@ add_authentication (json_t *state,
                     ANASTASIS_ActionCallback cb,
                     void *cb_cls)
 {
+  json_t *auth_providers = json_object_get (arguments,
+                                            "authentication_providers");
+
+  GNUNET_assert (NULL != auth_providers);
   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!
+
+  if (NULL == method)
+  {
+    json_t *error = json_pack ("{s:I, s:s}",
+                               "code",
+                               (json_int_t) ANASTASIS_EC_INVALID,
+                               "hint",
+                               "Authentication method required!");
+    cb (cb_cls,
+        ANASTASIS_EC_INVALID,
+        error);
+    return NULL;
+  }
+  const char *method_type = json_string_value (json_object_get (method,
+                                                                "method"));
+  if (! json_object_get (auth_providers,
+                         method_type))
+  {
+    json_t *error = json_pack ("{s:I, s:s}",
+                               "code",
+                               (json_int_t) ANASTASIS_EC_PARAMETER_MALFORMED,
+                               "hint",
+                               "Authentication method not supported!");
+    cb (cb_cls,
+        ANASTASIS_EC_INVALID,
+        error);
+    return NULL;
+  }
+  if (! json_object_get (method,
+                         "data"))
+  {
+    json_t *error = json_pack ("{s:I, s:s}",
+                               "code",
+                               (json_int_t) ANASTASIS_EC_PARAMETER_MALFORMED,
+                               "hint",
+                               "Authentication data missing!");
+    cb (cb_cls,
+        ANASTASIS_EC_INVALID,
+        error);
+    return NULL;
+  }
   json_t *auth_method_arr = json_object_get (state,
                                              "authentication_methods");
   if (NULL == auth_method_arr)
@@ -170,7 +226,6 @@ add_authentication (json_t *state,
   GNUNET_assert (0 == json_object_set (state,
                                        "authentication_methods",
                                        auth_method_arr));
-
   cb (cb_cls,
       ANASTASIS_EC_NONE,
       state);
@@ -399,6 +454,18 @@ method_candidate (struct PolicyBuilder *pb,
 }
 
 
+/**
+ * DispatchHandler/Callback function which is called for a
+ * "done_authentication" action.
+ * Returns an #ANASTASIS_ReduxAction if operation is async.
+ *
+ * @param state state to operate on
+ * @param arguments arguments to use for operation on state
+ * @param ctx CURL context
+ * @param cb callback (#DispatchHandler) to call during/after operation
+ * @param cb_cls callback closure
+ * @return NULL
+ */
 static struct ANASTASIS_ReduxAction *
 done_authentication (json_t *state,
                      const json_t *arguments,
@@ -454,6 +521,18 @@ done_authentication (json_t *state,
 }
 
 
+/**
+ * DispatchHandler/Callback function which is called for a
+ * "del_authentication" action.
+ * Returns an #ANASTASIS_ReduxAction if operation is async.
+ *
+ * @param state state to operate on
+ * @param arguments arguments to use for operation on state
+ * @param ctx CURL context
+ * @param cb callback (#DispatchHandler) to call during/after operation
+ * @param cb_cls callback closure
+ * @return NULL
+ */
 static struct ANASTASIS_ReduxAction *
 del_authentication (json_t *state,
                     const json_t *arguments,
@@ -461,7 +540,18 @@ del_authentication (json_t *state,
                     ANASTASIS_ActionCallback cb,
                     void *cb_cls)
 {
-  GNUNET_assert (NULL != arguments);
+  if (NULL == arguments)
+  {
+    json_t *error = json_pack ("{s:I, s:s}",
+                               "code",
+                               (json_int_t) ANASTASIS_EC_INVALID,
+                               "hint",
+                               "Arguments missing!");
+    cb (cb_cls,
+        ANASTASIS_EC_INVALID,
+        error);
+    return NULL;
+  }
   size_t index = (size_t) json_integer_value (
     json_object_get (arguments,
                      "auth_method_index"));
@@ -489,6 +579,18 @@ del_authentication (json_t *state,
 }
 
 
+/**
+ * DispatchHandler/Callback function which is called for a
+ * "add_policy" action.
+ * Returns an #ANASTASIS_ReduxAction if operation is async.
+ *
+ * @param state state to operate on
+ * @param arguments arguments to use for operation on state
+ * @param ctx CURL context
+ * @param cb callback (#DispatchHandler) to call during/after operation
+ * @param cb_cls callback closure
+ * @return NULL
+ */
 static struct ANASTASIS_ReduxAction *
 add_policy (json_t *state,
             const json_t *arguments,
@@ -496,6 +598,19 @@ add_policy (json_t *state,
             ANASTASIS_ActionCallback cb,
             void *cb_cls)
 {
+  if (NULL == arguments)
+  {
+    json_t *error = json_pack ("{s:I, s:s}",
+                               "code",
+                               (json_int_t) ANASTASIS_EC_INVALID,
+                               "hint",
+                               "Arguments missing!");
+    cb (cb_cls,
+        ANASTASIS_EC_INVALID,
+        error);
+    return NULL;
+  }
+
   size_t index;
   json_t *method;
   struct TALER_Amount recovery_cost;
@@ -511,8 +626,18 @@ add_policy (json_t *state,
   GNUNET_assert (json_is_array (policies));
   json_t *arg_array = json_object_get (arguments,
                                        "policy");
-
-  GNUNET_assert (json_is_array (arg_array));
+  if (! json_is_array (arg_array))
+  {
+    json_t *error = json_pack ("{s:I, s:s}",
+                               "code",
+                               (json_int_t) ANASTASIS_EC_PARAMETER_MALFORMED,
+                               "hint",
+                               "Policy is malformed!");
+    cb (cb_cls,
+        ANASTASIS_EC_INVALID,
+        error);
+    return NULL;
+  }
   GNUNET_assert (GNUNET_OK ==
                  TALER_amount_get_zero (
                    json_string_value (json_object_get (state,
@@ -589,6 +714,18 @@ add_policy (json_t *state,
 }
 
 
+/**
+ * DispatchHandler/Callback function which is called for a
+ * "del_policy" action.
+ * Returns an #ANASTASIS_ReduxAction if operation is async.
+ *
+ * @param state state to operate on
+ * @param arguments arguments to use for operation on state
+ * @param ctx CURL context
+ * @param cb callback (#DispatchHandler) to call during/after operation
+ * @param cb_cls callback closure
+ * @return NULL
+ */
 static struct ANASTASIS_ReduxAction *
 del_policy (json_t *state,
             const json_t *arguments,
@@ -596,7 +733,19 @@ del_policy (json_t *state,
             ANASTASIS_ActionCallback cb,
             void *cb_cls)
 {
-  GNUNET_assert (NULL != arguments);
+  if (NULL == arguments)
+  {
+    json_t *error = json_pack ("{s:I, s:s}",
+                               "code",
+                               (json_int_t) ANASTASIS_EC_INVALID,
+                               "hint",
+                               "Arguments missing!");
+    cb (cb_cls,
+        ANASTASIS_EC_INVALID,
+        error);
+    return NULL;
+  }
+
   size_t index = (size_t) json_integer_value (
     json_object_get (arguments,
                      "policy_index"));
@@ -623,6 +772,18 @@ del_policy (json_t *state,
 }
 
 
+/**
+ * DispatchHandler/Callback function which is called for a
+ * "done_policy_review" action.
+ * Returns an #ANASTASIS_ReduxAction if operation is async.
+ *
+ * @param state state to operate on
+ * @param arguments arguments to use for operation on state
+ * @param ctx CURL context
+ * @param cb callback (#DispatchHandler) to call during/after operation
+ * @param cb_cls callback closure
+ * @return NULL
+ */
 static struct ANASTASIS_ReduxAction *
 done_policy_review (json_t *state,
                     const json_t *arguments,
@@ -630,7 +791,11 @@ done_policy_review (json_t *state,
                     ANASTASIS_ActionCallback cb,
                     void *cb_cls)
 {
-  // FIXME: implement
+  GNUNET_assert (NULL != state);
+  set_state (state,
+             ANASTASIS_backup_state_to_string (
+               ANASTASIS_BACKUP_STATE_SECRET_EDITING));
+
   cb (cb_cls,
       ANASTASIS_EC_NONE,
       state);
@@ -638,6 +803,18 @@ done_policy_review (json_t *state,
 }
 
 
+/**
+ * DispatchHandler/Callback function which is called for a
+ * "enter_secret" action.
+ * Returns an #ANASTASIS_ReduxAction if operation is async.
+ *
+ * @param state state to operate on
+ * @param arguments arguments to use for operation on state
+ * @param ctx CURL context
+ * @param cb callback (#DispatchHandler) to call during/after operation
+ * @param cb_cls callback closure
+ * @return NULL
+ */
 static struct ANASTASIS_ReduxAction *
 enter_secret (json_t *state,
               const json_t *arguments,
@@ -645,15 +822,41 @@ enter_secret (json_t *state,
               ANASTASIS_ActionCallback cb,
               void *cb_cls)
 {
-  GNUNET_assert (NULL != arguments);
-  GNUNET_assert (NULL != json_object_get (arguments,
-                                          "secret"));
-  GNUNET_assert (NULL != json_object_get (arguments,
-                                          "type"));
+  if (NULL == arguments)
+  {
+    json_t *error = json_pack ("{s:I, s:s}",
+                               "code",
+                               (json_int_t) ANASTASIS_EC_INVALID,
+                               "hint",
+                               "Arguments missing!");
+    cb (cb_cls,
+        ANASTASIS_EC_INVALID,
+        error);
+    return NULL;
+  }
+  GNUNET_assert (NULL != state);
+
+  if ((NULL == json_object_get (arguments,"secret"))
+      || (NULL == json_object_get (arguments, "type")))
+  {
+    json_t *error = json_pack ("{s:I, s:s}",
+                               "code",
+                               (json_int_t) ANASTASIS_EC_PARAMETER_MALFORMED,
+                               "hint",
+                               "Secret is malformed!");
+    cb (cb_cls,
+        ANASTASIS_EC_INVALID,
+        error);
+    return NULL;
+  }
   GNUNET_assert (0 ==
                  json_object_set_new (state,
                                       "core_secret",
                                       arguments));
+  set_state (state,
+             ANASTASIS_backup_state_to_string (
+               ANASTASIS_BACKUP_STATE_POLICIES_PAYING));
+
   cb (cb_cls,
       ANASTASIS_EC_NONE,
       state);
@@ -661,6 +864,18 @@ enter_secret (json_t *state,
 }
 
 
+/**
+ * DispatchHandler/Callback function which is called for a
+ * "pay_policy" action.
+ * Returns an #ANASTASIS_ReduxAction if operation is async.
+ *
+ * @param state state to operate on
+ * @param arguments arguments to use for operation on state
+ * @param ctx CURL context
+ * @param cb callback (#DispatchHandler) to call during/after operation
+ * @param cb_cls callback closure
+ * @return NULL
+ */
 static struct ANASTASIS_ReduxAction *
 pay_policy (json_t *state,
             const json_t *arguments,
@@ -668,7 +883,18 @@ pay_policy (json_t *state,
             ANASTASIS_ActionCallback cb,
             void *cb_cls)
 {
-  GNUNET_assert (NULL != arguments);
+  if (NULL == arguments)
+  {
+    json_t *error = json_pack ("{s:I, s:s}",
+                               "code",
+                               (json_int_t) ANASTASIS_EC_INVALID,
+                               "hint",
+                               "Arguments missing!");
+    cb (cb_cls,
+        ANASTASIS_EC_INVALID,
+        error);
+    return NULL;
+  }
   // FIXME: implement
   cb (cb_cls,
       ANASTASIS_EC_NONE,
@@ -677,6 +903,18 @@ pay_policy (json_t *state,
 }
 
 
+/**
+ * DispatchHandler/Callback function which is called for a
+ * "back" action if state is "FINISHED".
+ * Returns an #ANASTASIS_ReduxAction if operation is async.
+ *
+ * @param state state to operate on
+ * @param arguments arguments to use for operation on state
+ * @param ctx CURL context
+ * @param cb callback (#DispatchHandler) to call during/after operation
+ * @param cb_cls callback closure
+ * @return NULL
+ */
 static struct ANASTASIS_ReduxAction *
 back_finished (json_t *state,
                const json_t *arguments,
@@ -685,6 +923,11 @@ back_finished (json_t *state,
                void *cb_cls)
 {
   // FIXME: implement
+  GNUNET_assert (NULL != state);
+  set_state (state,
+             ANASTASIS_backup_state_to_string (
+               ANASTASIS_BACKUP_STATE_SECRET_EDITING));
+
   cb (cb_cls,
       ANASTASIS_EC_NONE,
       state);
diff --git a/src/lib/anastasis_api_config.c b/src/lib/anastasis_api_config.c
index aa46908..febe420 100644
--- a/src/lib/anastasis_api_config.c
+++ b/src/lib/anastasis_api_config.c
@@ -112,7 +112,6 @@ handle_config_finished (void *cls,
         GNUNET_JSON_spec_string ("currency", &co->currency),
         TALER_JSON_spec_amount ("annual_fee", &co->cost),
         TALER_JSON_spec_amount ("insurance", &co->insurance),
-        // FIXME add configs
         GNUNET_JSON_spec_end ()
       };
 

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