diff options
author | Christian Grothoff <christian@grothoff.org> | 2023-07-05 13:16:48 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2023-07-05 13:16:48 +0200 |
commit | c4b27ca9b9a5ef4291257e4a8b8f4bac56720b89 (patch) | |
tree | 39e195bbb8b7eba8b34ff730b64264e1f35538c1 /src/backend/taler-merchant-httpd_helper.c | |
parent | 4e3a4981d2aecf80c51759ceb37b7277d924e810 (diff) |
-more merchant clean upv0.9.3-dev.2
Diffstat (limited to 'src/backend/taler-merchant-httpd_helper.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_helper.c | 206 |
1 files changed, 101 insertions, 105 deletions
diff --git a/src/backend/taler-merchant-httpd_helper.c b/src/backend/taler-merchant-httpd_helper.c index 407323e2..172cb0a1 100644 --- a/src/backend/taler-merchant-httpd_helper.c +++ b/src/backend/taler-merchant-httpd_helper.c @@ -732,111 +732,6 @@ TMH_trigger_webhook (const char *instance, } -/** - * Closure for #add_matching_account(). - */ -struct ExchangeMatchContext -{ - /** - * Wire method to match, NULL for all. - */ - const char *wire_method; - - /** - * Array of accounts to return. - */ - json_t *accounts; -}; - - -/** - * If the given account is feasible, add it to the array - * of accounts we return. - * - * @param cls a `struct PostReserveContext` - * @param payto_uri URI of the account - * @param conversion_url URL of a conversion service - * @param debit_restrictions restrictions for debits from account - * @param credit_restrictions restrictions for credits to account - * @param master_sig signature affirming the account - */ -static void -add_matching_account (void *cls, - const char *payto_uri, - const char *conversion_url, - const json_t *debit_restrictions, - const json_t *credit_restrictions, - const struct TALER_MasterSignatureP *master_sig) -{ - struct ExchangeMatchContext *rc = cls; - char *method; - - method = TALER_payto_get_method (payto_uri); - if ( (NULL == rc->wire_method) || - (0 == strcmp (method, - rc->wire_method)) ) - { - json_t *acc; - - acc = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_string ("payto_uri", - payto_uri), - GNUNET_JSON_pack_data_auto ("master_sig", - master_sig), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ("conversion_url", - conversion_url)), - GNUNET_JSON_pack_array_incref ("credit_restrictions", - (json_t *) credit_restrictions), - GNUNET_JSON_pack_array_incref ("debit_restrictions", - (json_t *) debit_restrictions) - ); - GNUNET_assert (0 == - json_array_append_new (rc->accounts, - acc)); - } - GNUNET_free (method); -} - - -/** - * Return JSON array with all of the exchange accounts - * that support the given @a wire_method. - * - * FIXME: bad API, doesn't inherently ensure that we - * actually did request /wire before! - * => move into t-m-h_exchanges.c and integrate with /wire - * logic there! - * - * @param master_pub master public key to match exchange by - * @param wire_method NULL for any - * @return JSON array with information about all matching accounts - */ -json_t * -TMH_exchange_accounts_by_method ( - const struct TALER_MasterPublicKeyP *master_pub, - const char *wire_method) -{ - struct ExchangeMatchContext emc = { - .wire_method = wire_method, - .accounts = json_array () - }; - enum GNUNET_DB_QueryStatus qs; - - GNUNET_assert (NULL != emc.accounts); - qs = TMH_db->select_accounts_by_exchange (TMH_db->cls, - master_pub, - &add_matching_account, - &emc); - if (qs < 0) - { - json_decref (emc.accounts); - return NULL; - } - return emc.accounts; -} - - enum GNUNET_GenericReturnValue TMH_base_url_by_connection (struct MHD_Connection *connection, const char *instance, @@ -948,3 +843,104 @@ TMH_taler_uri_by_connection (struct MHD_Connection *connection, } return GNUNET_OK; } + + +/** + * Closure for #add_matching_account(). + */ +struct ExchangeMatchContext +{ + /** + * Wire method to match, NULL for all. + */ + const char *wire_method; + + /** + * Array of accounts to return. + */ + json_t *accounts; +}; + + +/** + * If the given account is feasible, add it to the array + * of accounts we return. + * + * @param cls a `struct PostReserveContext` + * @param payto_uri URI of the account + * @param conversion_url URL of a conversion service + * @param debit_restrictions restrictions for debits from account + * @param credit_restrictions restrictions for credits to account + * @param master_sig signature affirming the account + */ +static void +add_matching_account ( + void *cls, + const char *payto_uri, + const char *conversion_url, + const json_t *debit_restrictions, + const json_t *credit_restrictions, + const struct TALER_MasterSignatureP *master_sig) +{ + struct ExchangeMatchContext *rc = cls; + char *method; + + method = TALER_payto_get_method (payto_uri); + if ( (NULL == rc->wire_method) || + (0 == strcmp (method, + rc->wire_method)) ) + { + json_t *acc; + + acc = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("payto_uri", + payto_uri), + GNUNET_JSON_pack_data_auto ("master_sig", + master_sig), + GNUNET_JSON_pack_allow_null ( + GNUNET_JSON_pack_string ("conversion_url", + conversion_url)), + GNUNET_JSON_pack_array_incref ("credit_restrictions", + (json_t *) credit_restrictions), + GNUNET_JSON_pack_array_incref ("debit_restrictions", + (json_t *) debit_restrictions) + ); + GNUNET_assert (0 == + json_array_append_new (rc->accounts, + acc)); + } + GNUNET_free (method); +} + + +/** + * Return JSON array with all of the exchange accounts + * that support the given @a wire_method. + * + * @param master_pub master public key to match exchange by + * @param wire_method NULL for any + * @return JSON array with information about all matching accounts + */ +json_t * +TMH_exchange_accounts_by_method ( + const struct TALER_MasterPublicKeyP *master_pub, + const char *wire_method) +{ + struct ExchangeMatchContext emc = { + .wire_method = wire_method, + .accounts = json_array () + }; + enum GNUNET_DB_QueryStatus qs; + + GNUNET_assert (NULL != emc.accounts); + qs = TMH_db->select_accounts_by_exchange (TMH_db->cls, + master_pub, + &add_matching_account, + &emc); + if (qs < 0) + { + json_decref (emc.accounts); + return NULL; + } + return emc.accounts; +} |