![]() |
GNUnet
0.11.x
|
functions to parse JSON objects into GNUnet objects More...
Go to the source code of this file.
Data Structures | |
struct | GNUNET_JSON_Specification |
Entry in parser specification for GNUNET_JSON_parse(). More... | |
Macros | |
#define | GNUNET_JSON_spec_fixed_auto(name, obj) GNUNET_JSON_spec_fixed (name, obj, sizeof(*obj)) |
Fixed size object (in network byte order, encoded using Crockford Base32hex encoding). More... | |
#define | GNUNET_JSON_from_data_auto(ptr) GNUNET_JSON_from_data (ptr, sizeof(*ptr)) |
Convert binary data to a JSON string with the base32crockford encoding. More... | |
Typedefs | |
typedef int(* | GNUNET_JSON_Parser) (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) |
Function called to parse JSON argument. More... | |
typedef void(* | GNUNET_JSON_Cleaner) (void *cls, struct GNUNET_JSON_Specification *spec) |
Function called to clean up data from earlier parsing. More... | |
Enumerations | |
enum | GNUNET_JSON_PostResult { GNUNET_JSON_PR_SUCCESS, GNUNET_JSON_PR_CONTINUE, GNUNET_JSON_PR_OUT_OF_MEMORY, GNUNET_JSON_PR_REQUEST_TOO_LARGE, GNUNET_JSON_PR_JSON_INVALID } |
Return codes from GNUNET_JSON_post_parser(). More... | |
Functions | |
enum GNUNET_GenericReturnValue | GNUNET_JSON_parse (const json_t *root, struct GNUNET_JSON_Specification *spec, const char **error_json_name, unsigned int *error_line) |
Navigate and parse data in a JSON tree. More... | |
void | GNUNET_JSON_parse_free (struct GNUNET_JSON_Specification *spec) |
Frees all elements allocated during a GNUNET_JSON_parse() operation. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_end (void) |
End of a parser specification. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_mark_optional (struct GNUNET_JSON_Specification spec) |
Set the "optional" flag for a parser specification entry. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_fixed (const char *name, void *obj, size_t size) |
Variable size object (in network byte order, encoded using Crockford Base32hex encoding). More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_varsize (const char *name, void **obj, size_t *size) |
Variable size object (in network byte order, encoded using Crockford Base32hex encoding). More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_string (const char *name, const char **strptr) |
The expected field stores a string. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_json (const char *name, json_t **jsonp) |
JSON object. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_bool (const char *name, bool *b) |
boolean. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_uint8 (const char *name, uint8_t *u8) |
8-bit integer. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_uint16 (const char *name, uint16_t *u16) |
16-bit integer. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_uint32 (const char *name, uint32_t *u32) |
32-bit integer. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_uint64 (const char *name, uint64_t *u64) |
64-bit integer. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_int64 (const char *name, int64_t *i64) |
64-bit signed integer. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_boolean (const char *name, int *boolean) |
Boolean (true mapped to GNUNET_YES, false mapped to GNUNET_NO). More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_absolute_time (const char *name, struct GNUNET_TIME_Absolute *at) |
Absolute time. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_absolute_time_nbo (const char *name, struct GNUNET_TIME_AbsoluteNBO *at) |
Absolute time in network byte order. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_relative_time (const char *name, struct GNUNET_TIME_Relative *rt) |
Relative time. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_rsa_public_key (const char *name, struct GNUNET_CRYPTO_RsaPublicKey **pk) |
Specification for parsing an RSA public key. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_rsa_signature (const char *name, struct GNUNET_CRYPTO_RsaSignature **sig) |
Specification for parsing an RSA signature. More... | |
json_t * | GNUNET_JSON_from_data (const void *data, size_t size) |
Convert binary data to a JSON string with the base32crockford encoding. More... | |
json_t * | GNUNET_JSON_from_time_abs (struct GNUNET_TIME_Absolute stamp) |
Convert absolute timestamp to a json string. More... | |
json_t * | GNUNET_JSON_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO stamp) |
Convert absolute timestamp to a json string. More... | |
json_t * | GNUNET_JSON_from_time_rel (struct GNUNET_TIME_Relative stamp) |
Convert relative timestamp to a json string. More... | |
json_t * | GNUNET_JSON_from_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *pk) |
Convert RSA public key to JSON. More... | |
json_t * | GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig) |
Convert RSA signature to JSON. More... | |
enum GNUNET_JSON_PostResult | GNUNET_JSON_post_parser (size_t buffer_max, struct MHD_Connection *connection, void **con_cls, const char *upload_data, size_t *upload_data_size, json_t **json) |
Process a POST request containing a JSON object. More... | |
void | GNUNET_JSON_post_parser_cleanup (void *con_cls) |
Function called whenever we are done with a request to clean up our state. More... | |
struct GNUNET_GETOPT_CommandLineOption | GNUNET_JSON_getopt (char shortName, const char *name, const char *argumentHelp, const char *description, json_t **json) |
Allow user to specify a JSON input value. More... | |
functions to parse JSON objects into GNUnet objects
Definition in file gnunet_json_lib.h.
#define GNUNET_JSON_spec_fixed_auto | ( | name, | |
obj | |||
) | GNUNET_JSON_spec_fixed (name, obj, sizeof(*obj)) |
Fixed size object (in network byte order, encoded using Crockford Base32hex encoding).
name | name of the JSON field |
obj | pointer where to write the data (type of *obj will determine size) |
Definition at line 187 of file gnunet_json_lib.h.
#define GNUNET_JSON_from_data_auto | ( | ptr | ) | GNUNET_JSON_from_data (ptr, sizeof(*ptr)) |
Convert binary data to a JSON string with the base32crockford encoding.
ptr | binary data, sizeof (*ptr) must yield correct size |
Definition at line 383 of file gnunet_json_lib.h.
typedef int(* GNUNET_JSON_Parser) (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) |
Function called to parse JSON argument.
cls | closure |
root | JSON to parse |
spec | our specification entry with further details |
Definition at line 52 of file gnunet_json_lib.h.
typedef void(* GNUNET_JSON_Cleaner) (void *cls, struct GNUNET_JSON_Specification *spec) |
Function called to clean up data from earlier parsing.
cls | closure |
spec | our specification entry with data to clean. |
Definition at line 64 of file gnunet_json_lib.h.
Return codes from GNUNET_JSON_post_parser().
Enumerator | |
---|---|
GNUNET_JSON_PR_SUCCESS | Parsing successful, JSON result is in |
GNUNET_JSON_PR_CONTINUE | Parsing continues, call again soon! |
GNUNET_JSON_PR_OUT_OF_MEMORY | Sorry, memory allocation (malloc()) failed. |
GNUNET_JSON_PR_REQUEST_TOO_LARGE | Request size exceeded |
GNUNET_JSON_PR_JSON_INVALID | JSON parsing failed. This was not a JSON upload. |
Definition at line 441 of file gnunet_json_lib.h.
enum GNUNET_GenericReturnValue GNUNET_JSON_parse | ( | const json_t * | root, |
struct GNUNET_JSON_Specification * | spec, | ||
const char ** | error_json_name, | ||
unsigned int * | error_line | ||
) |
Navigate and parse data in a JSON tree.
Tries to parse the root to find all of the values given in the spec. If one of the entries in spec cannot be found or parsed, the name of the JSON field is returned in error_json_name, and the offset of the entry in spec is returned in error_line.
root | the JSON node to start the navigation at. | |
spec | parse specification array | |
[out] | error_json_name | which JSON field was problematic |
[out] | which | index into spec did we encounter an error |
Definition at line 45 of file json.c.
References GNUNET_JSON_Specification::field, GNUNET_JSON_parse_free(), GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::parser.
Referenced by add_attribute_cont(), add_credential_cont(), consume_ticket_cont(), namestore_add_or_update(), and revoke_ticket_cont().
void GNUNET_JSON_parse_free | ( | struct GNUNET_JSON_Specification * | spec | ) |
Frees all elements allocated during a GNUNET_JSON_parse() operation.
spec | specification of the parse operation |
Definition at line 106 of file json.c.
References GNUNET_JSON_Specification::cleaner, GNUNET_JSON_Specification::cls, and GNUNET_JSON_Specification::parser.
Referenced by add_attribute_cont(), add_credential_cont(), consume_ticket_cont(), GNUNET_JSON_parse(), namestore_add_or_update(), and revoke_ticket_cont().
struct GNUNET_JSON_Specification GNUNET_JSON_spec_end | ( | void | ) |
End of a parser specification.
Definition at line 35 of file json_helper.c.
References GNUNET_JSON_Specification::parser, and ret.
Referenced by add_attribute_cont(), add_credential_cont(), consume_ticket_cont(), namestore_add_or_update(), and revoke_ticket_cont().
struct GNUNET_JSON_Specification GNUNET_JSON_spec_mark_optional | ( | struct GNUNET_JSON_Specification | spec | ) |
Set the "optional" flag for a parser specification entry.
spec | specification to modify |
Definition at line 90 of file json.c.
References GNUNET_YES, GNUNET_JSON_Specification::is_optional, and ret.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_fixed | ( | const char * | name, |
void * | obj, | ||
size_t | size | ||
) |
Variable size object (in network byte order, encoded using Crockford Base32hex encoding).
name | name of the JSON field | |
[out] | obj | pointer where to write the data, must have size bytes |
size | number of bytes expected in obj |
Definition at line 96 of file json_helper.c.
References name, parse_fixed_data(), GNUNET_JSON_Specification::parser, ret, and size.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_varsize | ( | const char * | name, |
void ** | obj, | ||
size_t * | size | ||
) |
Variable size object (in network byte order, encoded using Crockford Base32hex encoding).
name | name of the JSON field | |
[out] | obj | pointer where to write the data, will be allocated |
[out] | size | where to store the number of bytes allocated for obj |
Definition at line 189 of file json_helper.c.
References clean_variable_data(), name, parse_variable_data(), GNUNET_JSON_Specification::parser, ret, and size.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_string | ( | const char * | name, |
const char ** | strptr | ||
) |
The expected field stores a string.
name | name of the JSON field |
strptr | where to store a pointer to the field |
Definition at line 242 of file json_helper.c.
References name, parse_string(), GNUNET_JSON_Specification::parser, and ret.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_json | ( | const char * | name, |
json_t ** | jsonp | ||
) |
JSON object.
name | name of the JSON field | |
[out] | jsonp | where to store the JSON found under name |
Definition at line 311 of file json_helper.c.
References clean_object(), name, parse_object(), GNUNET_JSON_Specification::parser, and ret.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_bool | ( | const char * | name, |
bool * | b | ||
) |
boolean.
name | name of the JSON field | |
[out] | b | where to store the boolean found under name |
Definition at line 366 of file json_helper.c.
References testconfigure::b, name, parse_bool(), GNUNET_JSON_Specification::parser, ret, and GNUNET_JSON_Specification::size_ptr.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint8 | ( | const char * | name, |
uint8_t * | u8 | ||
) |
8-bit integer.
name | name of the JSON field | |
[out] | u8 | where to store the integer found under name |
Definition at line 422 of file json_helper.c.
References name, parse_u8(), GNUNET_JSON_Specification::parser, ret, and GNUNET_JSON_Specification::size_ptr.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint16 | ( | const char * | name, |
uint16_t * | u16 | ||
) |
16-bit integer.
name | name of the JSON field | |
[out] | u16 | where to store the integer found under name |
Definition at line 478 of file json_helper.c.
References name, parse_u16(), GNUNET_JSON_Specification::parser, ret, and GNUNET_JSON_Specification::size_ptr.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint32 | ( | const char * | name, |
uint32_t * | u32 | ||
) |
32-bit integer.
name | name of the JSON field | |
[out] | u32 | where to store the integer found under name |
Definition at line 534 of file json_helper.c.
References name, parse_u32(), GNUNET_JSON_Specification::parser, ret, and GNUNET_JSON_Specification::size_ptr.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint64 | ( | const char * | name, |
uint64_t * | u64 | ||
) |
64-bit integer.
name | name of the JSON field | |
[out] | u64 | where to store the integer found under name |
Definition at line 585 of file json_helper.c.
References name, parse_u64(), GNUNET_JSON_Specification::parser, ret, and GNUNET_JSON_Specification::size_ptr.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_int64 | ( | const char * | name, |
int64_t * | i64 | ||
) |
64-bit signed integer.
name | name of the JSON field | |
[out] | i64 | where to store the integer found under name |
Definition at line 636 of file json_helper.c.
References name, parse_i64(), GNUNET_JSON_Specification::parser, ret, and GNUNET_JSON_Specification::size_ptr.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_boolean | ( | const char * | name, |
int * | boolean | ||
) |
Boolean (true mapped to GNUNET_YES, false mapped to GNUNET_NO).
name | name of the JSON field | |
[out] | boolean | where to store the boolean found under name |
Boolean (true mapped to GNUNET_YES, false mapped to GNUNET_NO).
name | name of the JSON field | |
[out] | boolean | where to store the boolean found under name |
Definition at line 1083 of file json_helper.c.
References name, parse_boolean(), GNUNET_JSON_Specification::parser, ret, and GNUNET_JSON_Specification::size_ptr.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_absolute_time | ( | const char * | name, |
struct GNUNET_TIME_Absolute * | at | ||
) |
Absolute time.
name | name of the JSON field | |
[out] | at | where to store the absolute time found under name |
Definition at line 715 of file json_helper.c.
References name, parse_abs_time(), GNUNET_JSON_Specification::parser, and ret.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_absolute_time_nbo | ( | const char * | name, |
struct GNUNET_TIME_AbsoluteNBO * | at | ||
) |
Absolute time in network byte order.
name | name of the JSON field | |
[out] | at | where to store the absolute time found under name |
Definition at line 769 of file json_helper.c.
References name, parse_abs_time_nbo(), GNUNET_JSON_Specification::parser, and ret.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_relative_time | ( | const char * | name, |
struct GNUNET_TIME_Relative * | rt | ||
) |
Relative time.
name | name of the JSON field | |
[out] | rt | where to store the relative time found under name |
Definition at line 846 of file json_helper.c.
References name, parse_rel_time(), GNUNET_JSON_Specification::parser, and ret.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_public_key | ( | const char * | name, |
struct GNUNET_CRYPTO_RsaPublicKey ** | pk | ||
) |
Specification for parsing an RSA public key.
name | name of the JSON field |
pk | where to store the RSA key found under name |
Definition at line 939 of file json_helper.c.
References clean_rsa_public_key(), name, parse_rsa_public_key(), GNUNET_JSON_Specification::parser, pk, and ret.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_signature | ( | const char * | name, |
struct GNUNET_CRYPTO_RsaSignature ** | sig | ||
) |
Specification for parsing an RSA signature.
name | name of the JSON field |
sig | where to store the RSA signature found under name |
Definition at line 1033 of file json_helper.c.
References clean_rsa_signature(), name, parse_rsa_signature(), GNUNET_JSON_Specification::parser, and ret.
json_t* GNUNET_JSON_from_data | ( | const void * | data, |
size_t | size | ||
) |
Convert binary data to a JSON string with the base32crockford encoding.
data | binary data |
size | size of data in bytes |
Definition at line 39 of file json_generator.c.
References buf, GNUNET_break, GNUNET_free, and GNUNET_STRINGS_data_to_string_alloc().
Referenced by GNUNET_JSON_from_rsa_public_key(), and GNUNET_JSON_from_rsa_signature().
json_t* GNUNET_JSON_from_time_abs | ( | struct GNUNET_TIME_Absolute | stamp | ) |
Convert absolute timestamp to a json string.
stamp | the time stamp |
Definition at line 60 of file json_generator.c.
References GNUNET_TIME_Absolute::abs_value_us, GNUNET_assert, GNUNET_break, GNUNET_OK, GNUNET_TIME_round_abs(), and GNUNET_TIME_UNIT_FOREVER_ABS.
Referenced by GNUNET_JSON_from_time_abs_nbo().
json_t* GNUNET_JSON_from_time_abs_nbo | ( | struct GNUNET_TIME_AbsoluteNBO | stamp | ) |
Convert absolute timestamp to a json string.
stamp | the time stamp |
Definition at line 107 of file json_generator.c.
References GNUNET_JSON_from_time_abs(), and GNUNET_TIME_absolute_ntoh().
json_t* GNUNET_JSON_from_time_rel | ( | struct GNUNET_TIME_Relative | stamp | ) |
Convert relative timestamp to a json string.
stamp | the time stamp |
Definition at line 120 of file json_generator.c.
References GNUNET_assert, GNUNET_break, GNUNET_OK, GNUNET_TIME_round_rel(), GNUNET_TIME_UNIT_FOREVER_REL, and GNUNET_TIME_Relative::rel_value_us.
json_t* GNUNET_JSON_from_rsa_public_key | ( | const struct GNUNET_CRYPTO_RsaPublicKey * | pk | ) |
Convert RSA public key to JSON.
pk | public key to convert |
Definition at line 167 of file json_generator.c.
References buf, GNUNET_CRYPTO_rsa_public_key_encode(), GNUNET_free, GNUNET_JSON_from_data(), and ret.
json_t* GNUNET_JSON_from_rsa_signature | ( | const struct GNUNET_CRYPTO_RsaSignature * | sig | ) |
Convert RSA signature to JSON.
sig | signature to convert |
Definition at line 189 of file json_generator.c.
References buf, GNUNET_CRYPTO_rsa_signature_encode(), GNUNET_free, GNUNET_JSON_from_data(), and ret.
enum GNUNET_JSON_PostResult GNUNET_JSON_post_parser | ( | size_t | buffer_max, |
struct MHD_Connection * | connection, | ||
void ** | con_cls, | ||
const char * | upload_data, | ||
size_t * | upload_data_size, | ||
json_t ** | json | ||
) |
Process a POST request containing a JSON object.
This function realizes an MHD POST processor that will (incrementally) process JSON data uploaded to the HTTP server. It will store the required state in the con_cls, which must be cleaned up using #GNUNET_JSON_post_parser_callback().
buffer_max | maximum allowed size for the buffer |
connection | MHD connection handle (for meta data about the upload) |
con_cls | the closure (will point to a struct Buffer * ) |
upload_data | the POST data |
upload_data_size | number of bytes in upload_data |
json | the JSON object for a completed request |
Definition at line 265 of file json_mhd.c.
References buffer_append(), buffer_deinit(), buffer_init(), Buffer::data, Buffer::fill, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_JSON_PR_CONTINUE, GNUNET_JSON_PR_JSON_INVALID, GNUNET_JSON_PR_OUT_OF_MEMORY, GNUNET_JSON_PR_REQUEST_TOO_LARGE, GNUNET_JSON_PR_SUCCESS, GNUNET_log, GNUNET_new, GNUNET_OK, inflate_data(), REQUEST_BUFFER_INITIAL, and ret.
void GNUNET_JSON_post_parser_cleanup | ( | void * | con_cls | ) |
Function called whenever we are done with a request to clean up our state.
con_cls | value as it was left by GNUNET_JSON_post_parser(), to be cleaned up |
Definition at line 357 of file json_mhd.c.
References buffer_deinit(), and GNUNET_free.
struct GNUNET_GETOPT_CommandLineOption GNUNET_JSON_getopt | ( | char | shortName, |
const char * | name, | ||
const char * | argumentHelp, | ||
const char * | description, | ||
json_t ** | json | ||
) |
Allow user to specify a JSON input value.
shortName | short name of the option | |
name | long name of the option | |
argumentHelp | help text for the option argument | |
description | long help text for the option | |
[out] | val | set to the JSON specified at the command line |
Definition at line 159 of file json.c.
References GNUNET_GETOPT_CommandLineOption::argumentHelp, GNUNET_GETOPT_CommandLineOption::description, name, set_json(), and GNUNET_GETOPT_CommandLineOption::shortName.