diff options
Diffstat (limited to 'src/backend/taler-merchant-httpd_post-using-templates.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_post-using-templates.c | 209 |
1 files changed, 109 insertions, 100 deletions
diff --git a/src/backend/taler-merchant-httpd_post-using-templates.c b/src/backend/taler-merchant-httpd_post-using-templates.c index 9252afc8..0f875853 100644 --- a/src/backend/taler-merchant-httpd_post-using-templates.c +++ b/src/backend/taler-merchant-httpd_post-using-templates.c @@ -112,124 +112,133 @@ TMH_post_using_templates_ID (const struct TMH_RequestHandler *rh, } /* End of the switch */ } - const char *tsummary; - uint32_t min_age; - struct GNUNET_TIME_Relative pay_duration; - struct TALER_Amount tamount; - bool no_tamount; - - struct GNUNET_JSON_Specification tspec[] = { - GNUNET_JSON_spec_mark_optional ( - GNUNET_JSON_spec_string ("summary", - &tsummary), - NULL), - GNUNET_JSON_spec_mark_optional ( - TALER_JSON_spec_amount ("amount", - TMH_currency, - &tamount), - &no_tamount), - GNUNET_JSON_spec_uint32 ("minimum_age", - &min_age), - GNUNET_JSON_spec_relative_time ("pay_duration", - &pay_duration), - GNUNET_JSON_spec_end () - }; - { - enum GNUNET_GenericReturnValue res; - const char *err_name; - unsigned int err_line; + const char *tsummary; + uint32_t min_age; + struct GNUNET_TIME_Relative pay_duration; + struct TALER_Amount tamount; + bool no_tamount; + + struct GNUNET_JSON_Specification tspec[] = { + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_string ("summary", + &tsummary), + NULL), + GNUNET_JSON_spec_mark_optional ( + TALER_JSON_spec_amount ("amount", + TMH_currency, + &tamount), + &no_tamount), + GNUNET_JSON_spec_uint32 ("minimum_age", + &min_age), + GNUNET_JSON_spec_relative_time ("pay_duration", + &pay_duration), + GNUNET_JSON_spec_end () + }; - res = GNUNET_JSON_parse (etp.template_contract, - tspec, - &err_name, - &err_line); - if (GNUNET_OK != res) { - GNUNET_break (0); - json_dumpf (etp.template_contract, - stderr, - JSON_INDENT (2)); - GNUNET_JSON_parse_free (spec); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_FETCH_FAILED, - err_name); + enum GNUNET_GenericReturnValue res; + const char *err_name; + unsigned int err_line; + + res = GNUNET_JSON_parse (etp.template_contract, + tspec, + &err_name, + &err_line); + if (GNUNET_OK != res) + { + GNUNET_break (0); + json_dumpf (etp.template_contract, + stderr, + JSON_INDENT (2)); + TALER_MERCHANTDB_template_details_free (&etp); + GNUNET_JSON_parse_free (spec); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + err_name); + } } - } - - // if amount given in template AND request - if ((! no_amount) && (! no_tamount)) - { - GNUNET_JSON_parse_free (spec); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_CONFLICT, - TALER_EC_MERCHANT_POST_USING_TEMPLATES_AMOUNT_CONFLICT_TEMPLATES_CONTRACT_AMOUNT, - NULL); - } - // if there is no amount in template and request - if (no_amount && no_tamount) - { - GNUNET_JSON_parse_free (spec); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_CONFLICT, - TALER_EC_MERCHANT_POST_USING_TEMPLATES_NO_AMOUNT, - NULL); - } + if ( (! no_amount) && + (! no_tamount) ) + { + GNUNET_JSON_parse_free (spec); + TALER_MERCHANTDB_template_details_free (&etp); + return TALER_MHD_reply_with_error ( + connection, + MHD_HTTP_CONFLICT, + TALER_EC_MERCHANT_POST_USING_TEMPLATES_AMOUNT_CONFLICT_TEMPLATES_CONTRACT_AMOUNT, + NULL); + } - if ( (NULL!=summary) && (NULL != tsummary)) - { + if (no_amount && no_tamount) + { + GNUNET_JSON_parse_free (spec); + TALER_MERCHANTDB_template_details_free (&etp); + return TALER_MHD_reply_with_error ( + connection, + MHD_HTTP_CONFLICT, + TALER_EC_MERCHANT_POST_USING_TEMPLATES_NO_AMOUNT, + NULL); + } - GNUNET_JSON_parse_free (spec); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_CONFLICT, - TALER_EC_MERCHANT_POST_USING_TEMPLATES_SUMMARY_CONFLICT_TEMPLATES_CONTRACT_SUBJECT, - NULL); - } + if ( (NULL != summary) && + (NULL != tsummary) ) + { + GNUNET_JSON_parse_free (spec); + TALER_MERCHANTDB_template_details_free (&etp); + return TALER_MHD_reply_with_error ( + connection, + MHD_HTTP_CONFLICT, + TALER_EC_MERCHANT_POST_USING_TEMPLATES_SUMMARY_CONFLICT_TEMPLATES_CONTRACT_SUBJECT, + NULL); + } - // if there is no summary in template and request - if ( (NULL == summary) && (NULL == tsummary) ) - { - GNUNET_JSON_parse_free (spec); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_CONFLICT, - TALER_EC_MERCHANT_POST_USING_TEMPLATES_NO_SUMMARY, - NULL); + if ( (NULL == summary) && + (NULL == tsummary) ) + { + GNUNET_JSON_parse_free (spec); + TALER_MERCHANTDB_template_details_free (&etp); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_CONFLICT, + TALER_EC_MERCHANT_POST_USING_TEMPLATES_NO_SUMMARY, + NULL); + } + no_summary = (NULL == summary); + fake_body = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_object_steal ("order", + GNUNET_JSON_PACK ( + TALER_JSON_pack_amount ("amount", + no_amount ? + &tamount : + &amount), + GNUNET_JSON_pack_string ("summary", + no_summary ? + tsummary : + summary), + GNUNET_JSON_pack_allow_null ( + GNUNET_JSON_pack_string ( + "fulfillment_url", + fulfillment_url)), + GNUNET_JSON_pack_allow_null ( + GNUNET_JSON_pack_string ( + "fulfillment_message", + fulfillment_message)) + )) + ); } - no_summary = (NULL == summary); - fake_body = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_object_steal ("order", - GNUNET_JSON_PACK ( - TALER_JSON_pack_amount ("amount", - no_amount ? - &tamount : - &amount), - GNUNET_JSON_pack_string ("summary", - no_summary ? - tsummary : - summary), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ( - "fulfillment_url", - fulfillment_url)), - GNUNET_JSON_pack_allow_null ( - GNUNET_JSON_pack_string ( - "fulfillment_message", - fulfillment_message)) - )) - ); - TALER_MERCHANTDB_template_details_free (&etp); { struct TMH_HandlerContext fake_hc = { .request_body = fake_body, .instance = hc->instance }; - mret = TMH_private_post_orders (NULL, /* not even used */ + mret = TMH_private_post_orders (NULL, /* not even used */ connection, &fake_hc); } + TALER_MERCHANTDB_template_details_free (&etp); json_decref (fake_body); return mret; } |