commit b97d08202347cbf5e3ac33e24d6f00f8ecf8c2ad
parent 29284d082b271748060a3ac471ee279204fd288e
Author: Christian Grothoff <christian@grothoff.org>
Date: Wed, 26 Nov 2025 23:28:04 +0100
get code to compile
Diffstat:
4 files changed, 77 insertions(+), 37 deletions(-)
diff --git a/configure.ac b/configure.ac
@@ -333,7 +333,9 @@ AM_CONDITIONAL([ENABLE_DOC], [test "x$enable_doc" = "xyes"])
AC_CONFIG_FILES([Makefile
+ doc/Makefile
src/Makefile
+ src/include/Makefile
src/backend/Makefile
])
AC_OUTPUT
diff --git a/src/backend/Makefile.am b/src/backend/Makefile.am
@@ -10,7 +10,8 @@ bin_PROGRAMS = \
paivana-httpd
paivana_httpd_SOURCES = \
- paivana-httpd.c
+ paivana-httpd.c \
+ paivana_pd.c paivana_pd.h
paivana_httpd_LDADD = \
$(LIBGCRYPT_LIBS) \
-lmicrohttpd \
diff --git a/src/backend/paivana-httpd.c b/src/backend/paivana-httpd.c
@@ -27,12 +27,13 @@
* @brief HTTP proxy that acts as a GNU Taler paywall
*/
#include "platform.h"
-#include <microhttpd2.h>
+#include <microhttpd.h>
#include <curl/curl.h>
#include <gnunet/gnunet_util_lib.h>
#include <microhttpd.h>
#include "paivana_pd.h"
+typedef enum MHD_Result MHD_RESULT;
#define PAIVANA_LOG_INFO(...) \
GNUNET_log (GNUNET_ERROR_TYPE_INFO, __VA_ARGS__)
@@ -177,11 +178,6 @@ struct HttpRequest
char *url;
/**
- * JSON we use to parse payloads (in both directions).
- */
- json_t *json;
-
- /**
* Handle to cURL
*/
CURL *curl;
@@ -408,7 +404,6 @@ static enum GNUNET_GenericReturnValue
create_mhd_response_from_hr (struct HttpRequest *hr)
{
long resp_code;
- json_error_t error;
if (NULL != hr->response)
{
@@ -424,12 +419,6 @@ create_mhd_response_from_hr (struct HttpRequest *hr)
"Creating MHD response with code %u\n",
(unsigned int) resp_code);
hr->response_code = resp_code;
- /* Note, will be NULL if io_buf does not represent
- * a JSON value. */
- hr->json = json_loadb (hr->io_buf,
- hr->io_len,
- JSON_DECODE_ANY,
- &error);
if (GNUNET_YES == hr->suspended)
{
MHD_resume_connection (hr->con);
@@ -718,6 +707,56 @@ curl_download_prepare ()
/**
+ * "Filter" function that translates MHD request headers to
+ * cURL's.
+ *
+ * @param cls our `struct HttpRequest`
+ * @param kind value kind
+ * @param key field key
+ * @param value field value
+ * @return #MHD_YES to continue to iterate
+ */
+static MHD_RESULT
+con_val_iter (void *cls,
+ enum MHD_ValueKind kind,
+ const char *key,
+ const char *value)
+{
+ struct HttpRequest *hr = cls;
+ char *hdr;
+ char *new_value = NULL;
+
+ (void) kind;
+ if (0 == strcmp (MHD_HTTP_HEADER_HOST,
+ key))
+ {
+ /* We don't take the host header as given in the request.
+ * We'll instead put the proxied service's hostname in it*/
+ return MHD_YES;
+ }
+ if ((0 == strcmp (MHD_HTTP_HEADER_CONTENT_LENGTH,
+ key)))
+ {
+ PAIVANA_LOG_INFO (
+ "Do not set Content-Length for request\n");
+ return MHD_YES;
+ }
+ GNUNET_asprintf (&hdr,
+ "%s: %s",
+ key,
+ value);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding header `%s' to HTTP request\n",
+ hdr);
+ hr->headers = curl_slist_append (hr->headers,
+ hdr);
+ GNUNET_free (hdr);
+ GNUNET_free (new_value);
+ return MHD_YES;
+}
+
+
+/**
* Task that is run when we are ready to receive
* more data from curl.
*
@@ -1122,11 +1161,6 @@ create_response (void *cls,
}
GNUNET_assert (REQUEST_STATE_PROXY_DOWNLOAD_DONE == hr->state);
- if (0 != hack_response_code)
- {
- hr->response_code = hack_response_code;
- hack_response_code = 0; /* reset for next request */
- }
for (struct HttpResponseHeader *header = hr->header_head;
NULL != header;
@@ -1134,12 +1168,6 @@ create_response (void *cls,
{
const char *value = header->value;
- if ((NULL != modify_header_dl) &&
- (0 == strcmp (header->type,
- modify_header_dl)))
- {
- value = modify_value;
- }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Adding MHD response header %s->%s\n",
header->type,
@@ -1644,13 +1672,15 @@ parse_serving_mean (const struct GNUNET_CONFIGURATION_Handle *ccfg,
* and finally start MHD on that port.
*
* @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be NULL!)
* @param c configuration
- * @param service the initialized service
-*/
+ */
static void
run (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *c,
- struct GNUNET_SERVICE_Handle *service)
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *c)
{
uint16_t port = 0;
int fh = -1;
@@ -1658,7 +1688,8 @@ run (void *cls,
mode_t serve_unixmode = 0;
(void) cls;
- (void) service;
+ (void) args;
+ (void) cfgfile;
cfg = c;
if (0 != curl_global_init (CURL_GLOBAL_WIN32))
@@ -1742,12 +1773,18 @@ int
main (int argc,
char *const *argv)
{
- return GNUNET_PROGRAM_run_ (PAIVANA_project_data (),
- argc,
- argv,
- "paivana-httpd",
- &run,
- NULL);
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+
+ return GNUNET_PROGRAM_run (PAIVANA_project_data (),
+ argc,
+ argv,
+ "paivana-httpd",
+ "reverse proxy requesting Taler payment",
+ options,
+ &run,
+ NULL);
}
diff --git a/src/backend/paivana_pd.c b/src/backend/paivana_pd.c
@@ -29,7 +29,7 @@
* Default project data used for installation path detection
* for Twister.
*/
-static const struct GNUNET_OS_ProjectData twister_project_data = {
+static const struct GNUNET_OS_ProjectData paivana_project_data = {
.libname = "libpaivana",
.project_dirname = "paivana",
.binary_name = "paivana-httpd",