paivana

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

commit f0e8ebb410c77699a531282ba7100868175a756f
parent 80e908cd4d88014129af0455a828a4d0977719f4
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat,  2 May 2026 23:18:24 +0200

update implementation to match latest spec

Diffstat:
Msrc/backend/paivana-httpd_daemon.c | 15+++++++++++++--
Msrc/backend/paivana-httpd_templates.c | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
Msrc/backend/paivana-httpd_templates.h | 14+++++++++++++-
3 files changed, 97 insertions(+), 7 deletions(-)

diff --git a/src/backend/paivana-httpd_daemon.c b/src/backend/paivana-httpd_daemon.c @@ -126,7 +126,7 @@ create_response (void *cls, (0 == strcmp (url, "/.well-known/paivana")) && (0 == strcasecmp (meth, - "POST")) ) + MHD_HTTP_METHOD_POST)) ) { rc->is_paivana = true; } @@ -144,6 +144,18 @@ create_response (void *cls, if (rc->do_forward) goto do_forward; + if ( (0 == strncmp (url, + "/.well-known/paivana/templates/", + strlen ("/.well-known/paivana/templates/"))) && + (0 == strcasecmp (meth, + MHD_HTTP_METHOD_GET)) ) + { + const char *id = &url[strlen ("/.well-known/paivana/templates/")]; + + return PAIVANA_HTTPD_return_template (rc->connection, + id); + } + if (! PAIVANA_HTTPD_get_base_url (con, &buf)) { @@ -157,7 +169,6 @@ create_response (void *cls, GNUNET_buffer_write_str (&buf, url); website = GNUNET_buffer_reap_str (&buf); - cookie = MHD_lookup_connection_value (con, MHD_COOKIE_KIND, "Paivana-Cookie"); diff --git a/src/backend/paivana-httpd_templates.c b/src/backend/paivana-httpd_templates.c @@ -30,6 +30,7 @@ #include <gnunet/gnunet_curl_lib.h> #include "paivana-httpd.h" #include "paivana-httpd_daemon.h" +#include "paivana-httpd_helper.h" #include "paivana-httpd_templates.h" #include <taler/taler_mhd_lib.h> #include <taler/taler_templating_lib.h> @@ -308,7 +309,7 @@ load_paywall (struct MHD_Connection *conn, GNUNET_break (MHD_YES == MHD_add_response_header (reply, MHD_HTTP_HEADER_CACHE_CONTROL, - "public, max-age=60")); + "public, max-age=300")); { char *uri; @@ -528,11 +529,48 @@ PAIVANA_HTTPD_search_templates (struct MHD_Connection *connection, 0, NULL, 0)) { + struct MHD_Response *redirect; enum MHD_Result ret; - - ret = load_paywall (connection, - t); + struct GNUNET_Buffer buf = { 0 }; + char *enc = NULL; + char *url; + + redirect = MHD_create_response_from_buffer_static (0, + NULL); + if (! PAIVANA_HTTPD_get_base_url (connection, + &buf)) + { + GNUNET_break (0); + return TALER_MHD_reply_with_error ( + connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_HTTP_HEADERS_MALFORMED, + "Host or X-Forwarded-Host required"); + } + GNUNET_STRINGS_base64url_encode (website, + strlen (website), + &enc); + GNUNET_buffer_write_str (&buf, + "/.well-known/paivana/templates/"); + GNUNET_buffer_write_str (&buf, + t->template_id); + GNUNET_buffer_write_str (&buf, + "#"); + GNUNET_buffer_write_str (&buf, + enc); + GNUNET_free (enc); + url = GNUNET_buffer_reap_str (&buf); + GNUNET_break (MHD_YES == + MHD_add_response_header (redirect, + MHD_HTTP_HEADER_LOCATION, + url)); + GNUNET_free (url); + ret = MHD_queue_response (connection, + MHD_HTTP_FOUND, + redirect); + MHD_destroy_response (redirect); return (MHD_YES == ret) ? GNUNET_OK : GNUNET_NO; + } GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Request for %s did not match template %s\n", @@ -544,6 +582,35 @@ PAIVANA_HTTPD_search_templates (struct MHD_Connection *connection, /** + * Return the paywall page for the given @a template. + * + * @param connection request to search paywall response for + * @param id template to return paywall template for + * @return MHD status code + */ +enum MHD_Result +PAIVANA_HTTPD_return_template (struct MHD_Connection *connection, + const char *template) +{ + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Searching template `%s'\n", + template); + for (struct Template *t = t_head; NULL != t; t = t->next) + { + if (0 == strcmp (template, + t->template_id)) + return load_paywall (connection, + t); + } + GNUNET_break_op (0); + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + TALER_EC_PAIVANA_TEMPLATE_UNKNOWN, + template); +} + + +/** * Unload all of the template state. */ void diff --git a/src/backend/paivana-httpd_templates.h b/src/backend/paivana-httpd_templates.h @@ -40,7 +40,7 @@ PAIVANA_HTTPD_load_templates (void); /** - * Return the paywall page for the given @a website. + * Redirect to the paywall page for the given @a website. * * @param connection request to search paywall response for * @param website site to look for paywall templates for @@ -54,6 +54,18 @@ PAIVANA_HTTPD_search_templates (struct MHD_Connection *connection, /** + * Return the paywall page for the given @a template. + * + * @param connection request to search paywall response for + * @param id template to return paywall template for + * @return MHD status code + */ +enum MHD_Result +PAIVANA_HTTPD_return_template (struct MHD_Connection *connection, + const char *template); + + +/** * Unload all of the template state. */ void