summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorpriscilla <priscilla.huang@efrei.net>2023-01-26 05:49:12 -0500
committerpriscilla <priscilla.huang@efrei.net>2023-01-26 05:49:34 -0500
commit23826f925e94ea021f3ece175917d2240d9601c8 (patch)
tree600c1157d4f36ae7f377b5cd57926111213ab481 /src/backend
parentdac80e1e35ab724312d00f7e581d560fbc7e01f5 (diff)
downloadmerchant-23826f925e94ea021f3ece175917d2240d9601c8.tar.gz
merchant-23826f925e94ea021f3ece175917d2240d9601c8.tar.bz2
merchant-23826f925e94ea021f3ece175917d2240d9601c8.zip
pending webhook update
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/taler-merchant-httpd_private-delete-pending-webhooks-ID.c70
-rw-r--r--src/backend/taler-merchant-httpd_private-get-pending-webhooks.c79
-rw-r--r--src/backend/taler-merchant-webhook.c43
-rw-r--r--src/backend/taler-merchant-webhook.h39
4 files changed, 65 insertions, 166 deletions
diff --git a/src/backend/taler-merchant-httpd_private-delete-pending-webhooks-ID.c b/src/backend/taler-merchant-httpd_private-delete-pending-webhooks-ID.c
deleted file mode 100644
index 16b7e3ce..00000000
--- a/src/backend/taler-merchant-httpd_private-delete-pending-webhooks-ID.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- This file is part of TALER
- (C) 2023 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Affero General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file taler-merchant-httpd_private-delete-pending-webhooks-ID.c
- * @brief implement DELETE /pending webhooks/$ID
- * @author Priscilla HUANG
- */
-#include "platform.h"
-#include "taler-merchant-httpd_private-delete-pending-webhooks-ID.h"
-#include <taler/taler_json_lib.h>
-
-
-MHD_RESULT
-TMH_private_delete_pending_webhooks_ID (const struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- struct TMH_HandlerContext *hc)
-{
- struct TMH_MerchantInstance *mi = hc->instance;
- enum GNUNET_DB_QueryStatus qs;
-
- (void) rh;
- GNUNET_assert (NULL != mi);
- GNUNET_assert (NULL != hc->infix);
- qs = TMH_db->delete_pending_webhook (TMH_db->cls,
- mi->settings.id,
- hc->infix);
- switch (qs)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_STORE_FAILED,
- "delete_pending_webhook");
- case GNUNET_DB_STATUS_SOFT_ERROR:
- GNUNET_break (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
- "delete_pending_webhook (soft)");
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_MERCHANT_GENERIC_PENDING_WEBHOOK_UNKNOWN,
- hc->infix);
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- return TALER_MHD_reply_static (connection,
- MHD_HTTP_NO_CONTENT,
- NULL,
- NULL,
- 0);
- }
- GNUNET_assert (0);
- return MHD_NO;
-}
-
-
-/* end of taler-merchant-httpd_private-delete-pending-webhooks-ID.c */
diff --git a/src/backend/taler-merchant-httpd_private-get-pending-webhooks.c b/src/backend/taler-merchant-httpd_private-get-pending-webhooks.c
deleted file mode 100644
index d5160476..00000000
--- a/src/backend/taler-merchant-httpd_private-get-pending-webhooks.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- This file is part of TALER
- (C) 2023 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Affero General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file taler-merchant-httpd_private-get-pending-webhooks.c
- * @brief implement GET /pending webhooks
- * @author Priscilla HUANG
- */
-#include "platform.h"
-#include "taler-merchant-httpd_private-get-pending-webhooks.h"
-
-/**
- * Add pending webhook details to our JSON array.
- *
- * @param cls a `json_t *` JSON array to build
- * @param webhook_serial reference of the webhook
- * @param next_attempt when will this hook be attempted next
- */
-static void
-add_pending_webhook (void *cls,
- uint64_t *webhook_serial,
- struct GNUNET_TIME_Absolute *next_attempt)
-{
- json_t *pa = cls;
-
- GNUNET_assert (0 ==
- json_array_append_new (
- pa,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_uint64 ("webhook_serial",
- webhook_serial),
- GNUNET_JSON_pack_string ("next_attempt",
- next_attempt)
- )));
-}
-
-
-MHD_RESULT
-TMH_private_get_pending_webhooks (const struct TMH_RequestHandler *rh,
- struct MHD_Connection *connection,
- struct TMH_HandlerContext *hc)
-{
- json_t *pa;
- enum GNUNET_DB_QueryStatus qs;
-
- pa = json_array ();
- GNUNET_assert (NULL != pa);
- qs = TMH_db->lookup_pending_webhooks (TMH_db->cls,
- &add_pending_webhook,
- pa);
- if (0 > qs)
- {
- GNUNET_break (0);
- json_decref (pa);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- NULL);
- }
- return TALER_MHD_REPLY_JSON_PACK (connection,
- MHD_HTTP_OK,
- GNUNET_JSON_pack_array_steal ("webhooks",
- pa));
-}
-
-
-/* end of taler-merchant-httpd_private-get-pending-webhooks.c */
diff --git a/src/backend/taler-merchant-webhook.c b/src/backend/taler-merchant-webhook.c
index 6d68c303..17e56bb2 100644
--- a/src/backend/taler-merchant-webhook.c
+++ b/src/backend/taler-merchant-webhook.c
@@ -125,7 +125,7 @@ shutdown_task (void *cls)
/**
- * This function is used by the function pending_webhooks_cb. According to the response code,
+ * This function is used by the function `pending_webhooks_cb`. According to the response code,
* we delete or update the webhook.
*
* @param cls closure
@@ -144,7 +144,6 @@ handle_webhook_response (void *cls,
(void) body;
(void) body_size;
- job = NULL;
if (2 == response_code / 100) /* any 2xx http status code is OK! */
{
@@ -161,6 +160,9 @@ handle_webhook_response (void *cls,
case MHD_HTTP_INTERNAL_SERVER_ERROR:
next_attempt = GNUNET_TIME_UNIT_MINUTES;
break;
+ case MHD_HTTP_FORBIDDEN:
+ next_attempt = GNUNET_TIME_UNIT_MINUTES;
+ break;
default:
next_attempt = GNUNET_TIME_UNIT_HOURS;
break;
@@ -305,6 +307,7 @@ static void
select_work (void *cls)
{
enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_TIME_Relative next_attempt;
(void) cls;
task = NULL;
@@ -322,28 +325,35 @@ select_work (void *cls)
NULL);
switch (qs)
{
- case 0:
+ case GNUNET_BD_STATUS_HARD_ERROR:
+ case GNUNET_BD_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:
qs = db_plugin->lookup_future_webhook (db_plugin->cls,
&future_webhook_cb,
NULL);
switch (qs) {
- case 0:
- return;
- case -1:
+ case GNUNET_BD_STATUS_HARD_ERROR:
+ case GNUNET_BD_STATUS_SOFT_ERROR:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed!\n");
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
- return;
+ return;
+ case GNUNET_DB_STATUS_ONE_RESULT:
+ return;
+ case GNUNET_DB_STATUS_NO_RESULT:
+ /* wait 5 min */
+ struct GNUNET_TIME_Relative rel = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5);
+ task = GNUNET_SCHEDULER_add_delayed (rel,
+ &select_work,
+ NULL);
+ return;
}
- return;
- case -1 / -2:
- // shutdown.
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed!\n");
- global_ret = EXIT_FAILURE;
- GNUNET_SCHEDULER_shutdown ();
- return;
default:
return; // wait for completion, then select more work.
}
@@ -404,8 +414,7 @@ run (void *cls,
/**
- * The main function of the taler-exchange-transfer.
- *
+ * The main function of the taler-merchant-webhook
* @param argc number of arguments from the command line
* @param argv command line arguments
* @return 0 ok, 1 on error
diff --git a/src/backend/taler-merchant-webhook.h b/src/backend/taler-merchant-webhook.h
new file mode 100644
index 00000000..bfb732f5
--- /dev/null
+++ b/src/backend/taler-merchant-webhook.h
@@ -0,0 +1,39 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file taler-merchant-webhook.h
+ * @brief logic to preload and serve static files
+ * @author Priscilla HUANG
+ */
+#ifndef TALER_MERCHANT_WEBHOOK_H
+#define TALER_MERCHANT_WEBHOOK_H
+
+#include <microhttpd.h>
+#include "taler-merchant-httpd.h"
+
+/**
+ * The main function of the taler-merchant-webhook
+ * @param argc number of arguments from the command line
+ * @param argv command line arguments
+ * @return 0 ok, 1 on error
+ */
+int
+main (int argc,
+ char *const *argv);
+
+
+#endif