[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: fix #6754
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: fix #6754 |
Date: |
Sun, 04 Apr 2021 19:16:35 +0200 |
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 c744ea1 fix #6754
c744ea1 is described below
commit c744ea1fba6f7ca2f440f34b00d167000ef0361c
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Apr 4 19:16:32 2021 +0200
fix #6754
---
.../anastasis_authorization_plugin_email.c | 71 +++++++++++++++-----
.../anastasis_authorization_plugin_file.c | 76 ++++++++++++++++------
.../anastasis_authorization_plugin_post.c | 60 ++++++++++++-----
.../anastasis_authorization_plugin_sms.c | 64 +++++++++++++-----
4 files changed, 199 insertions(+), 72 deletions(-)
diff --git a/src/authorization/anastasis_authorization_plugin_email.c
b/src/authorization/anastasis_authorization_plugin_email.c
index 6cb5cb7..f5fdf26 100644
--- a/src/authorization/anastasis_authorization_plugin_email.c
+++ b/src/authorization/anastasis_authorization_plugin_email.c
@@ -243,7 +243,19 @@ email_process (struct ANASTASIS_AUTHORIZATION_State *as,
struct MHD_Connection *connection)
{
MHD_RESULT mres;
-
+ const char *mime;
+ const char *lang;
+
+ mime = MHD_lookup_connection_value (connection,
+ MHD_HEADER_KIND,
+ MHD_HTTP_HEADER_ACCEPT);
+ if (NULL == mime)
+ mime = "text/plain";
+ lang = MHD_lookup_connection_value (connection,
+ MHD_HEADER_KIND,
+ MHD_HTTP_HEADER_ACCEPT_LANGUAGE);
+ if (NULL == lang)
+ lang = "en";
if (NULL == as->msg)
{
/* First time, start child process and feed pipe */
@@ -290,6 +302,7 @@ email_process (struct ANASTASIS_AUTHORIZATION_State *as,
tpk = GNUNET_STRINGS_data_to_string_alloc (
&as->truth_uuid,
sizeof (as->truth_uuid));
+ /* FIXME #6749: i18n based on language preferences of the client */
GNUNET_asprintf (&as->msg,
"Subject: Anastasis recovery code: A-%llu\n\nThis is
for challenge %s.\n",
(unsigned long long) as->code,
@@ -362,36 +375,58 @@ email_process (struct ANASTASIS_AUTHORIZATION_State *as,
/* Build HTTP response */
{
struct MHD_Response *resp;
- size_t reply_len;
- char *reply;
const char *at;
size_t len;
- /* FIXME #6749: i18n based on language preferences of the client */
- /* FIXME #6754: Reply in JSON if requested by client */
at = strchr (as->email, '@');
if (NULL == at)
len = 0;
else
len = at - as->email;
- reply_len = GNUNET_asprintf (&reply,
- "Recovery TAN send to email %.*s@DOMAIN",
- (unsigned int) len,
- as->email);
- resp = MHD_create_response_from_buffer (reply_len,
- reply,
- MHD_RESPMEM_MUST_COPY);
- GNUNET_free (reply);
- TALER_MHD_add_global_headers (resp);
+
+ if (TALER_MHD_xmime_matches (mime,
+ "application/json"))
+ {
+ json_t *body;
+ char *user;
+
+ user = GNUNET_strndup (as->email,
+ len);
+ body = json_pack ("{s:s}",
+ "email_username",
+ user);
+ GNUNET_free (user);
+ GNUNET_break (NULL != body);
+ resp = TALER_MHD_make_json (body);
+ }
+ else
+ {
+ size_t reply_len;
+ char *reply;
+
+ /* FIXME #6749: i18n based on language preferences of the client */
+ reply_len = GNUNET_asprintf (&reply,
+ "Recovery TAN send to email %.*s@DOMAIN",
+ (unsigned int) len,
+ as->email);
+ resp = MHD_create_response_from_buffer (reply_len,
+ reply,
+ MHD_RESPMEM_MUST_COPY);
+ GNUNET_free (reply);
+ TALER_MHD_add_global_headers (resp);
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (resp,
+ MHD_HTTP_HEADER_CONTENT_TYPE,
+ "text/plain"));
+ }
mres = MHD_queue_response (connection,
MHD_HTTP_FORBIDDEN,
resp);
MHD_destroy_response (resp);
+ if (MHD_YES != mres)
+ return ANASTASIS_AUTHORIZATION_RES_SUCCESS_REPLY_FAILED;
+ return ANASTASIS_AUTHORIZATION_RES_SUCCESS;
}
-
- if (MHD_YES != mres)
- return ANASTASIS_AUTHORIZATION_RES_SUCCESS_REPLY_FAILED;
- return ANASTASIS_AUTHORIZATION_RES_SUCCESS;
}
diff --git a/src/authorization/anastasis_authorization_plugin_file.c
b/src/authorization/anastasis_authorization_plugin_file.c
index 8951537..0c88719 100644
--- a/src/authorization/anastasis_authorization_plugin_file.c
+++ b/src/authorization/anastasis_authorization_plugin_file.c
@@ -145,6 +145,19 @@ static enum ANASTASIS_AUTHORIZATION_Result
file_process (struct ANASTASIS_AUTHORIZATION_State *as,
struct MHD_Connection *connection)
{
+ const char *mime;
+ const char *lang;
+
+ mime = MHD_lookup_connection_value (connection,
+ MHD_HEADER_KIND,
+ MHD_HTTP_HEADER_ACCEPT);
+ if (NULL == mime)
+ mime = "text/plain";
+ lang = MHD_lookup_connection_value (connection,
+ MHD_HEADER_KIND,
+ MHD_HTTP_HEADER_ACCEPT_LANGUAGE);
+ if (NULL == lang)
+ lang = "en";
{
FILE *f = fopen (as->filename, "w");
@@ -189,28 +202,51 @@ file_process (struct ANASTASIS_AUTHORIZATION_State *as,
GNUNET_break (0 == fclose (f));
}
+ /* Build HTTP response */
{
struct MHD_Response *resp;
- size_t response_size;
- char *response;
- MHD_RESULT mres;
-
- /* FIXME #6749: i18n based on language preferences of the client */
- /* FIXME #6754: Reply in JSON if requested by client */
- response_size = GNUNET_asprintf (&response,
- "Challenge written to file");
- resp = MHD_create_response_from_buffer (response_size,
- response,
- MHD_RESPMEM_MUST_COPY);
- GNUNET_free (response);
- TALER_MHD_add_global_headers (resp);
- mres = MHD_queue_response (connection,
- MHD_HTTP_FORBIDDEN,
- resp);
- MHD_destroy_response (resp);
- if (MHD_YES != mres)
- return ANASTASIS_AUTHORIZATION_RES_SUCCESS_REPLY_FAILED;
- return ANASTASIS_AUTHORIZATION_RES_SUCCESS;
+
+ if (TALER_MHD_xmime_matches (mime,
+ "application/json"))
+ {
+ json_t *body;
+
+ body = json_pack ("{s:s}",
+ "filename",
+ as->filename);
+ GNUNET_break (NULL != body);
+ resp = TALER_MHD_make_json (body);
+ }
+ else
+ {
+ size_t response_size;
+ char *response;
+
+ /* FIXME #6749: i18n based on 'lang' (language preferences of the
client!) */
+ response_size = GNUNET_asprintf (&response,
+ "Challenge written to file");
+ resp = MHD_create_response_from_buffer (response_size,
+ response,
+ MHD_RESPMEM_MUST_COPY);
+ GNUNET_free (response);
+ TALER_MHD_add_global_headers (resp);
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (resp,
+ MHD_HTTP_HEADER_CONTENT_TYPE,
+ "text/plain"));
+ }
+
+ {
+ MHD_RESULT mres;
+
+ mres = MHD_queue_response (connection,
+ MHD_HTTP_FORBIDDEN,
+ resp);
+ MHD_destroy_response (resp);
+ if (MHD_YES != mres)
+ return ANASTASIS_AUTHORIZATION_RES_SUCCESS_REPLY_FAILED;
+ return ANASTASIS_AUTHORIZATION_RES_SUCCESS;
+ }
}
}
diff --git a/src/authorization/anastasis_authorization_plugin_post.c
b/src/authorization/anastasis_authorization_plugin_post.c
index f59eec3..5ff2892 100644
--- a/src/authorization/anastasis_authorization_plugin_post.c
+++ b/src/authorization/anastasis_authorization_plugin_post.c
@@ -278,6 +278,8 @@ static enum ANASTASIS_AUTHORIZATION_Result
post_process (struct ANASTASIS_AUTHORIZATION_State *as,
struct MHD_Connection *connection)
{
+ const char *mime;
+ const char *lang;
MHD_RESULT mres;
const char *name;
const char *street;
@@ -298,6 +300,16 @@ post_process (struct ANASTASIS_AUTHORIZATION_State *as,
GNUNET_JSON_spec_end ()
};
+ mime = MHD_lookup_connection_value (connection,
+ MHD_HEADER_KIND,
+ MHD_HTTP_HEADER_ACCEPT);
+ if (NULL == mime)
+ mime = "text/plain";
+ lang = MHD_lookup_connection_value (connection,
+ MHD_HEADER_KIND,
+ MHD_HTTP_HEADER_ACCEPT_LANGUAGE);
+ if (NULL == lang)
+ lang = "en";
if (GNUNET_OK !=
GNUNET_JSON_parse (as->post,
spec,
@@ -362,6 +374,7 @@ post_process (struct ANASTASIS_AUTHORIZATION_State *as,
tpk = GNUNET_STRINGS_data_to_string_alloc (
&as->truth_uuid,
sizeof (as->truth_uuid));
+ /* FIXME #6749: i18n based on language preferences of the client */
GNUNET_asprintf (&as->msg,
"Dear Customer\n\n"
"The Anastasis recovery code you need to\n"
@@ -439,28 +452,41 @@ post_process (struct ANASTASIS_AUTHORIZATION_State *as,
/* Build HTTP response */
{
struct MHD_Response *resp;
- size_t reply_len;
- char *reply;
-
- /* FIXME #6749: i18n based on language preferences of the client */
- /* FIXME #6754: Reply in JSON if requested by client */
- reply_len = GNUNET_asprintf (&reply,
- "Recovery message zip code %s",
- zip);
- resp = MHD_create_response_from_buffer (reply_len,
- reply,
- MHD_RESPMEM_MUST_COPY);
- GNUNET_free (reply);
- TALER_MHD_add_global_headers (resp);
+
+ if (TALER_MHD_xmime_matches (mime,
+ "application/json"))
+ {
+ json_t *body;
+
+ body = json_pack ("{s:s}",
+ "zip_code",
+ zip);
+ GNUNET_break (NULL != body);
+ resp = TALER_MHD_make_json (body);
+ }
+ else
+ {
+ size_t reply_len;
+ char *reply;
+
+ /* FIXME #6749: i18n based on language preferences of the client */
+ reply_len = GNUNET_asprintf (&reply,
+ "Recovery message zip code %s",
+ zip);
+ resp = MHD_create_response_from_buffer (reply_len,
+ reply,
+ MHD_RESPMEM_MUST_COPY);
+ GNUNET_free (reply);
+ TALER_MHD_add_global_headers (resp);
+ }
mres = MHD_queue_response (connection,
MHD_HTTP_FORBIDDEN,
resp);
MHD_destroy_response (resp);
+ if (MHD_YES != mres)
+ return ANASTASIS_AUTHORIZATION_RES_SUCCESS_REPLY_FAILED;
+ return ANASTASIS_AUTHORIZATION_RES_SUCCESS;
}
-
- if (MHD_YES != mres)
- return ANASTASIS_AUTHORIZATION_RES_SUCCESS_REPLY_FAILED;
- return ANASTASIS_AUTHORIZATION_RES_SUCCESS;
}
diff --git a/src/authorization/anastasis_authorization_plugin_sms.c
b/src/authorization/anastasis_authorization_plugin_sms.c
index 10c6ec6..45bafe9 100644
--- a/src/authorization/anastasis_authorization_plugin_sms.c
+++ b/src/authorization/anastasis_authorization_plugin_sms.c
@@ -242,7 +242,19 @@ sms_process (struct ANASTASIS_AUTHORIZATION_State *as,
struct MHD_Connection *connection)
{
MHD_RESULT mres;
-
+ const char *mime;
+ const char *lang;
+
+ mime = MHD_lookup_connection_value (connection,
+ MHD_HEADER_KIND,
+ MHD_HTTP_HEADER_ACCEPT);
+ if (NULL == mime)
+ mime = "text/plain";
+ lang = MHD_lookup_connection_value (connection,
+ MHD_HEADER_KIND,
+ MHD_HTTP_HEADER_ACCEPT_LANGUAGE);
+ if (NULL == lang)
+ lang = "en";
if (NULL == as->msg)
{
/* First time, start child process and feed pipe */
@@ -361,35 +373,53 @@ sms_process (struct ANASTASIS_AUTHORIZATION_State *as,
/* Build HTTP response */
{
struct MHD_Response *resp;
- size_t reply_len;
- char *reply;
const char *end;
size_t slen;
- /* FIXME #6749: i18n based on language preferences of the client */
- /* FIXME #6754: Reply in JSON if requested by client */
slen = strlen (as->phone_number);
if (slen > 4)
end = &as->phone_number[slen - 4];
else
end = &as->phone_number[slen / 2];
- reply_len = GNUNET_asprintf (&reply,
- "Recovery TAN send to phone number ending
with %s",
- end);
- resp = MHD_create_response_from_buffer (reply_len,
- reply,
- MHD_RESPMEM_MUST_COPY);
- GNUNET_free (reply);
- TALER_MHD_add_global_headers (resp);
+
+ if (TALER_MHD_xmime_matches (mime,
+ "application/json"))
+ {
+ json_t *body;
+
+ body = json_pack ("{s:s}",
+ "number_suffix",
+ end);
+ GNUNET_break (NULL != body);
+ resp = TALER_MHD_make_json (body);
+ }
+ else
+ {
+ size_t reply_len;
+ char *reply;
+
+ /* FIXME #6749: i18n based on language preferences of the client */
+ reply_len = GNUNET_asprintf (&reply,
+ "Recovery TAN send to phone number ending
with %s",
+ end);
+ resp = MHD_create_response_from_buffer (reply_len,
+ reply,
+ MHD_RESPMEM_MUST_COPY);
+ GNUNET_free (reply);
+ TALER_MHD_add_global_headers (resp);
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (resp,
+ MHD_HTTP_HEADER_CONTENT_TYPE,
+ "text/plain"));
+ }
mres = MHD_queue_response (connection,
MHD_HTTP_FORBIDDEN,
resp);
MHD_destroy_response (resp);
+ if (MHD_YES != mres)
+ return ANASTASIS_AUTHORIZATION_RES_SUCCESS_REPLY_FAILED;
+ return ANASTASIS_AUTHORIZATION_RES_SUCCESS;
}
-
- if (MHD_YES != mres)
- return ANASTASIS_AUTHORIZATION_RES_SUCCESS_REPLY_FAILED;
- return ANASTASIS_AUTHORIZATION_RES_SUCCESS;
}
--
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 #6754,
gnunet <=