paivana

HTTP paywall reverse proxy
Log | Files | Refs | README | LICENSE

commit 5cf3f7570730f25ea4c1c26f15087e59ff1dbac1
parent 241a5e964502180add6c2e5bbb18eb4e61bb4238
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon, 20 Apr 2026 20:08:05 +0200

complete template loading logic

Diffstat:
Mcontrib/Makefile.am | 4++--
Rcontrib/paywall.html -> contrib/paywall.en.must | 0
Msrc/backend/Makefile.am | 1+
Msrc/backend/paivana-httpd.c | 10++++++++++
Msrc/backend/paivana-httpd_templates.c | 80++++++++++++++++++++++++++++++++++++++-----------------------------------------
5 files changed, 51 insertions(+), 44 deletions(-)

diff --git a/contrib/Makefile.am b/contrib/Makefile.am @@ -1,7 +1,7 @@ SUBDIRS = . -paywallpkgdatadir = $(datadir)/paivana/ +paywallpkgdatadir = $(datadir)/paivana/templates/ paywallpkgdata_DATA = \ - paywall.html + paywall.en.must EXTRA_DIST = $(paywallpkgdata_DATA) diff --git a/contrib/paywall.html b/contrib/paywall.en.must diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am @@ -21,6 +21,7 @@ paivana_httpd_SOURCES = \ paivana_httpd_LDADD = \ $(LIBGCRYPT_LIBS) \ -ltalermerchant \ + -ltalertemplating \ -ltalermhd \ -ltalerutil \ -lgnunetjson \ diff --git a/src/backend/paivana-httpd.c b/src/backend/paivana-httpd.c @@ -31,6 +31,7 @@ #include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_curl_lib.h> #include <taler/taler_mhd_lib.h> +#include <taler/taler_templating_lib.h> #include "paivana-httpd.h" #include "paivana-httpd_cookie.h" #include "paivana-httpd_daemon.h" @@ -84,6 +85,7 @@ do_shutdown (void *cls) PAIVANA_HTTPD_reverse_shutdown (); TALER_MHD_daemons_destroy (); PAIVANA_HTTPD_unload_templates (); + TALER_TEMPLATING_done (); GNUNET_free (PH_target_server_base_url); GNUNET_free (PH_merchant_base_url); GNUNET_free (PH_base_url); @@ -124,8 +126,16 @@ run (void *cls, (void) cfgfile; PH_cfg = c; + if (GNUNET_OK != + TALER_TEMPLATING_init (PAIVANA_project_data ())) + { + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } if (! PAIVANA_HTTPD_reverse_init ()) { + GNUNET_break (0); GNUNET_SCHEDULER_shutdown (); return; } diff --git a/src/backend/paivana-httpd_templates.c b/src/backend/paivana-httpd_templates.c @@ -31,6 +31,7 @@ #include "paivana-httpd_daemon.h" #include "paivana-httpd_templates.h" #include <taler/taler_mhd_lib.h> +#include <taler/taler_templating_lib.h> #include "paivana_pd.h" #include <regex.h> @@ -110,52 +111,47 @@ static struct TALER_MERCHANT_GetPrivateTemplatesHandle *gpt; static struct MHD_Response * load_paywall (const char *template_id) { - struct MHD_Response *paywall; - char *tpath; - char *fn; - int fd; - struct stat sb; - - // FIXME: use templating logic to modify HTML - // based on template_id, backend base URL and - // possibly other values! - tpath = GNUNET_OS_installation_get_path (PAIVANA_project_data (), - GNUNET_OS_IPK_DATADIR); - GNUNET_asprintf (&fn, - "%s/paywall.html", - tpath); - GNUNET_free (tpath); - fd = open (fn, - O_RDONLY); - if (-1 == fd) + void *result; + size_t result_size; + { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, - "open", - fn); - GNUNET_free (fn); - return false; + json_t *data; + + data = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("template_id", + template_id), + GNUNET_JSON_pack_string ("merchant_backend", + PH_merchant_base_url)); + if (0 != + TALER_TEMPLATING_fill ("paywall", + data, + &result, + &result_size)) + { + GNUNET_break (0); + json_decref (data); + return NULL; + } + json_decref (data); } - if (0 != - fstat (fd, - &sb)) + { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, - "stat", - fn); - GNUNET_free (fn); - GNUNET_break (0 == close (fd)); - return NULL; + struct MHD_Response *paywall; + + paywall = MHD_create_response_from_buffer_copy (result_size, + result); + if (NULL == paywall) + { + GNUNET_free (result); + return NULL; + } + GNUNET_free (result); + GNUNET_break (MHD_YES == + MHD_add_response_header (paywall, + MHD_HTTP_HEADER_CONTENT_TYPE, + "text/html")); + return paywall; } - GNUNET_free (fn); - paywall = MHD_create_response_from_fd (sb.st_size, - fd); - if (NULL == paywall) - return NULL; - GNUNET_break (MHD_YES == - MHD_add_response_header (paywall, - MHD_HTTP_HEADER_CONTENT_TYPE, - "text/html")); - return paywall; }