[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: fix continents loader
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: fix continents loader |
Date: |
Wed, 17 Feb 2021 13:15:33 +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 15b5edf fix continents loader
15b5edf is described below
commit 15b5edfdfe0a81b61e7178f7e8f9553fe0bf5171
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Wed Feb 17 13:15:31 2021 +0100
fix continents loader
---
src/reducer/anastasis_api_backup_redux.c | 90 ++++++++++--------------------
src/reducer/anastasis_api_recovery_redux.c | 63 ++++++---------------
src/reducer/anastasis_api_redux.c | 66 ++++++++++++++++++++++
src/reducer/anastasis_api_redux.h | 8 +++
4 files changed, 118 insertions(+), 109 deletions(-)
diff --git a/src/reducer/anastasis_api_backup_redux.c
b/src/reducer/anastasis_api_backup_redux.c
index 1043c4e..175061d 100644
--- a/src/reducer/anastasis_api_backup_redux.c
+++ b/src/reducer/anastasis_api_backup_redux.c
@@ -219,6 +219,8 @@ struct SecretShareState
json_t *state;
};
+
+// FIXME: all of these globals must die!
/**
* Generic container for an action with asynchronous activities.
*/
@@ -260,6 +262,7 @@ typedef struct ANASTASIS_ReduxAction *
void *cb_cls);
+// FIXME: this function should die
static const char *
get_provider_url_from_id (const char *id,
json_t *state)
@@ -290,14 +293,22 @@ get_provider_url_from_id (const char *id,
}
+/**
+ * Update the 'backup_state' field of @a state to @a new_backup_state.
+ *
+ * @param[in,out] state the state to transition
+ * @param new_backup_state the state to transition to
+ */
static void
set_state (json_t *state,
- const char *new_backup_state)
+ enum ANASTASIS_BackupState new_backup_state)
{
- GNUNET_assert (0 ==
- json_object_set_new (state,
- "backup_state",
- json_string (new_backup_state)));
+ GNUNET_assert (
+ 0 ==
+ json_object_set_new (
+ state,
+ "backup_state",
+ json_string (ANASTASIS_backup_state_to_string_ (new_backup_state))));
}
@@ -311,45 +322,13 @@ json_t *
ANASTASIS_backup_start (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
json_t *initial_state;
- json_t *temp_country;
- size_t index;
- json_t *root;
- json_t *continents = json_array ();
- const json_t *redux_countries = ANASTASIS_redux_countries_init_ ();
-
- GNUNET_assert (NULL != redux_countries);
- root = json_object_get (redux_countries,
- "countries");
- GNUNET_assert (NULL != root);
-
- json_array_foreach (root, index, temp_country)
- {
- size_t inner_index;
- json_t *inner_continent;
- json_t *continent = json_object_get (json_array_get (root, index),
- "continent");
- bool existing = false;
- json_array_foreach (continents, inner_index, inner_continent)
- {
- if (1 == json_equal (continent,
- inner_continent))
- {
- existing = true;
- break;
- }
- }
- if (! existing)
- json_array_append_new (continents,
- continent);
- }
- initial_state = json_pack ("{s:s, s:o}",
- "backup_state",
- ANASTASIS_generic_state_to_string_ (
- ANASTASIS_BACKUP_STATE_CONTINENT_SELECTING),
- "continents",
- continents);
- GNUNET_assert (NULL != initial_state);
+ (void) cfg;
+ initial_state = ANASTASIS_REDUX_load_continents_ ();
+ if (NULL == initial_state)
+ return NULL;
+ set_state (initial_state,
+ ANASTASIS_BACKUP_STATE_CONTINENT_SELECTING);
return initial_state;
}
@@ -716,8 +695,7 @@ done_authentication (json_t *state,
"policies",
pb.policies));
set_state (state,
- ANASTASIS_backup_state_to_string_ (
- ANASTASIS_BACKUP_STATE_POLICIES_REVIEWING));
+ ANASTASIS_BACKUP_STATE_POLICIES_REVIEWING);
cb (cb_cls,
TALER_EC_NONE,
state);
@@ -1129,7 +1107,6 @@ initialize_truths (json_t *state)
/**
* DispatchHandler/Callback function which is called for a
* "done_policy_review" action.
- * Returns an #ANASTASIS_ReduxAction if operation is async.
*
* @param state state to operate on
* @param arguments arguments to use for operation on state
@@ -1143,11 +1120,8 @@ done_policy_review (json_t *state,
ANASTASIS_ActionCallback cb,
void *cb_cls)
{
- GNUNET_assert (NULL != state);
set_state (state,
- ANASTASIS_backup_state_to_string_ (
- ANASTASIS_BACKUP_STATE_SECRET_EDITING));
-
+ ANASTASIS_BACKUP_STATE_SECRET_EDITING);
GNUNET_assert (0 ==
json_object_set (state,
"truths",
@@ -1454,8 +1428,7 @@ secret_share_payment_cb (void *cls,
sss->payment_order_id = GNUNET_strdup (pd.order_id);
TALER_MERCHANT_parse_pay_uri_free (&pd);
set_state (sss->state,
- ANASTASIS_backup_state_to_string_ (
- ANASTASIS_BACKUP_STATE_POLICIES_PAYING));
+ ANASTASIS_BACKUP_STATE_POLICIES_PAYING);
if (check_uploads (rec_doc_uploads, false))
{
sss->cb (sss->cb_cls,
@@ -1513,8 +1486,7 @@ secret_share_result_cb (void *cls,
if (check_uploads (rec_doc_uploads, true))
{
set_state (sss->state,
- ANASTASIS_backup_state_to_string_ (
- ANASTASIS_BACKUP_STATE_BACKUP_FINISHED));
+ ANASTASIS_BACKUP_STATE_BACKUP_FINISHED);
sss->cb (sss->cb_cls,
TALER_EC_NONE,
sss->state);
@@ -1703,8 +1675,7 @@ truth_upload_cb (void *cls,
}
set_state (tus->state,
- ANASTASIS_backup_state_to_string_ (
- ANASTASIS_BACKUP_STATE_POLICIES_PAYING));
+ ANASTASIS_BACKUP_STATE_POLICIES_PAYING);
tus->cb (tus->cb_cls,
TALER_EC_NONE,
tus->state);
@@ -2068,7 +2039,6 @@ pay_backup (json_t *state,
/**
* DispatchHandler/Callback function which is called for a
* "back" action if state is "FINISHED".
- * Returns an #ANASTASIS_ReduxAction if operation is async.
*
* @param state state to operate on
* @param arguments arguments to use for operation on state
@@ -2082,12 +2052,8 @@ back_finished (json_t *state,
ANASTASIS_ActionCallback cb,
void *cb_cls)
{
- // FIXME: implement
- GNUNET_assert (NULL != state);
set_state (state,
- ANASTASIS_backup_state_to_string_ (
- ANASTASIS_BACKUP_STATE_SECRET_EDITING));
-
+ ANASTASIS_BACKUP_STATE_SECRET_EDITING);
cb (cb_cls,
TALER_EC_NONE,
state);
diff --git a/src/reducer/anastasis_api_recovery_redux.c
b/src/reducer/anastasis_api_recovery_redux.c
index d442270..c5b0d92 100644
--- a/src/reducer/anastasis_api_recovery_redux.c
+++ b/src/reducer/anastasis_api_recovery_redux.c
@@ -150,12 +150,14 @@ struct ChallengeState
static void
set_state (json_t *state,
- const char *new_backup_state)
+ enum ANASTASIS_RecoveryState new_recovery_state)
{
- GNUNET_assert (0 ==
- json_object_set_new (state,
- "recovery_state",
- json_string (new_backup_state)));
+ GNUNET_assert (
+ 0 ==
+ json_object_set_new (
+ state,
+ "recovery_state",
+ json_string (ANASTASIS_recovery_state_to_string_ (new_recovery_state))));
}
@@ -230,8 +232,7 @@ challenge_payment_cb (void *cls,
cs->payment_order_id);
set_state (cs->state,
- ANASTASIS_recovery_state_to_string_ (
- ANASTASIS_RECOVERY_STATE_CHALLENGE_PAYING));
+ ANASTASIS_RECOVERY_STATE_CHALLENGE_PAYING);
recovery_information = json_object_get (cs->state,
"recovery_information");
@@ -279,8 +280,7 @@ challenge_start_cb (void *cls,
else
{
set_state (cs->state,
- ANASTASIS_recovery_state_to_string_ (
- ANASTASIS_RECOVERY_STATE_CHALLENGE_SOLVING));
+ ANASTASIS_RECOVERY_STATE_CHALLENGE_SOLVING);
}
ci = ANASTASIS_challenge_get_details (cs->c);
GNUNET_assert (NULL != ci);
@@ -319,43 +319,13 @@ json_t *
ANASTASIS_recovery_start (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
json_t *initial_state;
- json_t *temp_country;
- size_t index;
- json_t *root;
- json_t *continents = json_array ();
- const json_t *redux_countries = ANASTASIS_redux_countries_init_ ();
- GNUNET_assert (NULL != redux_countries);
- root = json_object_get (redux_countries, "countries");
- GNUNET_assert (NULL != root);
-
- json_array_foreach (root, index, temp_country)
- {
- size_t inner_index;
- json_t *inner_continent;
- json_t *continent = json_object_get (json_array_get (root, index),
- "continent");
- bool existing = false;
-
- json_array_foreach (continents, inner_index, inner_continent)
- {
- if (1 == json_equal (continent,
- inner_continent))
- {
- existing = true;
- break;
- }
- }
- if (! existing)
- json_array_append_new (continents, continent);
- }
- initial_state = json_pack ("{s:s, s:o}",
- "recovery_state",
- ANASTASIS_generic_state_to_string_ (
- ANASTASIS_RECOVERY_STATE_CONTINENT_SELECTING),
- "continents",
- continents);
- GNUNET_assert (NULL != initial_state);
+ (void) cfg;
+ initial_state = ANASTASIS_REDUX_load_continents_ ();
+ if (NULL == initial_state)
+ return NULL;
+ set_state (initial_state,
+ ANASTASIS_RECOVERY_STATE_CONTINENT_SELECTING);
return initial_state;
}
@@ -589,8 +559,7 @@ challenge_answer_cb (void *af_cls,
// = GNUNET_new (struct RecoverSecretState);
// FIXME: implement -> call recovery begin again
set_state (cs->state,
- ANASTASIS_recovery_state_to_string_ (
- ANASTASIS_RECOVERY_STATE_RECOVERY_FINISHED));
+ ANASTASIS_RECOVERY_STATE_RECOVERY_FINISHED);
}
}
diff --git a/src/reducer/anastasis_api_redux.c
b/src/reducer/anastasis_api_redux.c
index c9ce3b1..f6468a3 100644
--- a/src/reducer/anastasis_api_redux.c
+++ b/src/reducer/anastasis_api_redux.c
@@ -1430,3 +1430,69 @@ ANASTASIS_redux_action_cancel (struct
ANASTASIS_ReduxAction *ra)
ra->cleanup (ra->cleanup_cls);
GNUNET_free (ra);
}
+
+
+json_t *
+ANASTASIS_REDUX_load_continents_ ()
+{
+ json_t *countries;
+ json_t *continents;
+ const json_t *redux_countries = ANASTASIS_redux_countries_init_ ();
+
+ if (NULL == redux_countries)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ countries = json_object_get (redux_countries,
+ "countries");
+ if (NULL == countries)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ continents = json_array ();
+ GNUNET_assert (NULL != continents);
+
+ {
+ json_t *country;
+ size_t index;
+
+ json_array_foreach (countries, index, country)
+ {
+ bool existing = false;
+ json_t *continent;
+
+ continent = json_object_get (country,
+ "continent");
+ if ( (NULL == continent) ||
+ (! json_is_string (continent)) )
+ {
+ GNUNET_break (0);
+ continue;
+ }
+
+ {
+ size_t inner_index;
+ json_t *inner_continent;
+
+ json_array_foreach (continents, inner_index, inner_continent)
+ {
+ if (1 == json_equal (continent,
+ inner_continent))
+ {
+ existing = true;
+ break;
+ }
+ }
+ }
+ if (! existing)
+ GNUNET_assert (0 ==
+ json_array_append (continents,
+ continent));
+ }
+ }
+ return json_pack ("{s:o}",
+ "continents",
+ continents);
+}
diff --git a/src/reducer/anastasis_api_redux.h
b/src/reducer/anastasis_api_redux.h
index df4fd2f..c914e8f 100644
--- a/src/reducer/anastasis_api_redux.h
+++ b/src/reducer/anastasis_api_redux.h
@@ -96,6 +96,14 @@ void
ANASTASIS_redux_done (void);
+/**
+ * Produce an initial state with an initialized list of
+ * continents.
+ */
+json_t *
+ANASTASIS_REDUX_load_continents_ (void);
+
+
/**
* Returns the enum value to a string value of a state.
*
--
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 continents loader,
gnunet <=