Line data Source code
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 277 : parse_contract_version (void *cls,
35 : json_t *root,
36 : struct GNUNET_JSON_Specification *spec)
37 : {
38 277 : enum TALER_MERCHANT_ContractVersion *res
39 : = (enum TALER_MERCHANT_ContractVersion *) spec->ptr;
40 :
41 : (void) cls;
42 277 : if (json_is_integer (root))
43 : {
44 277 : json_int_t version = json_integer_value (root);
45 :
46 277 : switch (version)
47 : {
48 214 : case 0:
49 214 : *res = TALER_MERCHANT_CONTRACT_VERSION_0;
50 214 : return GNUNET_OK;
51 63 : case 1:
52 63 : *res = TALER_MERCHANT_CONTRACT_VERSION_1;
53 63 : return GNUNET_OK;
54 : }
55 :
56 0 : GNUNET_break_op (0);
57 0 : return GNUNET_SYSERR;
58 : }
59 :
60 0 : if (json_is_null (root))
61 : {
62 0 : *res = TALER_MERCHANT_CONTRACT_VERSION_0;
63 0 : return GNUNET_OK;
64 : }
65 :
66 0 : GNUNET_break_op (0);
67 0 : return GNUNET_SYSERR;
68 : }
69 :
70 :
71 : struct GNUNET_JSON_Specification
72 372 : TALER_MERCHANT_spec_contract_version (
73 : const char *name,
74 : enum TALER_MERCHANT_ContractVersion *version)
75 : {
76 372 : struct GNUNET_JSON_Specification ret = {
77 : .parser = &parse_contract_version,
78 : .field = name,
79 : .ptr = version
80 : };
81 :
82 372 : *version = TALER_MERCHANT_CONTRACT_VERSION_0;
83 372 : return ret;
84 : }
|