From 01f946e7e059ad4f1490593145b783db6951b989 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 5 May 2016 08:33:30 +0200 Subject: parse out /contract response details --- src/include/taler_merchant_service.h | 10 ++++++++-- src/lib/merchant_api_contract.c | 38 ++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h index 5d72e6e9..fc98f09b 100644 --- a/src/include/taler_merchant_service.h +++ b/src/include/taler_merchant_service.h @@ -41,13 +41,19 @@ struct TALER_MERCHANT_ContractOperation; * @param cls closure * @param http_status HTTP response code, 200 indicates success; * 0 if the backend's reply is bogus (fails to follow the protocol) - * @param obj the received JSON reply, with the contract on success, or + * @param obj the full received JSON reply, or * error details if the request failed + * @param contract completed contract, NULL on error + * @param sig merchant's signature over the contract, NULL on error + * @param h_contract hash of the contract, NULL on error */ typedef void (*TALER_MERCHANT_ContractCallback) (void *cls, unsigned int http_status, - const json_t *obj); + const json_t *obj, + const json_t *contract, + const struct TALER_MerchantSignatureP *sig, + const struct GNUNET_HashCode *h_contract); /** diff --git a/src/lib/merchant_api_contract.c b/src/lib/merchant_api_contract.c index f8c3bcd3..fa327a5d 100644 --- a/src/lib/merchant_api_contract.c +++ b/src/lib/merchant_api_contract.c @@ -68,7 +68,6 @@ struct TALER_MERCHANT_ContractOperation }; - /** * Function called when we're done processing the * HTTP /contract request. @@ -83,13 +82,43 @@ handle_contract_finished (void *cls, const json_t *json) { struct TALER_MERCHANT_ContractOperation *co = cls; + json_t *contract; + const struct TALER_MerchantSignatureP *sigp; + const struct GNUNET_HashCode *h_contractp; + struct TALER_MerchantSignatureP sig; + struct GNUNET_HashCode h_contract; co->job = NULL; + contract = NULL; + sigp = NULL; + h_contractp = NULL; switch (response_code) { case 0: break; case MHD_HTTP_OK: + { + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_json ("contract", &contract), + GNUNET_JSON_spec_fixed_auto ("merchant_sig", &sig), + GNUNET_JSON_spec_fixed_auto ("H_contract", &h_contract), + GNUNET_JSON_spec_end() + }; + + if (GNUNET_OK != + GNUNET_JSON_parse (json, + spec, + NULL, NULL)) + { + GNUNET_break_op (0); + response_code = 0; + } + else + { + h_contractp = &h_contract; + sigp = &sig; + } + } break; case MHD_HTTP_BAD_REQUEST: /* This should never happen, either us or the merchant is buggy @@ -121,7 +150,12 @@ handle_contract_finished (void *cls, } co->cb (co->cb_cls, response_code, - json); + json, + contract, + sigp, + h_contractp); + if (NULL != contract) + json_decref (contract); TALER_MERCHANT_contract_sign_cancel (co); } -- cgit v1.2.3