From d239c2f6dc034547daf2cee7d1737c592d59c7aa Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 26 Sep 2019 14:32:32 +0200 Subject: refactor to check for instance in one place, instead of in each handler --- src/backend/taler-merchant-httpd.c | 505 +++++++++++---------- src/backend/taler-merchant-httpd.h | 17 +- src/backend/taler-merchant-httpd_check-payment.c | 42 +- src/backend/taler-merchant-httpd_check-payment.h | 5 +- src/backend/taler-merchant-httpd_config.c | 25 +- src/backend/taler-merchant-httpd_config.h | 5 +- src/backend/taler-merchant-httpd_history.c | 16 +- src/backend/taler-merchant-httpd_history.h | 5 +- src/backend/taler-merchant-httpd_mhd.c | 33 +- src/backend/taler-merchant-httpd_mhd.h | 15 +- src/backend/taler-merchant-httpd_pay.c | 231 +++++----- src/backend/taler-merchant-httpd_pay.h | 5 +- src/backend/taler-merchant-httpd_proposal.c | 119 +++-- src/backend/taler-merchant-httpd_proposal.h | 8 +- src/backend/taler-merchant-httpd_refund.c | 63 +-- src/backend/taler-merchant-httpd_refund.h | 12 +- src/backend/taler-merchant-httpd_tip-authorize.c | 36 +- src/backend/taler-merchant-httpd_tip-authorize.h | 5 +- src/backend/taler-merchant-httpd_tip-pickup.c | 63 +-- src/backend/taler-merchant-httpd_tip-pickup.h | 11 +- src/backend/taler-merchant-httpd_tip-query.c | 37 +- src/backend/taler-merchant-httpd_tip-query.h | 5 +- .../taler-merchant-httpd_track-transaction.c | 165 +++---- .../taler-merchant-httpd_track-transaction.h | 5 +- src/backend/taler-merchant-httpd_track-transfer.c | 201 ++++---- src/backend/taler-merchant-httpd_track-transfer.h | 5 +- 26 files changed, 789 insertions(+), 850 deletions(-) (limited to 'src/backend') diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index 8e4db769..2864ef66 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -152,10 +152,10 @@ static mode_t unixpath_mode; /** - * Return GNUNET_YES if given a valid correlation ID and - * GNUNET_NO otherwise. + * Return #GNUNET_YES if given a valid correlation ID and + * #GNUNET_NO otherwise. * - * @returns GNUNET_YES iff given a valid correlation ID + * @returns #GNUNET_YES iff given a valid correlation ID */ static int is_valid_correlation_id (const char *correlation_id) @@ -169,249 +169,6 @@ is_valid_correlation_id (const char *correlation_id) } -/** - * A client has requested the given url using the given method - * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT, - * #MHD_HTTP_METHOD_DELETE, #MHD_HTTP_METHOD_POST, etc). The callback - * must call MHD callbacks to provide content to give back to the - * client and return an HTTP status code (i.e. #MHD_HTTP_OK, - * #MHD_HTTP_NOT_FOUND, etc.). - * - * @param cls argument given together with the function - * pointer when the handler was registered with MHD - * @param url the requested url - * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, - * #MHD_HTTP_METHOD_PUT, etc.) - * @param version the HTTP version string (i.e. - * #MHD_HTTP_VERSION_1_1) - * @param upload_data the data being uploaded (excluding HEADERS, - * for a POST that fits into memory and that is encoded - * with a supported encoding, the POST data will NOT be - * given in upload_data and is instead available as - * part of #MHD_get_connection_values; very large POST - * data *will* be made available incrementally in - * @a upload_data) - * @param upload_data_size set initially to the size of the - * @a upload_data provided; the method must update this - * value to the number of bytes NOT processed; - * @param con_cls pointer that the callback can set to some - * address and that will be preserved by MHD for future - * calls for this request; since the access handler may - * be called many times (i.e., for a PUT/POST operation - * with plenty of upload data) this allows the application - * to easily associate some request-specific state. - * If necessary, this state can be cleaned up in the - * global #MHD_RequestCompletedCallback (which - * can be set with the #MHD_OPTION_NOTIFY_COMPLETED). - * Initially, `*con_cls` will be NULL. - * @return #MHD_YES if the connection was handled successfully, - * #MHD_NO if the socket must be closed due to a serios - * error while handling the request - */ -static int -url_handler (void *cls, - struct MHD_Connection *connection, - const char *url, - const char *method, - const char *version, - const char *upload_data, - size_t *upload_data_size, - void **con_cls) -{ - static struct TMH_RequestHandler handlers[] = { - /* Landing page, tell humans to go away. */ - { "/", MHD_HTTP_METHOD_GET, "text/plain", - "Hello, I'm a merchant's Taler backend. This HTTP server is not for humans.\n", - 0, - &TMH_MHD_handler_static_response, MHD_HTTP_OK }, - { "/agpl", MHD_HTTP_METHOD_GET, "text/plain", - NULL, 0, - &TMH_MHD_handler_agpl_redirect, MHD_HTTP_FOUND }, - { "/public/pay", MHD_HTTP_METHOD_POST, "application/json", - NULL, 0, - &MH_handler_pay, MHD_HTTP_OK }, - { "/public/pay", NULL, "text/plain", - "Only POST is allowed", 0, - &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED }, - { "/track/transfer", MHD_HTTP_METHOD_GET, "application/json", - NULL, 0, - &MH_handler_track_transfer, MHD_HTTP_OK}, - { "/track/transfer", NULL, "text/plain", - "Only GET is allowed", 0, - &TMH_MHD_handler_static_response, MHD_HTTP_OK}, - { "/track/transaction", MHD_HTTP_METHOD_GET, "application/json", - NULL, 0, - &MH_handler_track_transaction, MHD_HTTP_OK}, - { "/track/transaction", NULL, "text/plain", - "Only GET is allowed", 0, - &TMH_MHD_handler_static_response, MHD_HTTP_OK}, - { "/history", MHD_HTTP_METHOD_GET, "text/plain", - "Only GET is allowed", 0, - &MH_handler_history, MHD_HTTP_OK}, - { "/order", MHD_HTTP_METHOD_POST, "application/json", - NULL, 0, - &MH_handler_proposal_put, MHD_HTTP_OK }, - { "/public/proposal", MHD_HTTP_METHOD_GET, "text/plain", - NULL, 0, - &MH_handler_proposal_lookup, MHD_HTTP_OK}, - { "/proposal", NULL, "text/plain", - "Only GET/POST are allowed", 0, - &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED }, - { "/refund", MHD_HTTP_METHOD_POST, "application/json", - NULL, 0, - &MH_handler_refund_increase, MHD_HTTP_OK}, - { "/public/refund", MHD_HTTP_METHOD_GET, "text/plain", - NULL, 0, - &MH_handler_refund_lookup, MHD_HTTP_OK}, - { "/refund", NULL, "application/json", - "Only POST/GET are allowed", 0, - &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED}, - { "/tip-authorize", MHD_HTTP_METHOD_POST, "text/plain", - NULL, 0, - &MH_handler_tip_authorize, MHD_HTTP_OK}, - { "/tip-authorize", NULL, "application/json", - "Only POST is allowed", 0, - &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED}, - { "/public/tip-pickup", MHD_HTTP_METHOD_POST, "text/plain", - NULL, 0, - &MH_handler_tip_pickup, MHD_HTTP_OK}, - { "/public/tip-pickup", MHD_HTTP_METHOD_GET, "text/plain", - NULL, 0, - &MH_handler_tip_pickup_get, MHD_HTTP_OK}, - { "/public/tip-pickup", NULL, "application/json", - "Only POST/GET are allowed", 0, - &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED}, - { "/tip-query", MHD_HTTP_METHOD_GET, "text/plain", - NULL, 0, - &MH_handler_tip_query, MHD_HTTP_OK}, - { "/check-payment", MHD_HTTP_METHOD_GET, "text/plain", - NULL, 0, - &MH_handler_check_payment, MHD_HTTP_OK}, - { "/config", MHD_HTTP_METHOD_GET, "text/plain", - NULL, 0, - &MH_handler_config, MHD_HTTP_OK}, - {NULL, NULL, NULL, NULL, 0, 0 } - }; - static struct TMH_RequestHandler h404 = { - "", NULL, "text/html", - "404: not found", 0, - &TMH_MHD_handler_static_response, MHD_HTTP_NOT_FOUND - }; - - struct TM_HandlerContext *hc = *con_cls; - struct GNUNET_AsyncScopeId aid; - const char *correlation_id = NULL; - char *instance_id; - const char *effective_url; - int ret; - - if (NULL == hc) - { - GNUNET_async_scope_fresh (&aid); - /* We only read the correlation ID on the first callback for every client */ - correlation_id = MHD_lookup_connection_value (connection, - MHD_HEADER_KIND, - "Taler-Correlation-Id"); - if ((NULL != correlation_id) && - (GNUNET_YES != is_valid_correlation_id (correlation_id))) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "illegal incoming correlation ID\n"); - correlation_id = NULL; - } - } - else - { - aid = hc->async_scope_id; - } - - GNUNET_SCHEDULER_begin_async_scope (&aid); - - if (NULL != correlation_id) - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Handling request for (%s) URL '%s', correlation_id=%s\n", - method, - url, - correlation_id); - else - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Handling request (%s) for URL '%s'\n", - method, - url); - - /* Find out the merchant backend instance for the request. - * If there is an instance, remove the instance specification - * from the beginning of the request URL. */ - { - const char *instance_prefix = "/instances/"; - - if (0 == strncmp (url, - instance_prefix, - strlen (instance_prefix))) - { - /* url starts with "/instances/" */ - const char *istart = url + strlen (instance_prefix); - const char *slash = strchr (istart, '/'); - - if (NULL == slash) - { - return TMH_MHD_handler_static_response (&h404, - connection, - con_cls, - upload_data, - upload_data_size, - NULL); - } - instance_id = GNUNET_strndup (istart, - slash - istart); - effective_url = slash; - } - else - { - effective_url = url; - instance_id = NULL; - } - } - - for (unsigned int i = 0; NULL != handlers[i].url; i++) - { - struct TMH_RequestHandler *rh = &handlers[i]; - - if ( (0 == strcasecmp (effective_url, - rh->url)) && - ( (NULL == rh->method) || - (0 == strcasecmp (method, - rh->method)) ) ) - { - ret = rh->handler (rh, - connection, - con_cls, - upload_data, - upload_data_size, - instance_id); - hc = *con_cls; - if (NULL != hc) - { - hc->rh = rh; - /* Store the async context ID, so we can restore it if - * we get another callack for this request. */ - hc->async_scope_id = aid; - } - GNUNET_free_non_null (instance_id); - return ret; - } - } - ret = TMH_MHD_handler_static_response (&h404, - connection, - con_cls, - upload_data, - upload_data_size, - instance_id); - GNUNET_free_non_null (instance_id); - return ret; -} - - /** * Callback that frees all the elements in the hashmap * @@ -1175,8 +932,8 @@ instances_iterator_cb (void *cls, * @param instance_id identifier of the instance to resolve * @return NULL if that instance is unknown to us */ -struct MerchantInstance * -TMH_lookup_instance (const char *instance_id) +static struct MerchantInstance * +lookup_instance (const char *instance_id) { struct GNUNET_HashCode h_instance; @@ -1251,6 +1008,257 @@ iterate_instances (const struct GNUNET_CONFIGURATION_Handle *config) } +/** + * A client has requested the given url using the given method + * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT, + * #MHD_HTTP_METHOD_DELETE, #MHD_HTTP_METHOD_POST, etc). The callback + * must call MHD callbacks to provide content to give back to the + * client and return an HTTP status code (i.e. #MHD_HTTP_OK, + * #MHD_HTTP_NOT_FOUND, etc.). + * + * @param cls argument given together with the function + * pointer when the handler was registered with MHD + * @param url the requested url + * @param method the HTTP method used (#MHD_HTTP_METHOD_GET, + * #MHD_HTTP_METHOD_PUT, etc.) + * @param version the HTTP version string (i.e. + * #MHD_HTTP_VERSION_1_1) + * @param upload_data the data being uploaded (excluding HEADERS, + * for a POST that fits into memory and that is encoded + * with a supported encoding, the POST data will NOT be + * given in upload_data and is instead available as + * part of #MHD_get_connection_values; very large POST + * data *will* be made available incrementally in + * @a upload_data) + * @param upload_data_size set initially to the size of the + * @a upload_data provided; the method must update this + * value to the number of bytes NOT processed; + * @param con_cls pointer that the callback can set to some + * address and that will be preserved by MHD for future + * calls for this request; since the access handler may + * be called many times (i.e., for a PUT/POST operation + * with plenty of upload data) this allows the application + * to easily associate some request-specific state. + * If necessary, this state can be cleaned up in the + * global #MHD_RequestCompletedCallback (which + * can be set with the #MHD_OPTION_NOTIFY_COMPLETED). + * Initially, `*con_cls` will be NULL. + * @return #MHD_YES if the connection was handled successfully, + * #MHD_NO if the socket must be closed due to a serios + * error while handling the request + */ +static int +url_handler (void *cls, + struct MHD_Connection *connection, + const char *url, + const char *method, + const char *version, + const char *upload_data, + size_t *upload_data_size, + void **con_cls) +{ + static struct TMH_RequestHandler handlers[] = { + /* Landing page, tell humans to go away. */ + { "/", MHD_HTTP_METHOD_GET, "text/plain", + "Hello, I'm a merchant's Taler backend. This HTTP server is not for humans.\n", + 0, + &TMH_MHD_handler_static_response, MHD_HTTP_OK }, + { "/agpl", MHD_HTTP_METHOD_GET, "text/plain", + NULL, 0, + &TMH_MHD_handler_agpl_redirect, MHD_HTTP_FOUND }, + { "/public/pay", MHD_HTTP_METHOD_POST, "application/json", + NULL, 0, + &MH_handler_pay, MHD_HTTP_OK }, + { "/public/pay", NULL, "text/plain", + "Only POST is allowed", 0, + &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED }, + { "/track/transfer", MHD_HTTP_METHOD_GET, "application/json", + NULL, 0, + &MH_handler_track_transfer, MHD_HTTP_OK}, + { "/track/transfer", NULL, "text/plain", + "Only GET is allowed", 0, + &TMH_MHD_handler_static_response, MHD_HTTP_OK}, + { "/track/transaction", MHD_HTTP_METHOD_GET, "application/json", + NULL, 0, + &MH_handler_track_transaction, MHD_HTTP_OK}, + { "/track/transaction", NULL, "text/plain", + "Only GET is allowed", 0, + &TMH_MHD_handler_static_response, MHD_HTTP_OK}, + { "/history", MHD_HTTP_METHOD_GET, "text/plain", + "Only GET is allowed", 0, + &MH_handler_history, MHD_HTTP_OK}, + { "/order", MHD_HTTP_METHOD_POST, "application/json", + NULL, 0, + &MH_handler_proposal_put, MHD_HTTP_OK }, + { "/public/proposal", MHD_HTTP_METHOD_GET, "text/plain", + NULL, 0, + &MH_handler_proposal_lookup, MHD_HTTP_OK}, + { "/proposal", NULL, "text/plain", + "Only GET/POST are allowed", 0, + &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED }, + { "/refund", MHD_HTTP_METHOD_POST, "application/json", + NULL, 0, + &MH_handler_refund_increase, MHD_HTTP_OK}, + { "/public/refund", MHD_HTTP_METHOD_GET, "text/plain", + NULL, 0, + &MH_handler_refund_lookup, MHD_HTTP_OK}, + { "/refund", NULL, "application/json", + "Only POST/GET are allowed", 0, + &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED}, + { "/tip-authorize", MHD_HTTP_METHOD_POST, "text/plain", + NULL, 0, + &MH_handler_tip_authorize, MHD_HTTP_OK}, + { "/tip-authorize", NULL, "application/json", + "Only POST is allowed", 0, + &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED}, + { "/public/tip-pickup", MHD_HTTP_METHOD_POST, "text/plain", + NULL, 0, + &MH_handler_tip_pickup, MHD_HTTP_OK}, + { "/public/tip-pickup", MHD_HTTP_METHOD_GET, "text/plain", + NULL, 0, + &MH_handler_tip_pickup_get, MHD_HTTP_OK}, + { "/public/tip-pickup", NULL, "application/json", + "Only POST/GET are allowed", 0, + &TMH_MHD_handler_send_json_pack_error, MHD_HTTP_METHOD_NOT_ALLOWED}, + { "/tip-query", MHD_HTTP_METHOD_GET, "text/plain", + NULL, 0, + &MH_handler_tip_query, MHD_HTTP_OK}, + { "/check-payment", MHD_HTTP_METHOD_GET, "text/plain", + NULL, 0, + &MH_handler_check_payment, MHD_HTTP_OK}, + { "/config", MHD_HTTP_METHOD_GET, "text/plain", + NULL, 0, + &MH_handler_config, MHD_HTTP_OK}, + {NULL, NULL, NULL, NULL, 0, 0 } + }; + static struct TMH_RequestHandler h404 = { + "", NULL, "text/html", + "404: not found", 0, + &TMH_MHD_handler_static_response, MHD_HTTP_NOT_FOUND + }; + + struct TM_HandlerContext *hc = *con_cls; + struct GNUNET_AsyncScopeId aid; + const char *correlation_id = NULL; + struct MerchantInstance *instance; + const char *effective_url; + int ret; + + if (NULL == hc) + { + GNUNET_async_scope_fresh (&aid); + /* We only read the correlation ID on the first callback for every client */ + correlation_id = MHD_lookup_connection_value (connection, + MHD_HEADER_KIND, + "Taler-Correlation-Id"); + if ((NULL != correlation_id) && + (GNUNET_YES != is_valid_correlation_id (correlation_id))) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "illegal incoming correlation ID\n"); + correlation_id = NULL; + } + } + else + { + aid = hc->async_scope_id; + } + + GNUNET_SCHEDULER_begin_async_scope (&aid); + + if (NULL != correlation_id) + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Handling request for (%s) URL '%s', correlation_id=%s\n", + method, + url, + correlation_id); + else + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Handling request (%s) for URL '%s'\n", + method, + url); + + /* Find out the merchant backend instance for the request. + * If there is an instance, remove the instance specification + * from the beginning of the request URL. */ + { + const char *instance_prefix = "/instances/"; + + if (0 == strncmp (url, + instance_prefix, + strlen (instance_prefix))) + { + /* url starts with "/instances/" */ + const char *istart = url + strlen (instance_prefix); + const char *slash = strchr (istart, '/'); + char *instance_id; + + if (NULL == slash) + { + return TMH_MHD_handler_static_response (&h404, + connection, + con_cls, + upload_data, + upload_data_size, + NULL); + } + instance_id = GNUNET_strndup (istart, + slash - istart); + instance = lookup_instance (instance_id); + GNUNET_free (instance_id); + effective_url = slash; + } + else + { + effective_url = url; + instance = lookup_instance (NULL); + } + } + if (NULL == instance) + return TMH_RESPONSE_reply_json_pack (connection, + MHD_HTTP_NOT_FOUND, + "{s:I, s:s}", + "code", + (json_int_t) TALER_EC_INSTANCE_UNKNOWN, + "error", + "merchant instance unknown"); + + for (unsigned int i = 0; NULL != handlers[i].url; i++) + { + struct TMH_RequestHandler *rh = &handlers[i]; + + if ( (0 == strcasecmp (effective_url, + rh->url)) && + ( (NULL == rh->method) || + (0 == strcasecmp (method, + rh->method)) ) ) + { + ret = rh->handler (rh, + connection, + con_cls, + upload_data, + upload_data_size, + instance); + hc = *con_cls; + if (NULL != hc) + { + hc->rh = rh; + /* Store the async context ID, so we can restore it if + * we get another callack for this request. */ + hc->async_scope_id = aid; + } + return ret; + } + } + return TMH_MHD_handler_static_response (&h404, + connection, + con_cls, + upload_data, + upload_data_size, + instance); +} + + /** * Main function that will be run by the scheduler. * @@ -1412,7 +1420,6 @@ run (void *cls, const char *choices[] = {"tcp", "unix", NULL}; - const char *serve_type; if (GNUNET_OK != diff --git a/src/backend/taler-merchant-httpd.h b/src/backend/taler-merchant-httpd.h index 4e939b96..c7046d87 100644 --- a/src/backend/taler-merchant-httpd.h +++ b/src/backend/taler-merchant-httpd.h @@ -62,7 +62,7 @@ struct IterateInstancesCls * Tells if the parsing encountered any error. We need this * field since the iterator must return void */ - unsigned int ret; + unsigned int ret; }; @@ -203,8 +203,7 @@ struct TMH_RequestHandler * @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 - * @param instance_id mechant backend instance ID, or NULL if no explicit - * instance has been specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int (*handler)(struct TMH_RequestHandler *rh, @@ -212,7 +211,7 @@ struct TMH_RequestHandler void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id); + struct MerchantInstance *mi); /** * Default response code. @@ -344,14 +343,4 @@ extern struct GNUNET_TIME_Relative default_pay_deadline; void TMH_trigger_daemon (void); -/** - * Lookup a merchant instance by its name. - * - * @param name name of the instance to resolve - * @return NULL if that instance is unknown to us - */ -struct MerchantInstance * -TMH_lookup_instance (const char *name); - - #endif diff --git a/src/backend/taler-merchant-httpd_check-payment.c b/src/backend/taler-merchant-httpd_check-payment.c index 2ba4cc4a..a77e731c 100644 --- a/src/backend/taler-merchant-httpd_check-payment.c +++ b/src/backend/taler-merchant-httpd_check-payment.c @@ -48,7 +48,7 @@ * if not a session-bound payment * @returns the URI, must be freed with #GNUNET_free */ -char * +static char * make_taler_pay_uri (struct MHD_Connection *connection, const char *instance_id, const char *order_id, @@ -66,7 +66,7 @@ make_taler_pay_uri (struct MHD_Connection *connection, "X-Forwarded-Host"); uri_path = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, - "X-Forwarded-Prefix"); + "X-Forwarded-Prefix"); if (NULL == uri_path) uri_path = "-"; @@ -259,15 +259,16 @@ check_order_and_request_payment (struct MHD_Connection *connection, TALER_JSON_hash (contract_terms, &h_contract_terms)) { - GNUNET_break (0); - json_decref (contract_terms); - return TMH_RESPONSE_reply_internal_error (connection, - TALER_EC_CHECK_PAYMENT_FAILED_COMPUTE_PROPOSAL_HASH, - "Failed to hash proposal"); + GNUNET_break (0); + json_decref (contract_terms); + return TMH_RESPONSE_reply_internal_error (connection, + TALER_EC_CHECK_PAYMENT_FAILED_COMPUTE_PROPOSAL_HASH, + "Failed to hash proposal"); } /* Offer was not picked up yet, but we ensured that it exists */ h_contract_terms_str = GNUNET_STRINGS_data_to_string_alloc (&h_contract_terms, - sizeof (struct GNUNET_HashCode)); + sizeof (struct + GNUNET_HashCode)); ret = send_pay_request (connection, order_id, final_contract_url, @@ -291,8 +292,7 @@ check_order_and_request_payment (struct MHD_Connection *connection, * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -301,7 +301,7 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id) + struct MerchantInstance *mi) { const char *order_id; const char *contract_url; @@ -309,7 +309,6 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, const char *fulfillment_url; char *final_contract_url; char *h_contract_terms_str; - struct MerchantInstance *mi; enum GNUNET_DB_QueryStatus qs; json_t *contract_terms; struct GNUNET_HashCode h_contract_terms; @@ -317,11 +316,6 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, int ret; int refunded; - mi = TMH_lookup_instance (instance_id); - if (NULL == mi) - return TMH_RESPONSE_reply_bad_request (connection, - TALER_EC_CHECK_PAYMENT_INSTANCE_UNKNOWN, - "merchant instance unknown"); order_id = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "order_id"); @@ -340,7 +334,7 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, { final_contract_url = TALER_url_absolute_mhd (connection, "/public/proposal", - "instance", instance_id, + "instance", mi->id, "order_id", order_id, NULL); GNUNET_assert (NULL != final_contract_url); @@ -350,8 +344,8 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, final_contract_url = GNUNET_strdup (contract_url); } session_id = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "session_id"); + MHD_GET_ARGUMENT_KIND, + "session_id"); db->preflight (db->cls); qs = db->find_contract_terms (db->cls, @@ -419,7 +413,8 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, } h_contract_terms_str = GNUNET_STRINGS_data_to_string_alloc (&h_contract_terms, - sizeof (struct GNUNET_HashCode)); + sizeof (struct + GNUNET_HashCode)); @@ -505,7 +500,7 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, } /* Accumulate refunds, if any. */ - for (unsigned int i=0;iget_refunds_from_contract_terms_hash (db->cls, &mi->pubkey, @@ -537,7 +532,8 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, "contract_terms", contract_terms, "paid", 1, "refunded", refunded, - "refund_amount", TALER_JSON_from_amount (&refund_amount)); + "refund_amount", TALER_JSON_from_amount ( + &refund_amount)); GNUNET_free (final_contract_url); return ret; } diff --git a/src/backend/taler-merchant-httpd_check-payment.h b/src/backend/taler-merchant-httpd_check-payment.h index 98fa3a11..2ff39d74 100644 --- a/src/backend/taler-merchant-httpd_check-payment.h +++ b/src/backend/taler-merchant-httpd_check-payment.h @@ -34,8 +34,7 @@ * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -44,6 +43,6 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id); + struct MerchantInstance *mi); #endif diff --git a/src/backend/taler-merchant-httpd_config.c b/src/backend/taler-merchant-httpd_config.c index 3e7b7b39..21fb55cc 100644 --- a/src/backend/taler-merchant-httpd_config.c +++ b/src/backend/taler-merchant-httpd_config.c @@ -39,8 +39,7 @@ * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -49,24 +48,12 @@ MH_handler_config (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id) + struct MerchantInstance *mi) { - int ret; - struct MerchantInstance *mi; - - mi = TMH_lookup_instance (instance_id); - - if (NULL == mi) - return TMH_RESPONSE_reply_bad_request (connection, - TALER_EC_CHECK_PAYMENT_INSTANCE_UNKNOWN, - "merchant instance unknown"); - - ret = TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_OK, - "{s:s}", - "currency", TMH_currency); - - return ret; + return TMH_RESPONSE_reply_json_pack (connection, + MHD_HTTP_OK, + "{s:s}", + "currency", TMH_currency); } /* end of taler-merchant-httpd_config.c */ diff --git a/src/backend/taler-merchant-httpd_config.h b/src/backend/taler-merchant-httpd_config.h index 08594a5f..43c987d9 100644 --- a/src/backend/taler-merchant-httpd_config.h +++ b/src/backend/taler-merchant-httpd_config.h @@ -31,8 +31,7 @@ * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -41,6 +40,6 @@ MH_handler_config (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id); + struct MerchantInstance *mi); #endif diff --git a/src/backend/taler-merchant-httpd_history.c b/src/backend/taler-merchant-httpd_history.c index 36ca7290..5db0fb61 100644 --- a/src/backend/taler-merchant-httpd_history.c +++ b/src/backend/taler-merchant-httpd_history.c @@ -122,8 +122,7 @@ pd_cb (void *cls, * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -132,7 +131,7 @@ MH_handler_history (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id) + struct MerchantInstance *mi) { #define LOG_INFO(...) GNUNET_log (GNUNET_ERROR_TYPE_INFO, __VA_ARGS__) const char *str; @@ -141,7 +140,6 @@ MH_handler_history (struct TMH_RequestHandler *rh, int ret; unsigned int ascending = GNUNET_NO; unsigned long long seconds; - struct MerchantInstance *mi; unsigned long long start = INT64_MAX; long long delta = -20; enum GNUNET_DB_QueryStatus qs; @@ -175,16 +173,6 @@ MH_handler_history (struct TMH_RequestHandler *rh, } } - mi = TMH_lookup_instance (instance_id); - - if (NULL == mi) - { - json_decref (response); - return TMH_RESPONSE_reply_not_found (connection, - TALER_EC_HISTORY_INSTANCE_UNKNOWN, - "instance"); - } - /* Sanity check that we don't have some odd stale transaction running */ db->preflight (db->cls); diff --git a/src/backend/taler-merchant-httpd_history.h b/src/backend/taler-merchant-httpd_history.h index 5ea2ed23..d9c1a20b 100644 --- a/src/backend/taler-merchant-httpd_history.h +++ b/src/backend/taler-merchant-httpd_history.h @@ -34,8 +34,7 @@ * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -44,7 +43,7 @@ MH_handler_history (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id); + struct MerchantInstance *mi); /* end of taler-merchant-httpd_history.c */ #endif diff --git a/src/backend/taler-merchant-httpd_mhd.c b/src/backend/taler-merchant-httpd_mhd.c index a17485cc..a80c8339 100644 --- a/src/backend/taler-merchant-httpd_mhd.c +++ b/src/backend/taler-merchant-httpd_mhd.c @@ -37,8 +37,7 @@ * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, could be NULL in this specific case! * @return MHD result code */ int @@ -47,11 +46,12 @@ TMH_MHD_handler_static_response (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id) + struct MerchantInstance *instance) { struct MHD_Response *response; int ret; + (void) instance; if (0 == rh->data_size) rh->data_size = strlen ((const char *) rh->data); response = MHD_create_response_from_buffer (rh->data_size, @@ -84,23 +84,23 @@ TMH_MHD_handler_static_response (struct TMH_RequestHandler *rh, * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL (but unused) * @return MHD result code */ int TMH_MHD_handler_agpl_redirect (struct TMH_RequestHandler *rh, - struct MHD_Connection *connection, - void **connection_cls, - const char *upload_data, - size_t *upload_data_size, - const char *instance_id) + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + struct MerchantInstance *mi) { const char *agpl = "This server is licensed under the Affero GPL. You will now be redirected to the source code."; struct MHD_Response *response; int ret; + (void) mi; response = MHD_create_response_from_buffer (strlen (agpl), (void *) agpl, MHD_RESPMEM_PERSISTENT); @@ -142,17 +142,16 @@ TMH_MHD_handler_agpl_redirect (struct TMH_RequestHandler *rh, * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int TMH_MHD_handler_send_json_pack_error (struct TMH_RequestHandler *rh, - struct MHD_Connection *connection, - void **connection_cls, - const char *upload_data, - size_t *upload_data_size, - const char *instance_id) + struct MHD_Connection *connection, + void **connection_cls, + const char *upload_data, + size_t *upload_data_size, + struct MerchantInstance *mi) { return TMH_RESPONSE_reply_json_pack (connection, rh->response_code, diff --git a/src/backend/taler-merchant-httpd_mhd.h b/src/backend/taler-merchant-httpd_mhd.h index 0ec9830b..6564922b 100644 --- a/src/backend/taler-merchant-httpd_mhd.h +++ b/src/backend/taler-merchant-httpd_mhd.h @@ -37,8 +37,7 @@ * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, NULL is allowed in this case! * @return MHD result code */ int @@ -47,7 +46,7 @@ TMH_MHD_handler_static_response (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id); + struct MerchantInstance *mi); /** @@ -59,8 +58,7 @@ TMH_MHD_handler_static_response (struct TMH_RequestHandler *rh, * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -69,7 +67,7 @@ TMH_MHD_handler_agpl_redirect (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id); + struct MerchantInstance *mi); /** @@ -104,8 +102,7 @@ TMH_MHD_helper_send_json_pack (struct TMH_RequestHandler *rh, * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -114,7 +111,7 @@ TMH_MHD_handler_send_json_pack_error (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id); + struct MerchantInstance *mi); #endif diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c index e72a8e25..f3775c26 100644 --- a/src/backend/taler-merchant-httpd_pay.c +++ b/src/backend/taler-merchant-httpd_pay.c @@ -41,7 +41,8 @@ /** * How long to wait before giving up processing with the exchange? */ -#define PAY_TIMEOUT (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)) +#define PAY_TIMEOUT (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ + 30)) /** * How often do we retry the (complex!) database transaction? @@ -452,7 +453,7 @@ abort_deposit (struct PayContext *pc) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Aborting pending /deposit operations\n"); - for (unsigned int i=0;icoins_cnt;i++) + for (unsigned int i = 0; icoins_cnt; i++) { struct DepositConfirmation *dci = &pc->dc[i]; @@ -490,9 +491,9 @@ sign_success_response (struct PayContext *pc) errmsg); { struct PaymentResponsePS mr = { - .purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_PAYMENT_OK), - .purpose.size = htonl (sizeof (mr)), - .h_contract_terms = pc->h_contract_terms + .purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_PAYMENT_OK), + .purpose.size = htonl (sizeof (mr)), + .h_contract_terms = pc->h_contract_terms }; GNUNET_CRYPTO_eddsa_sign (&pc->mi->privkey.eddsa_priv, @@ -553,7 +554,7 @@ pay_context_cleanup (struct TM_HandlerContext *hc) pc->timeout_task = NULL; } TMH_PARSE_post_cleanup_callback (pc->json_parse_context); - for (unsigned int i=0;icoins_cnt;i++) + for (unsigned int i = 0; icoins_cnt; i++) { struct DepositConfirmation *dc = &pc->dc[i]; @@ -627,7 +628,7 @@ check_payment_sufficient (struct PayContext *pc) * This loops calculates what are the deposit fee / total * amount with fee / and wire fee, for all the coins. */ - for (unsigned int i=1;icoins_cnt;i++) + for (unsigned int i = 1; icoins_cnt; i++) { struct DepositConfirmation *dc = &pc->dc[i]; @@ -658,7 +659,7 @@ check_payment_sufficient (struct PayContext *pc) { int new_exchange = GNUNET_YES; - for (unsigned int j=0;jexchange_url, pc->dc[j].exchange_url)) { @@ -730,7 +731,7 @@ check_payment_sufficient (struct PayContext *pc) GNUNET_assert (GNUNET_OK == TALER_amount_get_zero (total_wire_fee.currency, - &wire_fee_customer_contribution)); + &wire_fee_customer_contribution)); } /** @@ -762,8 +763,8 @@ check_payment_sufficient (struct PayContext *pc) GNUNET_assert (GNUNET_OK == TALER_amount_add (&total_needed, - &total_needed, - &wire_fee_customer_contribution)); + &total_needed, + &wire_fee_customer_contribution)); /* check if total payment sufficies */ if (-1 == TALER_amount_cmp (&acc_amount, @@ -790,8 +791,8 @@ check_payment_sufficient (struct PayContext *pc) GNUNET_assert (GNUNET_SYSERR != TALER_amount_subtract (&deposit_fee_savings, - &pc->max_fee, - &acc_fee)); + &pc->max_fee, + &acc_fee)); /* See how much of wire fee contribution is covered by @@ -803,8 +804,8 @@ check_payment_sufficient (struct PayContext *pc) GNUNET_assert (GNUNET_SYSERR != TALER_amount_subtract (&wire_fee_customer_contribution, - &wire_fee_customer_contribution, - &deposit_fee_savings)); + &wire_fee_customer_contribution, + &deposit_fee_savings)); /* subtract remaining wire fees from total contribution */ GNUNET_log (GNUNET_ERROR_TYPE_INFO, @@ -814,9 +815,9 @@ check_payment_sufficient (struct PayContext *pc) (&wire_fee_customer_contribution)); if (GNUNET_SYSERR == TALER_amount_subtract - (&acc_amount, - &acc_amount, - &wire_fee_customer_contribution)) + (&acc_amount, + &acc_amount, + &wire_fee_customer_contribution)) { GNUNET_break_op (0); return TALER_EC_PAY_PAYMENT_INSUFFICIENT_DUE_TO_FEES; @@ -980,12 +981,18 @@ deposit_cb (void *cls, /* We can't do anything meaningful here, the exchange did something wrong */ resume_pay_with_response (pc, MHD_HTTP_SERVICE_UNAVAILABLE, - TMH_RESPONSE_make_json_pack ("{s:s, s:I, s:I, s:I, s:s}", - "error", "exchange failed", - "code", (json_int_t) TALER_EC_PAY_EXCHANGE_FAILED, - "exchange-code", (json_int_t) ec, - "exchange-http-status", (json_int_t) http_status, - "hint", "The exchange provided an unexpected response")); + TMH_RESPONSE_make_json_pack ( + "{s:s, s:I, s:I, s:I, s:s}", + "error", + "exchange failed", + "code", + (json_int_t) TALER_EC_PAY_EXCHANGE_FAILED, + "exchange-code", + (json_int_t) ec, + "exchange-http-status", + (json_int_t) http_status, + "hint", + "The exchange provided an unexpected response")); } else { @@ -1103,7 +1110,7 @@ process_pay_with_exchange (void *cls, /* Initiate /deposit operation for all coins of the current exchange (!) */ GNUNET_assert (0 == pc->pending_at_ce); - for (unsigned int i=0;icoins_cnt;i++) + for (unsigned int i = 0; icoins_cnt; i++) { struct DepositConfirmation *dc = &pc->dc[i]; const struct TALER_EXCHANGE_DenomPublicKey *denom_details; @@ -1111,25 +1118,25 @@ process_pay_with_exchange (void *cls, if (GNUNET_YES == dc->found_in_db) continue; if (0 != strcmp (dc->exchange_url, - pc->current_exchange)) + pc->current_exchange)) continue; denom_details = TALER_EXCHANGE_get_denomination_key - (keys, - &dc->denom); + (keys, + &dc->denom); if (NULL == denom_details) { GNUNET_break_op (0); resume_pay_with_response (pc, - MHD_HTTP_BAD_REQUEST, - TMH_RESPONSE_make_json_pack - ("{s:s, s:I, s:o, s:o}", - "error", "denomination not found", - "code", TALER_EC_PAY_DENOMINATION_KEY_NOT_FOUND, - "denom_pub", GNUNET_JSON_from_rsa_public_key - (dc->denom.rsa_public_key), - "exchange_keys", TALER_EXCHANGE_get_keys_raw (mh))); + MHD_HTTP_BAD_REQUEST, + TMH_RESPONSE_make_json_pack + ("{s:s, s:I, s:o, s:o}", + "error", "denomination not found", + "code", TALER_EC_PAY_DENOMINATION_KEY_NOT_FOUND, + "denom_pub", GNUNET_JSON_from_rsa_public_key + (dc->denom.rsa_public_key), + "exchange_keys", TALER_EXCHANGE_get_keys_raw (mh))); return; } if (GNUNET_OK != @@ -1140,14 +1147,14 @@ process_pay_with_exchange (void *cls, GNUNET_break_op (0); resume_pay_with_response (pc, - MHD_HTTP_BAD_REQUEST, - TMH_RESPONSE_make_json_pack - ("{s:s, s:I, s:o}", - "error", "invalid denomination", - "code", (json_int_t) - TALER_EC_PAY_DENOMINATION_KEY_AUDITOR_FAILURE, - "denom_pub", GNUNET_JSON_from_rsa_public_key - (dc->denom.rsa_public_key))); + MHD_HTTP_BAD_REQUEST, + TMH_RESPONSE_make_json_pack + ("{s:s, s:I, s:o}", + "error", "invalid denomination", + "code", (json_int_t) + TALER_EC_PAY_DENOMINATION_KEY_AUDITOR_FAILURE, + "denom_pub", GNUNET_JSON_from_rsa_public_key + (dc->denom.rsa_public_key))); return; } @@ -1159,11 +1166,11 @@ process_pay_with_exchange (void *cls, GNUNET_assert (NULL != pc->wm->j_wire); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Timing for this payment, wire_deadline:" - " %llu, refund_deadline: %llu\n", - (unsigned long long) - pc->wire_transfer_deadline.abs_value_us, - (unsigned long long) pc->refund_deadline.abs_value_us); + "Timing for this payment, wire_deadline:" + " %llu, refund_deadline: %llu\n", + (unsigned long long) + pc->wire_transfer_deadline.abs_value_us, + (unsigned long long) pc->refund_deadline.abs_value_us); db->preflight (db->cls); dc->dh = TALER_EXCHANGE_deposit (mh, @@ -1187,13 +1194,13 @@ process_pay_with_exchange (void *cls, GNUNET_break_op (0); resume_pay_with_response (pc, - MHD_HTTP_UNAUTHORIZED, - TMH_RESPONSE_make_json_pack - ("{s:s, s:I, s:i}", - "hint", "Coin signature invalid.", - "code", (json_int_t) - TALER_EC_PAY_COIN_SIGNATURE_INVALID, - "coin_idx", i)); + MHD_HTTP_UNAUTHORIZED, + TMH_RESPONSE_make_json_pack + ("{s:s, s:I, s:i}", + "hint", "Coin signature invalid.", + "code", (json_int_t) + TALER_EC_PAY_COIN_SIGNATURE_INVALID, + "coin_idx", i)); return; } @@ -1211,7 +1218,7 @@ process_pay_with_exchange (void *cls, static void find_next_exchange (struct PayContext *pc) { - for (unsigned int i=0;icoins_cnt;i++) + for (unsigned int i = 0; icoins_cnt; i++) { struct DepositConfirmation *dc = &pc->dc[i]; @@ -1301,7 +1308,7 @@ check_coin_paid (void *cls, GNUNET_break (0); return; } - for (unsigned int i=0;icoins_cnt;i++) + for (unsigned int i = 0; icoins_cnt; i++) { struct DepositConfirmation *dc = &pc->dc[i]; @@ -1317,7 +1324,7 @@ check_coin_paid (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Coin (%s) already found in our DB.\n", TALER_b2s (coin_pub, - sizeof (*coin_pub))); + sizeof (*coin_pub))); if (GNUNET_OK != TALER_amount_add (&pc->total_paid, &pc->total_paid, @@ -1381,7 +1388,7 @@ parse_pay (struct MHD_Connection *connection, &order_id), GNUNET_JSON_spec_fixed_auto ("merchant_pub", &merchant_pub), - GNUNET_JSON_spec_end() + GNUNET_JSON_spec_end () }; enum GNUNET_DB_QueryStatus qs; const char *session_id; @@ -1488,7 +1495,7 @@ parse_pay (struct MHD_Connection *connection, &fulfillment_url), GNUNET_JSON_spec_fixed_auto ("H_wire", &pc->h_wire), - GNUNET_JSON_spec_end() + GNUNET_JSON_spec_end () }; res = TMH_PARSE_json_data (connection, @@ -1515,7 +1522,7 @@ parse_pay (struct MHD_Connection *connection, struct GNUNET_JSON_Specification wspec[] = { GNUNET_JSON_spec_relative_time ("wire_transfer_delay", &used_wire_transfer_delay), - GNUNET_JSON_spec_end() + GNUNET_JSON_spec_end () }; res = TMH_PARSE_json_data (connection, @@ -1533,7 +1540,8 @@ parse_pay (struct MHD_Connection *connection, = GNUNET_TIME_absolute_add (pc->timestamp, used_wire_transfer_delay); - if (pc->wire_transfer_deadline.abs_value_us < pc->refund_deadline.abs_value_us) + if (pc->wire_transfer_deadline.abs_value_us < + pc->refund_deadline.abs_value_us) { GNUNET_break (0); GNUNET_JSON_parse_free (spec); @@ -1569,7 +1577,7 @@ parse_pay (struct MHD_Connection *connection, struct GNUNET_JSON_Specification espec[] = { TALER_JSON_spec_amount ("max_wire_fee", &pc->max_wire_fee), - GNUNET_JSON_spec_end() + GNUNET_JSON_spec_end () }; res = TMH_PARSE_json_data (connection, @@ -1596,8 +1604,8 @@ parse_pay (struct MHD_Connection *connection, { struct GNUNET_JSON_Specification espec[] = { GNUNET_JSON_spec_uint32 ("wire_fee_amortization", - &pc->wire_fee_amortization), - GNUNET_JSON_spec_end() + &pc->wire_fee_amortization), + GNUNET_JSON_spec_end () }; res = TMH_PARSE_json_data (connection, @@ -1635,7 +1643,7 @@ parse_pay (struct MHD_Connection *connection, const char *exchange_url; struct GNUNET_JSON_Specification ispec[] = { TALER_JSON_spec_denomination_public_key ("denom_pub", - &dc->denom), + &dc->denom), TALER_JSON_spec_amount ("contribution", &dc->amount_with_fee), GNUNET_JSON_spec_string ("exchange_url", @@ -1646,7 +1654,7 @@ parse_pay (struct MHD_Connection *connection, &dc->ub_sig), GNUNET_JSON_spec_fixed_auto ("coin_sig", &dc->coin_sig), - GNUNET_JSON_spec_end() + GNUNET_JSON_spec_end () }; res = TMH_PARSE_json_data (connection, @@ -1691,7 +1699,7 @@ check_coin_refunded (void *cls, { struct PayContext *pc = cls; - for (unsigned int i=0;icoins_cnt;i++) + for (unsigned int i = 0; icoins_cnt; i++) { struct DepositConfirmation *dc = &pc->dc[i]; @@ -1726,10 +1734,13 @@ begin_transaction (struct PayContext *pc) { GNUNET_break (0); resume_pay_with_response (pc, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TMH_RESPONSE_make_json_pack ("{s:I, s:s}", - "code", (json_int_t) TALER_EC_PAY_DB_STORE_TRANSACTION_ERROR, - "hint", "Soft merchant database error: retry counter exceeded")); + MHD_HTTP_INTERNAL_SERVER_ERROR, + TMH_RESPONSE_make_json_pack ("{s:I, s:s}", + "code", + (json_int_t) + TALER_EC_PAY_DB_STORE_TRANSACTION_ERROR, + "hint", + "Soft merchant database error: retry counter exceeded")); return; } @@ -1903,7 +1914,7 @@ begin_transaction (struct PayContext *pc) "could not create JSON array"); return; } - for (unsigned int i=0;icoins_cnt;i++) + for (unsigned int i = 0; icoins_cnt; i++) { struct TALER_RefundRequestPS rr; struct TALER_MerchantSignatureP msig; @@ -1944,11 +1955,20 @@ begin_transaction (struct PayContext *pc) if (0 != json_array_append_new (refunds, json_pack ("{s:I, s:o, s:o s:o s:o}", - "rtransaction_id", (json_int_t) rtransactionid, - "coin_pub", GNUNET_JSON_from_data_auto (&rr.coin_pub), - "merchant_sig", GNUNET_JSON_from_data_auto (&msig), - "refund_amount", TALER_JSON_from_amount_nbo (&rr.refund_amount), - "refund_fee", TALER_JSON_from_amount_nbo (&rr.refund_fee)))) + "rtransaction_id", + (json_int_t) rtransactionid, + "coin_pub", + GNUNET_JSON_from_data_auto ( + &rr.coin_pub), + "merchant_sig", + GNUNET_JSON_from_data_auto ( + &msig), + "refund_amount", + TALER_JSON_from_amount_nbo ( + &rr.refund_amount), + "refund_fee", + TALER_JSON_from_amount_nbo ( + &rr.refund_fee)))) { json_decref (refunds); GNUNET_break (0); @@ -1963,9 +1983,9 @@ begin_transaction (struct PayContext *pc) /* Resume and send back the response. */ resume_pay_with_response (pc, - MHD_HTTP_OK, - TMH_RESPONSE_make_json_pack - ("{s:o, s:o, s:o}", + MHD_HTTP_OK, + TMH_RESPONSE_make_json_pack + ("{s:o, s:o, s:o}", /* Refunds pack. */ "refund_permissions", refunds, "merchant_pub", @@ -2009,10 +2029,10 @@ begin_transaction (struct PayContext *pc) } resume_pay_with_error (pc, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_PAY_DB_STORE_PAYMENTS_ERROR, - "Merchant database error: could not " - "mark proposal as 'paid'"); + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_PAY_DB_STORE_PAYMENTS_ERROR, + "Merchant database error: could not " + "mark proposal as 'paid'"); return; } @@ -2040,10 +2060,10 @@ begin_transaction (struct PayContext *pc) } resume_pay_with_error (pc, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_PAY_DB_STORE_PAYMENTS_ERROR, - "Merchant database error: could not " - "mark proposal as 'paid'"); + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_PAY_DB_STORE_PAYMENTS_ERROR, + "Merchant database error: could not " + "mark proposal as 'paid'"); return; } @@ -2092,12 +2112,12 @@ handler_pay_json (struct MHD_Connection *connection, pc->suspended = GNUNET_YES; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Suspending /pay handling while working with the exchange\n"); + "Suspending /pay handling while working with the exchange\n"); pc->timeout_task = GNUNET_SCHEDULER_add_delayed - (PAY_TIMEOUT, - &handle_pay_timeout, - pc); + (PAY_TIMEOUT, + &handle_pay_timeout, + pc); begin_transaction (pc); return MHD_YES; @@ -2115,8 +2135,7 @@ handler_pay_json (struct MHD_Connection *connection, * @param upload_data upload data * @param[in,out] upload_data_size number of bytes (left) in @a * upload_data - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -2125,7 +2144,7 @@ MH_handler_pay (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id) + struct MerchantInstance *mi) { struct PayContext *pc; int res; @@ -2142,24 +2161,10 @@ MH_handler_pay (struct TMH_RequestHandler *rh, pc->hc.cc = &pay_context_cleanup; pc->connection = connection; *connection_cls = pc; - pc->mi = TMH_lookup_instance (instance_id); - if (NULL == pc->mi) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unable to find the specified instance\n"); - if (MHD_NO == - TMH_RESPONSE_reply_not_found (connection, - TALER_EC_PAY_INSTANCE_UNKNOWN, - "Unknown instance given")) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - return GNUNET_NO; - } + pc->mi = mi; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "/pay: picked instance %s\n", - pc->mi->id); + mi->id); } else diff --git a/src/backend/taler-merchant-httpd_pay.h b/src/backend/taler-merchant-httpd_pay.h index cffb13bb..78f5d782 100644 --- a/src/backend/taler-merchant-httpd_pay.h +++ b/src/backend/taler-merchant-httpd_pay.h @@ -40,8 +40,7 @@ MH_force_pc_resume (void); * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -50,6 +49,6 @@ MH_handler_pay (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id); + struct MerchantInstance *mi); #endif diff --git a/src/backend/taler-merchant-httpd_proposal.c b/src/backend/taler-merchant-httpd_proposal.c index 7f61d215..aa56e613 100644 --- a/src/backend/taler-merchant-httpd_proposal.c +++ b/src/backend/taler-merchant-httpd_proposal.c @@ -79,7 +79,7 @@ check_products (json_t *products) /* FIXME: there are other fields in the product specification that are currently not labeled as optional. Maybe check those as well, or make them truly optional. */ - GNUNET_JSON_spec_end() + GNUNET_JSON_spec_end () }; /* extract fields we need to sign separately */ @@ -191,7 +191,7 @@ proposal_put (struct MHD_Connection *connection, { char buf[256]; time_t timer; - struct tm* tm_info; + struct tm*tm_info; size_t off; uint64_t rand; char *last; @@ -201,9 +201,9 @@ proposal_put (struct MHD_Connection *connection, if (NULL == tm_info) { return TMH_RESPONSE_reply_internal_error - (connection, - TALER_EC_PROPOSAL_NO_LOCALTIME, - "failed to determine local time"); + (connection, + TALER_EC_PROPOSAL_NO_LOCALTIME, + "failed to determine local time"); } off = strftime (buf, sizeof (buf), @@ -280,9 +280,9 @@ proposal_put (struct MHD_Connection *connection, { json_object_set_new (order, - "wire_fee_amortization", - json_integer - ((json_int_t) default_wire_fee_amortization)); + "wire_fee_amortization", + json_integer + ((json_int_t) default_wire_fee_amortization)); } if (NULL == json_object_get (order, @@ -398,9 +398,9 @@ proposal_put (struct MHD_Connection *connection, if (GNUNET_SYSERR == res) { return TMH_RESPONSE_reply_internal_error - (connection, - TALER_EC_PROPOSAL_ORDER_PARSE_ERROR, - "Impossible to parse the order"); + (connection, + TALER_EC_PROPOSAL_ORDER_PARSE_ERROR, + "Impossible to parse the order"); } /* check contract is well-formed */ @@ -408,9 +408,9 @@ proposal_put (struct MHD_Connection *connection, { GNUNET_JSON_parse_free (spec); return TMH_RESPONSE_reply_arg_invalid - (connection, - TALER_EC_PARAMETER_MALFORMED, - "order:products"); + (connection, + TALER_EC_PARAMETER_MALFORMED, + "order:products"); } /* add fields to the contract that the backend should provide */ @@ -428,30 +428,28 @@ proposal_put (struct MHD_Connection *connection, if (NULL == wm) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "No wire method available for" - " instance '%s'\n", mi->id); + "No wire method available for instance '%s'\n", mi->id); GNUNET_JSON_parse_free (spec); - return TMH_RESPONSE_reply_not_found - (connection, - TALER_EC_CONTRACT_INSTANCE_UNKNOWN, - "No wire method configured for instance"); + return TMH_RESPONSE_reply_not_found (connection, + TALER_EC_PROPOSAL_INSTANCE_CONFIGURATION_LACKS_WIRE, + "No wire method configured for instance"); } json_object_set_new (order, "H_wire", - GNUNET_JSON_from_data_auto (&wm->h_wire)); + GNUNET_JSON_from_data_auto (&wm->h_wire)); json_object_set_new (order, "wire_method", - json_string (wm->wire_method)); + json_string (wm->wire_method)); json_object_set_new (order, "merchant_pub", - GNUNET_JSON_from_data_auto (&mi->pubkey)); + GNUNET_JSON_from_data_auto (&mi->pubkey)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Inserting order '%s' for instance '%s'\n", order_id, mi->id); - for (unsigned int i=0;ipreflight (db->cls); qs = db->insert_order (db->cls, @@ -469,10 +467,10 @@ proposal_put (struct MHD_Connection *connection, { GNUNET_break (0); return TMH_RESPONSE_reply_internal_error - (connection, - TALER_EC_PROPOSAL_STORE_DB_ERROR_SOFT, - "db error: could not check for existing order" - " due to repeated soft transaction failure"); + (connection, + TALER_EC_PROPOSAL_STORE_DB_ERROR_SOFT, + "db error: could not check for existing order" + " due to repeated soft transaction failure"); } { @@ -503,9 +501,9 @@ proposal_put (struct MHD_Connection *connection, JSON_COMPACT); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Order ID `%s' already exists with proposal `%s'\n"), - order_id, - js); + _ ("Order ID `%s' already exists with proposal `%s'\n"), + order_id, + js); free (js); } json_decref (contract_terms); @@ -513,9 +511,9 @@ proposal_put (struct MHD_Connection *connection, /* contract_terms may be private, only expose * duplicate order_id to the network */ rv = TMH_RESPONSE_reply_external_error - (connection, - TALER_EC_PROPOSAL_STORE_DB_ERROR_ALREADY_EXISTS, - msg); + (connection, + TALER_EC_PROPOSAL_STORE_DB_ERROR_ALREADY_EXISTS, + msg); GNUNET_free (msg); return rv; } @@ -524,9 +522,9 @@ proposal_put (struct MHD_Connection *connection, /* Other hard transaction error (disk full, etc.) */ GNUNET_JSON_parse_free (spec); return TMH_RESPONSE_reply_internal_error - (connection, - TALER_EC_PROPOSAL_STORE_DB_ERROR_HARD, - "db error: could not store this proposal's data into db"); + (connection, + TALER_EC_PROPOSAL_STORE_DB_ERROR_HARD, + "db error: could not store this proposal's data into db"); } /* DB transaction succeeded, generate positive response */ @@ -552,8 +550,7 @@ proposal_put (struct MHD_Connection *connection, * @param upload_data upload data * @param[in,out] upload_data_size number of bytes (left) in * @a upload_data - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -562,11 +559,10 @@ MH_handler_proposal_put (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id) + struct MerchantInstance *mi) { int res; struct TMH_JsonParseContext *ctx; - struct MerchantInstance *mi; json_t *root; json_t *order; @@ -592,24 +588,17 @@ MH_handler_proposal_put (struct TMH_RequestHandler *rh, /* A error response was already generated */ if ( (GNUNET_NO == res) || - /* or, need more data to accomplish parsing */ + /* or, need more data to accomplish parsing */ (NULL == root) ) return MHD_YES; - - mi = TMH_lookup_instance (instance_id); - if (NULL == mi) - return TMH_RESPONSE_reply_not_found (connection, - TALER_EC_CONTRACT_INSTANCE_UNKNOWN, - "instance"); - order = json_object_get (root, "order"); if (NULL == order) { res = TMH_RESPONSE_reply_arg_missing - (connection, - TALER_EC_PARAMETER_MISSING, - "order"); + (connection, + TALER_EC_PARAMETER_MISSING, + "order"); } else res = proposal_put (connection, order, mi); @@ -630,8 +619,7 @@ MH_handler_proposal_put (struct TMH_RequestHandler *rh, * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -640,35 +628,29 @@ MH_handler_proposal_lookup (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id) + struct MerchantInstance *mi) { const char *order_id; const char *nonce; int res; enum GNUNET_DB_QueryStatus qs; json_t *contract_terms; - struct MerchantInstance *mi; struct GNUNET_CRYPTO_EddsaSignature merchant_sig; const char *stored_nonce; - mi = TMH_lookup_instance (instance_id); - if (NULL == mi) - return TMH_RESPONSE_reply_not_found (connection, - TALER_EC_CONTRACT_INSTANCE_UNKNOWN, - "instance"); order_id = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "order_id"); if (NULL == order_id) return TMH_RESPONSE_reply_arg_missing (connection, - TALER_EC_PARAMETER_MISSING, + TALER_EC_PARAMETER_MISSING, "order_id"); nonce = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "nonce"); if (NULL == nonce) return TMH_RESPONSE_reply_arg_missing (connection, - TALER_EC_PARAMETER_MISSING, + TALER_EC_PARAMETER_MISSING, "nonce"); db->preflight (db->cls); qs = db->find_contract_terms (db->cls, @@ -712,8 +694,8 @@ MH_handler_proposal_lookup (struct TMH_RequestHandler *rh, /* extract fields we need to sign separately */ res = TMH_PARSE_json_data (connection, - contract_terms, - spec); + contract_terms, + spec); if (GNUNET_NO == res) { return MHD_YES; @@ -725,7 +707,7 @@ MH_handler_proposal_lookup (struct TMH_RequestHandler *rh, "Impossible to parse the order"); } - for (unsigned int i=0;ipreflight (db->cls); qs = db->insert_contract_terms (db->cls, @@ -764,7 +746,7 @@ MH_handler_proposal_lookup (struct TMH_RequestHandler *rh, } if (0 != strcmp (stored_nonce, - nonce)) + nonce)) { return TMH_RESPONSE_reply_bad_request (connection, TALER_EC_PROPOSAL_LOOKUP_NOT_FOUND, @@ -799,7 +781,8 @@ MH_handler_proposal_lookup (struct TMH_RequestHandler *rh, "contract_terms", contract_terms, "sig", - GNUNET_JSON_from_data_auto (&merchant_sig)); + GNUNET_JSON_from_data_auto ( + &merchant_sig)); return res; } diff --git a/src/backend/taler-merchant-httpd_proposal.h b/src/backend/taler-merchant-httpd_proposal.h index 137c32a6..4edac090 100644 --- a/src/backend/taler-merchant-httpd_proposal.h +++ b/src/backend/taler-merchant-httpd_proposal.h @@ -33,8 +33,7 @@ * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -43,7 +42,7 @@ MH_handler_proposal_put (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id); + struct MerchantInstance *mi); /** @@ -56,6 +55,7 @@ MH_handler_proposal_put (struct TMH_RequestHandler *rh, * @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 + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -64,5 +64,5 @@ MH_handler_proposal_lookup (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id); + struct MerchantInstance *mi); #endif diff --git a/src/backend/taler-merchant-httpd_refund.c b/src/backend/taler-merchant-httpd_refund.c index a20149a1..a9d8ab18 100644 --- a/src/backend/taler-merchant-httpd_refund.c +++ b/src/backend/taler-merchant-httpd_refund.c @@ -49,7 +49,7 @@ struct ProcessRefundData /** * Both public and private key are needed by the callback */ - const struct MerchantInstance *merchant; + const struct MerchantInstance *merchant; /** * Return code: #TALER_EC_NONE if successful. @@ -85,7 +85,7 @@ struct TMH_JsonParseContext * @param order_id order ID to show a refund for * @returns the URI, must be freed with #GNUNET_free */ -char * +static char * make_taler_refund_uri (struct MHD_Connection *connection, const char *instance_id, const char *order_id) @@ -155,8 +155,7 @@ json_parse_cleanup (struct TM_HandlerContext *hc) * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -165,7 +164,7 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id) + struct MerchantInstance *mi) { int res; struct TMH_JsonParseContext *ctx; @@ -174,7 +173,6 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh, json_t *contract_terms; const char *order_id; const char *reason; - struct MerchantInstance *mi; struct GNUNET_HashCode h_contract_terms; struct TALER_MerchantRefundConfirmationPS confirmation; struct GNUNET_CRYPTO_EddsaSignature sig; @@ -227,19 +225,6 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh, return MHD_NO; } - mi = TMH_lookup_instance (instance_id); - if (NULL == mi) - { - GNUNET_assert (NULL != instance_id); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Instance '%s' not found\n", instance_id); - GNUNET_JSON_parse_free (spec); - json_decref (root); - return TMH_RESPONSE_reply_not_found (connection, - TALER_EC_REFUND_INSTANCE_UNKNOWN, - "Unknown instance given"); - } - db->preflight (db->cls); /* Convert order id to h_contract_terms */ qs = db->find_contract_terms (db->cls, @@ -283,7 +268,7 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh, TALER_EC_INTERNAL_LOGIC_ERROR, "Could not hash contract terms"); } - for (unsigned int i=0;istart (db->cls, @@ -366,7 +351,8 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh, * the information needed to generate the right response. */ confirmation.purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_REFUND_OK); - confirmation.purpose.size = htonl (sizeof (struct TALER_MerchantRefundConfirmationPS)); + confirmation.purpose.size = htonl (sizeof (struct + TALER_MerchantRefundConfirmationPS)); GNUNET_CRYPTO_hash (order_id, strlen (order_id), &confirmation.h_order_id); @@ -451,8 +437,8 @@ process_refunds_cb (void *cls, if (GNUNET_OK != GNUNET_CRYPTO_eddsa_sign (&prd->merchant->privkey.eddsa_priv, - &rr.purpose, - &sig)) + &rr.purpose, + &sig)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not sign refund request\n"); @@ -493,8 +479,7 @@ process_refunds_cb (void *cls, * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -503,27 +488,13 @@ MH_handler_refund_lookup (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id) + struct MerchantInstance *mi) { const char *order_id; struct GNUNET_HashCode h_contract_terms; json_t *contract_terms; - struct MerchantInstance *mi; enum GNUNET_DB_QueryStatus qs; - mi = TMH_lookup_instance (instance_id); - - if (NULL == mi) - { - GNUNET_assert (NULL != instance_id); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unknown instance given: %s\n", - instance_id); - return TMH_RESPONSE_reply_not_found (connection, - TALER_EC_REFUND_INSTANCE_UNKNOWN, - "Unknown instance given"); - } - order_id = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "order_id"); @@ -532,7 +503,7 @@ MH_handler_refund_lookup (struct TMH_RequestHandler *rh, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Argument 'order_id' not given\n"); return TMH_RESPONSE_reply_arg_missing (connection, - TALER_EC_PARAMETER_MISSING, + TALER_EC_PARAMETER_MISSING, "order_id"); } @@ -597,9 +568,11 @@ MH_handler_refund_lookup (struct TMH_RequestHandler *rh, "refund_permissions", response, "merchant_pub", - GNUNET_JSON_from_data_auto (&mi->pubkey), + GNUNET_JSON_from_data_auto ( + &mi->pubkey), "h_contract_terms", - GNUNET_JSON_from_data_auto (&h_contract_terms)); + GNUNET_JSON_from_data_auto ( + &h_contract_terms)); } } @@ -627,7 +600,7 @@ TM_get_refund_json (const struct MerchantInstance *mi, prd.merchant = mi; prd.ec = TALER_EC_NONE; db->preflight (db->cls); - for (unsigned int i=0;iget_refunds_from_contract_terms_hash (db->cls, &mi->pubkey, @@ -645,7 +618,7 @@ TM_get_refund_json (const struct MerchantInstance *mi, json_decref (prd.response); *ret_ec = TALER_EC_REFUND_LOOKUP_DB_ERROR; *ret_errmsg = ("database hard error: looking for " - "h_contract_terms in merchant_refunds table"); + "h_contract_terms in merchant_refunds table"); } if (TALER_EC_NONE != prd.ec) { diff --git a/src/backend/taler-merchant-httpd_refund.h b/src/backend/taler-merchant-httpd_refund.h index eadd24a9..9713adb0 100644 --- a/src/backend/taler-merchant-httpd_refund.h +++ b/src/backend/taler-merchant-httpd_refund.h @@ -34,8 +34,7 @@ * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -44,7 +43,7 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id); + struct MerchantInstance *mi); /** @@ -55,8 +54,7 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh, * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -65,7 +63,7 @@ MH_handler_refund_lookup (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id); + struct MerchantInstance *mi); /** * Get the JSON representation of a refund. @@ -82,4 +80,4 @@ TM_get_refund_json (const struct MerchantInstance *mi, enum TALER_ErrorCode *ret_ec, const char **ret_errmsg); -#endif +#endif diff --git a/src/backend/taler-merchant-httpd_tip-authorize.c b/src/backend/taler-merchant-httpd_tip-authorize.c index 1a79d772..67c4a6e6 100644 --- a/src/backend/taler-merchant-httpd_tip-authorize.c +++ b/src/backend/taler-merchant-httpd_tip-authorize.c @@ -107,8 +107,7 @@ cleanup_tac (struct TM_HandlerContext *hc) * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -117,11 +116,10 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id) + struct MerchantInstance *mi) { struct TipAuthContext *tac; int res; - struct MerchantInstance *mi; enum TALER_ErrorCode ec; struct GNUNET_TIME_Absolute expiration; struct GNUNET_HashCode tip_id; @@ -152,7 +150,7 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh, struct GNUNET_JSON_Specification spec[] = { TALER_JSON_spec_amount ("amount", &tac->amount), GNUNET_JSON_spec_string ("justification", &tac->justification), - GNUNET_JSON_spec_end() + GNUNET_JSON_spec_end () }; res = TMH_PARSE_post_json (connection, @@ -178,22 +176,11 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh, tac->parsed_json = GNUNET_YES; } - mi = TMH_lookup_instance (instance_id); - if (NULL == mi) - { - GNUNET_assert (NULL != instance_id); - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Instance `%s' not configured\n", - instance_id); - return TMH_RESPONSE_reply_not_found (connection, - TALER_EC_TIP_AUTHORIZE_INSTANCE_UNKNOWN, - "unknown instance"); - } if (NULL == mi->tip_exchange) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Instance `%s' not configured for tipping\n", - (NULL != instance_id) ? instance_id : "default"); + mi->id); return TMH_RESPONSE_reply_not_found (connection, TALER_EC_TIP_AUTHORIZE_INSTANCE_DOES_NOT_TIP, "exchange for tipping not configured for the instance"); @@ -275,7 +262,7 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh, "X-Forwarded-Host"); uri_path = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, - "X-Forwarded-Prefix"); + "X-Forwarded-Prefix"); if (NULL == uri_path) uri_path = "-"; @@ -286,7 +273,8 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh, { /* Should never happen, at last the host header should be defined */ GNUNET_break (0); - return TMH_RESPONSE_reply_internal_error (connection, 0, "unable to identify backend host"); + return TMH_RESPONSE_reply_internal_error (connection, 0, + "unable to identify backend host"); } if (0 == strcmp (mi->id, "default")) @@ -297,11 +285,11 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh, GNUNET_CRYPTO_hash_to_enc (&tip_id, &hash_enc); GNUNET_assert (0 < GNUNET_asprintf (&taler_tip_uri, - "taler://tip/%s/%s/%s/%s", - host, - uri_path, - uri_instance_id, - hash_enc.encoding)); + "taler://tip/%s/%s/%s/%s", + host, + uri_path, + uri_instance_id, + hash_enc.encoding)); res = TMH_RESPONSE_reply_json_pack (connection, diff --git a/src/backend/taler-merchant-httpd_tip-authorize.h b/src/backend/taler-merchant-httpd_tip-authorize.h index 025b9580..8706d648 100644 --- a/src/backend/taler-merchant-httpd_tip-authorize.h +++ b/src/backend/taler-merchant-httpd_tip-authorize.h @@ -32,8 +32,7 @@ * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -42,6 +41,6 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id); + struct MerchantInstance *mi); #endif diff --git a/src/backend/taler-merchant-httpd_tip-pickup.c b/src/backend/taler-merchant-httpd_tip-pickup.c index 6232c4b8..bead3419 100644 --- a/src/backend/taler-merchant-httpd_tip-pickup.c +++ b/src/backend/taler-merchant-httpd_tip-pickup.c @@ -151,7 +151,7 @@ pickup_cleanup (struct TM_HandlerContext *hc) if (NULL != pc->planchets) { - for (unsigned int i=0;iplanchets_len;i++) + for (unsigned int i = 0; iplanchets_len; i++) GNUNET_free_non_null (pc->planchets[i].coin_ev); GNUNET_free (pc->planchets); pc->planchets = NULL; @@ -237,21 +237,22 @@ run_pickup (struct MHD_Connection *connection, } GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv.eddsa_priv, &reserve_pub.eddsa_pub); - for (unsigned int i=0;iplanchets_len;i++) + for (unsigned int i = 0; iplanchets_len; i++) { struct PlanchetDetail *pd = &pc->planchets[i]; struct TALER_ReserveSignatureP reserve_sig; pd->wr.reserve_pub = reserve_pub; GNUNET_assert (GNUNET_OK == - GNUNET_CRYPTO_eddsa_sign (&reserve_priv.eddsa_priv, - &pd->wr.purpose, - &reserve_sig.eddsa_signature)); + GNUNET_CRYPTO_eddsa_sign (&reserve_priv.eddsa_priv, + &pd->wr.purpose, + &reserve_sig.eddsa_signature)); if (0 != json_array_append_new (sigs, json_pack ("{s:o}", "reserve_sig", - GNUNET_JSON_from_data_auto (&reserve_sig)))) + GNUNET_JSON_from_data_auto ( + &reserve_sig)))) { GNUNET_break (0); json_decref (sigs); @@ -264,8 +265,10 @@ run_pickup (struct MHD_Connection *connection, return TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_OK, "{s:o, s:o}", - "reserve_pub", GNUNET_JSON_from_data_auto (&reserve_pub), - "reserve_sigs", sigs); + "reserve_pub", + GNUNET_JSON_from_data_auto ( + &reserve_pub), + "reserve_sigs", sigs); } @@ -304,7 +307,8 @@ exchange_found_cb (void *cls, if (NULL == keys) { pc->ec = TALER_EC_TIP_PICKUP_EXCHANGE_LACKED_KEYS; - pc->error_hint = "could not obtain denomination keys from exchange, check URL"; + pc->error_hint = + "could not obtain denomination keys from exchange, check URL"; pc->response_code = MHD_HTTP_FAILED_DEPENDENCY; TMH_trigger_daemon (); return; @@ -318,7 +322,7 @@ exchange_found_cb (void *cls, "Calculating tip amount over %u planchets!\n", pc->planchets_len); hc = GNUNET_CRYPTO_hash_context_start (); - for (unsigned int i=0;iplanchets_len;i++) + for (unsigned int i = 0; iplanchets_len; i++) { struct PlanchetDetail *pd = &pc->planchets[i]; const struct TALER_EXCHANGE_DenomPublicKey *dk; @@ -468,7 +472,7 @@ parse_planchet (struct MHD_Connection *connection, GNUNET_JSON_spec_varsize ("coin_ev", (void **) &pd->coin_ev, &pd->coin_ev_size), - GNUNET_JSON_spec_end() + GNUNET_JSON_spec_end () }; ret = TMH_PARSE_json_data (connection, @@ -494,8 +498,7 @@ parse_planchet (struct MHD_Connection *connection, * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -504,7 +507,7 @@ MH_handler_tip_pickup (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id) + struct MerchantInstance *mi) { int res; struct GNUNET_HashCode tip_id; @@ -514,7 +517,7 @@ MH_handler_tip_pickup (struct TMH_RequestHandler *rh, &tip_id), GNUNET_JSON_spec_json ("planchets", &planchets), - GNUNET_JSON_spec_end() + GNUNET_JSON_spec_end () }; struct PickupContext *pc; json_t *root; @@ -581,7 +584,7 @@ MH_handler_tip_pickup (struct TMH_RequestHandler *rh, db->preflight (db->cls); pc->planchets = GNUNET_new_array (pc->planchets_len, struct PlanchetDetail); - for (unsigned int i=0;iplanchets_len;i++) + for (unsigned int i = 0; iplanchets_len; i++) { if (GNUNET_OK != (res = parse_planchet (connection, @@ -611,8 +614,7 @@ MH_handler_tip_pickup (struct TMH_RequestHandler *rh, * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -621,9 +623,8 @@ MH_handler_tip_pickup_get (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id) + struct MerchantInstance *mi) { - struct MerchantInstance *mi; const char *tip_id_str; char *exchange_url; json_t *extra; @@ -635,12 +636,6 @@ MH_handler_tip_pickup_get (struct TMH_RequestHandler *rh, int ret; int qs; - mi = TMH_lookup_instance (instance_id); - if (NULL == mi) - return TMH_RESPONSE_reply_bad_request (connection, - TALER_EC_TIP_INSTANCE_UNKNOWN, - "merchant instance unknown"); - tip_id_str = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "tip_id"); @@ -703,16 +698,22 @@ MH_handler_tip_pickup_get (struct TMH_RequestHandler *rh, "Could not determine exchange URL for the given tip id"); } - timestamp_expire = GNUNET_TIME_absolute_add (timestamp, GNUNET_TIME_UNIT_DAYS); + timestamp_expire = GNUNET_TIME_absolute_add (timestamp, + GNUNET_TIME_UNIT_DAYS); ret = TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_OK, "{s:s, s:o, s:o, s:o, s:o, s:o}", "exchange_url", exchange_url, - "amount", TALER_JSON_from_amount (&tip_amount), - "amount_left", TALER_JSON_from_amount (&tip_amount_left), - "stamp_created", GNUNET_JSON_from_time_abs (timestamp), - "stamp_expire", GNUNET_JSON_from_time_abs (timestamp_expire), + "amount", TALER_JSON_from_amount ( + &tip_amount), + "amount_left", TALER_JSON_from_amount ( + &tip_amount_left), + "stamp_created", + GNUNET_JSON_from_time_abs (timestamp), + "stamp_expire", + GNUNET_JSON_from_time_abs ( + timestamp_expire), "extra", extra); GNUNET_free (exchange_url); diff --git a/src/backend/taler-merchant-httpd_tip-pickup.h b/src/backend/taler-merchant-httpd_tip-pickup.h index f0e9733d..3ca15bb7 100644 --- a/src/backend/taler-merchant-httpd_tip-pickup.h +++ b/src/backend/taler-merchant-httpd_tip-pickup.h @@ -32,8 +32,7 @@ * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified +* @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -42,7 +41,8 @@ MH_handler_tip_pickup (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id); + struct MerchantInstance *mi); + /** * Manages a GET /tip-pickup call. @@ -52,8 +52,7 @@ MH_handler_tip_pickup (struct TMH_RequestHandler *rh, * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -62,7 +61,7 @@ MH_handler_tip_pickup_get (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id); + struct MerchantInstance *mi); #endif diff --git a/src/backend/taler-merchant-httpd_tip-query.c b/src/backend/taler-merchant-httpd_tip-query.c index bd61a3e6..d54625c0 100644 --- a/src/backend/taler-merchant-httpd_tip-query.c +++ b/src/backend/taler-merchant-httpd_tip-query.c @@ -112,15 +112,20 @@ generate_final_response (struct TipQueryContext *tqc) MHD_HTTP_OK, "{s:o, s:o, s:o, s:o, s:o}", "reserve_pub", - GNUNET_JSON_from_data_auto (&reserve_pub), + GNUNET_JSON_from_data_auto ( + &reserve_pub), "reserve_expiration", - GNUNET_JSON_from_time_abs (tqc->ctr.reserve_expiration), + GNUNET_JSON_from_time_abs ( + tqc->ctr.reserve_expiration), "amount_authorized", - TALER_JSON_from_amount (&tqc->ctr.amount_authorized), + TALER_JSON_from_amount ( + &tqc->ctr.amount_authorized), "amount_picked_up", - TALER_JSON_from_amount (&tqc->ctr.amount_withdrawn), + TALER_JSON_from_amount ( + &tqc->ctr.amount_withdrawn), "amount_available", - TALER_JSON_from_amount (&amount_available)); + TALER_JSON_from_amount ( + &amount_available)); } @@ -132,8 +137,7 @@ generate_final_response (struct TipQueryContext *tqc) * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -142,10 +146,9 @@ MH_handler_tip_query (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id) + struct MerchantInstance *mi) { struct TipQueryContext *tqc; - struct MerchantInstance *mi; if (NULL == *connection_cls) { @@ -188,23 +191,11 @@ MH_handler_tip_query (struct TMH_RequestHandler *rh, return generate_final_response (tqc); } - - mi = TMH_lookup_instance (instance_id); - if (NULL == mi) - { - GNUNET_assert (NULL != instance_id); - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Instance `%s' not configured\n", - instance_id); - return TMH_RESPONSE_reply_not_found (connection, - TALER_EC_TIP_AUTHORIZE_INSTANCE_UNKNOWN, - "unknown instance"); - } if (NULL == mi->tip_exchange) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Instance `%s' not configured for tipping\n", - instance_id); + mi->id); return TMH_RESPONSE_reply_not_found (connection, TALER_EC_TIP_AUTHORIZE_INSTANCE_DOES_NOT_TIP, "exchange for tipping not configured for the instance"); @@ -213,7 +204,7 @@ MH_handler_tip_query (struct TMH_RequestHandler *rh, { int qs; - for (unsigned int i=0;ipreflight (db->cls); qs = db->get_authorized_tip_amount (db->cls, diff --git a/src/backend/taler-merchant-httpd_tip-query.h b/src/backend/taler-merchant-httpd_tip-query.h index 10b1e1be..257aaf71 100644 --- a/src/backend/taler-merchant-httpd_tip-query.h +++ b/src/backend/taler-merchant-httpd_tip-query.h @@ -31,8 +31,7 @@ * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -41,6 +40,6 @@ MH_handler_tip_query (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id); + struct MerchantInstance *mi); #endif diff --git a/src/backend/taler-merchant-httpd_track-transaction.c b/src/backend/taler-merchant-httpd_track-transaction.c index 1376aa9a..b8fe42bc 100644 --- a/src/backend/taler-merchant-httpd_track-transaction.c +++ b/src/backend/taler-merchant-httpd_track-transaction.c @@ -75,7 +75,8 @@ extern struct GNUNET_CONTAINER_MultiHashMap *by_id_map; /** * How long to wait before giving up processing with the exchange? */ -#define TRACK_TIMEOUT (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)) +#define TRACK_TIMEOUT (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ + 30)) /** * How often do we retry the simple INSERT database transaction? @@ -99,12 +100,12 @@ make_track_transaction_ok (unsigned int num_transfers, struct TALER_Amount sum; j_transfers = json_array (); - for (unsigned int i=0;icoins[0].amount_with_fee; - for (unsigned int j=1;jnum_coins;j++) + for (unsigned int j = 1; jnum_coins; j++) { const struct TALER_MERCHANT_CoinWireTransfer *coin = &transfer->coins[j]; @@ -117,10 +118,17 @@ make_track_transaction_ok (unsigned int num_transfers, GNUNET_assert (0 == json_array_append_new (j_transfers, json_pack ("{s:s, s:o, s:o, s:o}", - "exchange", transfer->exchange_url, - "wtid", GNUNET_JSON_from_data_auto (&transfer->wtid), - "execution_time", GNUNET_JSON_from_time_abs (transfer->execution_time), - "amount", TALER_JSON_from_amount (&sum)))); + "exchange", + transfer->exchange_url, + "wtid", + GNUNET_JSON_from_data_auto ( + &transfer->wtid), + "execution_time", + GNUNET_JSON_from_time_abs ( + transfer->execution_time), + "amount", + TALER_JSON_from_amount ( + &sum)))); } ret = TMH_RESPONSE_make_json (j_transfers); json_decref (j_transfers); @@ -462,15 +470,18 @@ wire_deposits_cb (void *cls, GNUNET_break_op (0); resume_track_transaction_with_response (tctx, - MHD_HTTP_FAILED_DEPENDENCY, - TMH_RESPONSE_make_json_pack ("{s:I, s:I, s:I, s:O}", - "code", (json_int_t) TALER_EC_TRACK_TRANSACTION_WIRE_TRANSFER_TRACE_ERROR, - "exchange-http-status", (json_int_t) http_status, - "exchange-code", (json_int_t) ec, - "details", json)); + MHD_HTTP_FAILED_DEPENDENCY, + TMH_RESPONSE_make_json_pack ("{s:I, s:I, s:I, s:O}", + "code", + (json_int_t) + TALER_EC_TRACK_TRANSACTION_WIRE_TRANSFER_TRACE_ERROR, + "exchange-http-status", + (json_int_t) http_status, + "exchange-code", (json_int_t) ec, + "details", json)); return; } - for (unsigned int i=0;ipreflight (db->cls); qs = db->store_transfer_to_proof (db->cls, @@ -492,13 +503,13 @@ wire_deposits_cb (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to store transfer-to-proof mapping in DB\n"); } - for (struct TrackCoinContext *tcc=tctx->tcc_head; + for (struct TrackCoinContext *tcc = tctx->tcc_head; NULL != tcc; - tcc=tcc->next) + tcc = tcc->next) { if (GNUNET_YES == tcc->have_wtid) continue; - for (unsigned int d=0;dhave_wtid = GNUNET_YES; } - for (unsigned int i=0;ipreflight (db->cls); qs = db->store_coin_to_transfer (db->cls, @@ -521,11 +532,11 @@ wire_deposits_cb (void *cls, } if (0 > qs) { - /* Not good, but not fatal either, log error and continue */ - /* Special report if retries insufficient */ - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR != qs); - /* Always report on hard error as well to enable diagnostics */ - GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + /* Not good, but not fatal either, log error and continue */ + /* Special report if retries insufficient */ + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR != qs); + /* Always report on hard error as well to enable diagnostics */ + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to store coin-to-transfer mapping in DB\n"); } @@ -613,9 +624,9 @@ wtid_cb (void *cls, { resume_track_transaction_with_response (tcc->tctx, - MHD_HTTP_ACCEPTED, - /* Return verbatim what the exchange said. */ - TMH_RESPONSE_make_json (json)); + MHD_HTTP_ACCEPTED, + /* Return verbatim what the exchange said. */ + TMH_RESPONSE_make_json (json)); return; } @@ -624,17 +635,17 @@ wtid_cb (void *cls, coins, report error! */ resume_track_transaction_with_response (tcc->tctx, - MHD_HTTP_FAILED_DEPENDENCY, - TMH_RESPONSE_make_json_pack - ("{s:I, s:I, s:I, s:O}", - "code", - (json_int_t) TALER_EC_TRACK_TRANSACTION_COIN_TRACE_ERROR, - "exchange-http-status", - (json_int_t) http_status, - "exchange-code", - (json_int_t) ec, - "details", - json)); + MHD_HTTP_FAILED_DEPENDENCY, + TMH_RESPONSE_make_json_pack + ("{s:I, s:I, s:I, s:O}", + "code", + (json_int_t) TALER_EC_TRACK_TRANSACTION_COIN_TRACE_ERROR, + "exchange-http-status", + (json_int_t) http_status, + "exchange-code", + (json_int_t) ec, + "details", + json)); return; } @@ -659,10 +670,10 @@ wtid_cb (void *cls, GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); resume_track_transaction_with_response (tcc->tctx, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TMH_RESPONSE_make_error - (TALER_EC_TRACK_TRANSACTION_DB_FETCH_FAILED, - "Fail to query database about proofs")); + MHD_HTTP_INTERNAL_SERVER_ERROR, + TMH_RESPONSE_make_error + (TALER_EC_TRACK_TRANSACTION_DB_FETCH_FAILED, + "Fail to query database about proofs")); return; } @@ -675,13 +686,17 @@ wtid_cb (void *cls, GNUNET_break_op (0); resume_track_transaction_with_response (tcc->tctx, - MHD_HTTP_FAILED_DEPENDENCY, - TMH_RESPONSE_make_json_pack ("{s:I, s:s, s:O, s:o, s:o}", - "code", (json_int_t) TALER_EC_TRACK_TRANSACTION_CONFLICTING_REPORTS, - "error", "conflicting transfer data from exchange", - "transaction_tracking_claim", json, - "wtid_tracking_claim", pcc.p_ret, - "coin_pub", GNUNET_JSON_from_data_auto (&tcc->coin_pub))); + MHD_HTTP_FAILED_DEPENDENCY, + TMH_RESPONSE_make_json_pack ("{s:I, s:s, s:O, s:o, s:o}", + "code", + (json_int_t) + TALER_EC_TRACK_TRANSACTION_CONFLICTING_REPORTS, + "error", + "conflicting transfer data from exchange", + "transaction_tracking_claim", json, + "wtid_tracking_claim", pcc.p_ret, + "coin_pub", GNUNET_JSON_from_data_auto ( + &tcc->coin_pub))); return; } @@ -712,8 +727,8 @@ generate_response (struct TrackTransactionContext *tctx) int found = GNUNET_NO; for (struct TrackCoinContext *tcc2 = tctx->tcc_head; - tcc2 != tcc; - tcc2 = tcc2->next) + tcc2 != tcc; + tcc2 = tcc2->next) { if (0 == GNUNET_memcmp (&tcc->wtid, &tcc2->wtid)) @@ -739,8 +754,8 @@ generate_response (struct TrackTransactionContext *tctx) int found = GNUNET_NO; for (struct TrackCoinContext *tcc2 = tctx->tcc_head; - tcc2 != tcc; - tcc2 = tcc2->next) + tcc2 != tcc; + tcc2 = tcc2->next) { if (0 == GNUNET_memcmp (&tcc->wtid, &tcc2->wtid)) @@ -756,13 +771,13 @@ generate_response (struct TrackTransactionContext *tctx) wt = &wts[wtid_off++]; wt->wtid = tcc->wtid; - wt->exchange_url = tcc->exchange_url; + wt->exchange_url = tcc->exchange_url; wt->execution_time = tcc->execution_time; /* count number of coins with this wtid */ num_coins = 0; for (struct TrackCoinContext *tcc2 = tctx->tcc_head; - NULL != tcc2; - tcc2 = tcc2->next) + NULL != tcc2; + tcc2 = tcc2->next) { if (0 == GNUNET_memcmp (&wt->wtid, &tcc2->wtid)) @@ -774,13 +789,14 @@ generate_response (struct TrackTransactionContext *tctx) struct TALER_MERCHANT_CoinWireTransfer); num_coins = 0; for (struct TrackCoinContext *tcc2 = tctx->tcc_head; - NULL != tcc2; - tcc2 = tcc2->next) + NULL != tcc2; + tcc2 = tcc2->next) { if (0 == GNUNET_memcmp (&wt->wtid, &tcc2->wtid)) { - struct TALER_MERCHANT_CoinWireTransfer *coin = &wt->coins[num_coins++]; + struct TALER_MERCHANT_CoinWireTransfer *coin = + &wt->coins[num_coins++]; coin->coin_pub = tcc2->coin_pub; coin->amount_with_fee = tcc2->amount_with_fee; @@ -792,8 +808,8 @@ generate_response (struct TrackTransactionContext *tctx) GNUNET_assert (wtid_off == num_wtid); resp = make_track_transaction_ok (num_wtid, - wts); - for (wtid_off=0;wtid_off < num_wtid; wtid_off++) + wts); + for (wtid_off = 0; wtid_off < num_wtid; wtid_off++) GNUNET_free (wts[wtid_off].coins); resume_track_transaction_with_response (tctx, MHD_HTTP_OK, @@ -835,7 +851,7 @@ trace_coins (struct TrackTransactionContext *tctx) if (NULL != tcc) { if (0 != strcmp (tcc->exchange_url, - tctx->current_exchange)) + tctx->current_exchange)) { /* exchange changed, find matching one first! */ tctx->eh = NULL; @@ -905,8 +921,9 @@ handle_track_transaction_timeout (void *cls) } resume_track_transaction_with_response (tctx, MHD_HTTP_SERVICE_UNAVAILABLE, - TMH_RESPONSE_make_error (TALER_EC_PAY_EXCHANGE_TIMEOUT, - "exchange not reachable")); + TMH_RESPONSE_make_error ( + TALER_EC_PAY_EXCHANGE_TIMEOUT, + "exchange not reachable")); } @@ -1011,14 +1028,15 @@ find_exchange (struct TrackTransactionContext *tctx) struct TrackCoinContext *tcc = tctx->tcc_head; while ( (NULL != tcc) && - (GNUNET_YES == tcc->have_wtid) ) + (GNUNET_YES == tcc->have_wtid) ) tcc = tcc->next; if (NULL != tcc) { tctx->current_exchange = tcc->exchange_url; tctx->fo = TMH_EXCHANGES_find_exchange (tctx->current_exchange, NULL, - &process_track_transaction_with_exchange, + & + process_track_transaction_with_exchange, tctx); } @@ -1037,8 +1055,7 @@ find_exchange (struct TrackTransactionContext *tctx) * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -1047,7 +1064,7 @@ MH_handler_track_transaction (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id) + struct MerchantInstance *mi) { struct TrackTransactionContext *tctx; const char *order_id; @@ -1107,14 +1124,10 @@ MH_handler_track_transaction (struct TMH_RequestHandler *rh, TALER_EC_PARAMETER_MISSING, "order_id"); - tctx->mi = TMH_lookup_instance (instance_id); - if (NULL == tctx->mi) - return TMH_RESPONSE_reply_not_found (connection, - TALER_EC_TRACK_TRANSACTION_INSTANCE_UNKNOWN, - "unknown instance"); + tctx->mi = mi; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Tracking on behalf of instance '%s'\n", - instance_id); + mi->id); /* Map order id to contract terms; the objective is to get @@ -1157,7 +1170,7 @@ MH_handler_track_transaction (struct TMH_RequestHandler *rh, &tctx->total_amount), GNUNET_JSON_spec_fixed_auto ("H_wire", &tctx->h_wire), - GNUNET_JSON_spec_end() + GNUNET_JSON_spec_end () }; if (GNUNET_YES != @@ -1192,7 +1205,7 @@ MH_handler_track_transaction (struct TMH_RequestHandler *rh, GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR != tctx->qs); return TMH_RESPONSE_reply_internal_error (connection, TALER_EC_TRACK_TRANSACTION_DB_FETCH_PAYMENT_ERROR, - "Database error: failed to find payment data"); + "Database error: failed to find payment data"); } if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) { diff --git a/src/backend/taler-merchant-httpd_track-transaction.h b/src/backend/taler-merchant-httpd_track-transaction.h index 7efecaa9..91b8c47c 100644 --- a/src/backend/taler-merchant-httpd_track-transaction.h +++ b/src/backend/taler-merchant-httpd_track-transaction.h @@ -32,8 +32,7 @@ * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -42,7 +41,7 @@ MH_handler_track_transaction (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id); + struct MerchantInstance *mi); #endif diff --git a/src/backend/taler-merchant-httpd_track-transfer.c b/src/backend/taler-merchant-httpd_track-transfer.c index f833c7e9..e9e0cb97 100644 --- a/src/backend/taler-merchant-httpd_track-transfer.c +++ b/src/backend/taler-merchant-httpd_track-transfer.c @@ -35,7 +35,8 @@ /** * How long to wait before giving up processing with the exchange? */ -#define TRACK_TIMEOUT (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)) +#define TRACK_TIMEOUT (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ + 30)) /** * How often do we retry the simple INSERT database transaction? @@ -259,8 +260,10 @@ build_deposits_response (void *cls, } element = json_pack ("{s:O, s:o, s:o}", "order_id", order_id, - "deposit_value", TALER_JSON_from_amount (&entry->deposit_value), - "deposit_fee", TALER_JSON_from_amount (&entry->deposit_fee)); + "deposit_value", TALER_JSON_from_amount ( + &entry->deposit_value), + "deposit_fee", TALER_JSON_from_amount ( + &entry->deposit_fee)); json_decref (contract_terms); if (NULL == element) { @@ -323,8 +326,8 @@ transform_response (const json_t *result, &h_key); if (NULL != (current_entry = - GNUNET_CONTAINER_multihashmap_get (map, - &h_key))) + GNUNET_CONTAINER_multihashmap_get (map, + &h_key))) { /* The map already knows this h_contract_terms*/ if ( (GNUNET_SYSERR == @@ -374,7 +377,7 @@ transform_response (const json_t *result, "deposits_sums", rctx->deposits_response); rctx->deposits_response = NULL; - cleanup: +cleanup: GNUNET_CONTAINER_multihashmap_iterate (map, &hashmap_free, NULL); @@ -467,16 +470,25 @@ check_transfer (void *cls, rctx->check_transfer_result = GNUNET_SYSERR; /* Build the `TrackTransferConflictDetails` */ rctx->response - = TMH_RESPONSE_make_json_pack ("{s:I, s:s, s:o, s:I, s:o, s:o, s:s, s:o, s:o}", - "code", (json_int_t) TALER_EC_TRACK_TRANSFER_CONFLICTING_REPORTS, - "hint", "disagreement about deposit valuation", - "exchange_deposit_proof", exchange_proof, - "conflict_offset", (json_int_t) rctx->current_offset, - "exchange_transfer_proof", rctx->original_response, - "coin_pub", GNUNET_JSON_from_data_auto (coin_pub), - "h_contract_terms", GNUNET_JSON_from_data_auto (&ttd->h_contract_terms), - "amount_with_fee", TALER_JSON_from_amount (amount_with_fee), - "deposit_fee", TALER_JSON_from_amount (deposit_fee)); + = TMH_RESPONSE_make_json_pack ( + "{s:I, s:s, s:o, s:I, s:o, s:o, s:s, s:o, s:o}", + "code", + (json_int_t) TALER_EC_TRACK_TRANSFER_CONFLICTING_REPORTS, + "hint", + "disagreement about deposit valuation", + "exchange_deposit_proof", exchange_proof, + "conflict_offset", + (json_int_t) rctx->current_offset, + "exchange_transfer_proof", + rctx->original_response, + "coin_pub", GNUNET_JSON_from_data_auto ( + coin_pub), + "h_contract_terms", + GNUNET_JSON_from_data_auto (&ttd->h_contract_terms), + "amount_with_fee", TALER_JSON_from_amount ( + amount_with_fee), + "deposit_fee", TALER_JSON_from_amount ( + deposit_fee)); return; } rctx->check_transfer_result = GNUNET_OK; @@ -552,18 +564,27 @@ check_wire_fee (struct TrackTransferContext *rctx, /* Wire fee check failed, export proof to client */ resume_track_transfer_with_response (rctx, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TMH_RESPONSE_make_json_pack ("{s:I, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:O}", - "code", (json_int_t) TALER_EC_TRACK_TRANSFER_JSON_BAD_WIRE_FEE, - "wire_fee", TALER_JSON_from_amount (wire_fee), - "execution_time", GNUNET_JSON_from_time_abs (execution_time), - "expected_wire_fee", TALER_JSON_from_amount (&expected_fee), - "expected_closing_fee", TALER_JSON_from_amount (&closing_fee), - "start_date", GNUNET_JSON_from_time_abs (start_date), - "end_date", GNUNET_JSON_from_time_abs (end_date), - "master_sig", GNUNET_JSON_from_data_auto (&master_sig), - "master_pub", GNUNET_JSON_from_data_auto (master_pub), - "json", json)); + MHD_HTTP_INTERNAL_SERVER_ERROR, + TMH_RESPONSE_make_json_pack ( + "{s:I, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:O}", + "code", + (json_int_t) TALER_EC_TRACK_TRANSFER_JSON_BAD_WIRE_FEE, + "wire_fee", TALER_JSON_from_amount (wire_fee), + "execution_time", GNUNET_JSON_from_time_abs ( + execution_time), + "expected_wire_fee", TALER_JSON_from_amount ( + &expected_fee), + "expected_closing_fee", + TALER_JSON_from_amount (&closing_fee), + "start_date", GNUNET_JSON_from_time_abs ( + start_date), + "end_date", GNUNET_JSON_from_time_abs ( + end_date), + "master_sig", GNUNET_JSON_from_data_auto ( + &master_sig), + "master_pub", GNUNET_JSON_from_data_auto ( + master_pub), + "json", json)); return GNUNET_SYSERR; } @@ -611,15 +632,18 @@ wire_transfer_cb (void *cls, { resume_track_transfer_with_response (rctx, - MHD_HTTP_FAILED_DEPENDENCY, - TMH_RESPONSE_make_json_pack ("{s:I, s:I, s:I, s:O}", - "code", (json_int_t) TALER_EC_TRACK_TRANSFER_EXCHANGE_ERROR, - "exchange-code", (json_int_t) ec, - "exchange-http-status", (json_int_t) http_status, - "details", json)); + MHD_HTTP_FAILED_DEPENDENCY, + TMH_RESPONSE_make_json_pack ("{s:I, s:I, s:I, s:O}", + "code", + (json_int_t) + TALER_EC_TRACK_TRANSFER_EXCHANGE_ERROR, + "exchange-code", (json_int_t) ec, + "exchange-http-status", + (json_int_t) http_status, + "details", json)); return; } - for (unsigned int i=0;ipreflight (db->cls); qs = db->store_transfer_to_proof (db->cls, @@ -639,10 +663,13 @@ wire_transfer_cb (void *cls, GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); resume_track_transfer_with_response (rctx, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TMH_RESPONSE_make_json_pack ("{s:I, s:s}", - "code", (json_int_t) TALER_EC_TRACK_TRANSFER_DB_STORE_TRANSFER_ERROR, - "details", "failed to store response from exchange to local database")); + MHD_HTTP_INTERNAL_SERVER_ERROR, + TMH_RESPONSE_make_json_pack ("{s:I, s:s}", + "code", + (json_int_t) + TALER_EC_TRACK_TRANSFER_DB_STORE_TRANSFER_ERROR, + "details", + "failed to store response from exchange to local database")); return; } rctx->original_response = json; @@ -662,7 +689,7 @@ wire_transfer_cb (void *cls, * details_length is how many (Taler coin) deposits have been * aggregated into _this_ wire transfer. */ - for (unsigned int i=0;icurrent_offset = i; rctx->current_detail = &details[i]; @@ -678,16 +705,19 @@ wire_transfer_cb (void *cls, if (0 > qs) { /* single, read-only SQL statements should never cause - serialization problems */ + serialization problems */ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR != qs); /* Always report on hard error as well to enable diagnostics */ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); resume_track_transfer_with_response (rctx, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TMH_RESPONSE_make_json_pack ("{s:I, s:s}", - "code", (json_int_t) TALER_EC_TRACK_TRANSFER_DB_FETCH_DEPOSIT_ERROR, - "details", "failed to obtain deposit data from local database")); + MHD_HTTP_INTERNAL_SERVER_ERROR, + TMH_RESPONSE_make_json_pack ("{s:I, s:s}", + "code", + (json_int_t) + TALER_EC_TRACK_TRANSFER_DB_FETCH_DEPOSIT_ERROR, + "details", + "failed to obtain deposit data from local database")); return; } if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) @@ -706,12 +736,14 @@ wire_transfer_cb (void *cls, GNUNET_break (0); resume_track_transfer_with_response (rctx, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TMH_RESPONSE_make_json_pack ("{s:I, s:s, s:I, s:s}", - "code", (json_int_t) TALER_EC_TRACK_TRANSFER_DB_INTERNAL_LOGIC_ERROR, - "details", "internal logic error", - "line", (json_int_t) __LINE__, - "file", __FILE__)); + MHD_HTTP_INTERNAL_SERVER_ERROR, + TMH_RESPONSE_make_json_pack ("{s:I, s:s, s:I, s:s}", + "code", + (json_int_t) + TALER_EC_TRACK_TRANSFER_DB_INTERNAL_LOGIC_ERROR, + "details", "internal logic error", + "line", (json_int_t) __LINE__, + "file", __FILE__)); return; } if (GNUNET_SYSERR == rctx->check_transfer_result) @@ -721,14 +753,14 @@ wire_transfer_cb (void *cls, GNUNET_assert (NULL != rctx->response); resume_track_transfer_with_response (rctx, - MHD_HTTP_FAILED_DEPENDENCY, - rctx->response); + MHD_HTTP_FAILED_DEPENDENCY, + rctx->response); rctx->response = NULL; return; } /* Response is consistent with the /deposit we made, remember it for future reference */ - for (unsigned int r=0;rpreflight (db->cls); qs = db->store_coin_to_transfer (db->cls, @@ -746,10 +778,13 @@ wire_transfer_cb (void *cls, GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); resume_track_transfer_with_response (rctx, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TMH_RESPONSE_make_json_pack ("{s:I, s:s}", - "code", (json_int_t) TALER_EC_TRACK_TRANSFER_DB_STORE_COIN_ERROR, - "details", "failed to store response from exchange to local database")); + MHD_HTTP_INTERNAL_SERVER_ERROR, + TMH_RESPONSE_make_json_pack ("{s:I, s:s}", + "code", + (json_int_t) + TALER_EC_TRACK_TRANSFER_DB_STORE_COIN_ERROR, + "details", + "failed to store response from exchange to local database")); return; } } @@ -759,14 +794,14 @@ wire_transfer_cb (void *cls, "About to call tracks transformator.\n"); if (NULL == (jresponse = - transform_response (json, - rctx))) + transform_response (json, + rctx))) { resume_track_transfer_with_response (rctx, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TMH_RESPONSE_make_error (TALER_EC_TRACK_TRANSFER_JSON_RESPONSE_ERROR, - "Fail to elaborate the response.")); + MHD_HTTP_INTERNAL_SERVER_ERROR, + TMH_RESPONSE_make_error (TALER_EC_TRACK_TRANSFER_JSON_RESPONSE_ERROR, + "Fail to elaborate the response.")); return; } @@ -804,10 +839,13 @@ process_track_transfer_with_exchange (void *cls, GNUNET_break (0); resume_track_transfer_with_response (rctx, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TMH_RESPONSE_make_json_pack ("{s:I, s:s}", - "code", (json_int_t) TALER_EC_TRACK_TRANSFER_REQUEST_ERROR, - "error", "failed to run /track/transfer on exchange")); + MHD_HTTP_INTERNAL_SERVER_ERROR, + TMH_RESPONSE_make_json_pack ("{s:I, s:s}", + "code", + (json_int_t) + TALER_EC_TRACK_TRANSFER_REQUEST_ERROR, + "error", + "failed to run /track/transfer on exchange")); } } @@ -833,8 +871,9 @@ handle_track_transfer_timeout (void *cls) } resume_track_transfer_with_response (rctx, MHD_HTTP_SERVICE_UNAVAILABLE, - TMH_RESPONSE_make_error (TALER_EC_TRACK_TRANSFER_EXCHANGE_TIMEOUT, - "exchange not reachable")); + TMH_RESPONSE_make_error ( + TALER_EC_TRACK_TRANSFER_EXCHANGE_TIMEOUT, + "exchange not reachable")); } @@ -855,13 +894,13 @@ proof_cb (void *cls, json_t *transformed_response; if (NULL == (transformed_response = - transform_response (proof, - rctx))) + transform_response (proof, + rctx))) { rctx->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; rctx->response = TMH_RESPONSE_make_error (TALER_EC_TRACK_TRANSFER_JSON_RESPONSE_ERROR, - "Fail to elaborate response."); + "Fail to elaborate response."); return; } @@ -881,8 +920,7 @@ proof_cb (void *cls, * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -891,7 +929,7 @@ MH_handler_track_transfer (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id) + struct MerchantInstance *mi) { struct TrackTransferContext *rctx; const char *str; @@ -966,20 +1004,15 @@ MH_handler_track_transfer (struct TMH_RequestHandler *rh, GNUNET_break (0); wire_method = "x-taler-bank"; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Client needs fixing, see API change for #4943!\n"); + "Client needs fixing, see API change for #4943!\n"); } else return TMH_RESPONSE_reply_arg_missing (connection, - TALER_EC_PARAMETER_MISSING, - "wire_method"); + TALER_EC_PARAMETER_MISSING, + "wire_method"); } rctx->wire_method = GNUNET_strdup (wire_method); - - rctx->mi = TMH_lookup_instance (instance_id); - if (NULL == rctx->mi) - return TMH_RESPONSE_reply_not_found (connection, - TALER_EC_TRACK_TRANSFER_INSTANCE_UNKNOWN, - "instance unknown"); + rctx->mi = mi; str = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "wtid"); diff --git a/src/backend/taler-merchant-httpd_track-transfer.h b/src/backend/taler-merchant-httpd_track-transfer.h index 8da998dc..8ec85678 100644 --- a/src/backend/taler-merchant-httpd_track-transfer.h +++ b/src/backend/taler-merchant-httpd_track-transfer.h @@ -34,8 +34,7 @@ * @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 - * @param instance_id merchant backend instance ID or NULL is no instance - * has been explicitly specified + * @param mi merchant backend instance, never NULL * @return MHD result code */ int @@ -44,7 +43,7 @@ MH_handler_track_transfer (struct TMH_RequestHandler *rh, void **connection_cls, const char *upload_data, size_t *upload_data_size, - const char *instance_id); + struct MerchantInstance *mi); #endif -- cgit v1.2.3