functions to parse JSON snippets More...
Go to the source code of this file.
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... | |
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... | |
void | GNUNET_JSON_parse_free (struct GNUNET_JSON_Specification *spec) |
Frees all elements allocated during a GNUNET_JSON_parse() operation. More... | |
static enum GNUNET_GenericReturnValue | set_json (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value) |
Set an option with a JSON value from the command line. 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 snippets
Definition in file json.c.
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().
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.
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().
|
static |
Set an option with a JSON value from the command line.
A pointer to this function should be passed as part of the 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options of this type.
ctx | command line processing context |
scls | additional closure (will point to the 'json_t *') |
option | name of the option |
value | actual value of the option as a string. |
Definition at line 122 of file json.c.
References _, GNUNET_OK, GNUNET_SYSERR, and value.
Referenced by GNUNET_JSON_getopt().
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.