diff options
Diffstat (limited to 'src/anastasis/anastasis-gtk_action.c')
-rw-r--r-- | src/anastasis/anastasis-gtk_action.c | 262 |
1 files changed, 150 insertions, 112 deletions
diff --git a/src/anastasis/anastasis-gtk_action.c b/src/anastasis/anastasis-gtk_action.c index c13885a..a30f60d 100644 --- a/src/anastasis/anastasis-gtk_action.c +++ b/src/anastasis/anastasis-gtk_action.c @@ -132,12 +132,9 @@ action_continent_selecting (void) continent) { const char *name; - const char *name_i18n; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ("name", &name), - TALER_JSON_spec_i18n_str ("name", - &name_i18n), GNUNET_JSON_spec_end () }; @@ -157,7 +154,8 @@ action_continent_selecting (void) AG_CMC_CONTINENT_NAME, name, AG_CMC_CONTINENT_NAME_I18N, - name_i18n, + dgettext ("anastasis", + name), -1); GNUNET_JSON_parse_free (spec); } @@ -217,8 +215,8 @@ action_country_selecting (void) struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ("code", &code), - TALER_JSON_spec_i18n_str ("name", - &name), + GNUNET_JSON_spec_string ("name", + &name), GNUNET_JSON_spec_end () }; @@ -237,7 +235,8 @@ action_country_selecting (void) &iter, -1, AG_CCMC_COUNTRY_NAME, - name, + dgettext ("anastasis", + name), AG_CCMC_COUNTRY_CODE, code, -1); @@ -537,8 +536,8 @@ action_user_attributes_collecting (void) GNUNET_JSON_spec_string ("name", &attr_name), GNUNET_JSON_spec_mark_optional ( - TALER_JSON_spec_i18n_str ("label", - &attr_label), + GNUNET_JSON_spec_string ("label", + &attr_label), NULL), GNUNET_JSON_spec_end () }; @@ -571,9 +570,11 @@ action_user_attributes_collecting (void) if (optional) GNUNET_asprintf (&l, _ ("%s (optional)"), - attr_label); + dgettext ("anastasis", + attr_label)); else - l = GNUNET_strdup (attr_label); + l = GNUNET_strdup (dgettext ("anastasis", + attr_label)); if ( (NULL != widget_name) && (NULL != w) ) { @@ -700,6 +701,107 @@ activate_by_method (json_t *methods) } +/** + * Function called with the results of #ANASTASIS_redux_action on "poll_providers". + * + * @param cls NULL + * @param error_code Error code + * @param response new state as result or config information of a provider + */ +static void +long_poll_providers_action_cb (void *cls, + enum TALER_ErrorCode error_code, + json_t *response); + + +/** + * Schedules the specified action. + * + * @param cls NULL + */ +static void +long_poll_providers_task (void *cls) +{ + struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_PROVIDERS]; + json_t *tspec; + + (void) cls; + la->task = NULL; + if (GNUNET_TIME_absolute_is_future (la->next_time)) + { + la->task = GNUNET_SCHEDULER_add_at (la->next_time, + &long_poll_providers_task, + NULL); + return; + } + la->next_time = GNUNET_TIME_relative_to_absolute (LP_TIMEOUT); + tspec = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_time_rel ("timeout", + LP_TIMEOUT)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Starting long polling task for provider configurations\n"); + la->ra = ANASTASIS_redux_action (AG_redux_state, + "poll_providers", + tspec, + &long_poll_providers_action_cb, + NULL); + json_decref (tspec); +} + + +/** + * Check if all providers we care about are ready, + * and if not try to long poll them. + * + * @return false if we have no providers at all + */ +static bool +sync_providers (void) +{ + struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_PROVIDERS]; + json_t *ap; + const char *url; + json_t *obj; + bool ready = false; + bool poll = false; + + ap = json_object_get (AG_redux_state, + "authentication_providers"); + json_object_foreach (ap, url, obj) + { + struct ANASTASIS_CRYPTO_ProviderSaltP provider_salt; + enum GNUNET_GenericReturnValue ret; + + ret = ANASTASIS_reducer_lookup_salt (AG_redux_state, + url, + &provider_salt); + switch (ret) + { + case GNUNET_OK: + ready = true; + break; + case GNUNET_NO: + poll = true; + break; + case GNUNET_SYSERR: + GNUNET_break (0); + break; + } + } + if (poll) + { + la->next_time = GNUNET_TIME_UNIT_ZERO_ABS; + la->task = GNUNET_SCHEDULER_add_now (&long_poll_providers_task, + NULL); + } + return ready || poll; +} + + +/** + * Allow the user to configure authorization methods from + * the set of methods offered by known providers. + */ static void action_authentications_editing (void) { @@ -708,6 +810,7 @@ action_authentications_editing (void) AG_hide_all_frames (); AG_insensitive_children ("anastasis_gtk_auth_button_grid"); + (void) sync_providers (); aps = json_object_get (AG_redux_state, "authentication_providers"); { @@ -764,7 +867,7 @@ action_authentications_editing (void) activate_by_method (methods); break; default: - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Status of provider `%s' is %u/%u\n", provider_url, (unsigned int) ec, @@ -1673,7 +1776,7 @@ find_challenge_by_uuid (const char *uuid) rd = json_object_get (AG_redux_state, "recovery_document"); cs = json_object_get (rd, - "cs"); + "challenges"); json_array_foreach (cs, index, c) { const char *u; @@ -1809,6 +1912,7 @@ show_challenge_feedback (const char *uuid, * present in the state that was used to locate this version * @param server_time when did the provider receive the upload * @param secret_name name the user assigned to the backup + * @param providers json array of providers offering this policy */ static void expand_policy_list (void *cls, @@ -1817,14 +1921,15 @@ expand_policy_list (void *cls, uint32_t version, json_int_t attribute_mask, struct GNUNET_TIME_Timestamp server_time, - const char *secret_name) + const char *secret_name, + const json_t *providers) { GtkListStore *ls = cls; GtkTreeIter iter; - bool first; + bool have_first; - first = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ls), - &iter); + have_first = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ls), + &iter); gtk_list_store_insert_with_values ( ls, &iter, @@ -1835,8 +1940,9 @@ expand_policy_list (void *cls, AG_SSMC_SECRET_NAME, secret_name, AG_SSMC_POLICY_DATE_STRING, GNUNET_TIME_timestamp2s (server_time), AG_SSMC_POLICY_DATE_NUMERIC, (guint64) server_time.abs_time.abs_value_us, + AG_SSMC_POLICY_PROVIDER_JSON, (gpointer) providers, -1); - if (first) + if (! have_first) { GtkTreeSelection *selection; @@ -2003,54 +2109,6 @@ long_poll_sync_action_cb (void *cls, /** - * Function called with the results of #ANASTASIS_redux_action on "poll_providers". - * - * @param cls NULL - * @param error_code Error code - * @param response new state as result or config information of a provider - */ -static void -long_poll_providers_action_cb (void *cls, - enum TALER_ErrorCode error_code, - json_t *response); - - -/** - * Schedules the specified action. - * - * @param cls NULL - */ -static void -long_poll_providers_task (void *cls) -{ - struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_PROVIDERS]; - json_t *tspec; - - (void) cls; - la->task = NULL; - if (GNUNET_TIME_absolute_is_future (la->next_time)) - { - la->task = GNUNET_SCHEDULER_add_at (la->next_time, - &long_poll_providers_task, - NULL); - return; - } - la->next_time = GNUNET_TIME_relative_to_absolute (LP_TIMEOUT); - tspec = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_time_rel ("timeout", - LP_TIMEOUT)); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Starting long polling task for provider configurations\n"); - la->ra = ANASTASIS_redux_action (AG_redux_state, - "poll_providers", - tspec, - &long_poll_providers_action_cb, - NULL); - json_decref (tspec); -} - - -/** * Start policy discovery process. Triggers download(s) * of the various provider configurations and (once we * have any) starts the policy discovery process. @@ -2084,11 +2142,27 @@ long_poll_providers_action_cb (void *cls, NULL); return; } - GNUNET_assert (NULL != AG_pd); - /* Find out which provider is new, merge that one! */ ap = json_object_get (response, "authentication_providers"); GNUNET_assert (NULL != ap); + if (NULL == AG_pd) + { + json_t *ns; + + /* Simply merge the state */ + ap = json_object_get (response, + "authentication_providers"); + ns = json_incref (AG_redux_state); + json_object_set (ns, + "authentication_providers", + ap); + AG_action_cb (NULL, + TALER_EC_NONE, + ns); + json_decref (ns); + return; + } + /* Find out which provider is new, merge that one! */ json_object_foreach (ap, url, obj) { struct ANASTASIS_CRYPTO_ProviderSaltP provider_salt; @@ -2116,55 +2190,21 @@ long_poll_providers_action_cb (void *cls, static void begin_discovery (void) { - struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_PROVIDERS]; GtkListStore *ls; - json_t *ap; - const char *url; - json_t *obj; - bool ready = false; - bool poll = false; + bool have_providers; ls = GTK_LIST_STORE (GCG_get_main_window_object ( "secret_selection_liststore")); GNUNET_assert (NULL != ls); if (NULL == AG_pd) gtk_list_store_clear (ls); - ap = json_object_get (AG_redux_state, - "authentication_providers"); - json_object_foreach (ap, url, obj) - { - struct ANASTASIS_CRYPTO_ProviderSaltP provider_salt; - enum GNUNET_GenericReturnValue ret; - - ret = ANASTASIS_reducer_lookup_salt (AG_redux_state, - url, - &provider_salt); - switch (ret) - { - case GNUNET_OK: - ready = true; - break; - case GNUNET_NO: - poll = true; - break; - case GNUNET_SYSERR: - GNUNET_break (0); - break; - } - } - if (poll) - { - la->next_time = GNUNET_TIME_UNIT_ZERO_ABS; - la->task = GNUNET_SCHEDULER_add_now (&long_poll_providers_task, - NULL); - } + have_providers = sync_providers (); if (NULL == AG_pd) AG_pd = ANASTASIS_policy_discovery_start (AG_redux_state, NULL, &expand_policy_list, ls); - if ( (! ready) && - (! poll) ) + if (! have_providers) { AG_error (_ ("No available providers! Try to add one!")); } @@ -2296,7 +2336,7 @@ add_challenge (GtkBox *challenge_box, json_t *challenge; challenges = json_object_get (rd, - "cs"); + "challenges"); /* TODO: change data structure to have 'uuid' as the index into the 'challenges' object, instead of this 'challenges' being an array */ @@ -2468,7 +2508,8 @@ add_policy (GtkBox *policy_box, "Failed to process challenge #%u of policy #%u", (unsigned int) (1 + index), (unsigned int) (1 + pindex)); - AG_error (txt); + AG_error ("%s", + txt); GNUNET_free (txt); return false; } @@ -2525,7 +2566,7 @@ action_challenge_selecting (void) rd = json_object_get (AG_redux_state, "recovery_document"); policies = json_object_get (rd, - "dps"); + "decryption_policies"); GNUNET_assert (NULL != policies); policy_box = GTK_BOX (GCG_get_main_window_object ( "anastasis_gtk_policy_vbox")); @@ -2574,7 +2615,7 @@ action_challenge_selecting (void) "recovery_document"); GNUNET_assert (NULL != rd); challenges = json_object_get (rd, - "cs"); + "challenges"); GNUNET_assert (NULL != challenges); json_array_foreach (challenges, index, challenge) { @@ -2885,9 +2926,6 @@ render_feedback (GtkBuilder *builder, hide = true; type = "Hint"; break; - case TALER_EC_ANASTASIS_TRUTH_CHALLENGE_ACTIVE: - type = "Hint"; - break; default: break; } |