merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 75a0133773eff771146b6dcdb9bb0239043dbcb0
parent 496f3dab20532e9ff4b0318b39f4ddc8290a418f
Author: Florian Dold <florian.dold@gmail.com>
Date:   Wed, 17 Feb 2016 03:05:46 +0100

fix #4174

Diffstat:
Msrc/backend/taler-merchant-httpd.c | 14++++++++++++++
Msrc/backend/taler-merchant-httpd.h | 28++++++++++++++++++++++++++++
Msrc/backend/taler-merchant-httpd_contract.c | 14+++++++++++++-
Msrc/backend/taler-merchant-httpd_pay.c | 1+
Msrc/backend/taler-merchant-httpd_util.c | 16+++++++++++++++-
5 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c @@ -437,6 +437,20 @@ validate_and_hash_wireformat (const char *allowed) /** + * Custom cleanup routine for a `struct PayContext`. + * + * @param hc the `struct PayContext` to clean up. + */ +void +TMH_json_parse_cleanup (struct TM_HandlerContext *hc) +{ + struct TMH_JsonParseContext *jpc = (struct TMH_JsonParseContext *) hc; + + TMH_PARSE_post_cleanup_callback (jpc->json_parse_context); +} + + +/** * Function that queries MHD's select sets and * starts the task waiting for them. * diff --git a/src/backend/taler-merchant-httpd.h b/src/backend/taler-merchant-httpd.h @@ -127,6 +127,26 @@ struct TM_HandlerContext /** + * Information we keep for an individual calls + * to requests that parse JSON, but keep no other state. + */ +struct TMH_JsonParseContext +{ + + /** + * This field MUST be first. + * FIXME: Explain why! + */ + struct TM_HandlerContext hc; + + /** + * Placeholder for #TMH_PARSE_post_json() to keep its internal state. + */ + void *json_parse_context; +}; + + +/** * Our wire format details in JSON format (with salt). */ extern json_t *j_wire; @@ -168,5 +188,13 @@ extern struct GNUNET_TIME_Relative edate_delay; void TMH_trigger_daemon (void); +/** + * Custom cleanup routine for a `struct PayContext`. + * + * @param hc the `struct PayContext` to clean up. + */ +void +TMH_json_parse_cleanup (struct TM_HandlerContext *hc); + #endif diff --git a/src/backend/taler-merchant-httpd_contract.c b/src/backend/taler-merchant-httpd_contract.c @@ -54,6 +54,7 @@ MH_handler_contract (struct TMH_RequestHandler *rh, json_t *root; json_t *jcontract; int res; + struct TMH_JsonParseContext *ctx; struct TALER_ContractPS contract; struct GNUNET_CRYPTO_EddsaSignature contract_sig; struct TALER_Amount total; @@ -66,8 +67,19 @@ MH_handler_contract (struct TMH_RequestHandler *rh, TMH_PARSE_MEMBER_END }; + if (NULL == *connection_cls) + { + ctx = GNUNET_new (struct TMH_JsonParseContext); + ctx->hc.cc = &TMH_json_parse_cleanup; + *connection_cls = ctx; + } + else + { + ctx = *connection_cls; + } + res = TMH_PARSE_post_json (connection, - connection_cls, + &ctx->json_parse_context, upload_data, upload_data_size, &root); diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c @@ -104,6 +104,7 @@ struct PayContext /** * This field MUST be first. + * FIXME: Explain why! */ struct TM_HandlerContext hc; diff --git a/src/backend/taler-merchant-httpd_util.c b/src/backend/taler-merchant-httpd_util.c @@ -27,6 +27,8 @@ #include "taler-merchant-httpd_mints.h" #include "taler-merchant-httpd_responses.h" + + /** * Hashes a plain JSON contract sending the result to the other end of * HTTP communication @@ -50,9 +52,21 @@ MH_handler_hash_contract (struct TMH_RequestHandler *rh, json_t *jcontract; int res; struct GNUNET_HashCode hc; + struct TMH_JsonParseContext *ctx; + + if (NULL == *connection_cls) + { + ctx = GNUNET_new (struct TMH_JsonParseContext); + ctx->hc.cc = &TMH_json_parse_cleanup; + *connection_cls = ctx; + } + else + { + ctx = *connection_cls; + } res = TMH_PARSE_post_json (connection, - connection_cls, + &ctx->json_parse_context, upload_data, upload_data_size, &root);