gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-exchange] branch master updated: integrate /kyc-* handlers with d


From: gnunet
Subject: [taler-exchange] branch master updated: integrate /kyc-* handlers with dispatching logic
Date: Sun, 17 Oct 2021 19:02:28 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new adb93355 integrate /kyc-* handlers with dispatching logic
adb93355 is described below

commit adb93355282653438c9850948146cd5171d92aaf
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Oct 17 19:02:26 2021 +0200

    integrate /kyc-* handlers with dispatching logic
---
 src/exchange/taler-exchange-httpd.c            |  19 ++++
 src/exchange/taler-exchange-httpd_kyc-check.c  | 116 +++++++++++++++----------
 src/exchange/taler-exchange-httpd_kyc-check.h  |   8 +-
 src/exchange/taler-exchange-httpd_kyc-proof.c  |  25 ++++--
 src/exchange/taler-exchange-httpd_kyc-proof.h  |   9 +-
 src/exchange/taler-exchange-httpd_kyc-wallet.c |  15 ++--
 src/exchange/taler-exchange-httpd_kyc-wallet.h |  10 ++-
 7 files changed, 130 insertions(+), 72 deletions(-)

diff --git a/src/exchange/taler-exchange-httpd.c 
b/src/exchange/taler-exchange-httpd.c
index 194a2378..5491c3ef 100644
--- a/src/exchange/taler-exchange-httpd.c
+++ b/src/exchange/taler-exchange-httpd.c
@@ -835,6 +835,25 @@ handle_mhd_request (void *cls,
       .handler.get = &TEH_handler_deposits_get,
       .nargs = 4
     },
