gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 05/08: initialize truths


From: gnunet
Subject: [taler-anastasis] 05/08: initialize truths
Date: Fri, 06 Nov 2020 18:06:30 +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 2604eaab9dfc63a4bef2e5ebeb8622a1ba817fc2
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Thu Nov 5 14:30:20 2020 +0100

    initialize truths
---
 src/lib/anastasis_api_backup_redux.c | 171 ++++++++++++++++++++++++++++-------
 1 file changed, 140 insertions(+), 31 deletions(-)

diff --git a/src/lib/anastasis_api_backup_redux.c 
b/src/lib/anastasis_api_backup_redux.c
index 31d1181..ac31257 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -866,6 +866,146 @@ done_policy_review (json_t *state,
 }
 
 
+/**
+ * Initialize data for #ANASTASIS_truth_upload.
+ *
+ * @param state actual state to extract truth information from.
+ * @return json containing truth information
+ */
+static json_t *
+initialize_truths (json_t *state)
+{
+  size_t policy_index;
+  json_t *policy;
+  json_t *truths = json_array ();
+
+  GNUNET_assert (json_is_array (truths));
+  json_t *authentication_methods =
+    json_object_get (state,
+                     "authentication_methods");
+
+  GNUNET_assert (json_is_array (authentication_methods));
+  json_t *provider_methods = json_object_get (state,
+                                              "authentication_providers");
+
+  GNUNET_assert (NULL != provider_methods);
+  json_t *policy_json_array = json_object_get (state,
+                                               "policies");
+
+  GNUNET_assert (json_is_array (policy_json_array));
+  json_array_foreach (policy_json_array, policy_index, policy)
+  {
+    struct ANASTASIS_Truth *truths;
+    size_t index;
+    json_t *method;
+    json_t *policy_methods = json_object_get (policy,
+                                              "methods");
+
+    GNUNET_assert (json_is_array (policy_methods));
+    json_array_foreach (policy_methods, index, method)
+    {
+      const char *instructions;
+      const char *mime_type;
+      const char *backend_url;
+      size_t provider_index;
+      size_t check_index;
+      json_t *check_truth;
+      json_t *supported_provider;
+      size_t auth_method_index = json_integer_value (
+        json_object_get (method,
+                         "authentication_method"));
+      json_t *auth_method = json_array_get (authentication_methods,
+                                            auth_method_index);
+      GNUNET_assert (NULL != auth_method);
+      const char *method = json_string_value (json_object_get (auth_method,
+                                                               "method"));
+      json_t *truth_data = json_object_get (auth_method,
+                                            "data");
+      const char *backend_id = json_string_value (json_object_get (method,
+                                                                   
"provider"));
+      json_t *supported_providers = json_object_get (provider_methods,
+                                                     method);
+
+      GNUNET_assert (json_is_array (supported_providers));
+      json_array_foreach (supported_providers, provider_index,
+                          supported_provider)
+      {
+        json_t *provider_data =
+          json_object_get (supported_provider,
+                           backend_id);
+        if (NULL != provider_data)
+        {
+          backend_url = json_object_get (provider_data,
+                                         "provider_url");
+          break;
+        }
+      }
+
+      if (0 == strcmp (method, "question"))
+      {
+        instructions = json_string_value (json_object_get (truth_data,
+                                                           "question"));
+        mime_type = "text";
+      }
+      else if (0 == strcmp (method, "sms"))
+      {
+        instructions = "Please look at your phone.";
+        mime_type = "text";
+      }
+      else if (0 == strcmp (method, "email"))
+      {
+        instructions = "Please look at your emails.";
+        mime_type = "text";
+      }
+      else if (0 == strcmp (method, "post"))
+      {
+        instructions = "Please look into your post box.";
+        mime_type = "text";
+      }
+      else if (0 == strcmp (method, "video"))
+      {
+        instructions = "Please look into the camera.";
+        mime_type = "image";
+      }
+      else
+      {
+        GNUNET_break (0);
+        return NULL;
+      }
+
+      json_t *truth = json_pack ("{s:I, s:s, s:s, s:s, s:o, s:s, s:s}",
+                                 "auth_method_index",
+                                 (json_int_t) auth_method_index,
+                                 "backend_url",
+                                 backend_url,
+                                 "backend_id",
+                                 backend_id,
+                                 "method_type",
+                                 method,
+                                 "truth_data",
+                                 truth_data,
+                                 "instructions",
+                                 instructions,
+                                 "mime_type",
+                                 mime_type);
+      // check if truths allready contains this truth
+      bool existing = false;
+      json_array_foreach (truths, check_index, check_truth)
+      {
+        if (1 == json_equal (truth, check_truth))
+        {
+          existing = true;
+          break;
+        }
+      }
+      if (! existing)
+        GNUNET_assert (0 == json_array_append_new (truths, truth));
+    }
+  }
+  return truths;
+}
+
+
 /**
  * DispatchHandler/Callback function which is called for a
  * "enter_secret" action.
@@ -918,38 +1058,7 @@ enter_secret (json_t *state,
                                       arguments));
 
   // initialize #ANASTASIS_Policy array
-  json_t *authentication_json_array =
-    json_object_get (state,
-                     "authentication_methods");
 
-  GNUNET_assert (json_is_array (authentication_json_array));
-  json_t *provider_json_array = json_object_get (state,
-                                                 "authentication_providers");
-
-  GNUNET_assert (json_is_array (provider_json_array));
-  json_t *policy_json_array = json_object_get (state,
-                                               "policies");
-
-  GNUNET_assert (json_is_array (policy_json_array));
-  const struct ANASTASIS_Policy *policies[json_array_size (policy_json_array)];
-
-  for (unsigned int i = 0; i < json_array_size (policy_json_array); i++)
-  {
-    struct ANASTASIS_Truth *truths;
-    size_t index;
-    json_t *method;
-    json_t *policy_json = json_array_get (policy_json_array, i);
-
-    GNUNET_assert (NULL != policy_json);
-    json_t *methods = json_object_get (policy_json,
-                                       "methods");
-
-    GNUNET_assert (json_is_array (methods));
-    json_array_foreach (methods, index, method)
-    {
-
-    }
-  }
   // try uploading recovery document
   /*
   set_state (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]