summaryrefslogtreecommitdiff
path: root/src/include/gnunet_json_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_json_lib.h')
-rw-r--r--src/include/gnunet_json_lib.h136
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 */
70struct GNUNET_JSON_Specification 70struct 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 */
128int 127int
129GNUNET_JSON_parse (const json_t *root, 128GNUNET_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 */
141void 140void
142GNUNET_JSON_parse_free (struct GNUNET_JSON_Specification *spec); 141GNUNET_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 */
151struct GNUNET_JSON_Specification 150struct GNUNET_JSON_Specification
152GNUNET_JSON_spec_end (void); 151GNUNET_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 */
161struct GNUNET_JSON_Specification 160struct GNUNET_JSON_Specification
162GNUNET_JSON_spec_mark_optional (struct GNUNET_JSON_Specification spec); 161GNUNET_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 */
173struct GNUNET_JSON_Specification 172struct GNUNET_JSON_Specification
174GNUNET_JSON_spec_fixed (const char *name, void *obj, size_t size); 173GNUNET_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 */
196struct GNUNET_JSON_Specification 195struct GNUNET_JSON_Specification
197GNUNET_JSON_spec_varsize (const char *name, void **obj, size_t *size); 196GNUNET_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 */
206struct GNUNET_JSON_Specification 205struct GNUNET_JSON_Specification
207GNUNET_JSON_spec_string (const char *name, const char **strptr); 206GNUNET_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 */
215struct GNUNET_JSON_Specification 214struct GNUNET_JSON_Specification
216GNUNET_JSON_spec_json (const char *name, json_t **jsonp); 215GNUNET_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 */
225struct GNUNET_JSON_Specification 224struct GNUNET_JSON_Specification
226GNUNET_JSON_spec_uint8 (const char *name, uint8_t *u8); 225GNUNET_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 */
235struct GNUNET_JSON_Specification 234struct GNUNET_JSON_Specification
236GNUNET_JSON_spec_uint16 (const char *name, uint16_t *u16); 235GNUNET_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 */
245struct GNUNET_JSON_Specification 244struct GNUNET_JSON_Specification
246GNUNET_JSON_spec_uint32 (const char *name, uint32_t *u32); 245GNUNET_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 */
255struct GNUNET_JSON_Specification 254struct GNUNET_JSON_Specification
256GNUNET_JSON_spec_uint64 (const char *name, uint64_t *u64); 255GNUNET_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 */
265struct GNUNET_JSON_Specification 264struct GNUNET_JSON_Specification
266GNUNET_JSON_spec_boolean (const char *name, int *boolean); 265GNUNET_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 */
277struct GNUNET_JSON_Specification 276struct GNUNET_JSON_Specification
278GNUNET_JSON_spec_absolute_time (const char *name, 277GNUNET_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 */
288struct GNUNET_JSON_Specification 287struct GNUNET_JSON_Specification
289GNUNET_JSON_spec_absolute_time_nbo (const char *name, 288GNUNET_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 */
299struct GNUNET_JSON_Specification 298struct GNUNET_JSON_Specification
300GNUNET_JSON_spec_relative_time (const char *name, 299GNUNET_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 */
310struct GNUNET_JSON_Specification 309struct GNUNET_JSON_Specification
311GNUNET_JSON_spec_rsa_public_key (const char *name, 310GNUNET_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 */
321struct GNUNET_JSON_Specification 320struct GNUNET_JSON_Specification
322GNUNET_JSON_spec_rsa_signature (const char *name, 321GNUNET_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 */
332struct GNUNET_JSON_Specification 331struct GNUNET_JSON_Specification
333GNUNET_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, 332GNUNET_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 */
349json_t * 348json_t *
350GNUNET_JSON_from_data (const void *data, size_t size); 349GNUNET_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 */
370json_t * 369json_t *
371GNUNET_JSON_from_time_abs (struct GNUNET_TIME_Absolute stamp); 370GNUNET_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 */
380json_t * 379json_t *
381GNUNET_JSON_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO stamp); 380GNUNET_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 */
390json_t * 389json_t *
391GNUNET_JSON_from_time_rel (struct GNUNET_TIME_Relative stamp); 390GNUNET_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 */
400json_t * 399json_t *
401GNUNET_JSON_from_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *pk); 400GNUNET_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 */
410json_t * 409json_t *
411GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig); 410GNUNET_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 */
420json_t * 419json_t *
421GNUNET_JSON_from_gnsrecord (const char *rname, 420GNUNET_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 */
430enum GNUNET_JSON_PostResult 429enum 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 */
474enum GNUNET_JSON_PostResult 472enum GNUNET_JSON_PostResult
475GNUNET_JSON_post_parser (size_t buffer_max, 473GNUNET_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 */
490void 488void
491GNUNET_JSON_post_parser_cleanup (void *con_cls); 489GNUNET_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 */
506struct GNUNET_GETOPT_CommandLineOption 504struct GNUNET_GETOPT_CommandLineOption
507GNUNET_JSON_getopt (char shortName, 505GNUNET_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