gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: -complete va coin parser of purs


From: gnunet
Subject: [taler-exchange] branch master updated: -complete va coin parser of purse_create_deposit CMD
Date: Wed, 06 Apr 2022 13:54:14 +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 89431a41 -complete va coin parser of purse_create_deposit CMD
89431a41 is described below

commit 89431a41b795cfbd14d6ce08dc33272e4a9ab9e6
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Wed Apr 6 13:54:08 2022 +0200

    -complete va coin parser of purse_create_deposit CMD
---
 src/include/taler_testing_lib.h                    | 15 +++++
 src/testing/Makefile.am                            |  1 +
 src/testing/testing_api_cmd_common.c               | 64 ++++++++++++++++++++++
 src/testing/testing_api_cmd_purse_create_deposit.c | 37 ++++++++++++-
 src/testing/testing_api_cmd_recoup.c               | 58 +++-----------------
 src/testing/testing_api_cmd_recoup_refresh.c       | 58 +++-----------------
 src/testing/testing_api_cmd_withdraw.c             | 51 ++---------------
 7 files changed, 135 insertions(+), 149 deletions(-)

diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h
index 6980d9d8..7c407152 100644
--- a/src/include/taler_testing_lib.h
+++ b/src/include/taler_testing_lib.h
@@ -941,6 +941,21 @@ TALER_TESTING_has_in_name (const char *prog,
                            const char *marker);
 
 
+/**
+ * Parse reference to a coin.
+ *
+ * @param coin_reference of format $LABEL['#' $INDEX]?
+ * @param[out] cref where we return a copy of $LABEL
+ * @param[out] idx where we set $INDEX
+ * @return #GNUNET_SYSERR if $INDEX is present but not numeric
+ */
+enum GNUNET_GenericReturnValue
+TALER_TESTING_parse_coin_reference (
+  const char *coin_reference,
+  char **cref,
+  unsigned int *idx);
+
+
 /* ************** Specific interpreter commands ************ */
 
 
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index c0e67588..3f1afd69 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -54,6 +54,7 @@ libtalertesting_la_SOURCES = \
   testing_api_cmd_batch.c \
   testing_api_cmd_change_auth.c \
   testing_api_cmd_check_keys.c \
+  testing_api_cmd_common.c \
   testing_api_cmd_deposit.c \
   testing_api_cmd_deposits_get.c \
   testing_api_cmd_exec_aggregator.c \
diff --git a/src/testing/testing_api_cmd_common.c 
b/src/testing/testing_api_cmd_common.c
new file mode 100644
index 00000000..2d828a2b
--- /dev/null
+++ b/src/testing/testing_api_cmd_common.c
@@ -0,0 +1,64 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2018-2022 Taler Systems SA
+
+  TALER is free software; you can redistribute it and/or modify it
+  under the terms of the GNU 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
+  General Public License for more details.
+
+  You should have received a copy of the GNU General Public
+  License along with TALER; see the file COPYING.  If not, see
+  <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_common.c
+ * @brief common functions for commands
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_testing_lib.h"
+
+
+enum GNUNET_GenericReturnValue
+TALER_TESTING_parse_coin_reference (
+  const char *coin_reference,
+  char **cref,
+  unsigned int *idx)
+{
+  const char *index;
+  char dummy;
+
+  /* We allow command references of the form "$LABEL#$INDEX" or
+     just "$LABEL", which implies the index is 0. Figure out
+     which one it is. */
+  index = strchr (coin_reference, '#');
+  if (NULL == index)
+  {
+    *idx = 0;
+    *cref = GNUNET_strdup (coin_reference);
+    return GNUNET_OK;
+  }
+  *cref = GNUNET_strndup (coin_reference,
+                          index - coin_reference);
+  if (1 != sscanf (index + 1,
+                   "%u%c",
+                   idx,
+                   &dummy))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Numeric index (not `%s') required after `#' in command 
reference of command in %s:%u\n",
+                index,
+                __FILE__,
+                __LINE__);
+    GNUNET_free (*cref);
+    *cref = NULL;
+    return GNUNET_SYSERR;
+  }
+  return GNUNET_OK;
+}
diff --git a/src/testing/testing_api_cmd_purse_create_deposit.c 
b/src/testing/testing_api_cmd_purse_create_deposit.c
index 8aeab744..af7ed3f5 100644
--- a/src/testing/testing_api_cmd_purse_create_deposit.c
+++ b/src/testing/testing_api_cmd_purse_create_deposit.c
@@ -36,7 +36,7 @@ struct Coin
   /**
    * Reference to the respective command.
    */
