Line data Source code
1 : /*
2 : This file is part of TALER
3 : (C) 2019--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 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 src/backend/taler-merchant-httpd_get-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_get-config.h"
27 : #include "taler-merchant-httpd_exchanges.h"
28 : #include "taler-merchant-httpd_mhd.h"
29 : #include "taler-merchant-httpd_get-exchanges.h"
30 :
31 :
32 : /**
33 : * Taler protocol version in the format CURRENT:REVISION:AGE
34 : * as used by GNU libtool. See
35 : * https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
36 : *
37 : * Please be very careful when updating and follow
38 : * https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info
39 : * precisely. Note that this version has NOTHING to do with the
40 : * release version, and the format is NOT the same that semantic
41 : * versioning uses either.
42 : *
43 : * When changing this version, you likely want to also update
44 : * #MERCHANT_PROTOCOL_CURRENT and #MERCHANT_PROTOCOL_AGE in
45 : * merchant_api_get_config.c!
46 : */
47 : #define MERCHANT_PROTOCOL_VERSION "42:0:30"
48 :
49 :
50 : /**
51 : * Callback on an exchange known to us. Does not warrant
52 : * that the "keys" information is actually available for
53 : * @a exchange.
54 : *
55 : * @param cls closure with `json_t *` array to expand
56 : * @param url base URL of the exchange
57 : * @param exchange internal handle for the exchange
58 : */
59 : static void
60 18 : add_exchange (void *cls,
61 : const char *url,
62 : const struct TMH_Exchange *exchange)
63 : {
64 18 : json_t *xa = cls;
65 : json_t *xi;
66 :
67 18 : xi = GNUNET_JSON_PACK (
68 : GNUNET_JSON_pack_data_auto ("master_pub",
69 : TMH_EXCHANGES_get_master_pub (exchange)),
70 : GNUNET_JSON_pack_string ("currency",
71 : TMH_EXCHANGES_get_currency (exchange)),
72 : GNUNET_JSON_pack_string ("base_url",
73 : url));
74 18 : GNUNET_assert (NULL != xi);
75 18 : GNUNET_assert (0 ==
76 : json_array_append_new (xa,
77 : xi));
78 18 : }
79 :
80 :
81 : /**
82 : * Function to iterate over configuration sections, looking for
83 : * the report generators.
84 : *
85 : * @param cls closure with the `json *` array to build
86 : * @param section name of the section
87 : */
88 : static void
89 738 : add_report_generator (void *cls,
90 : const char *section)
91 : {
92 738 : json_t *rgs = cls;
93 :
94 738 : if (0 != strncasecmp (section,
95 : "report-generator-",
96 : strlen ("report-generator-")))
97 707 : return;
98 31 : if (GNUNET_YES !=
99 31 : GNUNET_CONFIGURATION_have_value (TMH_cfg,
100 : section,
101 : "BINARY"))
102 : {
103 0 : GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
104 : section,
105 : "BINARY");
106 0 : return;
107 : }
108 31 : GNUNET_assert (0 ==
109 : json_array_append_new (rgs,
110 : json_string (section
111 : + strlen (
112 : "report-generator-"))));
113 : }
114 :
115 :
116 : enum MHD_Result
117 21 : MH_handler_config (const struct TMH_RequestHandler *rh,
118 : struct MHD_Connection *connection,
119 : struct TMH_HandlerContext *hc)
120 : {
121 : static struct MHD_Response *response;
122 :
123 : (void) rh;
124 : (void) hc;
125 21 : if (NULL == response)
126 : {
127 18 : json_t *specs = json_object ();
128 18 : json_t *exchanges = json_array ();
129 18 : json_t *mtc = json_array ();
130 18 : json_t *rgs = json_array ();
131 :
132 18 : GNUNET_assert (NULL != specs);
133 18 : GNUNET_assert (NULL != exchanges);
134 18 : GNUNET_assert (NULL != mtc);
135 18 : GNUNET_assert (NULL != rgs);
136 18 : GNUNET_CONFIGURATION_iterate_sections (TMH_cfg,
137 : &add_report_generator,
138 : rgs);
139 18 : TMH_exchange_get_trusted (&add_exchange,
140 : exchanges);
141 18 : if (0 != (TMH_TCS_EMAIL & TEH_mandatory_tan_channels))
142 1 : GNUNET_assert (0 ==
143 : json_array_append_new (mtc,
144 : json_string ("email")));
145 18 : if (0 != (TMH_TCS_SMS & TEH_mandatory_tan_channels))
146 1 : GNUNET_assert (0 ==
147 : json_array_append_new (mtc,
148 : json_string ("sms")));
149 108 : for (unsigned int i = 0; i<TMH_num_cspecs; i++)
150 : {
151 90 : const struct TALER_CurrencySpecification *cspec = &TMH_cspecs[i];
152 :
153 90 : if (TMH_test_exchange_configured_for_currency (cspec->currency))
154 18 : GNUNET_assert (0 ==
155 : json_object_set_new (
156 : specs,
157 : cspec->currency,
158 : TALER_JSON_currency_specs_to_json (
159 : cspec)));
160 : }
161 18 : response = TALER_MHD_MAKE_JSON_PACK (
162 : GNUNET_JSON_pack_string ("currency",
163 : TMH_currency),
164 : GNUNET_JSON_pack_string ("payment_target_types",
165 : TMH_allowed_payment_targets),
166 : GNUNET_JSON_pack_allow_null (
167 : GNUNET_JSON_pack_string ("phone_regex",
168 : TMH_phone_regex)),
169 : GNUNET_JSON_pack_time_rel ("default_refund_delay",
170 : TMH_default_refund_delay),
171 : GNUNET_JSON_pack_time_rel ("default_wire_transfer_delay",
172 : TMH_default_wire_transfer_delay),
173 : GNUNET_JSON_pack_time_rel ("default_pay_delay",
174 : TMH_default_pay_delay),
175 : GNUNET_JSON_pack_string ("default_persona",
176 : TMH_default_persona),
177 : GNUNET_JSON_pack_allow_null (
178 : GNUNET_JSON_pack_string ("payment_target_regex",
179 : TMH_payment_target_regex)),
180 : GNUNET_JSON_pack_bool ("have_self_provisioning",
181 : GNUNET_YES ==
182 : TMH_have_self_provisioning),
183 : GNUNET_JSON_pack_bool ("have_donau",
184 : true),
185 : GNUNET_JSON_pack_object_steal ("currencies",
186 : specs),
187 : GNUNET_JSON_pack_allow_null (
188 : GNUNET_JSON_pack_object_steal ("spa_options",
189 : TMH_global_spa_config_data)),
190 : GNUNET_JSON_pack_array_steal ("report_generators",
191 : rgs),
192 : GNUNET_JSON_pack_array_steal ("exchanges",
193 : exchanges),
194 : GNUNET_JSON_pack_array_steal ("mandatory_tan_channels",
195 : mtc),
196 : GNUNET_JSON_pack_string (
197 : "implementation",
198 : "urn:net:taler:specs:taler-merchant:c-reference"),
199 : GNUNET_JSON_pack_string ("name",
200 : "taler-merchant"),
201 : GNUNET_JSON_pack_string ("build_version",
202 : PACKAGE_VERSION),
203 : GNUNET_JSON_pack_string ("version",
204 : MERCHANT_PROTOCOL_VERSION));
205 : }
206 21 : return MHD_queue_response (connection,
207 : MHD_HTTP_OK,
208 : response);
209 : }
210 :
211 :
212 : /* end of taler-merchant-httpd_get-config.c */
|