gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] 63/151: complete GET /aml//measures endpoint


From: gnunet
Subject: [taler-exchange] 63/151: complete GET /aml//measures endpoint
Date: Tue, 30 Jul 2024 23:37:13 +0200

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

grothoff pushed a commit to branch master
in repository exchange.

commit 985d7d8c7aacbda8332cfc3e1e02ca0d354dca95
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Jun 23 15:37:47 2024 +0200

    complete GET /aml//measures endpoint
---
 .../taler-exchange-httpd_aml-measures-get.c        |  10 +-
 src/include/taler_kyclogic_lib.h                   |  14 +++
 src/kyclogic/kyclogic_api.c                        | 128 +++++++++++++++++++++
 3 files changed, 146 insertions(+), 6 deletions(-)

diff --git a/src/exchange/taler-exchange-httpd_aml-measures-get.c 
b/src/exchange/taler-exchange-httpd_aml-measures-get.c
index aca4343f4..6332b4021 100644
--- a/src/exchange/taler-exchange-httpd_aml-measures-get.c
+++ b/src/exchange/taler-exchange-httpd_aml-measures-get.c
@@ -25,11 +25,10 @@
 #include <pthread.h>
 #include "taler_json_lib.h"
 #include "taler_mhd_lib.h"
+#include "taler_kyclogic_lib.h"
 #include "taler_signatures.h"
 #include "taler-exchange-httpd.h"
-#include "taler_exchangedb_plugin.h"
 #include "taler-exchange-httpd_aml-measures-get.h"
-#include "taler-exchange-httpd_metrics.h"
 
 
 MHD_RESULT
@@ -44,10 +43,9 @@ TEH_handler_aml_measures_get (
 
   if (NULL == roots)
   {
-    // FIXME: initialize these properly!
-    roots = json_object ();
-    programs = json_object ();
-    checks = json_object ();
+    TALER_KYCLOGIC_get_measure_configuration (&roots,
+                                              &programs,
+                                              &checks);
   }
   if (NULL != args[0])
   {
diff --git a/src/include/taler_kyclogic_lib.h b/src/include/taler_kyclogic_lib.h
index a1fa579bb..3cb40175c 100644
--- a/src/include/taler_kyclogic_lib.h
+++ b/src/include/taler_kyclogic_lib.h
@@ -561,4 +561,18 @@ TALER_KYCLOGIC_kyc_get_details (
   void *cb_cls);
 
 
+/**
+ * Return configuration data useful for the
+ * /aml/$PUB/measures endpoint.
+ *
+ * @param[out] proots set to the root measures
+ * @param[out] pprograms set to available AML programs
+ * @param[out] pchecks set to available KYC checks
+ */
+void
+TALER_KYCLOGIC_get_measure_configuration (
+  json_t **proots,
+  json_t **pprograms,
+  json_t **pchecks);
+
 #endif
diff --git a/src/kyclogic/kyclogic_api.c b/src/kyclogic/kyclogic_api.c
index 518c9fc1c..34e849ae1 100644
--- a/src/kyclogic/kyclogic_api.c
+++ b/src/kyclogic/kyclogic_api.c
@@ -2198,4 +2198,132 @@ TALER_KYCLOGIC_measure_to_requirement (
 }
 
 
+void
+TALER_KYCLOGIC_get_measure_configuration (
+  json_t **proots,
+  json_t **pprograms,
+  json_t **pchecks)
+{
+  json_t *roots;
+  json_t *programs;
+  json_t *checks;
+
+  roots = json_object ();
+  for (unsigned int i = 0; i<default_rules.num_custom_measures; i++)
+  {
+    const struct TALER_KYCLOGIC_Measure *m
+      = &default_rules.custom_measures[i];
+    json_t *jm;
+
+    jm = GNUNET_JSON_PACK (
+      GNUNET_JSON_pack_string ("check_name",
+                               m->check_name),
+      GNUNET_JSON_pack_string ("prog_name",
+                               m->prog_name),
+      GNUNET_JSON_pack_allow_null (
+        GNUNET_JSON_pack_object_incref ("context",
+                                        m->context)));
+    GNUNET_assert (0 ==
+                   json_object_set_new (roots,
+                                        m->measure_name,
+                                        jm));
+  }
+
+  programs = json_object ();
+  for (unsigned int i = 0; i<num_aml_programs; i++)
+  {
+    const struct TALER_KYCLOGIC_AmlProgram *ap
+      = aml_programs[i];
+    json_t *jp;
+    json_t *ctx;
+    json_t *inp;
+
+    ctx = json_array ();
+    GNUNET_assert (NULL != ctx);
+    for (unsigned int j = 0; j<ap->num_required_contexts; j++)
+    {
+      const char *rc = ap->required_contexts[j];
+
+      GNUNET_assert (0 ==
+                     json_array_append_new (ctx,
+                                            json_string (rc)));
+    }
+    inp = json_array ();
+    GNUNET_assert (NULL != inp);
+    for (unsigned int j = 0; j<ap->num_required_attributes; j++)
+    {
+      const char *ra = ap->required_attributes[j];
+
+      GNUNET_assert (0 ==
+                     json_array_append_new (inp,
+                                            json_string (ra)));
+    }
+
+    jp = GNUNET_JSON_PACK (
+      GNUNET_JSON_pack_string ("description",
+                               ap->description),
+      GNUNET_JSON_pack_array_steal ("context",
+                                    ctx),
+      GNUNET_JSON_pack_array_steal ("inputs",
+                                    inp));
+    GNUNET_assert (0 ==
+                   json_object_set_new (programs,
+                                        ap->program_name,
+                                        jp));
+  }
+
+  checks = json_object ();
+  for (unsigned int i = 0; i<num_kyc_checks; i++)
+  {
+    const struct TALER_KYCLOGIC_KycCheck *ck
+      = kyc_checks[i];
+    json_t *jc;
+    json_t *requires;
+    json_t *outputs;
+
+    requires = json_array ();
+    GNUNET_assert (NULL != requires);
+    for (unsigned int j = 0; j<ck->num_requires; j++)
+    {
+      const char *ra = ck->requires[j];
+
+      GNUNET_assert (0 ==
+                     json_array_append_new (requires,
+                                            json_string (ra)));
+    }
+    outputs = json_array ();
+    GNUNET_assert (NULL != outputs);
+    for (unsigned int j = 0; j<ck->num_outputs; j++)
+    {
+      const char *out = ck->outputs[j];
+
+      GNUNET_assert (0 ==
+                     json_array_append_new (outputs,
+                                            json_string (out)));
+    }
+
+    jc = GNUNET_JSON_PACK (
+      GNUNET_JSON_pack_string ("description",
+                               ck->description),
+      GNUNET_JSON_pack_allow_null (
+        GNUNET_JSON_pack_object_incref ("description",
+                                        ck->description_i18n)),
+      GNUNET_JSON_pack_array_steal ("requires",
+                                    requires),
+      GNUNET_JSON_pack_array_steal ("outputs",
+                                    outputs),
+      GNUNET_JSON_pack_string ("fallback",
+                               ck->fallback));
+    GNUNET_assert (0 ==
+                   json_object_set_new (checks,
+                                        ck->check_name,
+                                        jc));
+  }
+
+  *proots = roots;
+  *pprograms = programs;
+  *pchecks = checks;
+}
+
+
 /* end of kyclogic_api.c */

-- 
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]