aboutsummaryrefslogtreecommitdiff
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)
701} 701}
702 702
703 703
704/**
705 * Function called with the results of #ANASTASIS_redux_action on "poll_providers".
706 *
707 * @param cls NULL
708 * @param error_code Error code
709 * @param response new state as result or config information of a provider
710 */
711static void
712long_poll_providers_action_cb (void *cls,
713 enum TALER_ErrorCode error_code,
714 json_t *response);
715
716
717/**
718 * Schedules the specified action.
719 *
720 * @param cls NULL
721 */
722static void
723long_poll_providers_task (void *cls)
724{
725 struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_PROVIDERS];
726 json_t *tspec;
727
728 (void) cls;
729 la->task = NULL;
730 if (GNUNET_TIME_absolute_is_future (la->next_time))
731 {
732 la->task = GNUNET_SCHEDULER_add_at (la->next_time,
733 &long_poll_providers_task,
734 NULL);
735 return;
736 }
737 la->next_time = GNUNET_TIME_relative_to_absolute (LP_TIMEOUT);
738 tspec = GNUNET_JSON_PACK (
739 GNUNET_JSON_pack_time_rel ("timeout",
740 LP_TIMEOUT));
741 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
742 "Starting long polling task for provider configurations\n");
743 la->ra = ANASTASIS_redux_action (AG_redux_state,
744 "poll_providers",
745 tspec,
746 &long_poll_providers_action_cb,
747 NULL);
748 json_decref (tspec);
749}
750
751
752/**
753 * Check if all providers we care about are ready,
754 * and if not try to long poll them.
755 *
756 * @return false if we have no providers at all
757 */
758static bool
759sync_providers (void)
760{
761 struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_PROVIDERS];
762 json_t *ap;
763 const char *url;
764 json_t *obj;
765 bool ready = false;
766 bool poll = false;
767
768 ap = json_object_get (AG_redux_state,
769 "authentication_providers");
770 json_object_foreach (ap, url, obj)
771 {
772 struct ANASTASIS_CRYPTO_ProviderSaltP provider_salt;
773 enum GNUNET_GenericReturnValue ret;
774
775 ret = ANASTASIS_reducer_lookup_salt (AG_redux_state,
776 url,
777 &provider_salt);
778 switch (ret)
779 {
780 case GNUNET_OK:
781 ready = true;
782 break;
783 case GNUNET_NO:
784 poll = true;
785 break;
786 case GNUNET_SYSERR:
787 GNUNET_break (0);
788 break;
789 }
790 }
791 if (poll)
792 {
793 la->next_time = GNUNET_TIME_UNIT_ZERO_ABS;
794 la->task = GNUNET_SCHEDULER_add_now (&long_poll_providers_task,
795 NULL);
796 }
797 return ready || poll;
798}
799
800
801/**
802 * Allow the user to configure authorization methods from
803 * the set of methods offered by known providers.
804 */
704static void 805static void
705action_authentications_editing (void) 806action_authentications_editing (void)
706{ 807{
@@ -709,6 +810,7 @@ action_authentications_editing (void)
709 810
710 AG_hide_all_frames (); 811 AG_hide_all_frames ();
711 AG_insensitive_children ("anastasis_gtk_auth_button_grid"); 812 AG_insensitive_children ("anastasis_gtk_auth_button_grid");
813 (void) sync_providers ();
712 aps = json_object_get (AG_redux_state, 814 aps = json_object_get (AG_redux_state,
713 "authentication_providers"); 815 "authentication_providers");
714 { 816 {
@@ -765,7 +867,7 @@ action_authentications_editing (void)
765 activate_by_method (methods); 867 activate_by_method (methods);
766 break; 868 break;
767 default: 869 default:
768 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 870 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
769 "Status of provider `%s' is %u/%u\n", 871 "Status of provider `%s' is %u/%u\n",
770 provider_url, 872 provider_url,
771 (unsigned int) ec, 873 (unsigned int) ec,
@@ -2007,54 +2109,6 @@ long_poll_sync_action_cb (void *cls,
2007 2109
2008 2110
2009/** 2111/**
2010 * Function called with the results of #ANASTASIS_redux_action on "poll_providers".
2011 *
2012 * @param cls NULL
2013 * @param error_code Error code
2014 * @param response new state as result or config information of a provider
2015 */
2016static void
2017long_poll_providers_action_cb (void *cls,
2018 enum TALER_ErrorCode error_code,
2019 json_t *response);
2020
2021
2022/**
2023 * Schedules the specified action.
2024 *
2025 * @param cls NULL
2026 */
2027static void
2028long_poll_providers_task (void *cls)
2029{
2030 struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_PROVIDERS];
2031 json_t *tspec;
2032
2033 (void) cls;
2034 la->task = NULL;
2035 if (GNUNET_TIME_absolute_is_future (la->next_time))
2036 {
2037 la->task = GNUNET_SCHEDULER_add_at (la->next_time,
2038 &long_poll_providers_task,
2039 NULL);
2040 return;
2041 }
2042 la->next_time = GNUNET_TIME_relative_to_absolute (LP_TIMEOUT);
2043 tspec = GNUNET_JSON_PACK (
2044 GNUNET_JSON_pack_time_rel ("timeout",
2045 LP_TIMEOUT));
2046 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2047 "Starting long polling task for provider configurations\n");
2048 la->ra = ANASTASIS_redux_action (AG_redux_state,
2049 "poll_providers",
2050 tspec,
2051 &long_poll_providers_action_cb,
2052 NULL);
2053 json_decref (tspec);
2054}
2055
2056
2057/**
2058 * Start policy discovery process. Triggers download(s) 2112 * Start policy discovery process. Triggers download(s)
2059 * of the various provider configurations and (once we 2113 * of the various provider configurations and (once we
2060 * have any) starts the policy discovery process. 2114 * have any) starts the policy discovery process.
@@ -2088,11 +2142,27 @@ long_poll_providers_action_cb (void *cls,
2088 NULL); 2142 NULL);
2089 return; 2143 return;
2090 } 2144 }
2091 GNUNET_assert (NULL != AG_pd);
2092 /* Find out which provider is new, merge that one! */
2093 ap = json_object_get (response, 2145 ap = json_object_get (response,
2094 "authentication_providers"); 2146 "authentication_providers");
2095 GNUNET_assert (NULL != ap); 2147 GNUNET_assert (NULL != ap);
2148 if (NULL == AG_pd)
2149 {
2150 json_t *ns;
2151
2152 /* Simply merge the state */
2153 ap = json_object_get (response,
2154 "authentication_providers");
2155 ns = json_incref (AG_redux_state);
2156 json_object_set (ns,
2157 "authentication_providers",
2158 ap);
2159 AG_action_cb (NULL,
2160 TALER_EC_NONE,
2161 ns);
2162 json_decref (ns);
2163 return;
2164 }
2165 /* Find out which provider is new, merge that one! */
2096 json_object_foreach (ap, url, obj) 2166 json_object_foreach (ap, url, obj)
2097 { 2167 {
2098 struct ANASTASIS_CRYPTO_ProviderSaltP provider_salt; 2168 struct ANASTASIS_CRYPTO_ProviderSaltP provider_salt;
@@ -2120,55 +2190,21 @@ long_poll_providers_action_cb (void *cls,
2120static void 2190static void
2121begin_discovery (void) 2191begin_discovery (void)
2122{ 2192{
2123 struct ANASTASIS_LongAction *la = &AG_lacs[ANASTASIS_LP_POLL_PROVIDERS];
2124 GtkListStore *ls; 2193 GtkListStore *ls;
2125 json_t *ap; 2194 bool have_providers;
2126 const char *url;
2127 json_t *obj;
2128 bool ready = false;
2129 bool poll = false;
2130 2195
2131 ls = GTK_LIST_STORE (GCG_get_main_window_object ( 2196 ls = GTK_LIST_STORE (GCG_get_main_window_object (
2132 "secret_selection_liststore")); 2197 "secret_selection_liststore"));
2133 GNUNET_assert (NULL != ls); 2198 GNUNET_assert (NULL != ls);
2134 if (NULL == AG_pd) 2199 if (NULL == AG_pd)
2135 gtk_list_store_clear (ls); 2200 gtk_list_store_clear (ls);
2136 ap = json_object_get (AG_redux_state, 2201 have_providers = sync_providers ();
2137 "authentication_providers");
2138 json_object_foreach (ap, url, obj)
2139 {
2140 struct ANASTASIS_CRYPTO_ProviderSaltP provider_salt;
2141 enum GNUNET_GenericReturnValue ret;
2142
2143 ret = ANASTASIS_reducer_lookup_salt (AG_redux_state,
2144 url,
2145 &provider_salt);
2146 switch (ret)
2147 {
2148 case GNUNET_OK:
2149 ready = true;
2150 break;
2151 case GNUNET_NO:
2152 poll = true;
2153 break;
2154 case GNUNET_SYSERR:
2155 GNUNET_break (0);
2156 break;
2157 }
2158 }
2159 if (poll)
2160 {
2161 la->next_time = GNUNET_TIME_UNIT_ZERO_ABS;
2162 la->task = GNUNET_SCHEDULER_add_now (&long_poll_providers_task,
2163 NULL);
2164 }
2165 if (NULL == AG_pd) 2202 if (NULL == AG_pd)
2166 AG_pd = ANASTASIS_policy_discovery_start (AG_redux_state, 2203 AG_pd = ANASTASIS_policy_discovery_start (AG_redux_state,
2167 NULL, 2204 NULL,
2168 &expand_policy_list, 2205 &expand_policy_list,
2169 ls); 2206 ls);
2170 if ( (! ready) && 2207 if (! have_providers)
2171 (! poll) )
2172 { 2208 {
2173 AG_error (_ ("No available providers! Try to add one!")); 2209 AG_error (_ ("No available providers! Try to add one!"));
2174 } 2210 }