exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

testing_api_cmd_common.c (1880B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2018-2022 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it
      6   under the terms of the GNU General Public License as published by
      7   the Free Software Foundation; either version 3, or (at your
      8   option) any later version.
      9 
     10   TALER is distributed in the hope that it will be useful, but
     11   WITHOUT ANY WARRANTY; without even the implied warranty of
     12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13   General Public License for more details.
     14 
     15   You should have received a copy of the GNU General Public
     16   License along with TALER; see the file COPYING.  If not, see
     17   <http://www.gnu.org/licenses/>
     18 */
     19 /**
     20  * @file testing/testing_api_cmd_common.c
     21  * @brief common functions for commands
     22  * @author Christian Grothoff
     23  */
     24 #include "taler/platform.h"
     25 #include "taler/taler_testing_lib.h"
     26 
     27 
     28 enum GNUNET_GenericReturnValue
     29 TALER_TESTING_parse_coin_reference (
     30   const char *coin_reference,
     31   char **cref,
     32   unsigned int *idx)
     33 {
     34   const char *index;
     35   char dummy;
     36 
     37   /* We allow command references of the form "$LABEL#$INDEX" or
     38      just "$LABEL", which implies the index is 0. Figure out
     39      which one it is. */
     40   index = strchr (coin_reference, '#');
     41   if (NULL == index)
     42   {
     43     *idx = 0;
     44     *cref = GNUNET_strdup (coin_reference);
     45     return GNUNET_OK;
     46   }
     47   *cref = GNUNET_strndup (coin_reference,
     48                           index - coin_reference);
     49   if (1 != sscanf (index + 1,
     50                    "%u%c",
     51                    idx,
     52                    &dummy))
     53   {
     54     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     55                 "Numeric index (not `%s') required after `#' in command reference of command in %s:%u\n",
     56                 index,
     57                 __FILE__,
     58                 __LINE__);
     59     GNUNET_free (*cref);
     60     *cref = NULL;
     61     return GNUNET_SYSERR;
     62   }
     63   return GNUNET_OK;
     64 }