summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-05-05 08:33:30 +0200
committerChristian Grothoff <christian@grothoff.org>2016-05-05 08:33:30 +0200
commit01f946e7e059ad4f1490593145b783db6951b989 (patch)
treec7887a94bd354cbeab4a7bb7a08df8e7f176350a
parent93b0c3b5bc99cd192f0b3d9da22467ed2280bb69 (diff)
downloadmerchant-01f946e7e059ad4f1490593145b783db6951b989.tar.gz
merchant-01f946e7e059ad4f1490593145b783db6951b989.tar.bz2
merchant-01f946e7e059ad4f1490593145b783db6951b989.zip
parse out /contract response details
-rw-r--r--src/include/taler_merchant_service.h10
-rw-r--r--src/lib/merchant_api_contract.c38
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);
}