summaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/taler-merchant-httpd.c')
-rw-r--r--src/backend/taler-merchant-httpd.c64
1 files changed, 63 insertions, 1 deletions
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c
index 77dd7449..b92aad47 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -152,6 +152,24 @@ static mode_t unixpath_mode;
/**
+ * Return GNUNET_YES if given a valid correlation ID and
+ * GNUNET_NO otherwise.
+ *
+ * @returns GNUNET_YES iff given a valid correlation ID
+ */
+static int
+is_valid_correlation_id (const char *correlation_id)
+{
+ if (strlen (correlation_id) >= 64)
+ return GNUNET_NO;
+ for (int i = 0; i < strlen (correlation_id); i++)
+ if (!(isalnum (correlation_id[i]) || correlation_id[i] == '-'))
+ return GNUNET_NO;
+ return GNUNET_YES;
+}
+
+
+/**
* A client has requested the given url using the given method
* (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT,
* #MHD_HTTP_METHOD_DELETE, #MHD_HTTP_METHOD_POST, etc). The callback
@@ -282,6 +300,46 @@ url_handler (void *cls,
"Handling request (%s) for URL `%s'\n",
method,
url);
+
+ struct TM_HandlerContext *hc;
+ struct GNUNET_AsyncScopeId aid;
+ const char *correlation_id = NULL;
+
+ hc = *con_cls;
+
+ if (NULL == hc)
+ {
+ GNUNET_async_scope_fresh (&aid);
+ /* We only read the correlation ID on the first callback for every client */
+ correlation_id = MHD_lookup_connection_value (connection,
+ MHD_HEADER_KIND,
+ "Taler-Correlation-Id");
+ if ((NULL != correlation_id) &&
+ (GNUNET_YES != is_valid_correlation_id (correlation_id)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "illegal incoming correlation ID\n");
+ correlation_id = NULL;
+ }
+ }
+ else
+ {
+ aid = hc->async_scope_id;
+ }
+
+ GNUNET_SCHEDULER_begin_async_scope (&aid);
+
+ if (NULL != correlation_id)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Handling request for (%s) URL '%s', correlation_id=%s\n",
+ method,
+ url,
+ correlation_id);
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Handling request (%s) for URL '%s'\n",
+ method,
+ url);
+
for (unsigned int i=0;NULL != handlers[i].url;i++)
{
struct TMH_RequestHandler *rh = &handlers[i];
@@ -292,7 +350,6 @@ url_handler (void *cls,
(0 == strcasecmp (method,
rh->method)) ) )
{
- struct TM_HandlerContext *hc;
int ret;
ret = rh->handler (rh,
@@ -302,7 +359,12 @@ url_handler (void *cls,
upload_data_size);
hc = *con_cls;
if (NULL != hc)
+ {
hc->rh = rh;
+ /* Store the async context ID, so we can restore it if
+ * we get another callack for this request. */
+ hc->async_scope_id = aid;
+ }
return ret;
}
}