Line data Source code
1 : /*
2 : This file is part of TALER
3 : (C) 2019, 2020, 2021, 2023, 2024 Taler Systems SA
4 :
5 : TALER is free software; you can redistribute it and/or modify it under the
6 : terms of the GNU Affero 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 taler-merchant-httpd_config.c
18 : * @brief implement API for querying configuration data of the backend
19 : * @author Florian Dold
20 : */
21 : #include "platform.h"
22 : #include <jansson.h>
23 : #include <taler/taler_util.h>
24 : #include <taler/taler_json_lib.h>
25 : #include "taler-merchant-httpd.h"
26 : #include "taler-merchant-httpd_config.h"
27 : #include "taler-merchant-httpd_mhd.h"
28 : #include "taler-merchant-httpd_exchanges.h"
29 :
30 :
31 : /**
32 : * Taler protocol version in the format CURRENT:REVISION:AGE
33 : * as used by GNU libtool. See
34 : * https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
35 : *
36 : * Please be very careful when updating and follow
37 : * https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info
38 : * precisely. Note that this version has NOTHING to do with the
39 : * release version, and the format is NOT the same that semantic
40 : * versioning uses either.
41 : *
42 : * When changing this version, you likely want to also update
43 : * #MERCHANT_PROTOCOL_CURRENT and #MERCHANT_PROTOCOL_AGE in
44 : * merchant_api_config.c!
45 : */
46 : #define MERCHANT_PROTOCOL_VERSION "20:0:8"
47 :
48 :
49 : /**
50 : * Callback on an exchange known to us. Does not warrant
51 : * that the "keys" information is actually available for
52 : * @a exchange.
53 : *
54 : * @param cls closure with `json_t *` array to expand
55 : * @param url base URL of the exchange
56 : * @param exchange internal handle for the exchange
57 : */
58 : static void
59 14 : add_exchange (void *cls,
60 : const char *url,
61 : const struct TMH_Exchange *exchange)
62 : {
63 14 : json_t *xa = cls;
64 : json_t *xi;
65 :
66 14 : xi = GNUNET_JSON_PACK (
67 : GNUNET_JSON_pack_data_auto ("master_pub",
68 : TMH_EXCHANGES_get_master_pub (exchange)),
69 : GNUNET_JSON_pack_string ("currency",
70 : TMH_EXCHANGES_get_currency (exchange)),
71 : GNUNET_JSON_pack_string ("base_url",
72 : url));
73 14 : GNUNET_assert (NULL != xi);
74 14 : GNUNET_assert (0 ==
75 : json_array_append_new (xa,
76 : xi));
77 14 : }
78 :
79 :
80 : MHD_RESULT
81 17 : MH_handler_config (const struct TMH_RequestHandler *rh,
82 : struct MHD_Connection *connection,
83 : struct TMH_HandlerContext *hc)
84 : {
85 : static struct MHD_Response *response;
86 :
87 : (void) rh;
88 : (void) hc;
89 17 : if (NULL == response)
90 : {
91 14 : json_t *specs = json_object ();
92 14 : json_t *exchanges = json_array ();
93 14 : json_t *mtc = json_array ();
94 :
95 14 : GNUNET_assert (NULL != specs);
96 14 : GNUNET_assert (NULL != exchanges);
97 14 : GNUNET_assert (NULL != mtc);
98 14 : TMH_exchange_get_trusted (&add_exchange,
99 : exchanges);
100 14 : if (0 != (TEH_TCS_SMS & TEH_mandatory_tan_channels))
101 0 : GNUNET_assert (0 ==
102 : json_array_append_new (mtc,
103 : json_string ("sms")));
104 14 : if (0 != (TEH_TCS_EMAIL & TEH_mandatory_tan_channels))
105 0 : GNUNET_assert (0 ==
106 : json_array_append_new (mtc,
107 : json_string ("email")));
108 84 : for (unsigned int i = 0; i<TMH_num_cspecs; i++)
109 : {
110 70 : const struct TALER_CurrencySpecification *cspec = &TMH_cspecs[i];
111 :
112 70 : if (TMH_test_exchange_configured_for_currency (cspec->currency))
113 14 : GNUNET_assert (0 ==
114 : json_object_set_new (
115 : specs,
116 : cspec->currency,
117 : TALER_JSON_currency_specs_to_json (
118 : cspec)));
119 : }
120 14 : response = TALER_MHD_MAKE_JSON_PACK (
121 : GNUNET_JSON_pack_string ("currency",
122 : TMH_currency),
123 : GNUNET_JSON_pack_bool ("have_self_provisioning",
124 : GNUNET_YES ==
125 : TMH_have_self_provisioning),
126 : GNUNET_JSON_pack_object_steal ("currencies",
127 : specs),
128 : GNUNET_JSON_pack_array_steal ("exchanges",
129 : exchanges),
130 : GNUNET_JSON_pack_array_steal ("mandatory_tan_channels",
131 : mtc),
132 : GNUNET_JSON_pack_string (
133 : "implementation",
134 : "urn:net:taler:specs:taler-merchant:c-reference"),
135 : GNUNET_JSON_pack_string ("name",
136 : "taler-merchant"),
137 : GNUNET_JSON_pack_string ("version",
138 : MERCHANT_PROTOCOL_VERSION));
139 : }
140 17 : return MHD_queue_response (connection,
141 : MHD_HTTP_OK,
142 : response);
143 : }
144 :
145 :
146 : /* end of taler-merchant-httpd_config.c */
|