summaryrefslogtreecommitdiff
path: root/src/exchange
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-04-01 16:15:35 +0200
committerChristian Grothoff <christian@grothoff.org>2016-04-01 16:15:35 +0200
commitde3e26303e0069614d4a5aa425e4fa5ddb088b8b (patch)
tree982ba3095d80ec48a910dad15e3d886b36c6be24 /src/exchange
parent92907bee45681b1273172a3c88461a60bcae8589 (diff)
downloadexchange-de3e26303e0069614d4a5aa425e4fa5ddb088b8b.tar.gz
exchange-de3e26303e0069614d4a5aa425e4fa5ddb088b8b.tar.bz2
exchange-de3e26303e0069614d4a5aa425e4fa5ddb088b8b.zip
implementing #4356, tests still failing, but main logic should now be updated
Diffstat (limited to 'src/exchange')
-rw-r--r--src/exchange/taler-exchange-httpd.c16
-rw-r--r--src/exchange/taler-exchange-httpd_validation.c38
-rw-r--r--src/exchange/taler-exchange-httpd_validation.h9
-rw-r--r--src/exchange/taler-exchange-httpd_wire.c188
-rw-r--r--src/exchange/taler-exchange-httpd_wire.h37
5 files changed, 35 insertions, 253 deletions
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c
index 877876dbb..2ef58b0f7 100644
--- a/src/exchange/taler-exchange-httpd.c
+++ b/src/exchange/taler-exchange-httpd.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014, 2015 GNUnet e.V.
+ Copyright (C) 2014, 2015, 2016 Inria and GNUnet e.V.
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -177,20 +177,6 @@ handle_mhd_request (void *cls,
"Only GET is allowed", 0,
&TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED },
- { "/wire/test", MHD_HTTP_METHOD_GET, "application/json",
- NULL, 0,
- &TMH_WIRE_handler_wire_test, MHD_HTTP_FOUND },
- { "/wire/test", NULL, "text/plain",
- "Only GET is allowed", 0,
- &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED },
-
- { "/wire/sepa", MHD_HTTP_METHOD_GET, "application/json",
- NULL, 0,
- &TMH_WIRE_handler_wire_sepa, MHD_HTTP_OK },
- { "/wire/sepa", NULL, "text/plain",
- "Only GET is allowed", 0,
- &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED },
-
/* Withdrawing coins / interaction with reserves */
{ "/reserve/status", MHD_HTTP_METHOD_GET, "application/json",
NULL, 0,
diff --git a/src/exchange/taler-exchange-httpd_validation.c b/src/exchange/taler-exchange-httpd_validation.c
index b7e8a7f80..0b72960c5 100644
--- a/src/exchange/taler-exchange-httpd_validation.c
+++ b/src/exchange/taler-exchange-httpd_validation.c
@@ -200,33 +200,39 @@ TMH_VALIDATION_test_method (const char *type)
/**
- * Obtain supported validation methods as a JSON array,
- * and as a hash.
+ * Obtain JSON of the supported wire methods for a given
+ * account name prefix.
*
- * @param[out] h set to the hash of the JSON methods
+ * @param prefix prefix for the account, the suffix will
+ * be determined by the name of the plugin
* @return JSON array with the supported validation methods
*/
json_t *
-TMH_VALIDATION_get_methods (struct GNUNET_HashCode *h)
+TMH_VALIDATION_get_wire_methods (const char *prefix)
{
json_t *methods;
- struct GNUNET_HashContext *hc;
- const char *wf;
+ json_t *method;
struct Plugin *p;
+ struct TALER_WIRE_Plugin *plugin;
+ char *account_name;
- methods = json_array ();
- hc = GNUNET_CRYPTO_hash_context_start ();
+ methods = json_object ();
for (p=wire_head;NULL != p;p = p->next)
{
- wf = p->type;
- json_array_append_new (methods,
- json_string (wf));
- GNUNET_CRYPTO_hash_context_read (hc,
- wf,
- strlen (wf) + 1);
+ plugin = p->plugin;
+ GNUNET_asprintf (&account_name,
+ "%s-%s\n",
+ prefix,
+ p->type);
+ method = plugin->get_wire_details (plugin->cls,
+ cfg,
+ account_name);
+ if (NULL != method)
+ json_object_set_new (methods,
+ p->type,
+ method);
+ GNUNET_free (account_name);
}
- GNUNET_CRYPTO_hash_context_finish (hc,
- h);
return methods;
}
diff --git a/src/exchange/taler-exchange-httpd_validation.h b/src/exchange/taler-exchange-httpd_validation.h
index f41e2ee5f..a5403edd4 100644
--- a/src/exchange/taler-exchange-httpd_validation.h
+++ b/src/exchange/taler-exchange-httpd_validation.h
@@ -63,14 +63,15 @@ TMH_VALIDATION_test_method (const char *type);
/**
- * Obtain supported validation methods as a JSON array,
- * and as a hash.
+ * Obtain JSON of the supported wire methods for a given
+ * account name prefix.
*
- * @param[out] h set to the hash of the JSON methods
+ * @param prefix prefix for the account, the suffix will
+ * be determined by the name of the plugin
* @return JSON array with the supported validation methods
*/
json_t *
-TMH_VALIDATION_get_methods (struct GNUNET_HashCode *h);
+TMH_VALIDATION_get_wire_methods (const char *prefix);
#endif
diff --git a/src/exchange/taler-exchange-httpd_wire.c b/src/exchange/taler-exchange-httpd_wire.c
index 1b3d3b541..975788b35 100644
--- a/src/exchange/taler-exchange-httpd_wire.c
+++ b/src/exchange/taler-exchange-httpd_wire.c
@@ -43,191 +43,15 @@ TMH_WIRE_handler_wire (struct TMH_RequestHandler *rh,
const char *upload_data,
size_t *upload_data_size)
{
- struct TALER_ExchangeWireSupportMethodsPS wsm;
- struct TALER_ExchangePublicKeyP pub;
- struct TALER_ExchangeSignatureP sig;
- json_t *methods;
+ static json_t *wire_methods;
- wsm.purpose.size = htonl (sizeof (wsm));
- wsm.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_WIRE_TYPES);
- methods = TMH_VALIDATION_get_methods (&wsm.h_wire_types);
- TMH_KS_sign (&wsm.purpose,
- &pub,
- &sig);
- return TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_OK,
- "{s:o, s:o, s:o}",
- "methods", methods,
- "sig", GNUNET_JSON_from_data (&sig,
- sizeof (sig)),
- "pub", GNUNET_JSON_from_data (&pub,
- sizeof (pub)));
-}
-
-
-/**
- * Handle a "/wire/test" request.
- *
- * @param rh context of the handler
- * @param connection the MHD connection to handle
- * @param[in,out] connection_cls the connection's closure (can be updated)
- * @param upload_data upload data
- * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
- * @return MHD result code
- */
-int
-TMH_WIRE_handler_wire_test (struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size)
-{
- struct MHD_Response *response;
- int ret;
- char *bank_uri;
- unsigned long long account_number;
+ if (NULL == wire_methods)
+ wire_methods = TMH_VALIDATION_get_wire_methods ("wire-incoming");
- 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);
- if (GNUNET_NO == TMH_VALIDATION_test_method ("test"))
- {
- /* 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,
- "wire-test",
- "BANK_URI",
- &bank_uri))
- {
- /* oopsie, configuration error */
- MHD_destroy_response (response);
- return TMH_RESPONSE_reply_internal_error (connection,
- "BANK_URI not configured");
- }
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "wire-test",
- "BANK_ACCOUNT_NO_INCOMING",
- &account_number))
- {
- /* oopsie, configuration error */
- MHD_destroy_response (response);
- GNUNET_free (bank_uri);
- return TMH_RESPONSE_reply_internal_error (connection,
- "BANK_ACCOUNT_NO_INCOMING not configured");
- }
- ret = TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_OK,
- "{s:s, s:I, s:s}",
- "type", "test",
- "account_number", (json_int_t) account_number,
- "bank_uri", bank_uri);
- GNUNET_free (bank_uri);
- return ret;
+ return TMH_RESPONSE_reply_json (connection,
+ wire_methods,
+ MHD_HTTP_OK);
}
-/**
- * Handle a "/wire/sepa" request.
- *
- * @param rh context of the handler
- * @param connection the MHD connection to handle
- * @param[in,out] connection_cls the connection's closure (can be updated)
- * @param upload_data upload data
- * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
- * @return MHD result code
- */
-int
-TMH_WIRE_handler_wire_sepa (struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size)
-{
- struct MHD_Response *response;
- int ret;
- char *sepa_wire_file;
- int fd;
- struct stat sbuf;
-
- if (GNUNET_NO == TMH_VALIDATION_test_method ("sepa"))
- {
- /* 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_filename (cfg,
- "wire-sepa",
- "SEPA_RESPONSE_FILE",
- &sepa_wire_file))
- {
- return TMH_RESPONSE_reply_internal_error (connection,
- "SEPA_RESPONSE_FILE not configured");
- }
- fd = open (sepa_wire_file,
- O_RDONLY);
- if (-1 == fd)
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "open",
- sepa_wire_file);
- GNUNET_free (sepa_wire_file);
- return TMH_RESPONSE_reply_internal_error (connection,
- "Failed to open SEPA_RESPONSE_FILE");
- }
- if (0 != fstat (fd, &sbuf))
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "fstat",
- sepa_wire_file);
- (void) close (fd);
- GNUNET_free (sepa_wire_file);
- return TMH_RESPONSE_reply_internal_error (connection,
- "Failed to open SEPA_RESPONSE_FILE");
- }
- response = MHD_create_response_from_fd ((size_t) sbuf.st_size,
- fd);
- GNUNET_free (sepa_wire_file);
- if (NULL == response)
- {
- (void) close (fd);
- 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,
- rh->mime_type);
- ret = MHD_queue_response (connection,
- rh->response_code,
- response);
- MHD_destroy_response (response);
- return ret;
-}
-
/* end of taler-exchange-httpd_wire.c */
diff --git a/src/exchange/taler-exchange-httpd_wire.h b/src/exchange/taler-exchange-httpd_wire.h
index dc6dcc0f4..cf04f16ff 100644
--- a/src/exchange/taler-exchange-httpd_wire.h
+++ b/src/exchange/taler-exchange-httpd_wire.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014 GNUnet e.V.
+ Copyright (C) 2014, 2015, 2016 Inria and GNUnet e.V.
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -44,39 +44,4 @@ TMH_WIRE_handler_wire (struct TMH_RequestHandler *rh,
size_t *upload_data_size);
-/**
- * Handle a "/wire/test" request.
- *
- * @param rh context of the handler
- * @param connection the MHD connection to handle
- * @param[in,out] connection_cls the connection's closure (can be updated)
- * @param upload_data upload data
- * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
- * @return MHD result code
- */
-int
-TMH_WIRE_handler_wire_test (struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size);
-
-
-/**
- * Handle a "/wire/sepa" request.
- *
- * @param rh context of the handler
- * @param connection the MHD connection to handle
- * @param[in,out] connection_cls the connection's closure (can be updated)
- * @param upload_data upload data
- * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
- * @return MHD result code
- */
-int
-TMH_WIRE_handler_wire_sepa (struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size);
-
#endif