contract_version_parse.c (2286B)
1 /* 2 This file is part of TALER 3 (C) 2026 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Lesser General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file src/util/contract_version_parse.c 18 * @brief parser for the contract version 19 * @author Christian Grothoff 20 */ 21 #include "platform.h" 22 #include <string.h> 23 #include "taler/taler_merchant_util.h" 24 25 /** 26 * Parse contract version of given JSON contract terms. 27 * 28 * @param cls closure, unused parameter 29 * @param root the JSON object representing data 30 * @param[out] spec where to write the data 31 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error 32 */ 33 static enum GNUNET_GenericReturnValue 34 parse_contract_version (void *cls, 35 json_t *root, 36 struct GNUNET_JSON_Specification *spec) 37 { 38 enum TALER_MERCHANT_ContractVersion *res 39 = (enum TALER_MERCHANT_ContractVersion *) spec->ptr; 40 41 (void) cls; 42 if (json_is_integer (root)) 43 { 44 json_int_t version = json_integer_value (root); 45 46 switch (version) 47 { 48 case 0: 49 *res = TALER_MERCHANT_CONTRACT_VERSION_0; 50 return GNUNET_OK; 51 case 1: 52 *res = TALER_MERCHANT_CONTRACT_VERSION_1; 53 return GNUNET_OK; 54 } 55 56 GNUNET_break_op (0); 57 return GNUNET_SYSERR; 58 } 59 60 if (json_is_null (root)) 61 { 62 *res = TALER_MERCHANT_CONTRACT_VERSION_0; 63 return GNUNET_OK; 64 } 65 66 GNUNET_break_op (0); 67 return GNUNET_SYSERR; 68 } 69 70 71 struct GNUNET_JSON_Specification 72 TALER_MERCHANT_spec_contract_version ( 73 const char *name, 74 enum TALER_MERCHANT_ContractVersion *version) 75 { 76 struct GNUNET_JSON_Specification ret = { 77 .parser = &parse_contract_version, 78 .field = name, 79 .ptr = version 80 }; 81 82 *version = TALER_MERCHANT_CONTRACT_VERSION_0; 83 return ret; 84 }