[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: fix FTBFS
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: fix FTBFS |
Date: |
Mon, 15 Feb 2021 16:34:53 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository anastasis.
The following commit(s) were added to refs/heads/master by this push:
new 6053a3e fix FTBFS
6053a3e is described below
commit 6053a3e452e5109b17d10424e74d3c4b3f714bdb
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon Feb 15 16:34:51 2021 +0100
fix FTBFS
---
contrib/gana | 2 +-
contrib/provider-list.json | 32 +-
src/reducer/Makefile.am | 3 +-
src/reducer/anastasis_api_redux.c | 707 +++++++++++++++++++-------------------
src/reducer/validation_CH_AHV.c | 25 ++
5 files changed, 404 insertions(+), 365 deletions(-)
diff --git a/contrib/gana b/contrib/gana
index c17bb5f..cf4c9cc 160000
--- a/contrib/gana
+++ b/contrib/gana
@@ -1 +1 @@
-Subproject commit c17bb5f294870f1179c3f104bafbe3ad9992c67e
+Subproject commit cf4c9cc53b19e2296481ae6c89aa6e5375a198e3
diff --git a/contrib/provider-list.json b/contrib/provider-list.json
index 8a28b07..2b9bb5b 100644
--- a/contrib/provider-list.json
+++ b/contrib/provider-list.json
@@ -1,24 +1,28 @@
{
"anastasis_provider": [
{
- "provider_id" : "anastasis_01",
- "provider_url" : "localhost:8086/",
- "provider_name" : "Anastasis 1"
+ "id" : "anastasis_01",
+ "url" : "localhost:8086/",
+ "name" : "Anastasis 1",
+ "currency" : "TESTKUDOS"
},
{
- "provider_id" : "anastasis_02",
- "provider_url" : "localhost:8087/",
- "provider_name" : "Anastasis 2"
+ "id" : "anastasis_02",
+ "url" : "localhost:8087/",
+ "name" : "Anastasis 2",
+ "currency" : "TESTKUDOS"
},
{
- "provider_id" : "anastasis_03",
- "provider_url" : "localhost:8088/",
- "provider_name" : "Anastasis 3"
+ "id" : "anastasis_03",
+ "url" : "localhost:8088/",
+ "name" : "Anastasis 3",
+ "currency" : "TESTKUDOS"
},
{
- "provider_id" : "anastasis_04",
- "provider_url" : "localhost:8089/",
- "provider_name" : "Anastasis 4"
+ "id" : "anastasis_04",
+ "url" : "localhost:8089/",
+ "name" : "Anastasis 4",
+ "currency" : "TESTKUDOS"
}
- ]
-}
\ No newline at end of file
+ ]
+}
diff --git a/src/reducer/Makefile.am b/src/reducer/Makefile.am
index 0480e93..3131760 100644
--- a/src/reducer/Makefile.am
+++ b/src/reducer/Makefile.am
@@ -17,7 +17,8 @@ libanastasisredux_la_LDFLAGS = \
libanastasisredux_la_SOURCES = \
anastasis_api_redux.c anastasis_api_redux.h \
anastasis_api_recovery_redux.c \
- anastasis_api_backup_redux.c
+ anastasis_api_backup_redux.c \
+ validation_CH_AHV.c
libanastasisredux_la_LIBADD = \
$(top_builddir)/src/restclient/libanastasisrest.la \
$(top_builddir)/src/lib/libanastasis.la \
diff --git a/src/reducer/anastasis_api_redux.c
b/src/reducer/anastasis_api_redux.c
index 80465d4..85787d2 100644
--- a/src/reducer/anastasis_api_redux.c
+++ b/src/reducer/anastasis_api_redux.c
@@ -29,6 +29,14 @@
#include <dlfcn.h>
+/**
+ * How long do we wait at most for a /config reply from an Anastasis provider.
+ * 60s is very generous, given the tiny bandwidth required, even for the most
+ * remote locations.
+ */
+#define CONFIG_GENERIC_TIMEOUT GNUNET_TIME_UNIT_MINUTES
+
+
#define GENERATE_STRING(STRING) #STRING,
static const char *generic_strings[] = {
ANASTASIS_GENERIC_STATES (GENERATE_STRING)
@@ -100,14 +108,25 @@ ANASTASIS_redux_fail_ (ANASTASIS_ActionCallback cb,
/**
- * How long do we wait at most for a /config reply from an Anastasis provider.
- * 60s is very generous, given the tiny bandwidth required, even for the most
- * remote locations.
+ * Transition the @a state to @a gs.
+ *
+ * @param[in,out] state to transition
+ * @param gs state to transition to
*/
-#define CONFIG_GENERIC_TIMEOUT GNUNET_TIME_UNIT_MINUTES
+static void
+redux_transition (json_t *state,
+ enum ANASTASIS_GenericState gs)
+{
+ const char *s_mode = get_state_mode (state);
+ GNUNET_assert (0 ==
+ json_object_set_new (
+ state,
+ s_mode,
+ json_string (
+ ANASTASIS_generic_state_to_string_ (gs))));
-struct SelectCountryHandle;
+}
/**
@@ -176,30 +195,18 @@ struct ConfigRequest
*/
json_t *backend_methods;
- struct GNUNET_SCHEDULER_Task *tt;
-};
-
-
-struct SelectCountryHandle
-{
-
/**
- * Current state
+ * Task to timeout /config requests.
*/
- json_t *state;
-
- /**
- * Function to call if config request was successful.
- */
- ANASTASIS_ActionCallback cb;
-
- /**
- * Closure for action callback #cb.
- */
- void *cb_cls;
+ struct GNUNET_SCHEDULER_Task *tt;
};
+/**
+ * Reducer API's CURL context handle.
+ */
+struct GNUNET_CURL_Context *ANASTASIS_REDUX_ctx_;
+
/**
* JSON containing country specific identity attributes to ask the user for.
*/
@@ -216,14 +223,14 @@ static struct ConfigRequest *cr_head;
static struct ConfigRequest *cr_tail;
/**
- * Reducer API's CURL context handle.
+ * JSON containing country specific information.
*/
-struct GNUNET_CURL_Context *ANASTASIS_REDUX_ctx_;
+static json_t *redux_countries;
/**
- * JSON containing country specific information.
+ * List of Anastasis providers.
*/
-json_t *redux_countries;
+static json_t *provider_list;
/**
@@ -285,6 +292,11 @@ ANASTASIS_redux_done ()
json_decref (redux_id_attr);
redux_id_attr = NULL;
}
+ if (NULL != provider_list)
+ {
+ json_decref (provider_list);
+ provider_list = NULL;
+ }
}
@@ -440,147 +452,92 @@ check_config (const char *url,
/**
- * Callback function which is called by the reducer in dependence of
- * given state and action.
- *
- * @param state the previous state to operate on
- * @param arguments the arguments needed by operation to operate on state
- * @param cb Callback function which returns the new state
- * @param cb_cls closure for @a cb
- * @return handle to cancel async actions, NULL if @a cb was already called
- */
-typedef struct ANASTASIS_ReduxAction *
-(*DispatchHandler)(json_t *state,
- const json_t *arguments,
- ANASTASIS_ActionCallback cb,
- void *cb_cls);
-
-
-/**
- * Function to free a #SelectCountryHandle.
- *
- * @param cls closure for a #SelectCountryHandle.
- */
-static void
-free_select_country (void *cls)
-{
- struct SelectCountryHandle *sch = cls;
-
- json_decref (sch->state);
- GNUNET_free (sch);
-}
-
-
-#if 0
-/**
- * Adds the server configuration from async #ConfigRequest
- * to the json state.
+ * Begin asynchronous check for provider configurations.
*
- * @param cr the config request
- * @param state the json state to operate on
+ * @param currency the currency to initiate the provider checks for
+ * @return #TALER_EC_NONE on success
*/
-static void
-add_config_to_state (struct ConfigRequest *cr,
- json_t *state)
+static enum TALER_ErrorCode
+begin_provider_config_check (const char *currency)
{
- json_t *method;
- size_t index;
- 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 (methods_list, index, method)
+ if (NULL == provider_list)
{
- const char *method_type = json_string_value (json_object_get (method,
- "method"));
- json_t *ma_arr;
- json_t *prov;
- json_t *ma = json_object ();
+ json_error_t error;
+ char *dn;
+ char *path;
- if (NULL == (ma_arr = json_object_get (provider_list,
- method_type)))
+ path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
+ if (NULL == path)
{
- GNUNET_assert (0 ==
- json_object_set_new (provider_list,
- method_type,
- ma_arr = json_array ()));
+ GNUNET_break (0);
+ return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
}
- char *provider_salt = GNUNET_STRINGS_data_to_string_alloc (
- &cr->backend_salt,
- sizeof (struct
- ANASTASIS_CRYPTO_PowSalt));
- prov = json_pack ("{s:o, s:o, s:o, s:s, s:s, s:s}",
- "method_cost",
- json_object_get (method,
- "cost"),
- "annual_cost",
- TALER_JSON_from_amount (&cr->backend_cost),
- "insurance",
- TALER_JSON_from_amount (&cr->backend_insurance),
- "provider_url",
- cr->backend_url,
- "provider_name",
- cr->backend_name,
- "provider_salt",
- provider_salt);
- GNUNET_free (provider_salt);
- GNUNET_assert (0 == json_object_set_new (ma,
- cr->backend_id,
- prov));
- GNUNET_assert (0 == json_array_append_new (ma_arr, ma));
+ GNUNET_asprintf (&dn,
+ "%s/provider-list.json",
+ path);
+ GNUNET_free (path);
+ provider_list = json_load_file (dn,
+ JSON_COMPACT,
+ &error);
+ if (NULL == provider_list)
+ {
+ 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 TALER_EC_ANASTASIS_REDUCER_RESOURCE_MALFORMED;
+ }
+ GNUNET_free (dn);
}
-}
-
-
-/**
- * Function which collects all configurations from the different
- * servers and calls the #ANASTASIS_ActionCallback.
- *
- * @param sch a handle to a country selection action
- */
-static void
-conclude_select_country (struct SelectCountryHandle *sch)
-{
- struct ConfigRequest *cr;
- const char *currency;
- currency = json_string_value (json_object_get (sch->state,
- "currency"));
- while (NULL != (cr = sch->cr_head))
{
- GNUNET_CONTAINER_DLL_remove (sch->cr_head,
- sch->cr_tail,
- cr);
- if ( (MHD_HTTP_OK != cr->http_status) ||
- (0 != strcmp (cr->backend_currency,
- currency)) )
+ size_t index;
+ json_t *provider;
+ const json_t *provider_arr = json_object_get (provider_list,
+ "anastasis_provider");
+ json_array_foreach (provider_arr, index, provider)
{
- free_config_request (cr);
- continue;
+ const char *url;
+ const char *name;
+ const char *id;
+ const char *cur;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("url",
+ &url),
+ GNUNET_JSON_spec_string ("name",
+ &name),
+ GNUNET_JSON_spec_string ("id",
+ &id),
+ GNUNET_JSON_spec_string ("currency",
+ &cur),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (provider,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break (0);
+ return TALER_EC_ANASTASIS_REDUCER_RESOURCE_MALFORMED;
+ }
+
+ if (0 != strcasecmp (currency,
+ cur))
+ continue;
+ check_config (url,
+ name,
+ id);
}
- add_config_to_state (cr,
- sch->state);
}
- sch->cb (NULL,
- TALER_EC_NONE,
- sch->state);
+ return TALER_EC_NONE;
}
-#endif
-
-
/**
* Function to validate an input by regular expression ("validation-regex").
*
@@ -622,8 +579,9 @@ validate_regex (const char *input,
/**
- * Function to load json containing country specific
- * identity attributes.
+ * Function to load json containing country specific identity
+ * attributes. Uses a single-slot cache to avoid loading
+ * exactly the same attributes twice.
*
* @param country_code country code (e.g. "de")
* @return NULL on error
@@ -632,7 +590,6 @@ static const json_t *
redux_id_attr_init (const char *country_code)
{
static char redux_id_cc[3];
- json_t *redux_id_attr;
char *dn;
json_error_t error;
@@ -691,7 +648,7 @@ redux_id_attr_init (const char *country_code)
*
* @param state state to operate on
* @param arguments arguments to use for operation on state
- * @param cb callback (#DispatchHandler) to call during/after operation
+ * @param cb callback to call during/after operation
* @param cb_cls callback closure
* @return NULL
*/
@@ -701,60 +658,65 @@ select_continent (json_t *state,
ANASTASIS_ActionCallback cb,
void *cb_cls)
{
+ const json_t *redux_countries = ANASTASIS_redux_countries_init_ ();
+ const json_t *root = json_object_get (redux_countries,
+ "countries");
+ const json_t *continent;
+ json_t *countries;
+
+ if (NULL == root)
+ {
+ ANASTASIS_redux_fail_ (cb,
+ cb_cls,
+ TALER_EC_ANASTASIS_REDUCER_RESOURCE_MALFORMED,
+ "'countries' missing");
+ return NULL;
+ }
if (NULL == arguments)
{
- json_t *error = json_pack ("{s:I, s:s}",
- "code",
- (json_int_t) TALER_EC_INVALID,
- "hint",
- "Arguments missing!");
- cb (cb_cls,
- TALER_EC_INVALID,
- error);
+ ANASTASIS_redux_fail_ (cb,
+ cb_cls,
+ TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID,
+ "arguments missing");
return NULL;
}
-
- size_t index;
- json_t *country;
- const json_t *redux_countries = ANASTASIS_redux_countries_init_ ();
- json_t *root = json_object_get (redux_countries, "countries");
- json_t *countries = json_array ();
- json_t *continent = json_object_get (arguments, "continent");
-
- GNUNET_assert (NULL != root);
+ continent = json_object_get (arguments,
+ "continent");
+ if (NULL == continent)
+ {
+ ANASTASIS_redux_fail_ (cb,
+ cb_cls,
+ TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID,
+ "'continent' missing");
+ return NULL;
+ }
+ countries = json_array ();
GNUNET_assert (NULL != countries);
- GNUNET_assert (NULL != continent);
- GNUNET_assert (NULL != state);
- const char *s_mode = get_state_mode (state);
- GNUNET_assert (NULL != s_mode);
-
- json_array_foreach (root, index, country)
{
- json_t *temp_continent = json_object_get (country,
- "continent");
+ size_t index;
+ json_t *country;
- if (1 == json_equal (continent, temp_continent))
- json_array_append_new (countries, country);
+ json_array_foreach (root, index, country)
+ {
+ json_t *temp_continent = json_object_get (country,
+ "continent");
+ if (1 == json_equal (continent,
+ temp_continent))
+ GNUNET_assert (0 ==
+ json_array_append_new (countries,
+ country));
+ }
}
-
+ redux_transition (state,
+ ANASTASIS_GENERIC_STATE_COUNTRY_SELECTING);
GNUNET_assert (0 ==
- json_object_set_new (
- state,
- s_mode,
- json_string (
- ANASTASIS_backup_state_to_string_ (
- ANASTASIS_GENERIC_STATE_COUNTRY_SELECTING))));
-
- GNUNET_assert (0 ==
- json_object_set_new (state,
- "selected_continent",
- continent));
-
+ json_object_set (state,
+ "selected_continent",
+ (json_t *) continent));
GNUNET_assert (0 ==
json_object_set_new (state,
"countries",
countries));
-
cb (cb_cls,
TALER_EC_NONE,
state);
@@ -769,7 +731,7 @@ select_continent (json_t *state,
*
* @param state state to operate on
* @param arguments arguments to use for operation on state
- * @param cb callback (#DispatchHandler) to call during/after operation
+ * @param cb callback to call during/after operation
* @param cb_cls callback closure
* @return #ANASTASIS_ReduxAction
*/
@@ -779,124 +741,74 @@ select_country (json_t *state,
ANASTASIS_ActionCallback cb,
void *cb_cls)
{
+ const json_t *required_attrs;
+ const json_t *country;
+ const char *currency;
+ const json_t *redux_id_attr;
+
if (NULL == arguments)
{
ANASTASIS_redux_fail_ (cb,
cb_cls,
- TALER_EC_ANASTASIS_REDUCER_ACTION_INVALID,
- "select_country");
+ TALER_EC_ANASTASIS_REDUCER_INPUT_INVALID,
+ "arguments missing");
return NULL;
}
-
- json_t *root;
- json_t *provider_list;
- char *dn;
- json_error_t error;
- json_t *country;
- const char *currency;
- const json_t *redux_id_attr;
-
country = json_object_get (arguments,
"country_code");
- GNUNET_assert (NULL != country);
+ if (NULL == country)
+ {
+ ANASTASIS_redux_fail_ (cb,
+ cb_cls,
+ TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
+ "'country_code' missing");
+ return NULL;
+ }
currency = json_string_value (json_object_get (arguments,
"currency"));
- GNUNET_assert (NULL != currency);
- const char *s_mode = get_state_mode (state);
- GNUNET_assert (NULL != s_mode);
- redux_id_attr = redux_id_attr_init (json_string_value (country));
- root = json_object_get (redux_id_attr,
- "required_attributes");
- GNUNET_assert (NULL != root);
- GNUNET_assert (0 ==
- json_object_set_new (
- state,
- s_mode,
- json_string (
- ANASTASIS_generic_state_to_string_ (
- ANASTASIS_GENERIC_STATE_USER_ATTRIBUTES_COLLECTING))));
- GNUNET_assert (0 ==
- json_object_set_new (state,
- "selected_country",
- country));
- GNUNET_assert (0 ==
- json_object_set_new (state,
- "currency",
- json_string (currency)));
- GNUNET_assert (0 ==
- json_object_set_new (state,
- "required_attributes",
- root));
-
- // initialize provider list
+ if (NULL == currency)
{
- char *path;
-
- path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
- if (NULL == path)
- {
- GNUNET_break (0);
- return NULL;
- }
- GNUNET_asprintf (&dn,
- "%s/provider-list.json",
- path);
- GNUNET_free (path);
+ ANASTASIS_redux_fail_ (cb,
+ cb_cls,
+ TALER_EC_ANASTASIS_REDUCER_STATE_INVALID,
+ "'currency' missing");
+ return NULL;
}
- provider_list = json_load_file (dn, JSON_COMPACT, &error);
- if (NULL == provider_list)
+ redux_id_attr = redux_id_attr_init (json_string_value (country));
+ 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);
+ ANASTASIS_redux_fail_ (cb,
+ cb_cls,
+ TALER_EC_ANASTASIS_REDUCER_RESOURCE_MISSING,
+ json_string_value (country));
return NULL;
}
- GNUNET_free (dn);
-
- // get configs from providers
+ required_attrs = json_object_get (redux_id_attr,
+ "required_attributes");
+ if (NULL == required_attrs)
{
- struct SelectCountryHandle *sch;
- size_t index;
- json_t *provider;
- json_t *provider_arr = json_object_get (provider_list,
- "anastasis_provider");
- sch = GNUNET_new (struct SelectCountryHandle);
- sch->cb = cb;
- sch->cb_cls = cb_cls;
- sch->state = json_incref (state);
- json_array_foreach (provider_arr, index, provider)
- {
- const char *url = json_string_value (json_object_get (provider,
- "provider_url"));
- const char *provider_name = json_string_value (json_object_get (provider,
-
"provider_name"));
- const char *provider_id = json_string_value (json_object_get (provider,
-
"provider_id"));
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Url is: %s\n", url);
- check_config (url,
- provider_name,
- provider_id);
- }
- json_decref (provider_list);
-#if 0
- conclude_select_country (sch);
-#endif
- {
- struct ANASTASIS_ReduxAction *ra;
-
- ra = GNUNET_new (struct ANASTASIS_ReduxAction);
- ra->cleanup_cls = sch;
- ra->cleanup = free_select_country;
- return ra;
- }
+ ANASTASIS_redux_fail_ (cb,
+ cb_cls,
+ TALER_EC_ANASTASIS_REDUCER_RESOURCE_MALFORMED,
+ "'required_attributes' missing");
+ return NULL;
}
+ redux_transition (state,
+ ANASTASIS_GENERIC_STATE_USER_ATTRIBUTES_COLLECTING);
+ GNUNET_assert (0 ==
+ json_object_set (state,
+ "selected_country",
+ (json_t *) country));
+ GNUNET_assert (0 ==
+ json_object_set_new (state,
+ "currency",
+ json_string (currency)));
+ GNUNET_assert (0 ==
+ json_object_set (state,
+ "required_attributes",
+ (json_t *) required_attrs));
+ begin_provider_config_check (currency);
+ return NULL;
}
@@ -907,7 +819,7 @@ select_country (json_t *state,
*
* @param state state to operate on
* @param arguments arguments to use for operation on state
- * @param cb callback (#DispatchHandler) to call during/after operation
+ * @param cb callback to call during/after operation
* @param cb_cls callback closure
* @return NULL
*/
@@ -917,15 +829,8 @@ unselect_country (json_t *state,
ANASTASIS_ActionCallback cb,
void *cb_cls)
{
- const char *s_mode = get_state_mode (state);
- GNUNET_assert (NULL != s_mode);
- GNUNET_assert (0 ==
- json_object_set_new (
- state,
- s_mode,
- json_string (
- ANASTASIS_generic_state_to_string_ (
- ANASTASIS_GENERIC_STATE_COUNTRY_SELECTING))));
+ redux_transition (state,
+ ANASTASIS_GENERIC_STATE_COUNTRY_SELECTING);
cb (cb_cls,
TALER_EC_NONE,
state);
@@ -940,7 +845,7 @@ unselect_country (json_t *state,
*
* @param state state to operate on
* @param arguments arguments to use for operation on state
- * @param cb callback (#DispatchHandler) to call during/after operation
+ * @param cb callback to call during/after operation
* @param cb_cls callback closure
* @return NULL
*/
@@ -950,16 +855,8 @@ unselect_continent (json_t *state,
ANASTASIS_ActionCallback cb,
void *cb_cls)
{
- GNUNET_assert (NULL != state);
- const char *s_mode = get_state_mode (state);
- GNUNET_assert (NULL != s_mode);
- GNUNET_assert (0 ==
- json_object_set_new (
- state,
- s_mode,
- json_string (
- ANASTASIS_generic_state_to_string_ (
- ANASTASIS_GENERIC_STATE_CONTINENT_SELECTING))));
+ redux_transition (state,
+ ANASTASIS_GENERIC_STATE_CONTINENT_SELECTING);
cb (cb_cls,
TALER_EC_NONE,
state);
@@ -967,6 +864,116 @@ unselect_continent (json_t *state,
}
+#if 0
+/**
+ * Adds the server configuration from async #ConfigRequest
+ * to the json state.
+ *
+ * @param cr the config request
+ * @param state the json state to operate on
+ */
+static void
+add_config_to_state (struct ConfigRequest *cr,
+ json_t *state)
+{
+ json_t *method;
+ size_t index;
+ 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 (methods_list, index, method)
+ {
+ const char *method_type = json_string_value (json_object_get (method,
+ "method"));
+ json_t *ma_arr;
+ json_t *prov;
+ json_t *ma = json_object ();
+
+ if (NULL == (ma_arr = json_object_get (provider_list,
+ method_type)))
+ {
+ GNUNET_assert (0 ==
+ json_object_set_new (provider_list,
+ method_type,
+ ma_arr = json_array ()));
+ }
+ char *provider_salt = GNUNET_STRINGS_data_to_string_alloc (
+ &cr->backend_salt,
+ sizeof (struct
+ ANASTASIS_CRYPTO_PowSalt));
+ prov = json_pack ("{s:o, s:o, s:o, s:s, s:s, s:s}",
+ "method_cost",
+ json_object_get (method,
+ "cost"),
+ "annual_cost",
+ TALER_JSON_from_amount (&cr->backend_cost),
+ "insurance",
+ TALER_JSON_from_amount (&cr->backend_insurance),
+ "provider_url",
+ cr->backend_url,
+ "provider_name",
+ cr->backend_name,
+ "provider_salt",
+ provider_salt);
+ GNUNET_free (provider_salt);
+ GNUNET_assert (0 == json_object_set_new (ma,
+ cr->backend_id,
+ prov));
+ GNUNET_assert (0 == json_array_append_new (ma_arr, ma));
+ }
+}
+
+
+/**
+ * Function which collects all configurations from the different
+ * servers and calls the #ANASTASIS_ActionCallback.
+ *
+ * @param sch a handle to a country selection action
+ */
+static void
+conclude_select_country (struct SelectCountryHandle *sch)
+{
+ struct ConfigRequest *cr;
+ const char *currency;
+
+ currency = json_string_value (json_object_get (sch->state,
+ "currency"));
+ while (NULL != (cr = sch->cr_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (sch->cr_head,
+ sch->cr_tail,
+ cr);
+ if ( (MHD_HTTP_OK != cr->http_status) ||
+ (0 != strcmp (cr->backend_currency,
+ currency)) )
+ {
+ free_config_request (cr);
+ continue;
+ }
+ add_config_to_state (cr,
+ sch->state);
+ }
+ sch->cb (NULL,
+ TALER_EC_NONE,
+ sch->state);
+}
+
+
+#endif
+
+
static void
policy_lookup_cb (void *cls,
const struct ANASTASIS_RecoveryInformation *ri)
@@ -1102,6 +1109,7 @@ static void
delayed_abort (void *cls)
{
struct ANASTASIS_Recovery *recovery = cls;
+
ANASTASIS_recovery_abort (recovery);
}
@@ -1139,7 +1147,7 @@ free_enter_user_attributes (void *cls)
*
* @param state state to operate on
* @param arguments arguments to use for operation on state
- * @param cb callback (#DispatchHandler) to call during/after operation
+ * @param cb callback to call during/after operation
* @param cb_cls callback closure
* @return NULL
*/
@@ -1195,8 +1203,7 @@ enter_user_attributes (json_t *state,
"{s:I, s:s}",
"code",
(json_int_t)
- // FIXME: create EC for 'regex failed'
- TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ TALER_EC_ANASTASIS_REDUCER_INPUT_REGEX_FAILED,
"hint", regexp);
cb (cb_cls,
TALER_EC_INVALID,
@@ -1216,8 +1223,7 @@ enter_user_attributes (json_t *state,
"{s:I, s:s}",
"code",
(json_int_t)
- // FIXME: create EC for 'regex failed'
- TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ TALER_EC_ANASTASIS_REDUCER_INPUT_VALIDATION_FAILED,
"hint", reglog);
cb (cb_cls,
TALER_EC_INVALID,
@@ -1235,11 +1241,8 @@ enter_user_attributes (json_t *state,
if (0 == strcmp (s_mode, "backup_state"))
{
- json_object_set_new (state,
- s_mode,
- json_string (
- ANASTASIS_backup_state_to_string_ (
- ANASTASIS_BACKUP_STATE_AUTHENTICATIONS_EDITING)));
+ redux_transition (state,
+ ANASTASIS_BACKUP_STATE_AUTHENTICATIONS_EDITING);
if (NULL != auth_providers)
json_object_set_new (state,
"authentication_providers",
@@ -1268,11 +1271,8 @@ enter_user_attributes (json_t *state,
if (NULL != version)
rss->version = (unsigned int) json_integer_value (version);
rss->challenges_length = 0;
- json_object_set_new (state,
- s_mode,
- json_string (
- ANASTASIS_recovery_state_to_string_ (
- ANASTASIS_RECOVERY_STATE_CHALLENGE_SELECTING)));
+ redux_transition (state,
+ ANASTASIS_RECOVERY_STATE_CHALLENGE_SELECTING);
rss->state = json_incref (state);
rss->cb = cb;
rss->cb_cls = cb_cls;
@@ -1352,7 +1352,7 @@ enter_user_attributes (json_t *state,
*
* @param state state to operate on
* @param arguments arguments to use for operation on state
- * @param cb callback (#DispatchHandler) to call during/after operation
+ * @param cb callback to call during/after operation
* @param cb_cls callback closure
* @return NULL (no asynchronous action)
*/
@@ -1375,24 +1375,16 @@ ANASTASIS_back_generic_decrement_ (json_t *state,
state_index = ANASTASIS_backup_state_from_string_ (state_string);
GNUNET_assert (state_index > 0);
state_index = state_index - 1;
- GNUNET_assert (0 ==
- json_object_set_new (
- state,
- s_mode,
- json_string (
- ANASTASIS_generic_state_to_string_ (state_index))));
+ redux_transition (state,
+ state_index);
}
else
{
state_index = ANASTASIS_recovery_state_from_string_ (state_string);
GNUNET_assert (state_index > 0);
state_index = state_index - 1;
- GNUNET_assert (0 ==
- json_object_set_new (
- state,
- s_mode,
- json_string (
- ANASTASIS_generic_state_to_string_ (state_index))));
+ redux_transition (state,
+ state_index);
}
cb (cb_cls,
TALER_EC_NONE,
@@ -1401,6 +1393,23 @@ ANASTASIS_back_generic_decrement_ (json_t *state,
}
+/**
+ * Callback function which is called by the reducer in dependence of
+ * given state and action.
+ *
+ * @param state the previous state to operate on
+ * @param arguments the arguments needed by operation to operate on state
+ * @param cb Callback function which returns the new state
+ * @param cb_cls closure for @a cb
+ * @return handle to cancel async actions, NULL if @a cb was already called
+ */
+typedef struct ANASTASIS_ReduxAction *
+(*DispatchHandler)(json_t *state,
+ const json_t *arguments,
+ ANASTASIS_ActionCallback cb,
+ void *cb_cls);
+
+
/**
* Operates on a state depending on given #ANASTASIS_BackupState
* or #ANASTASIS_RecoveryState and #ANASTASIS_BackupAction or
diff --git a/src/reducer/validation_CH_AHV.c b/src/reducer/validation_CH_AHV.c
index 0718a88..ba5ff9e 100644
--- a/src/reducer/validation_CH_AHV.c
+++ b/src/reducer/validation_CH_AHV.c
@@ -1,3 +1,28 @@
+/*
+ This file is part of Anastasis
+ Copyright (C) 2020, 2021 Taler Systems SA
+
+ Anastasis is free software; you can redistribute it and/or modify it under
the
+ terms of the GNU Lesser General Public License as published by the Free
Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ Anastasis; see the file COPYING.GPL. If not, see
<http://www.gnu.org/licenses/>
+*/
+/**
+ * @file redux/validation_CH_AHV.c
+ * @brief anastasis reducer api
+ * @author Christian Grothoff
+ * @author Dominik Meister
+ * @author Dennis Neufeld
+ */
+#include <string.h>
+#include <stdbool.h>
+
/**
* Function to validate a Swiss AHV number.
*
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis] branch master updated: fix FTBFS,
gnunet <=