commit 18904942205beaa1d2fbe8df68e5de918e18ec8f
parent 6ed4119af38b5f9139358b22fc5e26e58a67a325
Author: Christian Grothoff <christian@grothoff.org>
Date: Mon, 24 Jun 2024 13:17:44 +0200
add kyc-upload logic to demultiplexer
Diffstat:
4 files changed, 141 insertions(+), 0 deletions(-)
diff --git a/src/exchange/Makefile.am b/src/exchange/Makefile.am
@@ -147,6 +147,7 @@ taler_exchange_httpd_SOURCES = \
taler-exchange-httpd_kyc-check.c taler-exchange-httpd_kyc-check.h \
taler-exchange-httpd_kyc-info.c taler-exchange-httpd_kyc-info.h \
taler-exchange-httpd_kyc-proof.c taler-exchange-httpd_kyc-proof.h \
+ taler-exchange-httpd_kyc-upload.c taler-exchange-httpd_kyc-upload.h \
taler-exchange-httpd_kyc-wallet.c taler-exchange-httpd_kyc-wallet.h \
taler-exchange-httpd_kyc-webhook.c taler-exchange-httpd_kyc-webhook.h \
taler-exchange-httpd_link.c taler-exchange-httpd_link.h \
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c
@@ -48,6 +48,7 @@
#include "taler-exchange-httpd_keys.h"
#include "taler-exchange-httpd_kyc-check.h"
#include "taler-exchange-httpd_kyc-proof.h"
+#include "taler-exchange-httpd_kyc-upload.h"
#include "taler-exchange-httpd_kyc-wallet.h"
#include "taler-exchange-httpd_kyc-webhook.h"
#include "taler-exchange-httpd_link.h"
@@ -2058,6 +2059,34 @@ handle_mhd_request (void *cls,
return ret;
}
}
+ if (0 == strncmp (url,
+ "/kyc-upload/",
+ strlen ("/kyc-upload/")))
+ {
+ if (0 != strcasecmp (method,
+ MHD_HTTP_METHOD_POST))
+ {
+ MHD_RESULT ret;
+ struct MHD_Response *reply;
+
+ reply = TALER_MHD_make_error (TALER_EC_GENERIC_METHOD_INVALID,
+ method);
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (reply,
+ MHD_HTTP_HEADER_ALLOW,
+ MHD_HTTP_METHOD_POST));
+ ret = MHD_queue_response (connection,
+ MHD_HTTP_METHOD_NOT_ALLOWED,
+ reply);
+ MHD_destroy_response (reply);
+ return ret;
+ }
+ return TEH_handler_kyc_upload (rc,
+ url + strlen ("/kyc-upload/"),
+ upload_data_size,
+ upload_data);
+ }
+
/* No handler matches, generate not found */
{
diff --git a/src/exchange/taler-exchange-httpd_kyc-upload.c b/src/exchange/taler-exchange-httpd_kyc-upload.c
@@ -0,0 +1,61 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero 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 Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_kyc-upload.c
+ * @brief Handle /kyc-upload/$ID request
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler-exchange-httpd_kyc-upload.h"
+
+
+/**
+ * Context used for processing the KYC upload req
+ */
+struct UploadContext
+{
+ struct MHD_PostProcessor *pp;
+};
+
+
+/**
+ * Function called to clean up upload context.
+ */
+static void
+upload_cleaner (struct TEH_RequestContext *rc)
+{
+ struct UploadContext *uc = rc->rh_ctx;
+
+ GNUNET_free (uc);
+}
+
+
+MHD_RESULT
+TEH_handler_kyc_upload (struct TEH_RequestContext *rc,
+ const char *id,
+ size_t *upload_data_size,
+ const char *upload_data)
+{
+ struct UploadContext *uc = rc->rh_ctx;
+
+ if (NULL == uc)
+ {
+ uc = GNUNET_new (struct UploadContext);
+ rc->rh_ctx = uc;
+ rc->rh_cleaner = &upload_cleaner;
+ }
+ return MHD_NO;
+}
diff --git a/src/exchange/taler-exchange-httpd_kyc-upload.h b/src/exchange/taler-exchange-httpd_kyc-upload.h
@@ -0,0 +1,50 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2019, 2021 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero 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 Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_kyc-upload.h
+ * @brief Handle /kyc-upload/$ID requests
+ * @author Christian Grothoff
+ */
+#ifndef TALER_EXCHANGE_HTTPD_KYC_UPLOAD_H
+#define TALER_EXCHANGE_HTTPD_KYC_UPLOAD_H
+
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include "taler_mhd_lib.h"
+#include "taler-exchange-httpd_responses.h"
+
+
+/**
+ * Handle a "/kyc-upload/$ID" request.
+ *
+ * @param rc request context
+ * @param id the ID from the URL (without "/")
+ * @param[in,out] upload_data_size length of @a upload_data,
+ * to be update to reflect number of bytes remaining
+ * @param upload_data upload data of the POST, if any
+ * @param args array of additional options (must be empty for this function)
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_handler_kyc_upload (struct TEH_RequestContext *rc,
+ const char *id,
+ size_t *upload_data_size,
+ const char *upload_data);
+
+
+#endif