gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated (fe988cb -> ed2ce87)


From: gnunet
Subject: [taler-anastasis] branch master updated (fe988cb -> ed2ce87)
Date: Sun, 18 Oct 2020 20:49:47 +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 fe988cb  rework anastasis-cli-redux to support redirections
     new b011c67  pass ctx as argument
     new 546bd10  fix enum
     new ed2ce87  fix loop

The 3 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/cli/anastasis-cli-redux.c          | 76 ++++++++++++++++++++--------------
 src/include/anastasis_redux.h          | 13 +++---
 src/lib/anastasis_api_backup_redux.c   | 17 +++++---
 src/lib/anastasis_api_recovery_redux.c | 11 +++--
 src/lib/anastasis_api_redux.c          | 48 ++++++++++++++-------
 src/lib/anastasis_api_redux.h          |  1 +
 6 files changed, 104 insertions(+), 62 deletions(-)

diff --git a/src/cli/anastasis-cli-redux.c b/src/cli/anastasis-cli-redux.c
index 57a76e4..5fc37d3 100644
--- a/src/cli/anastasis-cli-redux.c
+++ b/src/cli/anastasis-cli-redux.c
@@ -78,9 +78,14 @@ static json_t *arguments;
  */
 static char *action;
 
+/**
+ * Handle to an ongoing action.
+ */
+static struct ANASTASIS_ReduxAction *ra;
+
 /**
  * Persist a json state.
- * 
+ *
  * @param state to persist
  * @return 0 if operation failed
  */
