diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-03-04 12:08:18 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-03-04 12:08:18 +0100 |
commit | 1ca25d6db21187dd82d83edbda11a507c16ec9f3 (patch) | |
tree | 113e72558c7ee82c89552c871d903f7f65440d26 /src/backend | |
parent | 39232092eb3038d720d81e6b7891f6bdd7c048f0 (diff) | |
download | merchant-1ca25d6db21187dd82d83edbda11a507c16ec9f3.tar.gz merchant-1ca25d6db21187dd82d83edbda11a507c16ec9f3.tar.bz2 merchant-1ca25d6db21187dd82d83edbda11a507c16ec9f3.zip |
fix #6780
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/taler-merchant-httpd.c | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index 5519f517..e46e4c8e 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -960,6 +960,7 @@ TMH_add_instance (struct TMH_MerchantInstance *mi) return ret; } + /** * Extract the token from authorization header value @a auth. * @@ -990,6 +991,7 @@ extract_token (const char **auth) *auth = tok; } + /** * A client has requested the given url using the given method * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT, @@ -1041,13 +1043,30 @@ url_handler (void *cls, void **con_cls) { static struct TMH_RequestHandler private_handlers[] = { - /* GET /instances: */ + /* GET /instances; MUST be at the beginning of the + array, as this endpoint ONLY applies to the + default instance! See use_default logic below. */ { .url_prefix = "/instances", .method = MHD_HTTP_METHOD_GET, .skip_instance = true, .handler = &TMH_private_get_instances }, + /* POST /instances; MUST be at the beginning of the + array, as this endpoint ONLY applies to the + default instance! See use_default logic below. */ + { + .url_prefix = "/instances", + .method = MHD_HTTP_METHOD_POST, + .skip_instance = true, + .handler = &TMH_private_post_instances, + /* allow instance data of up to 8 MB, that should be plenty; + note that exceeding #GNUNET_MAX_MALLOC_CHECKED (40 MB) + would require further changes to the allocation logic + in the code... */ + .max_upload = 1024 * 1024 * 8 + }, + /* **** End of array entries specific to default instance **** */ /* GET /instances/$ID/: */ { .url_prefix = "/", @@ -1071,18 +1090,6 @@ url_handler (void *cls, in the code... */ .max_upload = 1024 * 1024 * 8 }, - /* POST /instances: */ - { - .url_prefix = "/instances", - .method = MHD_HTTP_METHOD_POST, - .skip_instance = true, - .handler = &TMH_private_post_instances, - /* allow instance data of up to 8 MB, that should be plenty; - note that exceeding #GNUNET_MAX_MALLOC_CHECKED (40 MB) - would require further changes to the allocation logic - in the code... */ - .max_upload = 1024 * 1024 * 8 - }, /* POST /auth: */ { .url_prefix = "/auth", @@ -1404,6 +1411,7 @@ url_handler (void *cls, struct TMH_HandlerContext *hc = *con_cls; struct TMH_RequestHandler *handlers; bool use_private = false; + bool use_default = false; (void) cls; (void) version; @@ -1484,18 +1492,6 @@ url_handler (void *cls, MHD_HTTP_METHOD_HEAD)) method = MHD_HTTP_METHOD_GET; /* MHD will deal with the rest */ - { - const char *private_prefix = "/private/"; - - if (0 == strncmp (url, - private_prefix, - strlen (private_prefix))) - { - use_private = true; - url += strlen (private_prefix) - 1; - } - } - /* 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. */ @@ -1518,6 +1514,11 @@ url_handler (void *cls, slash - istart); hc->instance = TMH_lookup_instance (instance_id); GNUNET_free (instance_id); + if (NULL == hc->instance) + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + TALER_EC_GENERIC_ENDPOINT_UNKNOWN, + url); if (NULL == slash) url = ""; else @@ -1526,6 +1527,7 @@ url_handler (void *cls, else { /* use 'default' */ + use_default = true; hc->instance = TMH_lookup_instance (NULL); if ( (NULL != default_auth) && (NULL != hc->instance) ) @@ -1544,17 +1546,22 @@ url_handler (void *cls, { const char *private_prefix = "/private/"; - if (0 == strncmp (url, - private_prefix, - strlen (private_prefix))) + if ( (0 == strncmp (url, + private_prefix, + strlen (private_prefix))) || + (0 == strcmp (url, + "/private")) ) { - handlers = private_handlers; + if (use_default) + handlers = private_handlers; + else + handlers = &private_handlers[2]; /* skip first two methods: default instance-only! */ url += strlen (private_prefix) - 1; use_private = true; } else { - handlers = (use_private) ? private_handlers : public_handlers; + handlers = public_handlers; } } |