merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 0c1c731b698028c4a250dda84685307b7004bc56
parent 7ce5a97d50278b3cdddf205749df01f449c51348
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 15 Jun 2025 19:58:35 +0200

adjust to API changes needed for #10024

Diffstat:
Mconfigure.ac | 4++--
Msrc/backend/taler-merchant-httpd.c | 110+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
Msrc/testing/test_merchant_wirewatch.sh | 2+-
3 files changed, 71 insertions(+), 45 deletions(-)

diff --git a/configure.ac b/configure.ac @@ -321,12 +321,12 @@ AS_CASE([$with_exchange], CPPFLAGS="-I$with_exchange/include $CPPFLAGS $POSTGRESQL_CPPFLAGS"]) AC_CHECK_HEADERS([taler/taler_mhd_lib.h], - [AC_CHECK_LIB([talermhd], [TALER_MHD_arg_to_yna], libtalermhd=1)]) + [AC_CHECK_LIB([talermhd], [TALER_MHD_listen_bind], libtalermhd=1)]) AM_CONDITIONAL(HAVE_TALERMHD, test x$libtalermhd = x1) AS_IF([test $libtalermhd != 1], [AC_MSG_ERROR([[ *** -*** You need libtalermhd >= 0.14.7 (API v3) to build this program. +*** You need libtalermhd >= 1.1.0 (API v6) to build this program. *** This library is part of the GNU Taler exchange, available at *** https://taler.net *** ]])]) diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c @@ -169,9 +169,9 @@ unsigned int TMH_num_cspecs; struct TALER_CurrencySpecification *TMH_cspecs; /** - * The port we are running on + * True if we started any HTTP daemon. */ -static uint16_t port; +static bool have_daemons; /** * Should a "Connection: close" header be added to each HTTP response? @@ -395,8 +395,8 @@ TMH_instance_free_cb (void *cls, /** - * Shutdown task (magically invoked when the application is being - * quit) + * Shutdown task (invoked when the application is being + * terminated for any reason) * * @param cls NULL */ @@ -404,6 +404,7 @@ static void do_shutdown (void *cls) { (void) cls; + TALER_MHD_daemons_halt (); TMH_force_orders_resume (); TMH_force_ac_resume (); TMH_force_pc_resume (); @@ -411,13 +412,7 @@ do_shutdown (void *cls) TMH_force_gorc_resume (); TMH_force_wallet_get_order_resume (); TMH_force_wallet_refund_order_resume (); - { - struct MHD_Daemon *mhd; - - mhd = TALER_MHD_daemon_stop (); - if (NULL != mhd) - MHD_stop_daemon (mhd); - } + TALER_MHD_daemons_destroy (); if (NULL != instance_eh) { TMH_db->event_listen_cancel (instance_eh); @@ -2214,6 +2209,46 @@ TMH_reload_instances (const char *id) /** + * Callback invoked on every listen socket to start the + * respective MHD HTTP daemon. + * + * @param cls unused + * @param lsock the listen socket + */ +static void +start_daemon (void *cls, + int lsock) +{ + struct MHD_Daemon *mhd; + + (void) cls; + GNUNET_assert (-1 != lsock); + mhd = MHD_start_daemon (MHD_USE_SUSPEND_RESUME | MHD_USE_DUAL_STACK + | MHD_USE_AUTO, + 0 /* port */, + NULL, NULL, + &url_handler, NULL, + MHD_OPTION_LISTEN_SOCKET, lsock, + MHD_OPTION_URI_LOG_CALLBACK, + &full_url_track_callback, NULL, + MHD_OPTION_NOTIFY_COMPLETED, + &handle_mhd_completion_callback, NULL, + MHD_OPTION_CONNECTION_TIMEOUT, + (unsigned int) 10 /* 10s */, + MHD_OPTION_END); + if (NULL == mhd) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to launch HTTP service.\n"); + GNUNET_SCHEDULER_shutdown (); + return; + } + have_daemons = true; + TALER_MHD_daemon_start (mhd); +} + + +/** * Main function that will be run by the scheduler. * * @param cls closure @@ -2228,7 +2263,6 @@ run (void *cls, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config) { - int fh; enum TALER_MHD_GlobalOptions go; int elen; const char *tok; @@ -2402,42 +2436,34 @@ run (void *cls, load_instances (NULL, NULL, 0); - fh = TALER_MHD_bind (cfg, - "merchant", - &port); - if ( (0 == port) && - (-1 == fh) ) { - GNUNET_SCHEDULER_shutdown (); - return; - } + enum GNUNET_GenericReturnValue ret; - { - struct MHD_Daemon *mhd; - - mhd = MHD_start_daemon (MHD_USE_SUSPEND_RESUME | MHD_USE_DUAL_STACK - | MHD_USE_AUTO, - port, - NULL, NULL, - &url_handler, NULL, - MHD_OPTION_LISTEN_SOCKET, fh, - MHD_OPTION_URI_LOG_CALLBACK, - &full_url_track_callback, NULL, - MHD_OPTION_NOTIFY_COMPLETED, - &handle_mhd_completion_callback, NULL, - MHD_OPTION_CONNECTION_TIMEOUT, - (unsigned int) 10 /* 10s */, - MHD_OPTION_END); - if (NULL == mhd) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to launch HTTP service. Is the port in use?\n"); + ret = TALER_MHD_listen_bind (cfg, + "merchant", + &start_daemon, + NULL); + switch (ret) + { + case GNUNET_SYSERR: + global_ret = EXIT_NOTCONFIGURED; GNUNET_SCHEDULER_shutdown (); return; + case GNUNET_NO: + if (! have_daemons) + { + global_ret = EXIT_NOTCONFIGURED; + GNUNET_SCHEDULER_shutdown (); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Could not open all configured listen sockets\n"); + break; + case GNUNET_OK: + break; } - global_ret = EXIT_SUCCESS; - TALER_MHD_daemon_start (mhd); } + global_ret = EXIT_SUCCESS; } diff --git a/src/testing/test_merchant_wirewatch.sh b/src/testing/test_merchant_wirewatch.sh @@ -45,7 +45,7 @@ else ACCOUNT="exchange-account-1" WIRE_METHOD="iban" - BANK_FLAGS="-ns -d $WIRE_METHOD -u $ACCOUNT" + BANK_FLAGS="-n -d $WIRE_METHOD -u $ACCOUNT" BANK_URL="http://localhost:18082/" fi