+    /* KYC endpoints */
+    {
+      .url = "kyc-check",
+      .method = MHD_HTTP_METHOD_GET,
+      .handler.get = &TEH_handler_kyc_check,
+      .nargs = 1
+    },
+    {
+      .url = "kyc-proof",
+      .method = MHD_HTTP_METHOD_GET,
+      .handler.get = &TEH_handler_kyc_proof,
+      .nargs = 1
+    },
+    {
+      .url = "kyc-wallet",
+      .method = MHD_HTTP_METHOD_POST,
+      .handler.post = &TEH_handler_kyc_wallet,
+      .nargs = 0
+    },
     /* POST management endpoints */
     {
       .url = "management",
diff --git a/src/exchange/taler-exchange-httpd_kyc-check.c 
b/src/exchange/taler-exchange-httpd_kyc-check.c
index 1e29ba2c..13f5810b 100644
--- a/src/exchange/taler-exchange-httpd_kyc-check.c
+++ b/src/exchange/taler-exchange-httpd_kyc-check.c
@@ -98,69 +98,89 @@ kyc_check (void *cls,
 
 MHD_RESULT
 TEH_handler_kyc_check (
-  struct MHD_Connection *connection,
-  uint64_t payment_target_uuid)
+  struct TEH_RequestContext *rc,
+  const char *const args[])
 {
-  struct KycCheckContext kcc = {
-    .payment_target_uuid = payment_target_uuid
-  };
+  unsigned long long payment_target_uuid;
   MHD_RESULT res;
   enum GNUNET_GenericReturnValue ret;
-  struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
+  char dummy;
+
+  if (1 !=
+      sscanf (args[0],
+              "%llu%c",
+              &payment_target_uuid,
+              &dummy))
+  {
+    GNUNET_break_op (0);
+    return TALER_MHD_reply_with_error (rc->connection,
+                                       MHD_HTTP_BAD_REQUEST,
+                                       TALER_EC_GENERIC_PARAMETER_MALFORMED,
+                                       "payment_target_uuid");
+  }
 
-  (void) GNUNET_TIME_round_abs (&now);
   if (TEH_KYC_NONE == TEH_kyc_config.mode)
     return TALER_MHD_reply_static (
-      connection,
+      rc->connection,
       MHD_HTTP_NO_CONTENT,
       NULL,
       NULL,
       0);
-  ret = TEH_DB_run_transaction (connection,
-                                "kyc check",
-                                &res,
-                                &kyc_check,
-                                &kcc);
-  if (GNUNET_SYSERR == ret)
-    return res;
-  if (! kcc.kyc.ok)
   {
-    GNUNET_assert (TEH_KYC_OAUTH2 == TEH_kyc_config.mode);
-    return TALER_MHD_REPLY_JSON_PACK (
-      connection,
-      MHD_HTTP_ACCEPTED,
-      GNUNET_JSON_pack_string ("kyc_url",
-                               TEH_kyc_config.details.oauth2.url));
-  }
-  {
-    struct TALER_ExchangePublicKeyP pub;
-    struct TALER_ExchangeSignatureP sig;
-    struct TALER_ExchangeAccountSetupSuccessPS as = {
-      .purpose.purpose = htonl 
(TALER_SIGNATURE_EXCHANGE_ACCOUNT_SETUP_SUCCESS),
-      .purpose.size = htonl (sizeof (as)),
-      .h_payto = kcc.h_payto,
-      .timestamp = GNUNET_TIME_absolute_hton (now)
+    struct GNUNET_TIME_Absolute now;
+    struct KycCheckContext kcc = {
+      .payment_target_uuid = payment_target_uuid
     };
-    enum TALER_ErrorCode ec;
 
-    if (TALER_EC_NONE !=
-        (ec = TEH_keys_exchange_sign (&as,
-                                      &pub,
-                                      &sig)))
+    now = GNUNET_TIME_absolute_get ();
+    (void) GNUNET_TIME_round_abs (&now);
+    ret = TEH_DB_run_transaction (rc->connection,
+                                  "kyc check",
+                                  &res,
+                                  &kyc_check,
+                                  &kcc);
+    if (GNUNET_SYSERR == ret)
+      return res;
+    if (! kcc.kyc.ok)
+    {
+      GNUNET_assert (TEH_KYC_OAUTH2 == TEH_kyc_config.mode);
+      return TALER_MHD_REPLY_JSON_PACK (
+        rc->connection,
+        MHD_HTTP_ACCEPTED,
+        GNUNET_JSON_pack_string ("kyc_url",
+                                 TEH_kyc_config.details.oauth2.url));
+    }
     {
-      return TALER_MHD_reply_with_ec (connection,
-                                      ec,
-                                      NULL);
+      struct TALER_ExchangePublicKeyP pub;
+      struct TALER_ExchangeSignatureP sig;
+      struct TALER_ExchangeAccountSetupSuccessPS as = {
+        .purpose.purpose = htonl (
+          TALER_SIGNATURE_EXCHANGE_ACCOUNT_SETUP_SUCCESS),
+        .purpose.size = htonl (sizeof (as)),
+        .h_payto = kcc.h_payto,
+        .timestamp = GNUNET_TIME_absolute_hton (now)
+      };
+      enum TALER_ErrorCode ec;
+
+      if (TALER_EC_NONE !=
+          (ec = TEH_keys_exchange_sign (&as,
+                                        &pub,
+                                        &sig)))
+      {
+        return TALER_MHD_reply_with_ec (rc->connection,
+                                        ec,
+                                        NULL);
+      }
+      return TALER_MHD_REPLY_JSON_PACK (
+        rc->connection,
+        MHD_HTTP_OK,
+        GNUNET_JSON_pack_data_auto ("exchange_sig",
+                                    &sig),
+        GNUNET_JSON_pack_data_auto ("exchange_pub",
+                                    &pub),
+        GNUNET_JSON_pack_time_abs ("now",
+                                   now));
     }
-    return TALER_MHD_REPLY_JSON_PACK (
-      connection,
-      MHD_HTTP_OK,
-      GNUNET_JSON_pack_data_auto ("exchange_sig",
-                                  &sig),
-      GNUNET_JSON_pack_data_auto ("exchange_pub",
-                                  &pub),
-      GNUNET_JSON_pack_time_abs ("now",
-                                 now));
   }
 }
 
diff --git a/src/exchange/taler-exchange-httpd_kyc-check.h 
b/src/exchange/taler-exchange-httpd_kyc-check.h
index 12f24488..8120a173 100644
--- a/src/exchange/taler-exchange-httpd_kyc-check.h
+++ b/src/exchange/taler-exchange-httpd_kyc-check.h
@@ -30,13 +30,13 @@
  * status of the given account and returns it.
  *
  * @param connection request to handle
- * @param payment_target_uuid which account are we to check
+ * @param args one argument with the payment_target_uuid
  * @return MHD result code
-  */
+ */
 MHD_RESULT
 TEH_handler_kyc_check (
-  struct MHD_Connection *connection,
-  uint64_t payment_target_uuid);
+  struct TEH_RequestContext *rc,
+  const char *const args[]);
 
 
 #endif
diff --git a/src/exchange/taler-exchange-httpd_kyc-proof.c 
b/src/exchange/taler-exchange-httpd_kyc-proof.c
index cb3f00dd..be7fc50f 100644
--- a/src/exchange/taler-exchange-httpd_kyc-proof.c
+++ b/src/exchange/taler-exchange-httpd_kyc-proof.c
@@ -67,21 +67,36 @@ proof_kyc_check (void *cls,
 
 MHD_RESULT
 TEH_handler_kyc_proof (
-  struct MHD_Connection *connection,
-  ...)
+  struct TEH_RequestContext *rc,
+  const char *const args[])
 {
   struct KycProofContext kpc;
   MHD_RESULT res;
   enum GNUNET_GenericReturnValue ret;
+  unsigned long long payment_target_uuid;
+  char dummy;
+
+  if (1 !=
+      sscanf (args[0],
+              "%llu%c",
+              &payment_target_uuid,
+              &dummy))
+  {
+    GNUNET_break_op (0);
+    return TALER_MHD_reply_with_error (rc->connection,
+                                       MHD_HTTP_BAD_REQUEST,
+                                       TALER_EC_GENERIC_PARAMETER_MALFORMED,
+                                       "payment_target_uuid");
+  }
 
   if (1 || (TEH_KYC_NONE == TEH_kyc_config.mode))
     return TALER_MHD_reply_static (
-      connection,
+      rc->connection,
       MHD_HTTP_NO_CONTENT,
       NULL,
       NULL,
       0);
-  ret = TEH_DB_run_transaction (connection,
+  ret = TEH_DB_run_transaction (rc->connection,
                                 "check proof kyc",
                                 &res,
                                 &proof_kyc_check,
@@ -89,7 +104,7 @@ TEH_handler_kyc_proof (
   if (GNUNET_SYSERR == ret)
     return res;
   return TALER_MHD_REPLY_JSON_PACK (
-    connection,
+    rc->connection,
     MHD_HTTP_OK,
     GNUNET_JSON_pack_uint64 ("42",
                              42));
diff --git a/src/exchange/taler-exchange-httpd_kyc-proof.h 
b/src/exchange/taler-exchange-httpd_kyc-proof.h
index 1958a004..9cf1963c 100644
--- a/src/exchange/taler-exchange-httpd_kyc-proof.h
+++ b/src/exchange/taler-exchange-httpd_kyc-proof.h
@@ -28,13 +28,14 @@
 /**
  * Handle a "/kyc-proof" request.
  *
- * @param connection request to handle
+ * @param rc request to handle
+ * @param args one argument with the payment_target_uuid
  * @return MHD result code
-  */
+ */
 MHD_RESULT
 TEH_handler_kyc_proof (
-  struct MHD_Connection *connection,
-  ...);
+  struct TEH_RequestContext *rc,
+  const char *const args[]);
 
 
 #endif
diff --git a/src/exchange/taler-exchange-httpd_kyc-wallet.c 
b/src/exchange/taler-exchange-httpd_kyc-wallet.c
index d5bbb851..dcab3dca 100644
--- a/src/exchange/taler-exchange-httpd_kyc-wallet.c
+++ b/src/exchange/taler-exchange-httpd_kyc-wallet.c
@@ -89,8 +89,9 @@ wallet_kyc_check (void *cls,
 
 MHD_RESULT
 TEH_handler_kyc_wallet (
-  struct MHD_Connection *connection,
-  const json_t *root)
+  struct TEH_RequestContext *rc,
+  const json_t *root,
+  const char *const args[])
 {
   struct TALER_ReserveSignatureP reserve_sig;
   struct KycRequestContext krc;
@@ -108,7 +109,7 @@ TEH_handler_kyc_wallet (
     .purpose = htonl (TALER_SIGNATURE_WALLET_ACCOUNT_SETUP)
   };
 
-  ret = TALER_MHD_parse_json_data (connection,
+  ret = TALER_MHD_parse_json_data (rc->connection,
                                    root,
                                    spec);
   if (GNUNET_SYSERR == ret)
@@ -124,19 +125,19 @@ TEH_handler_kyc_wallet (
   {
     GNUNET_break_op (0);
     return TALER_MHD_reply_with_error (
-      connection,
+      rc->connection,
       MHD_HTTP_FORBIDDEN,
       TALER_EC_EXCHANGE_KYC_WALLET_SIGNATURE_INVALID,
       NULL);
   }
   if (TEH_KYC_NONE == TEH_kyc_config.mode)
     return TALER_MHD_reply_static (
-      connection,
+      rc->connection,
       MHD_HTTP_NO_CONTENT,
       NULL,
       NULL,
       0);
-  ret = TEH_DB_run_transaction (connection,
+  ret = TEH_DB_run_transaction (rc->connection,
                                 "check wallet kyc",
                                 &res,
                                 &wallet_kyc_check,
@@ -144,7 +145,7 @@ TEH_handler_kyc_wallet (
   if (GNUNET_SYSERR == ret)
     return res;
   return TALER_MHD_REPLY_JSON_PACK (
-    connection,
+    rc->connection,
     MHD_HTTP_OK,
     GNUNET_JSON_pack_uint64 ("payment_target_uuid",
                              krc.kyc.payment_target_uuid));
diff --git a/src/exchange/taler-exchange-httpd_kyc-wallet.h 
b/src/exchange/taler-exchange-httpd_kyc-wallet.h
index 70ac5094..bd8ae1b0 100644
--- a/src/exchange/taler-exchange-httpd_kyc-wallet.h
+++ b/src/exchange/taler-exchange-httpd_kyc-wallet.h
@@ -30,14 +30,16 @@
  * reserve and the signature "reserve_sig" which affirms the operation. If OK,
  * a KYC record is created (if missing) and the KYC status returned.
  *
- * @param connection request to handle
+ * @param rc request to handle
  * @param root uploaded JSON data
+ * @param args empty array
  * @return MHD result code
-  */
+ */
 MHD_RESULT
 TEH_handler_kyc_wallet (
-  struct MHD_Connection *connection,
-  const json_t *root);
+  struct TEH_RequestContext *rc,
+  const json_t *root,
+  const char *const args[]);
 
 
 #endif

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]