diff options
author | Christian Grothoff <christian@grothoff.org> | 2023-05-04 17:13:54 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2023-05-04 17:13:54 +0200 |
commit | 0bf27e7e97ed2b8b29ca610f8fb15d3194c84f07 (patch) | |
tree | 19574cd8c8baa6f33288706e35df4c01f20fcd84 | |
parent | 9316c050740bf275468ca5429d402718d7e69a07 (diff) | |
download | merchant-0bf27e7e97ed2b8b29ca610f8fb15d3194c84f07.tar.gz merchant-0bf27e7e97ed2b8b29ca610f8fb15d3194c84f07.tar.bz2 merchant-0bf27e7e97ed2b8b29ca610f8fb15d3194c84f07.zip |
-minor code cleanup
5 files changed, 198 insertions, 387 deletions
diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c b/src/backend/taler-merchant-httpd_get-orders-ID.c index 498ad1c4..9c60f7a9 100644 --- a/src/backend/taler-merchant-httpd_get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_get-orders-ID.c @@ -146,6 +146,16 @@ struct GetOrderData enum GNUNET_GenericReturnValue suspended; /** + * Set to true if the client passed 'h_contract'. + */ + bool h_contract_provided; + + /** + * Set to true if the client passed a 'claim' token. + */ + bool claim_token_provided; + + /** * Set to true if we are dealing with a claimed order * (and thus @e h_contract_terms is set, otherwise certain * DB queries will not work). @@ -756,8 +766,6 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, enum GNUNET_DB_QueryStatus qs; bool contract_match = false; bool token_match = false; - bool h_contract_provided = false; - bool claim_token_provided = false; bool contract_available = false; const char *merchant_base_url; @@ -772,53 +780,15 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, god->order_id = order_id; god->generate_html = TMH_MHD_test_html_desired (connection); - /* first-time initialization / sanity checks */ - { - const char *cts; - - cts = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "h_contract"); - if ( (NULL != cts) && - (GNUNET_OK != - GNUNET_CRYPTO_hash_from_string (cts, - &god->h_contract_terms.hash)) ) - { - /* cts has wrong encoding */ - GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "h_contract"); - } - if (NULL != cts) - h_contract_provided = true; - } - - { - const char *ct; - - ct = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "token"); - if ( (NULL != ct) && - (GNUNET_OK != - GNUNET_STRINGS_string_to_data (ct, - strlen (ct), - &god->claim_token, - sizeof (god->claim_token))) ) - { - /* ct has wrong encoding */ - GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "token"); - } - if (NULL != ct) - claim_token_provided = true; - } + TALER_MHD_parse_request_arg_auto (connection, + "h_contract", + &god->h_contract_terms, + god->h_contract_provided); + TALER_MHD_parse_request_arg_auto (connection, + "token", + &god->claim_token, + god->claim_token_provided); god->session_id = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "session_id"); @@ -868,89 +838,62 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, } } - - /* process timeout_ms argument */ + TALER_MHD_parse_request_timeout (connection, + &god->sc.long_poll_timeout); + /* If HTML is requested, we never actually long poll. Makes no sense */ + if ( (! god->generate_html) && + (GNUNET_TIME_absolute_is_future (god->sc.long_poll_timeout)) ) { - const char *long_poll_timeout_ms; - - long_poll_timeout_ms = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "timeout_ms"); - if (NULL != long_poll_timeout_ms) + if (god->sc.awaiting_refund || + god->sc.awaiting_refund_obtained) { - unsigned int timeout_ms; - char dummy; - - if (1 != sscanf (long_poll_timeout_ms, - "%u%c", - &timeout_ms, - &dummy)) - { - GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "timeout_ms (must be non-negative number)"); - } - /* If HTML is requested, we never long poll. Makes no sense */ - if (! god->generate_html) - { - struct GNUNET_TIME_Relative timeout; - - timeout = GNUNET_TIME_relative_multiply ( - GNUNET_TIME_UNIT_MILLISECONDS, - timeout_ms); - god->sc.long_poll_timeout - = GNUNET_TIME_relative_to_absolute (timeout); - if (! GNUNET_TIME_relative_is_zero (timeout)) - { - if (god->sc.awaiting_refund || - god->sc.awaiting_refund_obtained) - { - struct TMH_OrderPayEventP refund_eh = { - .header.size = htons (sizeof (refund_eh)), - .header.type = htons (god->sc.awaiting_refund_obtained - ? TALER_DBEVENT_MERCHANT_REFUND_OBTAINED - : TALER_DBEVENT_MERCHANT_ORDER_REFUND), - .merchant_pub = hc->instance->merchant_pub - }; - - GNUNET_CRYPTO_hash (god->order_id, - strlen (god->order_id), - &refund_eh.h_order_id); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Subscribing %p to refunds on %s\n", - god, - god->order_id); - god->refund_eh = TMH_db->event_listen (TMH_db->cls, - &refund_eh.header, - timeout, - &resume_by_event, - god); - } - { - struct TMH_OrderPayEventP pay_eh = { - .header.size = htons (sizeof (pay_eh)), - .header.type = htons (TALER_DBEVENT_MERCHANT_ORDER_PAID), - .merchant_pub = hc->instance->merchant_pub - }; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Subscribing to payments on %s\n", - god->order_id); - GNUNET_CRYPTO_hash (god->order_id, - strlen (god->order_id), - &pay_eh.h_order_id); - god->pay_eh = TMH_db->event_listen (TMH_db->cls, - &pay_eh.header, - timeout, - &resume_by_event, - god); - } - } /* end of timeout non-zero */ - } /* end of HTML generation NOT requested */ - } /* end of timeout_ms argument provided */ - } /* end of timeout_ms argument handling */ + struct TMH_OrderPayEventP refund_eh = { + .header.size = htons (sizeof (refund_eh)), + .header.type = htons (god->sc.awaiting_refund_obtained + ? TALER_DBEVENT_MERCHANT_REFUND_OBTAINED + : TALER_DBEVENT_MERCHANT_ORDER_REFUND), + .merchant_pub = hc->instance->merchant_pub + }; + + GNUNET_CRYPTO_hash (god->order_id, + strlen (god->order_id), + &refund_eh.h_order_id); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Subscribing %p to refunds on %s\n", + god, + god->order_id); + god->refund_eh + = TMH_db->event_listen ( + TMH_db->cls, + &refund_eh.header, + GNUNET_TIME_absolute_get_remaining ( + god->sc.long_poll_timeout), + &resume_by_event, + god); + } + { + struct TMH_OrderPayEventP pay_eh = { + .header.size = htons (sizeof (pay_eh)), + .header.type = htons (TALER_DBEVENT_MERCHANT_ORDER_PAID), + .merchant_pub = hc->instance->merchant_pub + }; + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Subscribing to payments on %s\n", + god->order_id); + GNUNET_CRYPTO_hash (god->order_id, + strlen (god->order_id), + &pay_eh.h_order_id); + god->pay_eh + = TMH_db->event_listen ( + TMH_db->cls, + &pay_eh.header, + GNUNET_TIME_absolute_get_remaining ( + god->sc.long_poll_timeout), + &resume_by_event, + god); + } + } /* end of do long-polling / no HTML */ } /* end of first-time initialization / sanity checks */ @@ -1119,7 +1062,7 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, contract_match, god->claimed); - if (claim_token_provided && ! token_match) + if (god->claim_token_provided && ! token_match) { /* Authentication provided but wrong. */ GNUNET_break_op (0); @@ -1129,7 +1072,7 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, "authentication with claim token provided but wrong"); } - if (h_contract_provided && ! contract_match) + if (god->h_contract_provided && ! contract_match) { /* Authentication provided but wrong. */ GNUNET_break_op (0); @@ -1338,7 +1281,8 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, struct GNUNET_TIME_Relative remaining; remaining = GNUNET_TIME_absolute_get_remaining (god->sc.long_poll_timeout); - if (! GNUNET_TIME_relative_is_zero (remaining)) + if ( (! GNUNET_TIME_relative_is_zero (remaining)) && + (! god->generate_html) ) { /* yes, indeed suspend */ if (god->sc.awaiting_refund) diff --git a/src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c b/src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c index 3d807569..5e229b48 100644 --- a/src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c +++ b/src/backend/taler-merchant-httpd_private-get-instances-ID-kyc.c @@ -192,7 +192,7 @@ struct KycContext /** * How long are we willing to wait for the exchange(s)? */ - struct GNUNET_TIME_Relative timeout; + struct GNUNET_TIME_Absolute timeout; /** * HTTP status code to use for the reply, i.e 200 for "OK". @@ -693,7 +693,7 @@ kyc_with_exchange (void *cls, ekr->exchange_kyc_serial, &h_payto, ekr->kc->mi->settings.ut, - kc->timeout, + GNUNET_TIME_absolute_get_remaining (kc->timeout), &exchange_check_cb, ekr); } @@ -786,39 +786,13 @@ get_instances_ID_kyc (struct TMH_MerchantInstance *mi, kc->timeout_kycs = json_array (); GNUNET_assert (NULL != kc->timeout_kycs); - /* process 'timeout_ms' argument */ - { - const char *long_poll_timeout_s; - - long_poll_timeout_s - = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "timeout_ms"); - if (NULL != long_poll_timeout_s) - { - unsigned int timeout_ms; - char dummy; - - if (1 != sscanf (long_poll_timeout_s, - "%u%c", - &timeout_ms, - &dummy)) - { - GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "timeout_ms must be non-negative number"); - } - kc->timeout = GNUNET_TIME_relative_multiply ( - GNUNET_TIME_UNIT_MILLISECONDS, - timeout_ms); - kc->timeout_task - = GNUNET_SCHEDULER_add_delayed (kc->timeout, - &handle_kyc_timeout, - kc); - } - } /* end timeout processing */ + TALER_MHD_parse_request_timeout (connection, + &kc->timeout); + if (! GNUNET_TIME_absolute_is_past (kc->timeout)) + kc->timeout_task + = GNUNET_SCHEDULER_add_at (kc->timeout, + &handle_kyc_timeout, + kc); /* process 'exchange_url' argument */ kc->exchange_url = MHD_lookup_connection_value (connection, @@ -840,32 +814,10 @@ get_instances_ID_kyc (struct TMH_MerchantInstance *mi, "exchange_url must be a valid HTTP(s) URL"); } - /* process 'h_wire' argument */ - { - const char *h_wire_s; - - h_wire_s - = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "h_wire"); - if (NULL != h_wire_s) - { - if (GNUNET_OK != - GNUNET_STRINGS_string_to_data (h_wire_s, - strlen (h_wire_s), - &kc->h_wire, - sizeof (kc->h_wire))) - { - GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "h_wire must be Crockford base32 encoded hash"); - } - kc->have_h_wire = true; - } - } /* end of h_wire processing */ - + TALER_MHD_parse_request_arg_auto (connection, + "h_wire", + &kc->h_wire, + kc->have_h_wire); /* Check our database */ { enum GNUNET_DB_QueryStatus qs; diff --git a/src/backend/taler-merchant-httpd_private-get-orders-ID.c b/src/backend/taler-merchant-httpd_private-get-orders-ID.c index feaa6164..f6489e65 100644 --- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c @@ -905,83 +905,53 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, gorc->transfer_status_requested = true; } - /* process 'timeout_ms' argument */ + TALER_MHD_parse_request_timeout (connection, + &gorc->sc.long_poll_timeout); + if (GNUNET_TIME_absolute_is_future (gorc->sc.long_poll_timeout)) { - const char *long_poll_timeout_s; - - long_poll_timeout_s = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "timeout_ms"); - if (NULL != long_poll_timeout_s) - { - unsigned int timeout_ms; - char dummy; - struct GNUNET_TIME_Relative timeout; - - if (1 != sscanf (long_poll_timeout_s, - "%u%c", - &timeout_ms, - &dummy)) - { - GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "timeout_ms must be non-negative number"); - } - timeout = GNUNET_TIME_relative_multiply ( - GNUNET_TIME_UNIT_MILLISECONDS, - timeout_ms); - gorc->sc.long_poll_timeout - = GNUNET_TIME_relative_to_absolute (timeout); - if (! GNUNET_TIME_relative_is_zero (timeout)) - { - struct TMH_OrderPayEventP pay_eh = { - .header.size = htons (sizeof (pay_eh)), - .header.type = htons (TALER_DBEVENT_MERCHANT_ORDER_PAID), - .merchant_pub = hc->instance->merchant_pub - }; - - GNUNET_CRYPTO_hash (hc->infix, - strlen (hc->infix), - &pay_eh.h_order_id); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Subscribing to payment triggers for %p\n", - gorc); - gorc->eh = TMH_db->event_listen (TMH_db->cls, - &pay_eh.header, - timeout, - &resume_by_event, - gorc); - if ( (NULL != gorc->session_id) && - (NULL != gorc->fulfillment_url) ) - { - struct TMH_SessionEventP session_eh = { - .header.size = htons (sizeof (session_eh)), - .header.type = htons (TALER_DBEVENT_MERCHANT_SESSION_CAPTURED), - .merchant_pub = hc->instance->merchant_pub - }; - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Subscribing to session triggers for %p\n", - gorc); - GNUNET_CRYPTO_hash (gorc->session_id, - strlen (gorc->session_id), - &session_eh.h_session_id); - GNUNET_CRYPTO_hash (gorc->fulfillment_url, - strlen (gorc->fulfillment_url), - &session_eh.h_fulfillment_url); - gorc->session_eh = TMH_db->event_listen (TMH_db->cls, - &session_eh.header, - timeout, - &resume_by_event, - gorc); - } - } - } - else + struct TMH_OrderPayEventP pay_eh = { + .header.size = htons (sizeof (pay_eh)), + .header.type = htons (TALER_DBEVENT_MERCHANT_ORDER_PAID), + .merchant_pub = hc->instance->merchant_pub + }; + + GNUNET_CRYPTO_hash (hc->infix, + strlen (hc->infix), + &pay_eh.h_order_id); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Subscribing to payment triggers for %p\n", + gorc); + gorc->eh = TMH_db->event_listen ( + TMH_db->cls, + &pay_eh.header, + GNUNET_TIME_absolute_get_remaining (gorc->sc.long_poll_timeout), + &resume_by_event, + gorc); + if ( (NULL != gorc->session_id) && + (NULL != gorc->fulfillment_url) ) { - gorc->sc.long_poll_timeout = GNUNET_TIME_UNIT_ZERO_ABS; + struct TMH_SessionEventP session_eh = { + .header.size = htons (sizeof (session_eh)), + .header.type = htons (TALER_DBEVENT_MERCHANT_SESSION_CAPTURED), + .merchant_pub = hc->instance->merchant_pub + }; + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Subscribing to session triggers for %p\n", + gorc); + GNUNET_CRYPTO_hash (gorc->session_id, + strlen (gorc->session_id), + &session_eh.h_session_id); + GNUNET_CRYPTO_hash (gorc->fulfillment_url, + strlen (gorc->fulfillment_url), + &session_eh.h_fulfillment_url); + gorc->session_eh + = TMH_db->event_listen ( + TMH_db->cls, + &session_eh.header, + GNUNET_TIME_absolute_get_remaining (gorc->sc.long_poll_timeout), + &resume_by_event, + gorc); } } } /* end first-time per-request initialization */ diff --git a/src/backend/taler-merchant-httpd_private-get-orders.c b/src/backend/taler-merchant-httpd_private-get-orders.c index d4f74184..4998c029 100644 --- a/src/backend/taler-merchant-httpd_private-get-orders.c +++ b/src/backend/taler-merchant-httpd_private-get-orders.c @@ -602,7 +602,6 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh, { struct TMH_PendingOrder *po = hc->ctx; enum GNUNET_DB_QueryStatus qs; - struct TALER_MERCHANTDB_OrderFilter of; if (NULL != po) { @@ -622,11 +621,19 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh, GNUNET_JSON_pack_array_incref ("orders", po->pa)); } + po = GNUNET_new (struct TMH_PendingOrder); + hc->ctx = po; + hc->cc = &cleanup; + po->con = connection; + po->pa = json_array (); + GNUNET_assert (NULL != po->pa); + po->instance_id = hc->instance->settings.id; + po->mi = hc->instance; if (! (TALER_arg_to_yna (connection, "paid", TALER_EXCHANGE_YNA_ALL, - &of.paid)) ) + &po->of.paid)) ) return TALER_MHD_reply_with_error (connection, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MALFORMED, @@ -634,7 +641,7 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh, if (! (TALER_arg_to_yna (connection, "refunded", TALER_EXCHANGE_YNA_ALL, - &of.refunded)) ) + &po->of.refunded)) ) return TALER_MHD_reply_with_error (connection, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MALFORMED, @@ -642,7 +649,7 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh, if (! (TALER_arg_to_yna (connection, "wired", TALER_EXCHANGE_YNA_ALL, - &of.wired)) ) + &po->of.wired)) ) return TALER_MHD_reply_with_error (connection, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MALFORMED, @@ -655,7 +662,7 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh, "delta"); if (NULL == delta_str) { - of.delta = -20; + po->of.delta = -20; } else { @@ -674,9 +681,9 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh, TALER_EC_GENERIC_PARAMETER_MALFORMED, "delta"); } - of.delta = (int64_t) ll; - if ( (-MAX_DELTA > of.delta) || - (of.delta > MAX_DELTA) ) + po->of.delta = (int64_t) ll; + if ( (-MAX_DELTA > po->of.delta) || + (po->of.delta > MAX_DELTA) ) { GNUNET_break_op (0); return TALER_MHD_reply_with_error (connection, @@ -694,10 +701,10 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh, "date_s"); if (NULL == date_s_str) { - if (of.delta > 0) - of.date = GNUNET_TIME_UNIT_ZERO_TS; + if (po->of.delta > 0) + po->of.date = GNUNET_TIME_UNIT_ZERO_TS; else - of.date = GNUNET_TIME_UNIT_FOREVER_TS; + po->of.date = GNUNET_TIME_UNIT_FOREVER_TS; } else { @@ -717,9 +724,9 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh, "date_ms"); } - of.date = GNUNET_TIME_absolute_to_timestamp ( + po->of.date = GNUNET_TIME_absolute_to_timestamp ( GNUNET_TIME_absolute_from_s (ll)); - if (GNUNET_TIME_absolute_is_never (of.date.abs_time)) + if (GNUNET_TIME_absolute_is_never (po->of.date.abs_time)) { GNUNET_break_op (0); return TALER_MHD_reply_with_error (connection, @@ -737,10 +744,10 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh, "start"); if (NULL == start_row_str) { - if (of.delta > 0) - of.start_row = 0; + if (po->of.delta > 0) + po->of.start_row = 0; else - of.start_row = INT64_MAX; + po->of.start_row = INT64_MAX; } else { @@ -756,8 +763,8 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MALFORMED, "start"); - of.start_row = (uint64_t) ull; - if (INT64_MAX < of.start_row) + po->of.start_row = (uint64_t) ull; + if (INT64_MAX < po->of.start_row) { GNUNET_break_op (0); return TALER_MHD_reply_with_error (connection, @@ -767,61 +774,28 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh, } } } + TALER_MHD_parse_request_timeout (connection, + &po->long_poll_timeout); + if (GNUNET_TIME_absolute_is_never (po->long_poll_timeout)) { - const char *timeout_ms_str; - - timeout_ms_str = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "timeout_ms"); - if (NULL == timeout_ms_str) - { - of.timeout = GNUNET_TIME_UNIT_ZERO; - } - else - { - char dummy; - unsigned long long ull; - - if (1 != - sscanf (timeout_ms_str, - "%llu%c", - &ull, - &dummy)) - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "timeout_ms"); - of.timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, - ull); - if (GNUNET_TIME_relative_is_forever (of.timeout)) - { - GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "timeout_ms"); - } - } - - if ( (0 >= of.delta) && - (! GNUNET_TIME_relative_is_zero (of.timeout)) ) - { - GNUNET_break_op (0); - of.timeout = GNUNET_TIME_UNIT_ZERO; - } + GNUNET_break_op (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + "timeout_ms"); + } + po->of.timeout = GNUNET_TIME_absolute_get_remaining (po->long_poll_timeout); + if ( (0 >= po->of.delta) && + (GNUNET_TIME_absolute_is_future (po->long_poll_timeout)) ) + { + GNUNET_break_op (0); + po->of.timeout = GNUNET_TIME_UNIT_ZERO; + po->long_poll_timeout = GNUNET_TIME_UNIT_ZERO_ABS; } - po = GNUNET_new (struct TMH_PendingOrder); - hc->ctx = po; - hc->cc = &cleanup; - po->con = connection; - po->pa = json_array (); - GNUNET_assert (NULL != po->pa); - po->instance_id = hc->instance->settings.id; - po->mi = hc->instance; qs = TMH_db->lookup_orders (TMH_db->cls, po->instance_id, - &of, + &po->of, &add_order, po); if (0 > qs) @@ -838,7 +812,7 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh, NULL); } if ( (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) && - (! GNUNET_TIME_relative_is_zero (of.timeout)) ) + (GNUNET_TIME_absolute_is_future (po->long_poll_timeout)) ) { struct TMH_MerchantInstance *mi = hc->instance; @@ -849,8 +823,6 @@ TMH_private_get_orders (const struct TMH_RequestHandler *rh, po->hn = GNUNET_CONTAINER_heap_insert (order_timeout_heap, po, po->long_poll_timeout.abs_value_us); - po->long_poll_timeout = GNUNET_TIME_relative_to_absolute (of.timeout); - po->of = of; GNUNET_CONTAINER_DLL_insert (mi->po_head, mi->po_tail, po); diff --git a/src/backend/taler-merchant-httpd_private-get-tips-ID.c b/src/backend/taler-merchant-httpd_private-get-tips-ID.c index 8be57417..f6a58ef7 100644 --- a/src/backend/taler-merchant-httpd_private-get-tips-ID.c +++ b/src/backend/taler-merchant-httpd_private-get-tips-ID.c @@ -263,55 +263,28 @@ TMH_private_get_tips_ID (const struct TMH_RequestHandler *rh, } } } - /* process 'timeout_ms' argument */ + TALER_MHD_parse_request_timeout (connection, + &tc->timeout); + if (! GNUNET_TIME_absolute_is_future (tc->timeout)) { - const char *long_poll_timeout_s; - - long_poll_timeout_s = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "timeout_ms"); - if (NULL != long_poll_timeout_s) - { - unsigned int timeout_ms; - char dummy; - struct GNUNET_TIME_Relative timeout; - - if (1 != sscanf (long_poll_timeout_s, - "%u%c", - &timeout_ms, - &dummy)) - { - GNUNET_break_op (0); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "timeout_ms must be non-negative number"); - } - timeout = GNUNET_TIME_relative_multiply ( - GNUNET_TIME_UNIT_MILLISECONDS, - timeout_ms); - tc->timeout = GNUNET_TIME_relative_to_absolute (timeout); - if (! GNUNET_TIME_relative_is_zero (timeout)) - { - struct TMH_TipPickupEventP tip_eh = { - .header.size = htons (sizeof (tip_eh)), - .header.type = htons (TALER_DBEVENT_MERCHANT_TIP_PICKUP), - .tip_id = tc->tip_id - }; - - GNUNET_CRYPTO_hash (hc->instance->settings.id, - strlen (hc->instance->settings.id), - &tip_eh.h_instance); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Subscribing to payment triggers for %p\n", - tc); - tc->eh = TMH_db->event_listen (TMH_db->cls, - &tip_eh.header, - timeout, - &resume_by_event, - tc); - } - } + struct TMH_TipPickupEventP tip_eh = { + .header.size = htons (sizeof (tip_eh)), + .header.type = htons (TALER_DBEVENT_MERCHANT_TIP_PICKUP), + .tip_id = tc->tip_id + }; + + GNUNET_CRYPTO_hash (hc->instance->settings.id, + strlen (hc->instance->settings.id), + &tip_eh.h_instance); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Subscribing to payment triggers for %p\n", + tc); + tc->eh = TMH_db->event_listen ( + TMH_db->cls, + &tip_eh.header, + GNUNET_TIME_absolute_get_remaining (tc->timeout), + &resume_by_event, + tc); } } |