summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorpriscilla <priscilla.huang@efrei.net>2023-01-24 09:07:03 -0500
committerpriscilla <priscilla.huang@efrei.net>2023-01-24 09:07:03 -0500
commit37cd7259f99a112ee95ffb07ba40589c853ad028 (patch)
treefe44b8267fec9789aeff66954b4ce10db3ab6671 /src/backend
parenta99ab8c90f26396d1d7a62ce9582fb4150a1818e (diff)
downloadmerchant-37cd7259f99a112ee95ffb07ba40589c853ad028.tar.gz
merchant-37cd7259f99a112ee95ffb07ba40589c853ad028.tar.bz2
merchant-37cd7259f99a112ee95ffb07ba40589c853ad028.zip
update pending webhooks
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/taler-merchant-webhook.c89
1 files changed, 49 insertions, 40 deletions
diff --git a/src/backend/taler-merchant-webhook.c b/src/backend/taler-merchant-webhook.c
index 42600a5a..6d68c303 100644
--- a/src/backend/taler-merchant-webhook.c
+++ b/src/backend/taler-merchant-webhook.c
@@ -88,7 +88,7 @@ static void
shutdown_task (void *cls)
{
struct Work_response *w;
-
+
(void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Running shutdown\n");
@@ -125,17 +125,8 @@ shutdown_task (void *cls)
/**
- * Select webhook to process.
- *
- * @param cls NULL
- */
-static void
-select_work (void *cls);
-
-//http request and delete or update in function of the http. And do select work again
-
-/**
- * Function to call upon completion of a raw job.
+ * This function is used by the function pending_webhooks_cb. According to the response code,
+ * we delete or update the webhook.
*
* @param cls closure
* @param response_code HTTP response code from server, 0 on hard error
@@ -154,7 +145,7 @@ handle_webhook_response (void *cls,
(void) body;
(void) body_size;
job = NULL;
- // update DB status on the webhook! (delete or update webhook)
+
if (2 == response_code / 100) /* any 2xx http status code is OK! */
{
db_plugib->delete_pending_webhook (db_plugin->cls,
@@ -191,7 +182,7 @@ handle_webhook_response (void *cls,
/**
- * Typically called by `lookup_pending_webhooks`.
+ * Typically called by `select_work`.
*
* @param cls a `json_t *` JSON array to build
* @param webhook_serial reference to the configured webhook template.
@@ -202,20 +193,21 @@ handle_webhook_response (void *cls,
* @param header of the webhook
* @param body of the webhook
*/
-// initialisation curl, and do the job
static void
-cb (void *cls,
- uint64_t webhook_serial,
- struct GNUNET_TIME_Absolute next_attempt,
- uint32_t retries,
- const char *url,
- const char *http_method,
- const char *header,
- const char *body)
+pending_webhooks_cb (void *cls,
+ uint64_t webhook_serial,
+ struct GNUNET_TIME_Absolute next_attempt,
+ uint32_t retries,
+ const char *url,
+ const char *http_method,
+ const char *header,
+ const char *body)
{
struct Work_response *w = GNUNET_new (struct Work_response);
CURL *eh;
struct curl_slist *job_headers = NULL;
+ (void) retries;
+ (void) next_attempt;
GNUNET_CONTAINER_DLL_insert (w_head,
w_tail,
@@ -231,14 +223,22 @@ cb (void *cls,
curl_easy_setopt (eh,
CURLOPT_URL,
url));
- // FIXME: convert header to job_headers!
+ /* conversion body data */
w->body = GNUNET_strdup (body);
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_POSTFIELDS,
w->body));
+
+ /* conversion header to job_headers data */
+ job_headers = GNUNET_strdup (header);
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_POSTFIELDS,
+ job_headers));
w->job_headers = job_headers;
+
w->job = GNUNET_CURL_job_add_raw (ctx,
eh,
job_headers,
@@ -262,7 +262,7 @@ cb (void *cls,
/**
- * Typically called by `lookup_pending_webhooks`.
+ * Typically called by `select_work`.
*
* @param cls a `json_t *` JSON array to build
* @param webhook_serial reference to the configured webhook template.
@@ -273,19 +273,23 @@ cb (void *cls,
* @param header of the webhook
* @param body of the webhook
*/
-// initialisation curl, and do the job
static void
-cb_future (void *cls,
- uint64_t webhook_serial,
- struct GNUNET_TIME_Absolute next_attempt,
- uint32_t retries,
- const char *url,
- const char *http_method,
- const char *header,
- const char *body)
+future_webhook_cb (void *cls,
+ uint64_t webhook_serial,
+ struct GNUNET_TIME_Absolute next_attempt,
+ uint32_t retries,
+ const char *url,
+ const char *http_method,
+ const char *header,
+ const char *body)
{
(void) webhook_serial;
-
+ (void) retries;
+ (void) url;
+ (void) http_method;
+ (void) header;
+ (void) body;
+
task = GNUNET_SCHEDULER_add_at (next_attempt,
&select_work,
NULL);
@@ -297,7 +301,6 @@ cb_future (void *cls,
*
* @param cls NULL
*/
-// do the action of the pending webhook
static void
select_work (void *cls)
{
@@ -315,17 +318,23 @@ select_work (void *cls)
return;
}
qs = db_plugin->lookup_pending_webhooks (db_plugin->cls,
- &cb,
+ &pending_webhooks_cb,
NULL);
switch (qs)
{
- // FIXME: handle qs
case 0:
qs = db_plugin->lookup_future_webhook (db_plugin->cls,
- &cb_future,
+ &future_webhook_cb,
NULL);
switch (qs) {
- // ...
+ case 0:
+ return;
+ case -1:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed!\n");
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
}
return;
case -1 / -2: