[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis-gtk] branch master updated: fix mime-type confusion in
From: |
gnunet |
Subject: |
[taler-anastasis-gtk] branch master updated: fix mime-type confusion in 'instructions' of challenge |
Date: |
Sun, 04 Apr 2021 14:41:46 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository anastasis-gtk.
The following commit(s) were added to refs/heads/master by this push:
new 16a7605 fix mime-type confusion in 'instructions' of challenge
16a7605 is described below
commit 16a7605463a91cdbd152bd2474a4d6908f9d8c3c
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Apr 4 14:41:44 2021 +0200
fix mime-type confusion in 'instructions' of challenge
---
src/anastasis/anastasis-gtk_action.c | 300 ++++++++++++++++++++---------------
1 file changed, 173 insertions(+), 127 deletions(-)
diff --git a/src/anastasis/anastasis-gtk_action.c
b/src/anastasis/anastasis-gtk_action.c
index de03da2..171a9c8 100644
--- a/src/anastasis/anastasis-gtk_action.c
+++ b/src/anastasis/anastasis-gtk_action.c
@@ -17,7 +17,6 @@
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
-
/**
* @file src/anastasis/anastasis-gtk_action.c
* @brief Handle redux action results
@@ -649,8 +648,9 @@ action_authentications_editing (void)
* @param provider URL of provider
* @param type authentication method to look for
* @param[out] method_cost cost to return
+ * @return #GNUNET_OK on success
*/
-static void
+static int
lookup_recovery_cost (const char *provider,
const char *type,
struct TALER_Amount *method_cost)
@@ -672,7 +672,7 @@ lookup_recovery_cost (const char *provider,
if (NULL == ap)
{
GNUNET_break (0);
- return;
+ return GNUNET_SYSERR;
}
methods = json_object_get (ap,
"methods");
@@ -700,10 +700,11 @@ lookup_recovery_cost (const char *provider,
type))
{
*method_cost = fee;
- return;
+ return GNUNET_OK;
}
}
GNUNET_break (0);
+ return GNUNET_SYSERR;
}
@@ -799,9 +800,14 @@ action_policies_reviewing (void)
GNUNET_break (0);
continue;
}
- lookup_recovery_cost (provider,
- type,
- &method_cost);
+ if (GNUNET_OK !=
+ lookup_recovery_cost (provider,
+ type,
+ &method_cost))
+ {
+ GNUNET_break (0);
+ continue;
+ }
gtk_tree_store_insert_with_values (ts,
&miter,
&piter, /* parent */
@@ -1368,10 +1374,9 @@ get_challenge_offset (const char *uuid,
u))
{
*roff = off;
- lookup_recovery_cost (provider,
- type,
- cost);
- return GNUNET_OK;
+ return lookup_recovery_cost (provider,
+ type,
+ cost);
}
}
GNUNET_break (0);
@@ -1396,17 +1401,21 @@ translate_state (const char *state)
{ .in = "solved",
.out = _ ("challenge solved") },
{ .in = "payment",
- .out = _ ("payment required") },
- { .in = "instructions",
- .out = _ ("solution required") },
+ .out = _ ("make payment") },
+ { .in = "body",
+ .out = _ ("unexpected reply") },
+ { .in = "hint",
+ .out = _ ("read hint") },
+ { .in = "details",
+ .out = _ ("read feedback") },
{ .in = "redirect",
- .out = _ ("visit Web site") },
+ .out = _ ("open link") },
{ .in = "server-failure",
- .out = _ ("provider failure") },
+ .out = _ ("wait, provider failed") },
{ .in = "truth-unknown",
.out = _ ("challenge unknown") },
{ .in = "rate-limit-exceeded",
- .out = _ ("tries exceeded, wait") },
+ .out = _ ("wait, tries exceeded") },
{ .in = NULL,
.out = NULL }
};
@@ -1445,7 +1454,8 @@ show_challenge_feedback (void)
{
const char *state;
const char *redirect_url = NULL;
- const char *instructions = NULL;
+ const char *hint = NULL;
+ json_t *details = NULL;
const char *taler_pay_uri = NULL;
uint32_t ec = 0;
uint32_t http_status = 0;
@@ -1455,12 +1465,15 @@ show_challenge_feedback (void)
GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_string ("taler_pay_uri",
&taler_pay_uri)),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_json ("details",
+ &details)),
GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_string ("redirect_url",
&redirect_url)),
GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_string ("instructions",
- &instructions)),
+ GNUNET_JSON_spec_string ("hint",
+ &hint)),
GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_uint32 ("http_status",
&http_status)),
@@ -1491,6 +1504,7 @@ show_challenge_feedback (void)
&cost))
{
GNUNET_break (0);
+ GNUNET_JSON_parse_free (spec);
continue;
}
if (NULL != taler_pay_uri)
@@ -1502,8 +1516,14 @@ show_challenge_feedback (void)
if (TALER_EC_NONE != ec)
emsg = TALER_ErrorCode_get_hint (ec);
if (0 == strcmp (state,
- "instructions"))
- emsg = instructions; // FIXME: deal with JSON instructions nicely!
+ "hint"))
+ emsg = hint;
+ if (0 == strcmp (state,
+ "details"))
+ {
+ emsg = json_string_value (json_object_get (details,
+ "hint"));
+ }
gtk_list_store_insert_with_values (
ls,
NULL,
@@ -1521,6 +1541,7 @@ show_challenge_feedback (void)
AG_CSM_REDIRECT_URL, redirect_url,
AG_CSM_HAVE_REDIRECT, NULL != redirect_url,
-1);
+ GNUNET_JSON_parse_free (spec);
}
}
@@ -1723,9 +1744,15 @@ action_challenge_selecting (void)
return;
}
- lookup_recovery_cost (provider,
- type,
- &recovery_cost);
+ if (GNUNET_OK !=
+ lookup_recovery_cost (provider,
+ type,
+ &recovery_cost))
+ {
+ GNUNET_break_op (0);
+ AG_error ("Policy did not parse correctly");
+ return;
+ }
gtk_tree_store_insert_with_values (ts,
NULL,
&piter, /* parent */
@@ -1814,9 +1841,14 @@ action_challenge_selecting (void)
GNUNET_break (0);
continue;
}
- lookup_recovery_cost (provider,
- type,
- &cost);
+ if (GNUNET_OK !=
+ lookup_recovery_cost (provider,
+ type,
+ &cost))
+ {
+ GNUNET_break (0);
+ continue;
+ }
{
char *ins_str;
@@ -1971,27 +2003,42 @@ action_challenge_paying (void)
* @param builder a builder to get widgets from
* @param target_widget the widget to upate
* @param uuid_str the UUID to render feedback for
- * @param details the details to get feedback from
*/
static void
render_feedback (GtkBuilder *builder,
const char *target_widget,
- const char *uuid_str,
- const json_t *details)
+ const char *uuid_str)
{
json_t *cf;
json_t *cs;
const char *state;
- const char *instructions = NULL;
- uint32_t http_status;
+ const char *redirect_url = NULL;
+ const char *hint = NULL;
+ json_t *details = NULL;
+ const char *taler_pay_uri = NULL;
+ uint32_t ec = 0;
+ uint32_t http_status = 0;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_string ("state",
&state),
- GNUNET_JSON_spec_uint32 ("http_status",
- &http_status),
GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_string ("instructions",
- &instructions)),
+ GNUNET_JSON_spec_string ("taler_pay_uri",
+ &taler_pay_uri)),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_json ("details",
+ &details)),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("redirect_url",
+ &redirect_url)),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("hint",
+ &hint)),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_uint32 ("http_status",
+ &http_status)),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_uint32 ("error_code",
+ &ec)),
GNUNET_JSON_spec_end ()
};
GtkLabel *elabel;
@@ -2020,103 +2067,94 @@ render_feedback (GtkBuilder *builder,
gtk_label_set_text (elabel,
_ ("INTERNAL ERROR: could not parse state"));
gtk_widget_show (GTK_WIDGET (elabel));
+ return;
}
- else
+ if ( (0 == strcmp (state,
+ "hint")) &&
+ (NULL != hint) )
{
- if ( (0 == strcmp (state,
- "instructions")) &&
- (NULL != instructions) )
- {
- json_t *jdetail;
+ GNUNET_asprintf (&msg,
+ _ ("Hint (#%u): %s"),
+ (unsigned int) http_status,
+ hint);
+ }
+ else if ( (0 == strcmp (state,
+ "details")) &&
+ (NULL != details) )
+ {
+ uint32_t code;
+ const char *hint = NULL;
+ const char *detail = NULL;
+ struct GNUNET_JSON_Specification ispec[] = {
+ GNUNET_JSON_spec_uint32 ("code",
+ &code),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("hint",
+ &hint)),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("detail",
+ &detail)),
+ GNUNET_JSON_spec_end ()
+ };
- jdetail = json_loads (instructions,
- 0,
- NULL);
- if (NULL == jdetail)
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (details,
+ ispec,
+ NULL, NULL))
+ {
+ GNUNET_break (0);
+ msg = GNUNET_strdup (
+ _ ("ERROR: failed to parse server JSON instructions"));
+ }
+ else
+ {
+ const char *ihint;
+
+ ihint = TALER_ErrorCode_get_hint (code);
+ if ( (NULL != hint) &&
+ ( (NULL == ihint) ||
+ ('<' == ihint[0])) )
+ ihint = hint; /* use server hint */
+ if (NULL == detail)
{
- GNUNET_asprintf (&msg,
- _ ("Hint (#%u): %s"),
- (unsigned int) http_status,
- instructions);
+ if (NULL == ihint)
+ GNUNET_asprintf (&msg,
+ "Error #%u",
+ (unsigned int) code);
+ else
+ GNUNET_asprintf (&msg,
+ "Error #%u: %s",
+ (unsigned int) code,
+ ihint);
}
else
{
- uint32_t code;
- const char *hint = NULL;
- const char *detail = NULL;
- struct GNUNET_JSON_Specification ispec[] = {
- GNUNET_JSON_spec_uint32 ("code",
- &code),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_string ("hint",
- &hint)),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_string ("detail",
- &detail)),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (jdetail,
- ispec,
- NULL, NULL))
- {
- GNUNET_break (0);
- msg = GNUNET_strdup (
- _ ("ERROR: failed to parse server JSON instructions"));
- AG_show ("anastasis_gtk_c_code_error_label");
- }
+ if (NULL == ihint)
+ GNUNET_asprintf (&msg,
+ "Error #%u (%s)",
+ (unsigned int) code,
+ detail);
else
- {
- const char *ihint;
-
- ihint = TALER_ErrorCode_get_hint (code);
- if ( (NULL != hint) &&
- ( (NULL == ihint) ||
- ('<' == ihint[0])) )
- ihint = hint; /* use server hint */
- if (NULL == detail)
- {
- if (NULL == ihint)
- GNUNET_asprintf (&msg,
- "Error #%u",
- (unsigned int) code);
- else
- GNUNET_asprintf (&msg,
- "Error #%u: %s",
- (unsigned int) code,
- ihint);
- }
- else
- {
- if (NULL == ihint)
- GNUNET_asprintf (&msg,
- "Error #%u (%s)",
- (unsigned int) code,
- detail);
- else
- GNUNET_asprintf (&msg,
- "Error #%u: %s (%s)",
- (unsigned int) code,
- ihint,
- detail);
- }
- }
- json_decref (jdetail);
+ GNUNET_asprintf (&msg,
+ "Error #%u: %s (%s)",
+ (unsigned int) code,
+ ihint,
+ detail);
}
}
- else
- {
- GNUNET_asprintf (&msg,
- "ERROR: state `%s` with HTTP Status %u",
- state,
- (unsigned int) http_status);
- }
- gtk_label_set_text (elabel,
- msg);
- GNUNET_free (msg);
- gtk_widget_show (GTK_WIDGET (elabel));
}
+ else
+ {
+ GNUNET_asprintf (&msg,
+ "ERROR: state `%s` with HTTP Status %u",
+ state,
+ (unsigned int) http_status);
+ }
+ gtk_label_set_text (elabel,
+ msg);
+ GNUNET_free (msg);
+ gtk_widget_show (GTK_WIDGET (elabel));
+ GNUNET_JSON_parse_free (spec);
}
@@ -2160,13 +2198,18 @@ diag_question (const json_t *details)
"uuid"));
render_feedback (builder,
"anastasis_gtk_c_question_error_label",
- uuid_str,
- details);
+ uuid_str);
}
return ad;
}
+/**
+ * Create a dialog for the user to enter a PIN code.
+ *
+ * @param details details about the dialog to render
+ * @return dialog object
+ */
static GtkDialog *
diag_code (const json_t *details)
{
@@ -2202,8 +2245,7 @@ diag_code (const json_t *details)
uuid_str);
render_feedback (builder,
"anastasis_gtk_c_code_error_label",
- uuid_str,
- details);
+ uuid_str);
}
{
GtkDialog *ad;
@@ -2215,6 +2257,10 @@ diag_code (const json_t *details)
}
+/**
+ * The user wants to solve the selected challenge. Launch the
+ * dialog to allow the user to enter the solution.
+ */
static void
action_challenge_solving (void)
{
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis-gtk] branch master updated: fix mime-type confusion in 'instructions' of challenge,
gnunet <=