diff options
Diffstat (limited to 'src/backend/taler-merchant-httpd.c')
-rw-r--r-- | src/backend/taler-merchant-httpd.c | 138 |
1 files changed, 109 insertions, 29 deletions
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index d8be1edc..9c543958 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -37,14 +37,13 @@ #include "taler-merchant-httpd_private-delete-instances-ID.h" #include "taler-merchant-httpd_private-delete-products-ID.h" #include "taler-merchant-httpd_private-delete-orders-ID.h" +#include "taler-merchant-httpd_private-delete-otp-devices-ID.h" #include "taler-merchant-httpd_private-delete-reserves-ID.h" #include "taler-merchant-httpd_private-delete-templates-ID.h" #include "taler-merchant-httpd_private-delete-transfers-ID.h" #include "taler-merchant-httpd_private-delete-webhooks-ID.h" -#include "taler-merchant-httpd_private-get-webhooks.h" -#include "taler-merchant-httpd_private-get-webhooks-ID.h" -#include "taler-merchant-httpd_private-get-templates.h" -#include "taler-merchant-httpd_private-get-templates-ID.h" +#include "taler-merchant-httpd_private-get-accounts.h" +#include "taler-merchant-httpd_private-get-accounts-ID.h" #include "taler-merchant-httpd_private-get-instances.h" #include "taler-merchant-httpd_private-get-instances-ID.h" #include "taler-merchant-httpd_private-get-instances-ID-kyc.h" @@ -52,19 +51,28 @@ #include "taler-merchant-httpd_private-get-products-ID.h" #include "taler-merchant-httpd_private-get-orders.h" #include "taler-merchant-httpd_private-get-orders-ID.h" +#include "taler-merchant-httpd_private-get-otp-devices.h" +#include "taler-merchant-httpd_private-get-otp-devices-ID.h" #include "taler-merchant-httpd_private-get-reserves.h" #include "taler-merchant-httpd_private-get-reserves-ID.h" #include "taler-merchant-httpd_private-get-rewards-ID.h" #include "taler-merchant-httpd_private-get-rewards.h" +#include "taler-merchant-httpd_private-get-templates.h" +#include "taler-merchant-httpd_private-get-templates-ID.h" #include "taler-merchant-httpd_private-get-transfers.h" -#include "taler-merchant-httpd_private-patch-webhooks-ID.h" -#include "taler-merchant-httpd_private-patch-templates-ID.h" +#include "taler-merchant-httpd_private-get-webhooks.h" +#include "taler-merchant-httpd_private-get-webhooks-ID.h" +#include "taler-merchant-httpd_private-patch-accounts-ID.h" #include "taler-merchant-httpd_private-patch-instances-ID.h" #include "taler-merchant-httpd_private-patch-orders-ID-forget.h" +#include "taler-merchant-httpd_private-patch-otp-devices-ID.h" #include "taler-merchant-httpd_private-patch-products-ID.h" +#include "taler-merchant-httpd_private-patch-templates-ID.h" +#include "taler-merchant-httpd_private-patch-webhooks-ID.h" #include "taler-merchant-httpd_private-post-account.h" #include "taler-merchant-httpd_private-post-instances.h" #include "taler-merchant-httpd_private-post-instances-ID-auth.h" +#include "taler-merchant-httpd_private-post-otp-devices.h" #include "taler-merchant-httpd_private-post-orders.h" #include "taler-merchant-httpd_private-post-orders-ID-refund.h" #include "taler-merchant-httpd_private-post-products.h" @@ -1041,6 +1049,39 @@ url_handler (void *cls, .allow_deleted_instance = true, .handler = &TMH_private_get_transfers }, + /* POST /otp-devices: */ + { + .url_prefix = "/otp-devices", + .method = MHD_HTTP_METHOD_POST, + .handler = &TMH_private_post_otp_devices + }, + /* GET /otp-devices: */ + { + .url_prefix = "/otp-devices", + .method = MHD_HTTP_METHOD_GET, + .handler = &TMH_private_get_otp_devices + }, + /* GET /otp-devices/$ID/: */ + { + .url_prefix = "/otp-devices/", + .method = MHD_HTTP_METHOD_GET, + .have_id_segment = true, + .handler = &TMH_private_get_otp_devices_ID + }, + /* DELETE /otp-devices/$ID/: */ + { + .url_prefix = "/otp-devices/", + .method = MHD_HTTP_METHOD_DELETE, + .have_id_segment = true, + .handler = &TMH_private_delete_otp_devices_ID + }, + /* PATCH /otp-devices/$ID/: */ + { + .url_prefix = "/otp-devices/", + .method = MHD_HTTP_METHOD_PATCH, + .have_id_segment = true, + .handler = &TMH_private_patch_otp_devices_ID + }, /* POST /templates: */ { .url_prefix = "/templates", @@ -1133,17 +1174,39 @@ url_handler (void *cls, in the code... */ .max_upload = 1024 * 1024 * 8 }, - /* POST /account: */ + /* POST /accounts: */ { - .url_prefix = "/account", + .url_prefix = "/accounts", .method = MHD_HTTP_METHOD_POST, .handler = &TMH_private_post_account, /* allow account details of up to 8 kb, that should be plenty */ .max_upload = 1024 * 8 }, - /* DELETE /account/$PAYTO: */ + /* PATCH /accounts/$H_WIRE: */ { - .url_prefix = "/account", + .url_prefix = "/accounts", + .method = MHD_HTTP_METHOD_PATCH, + .handler = &TMH_private_patch_accounts_ID, + .have_id_segment = true, + /* allow account details of up to 8 kb, that should be plenty */ + .max_upload = 1024 * 8 + }, + /* GET /accounts: */ + { + .url_prefix = "/accounts", + .method = MHD_HTTP_METHOD_GET, + .handler = &TMH_private_get_accounts + }, + /* GET /accounts/$H_WIRE: */ + { + .url_prefix = "/accounts", + .method = MHD_HTTP_METHOD_GET, + .have_id_segment = true, + .handler = &TMH_private_get_accounts_ID + }, + /* DELETE /accounts/$H_WIRE: */ + { + .url_prefix = "/accounts", .method = MHD_HTTP_METHOD_DELETE, .handler = &TMH_private_delete_account_ID, .have_id_segment = true @@ -1779,6 +1842,31 @@ url_handler (void *cls, /** + * Callback invoked with information about a bank account. + * + * @param cls closure with a `struct TMH_MerchantInstance *` + * @param ad details about the account + */ +static void +add_account_cb (void *cls, + const struct TALER_MERCHANTDB_AccountDetails *acc) +{ + struct TMH_MerchantInstance *mi = cls; + struct TMH_WireMethod *wm; + + wm = GNUNET_new (struct TMH_WireMethod); + wm->h_wire = acc->h_wire; + wm->payto_uri = GNUNET_strdup (acc->payto_uri); + wm->wire_salt = acc->salt; + wm->wire_method = TALER_payto_get_method (acc->payto_uri); + wm->active = acc->active; + GNUNET_CONTAINER_DLL_insert (mi->wm_head, + mi->wm_tail, + wm); +} + + +/** * Function called during startup to add all known instances to our * hash map in memory for faster lookups when we receive requests. * @@ -1787,20 +1875,17 @@ url_handler (void *cls, * @param merchant_priv private key of the instance, NULL if not available * @param is detailed configuration settings for the instance * @param ias authentication settings for the instance - * @param accounts_length length of the @a accounts array - * @param accounts list of accounts of the merchant */ static void add_instance_cb (void *cls, const struct TALER_MerchantPublicKeyP *merchant_pub, const struct TALER_MerchantPrivateKeyP *merchant_priv, const struct TALER_MERCHANTDB_InstanceSettings *is, - const struct TALER_MERCHANTDB_InstanceAuthSettings *ias, - unsigned int accounts_length, - const struct TALER_MERCHANTDB_AccountDetails accounts[]) + const struct TALER_MERCHANTDB_InstanceAuthSettings *ias) { struct TMH_MerchantInstance *mi; - + enum GNUNET_DB_QueryStatus qs; + (void) cls; mi = TMH_lookup_instance (is->id); if (NULL != mi) @@ -1829,20 +1914,15 @@ add_instance_cb (void *cls, else mi->deleted = true; mi->merchant_pub = *merchant_pub; - for (unsigned int i = 0; i<accounts_length; i++) + qs = TMH_db->select_accounts (TMH_db->cls, + mi->settings.id, + &add_account_cb, + mi); + if (0 > qs) { - const struct TALER_MERCHANTDB_AccountDetails *acc = &accounts[i]; - struct TMH_WireMethod *wm; - - wm = GNUNET_new (struct TMH_WireMethod); - wm->h_wire = acc->h_wire; - wm->payto_uri = GNUNET_strdup (acc->payto_uri); - wm->wire_salt = acc->salt; - wm->wire_method = TALER_payto_get_method (acc->payto_uri); - wm->active = acc->active; - GNUNET_CONTAINER_DLL_insert (mi->wm_head, - mi->wm_tail, - wm); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Error loading accounts of `%s' from database\n", + mi->settings.id); } GNUNET_assert (GNUNET_OK == TMH_add_instance (mi)); |