-complete va coin parser of purse_create_deposit CMD
This commit is contained in:
parent
22cfc59d90
commit
89431a41b7
@ -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 ************ */
|
||||
|
||||
|
||||
|
@ -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 \
|
||||
|
64
src/testing/testing_api_cmd_common.c
Normal file
64
src/testing/testing_api_cmd_common.c
Normal file
@ -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;
|
||||
}
|
@ -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));
|
||||
|
@ -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,7 +107,8 @@ recoup_cb (void *cls,
|
||||
}
|
||||
|
||||
if (GNUNET_OK !=
|
||||
parse_coin_reference (ps->coin_reference,
|
||||
TALER_TESTING_parse_coin_reference (
|
||||
ps->coin_reference,
|
||||
&cref,
|
||||
&idx))
|
||||
{
|
||||
@ -246,7 +203,8 @@ recoup_run (void *cls,
|
||||
|
||||
ps->is = is;
|
||||
if (GNUNET_OK !=
|
||||
parse_coin_reference (ps->coin_reference,
|
||||
TALER_TESTING_parse_coin_reference (
|
||||
ps->coin_reference,
|
||||
&cref,
|
||||
&idx))
|
||||
{
|
||||
|
@ -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,7 +106,8 @@ recoup_refresh_cb (void *cls,
|
||||
}
|
||||
|
||||
if (GNUNET_OK !=
|
||||
parse_coin_reference (rrs->coin_reference,
|
||||
TALER_TESTING_parse_coin_reference (
|
||||
rrs->coin_reference,
|
||||
&cref,
|
||||
&idx))
|
||||
{
|
||||
@ -242,7 +199,8 @@ recoup_refresh_run (void *cls,
|
||||
|
||||
rrs->is = is;
|
||||
if (GNUNET_OK !=
|
||||
parse_coin_reference (rrs->coin_reference,
|
||||
TALER_TESTING_parse_coin_reference (
|
||||
rrs->coin_reference,
|
||||
&cref,
|
||||
&idx))
|
||||
{
|
||||
|
@ -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,7 +390,8 @@ withdraw_run (void *cls,
|
||||
unsigned int index;
|
||||
|
||||
GNUNET_assert (GNUNET_OK ==
|
||||
parse_coin_reference (ws->reuse_coin_key_ref,
|
||||
TALER_TESTING_parse_coin_reference (
|
||||
ws->reuse_coin_key_ref,
|
||||
&cstr,
|
||||
&index));
|
||||
cref = TALER_TESTING_interpreter_lookup_command (is,
|
||||
|
Loading…
Reference in New Issue
Block a user