summaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-webhook.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/taler-merchant-webhook.c')
-rw-r--r--src/backend/taler-merchant-webhook.c66
1 files changed, 35 insertions, 31 deletions
diff --git a/src/backend/taler-merchant-webhook.c b/src/backend/taler-merchant-webhook.c
index 17e56bb2..36e0f1a1 100644
--- a/src/backend/taler-merchant-webhook.c
+++ b/src/backend/taler-merchant-webhook.c
@@ -22,10 +22,8 @@
#include <gnunet/gnunet_util_lib.h>
#include <jansson.h>
#include <pthread.h>
-#include <curl.h>
#include "taler_merchantdb_lib.h"
#include "taler_merchantdb_plugin.h"
-#include "taler_json_lib.h"
struct Work_response
@@ -103,7 +101,7 @@ shutdown_task (void *cls)
w_tail,
w);
GNUNET_CURL_job_cancel (w->job);
- curl_slist_free (w->job_headers);
+ curl_slist_free_all (w->job_headers);
GNUNET_free (w->body);
GNUNET_free (w);
}
@@ -123,6 +121,9 @@ shutdown_task (void *cls)
}
}
+/* The fuction is defined after */
+static void select_work (void *cls);
+
/**
* This function is used by the function `pending_webhooks_cb`. According to the response code,
@@ -147,7 +148,7 @@ handle_webhook_response (void *cls,
if (2 == response_code / 100) /* any 2xx http status code is OK! */
{
- db_plugib->delete_pending_webhook (db_plugin->cls,
+ db_plugin->delete_pending_webhook (db_plugin->cls,
w->webhook_serial);
}
else
@@ -210,12 +211,13 @@ pending_webhooks_cb (void *cls,
struct curl_slist *job_headers = NULL;
(void) retries;
(void) next_attempt;
+ (void) cls;
GNUNET_CONTAINER_DLL_insert (w_head,
w_tail,
w);
w->webhook_serial = webhook_serial;
- eh = curl_easy_new ();
+ eh = curl_easy_init ();
GNUNET_assert (NULL != eh);
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
@@ -234,7 +236,11 @@ pending_webhooks_cb (void *cls,
w->body));
/* conversion header to job_headers data */
- job_headers = GNUNET_strdup (header);
+ char *header_copy = GNUNET_strdup (header);
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_POSTFIELDS,
+ header_copy));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_POSTFIELDS,
@@ -263,6 +269,8 @@ pending_webhooks_cb (void *cls,
}
+
+
/**
* Typically called by `select_work`.
*
@@ -307,60 +315,58 @@ static void
select_work (void *cls)
{
enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_TIME_Relative next_attempt;
+ struct GNUNET_TIME_Relative rel;
(void) cls;
task = NULL;
- if (GNUNET_SYSERR ==
- db_plugin->preflight (db_plugin->cls))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to obtain database connection!\n");
- global_ret = EXIT_FAILURE;
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
+ db_plugin->preflight (db_plugin->cls);
qs = db_plugin->lookup_pending_webhooks (db_plugin->cls,
&pending_webhooks_cb,
NULL);
switch (qs)
{
- case GNUNET_BD_STATUS_HARD_ERROR:
- case GNUNET_BD_STATUS_SOFT_ERROR:
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ case GNUNET_DB_STATUS_SOFT_ERROR:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed!\n");
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ if (test_mode)
+ {
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
qs = db_plugin->lookup_future_webhook (db_plugin->cls,
&future_webhook_cb,
NULL);
switch (qs) {
- case GNUNET_BD_STATUS_HARD_ERROR:
- case GNUNET_BD_STATUS_SOFT_ERROR:
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ case GNUNET_DB_STATUS_SOFT_ERROR:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed!\n");
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
- case GNUNET_DB_STATUS_ONE_RESULT:
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
return;
- case GNUNET_DB_STATUS_NO_RESULT:
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
/* wait 5 min */
- struct GNUNET_TIME_Relative rel = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5);
+ rel = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5);
task = GNUNET_SCHEDULER_add_delayed (rel,
&select_work,
NULL);
return;
}
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
default:
return; // wait for completion, then select more work.
}
}
-/**
+/*
* First task.
*
* @param cls closure, NULL
@@ -374,7 +380,6 @@ run (void *cls,
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c)
{
- (void) cls;
(void) args;
(void) cfgfile;
@@ -398,15 +403,14 @@ run (void *cls,
GNUNET_SCHEDULER_shutdown ();
return;
}
- if (GNUNET_SYSERR ==
- db_plugin->preflight (db_plugin->cls))
+ if (GNUNET_OK !=
+ db_plugin->connect (db_plugin->cls))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to obtain database connection!\n");
- global_ret = EXIT_FAILURE;
+ "Failed to connect to database\n");
GNUNET_SCHEDULER_shutdown ();
return;
- }
+ }
GNUNET_assert (NULL == task);
task = GNUNET_SCHEDULER_add_now (&select_work,
NULL);