testing_api_cmd_common.c (1852B)
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/taler_testing_lib.h" 25 26 27 enum GNUNET_GenericReturnValue 28 TALER_TESTING_parse_coin_reference ( 29 const char *coin_reference, 30 char **cref, 31 unsigned int *idx) 32 { 33 const char *index; 34 char dummy; 35 36 /* We allow command references of the form "$LABEL#$INDEX" or 37 just "$LABEL", which implies the index is 0. Figure out 38 which one it is. */ 39 index = strchr (coin_reference, '#'); 40 if (NULL == index) 41 { 42 *idx = 0; 43 *cref = GNUNET_strdup (coin_reference); 44 return GNUNET_OK; 45 } 46 *cref = GNUNET_strndup (coin_reference, 47 index - coin_reference); 48 if (1 != sscanf (index + 1, 49 "%u%c", 50 idx, 51 &dummy)) 52 { 53 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 54 "Numeric index (not `%s') required after `#' in command reference of command in %s:%u\n", 55 index, 56 __FILE__, 57 __LINE__); 58 GNUNET_free (*cref); 59 *cref = NULL; 60 return GNUNET_SYSERR; 61 } 62 return GNUNET_OK; 63 }