gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 04/06: add select country


From: gnunet
Subject: [taler-anastasis] 04/06: add select country
Date: Tue, 15 Sep 2020 19:28:20 +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 ca0ae3dc340f5c024631fa7e831127bf0da1633b
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Tue Sep 15 16:39:14 2020 +0200

    add select country
---
 contrib/redux.countries.json         |   2 +-
 src/lib/anastasis_api_backup_redux.c | 104 +++++++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+), 1 deletion(-)

diff --git a/contrib/redux.countries.json b/contrib/redux.countries.json
index 57a0262..2a397a5 100644
--- a/contrib/redux.countries.json
+++ b/contrib/redux.countries.json
@@ -26,7 +26,7 @@
        { 
                "code" : "us",
                "name" : "United States of America (USA)",
-               "continent" : "North America",
+               "continent" : "North_America",
                "continent_i18n" : { "de" : "Nordamerika" },
                "name_i18n" : { "de_DE":"Vereinigte Staaten von Amerika (USA)",
                                                "de_CH":"Vereinigte Staaten von 
Amerika (USA)",
diff --git a/src/lib/anastasis_api_backup_redux.c 
b/src/lib/anastasis_api_backup_redux.c
index b41aa48..d6cefb4 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -36,6 +36,7 @@ json_t *redux_countries;
  */
 json_t *redux_id_attr;
 
+
 /**
  * Callback function FIXME: Description.
  *
@@ -50,6 +51,13 @@ typedef void
                    ANASTASIS_ActionCallback cb,
                    void *cb_cls);
 
+
+/**
+ * Function to load json containing all countries.
+ * Returns #GNUNET_OK if operation succeeded, else #GNUNET_SYSERR.
+ *
+ * @return int
+ */
 static int
 redux_countries_init ()
 {
@@ -87,6 +95,54 @@ redux_countries_init ()
   return GNUNET_OK;
 }
 
+
+/**
+ * Function to load json containing country specific
+ * identity attributes. Returns #GNUNET_OK if operation
+ * succeeded, else #GNUNET_SYSERR.
+ *
+ * @param country_code country code (e.g. "de")
+ * @return int
+ */
+static int
+redux_id_attr_init (const char*country_code)
+{
+  char *dn;
+  json_error_t error;
+
+  {
+    char *path;
+
+    path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_PREFIX);
+    if (NULL == path)
+    {
+      GNUNET_break (0);
+      return GNUNET_SYSERR;
+    }
+    GNUNET_asprintf (&dn,
+                     "%s/share/anastasis/redux.%s.json",
+                     path,
+                     country_code);
+    GNUNET_free (path);
+  }
+  redux_id_attr = json_load_file (dn, JSON_COMPACT, &error);
+  if (NULL == redux_id_attr)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Failed to parse `%s': %s at %d:%d (%d)\n",
+                dn,
+                error.text,
+                error.line,
+                error.column,
+                error.position);
+    GNUNET_free (dn);
+    return GNUNET_SYSERR;
+  }
+  GNUNET_free (dn);
+  return GNUNET_OK;
+}
+
+
 /**
  * Returns an initial ANASTASIS backup state.
  *
@@ -204,7 +260,55 @@ select_country (const json_t *state,
                 ANASTASIS_ActionCallback cb,
                 void *cb_cls)
 {
+  json_t *new_state;
+  json_t *root;
+  json_t *country = json_object_get (arguments, "country");
+
+  if (NULL == state)
+  {
+    GNUNET_break (0);
+    cb (cb_cls,
+        ANASTASIS_EC_INVALID, // FIXME: Define correct error code
+        NULL);
+  }
+  if (NULL == country)
+  {
+    GNUNET_break (0);
+    cb (cb_cls,
+        ANASTASIS_EC_INVALID, // FIXME: Define correct error code
+        NULL);
+  }
+  if (GNUNET_SYSERR ==
+      redux_countries_init (json_string_value (country)))
+  {
+    GNUNET_break (0);
+    return NULL;
+  }
+  new_state = json_deep_copy (state);
+  if (NULL == new_state)
+  {
+    GNUNET_break (0);
+    cb (cb_cls,
+        ANASTASIS_EC_INVALID, // FIXME: Define correct error code
+        NULL);
+  }
+  root = json_object_get (redux_id_attr, "required_attributes");
 
+  json_object_set (new_state,
+                   "backup-state",
+                   json_string ("ReduxCountrySelectedState"));
+
+  json_object_set_new (new_state,
+                       "required_attributes",
+                       redux_id_attr);
+  // optional:
+  json_object_set_new (new_state,
+                       "selected_country",
+                       country);
+  cb (cb_cls,
+      ANASTASIS_EC_NONE,
+      new_state);
+  json_decref (new_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]