frosix-httpd_config.c (3951B)
1 /* 2 This file is part of Frosix 3 Copyright (C) 2020, 2021 Anastasis SARL 4 5 Frosix 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 Frosix 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 Frosix; see the file COPYING.GPL. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file backend/frosix-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 "frosix-httpd_config.h" 26 #include "frosix-httpd.h" 27 #include "frosix_authorization_plugin.h" 28 #include "frosix_authorization_lib.h" 29 #include <taler/taler_json_lib.h> 30 31 32 /** 33 * Add enabled methods and their fees to the ``/config`` response. 34 * 35 * @param[in,out] cls a `json_t` array to build 36 * @param section configuration section to inspect 37 */ 38 static void 39 add_methods (void *cls, 40 const char *section) 41 { 42 json_t *method_arr = cls; 43 struct FROSIX_AuthorizationPlugin *p; 44 json_t *method; 45 46 if (0 != strncasecmp (section, 47 "authorization-", 48 strlen ("authorization-"))) 49 return; 50 if (GNUNET_YES != 51 GNUNET_CONFIGURATION_get_value_yesno (FH_cfg, 52 section, 53 "ENABLED")) 54 return; 55 section += strlen ("authorization-"); 56 p = FROSIX_authorization_plugin_load (section, 57 db, 58 FH_cfg); 59 if (NULL == p) 60 { 61 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 62 "Failed to load authorization plugin `%s'\n", 63 section); 64 return; 65 } 66 method = GNUNET_JSON_PACK ( 67 GNUNET_JSON_pack_string ("type", 68 section), 69 TALER_JSON_pack_amount ("cost", 70 &p->cost)); 71 GNUNET_assert ( 72 0 == 73 json_array_append_new (method_arr, 74 method)); 75 } 76 77 78 MHD_RESULT 79 FH_handler_config (struct FH_RequestHandler *rh, 80 struct MHD_Connection *connection) 81 { 82 json_t *method_arr = json_array (); 83 84 GNUNET_assert (NULL != method_arr); 85 { 86 json_t *method; 87 88 method = GNUNET_JSON_PACK ( 89 GNUNET_JSON_pack_string ("type", 90 "question"), 91 TALER_JSON_pack_amount ("cost", 92 &FH_question_cost)); 93 GNUNET_assert ( 94 0 == 95 json_array_append_new (method_arr, 96 method)); 97 } 98 GNUNET_CONFIGURATION_iterate_sections (FH_cfg, 99 &add_methods, 100 method_arr); 101 return TALER_MHD_REPLY_JSON_PACK ( 102 connection, 103 MHD_HTTP_OK, 104 GNUNET_JSON_pack_string ("name", 105 "frosix"), 106 GNUNET_JSON_pack_string ("version", 107 "0:0:0"), 108 GNUNET_JSON_pack_string ("business_name", 109 FH_business_name), 110 GNUNET_JSON_pack_array_steal ("methods", 111 method_arr), 112 TALER_JSON_pack_amount ("annual_fee", 113 &FH_annual_fee), 114 TALER_JSON_pack_amount ("signature_creation_fee", 115 &FH_signature_creation_fee), 116 GNUNET_JSON_pack_data_auto ("provider_salt", 117 &FH_provider_salt), 118 GNUNET_JSON_pack_data_auto ("public_key", 119 &FH_pub_sig_key)); 120 } 121 122 123 /* end of frosix-httpd_config.c */