anastasis-httpd_config.c (6089B)
1 /* 2 This file is part of Anastasis 3 Copyright (C) 2020, 2021, 2024 Anastasis SARL 4 5 Anastasis 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 Anastasis 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 Affero General Public License for more details. 12 13 You should have received a copy of the GNU Affero General Public License along with 14 Anastasis; see the file COPYING.GPL. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file backend/anastasis-httpd_config.c 18 * @brief headers for /terms handler 19 * @author Christian Grothoff 20 * @author Dennis Neufeld 21 * @author Dominik Meister 22 */ 23 #include "platform.h" 24 #include <jansson.h> 25 #include "anastasis-httpd_config.h" 26 #include "anastasis-httpd.h" 27 #include <taler/taler_json_lib.h> 28 #include "anastasis_authorization_lib.h" 29 30 31 /** 32 * Add enabled methods and their fees to the ``/config`` response. 33 * 34 * @param[in,out] cls a `json_t` array to build 35 * @param section configuration section to inspect 36 */ 37 static void 38 add_methods (void *cls, 39 const char *section) 40 { 41 json_t *method_arr = cls; 42 struct ANASTASIS_AuthorizationPlugin *p; 43 json_t *method; 44 45 if (0 != strncasecmp (section, 46 "authorization-", 47 strlen ("authorization-"))) 48 return; 49 if (GNUNET_YES != 50 GNUNET_CONFIGURATION_get_value_yesno (AH_cfg, 51 section, 52 "ENABLED")) 53 return; 54 section += strlen ("authorization-"); 55 p = ANASTASIS_authorization_plugin_load (section, 56 AH_cfg); 57 if (NULL == p) 58 { 59 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 60 "Failed to load authorization plugin `%s'\n", 61 section); 62 return; 63 } 64 method = GNUNET_JSON_PACK ( 65 GNUNET_JSON_pack_string ("type", 66 section), 67 TALER_JSON_pack_amount ("cost", 68 AH_primary_price (&p->costs)), 69 TALER_JSON_pack_amount_list ("costs", 70 &p->costs)); 71 GNUNET_assert ( 72 0 == 73 json_array_append_new (method_arr, 74 method)); 75 } 76 77 78 enum MHD_Result 79 AH_handler_config (struct AH_RequestHandler *rh, 80 struct MHD_Connection *connection) 81 { 82 static struct MHD_Response *response; 83 84 if (NULL == response) 85 { 86 json_t *method_arr = json_array (); 87 json_t *currency_arr = json_array (); 88 89 GNUNET_assert (NULL != method_arr); 90 GNUNET_assert (NULL != currency_arr); 91 for (unsigned int i = 0; i<AH_currencies_len; i++) 92 GNUNET_assert (0 == 93 json_array_append_new (currency_arr, 94 json_string (AH_currencies[i]))); 95 { 96 json_t *method; 97 98 method = GNUNET_JSON_PACK ( 99 GNUNET_JSON_pack_string ("type", 100 "question"), 101 TALER_JSON_pack_amount ("cost", 102 AH_primary_price (&AH_question_costs)), 103 TALER_JSON_pack_amount_list ("costs", 104 &AH_question_costs)); 105 GNUNET_assert ( 106 0 == 107 json_array_append_new (method_arr, 108 method)); 109 } 110 GNUNET_CONFIGURATION_iterate_sections (AH_cfg, 111 &add_methods, 112 method_arr); 113 114 response = TALER_MHD_MAKE_JSON_PACK ( 115 GNUNET_JSON_pack_string ("name", 116 "anastasis"), 117 /* Deliberately incompatible with 0:x:x: the key derivation was fixed to 118 use the full context string, so every key derived by an older client 119 differs and backups made with one cannot be recovered by the other. 120 3 adds the plural "…s" fields and "currencies" without removing 121 anything, so the age stays at 1 and a version 2 client still works 122 against us, seeing only the primary currency. */ 123 GNUNET_JSON_pack_string ("version", 124 "3:0:1"), 125 GNUNET_JSON_pack_string ("build_version", 126 PACKAGE_VERSION), 127 GNUNET_JSON_pack_string ("implementation", 128 "urn:net:taler:specs:anastasis:c-reference"), 129 GNUNET_JSON_pack_string ("business_name", 130 AH_business_name), 131 GNUNET_JSON_pack_array_steal ("methods", 132 method_arr), 133 GNUNET_JSON_pack_uint64 ("storage_limit_in_megabytes", 134 AH_upload_limit_mb), 135 GNUNET_JSON_pack_array_steal ("currencies", 136 currency_arr), 137 /* The scalar fields report the primary currency and stay for the 138 benefit of version 2 clients; the plural ones carry the full 139 list. */ 140 TALER_JSON_pack_amount ("annual_fee", 141 AH_primary_price (&AH_annual_fees)), 142 TALER_JSON_pack_amount_list ("annual_fees", 143 &AH_annual_fees), 144 TALER_JSON_pack_amount ("truth_upload_fee", 145 AH_primary_price (&AH_truth_upload_fees)), 146 TALER_JSON_pack_amount_list ("truth_upload_fees", 147 &AH_truth_upload_fees), 148 TALER_JSON_pack_amount ("liability_limit", 149 AH_primary_price (&AH_insurance)), 150 TALER_JSON_pack_amount_list ("liability_limits", 151 &AH_insurance), 152 GNUNET_JSON_pack_data_auto ("provider_salt", 153 &AH_provider_salt)); 154 } 155 return MHD_queue_response (connection, 156 MHD_HTTP_OK, 157 response); 158 } 159 160 161 /* end of anastasis-httpd_config.c */