summaryrefslogtreecommitdiff
path: root/src/anastasis/anastasis-gtk_action.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/anastasis/anastasis-gtk_action.c')
-rw-r--r--src/anastasis/anastasis-gtk_action.c212
1 files changed, 124 insertions, 88 deletions
diff --git a/src/anastasis/anastasis-gtk_action.c b/src/anastasis/anastasis-gtk_action.c
index 05a4a86..0056e27 100644
--- a/src/anastasis/anastasis-gtk_action.c
+++ b/src/anastasis/anastasis-gtk_action.c
@@ -701,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)
{
@@ -709,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");
{
@@ -765,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,
@@ -2007,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.
@@ -2088,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;
@@ -2120,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!"));
}