aboutsummaryrefslogtreecommitdiff
path: root/src/backend/anastasis-httpd.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/anastasis-httpd.h')
-rw-r--r--src/backend/anastasis-httpd.h225
1 files changed, 225 insertions, 0 deletions
diff --git a/src/backend/anastasis-httpd.h b/src/backend/anastasis-httpd.h
new file mode 100644
index 0000000..6fe0023
--- /dev/null
+++ b/src/backend/anastasis-httpd.h
@@ -0,0 +1,225 @@
1/*
2 This file is part of TALER
3 Copyright (C) 2019 Taler Systems SA
4
5 TALER is free software; you can redistribute it and/or modify it under the
6 terms of the GNU 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 anastasis/anastasis-httpd.h
18 * @brief HTTP serving layer
19 * @author Christian Grothoff
20 */
21#ifndef ANASTASIS_HTTPD_H
22#define ANASTASIS_HTTPD_H
23
24#include "platform.h"
25#include "anastasis_database_lib.h"
26#include <microhttpd.h>
27#include <taler/taler_mhd_lib.h>
28#include <gnunet/gnunet_mhd_compat.h>
29
30
31/**
32 * For how many years do we allow users to store truth at most? Also
33 * how long we store things if the cost is zero.
34 */
35#define ANASTASIS_MAX_YEARS_STORAGE 5
36
37
38/**
39 * @brief Struct describing an URL and the handler for it.
40 */
41struct AH_RequestHandler
42{
43
44 /**
45 * URL the handler is for.
46 */
47 const char *url;
48
49 /**
50 * Method the handler is for, NULL for "all".
51 */
52 const char *method;
53
54 /**
55 * Mime type to use in reply (hint, can be NULL).
56 */
57 const char *mime_type;
58
59 /**
60 * Raw data for the @e handler
61 */
62 const void *data;
63
64 /**
65 * Number of bytes in @e data, 0 for 0-terminated.
66 */
67 size_t data_size;
68
69
70 /**
71 * Function to call to handle the request.
72 *
73 * @param rh this struct
74 * @param connection the MHD connection to handle
75 * @return MHD result code
76 */
77 MHD_RESULT (*handler)(struct AH_RequestHandler *rh,
78 struct MHD_Connection *connection);
79
80 /**
81 * Default response code.
82 */
83 unsigned int response_code;
84};
85
86
87/**
88 * Each MHD response handler that sets the "connection_cls" to a
89 * non-NULL value must use a struct that has this struct as its first
90 * member. This struct contains a single callback, which will be
91 * invoked to clean up the memory when the contection is completed.
92 */
93struct TM_HandlerContext;
94
95/**
96 * Signature of a function used to clean up the context
97 * we keep in the "connection_cls" of MHD when handling
98 * a request.
99 *
100 * @param hc header of the context to clean up.
101 */
102typedef void
103(*TM_ContextCleanup)(struct TM_HandlerContext *hc);
104
105
106/**
107 * Each MHD response handler that sets the "connection_cls" to a
108 * non-NULL value must use a struct that has this struct as its first
109 * member. This struct contains a single callback, which will be
110 * invoked to clean up the memory when the connection is completed.
111 */
112struct TM_HandlerContext
113{
114
115 /**
116 * Function to execute the handler-specific cleanup of the
117 * (typically larger) context.
118 */
119 TM_ContextCleanup cc;
120
121 /**
122 * Handler-specific context.
123 */
124 void *ctx;
125
126 /**
127 * Which request handler is handling this request?
128 */
129 const struct AH_RequestHandler *rh;
130
131 /**
132 * Asynchronous request context id.
133 */
134 struct GNUNET_AsyncScopeId async_scope_id;
135};
136
137/**
138 * Handle to the database backend.
139 */
140extern struct ANASTASIS_DatabasePlugin *db;
141
142/**
143 * Upload limit to the service, in megabytes.
144 */
145extern unsigned long long AH_upload_limit_mb;
146
147/**
148 * Annual fee for the backup account.
149 */
150extern struct TALER_Amount AH_annual_fee;
151
152/**
153 * Fee for a truth upload.
154 */
155extern struct TALER_Amount AH_truth_upload_fee;
156
157/**
158 * Amount of insurance.
159 */
160extern struct TALER_Amount AH_insurance;
161
162/**
163 * Cost for secure question truth download.
164 */
165extern struct TALER_Amount AH_question_cost;
166
167/**
168 * Our Taler backend to process payments.
169 */
170extern char *AH_backend_url;
171
172/**
173 * Taler currency.
174 */
175extern char *AH_currency;
176
177/**
178 * Our configuration.
179 */
180extern const struct GNUNET_CONFIGURATION_Handle *AH_cfg;
181
182/**
183 * Number of policy uploads permitted per annual fee payment.
184 */
185extern unsigned long long AH_post_counter;
186
187/**
188 * Our fulfillment URL
189 */
190extern char *AH_fulfillment_url;
191
192/**
193 * Our business name.
194 */
195extern char *AH_business_name;
196
197/**
198 * Our server salt.
199 */
200extern struct ANASTASIS_CRYPTO_ProviderSaltP AH_server_salt;
201
202/**
203 * Our context for making HTTP requests.
204 */
205extern struct GNUNET_CURL_Context *AH_ctx;
206
207
208/**
209 * Kick MHD to run now, to be called after MHD_resume_connection().
210 * Basically, we need to explicitly resume MHD's event loop whenever
211 * we made progress serving a request. This function re-schedules
212 * the task processing MHD's activities to run immediately.
213 *
214 * @param cls NULL
215 */
216void
217AH_trigger_daemon (void *cls);
218
219/**
220 * Kick GNUnet Curl scheduler to begin curl interactions.
221 */
222void
223AH_trigger_curl (void);
224
225#endif