summaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_check-payment.c
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-01-09 14:32:32 +0100
committerFlorian Dold <florian.dold@gmail.com>2018-01-09 23:45:42 +0100
commitabc3970d38ddad7faf51e6b0e22969904df04c9b (patch)
tree5b7dc1bd67b6b1bf478471d720e6ab62080bdc54 /src/backend/taler-merchant-httpd_check-payment.c
parentc327c3465474e6c1ca2f4c526f66694b0d55ef2d (diff)
downloadmerchant-abc3970d38ddad7faf51e6b0e22969904df04c9b.tar.gz
merchant-abc3970d38ddad7faf51e6b0e22969904df04c9b.tar.bz2
merchant-abc3970d38ddad7faf51e6b0e22969904df04c9b.zip
additional headers for taler-pay
Diffstat (limited to 'src/backend/taler-merchant-httpd_check-payment.c')
-rw-r--r--src/backend/taler-merchant-httpd_check-payment.c96
1 files changed, 1 insertions, 95 deletions
diff --git a/src/backend/taler-merchant-httpd_check-payment.c b/src/backend/taler-merchant-httpd_check-payment.c
index 145be9de..3079c5c2 100644
--- a/src/backend/taler-merchant-httpd_check-payment.c
+++ b/src/backend/taler-merchant-httpd_check-payment.c
@@ -33,100 +33,6 @@
/**
- * Concatenate two strings and grow the first buffer (of size n)
- * if necessary.
- */
-#define STR_CAT_GROW(s, p, n) do { \
- for (; strlen (s) + strlen (p) >= n; (n) = (n) * 2); \
- (s) = GNUNET_realloc ((s), (n)); \
- GNUNET_assert (NULL != (s)); \
- strncat (s, p, n); \
- } while (0)
-
-
-/**
- * Make an absolute URL to the backend.
- *
- * @param connection MHD connection to take header values from
- * @param path path of the url
- * @param ... NULL-terminated key-value pairs (char *) for query parameters
- */
-static char *
-make_absolute_backend_url (struct MHD_Connection *connection, char *path, ...)
-{
- static CURL *curl = NULL;
- if (NULL == curl)
- {
- curl = curl_easy_init();
- GNUNET_assert (NULL != curl);
- }
-
- size_t n = 256;
- char *res = GNUNET_malloc (n);
-
- GNUNET_assert (NULL != res);
-
- // By default we assume we're running under HTTP
- const char *proto = "http";
- const char *forwarded_proto = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, "X-Forwarded-Proto");
-
- if (NULL != forwarded_proto)
- proto = forwarded_proto;
-
- const char *host = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, "Host");
- const char *forwarded_host = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, "X-Forwarded-Host");
-
- const char *forwarded_prefix = 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 NULL;
- }
-
- STR_CAT_GROW (res, proto, n);
- STR_CAT_GROW (res, "://", n);
- STR_CAT_GROW (res, host, n);
- STR_CAT_GROW (res, "/", n);
- if (NULL != forwarded_prefix)
- STR_CAT_GROW (res, forwarded_prefix, n);
- STR_CAT_GROW (res, path, n);
-
- va_list args;
- va_start (args, path);
-
- unsigned int iparam = 0;
-
- while (1) {
- char *key = va_arg (args, char *);
- if (NULL == key)
- break;
- char *value = va_arg (args, char *);
- if (NULL == value)
- continue;
- if (0 == iparam)
- STR_CAT_GROW (res, "?", n);
- else
- STR_CAT_GROW (res, "&", n);
- iparam++;
- char *urlencoded_value = curl_easy_escape (curl, value, strlen (value));
- STR_CAT_GROW (res, key, n);
- STR_CAT_GROW (res, "=", n);
- STR_CAT_GROW (res, urlencoded_value, n);
- curl_free (urlencoded_value);
- }
-
- va_end (args);
-
- return res;
-}
-
-
-/**
* Manages a /check-payment call, checking the status
* of a payment and, if necessary, constructing the URL
* for a payment redirect URL.
@@ -311,7 +217,7 @@ MH_handler_check_payment (struct TMH_RequestHandler *rh,
do_pay:
{
- char *url = make_absolute_backend_url (connection, "trigger-pay",
+ char *url = TMH_make_absolute_backend_url (connection, "trigger-pay",
"contract_url", contract_url,
"session_id", session_id,
"h_contract_terms", h_contract_terms_str,