[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated (aa001ce -> 5e3ee12)
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated (aa001ce -> 5e3ee12) |
Date: |
Tue, 15 Sep 2020 19:28:16 +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 aa001ce fixed db test
new bcdd658 fix include
new e63ed67 worked on select country
new eea6088 fixed json array loop
new ca0ae3d add select country
new 5f1deaf fix country selection
new 5e3ee12 Merge branch 'master' of ssh://git.taler.net/anastasis into
master
The 6 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:
contrib/redux.countries.json | 2 +-
src/include/Makefile.am | 1 +
src/lib/anastasis_api_backup_redux.c | 135 +++++++++++++++++++++++++++++++----
3 files changed, 122 insertions(+), 16 deletions(-)
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/include/Makefile.am b/src/include/Makefile.am
index d5dd76e..2bb88f1 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -12,4 +12,5 @@ anastasisinclude_HEADERS = \
anastasis_database_lib.h \
anastasis_util_lib.h \
anastasis_crypto_lib.h \
+ anastasis_redux.h \
anastasis.h
diff --git a/src/lib/anastasis_api_backup_redux.c
b/src/lib/anastasis_api_backup_redux.c
index 6acbdfa..65455fb 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.
*
@@ -144,9 +200,9 @@ select_continent (const json_t *state,
json_t *new_state;
size_t index;
json_t *country;
- json_t *continent = json_object_get (arguments, "continent");
json_t *root = json_object_get (redux_countries, "countries");
json_t *countries = json_array ();
+ json_t *continent = json_object_get (arguments, "continent");
if (NULL == state)
{
@@ -163,33 +219,33 @@ select_continent (const json_t *state,
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);
+ }
json_array_foreach (root, index, country)
{
- size_t inner_index;
- json_t *inner_country;
- json_t *temp_continent = json_object_get (json_array_get (root, index),
+ json_t *temp_continent = json_object_get (country,
"continent");
- bool existing = false;
- json_array_foreach (countries, inner_index, inner_country)
- {
- if (1 == json_equal (continent, temp_continent))
- {
- existing = true;
- break;
- }
- }
- if (! existing)
+ if (1 == json_equal (continent, temp_continent))
json_array_append_new (countries, country);
}
+ json_object_set (new_state,
+ "backup-state",
+ json_string ("ReduxContinentSelectedState"));
+
json_object_set_new (new_state,
"countries",
countries);
// optional:
json_object_set_new (new_state,
- "continent",
+ "selected_continent",
continent);
cb (cb_cls,
ANASTASIS_EC_NONE,
@@ -204,7 +260,56 @@ 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_code");
+
+ 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_id_attr_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,
+ "selected_country",
+ country);
+ json_object_set_new (new_state,
+ "required_attributes",
+ root);
+
+ 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.
- [taler-anastasis] branch master updated (aa001ce -> 5e3ee12),
gnunet <=
- [taler-anastasis] 01/06: fix include, gnunet, 2020/09/15
- [taler-anastasis] 04/06: add select country, gnunet, 2020/09/15
- [taler-anastasis] 02/06: worked on select country, gnunet, 2020/09/15
- [taler-anastasis] 03/06: fixed json array loop, gnunet, 2020/09/15
- [taler-anastasis] 06/06: Merge branch 'master' of ssh://git.taler.net/anastasis into master, gnunet, 2020/09/15
- [taler-anastasis] 05/06: fix country selection, gnunet, 2020/09/15