commit 397311c176d12e76fcb48cbda13d52c55cf78b90
parent fa770a9a29f4123164567c873ae6d6f34444777b
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date: Fri, 9 Dec 2016 16:58:00 +0100
Exporting /map/in merchant-lib in include file
Diffstat:
4 files changed, 104 insertions(+), 45 deletions(-)
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h
@@ -27,6 +27,41 @@
#include <gnunet/gnunet_curl_lib.h>
#include <jansson.h>
+/* ********************* /map/in *********************** */
+
+struct TALER_MERCHANT_MapInOperation;
+
+typedef void
+(*TALER_MERCHANT_MapInOperationCallback) (void *cls,
+ unsigned int http_status);
+
+/**
+ * Issue a /map/in request to the backend.
+ *
+ * @param ctx execution context
+ * @param backend_uri base URL of the merchant backend
+ * @param contract contract to store
+ * @param h_contract hashcode of `contract`
+ * @param map_in_cb callback which will work the response gotten from the backend
+ * @param map_in_cb_cls closure to pass to @a history_cb
+ * @return handle for this operation, NULL upon errors
+ */
+struct TALER_MERCHANT_MapInOperation *
+TALER_MERCHANT_map_in (struct GNUNET_CURL_Context *ctx,
+ const char *backend_uri,
+ const json_t *contract,
+ const struct GNUNET_HashCode *h_contract,
+ TALER_MERCHANT_MapInOperationCallback map_in_cb,
+ void *map_in_cb_cls);
+
+/**
+ * Cancel a /map/in request.
+ *
+ * @param mio handle to the request to be canceled
+ */
+void
+TALER_MERCHANT_map_in_cancel (struct TALER_MERCHANT_MapInOperation *mio);
+
/* ********************* /contract *********************** */
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
@@ -18,7 +18,8 @@ libtalermerchant_la_SOURCES = \
merchant_api_pay.c \
merchant_api_track_transaction.c \
merchant_api_track_transfer.c \
- merchant_api_history.c
+ merchant_api_history.c \
+ merchant_api_map.c
libtalermerchant_la_LIBADD = \
-ltalerexchange \
diff --git a/src/lib/merchant_api_contract.c b/src/lib/merchant_api_contract.c
@@ -94,9 +94,9 @@ handle_contract_finished (void *cls,
h_contractp = NULL;
switch (response_code)
{
- case 0:
- break;
- case MHD_HTTP_OK:
+ case 0:
+ break;
+ case MHD_HTTP_OK:
{
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_json ("contract", &contract),
@@ -104,7 +104,7 @@ handle_contract_finished (void *cls,
GNUNET_JSON_spec_fixed_auto ("H_contract", &h_contract),
GNUNET_JSON_spec_end()
};
-
+
if (GNUNET_OK !=
GNUNET_JSON_parse (json,
spec,
@@ -117,34 +117,33 @@ handle_contract_finished (void *cls,
h_contractp = &h_contract;
sigp = &sig;
}
- break;
- case MHD_HTTP_BAD_REQUEST:
- /* This should never happen, either us or the merchant is buggy
- (or API version conflict); just pass JSON reply to the application */
- break;
- case MHD_HTTP_FORBIDDEN:
- break;
- case MHD_HTTP_UNAUTHORIZED:
- /* Nothing really to verify, merchant says one of the signatures is
- invalid; as we checked them, this should never happen, we
- should pass the JSON reply to the application */
- break;
- case MHD_HTTP_NOT_FOUND:
- /* Nothing really to verify, this should never
- happen, we should pass the JSON reply to the application */
- break;
- case MHD_HTTP_INTERNAL_SERVER_ERROR:
- /* Server had an internal issue; we should retry, but this API
- leaves this to the application */
- break;
- default:
- /* unexpected response code */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u\n",
- (unsigned int) response_code);
- GNUNET_break (0);
- response_code = 0;
- break;
+ break;
+ case MHD_HTTP_BAD_REQUEST:
+ /* This should never happen, either us or the merchant is buggy
+ (or API version conflict); just pass JSON reply to the application */
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ /* Nothing really to verify, merchant says one of the signatures is
+ invalid; as we checked them, this should never happen, we
+ should pass the JSON reply to the application */
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ /* Nothing really to verify, this should never
+ happen, we should pass the JSON reply to the application */
+ break;
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ /* Server had an internal issue; we should retry, but this API
+ leaves this to the application */
+ break;
+ default:
+ /* unexpected response code */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u\n",
+ (unsigned int) response_code);
+ GNUNET_break (0);
+ response_code = 0;
}
co->cb (co->cb_cls,
response_code,
diff --git a/src/lib/merchant_api_map.c b/src/lib/merchant_api_map.c
@@ -38,7 +38,7 @@ struct TALER_MERCHANT_MapInOperation
/**
* Request's body
*/
- json_t *json_enc;
+ char *json_enc;
/**
* Handle for the request.
@@ -63,23 +63,47 @@ struct TALER_MERCHANT_MapInOperation
};
/**
+ * Cancel a /map/in request.
+ *
+ * @param mio handle to the request to be canceled
+ */
+void
+TALER_MERCHANT_map_in_cancel (struct TALER_MERCHANT_MapInOperation *mio)
+{
+ if (NULL != mio->job)
+ {
+ GNUNET_CURL_job_cancel (mio->job);
+ mio->job = NULL;
+ }
+ GNUNET_free (mio->url);
+ GNUNET_free (mio->json_enc);
+ GNUNET_free (mio);
+}
+
+/**
* Function called when we're done processing the
* HTTP /map/in request.
*
* @param cls the `struct TALER_MERCHANT_FIXME`
* @param response_code HTTP response code, 0 on error
- * @param json response body, NULL if not in JSON
+ * @param json response body, should be NULL
*/
static void
-handle_contract_finished (void *cls,
+handle_map_in_finished (void *cls,
long response_code,
const json_t *json)
{
+ struct TALER_MERCHANT_MapInOperation *mio = cls;
/**
- * 1 Check if errors occurred
- * 2 Call callback
+ * As no data is supposed to be extracted from this
+ * call, we just invoke the provided callback from here.
*/
+ mio->cb (mio->cb_cls,
+ response_code);
+
+ /* Right to call this here? */
+ TALER_MERCHANT_map_in_cancel (mio);
}
/**
@@ -93,13 +117,13 @@ handle_contract_finished (void *cls,
* @param map_in_cb_cls closure to pass to @a history_cb
* @return handle for this operation, NULL upon errors
*/
-struct TALER_MERCHANT_HistoryOperation *
-TALER_MERCHANT_history (struct GNUNET_CURL_Context *ctx,
- const char *backend_uri,
- const json_t *contract,
- const struct GNUNET_HashCode *h_contract,
- TALER_MERCHANT_MapInOperationCallback map_in_cb,
- void *map_in_cb_cls)
+struct TALER_MERCHANT_MapInOperation *
+TALER_MERCHANT_map_in (struct GNUNET_CURL_Context *ctx,
+ const char *backend_uri,
+ const json_t *contract,
+ const struct GNUNET_HashCode *h_contract,
+ TALER_MERCHANT_MapInOperationCallback map_in_cb,
+ void *map_in_cb_cls)
{
struct TALER_MERCHANT_MapInOperation *mio;
CURL *eh;