diff options
author | Florian Dold <florian.dold@gmail.com> | 2020-08-07 00:31:54 +0530 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2020-08-07 00:31:54 +0530 |
commit | b791a14c6118f4cdb1cf0257ab499324d3859e6d (patch) | |
tree | 9bba328d67e2894c2c54a735ebd99a24d3ccf39d | |
parent | 5698d609efd715668e24c22e20fed9d952723852 (diff) | |
download | merchant-b791a14c6118f4cdb1cf0257ab499324d3859e6d.tar.gz merchant-b791a14c6118f4cdb1cf0257ab499324d3859e6d.tar.bz2 merchant-b791a14c6118f4cdb1cf0257ab499324d3859e6d.zip |
pass status URLs in template instead of using JS, fix remaining #6457 FIXMEs
-rw-r--r-- | contrib/offer_refund.en.must | 2 | ||||
-rw-r--r-- | contrib/offer_tip.en.must | 2 | ||||
-rw-r--r-- | contrib/request_payment.en.must | 220 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_get-orders-ID.c | 89 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_get-orders-ID.h | 16 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_get-tips-ID.c | 90 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_get-tips-ID.h | 27 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-get-orders-ID.c | 33 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c | 47 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_qr.c | 10 | ||||
-rw-r--r-- | src/lib/merchant_api_tip_authorize.c | 8 |
11 files changed, 270 insertions, 274 deletions
diff --git a/contrib/offer_refund.en.must b/contrib/offer_refund.en.must index 5aacb85d..8dc9f937 100644 --- a/contrib/offer_refund.en.must +++ b/contrib/offer_refund.en.must @@ -90,7 +90,7 @@ body { <body> <script> - let checkUrl = FIXME-#6457_dold_refund_uri_to_URL("{{taler_refund_uri}}"); + let checkUrl = "{{order_status_url}}"; let delayMs = 500; function check() { let req = new XMLHttpRequest(); diff --git a/contrib/offer_tip.en.must b/contrib/offer_tip.en.must index 339f64ff..0a7f366c 100644 --- a/contrib/offer_tip.en.must +++ b/contrib/offer_tip.en.must @@ -90,7 +90,7 @@ body { <body> <script> - let checkUrl = FIXME-#6457_dold_tip_uri_to_URL("{{taler_tip_uri}}"); + let checkUrl = "{{tip_status_url}}"; let delayMs = 500; function check() { let req = new XMLHttpRequest(); diff --git a/contrib/request_payment.en.must b/contrib/request_payment.en.must index c4beed59..4faa9f27 100644 --- a/contrib/request_payment.en.must +++ b/contrib/request_payment.en.must @@ -89,224 +89,6 @@ body { </head> <body> - -<script> -{{! - Auto-generated from https://git.taler.net/wallet-core.git with the command: - - $ rollup packages/taler-wallet-core/lib/util/taleruri.js --name "taleruri" --file out.js --format umd -}} - -(function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : - typeof define === 'function' && define.amd ? define(['exports'], factory) : - (global = global || self, factory(global.taleruri = {})); -}(this, (function (exports) { 'use strict'; - - /* - This file is part of GNU Taler - (C) 2020 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ - // @ts-ignore - const _URL = globalThis.URL; - if (!_URL) { - throw Error("FATAL: URL not available"); - } - // @ts-ignore - const _URLSearchParams = globalThis.URLSearchParams; - if (!_URLSearchParams) { - throw Error("FATAL: URLSearchParams not available"); - } - const URLSearchParams = _URLSearchParams; - - /* - This file is part of GNU Taler - (C) 2019-2020 Taler Systems S.A. - - GNU Taler is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ - /** - * Parse a taler[+http]://withdraw URI. - * Return undefined if not passed a valid URI. - */ - function parseWithdrawUri(s) { - const pi = parseProtoInfo(s, "withdraw"); - if (!pi) { - return undefined; - } - const parts = pi.rest.split("/"); - if (parts.length < 2) { - return undefined; - } - const host = parts[0].toLowerCase(); - const pathSegments = parts.slice(1, parts.length - 1); - const withdrawId = parts[parts.length - 1]; - const p = [host, ...pathSegments].join("/"); - return { - bankIntegrationApiBaseUrl: `${pi.innerProto}://${p}/`, - withdrawalOperationId: withdrawId, - }; - } - /** - * Classify a taler:// URI. - */ - function classifyTalerUri(s) { - const sl = s.toLowerCase(); - if (sl.startsWith("taler://pay/")) { - return "taler-pay" /* TalerPay */; - } - if (sl.startsWith("taler+http://pay/")) { - return "taler-pay" /* TalerPay */; - } - if (sl.startsWith("taler://tip/")) { - return "taler-tip" /* TalerTip */; - } - if (sl.startsWith("taler+http://tip/")) { - return "taler-tip" /* TalerTip */; - } - if (sl.startsWith("taler://refund/")) { - return "taler-refund" /* TalerRefund */; - } - if (sl.startsWith("taler+http://refund/")) { - return "taler-refund" /* TalerRefund */; - } - if (sl.startsWith("taler://withdraw/")) { - return "taler-withdraw" /* TalerWithdraw */; - } - if (sl.startsWith("taler://notify-reserve/")) { - return "taler-notify-reserve" /* TalerNotifyReserve */; - } - return "unknown" /* Unknown */; - } - function parseProtoInfo(s, action) { - const pfxPlain = `taler://${action}/`; - const pfxHttp = `taler+http://${action}/`; - if (s.toLowerCase().startsWith(pfxPlain)) { - return { - innerProto: "https", - rest: s.substring(pfxPlain.length), - }; - } - else if (s.toLowerCase().startsWith(pfxHttp)) { - return { - innerProto: "http", - rest: s.substring(pfxHttp.length), - }; - } - else { - return undefined; - } - } - /** - * Parse a taler[+http]://pay URI. - * Return undefined if not passed a valid URI. - */ - function parsePayUri(s) { - var _a, _b; - const pi = parseProtoInfo(s, "pay"); - if (!pi) { - return undefined; - } - const c = pi === null || pi === void 0 ? void 0 : pi.rest.split("?"); - const q = new URLSearchParams((_a = c[1]) !== null && _a !== void 0 ? _a : ""); - const claimToken = (_b = q.get("c")) !== null && _b !== void 0 ? _b : undefined; - const parts = c[0].split("/"); - if (parts.length < 3) { - return undefined; - } - const host = parts[0].toLowerCase(); - const sessionId = parts[parts.length - 1]; - const orderId = parts[parts.length - 2]; - const pathSegments = parts.slice(1, parts.length - 2); - const p = [host, ...pathSegments].join("/"); - const merchantBaseUrl = `${pi.innerProto}://${p}/`; - return { - merchantBaseUrl, - orderId, - sessionId: sessionId, - claimToken, - }; - } - /** - * Parse a taler[+http]://tip URI. - * Return undefined if not passed a valid URI. - */ - function parseTipUri(s) { - const pi = parseProtoInfo(s, "tip"); - if (!pi) { - return undefined; - } - const c = pi === null || pi === void 0 ? void 0 : pi.rest.split("?"); - const parts = c[0].split("/"); - if (parts.length < 2) { - return undefined; - } - const host = parts[0].toLowerCase(); - const tipId = parts[parts.length - 1]; - const pathSegments = parts.slice(1, parts.length - 1); - const p = [host, ...pathSegments].join("/"); - const merchantBaseUrl = `${pi.innerProto}://${p}/`; - return { - merchantBaseUrl, - merchantTipId: tipId, - }; - } - /** - * Parse a taler[+http]://refund URI. - * Return undefined if not passed a valid URI. - */ - function parseRefundUri(s) { - const pi = parseProtoInfo(s, "refund"); - if (!pi) { - return undefined; - } - const c = pi === null || pi === void 0 ? void 0 : pi.rest.split("?"); - const parts = c[0].split("/"); - if (parts.length < 2) { - return undefined; - } - const host = parts[0].toLowerCase(); - const orderId = parts[parts.length - 1]; - const pathSegments = parts.slice(1, parts.length - 1); - const p = [host, ...pathSegments].join("/"); - const merchantBaseUrl = `${pi.innerProto}://${p}/`; - return { - merchantBaseUrl, - orderId, - }; - } - - exports.classifyTalerUri = classifyTalerUri; - exports.parsePayUri = parsePayUri; - exports.parseRefundUri = parseRefundUri; - exports.parseTipUri = parseTipUri; - exports.parseWithdrawUri = parseWithdrawUri; - - Object.defineProperty(exports, '__esModule', { value: true }); - -}))); -</script> - <script> function pay_uri_to_order_url(uri) { let parsed = taleruri.parsePayUri(uri); @@ -320,7 +102,7 @@ body { return url; } - let checkUrl = pay_uri_to_order_url("{{taler_pay_uri}}"); + let checkUrl = "{{order_status_url}}"; let delayMs = 500; function check() { let req = new XMLHttpRequest(); diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c b/src/backend/taler-merchant-httpd_get-orders-ID.c index 08756e2b..afe452a0 100644 --- a/src/backend/taler-merchant-httpd_get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_get-orders-ID.c @@ -371,6 +371,87 @@ make_taler_refund_uri (struct MHD_Connection *con, /** + * Create a http(s) URL for the given @a con and @a order_id + * and @a instance_id to display the /orders/{order_id} page. + * + * @param con HTTP connection + * @param order_id the order id + * @param instance_id instance, may be "default" + * @param claim_token claim token for the order, may be NULL + * @return corresponding http(s):// URL, or NULL on missing "host" + */ +char * +TMH_make_order_status_url (struct MHD_Connection *con, + const char *order_id, + const char *instance_id, + struct TALER_ClaimTokenP *claim_token) +{ + const char *host; + const char *forwarded_host; + const char *uri_path; + struct GNUNET_Buffer buf = { 0 }; + + host = MHD_lookup_connection_value (con, + MHD_HEADER_KIND, + "Host"); + forwarded_host = MHD_lookup_connection_value (con, + MHD_HEADER_KIND, + "X-Forwarded-Host"); + + uri_path = MHD_lookup_connection_value (con, + MHD_HEADER_KIND, + "X-Forwarded-Prefix"); + if (NULL != forwarded_host) + host = forwarded_host; + + if (NULL == host) + { + GNUNET_break (0); + return NULL; + } + + GNUNET_assert (NULL != instance_id); + GNUNET_assert (NULL != order_id); + + if (GNUNET_NO == TALER_mhd_is_https (con)) + GNUNET_buffer_write_str (&buf, + "http://"); + else + GNUNET_buffer_write_str (&buf, + "https://"); + + GNUNET_buffer_write_str (&buf, + host); + if (NULL != uri_path) + GNUNET_buffer_write_path (&buf, + uri_path); + if (0 != strcmp ("default", + instance_id)) + { + GNUNET_buffer_write_path (&buf, + "instances"); + GNUNET_buffer_write_path (&buf, + instance_id); + } + GNUNET_buffer_write_path (&buf, + "/orders"); + GNUNET_buffer_write_path (&buf, + order_id); + if ((NULL != claim_token) && + (0 != GNUNET_is_zero (claim_token))) + { + GNUNET_buffer_write_str (&buf, + "?token="); + GNUNET_buffer_write_data_encoded (&buf, + (char *) claim_token, + sizeof (struct TALER_ClaimTokenP)); + } + + return GNUNET_buffer_reap_str (&buf); +} + + +/** * Create a taler://pay/ URI for the given @a con and @a order_id * and @a session_id and @a instance_id. * @@ -468,6 +549,7 @@ send_pay_request (struct GetOrderData *god, { MHD_RESULT ret; char *taler_pay_uri; + char *order_status_url; struct GNUNET_TIME_Relative remaining; remaining = GNUNET_TIME_absolute_get_remaining (god->sc.long_poll_timeout); @@ -488,6 +570,10 @@ send_pay_request (struct GetOrderData *god, god->session_id, god->hc->instance->settings.id, &god->claim_token); + order_status_url = TMH_make_order_status_url (god->sc.con, + god->order_id, + god->hc->instance->settings.id, + &god->claim_token); if (god->generate_html) { char *qr; @@ -502,6 +588,8 @@ send_pay_request (struct GetOrderData *god, struct KVC kvc[] = { { "taler_pay_uri", taler_pay_uri }, + { "order_status_url", + order_status_url }, { "taler_pay_qrcode_svg", qr }, { "order_summary", @@ -538,6 +626,7 @@ send_pay_request (struct GetOrderData *god, already_paid_order_id); } GNUNET_free (taler_pay_uri); + GNUNET_free (order_status_url); return ret; } diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.h b/src/backend/taler-merchant-httpd_get-orders-ID.h index 1eb9a18a..d5d33fac 100644 --- a/src/backend/taler-merchant-httpd_get-orders-ID.h +++ b/src/backend/taler-merchant-httpd_get-orders-ID.h @@ -42,6 +42,22 @@ TMH_make_taler_pay_uri (struct MHD_Connection *con, const char *instance_id, struct TALER_ClaimTokenP *claim_token); +/** + * Create a http(s) URL for the given @a con and @a order_id + * and @a instance_id to display the /orders/{order_id} page. + * + * @param con HTTP connection + * @param order_id the order id + * @param instance_id instance, may be "default" + * @param claim_token claim token for the order, may be NULL + * @return corresponding http(s):// URL, or NULL on missing "host" + */ +char * +TMH_make_order_status_url (struct MHD_Connection *con, + const char *order_id, + const char *instance_id, + struct TALER_ClaimTokenP *claim_token); + /** * Handle a GET "/orders/$ID" request. diff --git a/src/backend/taler-merchant-httpd_get-tips-ID.c b/src/backend/taler-merchant-httpd_get-tips-ID.c index 487e88f4..237c1a4a 100644 --- a/src/backend/taler-merchant-httpd_get-tips-ID.c +++ b/src/backend/taler-merchant-httpd_get-tips-ID.c @@ -38,10 +38,10 @@ * @param instance_id instance, may be "default" * @return corresponding taler://tip/ URI, or NULL on missing "host" */ -static char * -make_taler_tip_uri (struct MHD_Connection *con, - const struct GNUNET_HashCode *tip_id, - const char *instance_id) +char * +TMH_make_taler_tip_uri (struct MHD_Connection *con, + const struct GNUNET_HashCode *tip_id, + const char *instance_id) { const char *host; const char *forwarded_host; @@ -100,6 +100,75 @@ make_taler_tip_uri (struct MHD_Connection *con, /** + * Create a http(s):// URL for the given @a con and @a tip_id + * and @a instance_id. + * + * @param con HTTP connection + * @param tip_id the tip id + * @param instance_id instance, may be "default" + * @return corresponding taler://tip/ URI, or NULL on missing "host" + */ +char * +TMH_make_tip_status_url (struct MHD_Connection *con, + const struct GNUNET_HashCode *tip_id, + const char *instance_id) +{ + const char *host; + const char *forwarded_host; + const char *uri_path; + struct GNUNET_Buffer buf = { 0 }; + + host = MHD_lookup_connection_value (con, + MHD_HEADER_KIND, + "Host"); + forwarded_host = MHD_lookup_connection_value (con, + MHD_HEADER_KIND, + "X-Forwarded-Host"); + + uri_path = MHD_lookup_connection_value (con, + MHD_HEADER_KIND, + "X-Forwarded-Prefix"); + if (NULL != forwarded_host) + host = forwarded_host; + + if (NULL == host) + { + GNUNET_break (0); + return NULL; + } + + GNUNET_assert (NULL != instance_id); + GNUNET_assert (NULL != tip_id); + + if (GNUNET_NO == TALER_mhd_is_https (con)) + GNUNET_buffer_write_str (&buf, + "http"); + else + GNUNET_buffer_write_str (&buf, + "http"); + GNUNET_buffer_write_str (&buf, + host); + if (NULL != uri_path) + GNUNET_buffer_write_path (&buf, + uri_path); + if (0 != strcmp ("default", + instance_id)) + { + GNUNET_buffer_write_path (&buf, + "instances"); + GNUNET_buffer_write_path (&buf, + instance_id); + } + GNUNET_buffer_write_path (&buf, + "tips/"); + GNUNET_buffer_write_data_encoded (&buf, + tip_id, + sizeof (*tip_id)); + return GNUNET_buffer_reap_str (&buf); +} + + +/** * Handle a GET "/tips/$ID" request. * * @param rh context of the handler @@ -180,10 +249,14 @@ TMH_get_tips_ID (const struct TMH_RequestHandler *rh, { char *qr; char *uri; + char *tip_status_url; - uri = make_taler_tip_uri (connection, - &tip_id, - hc->instance->settings.id); + uri = TMH_make_taler_tip_uri (connection, + &tip_id, + hc->instance->settings.id); + tip_status_url = TMH_make_tip_status_url (connection, + &tip_id, + hc->instance->settings.id); qr = TMH_create_qrcode (uri); if (NULL == qr) { @@ -199,6 +272,8 @@ TMH_get_tips_ID (const struct TMH_RequestHandler *rh, struct KVC kvc[] = { { "remaining_tip", TALER_amount2s (&remaining) }, + { "tip_status_url", + tip_status_url }, { "taler_tip_uri", uri }, { "taler_tip_qrcode_svg", @@ -218,6 +293,7 @@ TMH_get_tips_ID (const struct TMH_RequestHandler *rh, uri, kvc); } + GNUNET_free (tip_status_url); GNUNET_free (uri); GNUNET_free (qr); } diff --git a/src/backend/taler-merchant-httpd_get-tips-ID.h b/src/backend/taler-merchant-httpd_get-tips-ID.h index 6fa0253a..9ee73a6a 100644 --- a/src/backend/taler-merchant-httpd_get-tips-ID.h +++ b/src/backend/taler-merchant-httpd_get-tips-ID.h @@ -23,6 +23,33 @@ #include <microhttpd.h> #include "taler-merchant-httpd.h" +/** + * Create a taler://tip/ URI for the given @a con and @a tip_id + * and @a instance_id. + * + * @param con HTTP connection + * @param tip_id the tip id + * @param instance_id instance, may be "default" + * @return corresponding taler://tip/ URI, or NULL on missing "host" + */ +char * +TMH_make_taler_tip_uri (struct MHD_Connection *con, + const struct GNUNET_HashCode *tip_id, + const char *instance_id); + +/** + * Create a http(s):// URL for the given @a con and @a tip_id + * and @a instance_id. + * + * @param con HTTP connection + * @param tip_id the tip id + * @param instance_id instance, may be "default" + * @return corresponding taler://tip/ URI, or NULL on missing "host" + */ +char * +TMH_make_tip_status_url (struct MHD_Connection *con, + const struct GNUNET_HashCode *tip_id, + const char *instance_id); /** * Handle a GET "/tips/$ID" request. diff --git a/src/backend/taler-merchant-httpd_private-get-orders-ID.c b/src/backend/taler-merchant-httpd_private-get-orders-ID.c index 7823837f..230a240f 100644 --- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c @@ -966,6 +966,7 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, /* User did pay for this order, but under a different session; ask wallet to switch order ID */ char *taler_pay_uri; + char *order_status_url; MHD_RESULT ret; taler_pay_uri = TMH_make_taler_pay_uri (connection, @@ -973,11 +974,17 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, gorc->session_id, hc->instance->settings.id, &claim_token); + order_status_url = TMH_make_order_status_url (connection, + hc->infix, + hc->instance->settings.id, + &claim_token); ret = TALER_MHD_reply_json_pack (connection, MHD_HTTP_OK, - "{s:s, s:s, s:s}", + "{s:s, s:s, s:s, s:s}", "taler_pay_uri", taler_pay_uri, + "order_status_url", + order_status_url, "order_status", "unpaid", "already_paid_order_id", @@ -1034,6 +1041,7 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, { /* User never paid for this order */ char *taler_pay_uri; + char *order_status_url; MHD_RESULT ret; taler_pay_uri = TMH_make_taler_pay_uri (connection, @@ -1041,16 +1049,23 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, gorc->session_id, hc->instance->settings.id, &claim_token); + order_status_url = TMH_make_order_status_url (connection, + hc->infix, + hc->instance->settings.id, + &claim_token); ret = TALER_MHD_reply_json_pack (connection, MHD_HTTP_OK, - "{s:s, s:O, s:s}", + "{s:s, s:s, s:O, s:s}", "taler_pay_uri", taler_pay_uri, + "order_status_url", + order_status_url, "contract_terms", gorc->contract_terms, "order_status", "unpaid"); GNUNET_free (taler_pay_uri); + GNUNET_free (order_status_url); return ret; } @@ -1081,6 +1096,8 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, { MHD_RESULT ret; + char *order_status_url; + GNUNET_assert (GNUNET_OK == TALER_amount_get_zero (TMH_currency, &gorc->deposits_total)); @@ -1166,10 +1183,15 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, } } + order_status_url = TMH_make_order_status_url (connection, + hc->infix, + hc->instance->settings.id, + &claim_token); + ret = TALER_MHD_reply_json_pack (connection, MHD_HTTP_OK, "{s:o, s:I, s:I, s:o, s:O," - " s:s, s:b, s:b, s:o, s:o, s:o}", + " s:s, s:b, s:b, s:o, s:o, s:o, s:s}", "wire_reports", gorc->wire_reports, "exchange_ec", @@ -1193,7 +1215,10 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, "wire_details", gorc->wire_details, "refund_details", - gorc->refund_details); + gorc->refund_details, + "order_status_url", + order_status_url); + GNUNET_free (order_status_url); gorc->wire_details = NULL; gorc->wire_reports = NULL; gorc->refund_details = NULL; diff --git a/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c b/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c index 1c28173b..2181f1eb 100644 --- a/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c +++ b/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c @@ -24,6 +24,7 @@ #include <taler/taler_json_lib.h> #include "taler-merchant-httpd.h" #include "taler-merchant-httpd_mhd.h" +#include "taler-merchant-httpd_get-tips-ID.h" #include "taler-merchant-httpd_private-post-reserves-ID-authorize-tip.h" @@ -116,54 +117,32 @@ authorize_tip (const struct TMH_RequestHandler *rh, /* generate success response */ { char *taler_tip_uri; - const char *host; - const char *forwarded_host; - const char *uri_path; + char *tip_status_url; struct GNUNET_CRYPTO_HashAsciiEncoded hash_enc; MHD_RESULT res; - host = MHD_lookup_connection_value (connection, - MHD_HEADER_KIND, - "Host"); - forwarded_host = MHD_lookup_connection_value (connection, - MHD_HEADER_KIND, - "X-Forwarded-Host"); - - uri_path = MHD_lookup_connection_value (connection, - MHD_HEADER_KIND, - "X-Forwarded-Prefix"); - if (NULL != forwarded_host) - host = forwarded_host; - if (NULL == host) - { - /* Should never happen, at last the host header should be defined */ - GNUNET_break (0); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_INTERNAL_INVARIANT_FAILURE, - "unable to identify backend host"); - } - GNUNET_CRYPTO_hash_to_enc (&tip_id, &hash_enc); - GNUNET_assert (0 < GNUNET_asprintf (&taler_tip_uri, - "taler://tip/%s/%s%sinstances/%s/%s", - host, - (NULL == uri_path) ? "" : uri_path, - (NULL == uri_path) ? "" : "/", - hc->instance->settings.id, - hash_enc.encoding)); + taler_tip_uri = TMH_make_taler_tip_uri (connection, + &tip_id, + hc->instance->settings.id); + tip_status_url = TMH_make_tip_status_url (connection, + &tip_id, + hc->instance->settings.id); GNUNET_TIME_round_abs (&expiration); res = TALER_MHD_reply_json_pack (connection, MHD_HTTP_OK, - "{s:s, s:s, s:o}", + "{s:s, s:s, s:s, s:o}", "tip_id", hash_enc.encoding, - "tip_redirect_url", + "taler_tip_uri", taler_tip_uri, + "tip_status_url", + tip_status_url, "tip_expiration", GNUNET_JSON_from_time_abs (expiration)); GNUNET_free (taler_tip_uri); + GNUNET_free (tip_status_url); return res; } } diff --git a/src/backend/taler-merchant-httpd_qr.c b/src/backend/taler-merchant-httpd_qr.c index ddb73167..1774f75b 100644 --- a/src/backend/taler-merchant-httpd_qr.c +++ b/src/backend/taler-merchant-httpd_qr.c @@ -73,11 +73,11 @@ TMH_create_qrcode (const char *uri) } QRinput_free (qri); GNUNET_buffer_write_fstr (&buf, - "<svg width='100mm' height='100mm' viewBox='0 0 %u %u' " - "version='1.1' xmlns='http://www.w3.org/2000/svg' " - "style='shape-rendering: crispedges;'>\n", - qrc->width, - qrc->width); + "<svg width='100mm' height='100mm' viewBox='0 0 %u %u' " + "version='1.1' xmlns='http://www.w3.org/2000/svg' " + "style='shape-rendering: crispedges;'>\n", + qrc->width, + qrc->width); for (unsigned int y = 0; y<qrc->width; y++) { for (unsigned int x = 0; x<qrc->width; x++) diff --git a/src/lib/merchant_api_tip_authorize.c b/src/lib/merchant_api_tip_authorize.c index d2f4cd9a..de71b747 100644 --- a/src/lib/merchant_api_tip_authorize.c +++ b/src/lib/merchant_api_tip_authorize.c @@ -83,11 +83,13 @@ static int check_ok (struct TALER_MERCHANT_TipAuthorizeHandle *tao, const json_t *json) { - const char *taler_tip_url; + const char *tip_status_url; + const char *taler_tip_uri; struct GNUNET_HashCode tip_id; struct GNUNET_TIME_Absolute expiration_time; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_string ("tip_redirect_url", &taler_tip_url), + GNUNET_JSON_spec_string ("tip_status_url", &tip_status_url), + GNUNET_JSON_spec_string ("taler_tip_uri", &taler_tip_uri), TALER_JSON_spec_absolute_time ("tip_expiration", &expiration_time), GNUNET_JSON_spec_fixed_auto ("tip_id", &tip_id), GNUNET_JSON_spec_end () @@ -116,7 +118,7 @@ check_ok (struct TALER_MERCHANT_TipAuthorizeHandle *tao, tao->cb (tao->cb_cls, &hr, &tip_id, - taler_tip_url, + taler_tip_uri, expiration_time); tao->cb = NULL; /* do not call twice */ GNUNET_JSON_parse_free (spec); |