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