34 const char **error_json_name,
35 unsigned int *error_line)
39 if (NULL != error_json_name)
40 *error_json_name =
"root is NULL";
41 if (NULL != error_line)
45 for (
unsigned int i = 0; NULL != spec[i].
parser; i++)
49 if (NULL == spec[i].field)
50 pos = (json_t *) root;
52 pos = json_object_get (root,
54 if ( ( (NULL == pos) ||
55 (json_is_null (pos) ) ) &&
56 (spec[i].is_optional) )
58 if (NULL != spec[i].missing)
64 spec[i].
parser (spec[i].cls,
68 if (NULL != error_json_name)
69 *error_json_name = spec[i].
field;
72 "Parsing failed for field `%s:%u`\n",
75 if (NULL != error_line)
80 if (NULL != spec[i].missing)
93 ret.is_optional =
true;
102 for (
unsigned int i = 0; NULL != spec[i].
parser; i++)
127 json_t **json = scls;
130 *json = json_loads (
value,
131 JSON_REJECT_DUPLICATES,
136 _ (
"Failed to parse JSON in option `%s': %s (%s)\n"),
158 .require_argument = 1,
160 .scls = (
void *) json
static int ret
Final status code.
static struct GNUNET_FS_Handle * ctx
static char * name
Name (label) of the records to list.
static char * value
Value of the record to add/remove.
functions to parse JSON objects into GNUnet objects
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_ERROR_TYPE_WARNING
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.
void GNUNET_JSON_parse_free(struct GNUNET_JSON_Specification *spec)
Frees all elements allocated during a GNUNET_JSON_parse() operation.
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.
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.
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.
Definition of a command line option.
const char * description
Help text for the option (description)
const char * argumentHelp
Name of the argument for the user in help text.
const char shortName
Short name of the option.
General context for command line processors.
Entry in parser specification for GNUNET_JSON_parse().
GNUNET_JSON_Cleaner cleaner
Function for how to clean up this type of entry.
bool * missing
Pointer to set to true if this argument is indeed missing.
const char * field
Name of the field to parse, use NULL to get the JSON of the main object instead of the JSON of an ind...
void * cls
Closure for parser and cleaner.
GNUNET_JSON_Parser parser
Function for how to parse this type of entry.