From 13fc3e0610ca35bceb4d06372368847088a8014a Mon Sep 17 00:00:00 2001 From: priscilla Date: Thu, 26 Jan 2023 10:25:28 -0500 Subject: update pending webhook --- src/backend/Makefile.am | 25 ++++- src/backend/taler-merchant-webhook | 210 +++++++++++++++++++++++++++++++++++ src/backend/taler-merchant-webhook.c | 66 +++++------ src/backend/taler-merchant-webhook.h | 39 ------- src/backend/test.conf | 172 ++++++++++++++++++++++++++++ 5 files changed, 440 insertions(+), 72 deletions(-) create mode 100755 src/backend/taler-merchant-webhook delete mode 100644 src/backend/taler-merchant-webhook.h create mode 100644 src/backend/test.conf diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am index 1fb445b3..99548ef8 100644 --- a/src/backend/Makefile.am +++ b/src/backend/Makefile.am @@ -16,7 +16,8 @@ EXTRA_DIST = \ $(pkgcfg_DATA) bin_PROGRAMS = \ - taler-merchant-httpd + taler-merchant-httpd \ + taler-merchant-webhook taler_merchant_httpd_SOURCES = \ taler-merchant-httpd.c taler-merchant-httpd.h \ @@ -129,7 +130,8 @@ taler_merchant_httpd_SOURCES = \ taler-merchant-httpd_spa.c \ taler-merchant-httpd_spa.h \ taler-merchant-httpd_statics.c \ - taler-merchant-httpd_statics.h + taler-merchant-httpd_statics.h + taler_merchant_httpd_LDADD = \ $(top_builddir)/src/backenddb/libtalermerchantdb.la \ -ltalerexchange \ @@ -149,3 +151,22 @@ taler_merchant_httpd_LDADD = \ taler_merchant_httpd_CFLAGS = \ @QR_CFLAGS@ \ $(AM_CFLAGS) + + +taler_merchant_webhook_SOURCES = \ + taler-merchant-webhook.c +taler_merchant_webhook_LDADD = \ + $(top_builddir)/src/backenddb/libtalermerchantdb.la \ + -ltalertemplating \ + -ltalermhd \ + -ltalerjson \ + -ltalerutil \ + -ltalerpq \ + -ljansson \ + -lgnunetcurl \ + -lgnunetjson \ + -lgnunetutil \ + -lcurl \ + $(XLIB) +taler_merchant_webhook_CFLAGS = \ + $(AM_CFLAGS) diff --git a/src/backend/taler-merchant-webhook b/src/backend/taler-merchant-webhook new file mode 100755 index 00000000..880c8c6d --- /dev/null +++ b/src/backend/taler-merchant-webhook @@ -0,0 +1,210 @@ +#! /bin/bash + +# taler-merchant-webhook - temporary wrapper script for .libs/taler-merchant-webhook +# Generated by libtool (GNU libtool) 2.4.6 Debian-2.4.6-15 +# +# The taler-merchant-webhook program cannot be directly executed until all the libtool +# libraries that it depends on are installed. +# +# This wrapper script should never be moved out of the build directory. +# If it is, it will not operate correctly. + +# Sed substitution that helps us do robust quoting. It backslashifies +# metacharacters that are still active within double-quoted strings. +sed_quote_subst='s|\([`"$\\]\)|\\\1|g' + +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +# The HP-UX ksh and POSIX shell print the target directory to stdout +# if CDPATH is set. +(unset CDPATH) >/dev/null 2>&1 && unset CDPATH + +relink_command="" + +# This environment variable determines our operation mode. +if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then + # install mode needs the following variables: + generated_by_libtool_version='2.4.6' + notinst_deplibs=' ../../src/backenddb/libtalermerchantdb.la' +else + # When we are sourced in execute mode, $file and $ECHO are already set. + if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then + file="$0" + +# A function that is used when there is no print builtin or printf. +func_fallback_echo () +{ + eval 'cat <<_LTECHO_EOF +$1 +_LTECHO_EOF' +} + ECHO="printf %s\\n" + fi + +# Very basic option parsing. These options are (a) specific to +# the libtool wrapper, (b) are identical between the wrapper +# /script/ and the wrapper /executable/ that is used only on +# windows platforms, and (c) all begin with the string --lt- +# (application programs are unlikely to have options that match +# this pattern). +# +# There are only two supported options: --lt-debug and +# --lt-dump-script. There is, deliberately, no --lt-help. +# +# The first argument to this parsing function should be the +# script's ../../libtool value, followed by no. +lt_option_debug= +func_parse_lt_options () +{ + lt_script_arg0=$0 + shift + for lt_opt + do + case "$lt_opt" in + --lt-debug) lt_option_debug=1 ;; + --lt-dump-script) + lt_dump_D=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%/[^/]*$%%'` + test "X$lt_dump_D" = "X$lt_script_arg0" && lt_dump_D=. + lt_dump_F=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%^.*/%%'` + cat "$lt_dump_D/$lt_dump_F" + exit 0 + ;; + --lt-*) + $ECHO "Unrecognized --lt- option: '$lt_opt'" 1>&2 + exit 1 + ;; + esac + done + + # Print the debug banner immediately: + if test -n "$lt_option_debug"; then + echo "taler-merchant-webhook:taler-merchant-webhook:$LINENO: libtool wrapper (GNU libtool) 2.4.6 Debian-2.4.6-15" 1>&2 + fi +} + +# Used when --lt-debug. Prints its arguments to stdout +# (redirection is the responsibility of the caller) +func_lt_dump_args () +{ + lt_dump_args_N=1; + for lt_arg + do + $ECHO "taler-merchant-webhook:taler-merchant-webhook:$LINENO: newargv[$lt_dump_args_N]: $lt_arg" + lt_dump_args_N=`expr $lt_dump_args_N + 1` + done +} + +# Core function for launching the target application +func_exec_program_core () +{ + + if test -n "$lt_option_debug"; then + $ECHO "taler-merchant-webhook:taler-merchant-webhook:$LINENO: newargv[0]: $progdir/$program" 1>&2 + func_lt_dump_args ${1+"$@"} 1>&2 + fi + exec "$progdir/$program" ${1+"$@"} + + $ECHO "$0: cannot exec $program $*" 1>&2 + exit 1 +} + +# A function to encapsulate launching the target application +# Strips options in the --lt-* namespace from $@ and +# launches target application with the remaining arguments. +func_exec_program () +{ + case " $* " in + *\ --lt-*) + for lt_wr_arg + do + case $lt_wr_arg in + --lt-*) ;; + *) set x "$@" "$lt_wr_arg"; shift;; + esac + shift + done ;; + esac + func_exec_program_core ${1+"$@"} +} + + # Parse options + func_parse_lt_options "$0" ${1+"$@"} + + # Find the directory that this script lives in. + thisdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'` + test "x$thisdir" = "x$file" && thisdir=. + + # Follow symbolic links until we get to the real thisdir. + file=`ls -ld "$file" | /usr/bin/sed -n 's/.*-> //p'` + while test -n "$file"; do + destdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'` + + # If there was a directory component, then change thisdir. + if test "x$destdir" != "x$file"; then + case "$destdir" in + [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;; + *) thisdir="$thisdir/$destdir" ;; + esac + fi + + file=`$ECHO "$file" | /usr/bin/sed 's%^.*/%%'` + file=`ls -ld "$thisdir/$file" | /usr/bin/sed -n 's/.*-> //p'` + done + + # Usually 'no', except on cygwin/mingw when embedded into + # the cwrapper. + WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no + if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then + # special case for '.' + if test "$thisdir" = "."; then + thisdir=`pwd` + fi + # remove .libs from thisdir + case "$thisdir" in + *[\\/].libs ) thisdir=`$ECHO "$thisdir" | /usr/bin/sed 's%[\\/][^\\/]*$%%'` ;; + .libs ) thisdir=. ;; + esac + fi + + # Try to get the absolute directory name. + absdir=`cd "$thisdir" && pwd` + test -n "$absdir" && thisdir="$absdir" + + program='taler-merchant-webhook' + progdir="$thisdir/.libs" + + + if test -f "$progdir/$program"; then + # Add our own library path to LD_LIBRARY_PATH + LD_LIBRARY_PATH="/home/priscilla/merchant/src/backenddb/.libs:/home/priscilla/install/lib:$LD_LIBRARY_PATH" + + # Some systems cannot cope with colon-terminated LD_LIBRARY_PATH + # The second colon is a workaround for a bug in BeOS R4 sed + LD_LIBRARY_PATH=`$ECHO "$LD_LIBRARY_PATH" | /usr/bin/sed 's/::*$//'` + + export LD_LIBRARY_PATH + + if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then + # Run the actual program with our arguments. + func_exec_program ${1+"$@"} + fi + else + # The program doesn't exist. + $ECHO "$0: error: '$progdir/$program' does not exist" 1>&2 + $ECHO "This script is just a wrapper for $program." 1>&2 + $ECHO "See the libtool documentation for more information." 1>&2 + exit 1 + fi +fi 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 #include #include -#include #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); diff --git a/src/backend/taler-merchant-webhook.h b/src/backend/taler-merchant-webhook.h deleted file mode 100644 index bfb732f5..00000000 --- a/src/backend/taler-merchant-webhook.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - 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 -*/ - -/** - * @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 -#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 diff --git a/src/backend/test.conf b/src/backend/test.conf new file mode 100644 index 00000000..502d807a --- /dev/null +++ b/src/backend/test.conf @@ -0,0 +1,172 @@ +# This file is in the public domain. +# +[PATHS] +# Persistent data storage for the testcase +TALER_TEST_HOME = test_merchant_api_home/ +TALER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/${USER:-}/taler-system-runtime/ + +# Persistent data storage +TALER_DATA_HOME = $TALER_HOME/.local/share/taler/ + +# Configuration files +TALER_CONFIG_HOME = $TALER_HOME/.config/taler/ + +# Cached data, no big deal if lost +TALER_CACHE_HOME = $TALER_HOME/.cache/taler/ + +[taler] +# What currency do we use? +CURRENCY = EUR +CURRENCY_ROUND_UNIT = EUR:0.01 + +[taler-helper-crypto-rsa] +# Reduce from 1 year to speed up test +LOOKAHEAD_SIGN = 24 days + +[taler-helper-crypto-eddsa] +# Reduce from 1 year to speed up test +LOOKAHEAD_SIGN = 24 days +# Reduce from 12 weeks to ensure we have multiple +DURATION = 14 days + +[bank] +HTTP_PORT = 8082 + +########################################## +# Configuration for the merchant backend # +########################################## + +[merchant] + +# Which port do we run the backend on? (HTTP server) +PORT = 8080 + +# Which plugin (backend) do we use for the DB. +DB = postgres + +# This specifies which database the postgres backend uses. +[merchantdb-postgres] +CONFIG = postgres:///talercheck + +# Sections starting with "merchant-exchange-" specify trusted exchanges +# (by the merchant) +[merchant-exchange-test] +MASTER_KEY = T1VVFQZZARQ1CMF4BN58EE7SKTW5AV2BS18S87ZEGYS4S29J6DNG +EXCHANGE_BASE_URL = http://localhost:8081/ +CURRENCY = EUR + + +####################################################### +# Configuration for the auditor for the testcase +####################################################### +[auditor] +BASE_URL = http://the.auditor/ + + +####################################################### +# Configuration for ??? Is this used? +####################################################### + +# Auditors must be in sections "auditor-", the rest of the section +# name could be anything. +[auditor-ezb] +# Informal name of the auditor. Just for the user. +NAME = European Central Bank + +# URL of the auditor (especially for in the future, when the +# auditor offers an automated issue reporting system). +# Not really used today. +URL = http://taler.ezb.eu/ + +# This is the important bit: the signing key of the auditor. +PUBLIC_KEY = 9QXF7XY7E9VPV47B5Z806NDFSX2VJ79SVHHD29QEQ3BG31ANHZ60 + +# Which currency is this auditor trusted for? +CURRENCY = EUR + + +################################################### +# Configuration for the exchange for the testcase # +################################################### + +[exchange] +# How to access our database +DB = postgres + +# HTTP port the exchange listens to +PORT = 8081 + +# Our public key +MASTER_PUBLIC_KEY = T1VVFQZZARQ1CMF4BN58EE7SKTW5AV2BS18S87ZEGYS4S29J6DNG + +# Base URL of the exchange. +BASE_URL = "http://localhost:8081/" + + +[exchangedb-postgres] +CONFIG = "postgres:///talercheck" + + +[auditordb-postgres] +CONFIG = postgres:///talercheck + + +# Account of the EXCHANGE +[exchange-account-exchange] +# What is the exchange's bank account (with the "Taler Bank" demo system)? +PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2" +ENABLE_DEBIT = YES +ENABLE_CREDIT = YES + +[exchange-accountcredentials-exchange] +WIRE_GATEWAY_URL = "http://localhost:8082/2/" +WIRE_GATEWAY_AUTH_METHOD = NONE + + +[coin_eur_ct_1] +value = EUR:0.01 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.00 +fee_deposit = EUR:0.00 +fee_refresh = EUR:0.01 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = CS + +[coin_eur_ct_10] +value = EUR:0.10 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = CS + +[coin_eur_1] +value = EUR:1 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = CS + +[coin_eur_5] +value = EUR:5 +duration_withdraw = 7 days +duration_spend = 2 years +duration_legal = 3 years +fee_withdraw = EUR:0.01 +fee_deposit = EUR:0.01 +fee_refresh = EUR:0.03 +fee_refund = EUR:0.01 +rsa_keysize = 1024 +CIPHER = CS -- cgit v1.2.3