diff options
-rw-r--r-- | src/backend/taler-merchant-httpd_private-patch-templates-ID.c | 22 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-templates.c | 12 | ||||
-rw-r--r-- | src/include/taler_merchant_service.h | 72 | ||||
-rw-r--r-- | src/include/taler_merchantdb_plugin.h | 5 | ||||
-rw-r--r-- | src/lib/merchant_api_get_template.c | 61 | ||||
-rw-r--r-- | src/lib/merchant_api_patch_template.c | 3 | ||||
-rw-r--r-- | src/lib/merchant_api_post_templates.c | 3 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_get_template.c | 23 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_patch_template.c | 29 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_post_templates.c | 1 |
10 files changed, 144 insertions, 87 deletions
diff --git a/src/backend/taler-merchant-httpd_private-patch-templates-ID.c b/src/backend/taler-merchant-httpd_private-patch-templates-ID.c index 57c6dd95..52a21b57 100644 --- a/src/backend/taler-merchant-httpd_private-patch-templates-ID.c +++ b/src/backend/taler-merchant-httpd_private-patch-templates-ID.c @@ -52,9 +52,9 @@ determine_cause (struct MHD_Connection *connection, enum GNUNET_DB_QueryStatus qs; qs = TMH_db->lookup_template (TMH_db->cls, - instance_id, - template_id, - &tpx); + instance_id, + template_id, + &tpx); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: @@ -102,16 +102,19 @@ determine_cause (struct MHD_Connection *connection, */ MHD_RESULT TMH_private_patch_templates_ID (const struct TMH_RequestHandler *rh, - struct MHD_Connection *connection, - struct TMH_HandlerContext *hc) + struct MHD_Connection *connection, + struct TMH_HandlerContext *hc) { struct TMH_MerchantInstance *mi = hc->instance; const char *template_id = hc->infix; struct TALER_MERCHANTDB_TemplateDetails tp = {0}; enum GNUNET_DB_QueryStatus qs; + uint32_t pos_algorithm; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ("template_description", (const char **) &tp.template_description), + GNUNET_JSON_spec_uint32 ("pos_algorithm", + &pos_algorithm), GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_string ("pos_key", (const char **) &tp.pos_key), @@ -135,7 +138,8 @@ TMH_private_patch_templates_ID (const struct TMH_RequestHandler *rh, : MHD_NO; } - if (! TMH_template_contract_valid (tp.template_contract)) + tp.pos_algorithm = (enum TALER_MerchantConfirmationAlgorithm) pos_algorithm; + if (! TMH_template_contract_valid (tp.template_contract)) { GNUNET_break_op (0); GNUNET_JSON_parse_free (spec); @@ -146,9 +150,9 @@ TMH_private_patch_templates_ID (const struct TMH_RequestHandler *rh, } qs = TMH_db->update_template (TMH_db->cls, - mi->settings.id, - template_id, - &tp); + mi->settings.id, + template_id, + &tp); { MHD_RESULT ret = MHD_NO; diff --git a/src/backend/taler-merchant-httpd_private-post-templates.c b/src/backend/taler-merchant-httpd_private-post-templates.c index ac2a9206..2ed76940 100644 --- a/src/backend/taler-merchant-httpd_private-post-templates.c +++ b/src/backend/taler-merchant-httpd_private-post-templates.c @@ -67,13 +67,16 @@ TMH_private_post_templates (const struct TMH_RequestHandler *rh, struct TALER_MERCHANTDB_TemplateDetails tp = { 0 }; const char *template_id; enum GNUNET_DB_QueryStatus qs; + uint32_t pos_algorithm; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ("template_id", &template_id), GNUNET_JSON_spec_string ("template_description", (const char **) &tp.template_description), - GNUNET_JSON_spec_mark_optional( - GNUNET_JSON_spec_string ("image", + GNUNET_JSON_spec_uint32 ("pos_algorithm", + &pos_algorithm), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_string ("pos_key", (const char **) &tp.pos_key), NULL), GNUNET_JSON_spec_json ("template_contract", @@ -96,6 +99,7 @@ TMH_private_post_templates (const struct TMH_RequestHandler *rh, : MHD_NO; } } + tp.pos_algorithm = (enum TALER_MerchantConfirmationAlgorithm) pos_algorithm; if (! TMH_template_contract_valid (tp.template_contract)) { GNUNET_break_op (0); @@ -185,8 +189,8 @@ TMH_private_post_templates (const struct TMH_RequestHandler *rh, if (GNUNET_DB_STATUS_SOFT_ERROR != qs) break; } -retry: - GNUNET_assert (GNUNET_DB_STATUS_SOFT_ERROR == qs); +retry: + GNUNET_assert (GNUNET_DB_STATUS_SOFT_ERROR == qs); TMH_db->rollback (TMH_db->cls); } /* for RETRIES loop */ GNUNET_JSON_parse_free (spec); diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h index 8237b47a..b748309e 100644 --- a/src/include/taler_merchant_service.h +++ b/src/include/taler_merchant_service.h @@ -4177,21 +4177,63 @@ struct TALER_MERCHANT_TemplateGetHandle; /** - * Function called with the result of the GET /templates operation. + * Details in a response to a GET /templates request. + */ +struct TALER_MERCHANT_TemplateGetResponse +{ + /** + * HTTP response details. + */ + struct TALER_MERCHANT_HttpResponse hr; + + /** + * Response details depending on the HTTP status. + */ + union + { + /** + * Information returned if the status was #MHD_HTTP_OK. + */ + struct + { + + /** + * description of the template + */ + const char *template_description; + + /** + * Shared key with the POS + */ + const char *pos_key; + + /** + * Template for the contract. + */ + const json_t *template_contract; + + /** + * Algorithm used to generate confirmations for the merchant. + */ + enum TALER_MerchantConfirmationAlgorithm mca; + + } success; + + } details; + +}; + + +/** + * Function called with the result of the GET /template/$ID operation. * * @param cls closure - * @param hr HTTP response details - * @param template_description description of the template - * @param image base64-encoded product image - * @param template_contract is the contract of the company + * @param tgr HTTP response details */ typedef void (*TALER_MERCHANT_TemplateGetCallback)( void *cls, - const struct TALER_MERCHANT_HttpResponse *hr, - const char *template_description, - const char *image, - const json_t *template_contract); + const struct TALER_MERCHANT_TemplateGetResponse *tgr); /** @@ -4249,7 +4291,8 @@ typedef void * @param backend_url HTTP base URL for the backend * @param template_id identifier to use for the template * @param template_description description of the template - * @param image base64-encoded product image + * @param pos_key shared key with the POS + * @param mca algorithm used to generate confirmations * @param template_contract is the contract of the company * @param cb function to call with the backend's result * @param cb_cls closure for @a cb @@ -4261,7 +4304,8 @@ TALER_MERCHANT_templates_post ( const char *backend_url, const char *template_id, const char *template_description, - const char *image, + const char *pos_key, + enum TALER_MerchantConfirmationAlgorithm mca, const json_t *template_contract, TALER_MERCHANT_TemplatesPostCallback cb, void *cb_cls); @@ -4304,7 +4348,8 @@ typedef void * or the transaction will fail with a #MHD_HTTP_NOT_FOUND * HTTP status code * @param template_description description of the template - * @param image base64-encoded product image + * @param pos shared key with the POS + * @param mca algorithm used to generate confirmations * @param template_contract is the contract of the company * @param cb function to call with the backend's result * @param cb_cls closure for @a cb @@ -4316,7 +4361,8 @@ TALER_MERCHANT_template_patch ( const char *backend_url, const char *template_id, const char *template_description, - const char *image, + const char *pos_key, + enum TALER_MerchantConfirmationAlgorithm mca, json_t *template_contract, TALER_MERCHANT_TemplatePatchCallback cb, void *cb_cls); diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h index 0cedf3ee..1ca27844 100644 --- a/src/include/taler_merchantdb_plugin.h +++ b/src/include/taler_merchantdb_plugin.h @@ -335,6 +335,11 @@ struct TALER_MERCHANTDB_TemplateDetails * In this template contract, we can have additional information. */ json_t *template_contract; + + /** + * Algorithm used to compute purchase confirmations. + */ + enum TALER_MerchantConfirmationAlgorithm pos_algorithm; }; diff --git a/src/lib/merchant_api_get_template.c b/src/lib/merchant_api_get_template.c index 3edb98a1..f65f48ba 100644 --- a/src/lib/merchant_api_get_template.c +++ b/src/lib/merchant_api_get_template.c @@ -79,9 +79,9 @@ handle_get_template_finished (void *cls, { struct TALER_MERCHANT_TemplateGetHandle *tgh = cls; const json_t *json = response; - struct TALER_MERCHANT_HttpResponse hr = { - .http_status = (unsigned int) response_code, - .reply = json + struct TALER_MERCHANT_TemplateGetResponse tgr = { + .hr.http_status = (unsigned int) response_code, + .hr.reply = json }; tgh->job = NULL; @@ -92,67 +92,62 @@ handle_get_template_finished (void *cls, { case MHD_HTTP_OK: { - const char *template_description; - const char *pos_key; - json_t *template_contract; - bool rst_ok = true; + uint32_t alg32; + json_t *contract; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ("template_description", - &template_description), + &tgr.details.success.template_description), + GNUNET_JSON_spec_uint32 ("pos_algorithm", + &alg32), GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_string ("pos_key", - &pos_key), + &tgr.details.success.pos_key), NULL), GNUNET_JSON_spec_json ("template_contract", - &template_contract), + &contract), GNUNET_JSON_spec_end () }; - - if ( (rst_ok) && - (GNUNET_OK == - GNUNET_JSON_parse (json, - spec, - NULL, NULL)) ) + if (GNUNET_OK == + GNUNET_JSON_parse (json, + spec, + NULL, NULL)) { + tgr.details.success.mca = + (enum TALER_MerchantConfirmationAlgorithm) alg32; + tgr.details.success.template_contract = contract; tgh->cb (tgh->cb_cls, - &hr, - template_description, - pos_key, - template_contract); + &tgr); GNUNET_JSON_parse_free (spec); TALER_MERCHANT_template_get_cancel (tgh); return; } - hr.http_status = 0; - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + tgr.hr.http_status = 0; + tgr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; GNUNET_JSON_parse_free (spec); break; } case MHD_HTTP_UNAUTHORIZED: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + tgr.hr.ec = TALER_JSON_get_error_code (json); + tgr.hr.hint = TALER_JSON_get_error_hint (json); /* Nothing really to verify, merchant says we need to authenticate. */ break; case MHD_HTTP_NOT_FOUND: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + tgr.hr.ec = TALER_JSON_get_error_code (json); + tgr.hr.hint = TALER_JSON_get_error_hint (json); break; default: /* unexpected response code */ - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + tgr.hr.ec = TALER_JSON_get_error_code (json); + tgr.hr.hint = TALER_JSON_get_error_hint (json); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d\n", (unsigned int) response_code, - (int) hr.ec); + (int) tgr.hr.ec); break; } tgh->cb (tgh->cb_cls, - &hr, - NULL, - NULL, - NULL); + &tgr); TALER_MERCHANT_template_get_cancel (tgh); } diff --git a/src/lib/merchant_api_patch_template.c b/src/lib/merchant_api_patch_template.c index 5034101d..0922586a 100644 --- a/src/lib/merchant_api_patch_template.c +++ b/src/lib/merchant_api_patch_template.c @@ -163,6 +163,7 @@ TALER_MERCHANT_template_patch ( const char *template_id, const char *template_description, const char *pos_key, + enum TALER_MerchantConfirmationAlgorithm mca, json_t *template_contract, TALER_MERCHANT_TemplatePatchCallback cb, void *cb_cls) @@ -173,6 +174,8 @@ TALER_MERCHANT_template_patch ( req_obj = GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("template_description", template_description), + GNUNET_JSON_pack_uint64 ("pos_algorithm", + (uint32_t) mca), GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_string ("pos_key", pos_key)), diff --git a/src/lib/merchant_api_post_templates.c b/src/lib/merchant_api_post_templates.c index 735368db..53111258 100644 --- a/src/lib/merchant_api_post_templates.c +++ b/src/lib/merchant_api_post_templates.c @@ -200,6 +200,7 @@ TALER_MERCHANT_templates_post ( const char *template_id, const char *template_description, const char *pos_key, + enum TALER_MerchantConfirmationAlgorithm pos_algorithm, const json_t *template_contract, TALER_MERCHANT_TemplatesPostCallback cb, void *cb_cls) @@ -217,6 +218,8 @@ TALER_MERCHANT_templates_post ( template_id), GNUNET_JSON_pack_string ("template_description", template_description), + GNUNET_JSON_pack_uint64 ("pos_algorithm", + (uint32_t) pos_algorithm), GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_string ("pos_key", pos_key)), diff --git a/src/testing/testing_api_cmd_get_template.c b/src/testing/testing_api_cmd_get_template.c index da8b6786..8b32156d 100644 --- a/src/testing/testing_api_cmd_get_template.c +++ b/src/testing/testing_api_cmd_get_template.c @@ -71,33 +71,27 @@ struct GetTemplateState * Callback for a /get/templates/$ID operation. * * @param cls closure for this function - * @param hr HTTP response details - * @param template_description description of the template - * @param pos_key shared key with the POS - * @param template_contract where the contract of the company is + * @param tgr HTTP response details */ static void get_template_cb (void *cls, - const struct TALER_MERCHANT_HttpResponse *hr, - const char *template_description, - const char *pos_key, - const json_t *template_contract) + const struct TALER_MERCHANT_TemplateGetResponse *tgr) { struct GetTemplateState *gis = cls; const struct TALER_TESTING_Command *template_cmd; gis->igh = NULL; - if (gis->http_status != hr->http_status) + if (gis->http_status != tgr->hr.http_status) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u (%d) to command %s\n", - hr->http_status, - (int) hr->ec, + tgr->hr.http_status, + (int) tgr->hr.ec, TALER_TESTING_interpreter_get_current_label (gis->is)); TALER_TESTING_interpreter_fail (gis->is); return; } - switch (hr->http_status) + switch (tgr->hr.http_status) { case MHD_HTTP_OK: { @@ -110,7 +104,7 @@ get_template_cb (void *cls, TALER_TESTING_get_trait_template_description (template_cmd, &expected_description)) TALER_TESTING_interpreter_fail (gis->is); - if (0 != strcmp (template_description, + if (0 != strcmp (tgr->details.success.template_description, *expected_description)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -121,6 +115,7 @@ get_template_cb (void *cls, } { const char **expected_pos_key; + const char *pos_key = tgr->details.success.pos_key; if (GNUNET_OK != TALER_TESTING_get_trait_template_pos_key (template_cmd, @@ -147,7 +142,7 @@ get_template_cb (void *cls, TALER_TESTING_get_trait_template_contract (template_cmd, &expected_template_contract)) TALER_TESTING_interpreter_fail (gis->is); - if (1 != json_equal (template_contract, + if (1 != json_equal (tgr->details.success.template_contract, expected_template_contract)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, diff --git a/src/testing/testing_api_cmd_patch_template.c b/src/testing/testing_api_cmd_patch_template.c index f6f5771b..81560fa7 100644 --- a/src/testing/testing_api_cmd_patch_template.c +++ b/src/testing/testing_api_cmd_patch_template.c @@ -85,7 +85,7 @@ struct PatchTemplateState */ static void patch_template_cb (void *cls, - const struct TALER_MERCHANT_HttpResponse *hr) + const struct TALER_MERCHANT_HttpResponse *hr) { struct PatchTemplateState *pis = cls; @@ -131,20 +131,21 @@ patch_template_cb (void *cls, */ static void patch_template_run (void *cls, - const struct TALER_TESTING_Command *cmd, - struct TALER_TESTING_Interpreter *is) + const struct TALER_TESTING_Command *cmd, + struct TALER_TESTING_Interpreter *is) { struct PatchTemplateState *pis = cls; pis->is = is; pis->iph = TALER_MERCHANT_template_patch (is->ctx, - pis->merchant_url, - pis->template_id, - pis->template_description, - pis->pos_key, - pis->template_contract, - &patch_template_cb, - pis); + pis->merchant_url, + pis->template_id, + pis->template_description, + pis->pos_key, + TALER_MCA_NONE, + pis->template_contract, + &patch_template_cb, + pis); GNUNET_assert (NULL != pis->iph); } @@ -161,9 +162,9 @@ patch_template_run (void *cls, */ static enum GNUNET_GenericReturnValue patch_template_traits (void *cls, - const void **ret, - const char *trait, - unsigned int index) + const void **ret, + const char *trait, + unsigned int index) { struct PatchTemplateState *pts = cls; struct TALER_TESTING_Trait traits[] = { @@ -191,7 +192,7 @@ patch_template_traits (void *cls, */ static void patch_template_cleanup (void *cls, - const struct TALER_TESTING_Command *cmd) + const struct TALER_TESTING_Command *cmd) { struct PatchTemplateState *pis = cls; diff --git a/src/testing/testing_api_cmd_post_templates.c b/src/testing/testing_api_cmd_post_templates.c index 434ddb96..39728792 100644 --- a/src/testing/testing_api_cmd_post_templates.c +++ b/src/testing/testing_api_cmd_post_templates.c @@ -141,6 +141,7 @@ post_templates_run (void *cls, tis->template_id, tis->template_description, tis->pos_key, + TALER_MCA_NONE, tis->template_contract, &post_templates_cb, tis); |