diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2023-11-25 16:05:05 +0900 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2023-11-25 16:05:05 +0900 |
commit | 7782a680228b6e76ae2598cacfc65ff250e8e020 (patch) | |
tree | 8a1e4e462808077b49cee038fed6b634d9176313 /src/lib | |
parent | 6fa958a3cec156bc0eb89ddfae8b150d7400d2be (diff) |
-update to new spec parsers for better error checking
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/merchant_api_get_account.c | 6 | ||||
-rw-r--r-- | src/lib/merchant_api_get_accounts.c | 4 | ||||
-rw-r--r-- | src/lib/merchant_api_get_config.c | 37 | ||||
-rw-r--r-- | src/lib/merchant_api_get_kyc.c | 23 | ||||
-rw-r--r-- | src/lib/merchant_api_get_transfers.c | 6 | ||||
-rw-r--r-- | src/lib/merchant_api_get_webhook.c | 2 | ||||
-rw-r--r-- | src/lib/merchant_api_merchant_get_order.c | 21 | ||||
-rw-r--r-- | src/lib/merchant_api_post_transfers.c | 9 | ||||
-rw-r--r-- | src/lib/merchant_api_reward_authorize.c | 2 | ||||
-rw-r--r-- | src/lib/merchant_api_wallet_get_reward.c | 3 |
10 files changed, 44 insertions, 69 deletions
diff --git a/src/lib/merchant_api_get_account.c b/src/lib/merchant_api_get_account.c index e9a13b33..84595e80 100644 --- a/src/lib/merchant_api_get_account.c +++ b/src/lib/merchant_api_get_account.c @@ -96,11 +96,11 @@ handle_get_account_finished (void *cls, GNUNET_JSON_spec_fixed_auto ("salt", &tgr.details.ok.ad.salt), GNUNET_JSON_spec_mark_optional ( - GNUNET_JSON_spec_string ("credit_facade_url", + TALER_JSON_spec_web_url ("credit_facade_url", &tgr.details.ok.ad.credit_facade_url), NULL), - GNUNET_JSON_spec_string ("payto_uri", - &tgr.details.ok.ad.payto_uri), + TALER_JSON_spec_payto_uri ("payto_uri", + &tgr.details.ok.ad.payto_uri), GNUNET_JSON_spec_fixed_auto ("h_wire", &tgr.details.ok.ad.h_wire), GNUNET_JSON_spec_bool ("active", diff --git a/src/lib/merchant_api_get_accounts.c b/src/lib/merchant_api_get_accounts.c index 9d09463b..95238827 100644 --- a/src/lib/merchant_api_get_accounts.c +++ b/src/lib/merchant_api_get_accounts.c @@ -85,8 +85,8 @@ parse_accounts (const json_t *ia, json_array_foreach (ia, index, value) { struct TALER_MERCHANT_AccountEntry *ie = &tmpl[index]; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_string ("payto_uri", - &ie->payto_uri), + TALER_JSON_spec_payto_uri ("payto_uri", + &ie->payto_uri), GNUNET_JSON_spec_fixed_auto ("h_wire", &ie->h_wire), GNUNET_JSON_spec_end () diff --git a/src/lib/merchant_api_get_config.c b/src/lib/merchant_api_get_config.c index 708b7907..93b7c863 100644 --- a/src/lib/merchant_api_get_config.c +++ b/src/lib/merchant_api_get_config.c @@ -105,11 +105,14 @@ handle_config_finished (void *cls, case MHD_HTTP_OK: { const json_t *jcs; + struct TALER_JSON_ProtocolVersion pv; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_object_const ("currencies", &jcs), GNUNET_JSON_spec_string ("currency", &cr.details.ok.ci.currency), + TALER_JSON_spec_version ("version", + &pv), GNUNET_JSON_spec_string ("version", &cr.details.ok.ci.version), GNUNET_JSON_spec_end () @@ -126,34 +129,18 @@ handle_config_finished (void *cls, } else { - unsigned int age; - unsigned int revision; - unsigned int current; - - if (3 != sscanf (cr.details.ok.ci.version, - "%u:%u:%u", - ¤t, - &revision, - &age)) + cr.details.ok.compat = TALER_MERCHANT_VC_MATCH; + if (MERCHANT_PROTOCOL_CURRENT < pv.current) { - cr.hr.http_status = 0; - cr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + cr.details.ok.compat |= TALER_MERCHANT_VC_NEWER; + if (MERCHANT_PROTOCOL_CURRENT < pv.current - pv.age) + cr.details.ok.compat |= TALER_MERCHANT_VC_INCOMPATIBLE; } - else + if (MERCHANT_PROTOCOL_CURRENT > pv.current) { - cr.details.ok.compat = TALER_MERCHANT_VC_MATCH; - if (MERCHANT_PROTOCOL_CURRENT < current) - { - cr.details.ok.compat |= TALER_MERCHANT_VC_NEWER; - if (MERCHANT_PROTOCOL_CURRENT < current - age) - cr.details.ok.compat |= TALER_MERCHANT_VC_INCOMPATIBLE; - } - if (MERCHANT_PROTOCOL_CURRENT > current) - { - cr.details.ok.compat |= TALER_MERCHANT_VC_OLDER; - if (MERCHANT_PROTOCOL_CURRENT - MERCHANT_PROTOCOL_AGE > current) - cr.details.ok.compat |= TALER_MERCHANT_VC_INCOMPATIBLE; - } + cr.details.ok.compat |= TALER_MERCHANT_VC_OLDER; + if (MERCHANT_PROTOCOL_CURRENT - MERCHANT_PROTOCOL_AGE > pv.current) + cr.details.ok.compat |= TALER_MERCHANT_VC_INCOMPATIBLE; } } { diff --git a/src/lib/merchant_api_get_kyc.c b/src/lib/merchant_api_get_kyc.c index c394590a..b3008ef6 100644 --- a/src/lib/merchant_api_get_kyc.c +++ b/src/lib/merchant_api_get_kyc.c @@ -91,18 +91,17 @@ parse_kyc (struct TALER_MERCHANT_KycGetHandle *kyc, sizeof (pending_kycs)); for (unsigned int i = 0; i<num_pends; i++) { - uint32_t status; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_mark_optional ( - GNUNET_JSON_spec_string ("kyc_url", + TALER_JSON_spec_web_url ("kyc_url", &pending_kycs[i].kyc_url), NULL), - GNUNET_JSON_spec_uint32 ("aml_status", - &status), - GNUNET_JSON_spec_string ("exchange_url", + TALER_JSON_spec_aml_decision ("aml_status", + &pending_kycs[i].aml_status), + TALER_JSON_spec_web_url ("exchange_url", &pending_kycs[i].exchange_url), - GNUNET_JSON_spec_string ("payto_uri", - &pending_kycs[i].payto_uri), + TALER_JSON_spec_payto_uri ("payto_uri", + &pending_kycs[i].payto_uri), GNUNET_JSON_spec_end () }; @@ -115,18 +114,15 @@ parse_kyc (struct TALER_MERCHANT_KycGetHandle *kyc, GNUNET_break (0); return GNUNET_SYSERR; } - pending_kycs[i].aml_status - = (enum TALER_AmlDecisionState) status; } for (unsigned int i = 0; i<num_touts; i++) { uint32_t hs; - uint32_t ec; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_string ("exchange_url", + TALER_JSON_spec_web_url ("exchange_url", &timeout_kycs[i].exchange_url), - GNUNET_JSON_spec_uint32 ("exchange_code", - &ec), + TALER_JSON_spec_ec ("exchange_code", + &timeout_kycs[i].exchange_code), GNUNET_JSON_spec_uint32 ("exchange_http_status", &hs), GNUNET_JSON_spec_end () @@ -142,7 +138,6 @@ parse_kyc (struct TALER_MERCHANT_KycGetHandle *kyc, return GNUNET_SYSERR; } timeout_kycs[i].exchange_http_status = (unsigned int) hs; - timeout_kycs[i].exchange_code = (enum TALER_ErrorCode) ec; } kr->details.kyc_status.pending_kycs = pending_kycs; kr->details.kyc_status.timeout_kycs = timeout_kycs; diff --git a/src/lib/merchant_api_get_transfers.c b/src/lib/merchant_api_get_transfers.c index 473d23a2..66a11edb 100644 --- a/src/lib/merchant_api_get_transfers.c +++ b/src/lib/merchant_api_get_transfers.c @@ -130,9 +130,9 @@ handle_transfers_get_finished (void *cls, &td->credit_amount), GNUNET_JSON_spec_fixed_auto ("wtid", &td->wtid), - GNUNET_JSON_spec_string ("payto_uri", - &td->payto_uri), - GNUNET_JSON_spec_string ("exchange_url", + TALER_JSON_spec_payto_uri ("payto_uri", + &td->payto_uri), + TALER_JSON_spec_web_url ("exchange_url", &td->exchange_url), GNUNET_JSON_spec_uint64 ("transfer_serial_id", &td->credit_serial), diff --git a/src/lib/merchant_api_get_webhook.c b/src/lib/merchant_api_get_webhook.c index 0e9abc6f..551aa915 100644 --- a/src/lib/merchant_api_get_webhook.c +++ b/src/lib/merchant_api_get_webhook.c @@ -101,7 +101,7 @@ handle_get_webhook_finished (void *cls, struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ("event_type", &event_type), - GNUNET_JSON_spec_string ("url", + TALER_JSON_spec_web_url ("url", &url), GNUNET_JSON_spec_string ("http_method", &http_method), diff --git a/src/lib/merchant_api_merchant_get_order.c b/src/lib/merchant_api_merchant_get_order.c index a8a50738..5e3a5ead 100644 --- a/src/lib/merchant_api_merchant_get_order.c +++ b/src/lib/merchant_api_merchant_get_order.c @@ -166,7 +166,6 @@ static void handle_paid (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh, struct TALER_MERCHANT_OrderStatusResponse *osr) { - uint32_t ec32; uint32_t hc32; const json_t *wire_details; const json_t *wire_reports; @@ -180,8 +179,8 @@ handle_paid (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh, &osr->details.ok.details.paid.wired), TALER_JSON_spec_amount_any ("deposit_total", &osr->details.ok.details.paid.deposit_total), - GNUNET_JSON_spec_uint32 ("exchange_code", - &ec32), + TALER_JSON_spec_ec ("exchange_code", + &osr->details.ok.details.paid.exchange_ec), GNUNET_JSON_spec_uint32 ("exchange_http_status", &hc32), TALER_JSON_spec_amount_any ("refund_amount", @@ -211,7 +210,7 @@ handle_paid (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh, return; } osr->details.ok.status = TALER_MERCHANT_OSC_PAID; - osr->details.ok.details.paid.exchange_ec = (enum TALER_ErrorCode) ec32; + osr->details.ok.details.paid.exchange_hc = (unsigned int) hc32; { unsigned int wts_len = json_array_size (wire_details); @@ -227,7 +226,7 @@ handle_paid (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh, const json_t *w = json_array_get (wire_details, i); struct GNUNET_JSON_Specification ispec[] = { - GNUNET_JSON_spec_string ("exchange_url", + TALER_JSON_spec_web_url ("exchange_url", &wt->exchange_url), GNUNET_JSON_spec_fixed_auto ("wtid", &wt->wtid), @@ -258,16 +257,14 @@ handle_paid (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh, { struct TALER_MERCHANT_WireReport *wr = &wrs[i]; const json_t *w = json_array_get (wire_reports, i); - uint32_t c32; - uint32_t eec32; uint32_t ehs32; struct GNUNET_JSON_Specification ispec[] = { - GNUNET_JSON_spec_uint32 ("code", - &c32), + TALER_JSON_spec_ec ("code", + &wr->code), GNUNET_JSON_spec_string ("hint", &wr->hint), - GNUNET_JSON_spec_uint32 ("exchange_code", - &eec32), + TALER_JSON_spec_ec ("exchange_code", + &wr->hr.ec), GNUNET_JSON_spec_uint32 ("exchange_http_status", &ehs32), GNUNET_JSON_spec_fixed_auto ("coin_pub", @@ -287,8 +284,6 @@ handle_paid (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh, osr); return; } - wr->code = (enum TALER_ErrorCode) c32; - wr->hr.ec = (enum TALER_ErrorCode) eec32; wr->hr.http_status = (unsigned int) ehs32; } diff --git a/src/lib/merchant_api_post_transfers.c b/src/lib/merchant_api_post_transfers.c index 4a4ad2ac..615453fa 100644 --- a/src/lib/merchant_api_post_transfers.c +++ b/src/lib/merchant_api_post_transfers.c @@ -123,11 +123,10 @@ handle_post_transfers_finished (void *cls, ptr.hr.ec = TALER_JSON_get_error_code (ptr.hr.reply); ptr.hr.hint = TALER_JSON_get_error_hint (ptr.hr.reply); { - uint32_t eec; uint32_t ehc; struct GNUNET_JSON_Specification ispec[] = { - GNUNET_JSON_spec_uint32 ("exchange_code", - &eec), + TALER_JSON_spec_ec ("exchange_code", + &ptr.details.bad_gateway.exchange_ec), GNUNET_JSON_spec_uint32 ("exchange_http_status", &ehc), GNUNET_JSON_spec_end () @@ -147,11 +146,9 @@ handle_post_transfers_finished (void *cls, { ptr.details.bad_gateway.exchange_http_status = (unsigned int) ehc; - ptr.details.bad_gateway.exchange_ec - = (enum TALER_ErrorCode) eec; GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Exchange returned %u/%u\n", - (unsigned int) eec, + (unsigned int) ptr.details.bad_gateway.exchange_ec, (unsigned int) ehc); } } diff --git a/src/lib/merchant_api_reward_authorize.c b/src/lib/merchant_api_reward_authorize.c index a695e378..c81b2eb2 100644 --- a/src/lib/merchant_api_reward_authorize.c +++ b/src/lib/merchant_api_reward_authorize.c @@ -91,7 +91,7 @@ check_ok (struct TALER_MERCHANT_RewardAuthorizeHandle *tao, .hr.reply = json }; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_string ("reward_status_url", + TALER_JSON_spec_web_url ("reward_status_url", &reward_status_url), GNUNET_JSON_spec_string ("taler_reward_uri", &tar.details.ok.reward_uri), diff --git a/src/lib/merchant_api_wallet_get_reward.c b/src/lib/merchant_api_wallet_get_reward.c index 534eb7f4..1f6f6176 100644 --- a/src/lib/merchant_api_wallet_get_reward.c +++ b/src/lib/merchant_api_wallet_get_reward.c @@ -97,8 +97,9 @@ handle_wallet_reward_get_finished (void *cls, struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_timestamp ("expiration", &wgr.details.ok.expiration), - GNUNET_JSON_spec_string ("exchange_url", + TALER_JSON_spec_web_url ("exchange_url", &wgr.details.ok.exchange_url), + /* Does not have to be a Web URL */ GNUNET_JSON_spec_string ("next_url", &wgr.details.ok.next_url), TALER_JSON_spec_amount_any ("reward_amount", |