aboutsummaryrefslogtreecommitdiff
path: root/src/mint/taler-mint-httpd_wire.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mint/taler-mint-httpd_wire.c')
-rw-r--r--src/mint/taler-mint-httpd_wire.c85
1 files changed, 62 insertions, 23 deletions
diff --git a/src/mint/taler-mint-httpd_wire.c b/src/mint/taler-mint-httpd_wire.c
index ee3b4ff0..1eb3f6be 100644
--- a/src/mint/taler-mint-httpd_wire.c
+++ b/src/mint/taler-mint-httpd_wire.c
@@ -45,25 +45,30 @@ TMH_WIRE_handler_wire (struct TMH_RequestHandler *rh,
struct TALER_MintPublicKeyP pub;
struct TALER_MintSignatureP sig;
json_t *methods;
+ struct GNUNET_HashContext *hc;
+ unsigned int i;
+ const char *wf;
+ methods = json_array ();
+ hc = GNUNET_CRYPTO_hash_context_start ();
+ for (i=0;NULL != (wf = TMH_expected_wire_formats[i]); i++)
+ {
+ json_array_append_new (methods,
+ json_string (wf));
+ GNUNET_CRYPTO_hash_context_read (hc,
+ wf,
+ strlen (wf) + 1);
+ }
wsm.purpose.size = htonl (sizeof (wsm));
wsm.purpose.purpose = htonl (TALER_SIGNATURE_MINT_WIRE_TYPES);
- GNUNET_CRYPTO_hash (TMH_expected_wire_format,
- strlen (TMH_expected_wire_format) + 1,
- &wsm.h_wire_types);
+ GNUNET_CRYPTO_hash_context_finish (hc,
+ &wsm.h_wire_types);
TMH_KS_sign (&wsm.purpose,
&pub,
&sig);
- methods = json_array ();
- /* NOTE: for now, we only support *ONE* wire format per
- mint instance; if we supply multiple, we need to
- add the strings for each type separately here -- and
- hash the 0-terminated strings above differently as well... */
- json_array_append_new (methods,
- json_string (TMH_expected_wire_format));
return TMH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_OK,
- "{s:s, s:o, s:o}",
+ "{s:o, s:o, s:o}",
"methods", methods,
"sig", TALER_json_from_data (&sig,
sizeof (sig)),
@@ -92,6 +97,7 @@ TMH_WIRE_handler_wire_test (struct TMH_RequestHandler *rh,
struct MHD_Response *response;
int ret;
char *wire_test_redirect;
+ unsigned int i;
response = MHD_create_response_from_buffer (0, NULL,
MHD_RESPMEM_PERSISTENT);
@@ -100,26 +106,35 @@ TMH_WIRE_handler_wire_test (struct TMH_RequestHandler *rh,
GNUNET_break (0);
return MHD_NO;
}
+ TMH_RESPONSE_add_global_headers (response);
+ for (i=0;NULL != TMH_expected_wire_formats[i];i++)
+ if (0 == strcasecmp ("test",
+ TMH_expected_wire_formats[i]))
+ break;
+ if (NULL == TMH_expected_wire_formats[i])
+ {
+ /* Return 501: not implemented */
+ ret = MHD_queue_response (connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ response);
+ MHD_destroy_response (response);
+ return ret;
+ }
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"mint-wire-test",
"REDIRECT_URL",
&wire_test_redirect))
{
- ret = MHD_queue_response (connection,
- MHD_HTTP_NOT_IMPLEMENTED,
- response);
+ /* oopsie, configuration error */
MHD_destroy_response (response);
- return ret;
+ return TMH_RESPONSE_reply_internal_error (connection,
+ "REDIRECT_URL not configured");
}
MHD_add_response_header (response,
MHD_HTTP_HEADER_LOCATION,
wire_test_redirect);
GNUNET_free (wire_test_redirect);
- if (NULL != rh->mime_type)
- (void) MHD_add_response_header (response,
- MHD_HTTP_HEADER_CONTENT_TYPE,
- rh->mime_type);
ret = MHD_queue_response (connection,
rh->response_code,
response);
@@ -150,12 +165,35 @@ TMH_WIRE_handler_wire_sepa (struct TMH_RequestHandler *rh,
char *sepa_wire_file;
int fd;
struct stat sbuf;
+ unsigned int i;
+ for (i=0;NULL != TMH_expected_wire_formats[i];i++)
+ if (0 == strcasecmp ("sepa",
+ TMH_expected_wire_formats[i]))
+ break;
+ if (NULL == TMH_expected_wire_formats[i])
+ {
+ /* Return 501: not implemented */
+ response = MHD_create_response_from_buffer (0, NULL,
+ MHD_RESPMEM_PERSISTENT);
+ if (NULL == response)
+ {
+ GNUNET_break (0);
+ return MHD_NO;
+ }
+ TMH_RESPONSE_add_global_headers (response);
+ ret = MHD_queue_response (connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ response);
+ MHD_destroy_response (response);
+ return ret;
+ }
+ /* Fetch reply */
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "mint-wire-sepa",
- "SEPA_RESPONSE_FILE",
- &sepa_wire_file))
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "mint-wire-sepa",
+ "SEPA_RESPONSE_FILE",
+ &sepa_wire_file))
{
return TMH_RESPONSE_reply_internal_error (connection,
"SEPA_RESPONSE_FILE not configured");
@@ -190,6 +228,7 @@ TMH_WIRE_handler_wire_sepa (struct TMH_RequestHandler *rh,
GNUNET_break (0);
return MHD_NO;
}
+ TMH_RESPONSE_add_global_headers (response);
if (NULL != rh->mime_type)
(void) MHD_add_response_header (response,
MHD_HTTP_HEADER_CONTENT_TYPE,