diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-09-23 18:39:17 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-09-23 18:39:17 +0200 |
commit | 63994abe1e2780d3a43e261090d3261e8d91a854 (patch) | |
tree | 2d2fb235f05d12fcd5d9ea9c34be29c6e37b51c5 /src/backend | |
parent | 7d50af6651ea4e0a15960434e1d574596552ead7 (diff) | |
download | merchant-63994abe1e2780d3a43e261090d3261e8d91a854.tar.gz merchant-63994abe1e2780d3a43e261090d3261e8d91a854.tar.bz2 merchant-63994abe1e2780d3a43e261090d3261e8d91a854.zip |
implement instances via one base URL per instance
Previously, instances were addressed in various ways depending on then
request (GET parameter, some instance_id in the POST body). With this
commit, users of the merchant backend don't see the instance, they just
see another base URL.
Diffstat (limited to 'src/backend')
26 files changed, 332 insertions, 367 deletions
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index 5269c4c4..0accbb85 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -301,6 +301,10 @@ url_handler (void *cls, struct TM_HandlerContext *hc; struct GNUNET_AsyncScopeId aid; const char *correlation_id = NULL; + char *instance_id; + char *effective_url; + int ret; + hc = *con_cls; @@ -338,23 +342,53 @@ url_handler (void *cls, method, url); - for (unsigned int i = 0; NULL != handlers[i].url; i++) + /* 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 "/instance/" + instance_id = GNUNET_strdup (url + strlen (instance_prefix)); + char *slash = strchr (instance_id, '/'); + if (NULL == slash) + { + GNUNET_free (instance_id); + return TMH_MHD_handler_static_response (&h404, + connection, + con_cls, + upload_data, + upload_data_size, + NULL); + } + effective_url = GNUNET_strdup (slash); + *slash = '\0'; + } + else + { + effective_url = GNUNET_strdup (url); + instance_id = NULL; + } + } + + + for (unsigned int i=0;NULL != handlers[i].url;i++) { struct TMH_RequestHandler *rh = &handlers[i]; - if ( (0 == strcmp (url, - rh->url)) && + if ( (0 == strcasecmp (effective_url, + rh->url)) && ( (NULL == rh->method) || (0 == strcasecmp (method, rh->method)) ) ) { - int ret; - ret = rh->handler (rh, - connection, - con_cls, - upload_data, - upload_data_size); + connection, + con_cls, + upload_data, + upload_data_size, + instance_id); hc = *con_cls; if (NULL != hc) { @@ -363,14 +397,18 @@ url_handler (void *cls, * we get another callack for this request. */ hc->async_scope_id = aid; } + GNUNET_free_non_null (instance_id); return ret; } } - return TMH_MHD_handler_static_response (&h404, - connection, - con_cls, - upload_data, - upload_data_size); + 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; } @@ -1132,23 +1170,26 @@ instances_iterator_cb (void *cls, /** - * Lookup a merchant instance by its name. + * Lookup a merchant instance by its instance ID. * - * @param name name of the instance to resolve + * @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 *name) +TMH_lookup_instance (const char *instance_id) { struct GNUNET_HashCode h_instance; - GNUNET_CRYPTO_hash (name, - strlen (name), + if (NULL == instance_id) + instance_id = "default"; + + GNUNET_CRYPTO_hash (instance_id, + strlen (instance_id), &h_instance); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking for by-id key %s of '%s' in hashmap\n", GNUNET_h2s (&h_instance), - name); + instance_id); /* We're fine if that returns NULL, the calling routine knows how to handle that */ return GNUNET_CONTAINER_multihashmap_get (by_id_map, @@ -1157,35 +1198,6 @@ TMH_lookup_instance (const char *name) /** - * Extract merchant instance from the given JSON; if not - * 'instance' field was found, then "default" instance is - * returned. - * - * @param json the JSON to inspect; it is not required to - * comply with any particular format. It will only be checked - * if the field "instance" is there. - * @return a pointer to a `struct MerchantInstance`. This will be - * the 'default' merchant if the frontend did not specify any - * "instance" field. The user should not care to free the returned - * value, as it is taken from a global array that will be freed - * by the general shutdown routine. NULL if the frontend specified - * a wrong instance - */ -struct MerchantInstance * -TMH_lookup_instance_json (struct json_t *json) -{ - struct json_t *instance; - const char *instance_str; - - if (NULL == (instance = json_object_get (json, "instance"))) - instance_str = "default"; - else - instance_str = json_string_value (instance); - return TMH_lookup_instance (instance_str); -} - - -/** * Iterate over locations in config in order to populate * the location data. * diff --git a/src/backend/taler-merchant-httpd.h b/src/backend/taler-merchant-httpd.h index ee3d88fe..4e939b96 100644 --- a/src/backend/taler-merchant-httpd.h +++ b/src/backend/taler-merchant-httpd.h @@ -203,13 +203,16 @@ 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 * @return MHD result code */ int (*handler)(struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size); + size_t *upload_data_size, + const char *instance_id); /** * Default response code. @@ -351,21 +354,4 @@ struct MerchantInstance * TMH_lookup_instance (const char *name); -/** - * Extract merchant instance from the given JSON - * - * @param json the JSON to inspect; it is not required to - * comply with any particular format. It will only be checked - * if the field "instance" is there. - * @return a pointer to a #struct MerchantInstance. This will be - * the 'default' merchant if the frontend did not specif any - * "instance" field. The user should not care to free the returned - * value, as it is taken from a global array that will be freed - * by the general shutdown routine. NULL if the frontend specified - * a wrong instance - */ -struct MerchantInstance * -TMH_lookup_instance_json (struct json_t *json); - - #endif diff --git a/src/backend/taler-merchant-httpd_check-payment.c b/src/backend/taler-merchant-httpd_check-payment.c index 59ed60d1..2ba4cc4a 100644 --- a/src/backend/taler-merchant-httpd_check-payment.c +++ b/src/backend/taler-merchant-httpd_check-payment.c @@ -291,6 +291,8 @@ 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 * @return MHD result code */ int @@ -298,12 +300,12 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size) + size_t *upload_data_size, + const char *instance_id) { const char *order_id; const char *contract_url; const char *session_id; - const char *instance_str; const char *fulfillment_url; char *final_contract_url; char *h_contract_terms_str; @@ -315,12 +317,7 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, int ret; int refunded; - instance_str = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "instance"); - if (NULL == instance_str) - instance_str = "default"; - mi = TMH_lookup_instance (instance_str); + mi = TMH_lookup_instance (instance_id); if (NULL == mi) return TMH_RESPONSE_reply_bad_request (connection, TALER_EC_CHECK_PAYMENT_INSTANCE_UNKNOWN, @@ -343,7 +340,7 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, { final_contract_url = TALER_url_absolute_mhd (connection, "/public/proposal", - "instance", instance_str, + "instance", instance_id, "order_id", order_id, NULL); GNUNET_assert (NULL != final_contract_url); diff --git a/src/backend/taler-merchant-httpd_check-payment.h b/src/backend/taler-merchant-httpd_check-payment.h index 14c2a67b..98fa3a11 100644 --- a/src/backend/taler-merchant-httpd_check-payment.h +++ b/src/backend/taler-merchant-httpd_check-payment.h @@ -34,6 +34,8 @@ * @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 * @return MHD result code */ int @@ -41,6 +43,7 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size); + size_t *upload_data_size, + const char *instance_id); #endif diff --git a/src/backend/taler-merchant-httpd_config.c b/src/backend/taler-merchant-httpd_config.c index 51d44729..3e7b7b39 100644 --- a/src/backend/taler-merchant-httpd_config.c +++ b/src/backend/taler-merchant-httpd_config.c @@ -39,6 +39,8 @@ * @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 * @return MHD result code */ int @@ -46,19 +48,13 @@ MH_handler_config (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size) + size_t *upload_data_size, + const char *instance_id) { int ret; - const char *instance_str; struct MerchantInstance *mi; - instance_str = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "instance"); - if (NULL == instance_str) - instance_str = "default"; - - mi = TMH_lookup_instance (instance_str); + mi = TMH_lookup_instance (instance_id); if (NULL == mi) return TMH_RESPONSE_reply_bad_request (connection, diff --git a/src/backend/taler-merchant-httpd_config.h b/src/backend/taler-merchant-httpd_config.h index cff766eb..08594a5f 100644 --- a/src/backend/taler-merchant-httpd_config.h +++ b/src/backend/taler-merchant-httpd_config.h @@ -31,6 +31,8 @@ * @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 * @return MHD result code */ int @@ -38,6 +40,7 @@ MH_handler_config (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size); + size_t *upload_data_size, + const char *instance_id); #endif diff --git a/src/backend/taler-merchant-httpd_history.c b/src/backend/taler-merchant-httpd_history.c index 2d620890..36ca7290 100644 --- a/src/backend/taler-merchant-httpd_history.c +++ b/src/backend/taler-merchant-httpd_history.c @@ -122,6 +122,8 @@ 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 * @return MHD result code */ int @@ -129,7 +131,8 @@ MH_handler_history (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size) + size_t *upload_data_size, + const char *instance_id) { #define LOG_INFO(...) GNUNET_log (GNUNET_ERROR_TYPE_INFO, __VA_ARGS__) const char *str; @@ -172,10 +175,7 @@ MH_handler_history (struct TMH_RequestHandler *rh, } } - str = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "instance"); - mi = TMH_lookup_instance (NULL != str ? str : "default"); + mi = TMH_lookup_instance (instance_id); if (NULL == mi) { diff --git a/src/backend/taler-merchant-httpd_history.h b/src/backend/taler-merchant-httpd_history.h index a06e926f..5ea2ed23 100644 --- a/src/backend/taler-merchant-httpd_history.h +++ b/src/backend/taler-merchant-httpd_history.h @@ -34,6 +34,8 @@ * @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 * @return MHD result code */ int @@ -41,7 +43,8 @@ MH_handler_history (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size); + size_t *upload_data_size, + const char *instance_id); /* 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 e4e5329c..a17485cc 100644 --- a/src/backend/taler-merchant-httpd_mhd.c +++ b/src/backend/taler-merchant-httpd_mhd.c @@ -37,6 +37,8 @@ * @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 * @return MHD result code */ int @@ -44,7 +46,8 @@ TMH_MHD_handler_static_response (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size) + size_t *upload_data_size, + const char *instance_id) { struct MHD_Response *response; int ret; @@ -81,6 +84,8 @@ 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 * @return MHD result code */ int @@ -88,7 +93,8 @@ 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) + size_t *upload_data_size, + const char *instance_id) { const char *agpl = "This server is licensed under the Affero GPL. You will now be redirected to the source code."; @@ -136,6 +142,8 @@ 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 * @return MHD result code */ int @@ -143,7 +151,8 @@ 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) + size_t *upload_data_size, + const char *instance_id) { 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 5f0e69be..0ec9830b 100644 --- a/src/backend/taler-merchant-httpd_mhd.h +++ b/src/backend/taler-merchant-httpd_mhd.h @@ -37,6 +37,8 @@ * @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 * @return MHD result code */ int @@ -44,7 +46,8 @@ TMH_MHD_handler_static_response (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size); + size_t *upload_data_size, + const char *instance_id); /** @@ -56,6 +59,8 @@ 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 * @return MHD result code */ int @@ -63,7 +68,8 @@ 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); + size_t *upload_data_size, + const char *instance_id); /** @@ -98,6 +104,8 @@ 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 * @return MHD result code */ int @@ -105,7 +113,8 @@ 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); + size_t *upload_data_size, + const char *instance_id); #endif diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c index d381c7ee..e72a8e25 100644 --- a/src/backend/taler-merchant-httpd_pay.c +++ b/src/backend/taler-merchant-httpd_pay.c @@ -1471,27 +1471,6 @@ parse_pay (struct MHD_Connection *connection, pc->mode = PC_MODE_PAY; else pc->mode = PC_MODE_ABORT_REFUND; - pc->mi = TMH_lookup_instance_json (merchant); - if (NULL == pc->mi) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Unable to find the specified instance\n"); - GNUNET_JSON_parse_free (spec); - 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; - } - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "/pay: picked instance %s\n", - pc->mi->id); - { const char *fulfillment_url; struct GNUNET_JSON_Specification espec[] = { @@ -2136,6 +2115,8 @@ 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 * @return MHD result code */ int @@ -2143,7 +2124,8 @@ MH_handler_pay (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size) + size_t *upload_data_size, + const char *instance_id) { struct PayContext *pc; int res; @@ -2160,6 +2142,25 @@ 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; + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "/pay: picked instance %s\n", + pc->mi->id); + } else { diff --git a/src/backend/taler-merchant-httpd_pay.h b/src/backend/taler-merchant-httpd_pay.h index d4f4958a..cffb13bb 100644 --- a/src/backend/taler-merchant-httpd_pay.h +++ b/src/backend/taler-merchant-httpd_pay.h @@ -40,6 +40,8 @@ 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 * @return MHD result code */ int @@ -47,6 +49,7 @@ MH_handler_pay (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size); + size_t *upload_data_size, + const char *instance_id); #endif diff --git a/src/backend/taler-merchant-httpd_proposal.c b/src/backend/taler-merchant-httpd_proposal.c index a93d6f17..7f61d215 100644 --- a/src/backend/taler-merchant-httpd_proposal.c +++ b/src/backend/taler-merchant-httpd_proposal.c @@ -149,10 +149,10 @@ json_parse_cleanup (struct TM_HandlerContext *hc) */ static int proposal_put (struct MHD_Connection *connection, - json_t *order) + json_t *order, + const struct MerchantInstance *mi) { int res; - struct MerchantInstance *mi; struct TALER_Amount total; const char *order_id; const char *summary; @@ -182,7 +182,6 @@ proposal_put (struct MHD_Connection *connection, GNUNET_JSON_spec_end () }; enum GNUNET_DB_QueryStatus qs; - const char *instance; struct WireMethod *wm; /* Add order_id if it doesn't exist. */ @@ -309,111 +308,81 @@ proposal_put (struct MHD_Connection *connection, json_array ()); } - instance = json_string_value (json_object_get (order, - "instance")); - if (NULL == instance) - { - TALER_LOG_DEBUG ("Giving 'default' instance\n"); - instance = "default"; - } - /* Fill in merchant information if necessary */ + if (NULL == json_object_get (order, "merchant")) { - /* The frontend either fully specifieds the "merchant" field, - * or just gives the backend the "instance" name and lets it - * fill out. */ - struct MerchantInstance *my_mi = TMH_lookup_instance (instance); - - if (NULL == my_mi) + const char *mj = NULL; + const char *ma = NULL; + json_t *locations; + char *label; + json_t *jmerchant; + + jmerchant = json_object (); + json_object_set_new (jmerchant, + "name", + json_string (mi->name)); + json_object_set_new (jmerchant, + "instance", + json_string (mi->id)); + locations = json_object_get (order, + "locations"); + if (NULL != locations) { - TALER_LOG_WARNING ("Does 'default' instance exist?\n"); - return TMH_RESPONSE_reply_not_found - (connection, - TALER_EC_CONTRACT_INSTANCE_UNKNOWN, - "merchant instance (order:instance) not found"); - } - - /** - * Potential bug: if the outer 'instance' field is not - * given and the 'merchant' object is also missing, then - * is not possible to extract the instance! - */ - if (NULL == json_object_get (order, - "merchant")) - { - const char *mj = NULL; - const char *ma = NULL; - json_t *locations; - char *label; - json_t *jmerchant; - - jmerchant = json_object (); - json_object_set_new (jmerchant, - "name", - json_string (my_mi->name)); - json_object_set_new (jmerchant, - "instance", - json_string (instance)); - locations = json_object_get (order, - "locations"); - if (NULL != locations) + json_t *loca; + json_t *locj; + + /* Handle merchant address */ + GNUNET_assert (0 < GNUNET_asprintf (&label, + "%s-address", + mi->id)); + loca = json_object_get (default_locations, + label); + if (NULL != loca) + { + loca = json_deep_copy (loca); + ma = STANDARD_LABEL_MERCHANT_ADDRESS; + json_object_set_new (locations, + ma, + loca); + json_object_set_new (jmerchant, + "address", + json_string (ma)); + } + GNUNET_free (label); + + /* Handle merchant jurisdiction */ + GNUNET_assert (0 < GNUNET_asprintf (&label, + "%s-jurisdiction", + mi->id)); + locj = json_object_get (default_locations, + label); + if (NULL != locj) { - json_t *loca; - json_t *locj; - - /* Handle merchant address */ - GNUNET_assert (0 < GNUNET_asprintf (&label, - "%s-address", - my_mi->id)); - loca = json_object_get (default_locations, - label); - if (NULL != loca) + if ( (NULL != loca) && + (1 == json_equal (locj, + loca)) ) { - loca = json_deep_copy (loca); - ma = STANDARD_LABEL_MERCHANT_ADDRESS; - json_object_set_new (locations, - ma, - loca); - json_object_set_new (jmerchant, - "address", - json_string (ma)); + /* addresses equal, re-use */ + mj = ma; } - GNUNET_free (label); - - /* Handle merchant jurisdiction */ - GNUNET_assert (0 < GNUNET_asprintf (&label, - "%s-jurisdiction", - my_mi->id)); - locj = json_object_get (default_locations, - label); - if (NULL != locj) + else { - if ( (NULL != loca) && - (1 == json_equal (locj, - loca)) ) - { - /* addresses equal, re-use */ - mj = ma; - } - else - { - locj = json_deep_copy (locj); - mj = STANDARD_LABEL_MERCHANT_JURISDICTION; - json_object_set_new (locations, - mj, - locj); - } - json_object_set_new (merchant, - "jurisdiction", - json_string (mj)); + locj = json_deep_copy (locj); + mj = STANDARD_LABEL_MERCHANT_JURISDICTION; + json_object_set_new (locations, + mj, + locj); } - GNUNET_free (label); - } /* have locations */ - json_object_set_new (order, - "merchant", - jmerchant); - } /* needed to synthesize merchant info */ - } /* scope of 'my_mi' */ + json_object_set_new (merchant, + "jurisdiction", + json_string (mj)); + } + GNUNET_free (label); + } /* have locations */ + json_object_set_new (order, + "merchant", + jmerchant); + } /* needed to synthesize merchant info */ /* extract fields we need to sign separately */ res = TMH_PARSE_json_data (connection, @@ -444,45 +413,6 @@ proposal_put (struct MHD_Connection *connection, "order:products"); } - mi = TMH_lookup_instance_json (merchant); - - if (NULL == mi) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Not able to find the specified instance\n"); - GNUNET_JSON_parse_free (spec); - return TMH_RESPONSE_reply_not_found - (connection, - TALER_EC_CONTRACT_INSTANCE_UNKNOWN, - "Unknown instance (order:merchant:instance) given"); - } - - /* The outer instance field, and the one included - * in the merchant object are different */ - if (0 != strcmp (mi->id, - instance)) - { - TALER_LOG_ERROR - ("Inconsistent instance specified" - " by merchant ('%s' vs '%s')\n", - instance, - mi->id); - - TALER_LOG_DEBUG ("Dump wrong order: %s\n", - json_dumps (order, - JSON_INDENT (1))); - - return TMH_RESPONSE_reply_not_found - (connection, - TALER_EC_CONTRACT_INSTANCE_INCONSISTENT, - "Inconsistent instance given"); - } - - /* Setting the instance on the order directly is just a shortcut, - the wallet shouldn't see that. */ - json_object_del (order, "instance"); - instance = NULL; - /* add fields to the contract that the backend should provide */ json_object_set (order, "exchanges", @@ -499,7 +429,7 @@ proposal_put (struct MHD_Connection *connection, { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No wire method available for" - " specified instance\n"); + " instance '%s'\n", mi->id); GNUNET_JSON_parse_free (spec); return TMH_RESPONSE_reply_not_found (connection, @@ -618,10 +548,12 @@ proposal_put (struct MHD_Connection *connection, * * @param connection the MHD connection to handle * @param[in,out] connection_cls the connection's closure - * (can be updated) + * (can be updated) * @param upload_data upload data * @param[in,out] upload_data_size number of bytes (left) in - * @a upload_data + * @a upload_data + * @param instance_id merchant backend instance ID or NULL is no instance + * has been explicitly specified * @return MHD result code */ int @@ -629,10 +561,12 @@ MH_handler_proposal_put (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size) + size_t *upload_data_size, + const char *instance_id) { int res; struct TMH_JsonParseContext *ctx; + struct MerchantInstance *mi; json_t *root; json_t *order; @@ -662,6 +596,12 @@ MH_handler_proposal_put (struct TMH_RequestHandler *rh, (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) @@ -672,8 +612,7 @@ MH_handler_proposal_put (struct TMH_RequestHandler *rh, "order"); } else - res = proposal_put (connection, - order); + res = proposal_put (connection, order, mi); json_decref (root); return res; } @@ -691,6 +630,8 @@ 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 * @return MHD result code */ int @@ -698,10 +639,10 @@ MH_handler_proposal_lookup (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size) + size_t *upload_data_size, + const char *instance_id) { const char *order_id; - const char *instance; const char *nonce; int res; enum GNUNET_DB_QueryStatus qs; @@ -710,14 +651,7 @@ MH_handler_proposal_lookup (struct TMH_RequestHandler *rh, struct GNUNET_CRYPTO_EddsaSignature merchant_sig; const char *stored_nonce; - instance = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "instance"); - if (NULL == instance) - return TMH_RESPONSE_reply_arg_missing (connection, - TALER_EC_PARAMETER_MISSING, - "instance"); - mi = TMH_lookup_instance (instance); + mi = TMH_lookup_instance (instance_id); if (NULL == mi) return TMH_RESPONSE_reply_not_found (connection, TALER_EC_CONTRACT_INSTANCE_UNKNOWN, diff --git a/src/backend/taler-merchant-httpd_proposal.h b/src/backend/taler-merchant-httpd_proposal.h index fe5b319a..137c32a6 100644 --- a/src/backend/taler-merchant-httpd_proposal.h +++ b/src/backend/taler-merchant-httpd_proposal.h @@ -33,6 +33,8 @@ * @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 * @return MHD result code */ int @@ -40,7 +42,8 @@ MH_handler_proposal_put (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size); + size_t *upload_data_size, + const char *instance_id); /** @@ -60,5 +63,6 @@ MH_handler_proposal_lookup (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size); + size_t *upload_data_size, + const char *instance_id); #endif diff --git a/src/backend/taler-merchant-httpd_refund.c b/src/backend/taler-merchant-httpd_refund.c index 1f80491c..a20149a1 100644 --- a/src/backend/taler-merchant-httpd_refund.c +++ b/src/backend/taler-merchant-httpd_refund.c @@ -155,6 +155,8 @@ 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 * @return MHD result code */ int @@ -162,7 +164,8 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size) + size_t *upload_data_size, + const char *instance_id) { int res; struct TMH_JsonParseContext *ctx; @@ -171,7 +174,6 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh, json_t *contract_terms; const char *order_id; const char *reason; - const char *merchant; struct MerchantInstance *mi; struct GNUNET_HashCode h_contract_terms; struct TALER_MerchantRefundConfirmationPS confirmation; @@ -180,7 +182,6 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh, TALER_JSON_spec_amount ("refund", &refund), GNUNET_JSON_spec_string ("order_id", &order_id), GNUNET_JSON_spec_string ("reason", &reason), - GNUNET_JSON_spec_string ("instance", &merchant), GNUNET_JSON_spec_end () }; enum GNUNET_DB_QueryStatus qs; @@ -226,11 +227,12 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh, return MHD_NO; } - mi = TMH_lookup_instance (merchant); + mi = TMH_lookup_instance (instance_id); if (NULL == mi) { + GNUNET_assert (NULL != instance_id); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "No instance found\n"); + "Instance '%s' not found\n", instance_id); GNUNET_JSON_parse_free (spec); json_decref (root); return TMH_RESPONSE_reply_not_found (connection, @@ -491,6 +493,8 @@ 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 * @return MHD result code */ int @@ -498,34 +502,23 @@ MH_handler_refund_lookup (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size) + size_t *upload_data_size, + const char *instance_id) { const char *order_id; - const char *instance; struct GNUNET_HashCode h_contract_terms; json_t *contract_terms; struct MerchantInstance *mi; enum GNUNET_DB_QueryStatus qs; - instance = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "instance"); - if (NULL == instance) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Argument 'instance' not given\n"); - return TMH_RESPONSE_reply_arg_missing (connection, - TALER_EC_PARAMETER_MISSING, - "instance"); - } - - mi = TMH_lookup_instance (instance); + 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); + instance_id); return TMH_RESPONSE_reply_not_found (connection, TALER_EC_REFUND_INSTANCE_UNKNOWN, "Unknown instance given"); diff --git a/src/backend/taler-merchant-httpd_refund.h b/src/backend/taler-merchant-httpd_refund.h index 32083273..eadd24a9 100644 --- a/src/backend/taler-merchant-httpd_refund.h +++ b/src/backend/taler-merchant-httpd_refund.h @@ -34,6 +34,8 @@ * @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 * @return MHD result code */ int @@ -41,7 +43,8 @@ MH_handler_refund_increase (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size); + size_t *upload_data_size, + const char *instance_id); /** @@ -52,6 +55,8 @@ 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 * @return MHD result code */ int @@ -59,7 +64,8 @@ MH_handler_refund_lookup (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size); + size_t *upload_data_size, + const char *instance_id); /** * Get the JSON representation of a refund. diff --git a/src/backend/taler-merchant-httpd_tip-authorize.c b/src/backend/taler-merchant-httpd_tip-authorize.c index 4c2451e8..1a79d772 100644 --- a/src/backend/taler-merchant-httpd_tip-authorize.c +++ b/src/backend/taler-merchant-httpd_tip-authorize.c @@ -45,11 +45,6 @@ struct TipAuthContext void *json_parse_context; /** - * Merchant instance to use. - */ - const char *instance; - - /** * Justification to use. */ const char *justification; @@ -112,6 +107,8 @@ 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 * @return MHD result code */ int @@ -119,7 +116,8 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size) + size_t *upload_data_size, + const char *instance_id) { struct TipAuthContext *tac; int res; @@ -153,7 +151,6 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh, { struct GNUNET_JSON_Specification spec[] = { TALER_JSON_spec_amount ("amount", &tac->amount), - GNUNET_JSON_spec_string ("instance", &tac->instance), GNUNET_JSON_spec_string ("justification", &tac->justification), GNUNET_JSON_spec_end() }; @@ -181,12 +178,13 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh, tac->parsed_json = GNUNET_YES; } - mi = TMH_lookup_instance (tac->instance); + 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", - tac->instance); + instance_id); return TMH_RESPONSE_reply_not_found (connection, TALER_EC_TIP_AUTHORIZE_INSTANCE_UNKNOWN, "unknown instance"); @@ -195,7 +193,7 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh, { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Instance `%s' not configured for tipping\n", - tac->instance); + (NULL != instance_id) ? instance_id : "default"); return TMH_RESPONSE_reply_not_found (connection, TALER_EC_TIP_AUTHORIZE_INSTANCE_DOES_NOT_TIP, "exchange for tipping not configured for the instance"); diff --git a/src/backend/taler-merchant-httpd_tip-authorize.h b/src/backend/taler-merchant-httpd_tip-authorize.h index b7c3b9a1..025b9580 100644 --- a/src/backend/taler-merchant-httpd_tip-authorize.h +++ b/src/backend/taler-merchant-httpd_tip-authorize.h @@ -32,6 +32,8 @@ * @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 * @return MHD result code */ int @@ -39,6 +41,7 @@ MH_handler_tip_authorize (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size); + size_t *upload_data_size, + const char *instance_id); #endif diff --git a/src/backend/taler-merchant-httpd_tip-pickup.c b/src/backend/taler-merchant-httpd_tip-pickup.c index eba99e38..6232c4b8 100644 --- a/src/backend/taler-merchant-httpd_tip-pickup.c +++ b/src/backend/taler-merchant-httpd_tip-pickup.c @@ -494,6 +494,8 @@ 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 * @return MHD result code */ int @@ -501,7 +503,8 @@ MH_handler_tip_pickup (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size) + size_t *upload_data_size, + const char *instance_id) { int res; struct GNUNET_HashCode tip_id; @@ -608,6 +611,8 @@ 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 * @return MHD result code */ int @@ -615,10 +620,10 @@ MH_handler_tip_pickup_get (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size) + size_t *upload_data_size, + const char *instance_id) { struct MerchantInstance *mi; - const char *instance_str; const char *tip_id_str; char *exchange_url; json_t *extra; @@ -630,12 +635,7 @@ MH_handler_tip_pickup_get (struct TMH_RequestHandler *rh, int ret; int qs; - instance_str = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "instance"); - if (NULL == instance_str) - instance_str = "default"; - mi = TMH_lookup_instance (instance_str); + mi = TMH_lookup_instance (instance_id); if (NULL == mi) return TMH_RESPONSE_reply_bad_request (connection, TALER_EC_TIP_INSTANCE_UNKNOWN, diff --git a/src/backend/taler-merchant-httpd_tip-pickup.h b/src/backend/taler-merchant-httpd_tip-pickup.h index 181725a7..f0e9733d 100644 --- a/src/backend/taler-merchant-httpd_tip-pickup.h +++ b/src/backend/taler-merchant-httpd_tip-pickup.h @@ -32,6 +32,8 @@ * @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 * @return MHD result code */ int @@ -39,7 +41,8 @@ MH_handler_tip_pickup (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size); + size_t *upload_data_size, + const char *instance_id); /** * Manages a GET /tip-pickup call. @@ -49,6 +52,8 @@ 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 * @return MHD result code */ int @@ -56,7 +61,8 @@ MH_handler_tip_pickup_get (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size); + size_t *upload_data_size, + const char *instance_id); #endif diff --git a/src/backend/taler-merchant-httpd_tip-query.c b/src/backend/taler-merchant-httpd_tip-query.c index 2b90b795..bd61a3e6 100644 --- a/src/backend/taler-merchant-httpd_tip-query.c +++ b/src/backend/taler-merchant-httpd_tip-query.c @@ -52,6 +52,12 @@ struct TipQueryContext const char *instance; /** + * GNUNET_YES if the tip query has already been processed + * and we can queue the response. + */ + int processed; + + /** * Context for checking the tipping reserve's status. */ struct CheckTipReserve ctr; @@ -126,6 +132,8 @@ 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 * @return MHD result code */ int @@ -133,7 +141,8 @@ MH_handler_tip_query (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size) + size_t *upload_data_size, + const char *instance_id) { struct TipQueryContext *tqc; struct MerchantInstance *mi; @@ -172,28 +181,21 @@ MH_handler_tip_query (struct TMH_RequestHandler *rh, return res; } - if (NULL != tqc->instance) + if (GNUNET_YES == tqc->processed) { /* We've been here before, so TMH_check_tip_reserve() must have finished and left the result for us. Finish processing. */ return generate_final_response (tqc); } - /* No error yet, so first time here, let's query the exchange */ - tqc->instance = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "instance"); - if (NULL == tqc->instance) - return TMH_RESPONSE_reply_arg_missing (connection, - TALER_EC_PARAMETER_MISSING, - "instance"); - mi = TMH_lookup_instance (tqc->instance); + 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", - tqc->instance); + instance_id); return TMH_RESPONSE_reply_not_found (connection, TALER_EC_TIP_AUTHORIZE_INSTANCE_UNKNOWN, "unknown instance"); @@ -202,7 +204,7 @@ MH_handler_tip_query (struct TMH_RequestHandler *rh, { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Instance `%s' not configured for tipping\n", - tqc->instance); + instance_id); return TMH_RESPONSE_reply_not_found (connection, TALER_EC_TIP_AUTHORIZE_INSTANCE_DOES_NOT_TIP, "exchange for tipping not configured for the instance"); @@ -236,6 +238,7 @@ MH_handler_tip_query (struct TMH_RequestHandler *rh, } } + tqc->processed = GNUNET_YES; TMH_check_tip_reserve (&tqc->ctr, mi->tip_exchange); return MHD_YES; diff --git a/src/backend/taler-merchant-httpd_tip-query.h b/src/backend/taler-merchant-httpd_tip-query.h index f3a9ebff..10b1e1be 100644 --- a/src/backend/taler-merchant-httpd_tip-query.h +++ b/src/backend/taler-merchant-httpd_tip-query.h @@ -31,6 +31,8 @@ * @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 * @return MHD result code */ int @@ -38,6 +40,7 @@ MH_handler_tip_query (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size); + size_t *upload_data_size, + const char *instance_id); #endif diff --git a/src/backend/taler-merchant-httpd_track-transaction.c b/src/backend/taler-merchant-httpd_track-transaction.c index 6879612d..1376aa9a 100644 --- a/src/backend/taler-merchant-httpd_track-transaction.c +++ b/src/backend/taler-merchant-httpd_track-transaction.c @@ -1037,6 +1037,8 @@ 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 * @return MHD result code */ int @@ -1044,13 +1046,12 @@ MH_handler_track_transaction (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size) + size_t *upload_data_size, + const char *instance_id) { struct TrackTransactionContext *tctx; const char *order_id; - const char *instance; enum GNUNET_DB_QueryStatus qs; - struct GNUNET_HashCode h_instance; struct json_t *contract_terms; if (NULL == *connection_cls) @@ -1105,26 +1106,16 @@ MH_handler_track_transaction (struct TMH_RequestHandler *rh, return TMH_RESPONSE_reply_arg_missing (connection, TALER_EC_PARAMETER_MISSING, "order_id"); - instance = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "instance"); - if (NULL == instance) - instance = "default"; - - GNUNET_CRYPTO_hash (instance, - strlen (instance), - &h_instance); - - tctx->mi = GNUNET_CONTAINER_multihashmap_get (by_id_map, - &h_instance); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Tracking on behalf of instance '%s'\n", - instance); + 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"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Tracking on behalf of instance '%s'\n", + instance_id); + /* Map order id to contract terms; the objective is to get the contract term's hashcode so as to retrieve all the diff --git a/src/backend/taler-merchant-httpd_track-transaction.h b/src/backend/taler-merchant-httpd_track-transaction.h index 30896bf3..7efecaa9 100644 --- a/src/backend/taler-merchant-httpd_track-transaction.h +++ b/src/backend/taler-merchant-httpd_track-transaction.h @@ -32,6 +32,8 @@ * @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 * @return MHD result code */ int @@ -39,7 +41,8 @@ MH_handler_track_transaction (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size); + size_t *upload_data_size, + const char *instance_id); #endif diff --git a/src/backend/taler-merchant-httpd_track-transfer.c b/src/backend/taler-merchant-httpd_track-transfer.c index 54810037..f833c7e9 100644 --- a/src/backend/taler-merchant-httpd_track-transfer.c +++ b/src/backend/taler-merchant-httpd_track-transfer.c @@ -881,6 +881,8 @@ 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 * @return MHD result code */ int @@ -888,12 +890,12 @@ MH_handler_track_transfer (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size) + size_t *upload_data_size, + const char *instance_id) { struct TrackTransferContext *rctx; const char *str; const char *url; - const char *instance_str; const char *wire_method; int ret; enum GNUNET_DB_QueryStatus qs; @@ -973,13 +975,7 @@ MH_handler_track_transfer (struct TMH_RequestHandler *rh, } rctx->wire_method = GNUNET_strdup (wire_method); - instance_str = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "instance"); - if (NULL == instance_str) - instance_str = "default"; - - rctx->mi = TMH_lookup_instance (instance_str); + rctx->mi = TMH_lookup_instance (instance_id); if (NULL == rctx->mi) return TMH_RESPONSE_reply_not_found (connection, TALER_EC_TRACK_TRANSFER_INSTANCE_UNKNOWN, diff --git a/src/backend/taler-merchant-httpd_track-transfer.h b/src/backend/taler-merchant-httpd_track-transfer.h index 13a173c9..8da998dc 100644 --- a/src/backend/taler-merchant-httpd_track-transfer.h +++ b/src/backend/taler-merchant-httpd_track-transfer.h @@ -34,6 +34,8 @@ * @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 * @return MHD result code */ int @@ -41,7 +43,8 @@ MH_handler_track_transfer (struct TMH_RequestHandler *rh, struct MHD_Connection *connection, void **connection_cls, const char *upload_data, - size_t *upload_data_size); + size_t *upload_data_size, + const char *instance_id); #endif |