diff options
author | priscilla <priscilla.huang@efrei.net> | 2023-01-30 09:50:43 -0500 |
---|---|---|
committer | priscilla <priscilla.huang@efrei.net> | 2023-01-30 09:51:04 -0500 |
commit | 60e77f622c825b81e663f4b97af2a8f98ef995bb (patch) | |
tree | f23cb2c892c408c16dcf19e384aacc5b5da1759f /src/backend/taler-merchant-webhook.c | |
parent | 7c7b7407afbf4f51d9c02479843257b50f398e42 (diff) |
testing pending webhook
Diffstat (limited to 'src/backend/taler-merchant-webhook.c')
-rw-r--r-- | src/backend/taler-merchant-webhook.c | 83 |
1 files changed, 58 insertions, 25 deletions
diff --git a/src/backend/taler-merchant-webhook.c b/src/backend/taler-merchant-webhook.c index 2e2e5532..a1a31558 100644 --- a/src/backend/taler-merchant-webhook.c +++ b/src/backend/taler-merchant-webhook.c @@ -26,10 +26,10 @@ #include "taler_merchantdb_plugin.h" -struct Work_response +struct WorkResponse { - struct Work_response *next; - struct Work_response *prev; + struct WorkResponse *next; + struct WorkResponse *prev; struct GNUNET_CURL_Job *job; uint64_t webhook_serial; char *body; @@ -37,9 +37,9 @@ struct Work_response }; -static struct Work_response *w_head; +static struct WorkResponse *w_head; -static struct Work_response *w_tail; +static struct WorkResponse *w_tail; /** * The exchange's configuration. @@ -85,7 +85,7 @@ static int test_mode; static void shutdown_task (void *cls) { - struct Work_response *w; + struct WorkResponse *w; (void) cls; GNUNET_log (GNUNET_ERROR_TYPE_INFO, @@ -146,12 +146,15 @@ handle_webhook_response (void *cls, const void *body, size_t body_size) { - struct Work_response *w = cls; - struct GNUNET_TIME_Relative next_attempt; + struct WorkResponse *w = cls; (void) body; (void) body_size; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Webhook %llu returned with status %ld\n", + (unsigned long long) w->webhook_serial, + response_code); if (2 == response_code / 100) /* any 2xx http status code is OK! */ { db_plugin->delete_pending_webhook (db_plugin->cls, @@ -159,6 +162,9 @@ handle_webhook_response (void *cls, } else { + struct GNUNET_TIME_Relative next_attempt; + enum GNUNET_DB_QueryStatus qs; + switch (response_code) { case MHD_HTTP_BAD_REQUEST: @@ -174,9 +180,13 @@ handle_webhook_response (void *cls, next_attempt = GNUNET_TIME_UNIT_HOURS; break; } - db_plugin->update_pending_webhook (db_plugin->cls, - w->webhook_serial, - GNUNET_TIME_relative_to_absolute (next_attempt)); + qs = db_plugin->update_pending_webhook (db_plugin->cls, + w->webhook_serial, + GNUNET_TIME_relative_to_absolute (next_attempt)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Next in %s Rval: %d\n", + GNUNET_TIME_relative2s (next_attempt, true), + qs); } GNUNET_CONTAINER_DLL_remove (w_head, w_tail, @@ -212,12 +222,12 @@ pending_webhooks_cb (void *cls, const char *header, const char *body) { - struct Work_response *w = GNUNET_new (struct Work_response); + struct WorkResponse *w = GNUNET_new (struct WorkResponse); CURL *eh; - struct curl_slist *job_headers = NULL; (void) retries; (void) next_attempt; (void) cls; + struct curl_slist *job_headers = NULL; GNUNET_CONTAINER_DLL_insert (w_head, w_tail, @@ -233,25 +243,48 @@ pending_webhooks_cb (void *cls, curl_easy_setopt (eh, CURLOPT_URL, url)); - - /* conversion body data */ - w->body = GNUNET_strdup (body); GNUNET_assert (CURLE_OK == curl_easy_setopt (eh, - CURLOPT_POSTFIELDS, - w->body)); + CURLOPT_VERBOSE, + 1L)); + /* conversion body data */ + if (NULL != body) + { + w->body = GNUNET_strdup (body); + GNUNET_assert (CURLE_OK == + curl_easy_setopt (eh, + CURLOPT_POSTFIELDS, + w->body)); + } /* conversion header to job_headers data */ - char *header_copy = GNUNET_strdup (header); + if (NULL != header) + { + char *header_copy = GNUNET_strdup (header); + + for (const char *tok = strtok (header_copy, "\n"); + tok = strtok (NULL, "\n"); + NULL != tok) + { + // extract all Key: value from 'header_copy'! + job_headers = curl_slist_append (job_headers, + tok); + } + GNUNET_free (header_copy); + GNUNET_assert (CURLE_OK == + curl_easy_setopt (eh, + CURLOPT_HTTPHEADER, + job_headers)); + w->job_headers = job_headers; + } GNUNET_assert (CURLE_OK == curl_easy_setopt (eh, - CURLOPT_POSTFIELDS, - header_copy)); + CURLOPT_MAXREDIRS, + 5)); GNUNET_assert (CURLE_OK == curl_easy_setopt (eh, - CURLOPT_POSTFIELDS, - job_headers)); - w->job_headers = job_headers; + CURLOPT_FOLLOWLOCATION, + 1)); w->job = GNUNET_CURL_job_add_raw (ctx, eh, @@ -411,7 +444,7 @@ run (void *cls, "Failed to connect to database\n"); GNUNET_SCHEDULER_shutdown (); return; - } + } GNUNET_assert (NULL == task); task = GNUNET_SCHEDULER_add_now (&select_work, NULL); |