diff options
Diffstat (limited to 'src/reducer/anastasis_api_redux.h')
-rw-r--r-- | src/reducer/anastasis_api_redux.h | 347 |
1 files changed, 347 insertions, 0 deletions
diff --git a/src/reducer/anastasis_api_redux.h b/src/reducer/anastasis_api_redux.h new file mode 100644 index 0000000..19d9466 --- /dev/null +++ b/src/reducer/anastasis_api_redux.h | |||
@@ -0,0 +1,347 @@ | |||
1 | /* | ||
2 | This file is part of Anastasis | ||
3 | Copyright (C) 2020, 2021 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 redux/anastasis_api_redux.h | ||
18 | * @brief anastasis reducer api, internal data structures | ||
19 | * @author Christian Grothoff | ||
20 | * @author Dominik Meister | ||
21 | * @author Dennis Neufeld | ||
22 | */ | ||
23 | #ifndef ANASTASIS_API_REDUX_H | ||
24 | #define ANASTASIS_API_REDUX_H | ||
25 | |||
26 | |||
27 | #define ANASTASIS_GENERIC_STATES(REDUX_STATE) \ | ||
28 | REDUX_STATE (ERROR) \ | ||
29 | REDUX_STATE (CONTINENT_SELECTING) \ | ||
30 | REDUX_STATE (COUNTRY_SELECTING) \ | ||
31 | REDUX_STATE (USER_ATTRIBUTES_COLLECTING) | ||
32 | |||
33 | #define GENERATE_GENERIC_ENUM(ENUM) ANASTASIS_GENERIC_STATE_ ## ENUM, | ||
34 | |||
35 | enum ANASTASIS_GenericState | ||
36 | { | ||
37 | ANASTASIS_GENERIC_STATES (GENERATE_GENERIC_ENUM) | ||
38 | }; | ||
39 | |||
40 | #undef GENERATE_GENERIC_ENUM | ||
41 | |||
42 | #define ANASTASIS_BACKUP_STATES(REDUX_STATE) \ | ||
43 | ANASTASIS_GENERIC_STATES (REDUX_STATE) \ | ||
44 | REDUX_STATE (AUTHENTICATIONS_EDITING) \ | ||
45 | REDUX_STATE (POLICIES_REVIEWING) \ | ||
46 | REDUX_STATE (SECRET_EDITING) \ | ||
47 | REDUX_STATE (TRUTHS_PAYING) \ | ||
48 | REDUX_STATE (POLICIES_PAYING) \ | ||
49 | REDUX_STATE (BACKUP_FINISHED) | ||
50 | |||
51 | #define GENERATE_BACKUP_ENUM(ENUM) ANASTASIS_BACKUP_STATE_ ## ENUM, | ||
52 | |||
53 | enum ANASTASIS_BackupState | ||
54 | { | ||
55 | ANASTASIS_BACKUP_STATES (GENERATE_BACKUP_ENUM) | ||
56 | }; | ||
57 | |||
58 | #undef GENERATE_BACKUP_ENUM | ||
59 | |||
60 | #define ANASTASIS_RECOVERY_STATES(REDUX_STATE) \ | ||
61 | ANASTASIS_GENERIC_STATES (REDUX_STATE) \ | ||
62 | REDUX_STATE (SECRET_SELECTING) \ | ||
63 | REDUX_STATE (CHALLENGE_SELECTING) \ | ||
64 | REDUX_STATE (CHALLENGE_PAYING) \ | ||
65 | REDUX_STATE (CHALLENGE_SOLVING) \ | ||
66 | REDUX_STATE (RECOVERY_FINISHED) | ||
67 | |||
68 | #define GENERATE_RECOVERY_ENUM(ENUM) ANASTASIS_RECOVERY_STATE_ ## ENUM, | ||
69 | |||
70 | enum ANASTASIS_RecoveryState | ||
71 | { | ||
72 | ANASTASIS_RECOVERY_STATES (GENERATE_RECOVERY_ENUM) | ||
73 | }; | ||
74 | |||
75 | #undef GENERATE_RECOVERY_ENUM | ||
76 | |||
77 | |||
78 | /** | ||
79 | * CURL context to be used by all operations. | ||
80 | */ | ||
81 | extern struct GNUNET_CURL_Context *ANASTASIS_REDUX_ctx_; | ||
82 | |||
83 | |||
84 | /** | ||
85 | * Initialize reducer subsystem. | ||
86 | * | ||
87 | * @param ctx context to use for CURL requests. | ||
88 | */ | ||
89 | void | ||
90 | ANASTASIS_redux_init (struct GNUNET_CURL_Context *ctx); | ||
91 | |||
92 | |||
93 | /** | ||
94 | * Terminate reducer subsystem. | ||
95 | */ | ||
96 | void | ||
97 | ANASTASIS_redux_done (void); | ||
98 | |||
99 | |||
100 | /** | ||
101 | * Produce an initial state with an initialized list of | ||
102 | * continents. | ||
103 | */ | ||
104 | json_t * | ||
105 | ANASTASIS_REDUX_load_continents_ (void); | ||
106 | |||
107 | |||
108 | /** | ||
109 | * Returns the enum value to a string value of a state. | ||
110 | * | ||
111 | * @param state_string | ||
112 | * @return #ANASTASIS_GENERIC_STATE_ERROR on error | ||
113 | */ | ||
114 | enum ANASTASIS_GenericState | ||
115 | ANASTASIS_generic_state_from_string_ (const char *state_string); | ||
116 | |||
117 | |||
118 | /** | ||
119 | * Returns the string value of a state. | ||
120 | * | ||
121 | * @param state_string | ||
122 | * @return NULL on error | ||
123 | */ | ||
124 | const char * | ||
125 | ANASTASIS_generic_state_to_string_ (enum ANASTASIS_GenericState gs); | ||
126 | |||
127 | |||
128 | /** | ||
129 | * Returns the enum value to a string value of a state. | ||
130 | * | ||
131 | * @param state_string | ||
132 | * @return #ANASTASIS_BACKUP_STATE_ERROR on error | ||
133 | */ | ||
134 | enum ANASTASIS_BackupState | ||
135 | ANASTASIS_backup_state_from_string_ (const char *state_string); | ||
136 | |||
137 | |||
138 | /** | ||
139 | * Returns the string value of a state. | ||
140 | * | ||
141 | * @param state_string | ||
142 | * @return NULL on error | ||
143 | */ | ||
144 | const char * | ||
145 | ANASTASIS_backup_state_to_string_ (enum ANASTASIS_BackupState bs); | ||
146 | |||
147 | |||
148 | /** | ||
149 | * Returns the enum value to a string value of a state. | ||
150 | * | ||
151 | * @param state_string | ||
152 | * @return XXX on error | ||
153 | */ | ||
154 | enum ANASTASIS_RecoveryState | ||
155 | ANASTASIS_recovery_state_from_string_ (const char *state_string); | ||
156 | |||
157 | |||
158 | /** | ||
159 | * Returns the string value of a state. | ||
160 | * | ||
161 | * @param state_string | ||
162 | * @return NULL on error | ||
163 | */ | ||
164 | const char * | ||
165 | ANASTASIS_recovery_state_to_string_ (enum ANASTASIS_RecoveryState rs); | ||
166 | |||
167 | |||
168 | /** | ||
169 | * Function to return a json error response. | ||
170 | * | ||
171 | * @param cb callback to give error to | ||
172 | * @param cb_cls callback closure | ||
173 | * @param ec error code | ||
174 | * @param detail error detail | ||
175 | */ | ||
176 | void | ||
177 | ANASTASIS_redux_fail_ (ANASTASIS_ActionCallback cb, | ||
178 | void *cb_cls, | ||
179 | enum TALER_ErrorCode ec, | ||
180 | const char *detail); | ||
181 | |||
182 | |||
183 | /** | ||
184 | * DispatchHandler/Callback function which is called for a | ||
185 | * "add_provider" action. Adds another Anastasis provider | ||
186 | * to the list of available providers for storing information. | ||
187 | * | ||
188 | * @param state state to operate on | ||
189 | * @param arguments arguments with a provider URL to add | ||
190 | * @param cb callback to call during/after operation | ||
191 | * @param cb_cls callback closure | ||
192 | * @return true if @a cb was invoked | ||
193 | */ | ||
194 | bool | ||
195 | ANASTASIS_add_provider_ (json_t *state, | ||
196 | const json_t *arguments, | ||
197 | ANASTASIS_ActionCallback cb, | ||
198 | void *cb_cls); | ||
199 | |||
200 | |||
201 | /** | ||
202 | * Adds the server configuration of the Anastasis provider | ||
203 | * at @a url to the json @a state. Checks if we have | ||
204 | * the provider information already available. If so, | ||
205 | * imports it into @a state. If not, queries the provider, | ||
206 | * generating a success or failure outcome asynchronously. | ||
207 | * | ||
208 | * @param cr the config request | ||
209 | * @param[in,out] state the json state to operate on | ||
210 | * @param cb callback to call during/after operation | ||
211 | * @param cb_cls callback closure | ||
212 | * @return handle to cancel asynchronous operation, NULL if | ||
213 | * we completed synchronously | ||
214 | */ | ||
215 | struct ANASTASIS_ReduxAction * | ||
216 | ANASTASIS_REDUX_add_provider_to_state_ (const char *url, | ||
217 | json_t *state, | ||
218 | ANASTASIS_ActionCallback cb, | ||
219 | void *cb_cls); | ||
220 | |||
221 | |||
222 | /** | ||
223 | * A generic DispatchHandler/Callback function which is called for a | ||
224 | * "back" action. | ||
225 | * | ||
226 | * @param state state to operate on | ||
227 | * @param arguments arguments to use for operation on state | ||
228 | * @param cb callback to call during/after operation | ||
229 | * @param cb_cls callback closure | ||
230 | * @return NULL (no asynchronous action) | ||
231 | */ | ||
232 | struct ANASTASIS_ReduxAction * | ||
233 | ANASTASIS_back_generic_decrement_ (json_t *state, | ||
234 | const json_t *arguments, | ||
235 | ANASTASIS_ActionCallback cb, | ||
236 | void *cb_cls); | ||
237 | |||
238 | |||
239 | /** | ||
240 | * Function to load json containing all countries. | ||
241 | * Returns the countries. | ||
242 | * | ||
243 | * @return json_t * | ||
244 | */ | ||
245 | const json_t * | ||
246 | ANASTASIS_redux_countries_init_ (void); | ||
247 | |||
248 | |||
249 | /** | ||
250 | * Operates on a recovery state depending on given #ANASTASIS_RecoveryState | ||
251 | * and #ANASTASIS_RecoveryAction. The new #ANASTASIS_RecoveryState is returned | ||
252 | * by a callback function. | ||
253 | * This function can do network access to talk to anastasis service providers. | ||
254 | * | ||
255 | * @param ctx the CURL context used to connect to the backend | ||
256 | * @param[in,out] state input/output state (to be modified) | ||
257 | * @param action what action to perform | ||
258 | * @param arguments data for the @a action | ||
259 | * @param cb function to call with the result | ||
260 | * @param cb_cls closure for @a cb | ||
261 | */ | ||
262 | struct ANASTASIS_ReduxAction * | ||
263 | ANASTASIS_recovery_action_ (json_t *state, | ||
264 | const char *action, | ||
265 | const json_t *arguments, | ||
266 | ANASTASIS_ActionCallback cb, | ||
267 | void *cb_cls); | ||
268 | |||
269 | |||
270 | /** | ||
271 | * DispatchHandler/Callback function which is called for a | ||
272 | * "enter_user_attributes" action after verifying that the | ||
273 | * arguments provided were OK and the state transition was | ||
274 | * initiated. Begins the actual recovery logic. | ||
275 | * | ||
276 | * Returns an #ANASTASIS_ReduxAction. | ||
277 | * | ||
278 | * @param state state to operate on | ||
279 | * @param cb callback to call during/after operation | ||
280 | * @param cb_cls callback closure | ||
281 | * @return NULL | ||
282 | */ | ||
283 | struct ANASTASIS_ReduxAction * | ||
284 | ANASTASIS_REDUX_recovery_challenge_begin_ (json_t *state, | ||
285 | const json_t *arguments, | ||
286 | ANASTASIS_ActionCallback cb, | ||
287 | void *cb_cls); | ||
288 | |||
289 | |||
290 | /** | ||
291 | * DispatchHandler/Callback function which is called for a | ||
292 | * "enter_user_attributes" action after verifying that the | ||
293 | * arguments provided were OK and the state transition was | ||
294 | * initiated. Begins the actual backup logic. | ||
295 | * | ||
296 | * Returns an #ANASTASIS_ReduxAction. | ||
297 | * | ||
298 | * @param state state to operate on | ||
299 | * @param cb callback to call during/after operation | ||
300 | * @param cb_cls callback closure | ||
301 | */ | ||
302 | struct ANASTASIS_ReduxAction * | ||
303 | ANASTASIS_REDUX_backup_begin_ (json_t *state, | ||
304 | const json_t *arguments, | ||
305 | ANASTASIS_ActionCallback cb, | ||
306 | void *cb_cls); | ||
307 | |||
308 | |||
309 | /** | ||
310 | * Operates on a backup state depending on given #ANASTASIS_BackupState | ||
311 | * and #ANASTASIS_BackupAction. The new #ANASTASIS_BackupState is returned | ||
312 | * by a callback function. | ||
313 | * This function can do network access to talk to anastasis service providers. | ||
314 | * | ||
315 | * @param ctx the CURL context used to connect to the backend | ||
316 | * @param[in,out] state input/output state (to be modified) | ||
317 | * @param action what action to perform | ||
318 | * @param arguments data for the @a action | ||
319 | * @param cb function to call with the result | ||
320 | * @param cb_cls closure for @a cb | ||
321 | */ | ||
322 | struct ANASTASIS_ReduxAction * | ||
323 | ANASTASIS_backup_action_ (json_t *state, | ||
324 | const char *action, | ||
325 | const json_t *arguments, | ||
326 | ANASTASIS_ActionCallback cb, | ||
327 | void *cb_cls); | ||
328 | |||
329 | |||
330 | /** | ||
331 | * Generic container for an action with asynchronous activities. | ||
332 | */ | ||
333 | struct ANASTASIS_ReduxAction | ||
334 | { | ||
335 | /** | ||
336 | * Function to call to clean up. | ||
337 | */ | ||
338 | void (*cleanup)(void *cls); | ||
339 | |||
340 | /** | ||
341 | * Action-specific state, closure for @e cleanup. | ||
342 | */ | ||
343 | void *cleanup_cls; | ||
344 | }; | ||
345 | |||
346 | |||
347 | #endif | ||