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