anastasis-httpd_config.c (4707B)
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 &p->cost)); 69 GNUNET_assert ( 70 0 == 71 json_array_append_new (method_arr, 72 method)); 73 } 74 75 76 enum MHD_Result 77 AH_handler_config (struct AH_RequestHandler *rh, 78 struct MHD_Connection *connection) 79 { 80 static struct MHD_Response *response; 81 82 if (NULL == response) 83 { 84 json_t *method_arr = json_array (); 85 86 GNUNET_assert (NULL != method_arr); 87 { 88 json_t *method; 89 90 method = GNUNET_JSON_PACK ( 91 GNUNET_JSON_pack_string ("type", 92 "question"), 93 TALER_JSON_pack_amount ("cost", 94 &AH_question_cost)); 95 GNUNET_assert ( 96 0 == 97 json_array_append_new (method_arr, 98 method)); 99 } 100 GNUNET_CONFIGURATION_iterate_sections (AH_cfg, 101 &add_methods, 102 method_arr); 103 104 response = TALER_MHD_MAKE_JSON_PACK ( 105 GNUNET_JSON_pack_string ("name", 106 "anastasis"), 107 /* Deliberately incompatible with 0:x:x: the key derivation was fixed to 108 use the full context string, so every key derived by an older client 109 differs and backups made with one cannot be recovered by the other. */ 110 GNUNET_JSON_pack_string ("version", 111 "2:0:1"), 112 GNUNET_JSON_pack_string ("build_version", 113 PACKAGE_VERSION), 114 GNUNET_JSON_pack_string ("implementation", 115 "urn:net:taler:specs:anastasis:c-reference"), 116 GNUNET_JSON_pack_string ("business_name", 117 AH_business_name), 118 GNUNET_JSON_pack_array_steal ("methods", 119 method_arr), 120 GNUNET_JSON_pack_uint64 ("storage_limit_in_megabytes", 121 AH_upload_limit_mb), 122 TALER_JSON_pack_amount ("annual_fee", 123 &AH_annual_fee), 124 TALER_JSON_pack_amount ("truth_upload_fee", 125 &AH_truth_upload_fee), 126 TALER_JSON_pack_amount ("liability_limit", 127 &AH_insurance), 128 GNUNET_JSON_pack_data_auto ("provider_salt", 129 &AH_provider_salt)); 130 } 131 return MHD_queue_response (connection, 132 MHD_HTTP_OK, 133 response); 134 } 135 136 137 /* end of anastasis-httpd_config.c */