gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: -simplify code


From: gnunet
Subject: [taler-exchange] branch master updated: -simplify code
Date: Sun, 24 Sep 2023 12:07:33 +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 ac941ca2 -simplify code
ac941ca2 is described below

commit ac941ca266732341272284a588df55aa1d260c54
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Sep 24 12:07:26 2023 +0200

    -simplify code
---
 src/exchange/taler-exchange-httpd.c | 179 ++++++++++++++++--------------------
 src/util/test_age_restriction.c     |  35 ++++---
 2 files changed, 95 insertions(+), 119 deletions(-)

diff --git a/src/exchange/taler-exchange-httpd.c 
b/src/exchange/taler-exchange-httpd.c
index 7129f6d1..a9d10cc3 100644
--- a/src/exchange/taler-exchange-httpd.c
+++ b/src/exchange/taler-exchange-httpd.c
@@ -1217,6 +1217,20 @@ handler_seed (struct TEH_RequestContext *rc,
 }
 
 
+/**
+ * Signature of functions that handle simple
+ * POST operations for the management API.
+ *
+ * @param connection the MHD connection to handle
+ * @param root uploaded JSON data
+ * @return MHD result code
+ */
+typedef MHD_RESULT
+(*ManagementPostHandler)(
+  struct MHD_Connection *connection,
+  const json_t *root);
+
+
 /**
  * Handle POST "/management/..." requests.
  *
@@ -1230,6 +1244,55 @@ handle_post_management (struct TEH_RequestContext *rc,
                         const json_t *root,
                         const char *const args[])
 {
+  static const struct
+  {
+    const char *arg0;
+    const char *arg1;
+    ManagementPostHandler handler;
+  } plain_posts[] = {
+    {
+      .arg0 = "keys",
+      .handler = &TEH_handler_management_post_keys
+    },
+    {
+      .arg0 = "wire",
+      .handler = &TEH_handler_management_post_wire
+    },
+    {
+      .arg0 = "wire",
+      .arg1 = "disable",
+      .handler = &TEH_handler_management_post_wire_disable
+    },
+    {
+      .arg0 = "wire-fee",
+      .handler = &TEH_handler_management_post_wire_fees
+    },
+    {
+      .arg0 = "global-fee",
+      .handler = &TEH_handler_management_post_global_fees
+    },
+    {
+      .arg0 = "extensions",
+      .handler = &TEH_handler_management_post_extensions
+    },
+    {
+      .arg0 = "drain",
+      .handler = &TEH_handler_management_post_drain
+    },
+    {
+      .arg0 = "aml-officers",
+      .handler = &TEH_handler_management_aml_officers
+    },
+    {
+      .arg0 = "partners",
+      .handler = &TEH_handler_management_partners
+    },
+    {
+      NULL,
+      NULL,
+      NULL
+    }
+  };
   if (NULL == args[0])
   {
     GNUNET_break_op (0);
@@ -1325,108 +1388,22 @@ handle_post_management (struct TEH_RequestContext *rc,
                                                       &exchange_pub,
                                                       root);
   }
-  /* FIXME-STYLE: all of the following can likely be nicely combined
-     into an array-based dispatcher to deduplicate the logic... */
-  if (0 == strcmp (args[0],
-                   "keys"))
-  {
-    if (NULL != args[1])
-    {
-      GNUNET_break_op (0);
-      return r404 (rc->connection,
-                   "/management/keys/*");
-    }
-    return TEH_handler_management_post_keys (rc->connection,
-                                             root);
-  }
-  if (0 == strcmp (args[0],
-                   "wire"))
-  {
-    if (NULL == args[1])
-      return TEH_handler_management_post_wire (rc->connection,
-                                               root);
-    if ( (0 != strcmp (args[1],
-                       "disable")) ||
-         (NULL != args[2]) )
-    {
-      GNUNET_break_op (0);
-      return r404 (rc->connection,
-                   "/management/wire/disable");
-    }
-    return TEH_handler_management_post_wire_disable (rc->connection,
-                                                     root);
-  }
-  if (0 == strcmp (args[0],
-                   "wire-fee"))
-  {
-    if (NULL != args[1])
-    {
-      GNUNET_break_op (0);
-      return r404 (rc->connection,
-                   "/management/wire-fee/*");
-    }
-    return TEH_handler_management_post_wire_fees (rc->connection,
-                                                  root);
-  }
-  if (0 == strcmp (args[0],
-                   "global-fee"))
-  {
-    if (NULL != args[1])
-    {
-      GNUNET_break_op (0);
-      return r404 (rc->connection,
-                   "/management/global-fee/*");
-    }
-    return TEH_handler_management_post_global_fees (rc->connection,
-                                                    root);
-  }
-  if (0 == strcmp (args[0],
-                   "extensions"))
-  {
-    if (NULL != args[1])
-    {
-      GNUNET_break_op (0);
-      return r404 (rc->connection,
-                   "/management/extensions/*");
-    }
-    return TEH_handler_management_post_extensions (rc->connection,
-                                                   root);
-  }
-  if (0 == strcmp (args[0],
-                   "drain"))
-  {
-    if (NULL != args[1])
-    {
-      GNUNET_break_op (0);
-      return r404 (rc->connection,
-                   "/management/drain/*");
-    }
-    return TEH_handler_management_post_drain (rc->connection,
-                                              root);
-  }
-  if (0 == strcmp (args[0],
-                   "aml-officers"))
-  {
-    if (NULL != args[1])
-    {
-      GNUNET_break_op (0);
-      return r404 (rc->connection,
-                   "/management/aml-officers/*");
-    }
-    return TEH_handler_management_aml_officers (rc->connection,
-                                                root);
-  }
-  if (0 == strcmp (args[0],
-                   "partners"))
-  {
-    if (NULL != args[1])
-    {
-      GNUNET_break_op (0);
-      return r404 (rc->connection,
-                   "/management/partners/*");
+  for (unsigned int i = 0;
+       NULL != plain_posts[i].handler;
+       i++)
+  {
+    if (0 == strcmp (args[0],
+                     plain_posts[i].arg0))
+    {
+      if ( ( (NULL == args[1]) &&
+             (NULL == plain_posts[i].arg1) ) ||
+           ( (NULL != args[1]) &&
+             (NULL != plain_posts[i].arg1) &&
+             (0 == strcmp (args[1],
+                           plain_posts[i].arg1)) ) )
+        return plain_posts[i].handler (rc->connection,
+                                       root);
     }
-    return TEH_handler_management_partners (rc->connection,
-                                            root);
   }
   GNUNET_break_op (0);
   return r404 (rc->connection,
diff --git a/src/util/test_age_restriction.c b/src/util/test_age_restriction.c
index 406d16ef..02b16c3e 100644
--- a/src/util/test_age_restriction.c
+++ b/src/util/test_age_restriction.c
@@ -80,24 +80,24 @@ test_groups (void)
       .bits =
         1 | 1 << 5 | 1 << 13 | 1 << 23,
 
-      .group = { 0, 0, 0, 0, 0,
-                 1, 1, 1, 1, 1, 1, 1, 1,
-                 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-                 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }
+        .group = { 0, 0, 0, 0, 0,
+                   1, 1, 1, 1, 1, 1, 1, 1,
+                   2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+                   3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }
 
 
     },
     {
       .bits =
         1 | 1 << 8 | 1 << 10 | 1 << 12 | 1 << 14 | 1 << 16 | 1 << 18 | 1 << 21,
-      .group = { 0, 0, 0, 0, 0, 0, 0, 0,
-                 1, 1,
-                 2, 2,
-                 3, 3,
-                 4, 4,
-                 5, 5,
-                 6, 6, 6,
-                 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7}
+        .group = { 0, 0, 0, 0, 0, 0, 0, 0,
+                   1, 1,
+                   2, 2,
+                   3, 3,
+                   4, 4,
+                   5, 5,
+                   6, 6, 6,
+                   7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7}
 
 
     }
@@ -168,7 +168,7 @@ test_dates (void)
      * loop */
     {.date = NULL, .expected = 0, .ret = GNUNET_OK },
   };
-  char buf[256]={0};
+  char buf[256] = {0};
 
   for (uint8_t t = 0; t < sizeof(test) / sizeof(test[0]); t++)
   {
@@ -321,11 +321,10 @@ test_attestation (void)
                                 &seed,
                                 sizeof(seed));
 
-    ret = TALER_age_restriction_commit (&age_mask,
-                                        age,
-                                        &seed,
-                                        &acp[0]);
-
+    TALER_age_restriction_commit (&age_mask,
+                                  age,
+                                  &seed,
+                                  &acp[0]);
     printf (
       "commit(age:%d) == %d; proof.num: %ld; age_group: %d\n",
       age,

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