@@ -105,15 +110,15 @@ action_cb (void *cls,
            json_t *result_state)
 {
   new_state = result_state;
-  
+
   if (NULL != new_state)
   {
     if (! isatty (STDOUT_FILENO))
     {
-      fprintf (stdout, 
-              "%s",
-              json_dumps (new_state,
-                          JSON_COMPACT));
+      fprintf (stdout,
+               "%s",
+               json_dumps (new_state,
+                           JSON_COMPACT));
     }
     else
     {
@@ -139,11 +144,21 @@ shutdown_task (void *cls)
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Shutdown initiated\n");
   // FIXME shutdown routine here
+  if (NULL != ctx)
+  {
+    GNUNET_CURL_fini (ctx);
+    ctx = NULL;
+  }
   if (NULL != rc)
   {
     GNUNET_CURL_gnunet_rc_destroy (rc);
     rc = NULL;
   }
+  if (NULL != ra)
+  {
+    GNUNET_free (ra);
+    ra = NULL;
+  }
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Shutdown complete\n");
@@ -180,8 +195,8 @@ run (void *cls,
                  GNUNET_log_setup ("anastasis-reducer",
                                    "WARNING",
                                    NULL));
-  
-  
+
+
   if (r_flag ^ b_flag)
   {
     json_t *init_state;
@@ -230,9 +245,9 @@ run (void *cls,
       else
       {
         fprintf (stderr,
-          "Please give a path to store initial json state!\n");
+                 "Please give a path to store initial json state!\n");
         fprintf (stderr,
-          "Example: anastasis-reducer -b init_state.json\n");
+                 "Example: anastasis-reducer -b init_state.json\n");
         GNUNET_SCHEDULER_shutdown ();
         return;
       }
@@ -240,9 +255,9 @@ run (void *cls,
     else
     {
       fprintf (stdout,
-                "%s",
-                json_dumps (init_state,
-                            JSON_COMPACT));
+               "%s",
+               json_dumps (init_state,
+                           JSON_COMPACT));
       return; // success!
     }
   }
@@ -293,7 +308,7 @@ run (void *cls,
           GNUNET_SCHEDULER_shutdown ();
           return;
         }
-        char *prev_state_str = NULL; 
+        char *prev_state_str = NULL;
         size_t size;
         if (getline (&prev_state_str,
                      &size,
@@ -319,9 +334,9 @@ run (void *cls,
       else
       {
         fprintf (stderr,
-                   "Please give arguments!\n");
+                 "Please give arguments!\n");
         fprintf (stderr,
-                  "Example: anastasis-reducer -a '{\"continent\":\"Europe\"}' 
select-continent < prev_state.json > new_state.json\n");
+                 "Example: anastasis-reducer -a '{\"continent\":\"Europe\"}' 
select-continent < prev_state.json > new_state.json\n");
         GNUNET_SCHEDULER_shutdown ();
         return;
       }
@@ -333,9 +348,9 @@ run (void *cls,
       else
       {
         fprintf (stderr,
-          "Please give path for json containing previous state!\n");
+                 "Please give path for json containing previous state!\n");
         fprintf (stderr,
-          "Example: anastasis-reducer prev.json action arguments.json 
new.json\n");
+                 "Example: anastasis-reducer prev.json action arguments.json 
new.json\n");
         GNUNET_SCHEDULER_shutdown ();
         return;
       }
@@ -345,9 +360,9 @@ run (void *cls,
       else
       {
         fprintf (stderr,
-          "Please give an action!\n");
+                 "Please give an action!\n");
         fprintf (stderr,
-          "Example: anastasis-reducer prev.json action arguments.json 
new.json\n");
+                 "Example: anastasis-reducer prev.json action arguments.json 
new.json\n");
         GNUNET_SCHEDULER_shutdown ();
         return;
       }
@@ -357,9 +372,9 @@ run (void *cls,
       else
       {
         fprintf (stderr,
-          "Please give path for json containing arguments for action!\n");
+                 "Please give path for json containing arguments for 
action!\n");
         fprintf (stderr,
-          "Example: anastasis-reducer prev.json action arguments.json 
new.json\n");
+                 "Example: anastasis-reducer prev.json action arguments.json 
new.json\n");
         GNUNET_SCHEDULER_shutdown ();
         return;
       }
@@ -369,9 +384,9 @@ run (void *cls,
       else
       {
         fprintf (stderr,
-          "Please give path for json containing new state!\n");
+                 "Please give path for json containing new state!\n");
         fprintf (stderr,
-          "Example: anastasis-reducer prev.json action arguments.json 
new.json\n");
+                 "Example: anastasis-reducer prev.json action arguments.json 
new.json\n");
         GNUNET_SCHEDULER_shutdown ();
         return;
       }
@@ -381,13 +396,12 @@ run (void *cls,
                             &rc);
     rc = GNUNET_CURL_gnunet_rc_create (ctx);
 
-    // FIXME: return value in global, shutdown handler to clean up, yada yada
-    ANASTASIS_redux_action (prev_state,
-                            action,
-                            arguments,
-                            ctx,
-                            &action_cb,
-                            cls);
+    ra = ANASTASIS_redux_action (prev_state,
+                                 action,
+                                 arguments,
+                                 ctx,
+                                 &action_cb,
+                                 cls);
   }
 }
 
diff --git a/src/include/anastasis_redux.h b/src/include/anastasis_redux.h
index b11ba9c..c0de517 100644
--- a/src/include/anastasis_redux.h
+++ b/src/include/anastasis_redux.h
@@ -41,14 +41,13 @@ enum ANASTASIS_GenericState
   ANASTASIS_GENERIC_STATES (GENERATE_GENERIC_ENUM)
 };
 
-#undef GENERATE_BACKUP_ENUM
+#undef GENERATE_GENERIC_ENUM
 
 #define ANASTASIS_BACKUP_STATES(REDUX_STATE) \
   ANASTASIS_GENERIC_STATES (REDUX_STATE) \
-  REDUX_STATE (AuthenticationsEditingState)  \
-  REDUX_STATE (PoliciesReviewingState)   \
-  REDUX_STATE (BackupPayingState)  \
-  REDUX_STATE (NoState) \
+  REDUX_STATE (AUTHENTICATIONS_EDITING)  \
+  REDUX_STATE (POLICIES_REVIEWING)   \
+  REDUX_STATE (PAYING)
 
 #define GENERATE_BACKUP_ENUM(ENUM) ANASTASIS_BACKUP_STATE_ ## ENUM,
 
@@ -73,6 +72,8 @@ enum ANASTASIS_RecoveryState
   ANASTASIS_RECOVERY_STATES (GENERATE_RECOVERY_ENUM)
 };
 
+#undef GENERATE_RECOVERY_ENUM
+
 
 /**
  * JSON containing country specific identity attributes to ask the user for.
@@ -187,7 +188,7 @@ typedef void
 
 
 /**
- * Handle to an ongoing action. Only valid until the #ANASTASIA_ActionCallback 
is invoked.
+ * Handle to an ongoing action. Only valid until the #ANASTASIS_ActionCallback 
is invoked.
  */
 struct ANASTASIS_ReduxAction;
 
diff --git a/src/lib/anastasis_api_backup_redux.c 
b/src/lib/anastasis_api_backup_redux.c
index 203d39f..5d0e55d 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -68,12 +68,14 @@ ANASTASIS_backup_state_to_string (enum 
ANASTASIS_BackupState bs)
  *
  *  @param state FIXME: Description
  *  @param arguments FIXME: Description
+ *  @param ctx Curl context
  *  @param cb FIXME: Description
  *  @param cb_cls FIXME: Description
  */
 typedef struct ANASTASIS_ReduxAction *
 (*DispatchHandler)(json_t *state,
                    const json_t *arguments,
+                   struct GNUNET_CURL_Context *ctx,
                    ANASTASIS_ActionCallback cb,
                    void *cb_cls);
 
@@ -153,6 +155,7 @@ ANASTASIS_backup_start (const struct 
GNUNET_CONFIGURATION_Handle *cfg)
 static struct ANASTASIS_ReduxAction *
 add_authentication (json_t *state,
                     const json_t *arguments,
+                    struct GNUNET_CURL_Context *ctx,
                     ANASTASIS_ActionCallback cb,
                     void *cb_cls)
 {
@@ -401,6 +404,7 @@ method_candidate (struct PolicyBuilder *pb,
 static struct ANASTASIS_ReduxAction *
 done_authentication (json_t *state,
                      const json_t *arguments,
+                     struct GNUNET_CURL_Context *ctx,
                      ANASTASIS_ActionCallback cb,
                      void *cb_cls)
 {
@@ -444,7 +448,7 @@ done_authentication (json_t *state,
                                            pb.policies));
   set_state (state,
              ANASTASIS_backup_state_to_string (
-               ANASTASIS_BACKUP_STATE_PoliciesReviewingState));
+               ANASTASIS_BACKUP_STATE_POLICIES_REVIEWING));
   cb (cb_cls,
       ANASTASIS_EC_NONE,
       state);
@@ -455,6 +459,7 @@ done_authentication (json_t *state,
 static struct ANASTASIS_ReduxAction *
 del_authentication (json_t *state,
                     const json_t *arguments,
+                    struct GNUNET_CURL_Context *ctx,
                     ANASTASIS_ActionCallback cb,
                     void *cb_cls)
 {
@@ -502,6 +507,7 @@ del_authentication (json_t *state,
 static struct ANASTASIS_ReduxAction *
 add_policy (json_t *state,
             const json_t *arguments,
+            struct GNUNET_CURL_Context *ctx,
             ANASTASIS_ActionCallback cb,
             void *cb_cls)
 {
@@ -537,22 +543,22 @@ ANASTASIS_backup_action_ (struct GNUNET_CURL_Context *ctx,
     DispatchHandler fun;
   } dispatchers[] = {
     {
-      ANASTASIS_BACKUP_STATE_AuthenticationsEditingState,
+      ANASTASIS_BACKUP_STATE_AUTHENTICATIONS_EDITING,
       "add_authentication",
       &add_authentication
     },
     {
-      ANASTASIS_BACKUP_STATE_AuthenticationsEditingState,
+      ANASTASIS_BACKUP_STATE_AUTHENTICATIONS_EDITING,
       "delete_authentication",
       &del_authentication
     },
     {
-      ANASTASIS_BACKUP_STATE_AuthenticationsEditingState,
+      ANASTASIS_BACKUP_STATE_AUTHENTICATIONS_EDITING,
       "next",
       &done_authentication
     },
     {
-      ANASTASIS_BACKUP_STATE_AuthenticationsEditingState,
+      ANASTASIS_BACKUP_STATE_AUTHENTICATIONS_EDITING,
       "back",
       &ANASTASIS_back_generic_decrement_,
     },
@@ -586,6 +592,7 @@ ANASTASIS_backup_action_ (struct GNUNET_CURL_Context *ctx,
     {
       return dispatchers[i].fun (state,
                                  arguments,
+                                 ctx,
                                  cb,
                                  cb_cls);
     }
diff --git a/src/lib/anastasis_api_recovery_redux.c 
b/src/lib/anastasis_api_recovery_redux.c
index 8a31adc..143ef2b 100644
--- a/src/lib/anastasis_api_recovery_redux.c
+++ b/src/lib/anastasis_api_recovery_redux.c
@@ -64,14 +64,16 @@ ANASTASIS_recovery_state_to_string (enum 
ANASTASIS_RecoveryState rs)
 /**
  * Callback function FIXME: Description.
  *
- *  @param state FIXME: Description
- *  @param arguments FIXME: Description
- *  @param cb FIXME: Description
- *  @param cb_cls FIXME: Description
+ * @param state FIXME: Description
+ * @param arguments FIXME: Description
+ * @param ctx Curl context
+ * @param cb FIXME: Description
+ * @param cb_cls FIXME: Description
  */
 typedef struct ANASTASIS_ReduxAction *
 (*DispatchHandler)(json_t *state,
                    const json_t *arguments,
+                   struct GNUNET_CURL_Context *ctx,
                    ANASTASIS_ActionCallback cb,
                    void *cb_cls);
 
@@ -192,6 +194,7 @@ ANASTASIS_recovery_action_ (struct GNUNET_CURL_Context *ctx,
     {
       return dispatchers[i].fun (state,
                                  arguments,
+                                 ctx,
                                  cb,
                                  cb_cls);
     }
diff --git a/src/lib/anastasis_api_redux.c b/src/lib/anastasis_api_redux.c
index dc0358a..61fa91e 100644
--- a/src/lib/anastasis_api_redux.c
+++ b/src/lib/anastasis_api_redux.c
@@ -154,11 +154,6 @@ struct SelectCountryHandle
 };
 
 
-/**
- * Curl context for communication with taler backend
- */
-struct GNUNET_CURL_Context *curl_ctx;
-
 /**
  * JSON containing country specific identity attributes to ask the user for.
  */
@@ -170,12 +165,14 @@ const json_t *redux_id_attr;
  *
  * @param state FIXME: Description
  * @param arguments FIXME: Description
+ * @param ctx Curl context
  * @param cb FIXME: Description
  * @param cb_cls FIXME: Description
  */
 typedef struct ANASTASIS_ReduxAction *
 (*DispatchHandler)(json_t *state,
                    const json_t *arguments,
+                   struct GNUNET_CURL_Context *ctx,
                    ANASTASIS_ActionCallback cb,
                    void *cb_cls);
 
@@ -217,24 +214,36 @@ add_config_to_state (struct ConfigRequest *cr,
 {
   json_t *method;
   size_t index;
-  json_t *methods_list = json_object_get (state, "authentication_methods");
-  json_t *provider_list = json_object_get (state, "authentication_providers");
+  json_t *provider_list;
+  json_t *methods_list = json_object_get (cr->backend_methods,
+                                          "methods");
+
+  if (NULL == (provider_list = json_object_get (state,
+                                                "authentication_providers")))
+  {
+    GNUNET_assert (0 ==
+                   json_object_set_new (state,
+                                        "authentication_providers",
+                                        provider_list = json_object ()));
+  }
+  provider_list = json_object_get (state, "authentication_providers");
 
   GNUNET_assert (NULL != provider_list);
-  json_array_foreach (cr->backend_methods, index, method)
+  json_array_foreach (methods_list, index, method)
   {
     const char *method_type = json_string_value (json_object_get (method,
                                                                   "method"));
-    json_t *ma;
+    json_t *ma_arr;
     json_t *prov;
+    json_t *ma = json_object ();
 
-    if (NULL == (ma = json_object_get (provider_list,
-                                       method_type)))
+    if (NULL == (ma_arr = json_object_get (provider_list,
+                                           method_type)))
     {
       GNUNET_assert (0 ==
-                     json_object_set_new (methods_list,
+                     json_object_set_new (provider_list,
                                           method_type,
-                                          ma = json_object ()));
+                                          ma_arr = json_array ()));
     }
     prov = json_pack ("{s:o}",
                       "method_cost",
@@ -254,6 +263,7 @@ add_config_to_state (struct ConfigRequest *cr,
     GNUNET_assert (0 == json_object_set_new (ma,
                                              cr->backend_id,
                                              prov));
+    GNUNET_assert (0 == json_array_append_new (ma_arr, ma));
   }
 }
 
@@ -454,6 +464,7 @@ redux_id_attr_init (const char *country_code)
 static struct ANASTASIS_ReduxAction *
 select_continent (json_t *state,
                   const json_t *arguments,
+                  struct GNUNET_CURL_Context *ctx,
                   ANASTASIS_ActionCallback cb,
                   void *cb_cls)
 {
@@ -508,6 +519,7 @@ select_continent (json_t *state,
 static struct ANASTASIS_ReduxAction *
 select_country (json_t *state,
                 const json_t *arguments,
+                struct GNUNET_CURL_Context *ctx,
                 ANASTASIS_ActionCallback cb,
                 void *cb_cls)
 {
@@ -611,7 +623,7 @@ select_country (json_t *state,
       GNUNET_CONTAINER_DLL_insert (sch->cr_head,
                                    sch->cr_tail,
                                    cr);
-      cr->co = ANASTASIS_get_config (curl_ctx, // FIXME: pass as argument!
+      cr->co = ANASTASIS_get_config (ctx,
                                      cr->backend_url,
                                      &config_cb,
                                      cr);
@@ -642,6 +654,7 @@ select_country (json_t *state,
 static struct ANASTASIS_ReduxAction *
 unselect_country (json_t *state,
                   const json_t *arguments,
+                  struct GNUNET_CURL_Context *ctx,
                   ANASTASIS_ActionCallback cb,
                   void *cb_cls)
 {
@@ -664,6 +677,7 @@ unselect_country (json_t *state,
 static struct ANASTASIS_ReduxAction *
 unselect_continent (json_t *state,
                     const json_t *arguments,
+                    struct GNUNET_CURL_Context *ctx,
                     ANASTASIS_ActionCallback cb,
                     void *cb_cls)
 {
@@ -687,6 +701,7 @@ unselect_continent (json_t *state,
 static struct ANASTASIS_ReduxAction *
 enter_user_attributes (json_t *state,
                        const json_t *arguments,
+                       struct GNUNET_CURL_Context *ctx,
                        ANASTASIS_ActionCallback cb,
                        void *cb_cls)
 {
@@ -704,7 +719,7 @@ enter_user_attributes (json_t *state,
                          s_mode,
                          json_string (
                            ANASTASIS_backup_state_to_string (
-                             
ANASTASIS_BACKUP_STATE_AuthenticationsEditingState)));
+                             ANASTASIS_BACKUP_STATE_AUTHENTICATIONS_EDITING)));
   /** else FIXME: do something for recovery mode*/
 
   json_object_set_new (state,
@@ -724,6 +739,7 @@ enter_user_attributes (json_t *state,
 struct ANASTASIS_ReduxAction *
 ANASTASIS_back_generic_decrement_ (json_t *state,
                                    const json_t *arguments,
+                                   struct GNUNET_CURL_Context *ctx,
                                    ANASTASIS_ActionCallback cb,
                                    void *cb_cls)
 {
@@ -841,7 +857,6 @@ ANASTASIS_redux_action (const json_t *state,
                                                       "backup_state"));
   enum ANASTASIS_GenericState gs;
 
-  curl_ctx = ctx; // FIXME: pass as argument instead of as global
   if (NULL == s)
   {
     s = json_string_value (json_object_get (state,
@@ -878,6 +893,7 @@ ANASTASIS_redux_action (const json_t *state,
       {
         ret = dispatchers[i].fun (new_state,
                                   arguments,
+                                  ctx,
                                   cb,
                                   cb_cls);
         json_decref (new_state);
diff --git a/src/lib/anastasis_api_redux.h b/src/lib/anastasis_api_redux.h
index f2de11e..c3cd309 100644
--- a/src/lib/anastasis_api_redux.h
+++ b/src/lib/anastasis_api_redux.h
@@ -4,6 +4,7 @@
 struct ANASTASIS_ReduxAction *
 ANASTASIS_back_generic_decrement_ (json_t *state,
                                    const json_t *arguments,
+                                   struct GNUNET_CURL_Context *ctx,
                                    ANASTASIS_ActionCallback cb,
                                    void *cb_cls);
 

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