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... | |
struct | GNUNET_JSON_PackSpec |
Element in the array to give to the packer. 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_spec_fixed64_auto(name, obj) GNUNET_JSON_spec_fixed (name, (obj), sizeof(*(obj))) |
Fixed size object (in network byte order, encoded using base64 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... | |
#define | GNUNET_JSON_from_data64_auto(ptr) GNUNET_JSON_from_data64 (ptr, sizeof(*(ptr))) |
Convert binary data to a JSON string with base64 encoding. More... | |
#define | GNUNET_JSON_PACK(...) |
Pack a JSON object from a spec. More... | |
#define | GNUNET_JSON_pack_data_auto(name, blob) GNUNET_JSON_pack_data_varsize (name, (blob), sizeof (*(blob))) |
Generate packer instruction for a JSON field where the size is automatically determined from the argument. More... | |
#define | GNUNET_JSON_pack_data64_auto(name, blob) GNUNET_JSON_pack_data64_varsize (name, (blob), sizeof (*(blob))) |
Generate packer instruction for a JSON field where the size is automatically determined from the argument. More... | |
Typedefs | |
typedef enum GNUNET_GenericReturnValue(* | 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... | |
typedef json_t *(* | GNUNET_JSON_PackCallback) (const struct GNUNET_JSON_PackSpec *se) |
Function called to pack an element into the JSON object as part of GNUNET_JSON_pack_(). 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, bool *missing) |
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_fixed64 (const char *name, void *obj, size_t size) |
Variable size object (in network byte order, encoded using base64 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 or array. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_object_const (const char *name, const json_t **jsonp) |
JSON object, reference counter not incremented. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_array_const (const char *name, const json_t **jsonp) |
JSON array, reference counter not incremented. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_bool (const char *name, bool *b) |
boolean. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_double (const char *name, double *f) |
double. 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_timestamp (const char *name, struct GNUNET_TIME_Timestamp *t) |
Timestamp. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_timestamp_nbo (const char *name, struct GNUNET_TIME_TimestampNBO *tn) |
Timestamp 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... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_blinded_message (const char *name, struct GNUNET_CRYPTO_BlindedMessage **msg) |
Specification for parsing a blinded message. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_blinded_signature (const char *field, struct GNUNET_CRYPTO_BlindedSignature **b_sig) |
Specification for parsing a blinded signature. More... | |
struct GNUNET_JSON_Specification | GNUNET_JSON_spec_unblinded_signature (const char *field, struct GNUNET_CRYPTO_UnblindedSignature **ub_sig) |
Specification for parsing an unblinded 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_data64 (const void *data, size_t size) |
Convert binary data to a JSON string with base64 encoding. More... | |
json_t * | GNUNET_JSON_from_timestamp (struct GNUNET_TIME_Timestamp stamp) |
Convert timestamp to a json string. More... | |
json_t * | GNUNET_JSON_from_timestamp_nbo (struct GNUNET_TIME_TimestampNBO stamp) |
Convert 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... | |
json_t * | GNUNET_JSON_pack_ (struct GNUNET_JSON_PackSpec spec[]) |
Pack a JSON object from a spec. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_end_ (void) |
Do not use directly. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_allow_null (struct GNUNET_JSON_PackSpec in) |
Modify packer instruction to allow NULL as a value. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_bool (const char *name, bool b) |
Generate packer instruction for a JSON field of type bool. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_double (const char *name, double f) |
Generate packer instruction for a JSON field of type double. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_string (const char *name, const char *s) |
Generate packer instruction for a JSON field of type string. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_uint64 (const char *name, uint64_t num) |
Generate packer instruction for a JSON field of type unsigned integer. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_int64 (const char *name, int64_t num) |
Generate packer instruction for a JSON field of type signed integer. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_object_steal (const char *name, json_t *o) |
Generate packer instruction for a JSON field of type JSON object where the reference is taken over by the packer. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_object_incref (const char *name, json_t *o) |
Generate packer instruction for a JSON field of type JSON object where the reference counter is incremented by the packer. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_array_steal (const char *name, json_t *a) |
Generate packer instruction for a JSON field of type JSON array where the reference is taken over by the packer. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_array_incref (const char *name, json_t *a) |
Generate packer instruction for a JSON field of type JSON array where the reference counter is incremented by the packer. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_data_varsize (const char *name, const void *blob, size_t blob_size) |
Generate packer instruction for a JSON field of type variable size binary blob. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_data64_varsize (const char *name, const void *blob, size_t blob_size) |
Generate packer instruction for a JSON field of type variable size binary blob. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_timestamp (const char *name, struct GNUNET_TIME_Timestamp at) |
Generate packer instruction for a JSON field of type timestamp. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_timestamp_nbo (const char *name, struct GNUNET_TIME_TimestampNBO at) |
Generate packer instruction for a JSON field of type timestamp in network byte order. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_time_rel (const char *name, struct GNUNET_TIME_Relative rt) |
Generate packer instruction for a JSON field of type relative time. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_time_rel_nbo (const char *name, struct GNUNET_TIME_RelativeNBO rt) |
Generate packer instruction for a JSON field of type relative time in network byte order. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_rsa_public_key (const char *name, const struct GNUNET_CRYPTO_RsaPublicKey *pk) |
Generate packer instruction for a JSON field of type RSA public key. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_rsa_signature (const char *name, const struct GNUNET_CRYPTO_RsaSignature *sig) |
Generate packer instruction for a JSON field of type RSA signature. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_unblinded_signature (const char *name, const struct GNUNET_CRYPTO_UnblindedSignature *sig) |
Generate packer instruction for a JSON field of type unblinded signature. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_blinded_message (const char *name, const struct GNUNET_CRYPTO_BlindedMessage *msg) |
Generate packer instruction for a JSON field of type blinded message. More... | |
struct GNUNET_JSON_PackSpec | GNUNET_JSON_pack_blinded_sig (const char *name, const struct GNUNET_CRYPTO_BlindedSignature *sig) |
Generate packer instruction for a JSON field of type blinded signature. 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 202 of file gnunet_json_lib.h.
#define GNUNET_JSON_spec_fixed64_auto | ( | name, | |
obj | |||
) | GNUNET_JSON_spec_fixed (name, (obj), sizeof(*(obj))) |
Fixed size object (in network byte order, encoded using base64 encoding).
name | name of the JSON field |
obj | pointer where to write the data (type of *obj will determine size) |
Definition at line 225 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 504 of file gnunet_json_lib.h.
#define GNUNET_JSON_from_data64_auto | ( | ptr | ) | GNUNET_JSON_from_data64 (ptr, sizeof(*(ptr))) |
Convert binary data to a JSON string with base64 encoding.
ptr | binary data, sizeof (*ptr) must yield correct size |
Definition at line 515 of file gnunet_json_lib.h.
#define GNUNET_JSON_PACK | ( | ... | ) |
Pack a JSON object from a spec.
Aborts if packing fails.
... | list of specification objects |
Definition at line 720 of file gnunet_json_lib.h.
#define GNUNET_JSON_pack_data_auto | ( | name, | |
blob | |||
) | GNUNET_JSON_pack_data_varsize (name, (blob), sizeof (*(blob))) |
Generate packer instruction for a JSON field where the size is automatically determined from the argument.
name | name of the field to add to the object |
blob | data to pack, must not be an array |
Definition at line 889 of file gnunet_json_lib.h.
#define GNUNET_JSON_pack_data64_auto | ( | name, | |
blob | |||
) | GNUNET_JSON_pack_data64_varsize (name, (blob), sizeof (*(blob))) |
Generate packer instruction for a JSON field where the size is automatically determined from the argument.
Use base64-encoding, instead of the more common Crockford base32-encoding.
name | name of the field to add to the object |
blob | data to pack, must not be an array |
Definition at line 920 of file gnunet_json_lib.h.
typedef enum GNUNET_GenericReturnValue(* 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 1 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.
typedef json_t *(* GNUNET_JSON_PackCallback) (const struct GNUNET_JSON_PackSpec *se) |
Function called to pack an element into the JSON object as part of GNUNET_JSON_pack_().
se | pack specification to execute |
Definition at line 673 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 573 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] | error_line | which index into spec did we encounter an error |
Definition at line 32 of file json.c.
References GNUNET_JSON_Specification::field, GNUNET_ERROR_TYPE_WARNING, GNUNET_JSON_parse_free(), GNUNET_log, GNUNET_OK, GNUNET_SYSERR, GNUNET_JSON_Specification::missing, consensus-simulation::parser, and GNUNET_JSON_Specification::parser.
Referenced by add_attribute_cont(), add_credential_cont(), bulk_tx_start(), consume_ticket_cont(), namestore_add_or_update(), parse_blinded_message(), parse_blinded_sig(), parse_unblinded_sig(), and revoke_ticket_cont().
void GNUNET_JSON_parse_free | ( | struct GNUNET_JSON_Specification * | spec | ) |
Frees all elements allocated during a GNUNET_JSON_parse() operation.
Convenience function to be called if cleaning up all heap-allocated data from a GNUNET_JSON_parse() is desired. The function does not have to be called if no data was heap-allocated (e.g. only integers, strings and fixed-sized data was used), or if the application calls the respective code to free the heap (not always GNUNET_free(), depends on the data type!) on the returned heap-allocated data itself.
spec | specification of the parse operation |
Definition at line 100 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 33 of file json_helper.c.
References ret.
Referenced by add_attribute_cont(), add_credential_cont(), bulk_tx_start(), consume_ticket_cont(), namestore_add_or_update(), parse_blinded_message(), parse_blinded_sig(), parse_unblinded_sig(), and revoke_ticket_cont().
struct GNUNET_JSON_Specification GNUNET_JSON_spec_mark_optional | ( | struct GNUNET_JSON_Specification | spec, |
bool * | missing | ||
) |
Set the "optional" flag for a parser specification entry.
spec | specification to modify | |
[out] | missing | set to true if the argument is missing, NULL is allowed. |
Definition at line 88 of file json.c.
References GNUNET_JSON_Specification::missing, 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 117 of file json_helper.c.
References name, parse_fixed_data(), ret, and size.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_fixed64 | ( | const char * | name, |
void * | obj, | ||
size_t | size | ||
) |
Variable size object (in network byte order, encoded using base64 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 181 of file json_helper.c.
References name, parse_fixed64_data(), 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 258 of file json_helper.c.
References clean_variable_data(), name, parse_variable_data(), ret, and size.
Referenced by parse_blinded_message().
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 306 of file json_helper.c.
References name, parse_string(), and ret.
Referenced by consume_ticket_cont(), parse_blinded_message(), parse_blinded_sig(), and parse_unblinded_sig().
struct GNUNET_JSON_Specification GNUNET_JSON_spec_json | ( | const char * | name, |
json_t ** | jsonp | ||
) |
JSON object or array.
Reference counter is incremented.
name | name of the JSON field | |
[out] | jsonp | where to store the JSON found under name |
Definition at line 365 of file json_helper.c.
References clean_json(), name, parse_json(), and ret.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_object_const | ( | const char * | name, |
const json_t ** | jsonp | ||
) |
JSON object, reference counter not incremented.
name | name of the JSON field | |
[out] | jsonp | where to store the JSON found under name |
Definition at line 409 of file json_helper.c.
References name, parse_object_const(), and ret.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_array_const | ( | const char * | name, |
const json_t ** | jsonp | ||
) |
JSON array, reference counter not incremented.
name | name of the JSON field | |
[out] | jsonp | where to store the JSON found under name |
Definition at line 452 of file json_helper.c.
References name, parse_array_const(), 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 500 of file json_helper.c.
References name, parse_bool(), ret, and GNUNET_JSON_Specification::size_ptr.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_double | ( | const char * | name, |
double * | f | ||
) |
double.
name | name of the JSON field | |
[out] | f | where to store the double found under name |
Definition at line 543 of file json_helper.c.
References removetrailingwhitespace::f, name, parse_double(), 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 593 of file json_helper.c.
References name, parse_u8(), 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 643 of file json_helper.c.
References name, parse_u16(), 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 693 of file json_helper.c.
References name, parse_u32(), ret, and GNUNET_JSON_Specification::size_ptr.
Referenced by parse_blinded_sig().
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 738 of file json_helper.c.
References name, parse_u64(), 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 783 of file json_helper.c.
References name, parse_i64(), 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 |
Definition at line 1190 of file json_helper.c.
References consensus-simulation::int, name, parse_boolean(), ret, and GNUNET_JSON_Specification::size_ptr.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp | ( | const char * | name, |
struct GNUNET_TIME_Timestamp * | t | ||
) |
Timestamp.
name | name of the JSON field | |
[out] | t | at where to store the absolute time found under name |
Definition at line 862 of file json_helper.c.
References name, parse_timestamp(), ret, and t.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp_nbo | ( | const char * | name, |
struct GNUNET_TIME_TimestampNBO * | tn | ||
) |
Timestamp in network byte order.
name | name of the JSON field | |
[out] | tn | where to store the absolute time found under name |
Definition at line 907 of file json_helper.c.
References name, parse_timestamp_nbo(), 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 977 of file json_helper.c.
References name, parse_rel_time(), 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 1061 of file json_helper.c.
References clean_rsa_public_key(), name, parse_rsa_public_key(), 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 1146 of file json_helper.c.
References clean_rsa_signature(), name, parse_rsa_signature(), and ret.
Referenced by parse_blinded_sig(), and parse_unblinded_sig().
struct GNUNET_JSON_Specification GNUNET_JSON_spec_blinded_message | ( | const char * | name, |
struct GNUNET_CRYPTO_BlindedMessage ** | msg | ||
) |
Specification for parsing a blinded message.
name | name of the JSON field |
sig | where to store the blinded message found under name |
Definition at line 1330 of file json_helper.c.
References clean_blinded_message(), msg, name, parse_blinded_message(), and ret.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_blinded_signature | ( | const char * | field, |
struct GNUNET_CRYPTO_BlindedSignature ** | b_sig | ||
) |
Specification for parsing a blinded signature.
name | name of the JSON field |
sig | where to store the blinded signature found under name |
Definition at line 1465 of file json_helper.c.
References clean_blinded_sig(), GNUNET_JSON_Specification::field, parse_blinded_sig(), and ret.
struct GNUNET_JSON_Specification GNUNET_JSON_spec_unblinded_signature | ( | const char * | field, |
struct GNUNET_CRYPTO_UnblindedSignature ** | ub_sig | ||
) |
Specification for parsing an unblinded signature.
name | name of the JSON field |
sig | where to store the unblinded signature found under name |
Definition at line 1598 of file json_helper.c.
References clean_unblinded_sig(), GNUNET_JSON_Specification::field, parse_unblinded_sig(), 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 31 of file json_generator.c.
References data, GNUNET_break, GNUNET_free, GNUNET_MAX_MALLOC_CHECKED, GNUNET_STRINGS_data_to_string_alloc(), and size.
Referenced by GNUNET_JSON_from_rsa_public_key(), GNUNET_JSON_from_rsa_signature(), and GNUNET_JSON_pack_data_varsize().
json_t * GNUNET_JSON_from_data64 | ( | const void * | data, |
size_t | size | ||
) |
Convert binary data to a JSON string with base64 encoding.
data | binary data |
size | size of data in bytes |
Definition at line 52 of file json_generator.c.
References data, GNUNET_break, GNUNET_free, GNUNET_MAX_MALLOC_CHECKED, GNUNET_STRINGS_base64_encode(), and size.
Referenced by GNUNET_JSON_pack_data64_varsize().
json_t * GNUNET_JSON_from_timestamp | ( | struct GNUNET_TIME_Timestamp | stamp | ) |
Convert timestamp to a json string.
stamp | the time stamp |
Definition at line 81 of file json_generator.c.
References GNUNET_TIME_Timestamp::abs_time, GNUNET_TIME_Absolute::abs_value_us, GNUNET_assert, GNUNET_break, GNUNET_TIME_absolute_is_never(), and GNUNET_TIME_UNIT_SECONDS.
Referenced by GNUNET_JSON_from_timestamp_nbo(), and GNUNET_JSON_pack_timestamp().
json_t * GNUNET_JSON_from_timestamp_nbo | ( | struct GNUNET_TIME_TimestampNBO | stamp | ) |
Convert timestamp to a json string.
stamp | the time stamp |
Definition at line 125 of file json_generator.c.
References GNUNET_JSON_from_timestamp(), and GNUNET_TIME_timestamp_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 132 of file json_generator.c.
References GNUNET_break, GNUNET_TIME_relative_is_forever(), and GNUNET_TIME_Relative::rel_value_us.
Referenced by GNUNET_JSON_pack_time_rel().
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 176 of file json_generator.c.
References GNUNET_CRYPTO_rsa_public_key_encode(), GNUNET_free, GNUNET_JSON_from_data(), pk, and ret.
Referenced by GNUNET_JSON_pack_rsa_public_key().
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 192 of file json_generator.c.
References GNUNET_CRYPTO_rsa_signature_encode(), GNUNET_free, GNUNET_JSON_from_data(), and ret.
Referenced by GNUNET_JSON_pack_rsa_signature().
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 367 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 147 of file json.c.
References GNUNET_GETOPT_CommandLineOption::argumentHelp, GNUNET_GETOPT_CommandLineOption::description, name, set_json(), and GNUNET_GETOPT_CommandLineOption::shortName.
json_t * GNUNET_JSON_pack_ | ( | struct GNUNET_JSON_PackSpec | spec[] | ) |
Pack a JSON object from a spec.
Aborts if packing fails.
spec | specification object |
Definition at line 29 of file json_pack.c.
References GNUNET_JSON_PackSpec::field_name, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_JSON_PackSpec::object, and ret.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_end_ | ( | void | ) |
Do not use directly.
Use GNUNET_JSON_PACK.
Definition at line 69 of file json_pack.c.
References ps.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_allow_null | ( | struct GNUNET_JSON_PackSpec | in | ) |
Modify packer instruction to allow NULL as a value.
in | json pack specification to modify |
Definition at line 80 of file json_pack.c.
References GNUNET_JSON_PackSpec::allow_null.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_bool | ( | const char * | name, |
bool | b | ||
) |
Generate packer instruction for a JSON field of type bool.
name | name of the field to add to the object |
b | boolean value |
Definition at line 88 of file json_pack.c.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_double | ( | const char * | name, |
double | f | ||
) |
Generate packer instruction for a JSON field of type double.
name | name of the field to add to the object |
f | double value |
Definition at line 101 of file json_pack.c.
References removetrailingwhitespace::f, name, and ps.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_string | ( | const char * | name, |
const char * | s | ||
) |
Generate packer instruction for a JSON field of type string.
name | name of the field to add to the object |
s | string value |
Definition at line 114 of file json_pack.c.
Referenced by GNUNET_JSON_pack_blinded_message(), GNUNET_JSON_pack_blinded_sig(), and GNUNET_JSON_pack_unblinded_signature().
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_uint64 | ( | const char * | name, |
uint64_t | num | ||
) |
Generate packer instruction for a JSON field of type unsigned integer.
Note that the maximum allowed value is still limited by JSON and not UINT64_MAX.
name | name of the field to add to the object |
num | numeric value |
Definition at line 127 of file json_pack.c.
References GNUNET_assert, name, and ps.
Referenced by GNUNET_JSON_pack_blinded_sig().
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_int64 | ( | const char * | name, |
int64_t | num | ||
) |
Generate packer instruction for a JSON field of type signed integer.
name | name of the field to add to the object |
num | numeric value |
Definition at line 145 of file json_pack.c.
References GNUNET_assert, name, and ps.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_object_steal | ( | const char * | name, |
json_t * | o | ||
) |
Generate packer instruction for a JSON field of type JSON object where the reference is taken over by the packer.
name | name of the field to add to the object |
o | object to steal |
Definition at line 165 of file json_pack.c.
References GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, name, and ps.
Referenced by GNUNET_JSON_pack_time_rel().
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_object_incref | ( | const char * | name, |
json_t * | o | ||
) |
Generate packer instruction for a JSON field of type JSON object where the reference counter is incremented by the packer.
Note that a deep copy is not performed.
name | name of the field to add to the object |
o | object to increment reference counter of |
Definition at line 187 of file json_pack.c.
References GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, name, and ps.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_array_steal | ( | const char * | name, |
json_t * | a | ||
) |
Generate packer instruction for a JSON field of type JSON array where the reference is taken over by the packer.
name | name of the field to add to the object |
a | array to steal |
Definition at line 210 of file json_pack.c.
References GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, name, and ps.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_array_incref | ( | const char * | name, |
json_t * | a | ||
) |
Generate packer instruction for a JSON field of type JSON array where the reference counter is incremented by the packer.
Note that a deep copy is not performed.
name | name of the field to add to the object |
a | array to increment reference counter of |
Definition at line 232 of file json_pack.c.
References GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, name, and ps.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_data_varsize | ( | const char * | name, |
const void * | blob, | ||
size_t | blob_size | ||
) |
Generate packer instruction for a JSON field of type variable size binary blob.
name | name of the field to add to the object |
blob | binary data to pack |
blob_size | number of bytes in blob |
Definition at line 255 of file json_pack.c.
References GNUNET_JSON_from_data(), name, and ps.
Referenced by GNUNET_JSON_pack_blinded_message().
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_data64_varsize | ( | const char * | name, |
const void * | blob, | ||
size_t | blob_size | ||
) |
Generate packer instruction for a JSON field of type variable size binary blob.
Use base64-encoding, instead of the more common Crockford base32-encoding.
name | name of the field to add to the object |
blob | binary data to pack |
blob_size | number of bytes in blob |
Definition at line 272 of file json_pack.c.
References GNUNET_JSON_from_data64(), name, and ps.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_timestamp | ( | const char * | name, |
struct GNUNET_TIME_Timestamp | at | ||
) |
Generate packer instruction for a JSON field of type timestamp.
name | name of the field to add to the object |
at | timestamp pack, a value of 0 is only allowed with GNUNET_JSON_pack_allow_null()! |
Definition at line 289 of file json_pack.c.
References GNUNET_assert, GNUNET_JSON_from_timestamp(), GNUNET_TIME_absolute_is_zero(), name, ps, and t.
Referenced by GNUNET_JSON_pack_timestamp_nbo().
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_timestamp_nbo | ( | const char * | name, |
struct GNUNET_TIME_TimestampNBO | at | ||
) |
Generate packer instruction for a JSON field of type timestamp in network byte order.
name | name of the field to add to the object |
at | timestamp to pack, a value of 0 is only allowed with GNUNET_JSON_pack_allow_null()! |
Definition at line 310 of file json_pack.c.
References GNUNET_JSON_pack_timestamp(), GNUNET_TIME_timestamp_ntoh(), and name.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rel | ( | const char * | name, |
struct GNUNET_TIME_Relative | rt | ||
) |
Generate packer instruction for a JSON field of type relative time.
name | name of the field to add to the object |
rt | relative time to pack |
Definition at line 319 of file json_pack.c.
References GNUNET_assert, GNUNET_JSON_from_time_rel(), GNUNET_JSON_pack_object_steal(), and name.
Referenced by GNUNET_JSON_pack_time_rel_nbo().
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rel_nbo | ( | const char * | name, |
struct GNUNET_TIME_RelativeNBO | rt | ||
) |
Generate packer instruction for a JSON field of type relative time in network byte order.
name | name of the field to add to the object |
rt | relative time to pack |
Definition at line 332 of file json_pack.c.
References GNUNET_JSON_pack_time_rel(), GNUNET_TIME_relative_ntoh(), and name.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_rsa_public_key | ( | const char * | name, |
const struct GNUNET_CRYPTO_RsaPublicKey * | pk | ||
) |
Generate packer instruction for a JSON field of type RSA public key.
name | name of the field to add to the object |
pk | RSA public key |
Definition at line 341 of file json_pack.c.
References GNUNET_JSON_from_rsa_public_key(), name, pk, and ps.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_rsa_signature | ( | const char * | name, |
const struct GNUNET_CRYPTO_RsaSignature * | sig | ||
) |
Generate packer instruction for a JSON field of type RSA signature.
name | name of the field to add to the object |
sig | RSA signature |
Definition at line 354 of file json_pack.c.
References GNUNET_JSON_from_rsa_signature(), name, and ps.
Referenced by GNUNET_JSON_pack_blinded_sig(), and GNUNET_JSON_pack_unblinded_signature().
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_unblinded_signature | ( | const char * | name, |
const struct GNUNET_CRYPTO_UnblindedSignature * | sig | ||
) |
Generate packer instruction for a JSON field of type unblinded signature.
name | name of the field to add to the object |
sig | unblinded signature |
Definition at line 367 of file json_pack.c.
References GNUNET_assert, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_JSON_PACK, GNUNET_JSON_pack_data_auto, GNUNET_JSON_pack_rsa_signature(), GNUNET_JSON_pack_string(), name, and ps.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_blinded_message | ( | const char * | name, |
const struct GNUNET_CRYPTO_BlindedMessage * | msg | ||
) |
Generate packer instruction for a JSON field of type blinded message.
name | name of the field to add to the object |
msg | blinded message |
Definition at line 404 of file json_pack.c.
References GNUNET_assert, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_JSON_PACK, GNUNET_JSON_pack_data_auto, GNUNET_JSON_pack_data_varsize(), GNUNET_JSON_pack_string(), msg, name, and ps.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_blinded_sig | ( | const char * | name, |
const struct GNUNET_CRYPTO_BlindedSignature * | sig | ||
) |
Generate packer instruction for a JSON field of type blinded signature.
name | name of the field to add to the object |
sig | blinded signature |
Definition at line 445 of file json_pack.c.
References GNUNET_assert, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_JSON_PACK, GNUNET_JSON_pack_data_auto, GNUNET_JSON_pack_rsa_signature(), GNUNET_JSON_pack_string(), GNUNET_JSON_pack_uint64(), name, and ps.