diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-orders.c | 228 |
1 files changed, 93 insertions, 135 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c index b355ba40..82e5e6c3 100644 --- a/src/backend/taler-merchant-httpd_private-post-orders.c +++ b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -1089,16 +1089,32 @@ TMH_private_post_orders (const struct TMH_RequestHandler *rh, struct TMH_HandlerContext *hc) { json_t *order; - struct GNUNET_TIME_Relative refund_delay; + struct GNUNET_TIME_Relative refund_delay = { + .rel_value_us = 0 + }; const char *payment_target = NULL; + json_t *ip = NULL; unsigned int ips_len = 0; struct InventoryProduct *ips = NULL; unsigned int uuids_len = 0; + json_t *uuid; struct GNUNET_Uuid *uuids = NULL; struct TALER_ClaimTokenP claim_token; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_json ("order", &order), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_json ("inventory_products", + &ip)), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_json ("lock_uuids", + &uuid)), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_string ("payment_target", + &payment_target)), + GNUNET_JSON_spec_mark_optional ( + TALER_JSON_spec_relative_time ("refund_delay", + &refund_delay)), GNUNET_JSON_spec_end () }; enum GNUNET_GenericReturnValue ret; @@ -1150,31 +1166,6 @@ TMH_private_post_orders (const struct TMH_RequestHandler *rh, 0, sizeof (claim_token)); } - /* parse the refund_delay (optionally given) */ - if (NULL != json_object_get (hc->request_body, - "refund_delay")) - { - struct GNUNET_JSON_Specification ispec[] = { - TALER_JSON_spec_relative_time ("refund_delay", - &refund_delay), - GNUNET_JSON_spec_end () - }; - - ret = TALER_MHD_parse_json_data (connection, - hc->request_body, - ispec); - if (GNUNET_OK != ret) - { - GNUNET_JSON_parse_free (spec); - return (GNUNET_NO == ret) - ? MHD_YES - : MHD_NO; - } - } - else - { - refund_delay.rel_value_us = 0; - } /* Compute h_post_data (for idempotency check) */ { @@ -1207,142 +1198,109 @@ TMH_private_post_orders (const struct TMH_RequestHandler *rh, GNUNET_free (input); } - /* parse the payment_target (optionally given) */ + /* parse the inventory_products (optionally given) */ + if (NULL != ip) { - const json_t *pt; - - pt = json_object_get (hc->request_body, - "payment_target"); - if (NULL != pt) + if (! json_is_array (ip)) { - if (! json_is_string (pt)) - { - GNUNET_JSON_parse_free (spec); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_PARAMETER_MALFORMED, - "payment_target"); - } - payment_target = json_string_value (pt); + GNUNET_JSON_parse_free (spec); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_PARAMETER_MALFORMED, + "inventory_products"); } - } - - - /* parse the inventory_products (optionally given) */ - { - const json_t *ip; - - ip = json_object_get (hc->request_body, - "inventory_products"); - if (NULL != ip) + GNUNET_array_grow (ips, + ips_len, + json_array_size (ip)); + for (unsigned int i = 0; i<ips_len; i++) { - if (! json_is_array (ip)) + const char *error_name; + unsigned int error_line; + struct GNUNET_JSON_Specification ispec[] = { + GNUNET_JSON_spec_string ("product_id", + &ips[i].product_id), + GNUNET_JSON_spec_uint32 ("quantity", + &ips[i].quantity), + GNUNET_JSON_spec_end () + }; + + ret = GNUNET_JSON_parse (json_array_get (ip, + i), + ispec, + &error_name, + &error_line); + if (GNUNET_OK != ret) { + GNUNET_break_op (0); + GNUNET_array_grow (ips, + ips_len, + 0); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Product parsing failed at #%u: %s:%u\n", + i, + error_name, + error_line); GNUNET_JSON_parse_free (spec); return TALER_MHD_reply_with_error (connection, MHD_HTTP_BAD_REQUEST, TALER_EC_PARAMETER_MALFORMED, "inventory_products"); } - GNUNET_array_grow (ips, - ips_len, - json_array_size (ip)); - for (unsigned int i = 0; i<ips_len; i++) - { - const char *error_name; - unsigned int error_line; - struct GNUNET_JSON_Specification ispec[] = { - GNUNET_JSON_spec_string ("product_id", - &ips[i].product_id), - GNUNET_JSON_spec_uint32 ("quantity", - &ips[i].quantity), - GNUNET_JSON_spec_end () - }; - - ret = GNUNET_JSON_parse (json_array_get (ip, - i), - ispec, - &error_name, - &error_line); - if (GNUNET_OK != ret) - { - GNUNET_break_op (0); - GNUNET_array_grow (ips, - ips_len, - 0); - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Product parsing failed at #%u: %s:%u\n", - i, - error_name, - error_line); - GNUNET_JSON_parse_free (spec); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_PARAMETER_MALFORMED, - "inventory_products"); - } - } } } /* parse the lock_uuids (optionally given) */ + if (NULL != uuid) { - const json_t *uuid; - - uuid = json_object_get (hc->request_body, - "lock_uuids"); - if (NULL != uuid) + if (! json_is_array (uuid)) + { + GNUNET_array_grow (ips, + ips_len, + 0); + GNUNET_JSON_parse_free (spec); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_PARAMETER_MALFORMED, + "lock_uuids"); + } + GNUNET_array_grow (uuids, + uuids_len, + json_array_size (uuid)); + for (unsigned int i = 0; i<uuids_len; i++) { - if (! json_is_array (uuid)) + const char *error_name; + unsigned int error_line; + struct GNUNET_JSON_Specification ispec[] = { + GNUNET_JSON_spec_fixed_auto ("uuid", + &uuids[i]), + GNUNET_JSON_spec_end () + }; + + ret = GNUNET_JSON_parse (json_array_get (uuid, + i), + ispec, + &error_name, + &error_line); + if (GNUNET_OK != ret) { + GNUNET_break_op (0); GNUNET_array_grow (ips, ips_len, 0); + GNUNET_array_grow (uuids, + uuids_len, + 0); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "UUID parsing failed at #%u: %s:%u\n", + i, + error_name, + error_line); GNUNET_JSON_parse_free (spec); return TALER_MHD_reply_with_error (connection, MHD_HTTP_BAD_REQUEST, TALER_EC_PARAMETER_MALFORMED, "lock_uuids"); } - GNUNET_array_grow (uuids, - uuids_len, - json_array_size (uuid)); - for (unsigned int i = 0; i<uuids_len; i++) - { - const char *error_name; - unsigned int error_line; - struct GNUNET_JSON_Specification ispec[] = { - GNUNET_JSON_spec_fixed_auto ("uuid", - &uuids[i]), - GNUNET_JSON_spec_end () - }; - - ret = GNUNET_JSON_parse (json_array_get (uuid, - i), - ispec, - &error_name, - &error_line); - if (GNUNET_OK != ret) - { - GNUNET_break_op (0); - GNUNET_array_grow (ips, - ips_len, - 0); - GNUNET_array_grow (uuids, - uuids_len, - 0); - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "UUID parsing failed at #%u: %s:%u\n", - i, - error_name, - error_line); - GNUNET_JSON_parse_free (spec); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_PARAMETER_MALFORMED, - "lock_uuids"); - } - } } } |