diff options
Diffstat (limited to 'src/include/gnunet_json_lib.h')
-rw-r--r-- | src/include/gnunet_json_lib.h | 136 |
1 files changed, 67 insertions, 69 deletions
diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h index bba994d03..3ca4bf729 100644 --- a/src/include/gnunet_json_lib.h +++ b/src/include/gnunet_json_lib.h | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2014, 2015, 2016 GNUnet e.V. | 3 | Copyright (C) 2014, 2015, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file gnunet_json_lib.h | 21 | * @file gnunet_json_lib.h |
22 | * @brief functions to parse JSON objects into GNUnet objects | 22 | * @brief functions to parse JSON objects into GNUnet objects |
@@ -67,8 +67,7 @@ typedef void (*GNUNET_JSON_Cleaner) (void *cls, | |||
67 | /** | 67 | /** |
68 | * @brief Entry in parser specification for #GNUNET_JSON_parse(). | 68 | * @brief Entry in parser specification for #GNUNET_JSON_parse(). |
69 | */ | 69 | */ |
70 | struct GNUNET_JSON_Specification | 70 | struct GNUNET_JSON_Specification { |
71 | { | ||
72 | /** | 71 | /** |
73 | * Function for how to parse this type of entry. | 72 | * Function for how to parse this type of entry. |
74 | */ | 73 | */ |
@@ -126,10 +125,10 @@ struct GNUNET_JSON_Specification | |||
126 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 125 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
127 | */ | 126 | */ |
128 | int | 127 | int |
129 | GNUNET_JSON_parse (const json_t *root, | 128 | GNUNET_JSON_parse(const json_t *root, |
130 | struct GNUNET_JSON_Specification *spec, | 129 | struct GNUNET_JSON_Specification *spec, |
131 | const char **error_json_name, | 130 | const char **error_json_name, |
132 | unsigned int *error_line); | 131 | unsigned int *error_line); |
133 | 132 | ||
134 | 133 | ||
135 | /** | 134 | /** |
@@ -139,7 +138,7 @@ GNUNET_JSON_parse (const json_t *root, | |||
139 | * @param spec specification of the parse operation | 138 | * @param spec specification of the parse operation |
140 | */ | 139 | */ |
141 | void | 140 | void |
142 | GNUNET_JSON_parse_free (struct GNUNET_JSON_Specification *spec); | 141 | GNUNET_JSON_parse_free(struct GNUNET_JSON_Specification *spec); |
143 | 142 | ||
144 | 143 | ||
145 | /* ****************** Canonical parser specifications ******************* */ | 144 | /* ****************** Canonical parser specifications ******************* */ |
@@ -149,7 +148,7 @@ GNUNET_JSON_parse_free (struct GNUNET_JSON_Specification *spec); | |||
149 | * End of a parser specification. | 148 | * End of a parser specification. |
150 | */ | 149 | */ |
151 | struct GNUNET_JSON_Specification | 150 | struct GNUNET_JSON_Specification |
152 | GNUNET_JSON_spec_end (void); | 151 | GNUNET_JSON_spec_end(void); |
153 | 152 | ||
154 | 153 | ||
155 | /** | 154 | /** |
@@ -159,7 +158,7 @@ GNUNET_JSON_spec_end (void); | |||
159 | * @return spec copy of @a spec with optional bit set | 158 | * @return spec copy of @a spec with optional bit set |
160 | */ | 159 | */ |
161 | struct GNUNET_JSON_Specification | 160 | struct GNUNET_JSON_Specification |
162 | GNUNET_JSON_spec_mark_optional (struct GNUNET_JSON_Specification spec); | 161 | GNUNET_JSON_spec_mark_optional(struct GNUNET_JSON_Specification spec); |
163 | 162 | ||
164 | 163 | ||
165 | /** | 164 | /** |
@@ -171,7 +170,7 @@ GNUNET_JSON_spec_mark_optional (struct GNUNET_JSON_Specification spec); | |||
171 | * @param size number of bytes expected in @a obj | 170 | * @param size number of bytes expected in @a obj |
172 | */ | 171 | */ |
173 | struct GNUNET_JSON_Specification | 172 | struct GNUNET_JSON_Specification |
174 | GNUNET_JSON_spec_fixed (const char *name, void *obj, size_t size); | 173 | GNUNET_JSON_spec_fixed(const char *name, void *obj, size_t size); |
175 | 174 | ||
176 | 175 | ||
177 | /** | 176 | /** |
@@ -182,7 +181,7 @@ GNUNET_JSON_spec_fixed (const char *name, void *obj, size_t size); | |||
182 | * @param obj pointer where to write the data (type of `*obj` will determine size) | 181 | * @param obj pointer where to write the data (type of `*obj` will determine size) |
183 | */ | 182 | */ |
184 | #define GNUNET_JSON_spec_fixed_auto(name, obj) \ | 183 | #define GNUNET_JSON_spec_fixed_auto(name, obj) \ |
185 | GNUNET_JSON_spec_fixed (name, obj, sizeof (*obj)) | 184 | GNUNET_JSON_spec_fixed(name, obj, sizeof(*obj)) |
186 | 185 | ||
187 | 186 | ||
188 | /** | 187 | /** |
@@ -194,7 +193,7 @@ GNUNET_JSON_spec_fixed (const char *name, void *obj, size_t size); | |||
194 | * @param[out] size where to store the number of bytes allocated for @a obj | 193 | * @param[out] size where to store the number of bytes allocated for @a obj |
195 | */ | 194 | */ |
196 | struct GNUNET_JSON_Specification | 195 | struct GNUNET_JSON_Specification |
197 | GNUNET_JSON_spec_varsize (const char *name, void **obj, size_t *size); | 196 | GNUNET_JSON_spec_varsize(const char *name, void **obj, size_t *size); |
198 | 197 | ||
199 | 198 | ||
200 | /** | 199 | /** |
@@ -204,7 +203,7 @@ GNUNET_JSON_spec_varsize (const char *name, void **obj, size_t *size); | |||
204 | * @param strptr where to store a pointer to the field | 203 | * @param strptr where to store a pointer to the field |
205 | */ | 204 | */ |
206 | struct GNUNET_JSON_Specification | 205 | struct GNUNET_JSON_Specification |
207 | GNUNET_JSON_spec_string (const char *name, const char **strptr); | 206 | GNUNET_JSON_spec_string(const char *name, const char **strptr); |
208 | 207 | ||
209 | /** | 208 | /** |
210 | * JSON object. | 209 | * JSON object. |
@@ -213,7 +212,7 @@ GNUNET_JSON_spec_string (const char *name, const char **strptr); | |||
213 | * @param[out] jsonp where to store the JSON found under @a name | 212 | * @param[out] jsonp where to store the JSON found under @a name |
214 | */ | 213 | */ |
215 | struct GNUNET_JSON_Specification | 214 | struct GNUNET_JSON_Specification |
216 | GNUNET_JSON_spec_json (const char *name, json_t **jsonp); | 215 | GNUNET_JSON_spec_json(const char *name, json_t **jsonp); |
217 | 216 | ||
218 | 217 | ||
219 | /** | 218 | /** |
@@ -223,7 +222,7 @@ GNUNET_JSON_spec_json (const char *name, json_t **jsonp); | |||
223 | * @param[out] u8 where to store the integer found under @a name | 222 | * @param[out] u8 where to store the integer found under @a name |
224 | */ | 223 | */ |
225 | struct GNUNET_JSON_Specification | 224 | struct GNUNET_JSON_Specification |
226 | GNUNET_JSON_spec_uint8 (const char *name, uint8_t *u8); | 225 | GNUNET_JSON_spec_uint8(const char *name, uint8_t *u8); |
227 | 226 | ||
228 | 227 | ||
229 | /** | 228 | /** |
@@ -233,7 +232,7 @@ GNUNET_JSON_spec_uint8 (const char *name, uint8_t *u8); | |||
233 | * @param[out] u16 where to store the integer found under @a name | 232 | * @param[out] u16 where to store the integer found under @a name |
234 | */ | 233 | */ |
235 | struct GNUNET_JSON_Specification | 234 | struct GNUNET_JSON_Specification |
236 | GNUNET_JSON_spec_uint16 (const char *name, uint16_t *u16); | 235 | GNUNET_JSON_spec_uint16(const char *name, uint16_t *u16); |
237 | 236 | ||
238 | 237 | ||
239 | /** | 238 | /** |
@@ -243,7 +242,7 @@ GNUNET_JSON_spec_uint16 (const char *name, uint16_t *u16); | |||
243 | * @param[out] u32 where to store the integer found under @a name | 242 | * @param[out] u32 where to store the integer found under @a name |
244 | */ | 243 | */ |
245 | struct GNUNET_JSON_Specification | 244 | struct GNUNET_JSON_Specification |
246 | GNUNET_JSON_spec_uint32 (const char *name, uint32_t *u32); | 245 | GNUNET_JSON_spec_uint32(const char *name, uint32_t *u32); |
247 | 246 | ||
248 | 247 | ||
249 | /** | 248 | /** |
@@ -253,7 +252,7 @@ GNUNET_JSON_spec_uint32 (const char *name, uint32_t *u32); | |||
253 | * @param[out] u64 where to store the integer found under @a name | 252 | * @param[out] u64 where to store the integer found under @a name |
254 | */ | 253 | */ |
255 | struct GNUNET_JSON_Specification | 254 | struct GNUNET_JSON_Specification |
256 | GNUNET_JSON_spec_uint64 (const char *name, uint64_t *u64); | 255 | GNUNET_JSON_spec_uint64(const char *name, uint64_t *u64); |
257 | 256 | ||
258 | 257 | ||
259 | /** | 258 | /** |
@@ -263,7 +262,7 @@ GNUNET_JSON_spec_uint64 (const char *name, uint64_t *u64); | |||
263 | * @param[out] boolean where to store the boolean found under @a name | 262 | * @param[out] boolean where to store the boolean found under @a name |
264 | */ | 263 | */ |
265 | struct GNUNET_JSON_Specification | 264 | struct GNUNET_JSON_Specification |
266 | GNUNET_JSON_spec_boolean (const char *name, int *boolean); | 265 | GNUNET_JSON_spec_boolean(const char *name, int *boolean); |
267 | 266 | ||
268 | 267 | ||
269 | /* ************ GNUnet-specific parser specifications ******************* */ | 268 | /* ************ GNUnet-specific parser specifications ******************* */ |
@@ -275,8 +274,8 @@ GNUNET_JSON_spec_boolean (const char *name, int *boolean); | |||
275 | * @param[out] at where to store the absolute time found under @a name | 274 | * @param[out] at where to store the absolute time found under @a name |
276 | */ | 275 | */ |
277 | struct GNUNET_JSON_Specification | 276 | struct GNUNET_JSON_Specification |
278 | GNUNET_JSON_spec_absolute_time (const char *name, | 277 | GNUNET_JSON_spec_absolute_time(const char *name, |
279 | struct GNUNET_TIME_Absolute *at); | 278 | struct GNUNET_TIME_Absolute *at); |
280 | 279 | ||
281 | 280 | ||
282 | /** | 281 | /** |
@@ -286,8 +285,8 @@ GNUNET_JSON_spec_absolute_time (const char *name, | |||
286 | * @param[out] at where to store the absolute time found under @a name | 285 | * @param[out] at where to store the absolute time found under @a name |
287 | */ | 286 | */ |
288 | struct GNUNET_JSON_Specification | 287 | struct GNUNET_JSON_Specification |
289 | GNUNET_JSON_spec_absolute_time_nbo (const char *name, | 288 | GNUNET_JSON_spec_absolute_time_nbo(const char *name, |
290 | struct GNUNET_TIME_AbsoluteNBO *at); | 289 | struct GNUNET_TIME_AbsoluteNBO *at); |
291 | 290 | ||
292 | 291 | ||
293 | /** | 292 | /** |
@@ -297,8 +296,8 @@ GNUNET_JSON_spec_absolute_time_nbo (const char *name, | |||
297 | * @param[out] rt where to store the relative time found under @a name | 296 | * @param[out] rt where to store the relative time found under @a name |
298 | */ | 297 | */ |
299 | struct GNUNET_JSON_Specification | 298 | struct GNUNET_JSON_Specification |
300 | GNUNET_JSON_spec_relative_time (const char *name, | 299 | GNUNET_JSON_spec_relative_time(const char *name, |
301 | struct GNUNET_TIME_Relative *rt); | 300 | struct GNUNET_TIME_Relative *rt); |
302 | 301 | ||
303 | 302 | ||
304 | /** | 303 | /** |
@@ -308,8 +307,8 @@ GNUNET_JSON_spec_relative_time (const char *name, | |||
308 | * @param pk where to store the RSA key found under @a name | 307 | * @param pk where to store the RSA key found under @a name |
309 | */ | 308 | */ |
310 | struct GNUNET_JSON_Specification | 309 | struct GNUNET_JSON_Specification |
311 | GNUNET_JSON_spec_rsa_public_key (const char *name, | 310 | GNUNET_JSON_spec_rsa_public_key(const char *name, |
312 | struct GNUNET_CRYPTO_RsaPublicKey **pk); | 311 | struct GNUNET_CRYPTO_RsaPublicKey **pk); |
313 | 312 | ||
314 | 313 | ||
315 | /** | 314 | /** |
@@ -319,8 +318,8 @@ GNUNET_JSON_spec_rsa_public_key (const char *name, | |||
319 | * @param sig where to store the RSA signature found under @a name | 318 | * @param sig where to store the RSA signature found under @a name |
320 | */ | 319 | */ |
321 | struct GNUNET_JSON_Specification | 320 | struct GNUNET_JSON_Specification |
322 | GNUNET_JSON_spec_rsa_signature (const char *name, | 321 | GNUNET_JSON_spec_rsa_signature(const char *name, |
323 | struct GNUNET_CRYPTO_RsaSignature **sig); | 322 | struct GNUNET_CRYPTO_RsaSignature **sig); |
324 | 323 | ||
325 | 324 | ||
326 | /** | 325 | /** |
@@ -330,9 +329,9 @@ GNUNET_JSON_spec_rsa_signature (const char *name, | |||
330 | * @return JSON Specification | 329 | * @return JSON Specification |
331 | */ | 330 | */ |
332 | struct GNUNET_JSON_Specification | 331 | struct GNUNET_JSON_Specification |
333 | GNUNET_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, | 332 | GNUNET_JSON_spec_gnsrecord(struct GNUNET_GNSRECORD_Data **rd, |
334 | unsigned int *rd_count, | 333 | unsigned int *rd_count, |
335 | char **name); | 334 | char **name); |
336 | 335 | ||
337 | 336 | ||
338 | /* ****************** Generic generator interface ******************* */ | 337 | /* ****************** Generic generator interface ******************* */ |
@@ -347,7 +346,7 @@ GNUNET_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, | |||
347 | * @return json string that encodes @a data | 346 | * @return json string that encodes @a data |
348 | */ | 347 | */ |
349 | json_t * | 348 | json_t * |
350 | GNUNET_JSON_from_data (const void *data, size_t size); | 349 | GNUNET_JSON_from_data(const void *data, size_t size); |
351 | 350 | ||
352 | 351 | ||
353 | /** | 352 | /** |
@@ -358,7 +357,7 @@ GNUNET_JSON_from_data (const void *data, size_t size); | |||
358 | * @return json string that encodes @a data | 357 | * @return json string that encodes @a data |
359 | */ | 358 | */ |
360 | #define GNUNET_JSON_from_data_auto(ptr) \ | 359 | #define GNUNET_JSON_from_data_auto(ptr) \ |
361 | GNUNET_JSON_from_data (ptr, sizeof (*ptr)) | 360 | GNUNET_JSON_from_data(ptr, sizeof(*ptr)) |
362 | 361 | ||
363 | 362 | ||
364 | /** | 363 | /** |
@@ -368,7 +367,7 @@ GNUNET_JSON_from_data (const void *data, size_t size); | |||
368 | * @return a json string with the timestamp in @a stamp | 367 | * @return a json string with the timestamp in @a stamp |
369 | */ | 368 | */ |
370 | json_t * | 369 | json_t * |
371 | GNUNET_JSON_from_time_abs (struct GNUNET_TIME_Absolute stamp); | 370 | GNUNET_JSON_from_time_abs(struct GNUNET_TIME_Absolute stamp); |
372 | 371 | ||
373 | 372 | ||
374 | /** | 373 | /** |
@@ -378,7 +377,7 @@ GNUNET_JSON_from_time_abs (struct GNUNET_TIME_Absolute stamp); | |||
378 | * @return a json string with the timestamp in @a stamp | 377 | * @return a json string with the timestamp in @a stamp |
379 | */ | 378 | */ |
380 | json_t * | 379 | json_t * |
381 | GNUNET_JSON_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO stamp); | 380 | GNUNET_JSON_from_time_abs_nbo(struct GNUNET_TIME_AbsoluteNBO stamp); |
382 | 381 | ||
383 | 382 | ||
384 | /** | 383 | /** |
@@ -388,7 +387,7 @@ GNUNET_JSON_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO stamp); | |||
388 | * @return a json string with the timestamp in @a stamp | 387 | * @return a json string with the timestamp in @a stamp |
389 | */ | 388 | */ |
390 | json_t * | 389 | json_t * |
391 | GNUNET_JSON_from_time_rel (struct GNUNET_TIME_Relative stamp); | 390 | GNUNET_JSON_from_time_rel(struct GNUNET_TIME_Relative stamp); |
392 | 391 | ||
393 | 392 | ||
394 | /** | 393 | /** |
@@ -398,7 +397,7 @@ GNUNET_JSON_from_time_rel (struct GNUNET_TIME_Relative stamp); | |||
398 | * @return corresponding JSON encoding | 397 | * @return corresponding JSON encoding |
399 | */ | 398 | */ |
400 | json_t * | 399 | json_t * |
401 | GNUNET_JSON_from_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *pk); | 400 | GNUNET_JSON_from_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *pk); |
402 | 401 | ||
403 | 402 | ||
404 | /** | 403 | /** |
@@ -408,7 +407,7 @@ GNUNET_JSON_from_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *pk); | |||
408 | * @return corresponding JSON encoding | 407 | * @return corresponding JSON encoding |
409 | */ | 408 | */ |
410 | json_t * | 409 | json_t * |
411 | GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig); | 410 | GNUNET_JSON_from_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *sig); |
412 | 411 | ||
413 | /** | 412 | /** |
414 | * Convert Gns record to JSON. | 413 | * Convert Gns record to JSON. |
@@ -418,17 +417,16 @@ GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig); | |||
418 | * @return corresponding JSON encoding | 417 | * @return corresponding JSON encoding |
419 | */ | 418 | */ |
420 | json_t * | 419 | json_t * |
421 | GNUNET_JSON_from_gnsrecord (const char *rname, | 420 | GNUNET_JSON_from_gnsrecord(const char *rname, |
422 | const struct GNUNET_GNSRECORD_Data *rd, | 421 | const struct GNUNET_GNSRECORD_Data *rd, |
423 | unsigned int rd_count); | 422 | unsigned int rd_count); |
424 | 423 | ||
425 | /* ******************* Helpers for MHD upload handling ******************* */ | 424 | /* ******************* Helpers for MHD upload handling ******************* */ |
426 | 425 | ||
427 | /** | 426 | /** |
428 | * Return codes from #GNUNET_JSON_post_parser(). | 427 | * Return codes from #GNUNET_JSON_post_parser(). |
429 | */ | 428 | */ |
430 | enum GNUNET_JSON_PostResult | 429 | enum GNUNET_JSON_PostResult { |
431 | { | ||
432 | /** | 430 | /** |
433 | * Parsing successful, JSON result is in `*json`. | 431 | * Parsing successful, JSON result is in `*json`. |
434 | */ | 432 | */ |
@@ -472,12 +470,12 @@ enum GNUNET_JSON_PostResult | |||
472 | * @return result code indicating the status of the operation | 470 | * @return result code indicating the status of the operation |
473 | */ | 471 | */ |
474 | enum GNUNET_JSON_PostResult | 472 | enum GNUNET_JSON_PostResult |
475 | GNUNET_JSON_post_parser (size_t buffer_max, | 473 | GNUNET_JSON_post_parser(size_t buffer_max, |
476 | struct MHD_Connection *connection, | 474 | struct MHD_Connection *connection, |
477 | void **con_cls, | 475 | void **con_cls, |
478 | const char *upload_data, | 476 | const char *upload_data, |
479 | size_t *upload_data_size, | 477 | size_t *upload_data_size, |
480 | json_t **json); | 478 | json_t **json); |
481 | 479 | ||
482 | 480 | ||
483 | /** | 481 | /** |
@@ -488,7 +486,7 @@ GNUNET_JSON_post_parser (size_t buffer_max, | |||
488 | * #GNUNET_JSON_post_parser(), to be cleaned up | 486 | * #GNUNET_JSON_post_parser(), to be cleaned up |
489 | */ | 487 | */ |
490 | void | 488 | void |
491 | GNUNET_JSON_post_parser_cleanup (void *con_cls); | 489 | GNUNET_JSON_post_parser_cleanup(void *con_cls); |
492 | 490 | ||
493 | 491 | ||
494 | /* ****************** GETOPT JSON helper ******************* */ | 492 | /* ****************** GETOPT JSON helper ******************* */ |
@@ -504,11 +502,11 @@ GNUNET_JSON_post_parser_cleanup (void *con_cls); | |||
504 | * @param[out] val set to the JSON specified at the command line | 502 | * @param[out] val set to the JSON specified at the command line |
505 | */ | 503 | */ |
506 | struct GNUNET_GETOPT_CommandLineOption | 504 | struct GNUNET_GETOPT_CommandLineOption |
507 | GNUNET_JSON_getopt (char shortName, | 505 | GNUNET_JSON_getopt(char shortName, |
508 | const char *name, | 506 | const char *name, |
509 | const char *argumentHelp, | 507 | const char *argumentHelp, |
510 | const char *description, | 508 | const char *description, |
511 | json_t **json); | 509 | json_t **json); |
512 | 510 | ||
513 | #endif | 511 | #endif |
514 | 512 | ||