taler-merchant-httpd_get-config.c (7895B)
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 taler-merchant-httpd_get-config.c 18 * @brief implement API for querying configuration data of the backend 19 * @author Florian Dold 20 */ 21 #include "taler/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 "27:0:15" 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 add_exchange (void *cls, 61 const char *url, 62 const struct TMH_Exchange *exchange) 63 { 64 json_t *xa = cls; 65 json_t *xi; 66 67 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 GNUNET_assert (NULL != xi); 75 GNUNET_assert (0 == 76 json_array_append_new (xa, 77 xi)); 78 } 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 add_report_generator (void *cls, 90 const char *section) 91 { 92 json_t *rgs = cls; 93 94 if (0 != strncasecmp (section, 95 "report-generator-", 96 strlen ("report-generator-"))) 97 return; 98 if (GNUNET_YES != 99 GNUNET_CONFIGURATION_have_value (TMH_cfg, 100 section, 101 "BINARY")) 102 { 103 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, 104 section, 105 "BINARY"); 106 return; 107 } 108 GNUNET_assert (0 == 109 json_array_append_new (rgs, 110 json_string (section 111 + strlen ( 112 "report-generator-")))); 113 } 114 115 116 MHD_RESULT 117 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 if (NULL == response) 126 { 127 json_t *specs = json_object (); 128 json_t *exchanges = json_array (); 129 json_t *mtc = json_array (); 130 json_t *rgs = json_array (); 131 132 GNUNET_assert (NULL != specs); 133 GNUNET_assert (NULL != exchanges); 134 GNUNET_assert (NULL != mtc); 135 GNUNET_assert (NULL != rgs); 136 GNUNET_CONFIGURATION_iterate_sections (TMH_cfg, 137 &add_report_generator, 138 rgs); 139 TMH_exchange_get_trusted (&add_exchange, 140 exchanges); 141 if (0 != (TMH_TCS_EMAIL & TEH_mandatory_tan_channels)) 142 GNUNET_assert (0 == 143 json_array_append_new (mtc, 144 json_string ("email"))); 145 if (0 != (TMH_TCS_SMS & TEH_mandatory_tan_channels)) 146 GNUNET_assert (0 == 147 json_array_append_new (mtc, 148 json_string ("sms"))); 149 for (unsigned int i = 0; i<TMH_num_cspecs; i++) 150 { 151 const struct TALER_CurrencySpecification *cspec = &TMH_cspecs[i]; 152 153 if (TMH_test_exchange_configured_for_currency (cspec->currency)) 154 GNUNET_assert (0 == 155 json_object_set_new ( 156 specs, 157 cspec->currency, 158 TALER_JSON_currency_specs_to_json ( 159 cspec))); 160 } 161 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 #ifdef HAVE_DONAU_DONAU_SERVICE_H 184 GNUNET_JSON_pack_bool ("have_donau", 185 true), 186 #else 187 GNUNET_JSON_pack_bool ("have_donau", 188 false), 189 #endif 190 GNUNET_JSON_pack_object_steal ("currencies", 191 specs), 192 GNUNET_JSON_pack_allow_null ( 193 GNUNET_JSON_pack_object_steal ("spa_options", 194 TMH_global_spa_config_data)), 195 GNUNET_JSON_pack_array_steal ("report_generators", 196 rgs), 197 GNUNET_JSON_pack_array_steal ("exchanges", 198 exchanges), 199 GNUNET_JSON_pack_array_steal ("mandatory_tan_channels", 200 mtc), 201 GNUNET_JSON_pack_string ( 202 "implementation", 203 "urn:net:taler:specs:taler-merchant:c-reference"), 204 GNUNET_JSON_pack_string ("name", 205 "taler-merchant"), 206 GNUNET_JSON_pack_string ("version", 207 MERCHANT_PROTOCOL_VERSION)); 208 } 209 return MHD_queue_response (connection, 210 MHD_HTTP_OK, 211 response); 212 } 213 214 215 /* end of taler-merchant-httpd_get-config.c */