aboutsummaryrefslogtreecommitdiff
path: root/src/backend/anastasis-httpd_config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/anastasis-httpd_config.c')
-rw-r--r--src/backend/anastasis-httpd_config.c132
1 files changed, 132 insertions, 0 deletions
diff --git a/src/backend/anastasis-httpd_config.c b/src/backend/anastasis-httpd_config.c
new file mode 100644
index 0000000..fff6bcb
--- /dev/null
+++ b/src/backend/anastasis-httpd_config.c
@@ -0,0 +1,132 @@
1/*
2 This file is part of Anastasis
3 Copyright (C) 2020 Taler Systems SA
4
5 Anastasis is free software; you can redistribute it and/or modify it under the
6 terms of the GNU Lesser 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 General Public License for more details.
12
13 You should have received a copy of the GNU 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 */
37static void
38add_methods (void *cls,
39 const char *section)
40{
41 json_t *method_arr = cls;
42 struct ANASTASIS_AuthorizationPlugin *p;
43 struct TALER_Amount cost;
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 (AH_cfg,
52 section,
53 "ENABLED"))
54 return;
55 section += strlen ("authorization-");
56 p = ANASTASIS_authorization_plugin_load (section,
57 AH_cfg,
58 &cost);
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 = json_pack ("{s:s, s:o}",
67 "type",
68 section,
69 "cost",
70 TALER_JSON_from_amount (&cost));
71 GNUNET_assert (NULL != method);
72 GNUNET_assert (
73 0 ==
74 json_array_append_new (method_arr,
75 method));
76}
77
78
79MHD_RESULT
80AH_handler_config (struct AH_RequestHandler *rh,
81 struct MHD_Connection *connection)
82{
83 json_t *method_arr = json_array ();
84
85 GNUNET_assert (NULL != method_arr);
86 {
87 json_t *method;
88
89 method = json_pack ("{s:s, s:o}",
90 "type",
91 "question",
92 "cost",
93 TALER_JSON_from_amount (&AH_question_cost));
94 GNUNET_assert (
95 0 ==
96 json_array_append_new (method_arr,
97 method));
98 }
99 GNUNET_CONFIGURATION_iterate_sections (AH_cfg,
100 &add_methods,
101 method_arr);
102 return TALER_MHD_reply_json_pack (connection,
103 MHD_HTTP_OK,
104 "{s:s, s:s, s:s, s:s, s:o, s:I,"
105 " s:o, s:o, s:o, s:o }",
106 "name",
107 "anastasis",
108 "version",
109 "0:0:0",
110 "business_name",
111 AH_business_name,
112 "currency",
113 (char *) AH_currency,
114 "methods",
115 method_arr,
116 "storage_limit_in_megabytes",
117 (json_int_t) AH_upload_limit_mb,
118 /* 6 */
119 "annual_fee",
120 TALER_JSON_from_amount (&AH_annual_fee),
121 "truth_upload_fee",
122 TALER_JSON_from_amount (
123 &AH_truth_upload_fee),
124 "liability_limit",
125 TALER_JSON_from_amount (&AH_insurance),
126 "server_salt",
127 GNUNET_JSON_from_data_auto (
128 &AH_server_salt));
129}
130
131
132/* end of anastasis-httpd_config.c */