-  const char *command_ref;
+  char *command_ref;
 
   /**
    * index of the specific coin in the traits of @e command_ref.
@@ -308,6 +308,8 @@ deposit_cleanup (void *cls,
     TALER_EXCHANGE_purse_create_with_deposit_cancel (ds->dh);
     ds->dh = NULL;
   }
+  for (unsigned int i = 0; i<ds->num_coin_references; i++)
+    GNUNET_free (ds->coin_references[i].command_ref);
   json_decref (ds->contract_terms);
   GNUNET_free (ds->coin_references);
   GNUNET_free (ds);
@@ -376,7 +378,38 @@ TALER_TESTING_cmd_purse_create_with_deposit (
                 label);
     GNUNET_assert (0);
   }
-  // FIXME: parse varargs!
+  {
+    va_list ap;
+    unsigned int i;
+    const char *ref;
+    const char *val;
+
+    va_start (ap, purse_expiration);
+    while (NULL != (va_arg (ap, const char *)))
+      ds->num_coin_references++;
+    va_end (ap);
+    GNUNET_assert (0 == (ds->num_coin_references % 2));
+    ds->num_coin_references /= 2;
+    ds->coin_references = GNUNET_new_array (ds->num_coin_references,
+                                            struct Coin);
+    i = 0;
+    va_start (ap, purse_expiration);
+    while (NULL != (ref = va_arg (ap, const char *)))
+    {
+      struct Coin *c = &ds->coin_references[i++];
+
+      GNUNET_assert (NULL != (val = va_arg (ap, const char *)));
+      GNUNET_assert (GNUNET_OK ==
+                     TALER_TESTING_parse_coin_reference (
+                       ref,
+                       &c->command_ref,
+                       &c->coin_index));
+      GNUNET_assert (GNUNET_OK ==
+                     TALER_string_to_amount (val,
+                                             &c->deposit_with_fee));
+    }
+    va_end (ap);
+  }
   GNUNET_assert (GNUNET_OK ==
                  TALER_string_to_amount (target_amount,
                                          &ds->target_amount));
diff --git a/src/testing/testing_api_cmd_recoup.c 
b/src/testing/testing_api_cmd_recoup.c
index ef271622..1a829020 100644
--- a/src/testing/testing_api_cmd_recoup.c
+++ b/src/testing/testing_api_cmd_recoup.c
@@ -67,50 +67,6 @@ struct RecoupState
 };
 
 
-/**
- * Parser reference to a coin.
- *
- * @param coin_reference of format $LABEL['#' $INDEX]?
- * @param[out] cref where we return a copy of $LABEL
- * @param[out] idx where we set $INDEX
- * @return #GNUNET_SYSERR if $INDEX is present but not numeric
- */
-static enum GNUNET_GenericReturnValue
-parse_coin_reference (const char *coin_reference,
-                      char **cref,
-                      unsigned int *idx)
-{
-  const char *index;
-
-  /* We allow command references of the form "$LABEL#$INDEX" or
-     just "$LABEL", which implies the index is 0. Figure out
-     which one it is. */
-  index = strchr (coin_reference, '#');
-  if (NULL == index)
-  {
-    *idx = 0;
-    *cref = GNUNET_strdup (coin_reference);
-    return GNUNET_OK;
-  }
-  *cref = GNUNET_strndup (coin_reference,
-                          index - coin_reference);
-  if (1 != sscanf (index + 1,
-                   "%u",
-                   idx))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Numeric index (not `%s') required after `#' in command 
reference of command in %s:%u\n",
-                index,
-                __FILE__,
-                __LINE__);
-    GNUNET_free (*cref);
-    *cref = NULL;
-    return GNUNET_SYSERR;
-  }
-  return GNUNET_OK;
-}
-
-
 /**
  * Check the result of the recoup request: checks whether
  * the HTTP response code is good, and that the coin that
@@ -151,9 +107,10 @@ recoup_cb (void *cls,
   }
 
   if (GNUNET_OK !=
-      parse_coin_reference (ps->coin_reference,
-                            &cref,
-                            &idx))
+      TALER_TESTING_parse_coin_reference (
+        ps->coin_reference,
+        &cref,
+        &idx))
   {
     TALER_TESTING_interpreter_fail (is);
     return;
@@ -246,9 +203,10 @@ recoup_run (void *cls,
 
   ps->is = is;
   if (GNUNET_OK !=
-      parse_coin_reference (ps->coin_reference,
-                            &cref,
-                            &idx))
+      TALER_TESTING_parse_coin_reference (
+        ps->coin_reference,
+        &cref,
+        &idx))
   {
     TALER_TESTING_interpreter_fail (is);
     return;
diff --git a/src/testing/testing_api_cmd_recoup_refresh.c 
b/src/testing/testing_api_cmd_recoup_refresh.c
index 1102fc75..6081a4ba 100644
--- a/src/testing/testing_api_cmd_recoup_refresh.c
+++ b/src/testing/testing_api_cmd_recoup_refresh.c
@@ -67,50 +67,6 @@ struct RecoupRefreshState
 };
 
 
-/**
- * Parser reference to a coin.
- *
- * @param coin_reference of format $LABEL['#' $INDEX]?
- * @param[out] cref where we return a copy of $LABEL
- * @param[out] idx where we set $INDEX
- * @return #GNUNET_SYSERR if $INDEX is present but not numeric
- */
-static enum GNUNET_GenericReturnValue
-parse_coin_reference (const char *coin_reference,
-                      char **cref,
-                      unsigned int *idx)
-{
-  const char *index;
-
-  /* We allow command references of the form "$LABEL#$INDEX" or
-     just "$LABEL", which implies the index is 0. Figure out
-     which one it is. */
-  index = strchr (coin_reference, '#');
-  if (NULL == index)
-  {
-    *idx = 0;
-    *cref = GNUNET_strdup (coin_reference);
-    return GNUNET_OK;
-  }
-  *cref = GNUNET_strndup (coin_reference,
-                          index - coin_reference);
-  if (1 != sscanf (index + 1,
-                   "%u",
-                   idx))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Numeric index (not `%s') required after `#' in command 
reference of command in %s:%u\n",
-                index,
-                __FILE__,
-                __LINE__);
-    GNUNET_free (*cref);
-    *cref = NULL;
-    return GNUNET_SYSERR;
-  }
-  return GNUNET_OK;
-}
-
-
 /**
  * Check the result of the recoup_refresh request: checks whether
  * the HTTP response code is good, and that the coin that
@@ -150,9 +106,10 @@ recoup_refresh_cb (void *cls,
   }
 
   if (GNUNET_OK !=
-      parse_coin_reference (rrs->coin_reference,
-                            &cref,
-                            &idx))
+      TALER_TESTING_parse_coin_reference (
+        rrs->coin_reference,
+        &cref,
+        &idx))
   {
     TALER_TESTING_interpreter_fail (is);
     return;
@@ -242,9 +199,10 @@ recoup_refresh_run (void *cls,
 
   rrs->is = is;
   if (GNUNET_OK !=
-      parse_coin_reference (rrs->coin_reference,
-                            &cref,
-                            &idx))
+      TALER_TESTING_parse_coin_reference (
+        rrs->coin_reference,
+        &cref,
+        &idx))
   {
     TALER_TESTING_interpreter_fail (is);
     return;
diff --git a/src/testing/testing_api_cmd_withdraw.c 
b/src/testing/testing_api_cmd_withdraw.c
index a3823398..80f8402c 100644
--- a/src/testing/testing_api_cmd_withdraw.c
+++ b/src/testing/testing_api_cmd_withdraw.c
@@ -332,50 +332,6 @@ reserve_withdraw_cb (void *cls,
 }
 
 
-/**
- * Parser reference to a coin.
- *
- * @param coin_reference of format $LABEL['#' $INDEX]?
- * @param[out] cref where we return a copy of $LABEL
- * @param[out] idx where we set $INDEX
- * @return #GNUNET_SYSERR if $INDEX is present but not numeric
- */
-static enum GNUNET_GenericReturnValue
-parse_coin_reference (const char *coin_reference,
-                      char **cref,
-                      unsigned int *idx)
-{
-  const char *index;
-
-  /* We allow command references of the form "$LABEL#$INDEX" or
-     just "$LABEL", which implies the index is 0. Figure out
-     which one it is. */
-  index = strchr (coin_reference, '#');
-  if (NULL == index)
-  {
-    *idx = 0;
-    *cref = GNUNET_strdup (coin_reference);
-    return GNUNET_OK;
-  }
-  *cref = GNUNET_strndup (coin_reference,
-                          index - coin_reference);
-  if (1 != sscanf (index + 1,
-                   "%u",
-                   idx))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Numeric index (not `%s') required after `#' in command 
reference of command in %s:%u\n",
-                index,
-                __FILE__,
-                __LINE__);
-    GNUNET_free (*cref);
-    *cref = NULL;
-    return GNUNET_SYSERR;
-  }
-  return GNUNET_OK;
-}
-
-
 /**
  * Run the command.
  */
@@ -434,9 +390,10 @@ withdraw_run (void *cls,
     unsigned int index;
 
     GNUNET_assert (GNUNET_OK ==
-                   parse_coin_reference (ws->reuse_coin_key_ref,
-                                         &cstr,
-                                         &index));
+                   TALER_TESTING_parse_coin_reference (
+                     ws->reuse_coin_key_ref,
+                     &cstr,
+                     &index));
     cref = TALER_TESTING_interpreter_lookup_command (is,
                                                      cstr);
     GNUNET_assert (NULL != cref);

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