diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/taler-merchant-httpd.c | 14 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd.h | 28 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_contract.c | 14 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_pay.c | 1 | ||||
-rw-r--r-- | src/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 index 9e0c7ac9..737e8f94 100644 --- 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 index c5a2c55e..ac5a4f89 100644 --- 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 index 6159dc6f..167e8b08 100644 --- 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 index 4c7b76f6..edace55b 100644 --- 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 index 2b541823..21f10bb0 100644 --- 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); |