gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 05/07: work on backup redux


From: gnunet
Subject: [taler-anastasis] 05/07: work on backup redux
Date: Sat, 12 Sep 2020 11:01:52 +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 09f7a555e773c6015bcecf99e5812f35f103ce04
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Fri Sep 11 21:27:24 2020 +0200

    work on backup redux
---
 src/cli/anastasis-cli-redux.c        | 87 +++++++++++++++++++++++++++++++++---
 src/lib/anastasis_api_backup_redux.c | 60 +++++++++++++++++++++++++
 2 files changed, 140 insertions(+), 7 deletions(-)

diff --git a/src/cli/anastasis-cli-redux.c b/src/cli/anastasis-cli-redux.c
index 61623e4..ef96094 100644
--- a/src/cli/anastasis-cli-redux.c
+++ b/src/cli/anastasis-cli-redux.c
@@ -67,12 +67,45 @@ static json_t *new_state;
  */
 static char *path_new_state;
 
+/**
+ * JSON containing arguments for action
+ */
+static json_t *arguments;
+
 /**
  * action to do with previous state
  */
 static char *action;
 
 
+static int
+persist_new_state ()
+{
+  return json_dump_file (new_state, path_new_state, JSON_COMPACT);
+}
+
+/**
+ * Function called with the results of #ANASTASIS_backup_action
+ * or #ANASTASIS_recovery_action.
+ *
+ * @param cls closure
+ * @param error_code Error code
+ * @param new_state new state as result
+ */
+static void
+action_cb (void *cls,
+           enum ANASTASIS_ErrorCode error_code,
+           json_t *result_state)
+{
+  new_state = result_state;
+  if (NULL != new_state)
+    if (0 == persist_new_state ())
+      return;
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              "Failed to persist new state! \n");
+  GNUNET_SCHEDULER_shutdown ();
+}
+
 /**
  * @brief Shutdown the application.
  *
@@ -113,7 +146,7 @@ run (void *cls,
 {
   (void) cls;
   (void) args;
-  (void) cfgfile;
+  (void) cfg;
   // FIXME: error handling json error
   json_error_t error;
 
@@ -131,7 +164,8 @@ run (void *cls,
   if (! (r_flag ^ b_flag ^ i_flag) || (r_flag && b_flag && i_flag))
   {
     printf ("Please set one option: -b, -r, -i!\n");
-    printf ("Example: anastasis-reducer -b prev.json action new.json\n");
+    printf (
+      "Example: anastasis-reducer -b prev.json action arguments.json 
new.json\n");
     printf ("Example: anastasis-reducer -i init.json\n");
     GNUNET_SCHEDULER_shutdown ();
     return;
@@ -171,7 +205,8 @@ run (void *cls,
     else
     {
       printf ("Please give path for json containing previous state!\n");
-      printf ("Example: anastasis-reducer -b prev.json action new.json\n");
+      printf (
+        "Example: anastasis-reducer -b prev.json action arguments.json 
new.json\n");
       GNUNET_SCHEDULER_shutdown ();
       return;
     }
@@ -181,27 +216,65 @@ run (void *cls,
     else
     {
       printf ("Please give an action!\n");
-      printf ("Example: anastasis-reducer -b prev.json action new.json\n");
+      printf (
+        "Example: anastasis-reducer -b prev.json action arguments.json 
new.json\n");
       GNUNET_SCHEDULER_shutdown ();
       return;
     }
 
     if (args[2])
-      path_new_state = (char *) args[2];
+      arguments = json_load_file ((char *) args[2], JSON_DECODE_ANY, &error);
+    else
+    {
+      printf ("Please give path for json containing arguments for action!\n");
+      printf (
+        "Example: anastasis-reducer -b prev.json action arguments.json 
new.json\n");
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
+
+    if (args[3])
+      path_new_state = (char *) args[3];
     else
     {
       printf ("Please give path for json containing new state!\n");
-      printf ("Example: anastasis-reducer -b prev.json action new.json\n");
+      printf (
+        "Example: anastasis-reducer -b prev.json action arguments.json 
new.json\n");
       GNUNET_SCHEDULER_shutdown ();
       return;
     }
   }
 
-
   /* initialize HTTP client FIXME: Do we need http client?*/
   ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
                           &rc);
   rc = GNUNET_CURL_gnunet_rc_create (ctx);
+
+  if (i_flag)
+  {
+    new_state = ANASTASIS_backup_start (cfg);
+    if (NULL != new_state)
+      if (0 == persist_new_state ())
+        return;
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Failed to persist new state! \n");
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+
+  if (b_flag)
+    ANASTASIS_backup_action (prev_state,
+                             action,
+                             arguments,
+                             &action_cb,
+                             cls);
+
+  if (r_flag)
+    ANASTASIS_recovery_action (prev_state,
+                               action,
+                               arguments,
+                               &action_cb,
+                               cls);
 }
 
 
diff --git a/src/lib/anastasis_api_backup_redux.c 
b/src/lib/anastasis_api_backup_redux.c
index b310b25..3640568 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -154,6 +154,46 @@ select_continent (const json_t *state,
 }
 
 
+static void
+select_country (const json_t *state,
+                const json_t *arguments,
+                ANASTASIS_ActionCallback cb,
+                void *cb_cls)
+{
+
+}
+
+
+static void
+enter_user_attributes (const json_t *state,
+                       const json_t *arguments,
+                       ANASTASIS_ActionCallback cb,
+                       void *cb_cls)
+{
+
+}
+
+
+static void
+add_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,
+            ANASTASIS_ActionCallback cb,
+            void *cb_cls)
+{
+
+}
+
+
 /**
  * Operates on a backup state depending on given #ANASTASIS_BackupState
  * and #ANASTASIS_BackupAction. The new #ANASTASIS_BackupState is returned
@@ -185,6 +225,26 @@ ANASTASIS_backup_action (const json_t *state,
       "selection_continent",
       &select_continent
     },
+    {
+      "ReduxContinentSelectedState",
+      "selection_country",
+      &select_country
+    },
+    {
+      "ReduxCountrySelectedState",
+      "entering_user_attributes",
+      &enter_user_attributes
+    },
+    {
+      "ReduxUserAttributesAddedState",
+      "adding_authentication",
+      &add_authentication
+    },
+    {
+      "ReduxAuthenticationAddedState",
+      "adding_policy",
+      &add_policy
+    },
     { NULL, NULL, NULL }
   };
   const char *s = json_string_value (json_object_get (state,

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