diff options
-rw-r--r-- | src/backend/taler-merchant-httpd.h | 9 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_config.c | 60 | ||||
-rw-r--r-- | src/include/taler_merchant_service.h | 2 | ||||
-rw-r--r-- | src/lib/merchant_api_config.c | 13 |
4 files changed, 74 insertions, 10 deletions
diff --git a/src/backend/taler-merchant-httpd.h b/src/backend/taler-merchant-httpd.h index 4695edd0..1e3aac53 100644 --- a/src/backend/taler-merchant-httpd.h +++ b/src/backend/taler-merchant-httpd.h @@ -101,7 +101,7 @@ struct WireMethod /** - * Information that defines a merchant "instance". Tha4673t way, a single + * Information that defines a merchant "instance". That way, a single * backend can account for several merchants, as used to do in donation * shops */ @@ -358,6 +358,13 @@ extern struct TALER_MerchantPrivateKeyP privkey; extern struct TALER_MerchantPublicKeyP pubkey; /** + * Hashmap pointing at merchant instances by 'id'. An 'id' is + * just a string that identifies a merchant instance. When a frontend + * needs to specify an instance to the backend, it does so by 'id' + */ +extern struct GNUNET_CONTAINER_MultiHashMap *by_id_map; + +/** * Handle to the database backend. */ extern struct TALER_MERCHANTDB_Plugin *db; diff --git a/src/backend/taler-merchant-httpd_config.c b/src/backend/taler-merchant-httpd_config.c index 10a91609..8282cfff 100644 --- a/src/backend/taler-merchant-httpd_config.c +++ b/src/backend/taler-merchant-httpd_config.c @@ -42,11 +42,44 @@ * * When changing this version, you likely want to also update * #MERCHANT_PROTOCOL_CURRENT and #MERCHANT_PROTOCOL_AGE in - * TBD.c! // FIXME: update comment once libtalermerchant looks at version! + * merchant_api_config.c! */ #define MERCHANT_PROTOCOL_VERSION "0:0:0" +static int +add_instance (void *cls, + const struct GNUNET_HashCode *key, + void *value) +{ + json_t *ja = cls; + struct MerchantInstance *mi = value; + char *url; + + GNUNET_asprintf (&url, + "/%s/", + mi->id); + GNUNET_assert (0 == + json_array_append_new ( + ja, + json_pack ( + (NULL != mi->tip_exchange) + ? "{s:s, s:s, s:o, s:s}" + : "{s:s, s:s, s:o}", + "name", + mi->name, + "backend_base_url", + url, + "merchant_pub", + GNUNET_JSON_from_data_auto (&mi->pubkey), + /* optional: */ + "tipping_exchange_baseurl", + mi->tip_exchange))); + GNUNET_free (url); + return GNUNET_OK; +} + + /** * Handle a "/config" request. * @@ -66,16 +99,31 @@ MH_handler_config (struct TMH_RequestHandler *rh, size_t *upload_data_size, struct MerchantInstance *mi) { + static struct MHD_Response *response; + (void) rh; (void) connection_cls; (void) upload_data; (void) upload_data_size; (void) mi; - return TALER_MHD_reply_json_pack (connection, - MHD_HTTP_OK, - "{s:s, s:s}", - "currency", TMH_currency, - "version", MERCHANT_PROTOCOL_VERSION); + if (NULL == response) + { + json_t *ia; + + ia = json_array (); + GNUNET_assert (NULL != ia); + GNUNET_CONTAINER_multihashmap_iterate (by_id_map, + &add_instance, + ia); + response = TALER_MHD_make_json_pack ("{s:s, s:s, s:o}", + "currency", TMH_currency, + "version", MERCHANT_PROTOCOL_VERSION, + "instances", ia); + + } + return MHD_queue_response (connection, + MHD_HTTP_OK, + response); } diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h index c99f18bb..ac7e4279 100644 --- a/src/include/taler_merchant_service.h +++ b/src/include/taler_merchant_service.h @@ -184,7 +184,7 @@ struct TALER_MERCHANT_InstanceInformation /** * URL of this instance. The URL can be relative to the current domain * (i.e. "/PizzaShop/") or include a schema and fully qualified domain name - * (i.e. "https://backend.example.com/"). The latter can be used to redirect + * (i.e. "https://backend.example.com/PS/"). The latter can be used to redirect * clients to a different server in case the deployment location changes. */ const char *instance_baseurl; diff --git a/src/lib/merchant_api_config.c b/src/lib/merchant_api_config.c index 16c20141..1d958a8c 100644 --- a/src/lib/merchant_api_config.c +++ b/src/lib/merchant_api_config.c @@ -109,10 +109,9 @@ parse_instances (const json_t *ia, &ii->instance_baseurl), GNUNET_JSON_spec_string ("name", &ii->name), - GNUNET_JSON_spec_string ("tipping_exchange_baseurl", - &ii->tipping_exchange_baseurl), GNUNET_JSON_spec_end () }; + json_t *teb; if (GNUNET_OK != GNUNET_JSON_parse (value, @@ -121,7 +120,17 @@ parse_instances (const json_t *ia, { GNUNET_break_op (0); ret = GNUNET_SYSERR; + continue; } + teb = json_object_get (value, + "tipping_exchange_baseurl"); + if (! json_is_string (teb)) + { + GNUNET_break_op (0); + ret = GNUNET_SYSERR; + continue; + } + ii->tipping_exchange_baseurl = json_string_value (teb); } return ret; } |