gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: add helper to parse amounts give


From: gnunet
Subject: [taler-exchange] branch master updated: add helper to parse amounts given as query parameters
Date: Sun, 03 Mar 2024 11:53:37 +0100

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 75067210 add helper to parse amounts given as query parameters
75067210 is described below

commit 75067210fead522fc72327bfa3ac5504d7eed28c
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Mar 3 11:45:01 2024 +0100

    add helper to parse amounts given as query parameters
---
 src/include/taler_mhd_lib.h | 45 +++++++++++++++++++++++++++++++++++++++++++++
 src/mhd/Makefile.am         |  4 ++--
 src/mhd/mhd_parsing.c       | 33 ++++++++++++++++++++++++++++++++-
 3 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/src/include/taler_mhd_lib.h b/src/include/taler_mhd_lib.h
index db6db05e..c16772bf 100644
--- a/src/include/taler_mhd_lib.h
+++ b/src/include/taler_mhd_lib.h
@@ -27,6 +27,7 @@
 #include <jansson.h>
 #include <microhttpd.h>
 #include "taler_error_codes.h"
+#include "taler_util.h"
 #include <gnunet/gnunet_mhd_compat.h>
 
 
@@ -520,6 +521,50 @@ TALER_MHD_parse_request_arg_number (struct MHD_Connection 
*connection,
   } while (0)
 
 
+/**
+ * Extract optional amount argument from request.
+ *
+ * @param connection the MHD connection
+ * @param name name of the query parameter
+ * @param[out] val set to the amount, unchanged if the
+ *             option was not given
+ * @return #GNUNET_OK on success,
+ *         #GNUNET_NO if an error was returned on @a connection (caller should 
return #MHD_YES) and
+ *     #GNUNET_SYSERR if we failed to return an error (caller should return 
#MHD_NO)
+ */
+enum GNUNET_GenericReturnValue
+TALER_MHD_parse_request_arg_amount (struct MHD_Connection *connection,
+                                    const char *name,
+                                    struct TALER_Amount *val);
+
+
+/**
+ * Extract optional amount argument from request.
+ * Macro that *returns* #MHD_YES/#MHD_NO if the
+ * requested argument existed but failed to parse.
+ *
+ * @param connection the MHD connection
+ * @param name name of the argument to parse
+ * @param[out] val set to the given amount,
+ *    unchanged if value was not specified
+ */
+#define TALER_MHD_parse_request_amount(connection,name,val)  \
+  do {                                                         \
+    switch (TALER_MHD_parse_request_arg_amount (connection,   \
+                                                name, \
+                                                val))  \
+    {                      \
+    case GNUNET_SYSERR:    \
+      GNUNET_break (0);    \
+      return MHD_NO;       \
+    case GNUNET_NO:        \
+      GNUNET_break_op (0); \
+    case GNUNET_OK:        \
+      break;               \
+    }                      \
+  } while (0)
+
+
 /**
  * Extract fixed-size base32crockford encoded data from request argument.
  *
diff --git a/src/mhd/Makefile.am b/src/mhd/Makefile.am
index f7f052d5..1e3c4939 100644
--- a/src/mhd/Makefile.am
+++ b/src/mhd/Makefile.am
@@ -16,12 +16,12 @@ libtalermhd_la_SOURCES = \
   mhd_responses.c \
   mhd_run.c
 libtalermhd_la_LDFLAGS = \
-  -version-info 0:0:0 \
+  -version-info 1:0:1 \
   -no-undefined
 libtalermhd_la_LIBADD = \
-  -lgnunetjson \
   $(top_builddir)/src/json/libtalerjson.la \
   $(top_builddir)/src/util/libtalerutil.la \
+  -lgnunetjson \
   -lgnunetutil \
   -lmicrohttpd \
   -ljansson \
diff --git a/src/mhd/mhd_parsing.c b/src/mhd/mhd_parsing.c
index 381b064f..1e8258f5 100644
--- a/src/mhd/mhd_parsing.c
+++ b/src/mhd/mhd_parsing.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  Copyright (C) 2014--2020 Taler Systems SA
+  Copyright (C) 2014--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
@@ -245,6 +245,37 @@ TALER_MHD_parse_request_arg_number (struct MHD_Connection 
*connection,
 }
 
 
+enum GNUNET_GenericReturnValue
+TALER_MHD_parse_request_arg_amount (struct MHD_Connection *connection,
+                                    const char *name,
+                                    struct TALER_Amount *val)
+{
+  const char *ts;
+
+  ts = MHD_lookup_connection_value (connection,
+                                    MHD_GET_ARGUMENT_KIND,
+                                    name);
+  if (NULL == ts)
+    return GNUNET_OK;
+  if (GNUNET_OK !=
+      TALER_string_to_amount (ts,
+                              val))
+  {
+    MHD_RESULT mret;
+
+    GNUNET_break_op (0);
+    mret = TALER_MHD_reply_with_error (connection,
+                                       MHD_HTTP_BAD_REQUEST,
+                                       TALER_EC_GENERIC_PARAMETER_MALFORMED,
+                                       name);
+    return (MHD_YES == mret)
+      ? GNUNET_NO
+      : GNUNET_SYSERR;
+  }
+  return GNUNET_OK;
+}
+
+
 enum GNUNET_GenericReturnValue
 TALER_MHD_parse_json_data (struct MHD_Connection *connection,
                            const json_t *root,

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