34 const char **error_json_name,
35 unsigned int *error_line)
39 for (
unsigned int i = 0; NULL != spec[i].
parser; i++)
43 if (NULL == spec[i].field)
44 pos = (json_t *) root;
46 pos = json_object_get (root,
48 if ( ( (NULL == pos) ||
49 (json_is_null (pos) ) ) &&
50 (spec[i].is_optional) )
52 if (NULL != spec[i].missing)
58 spec[i].
parser (spec[i].cls,
62 if (NULL != error_json_name)
63 *error_json_name = spec[i].
field;
66 "Parsing failed for field `%s:%u`\n",
69 if (NULL != error_line)
74 if (NULL != spec[i].missing)
87 ret.is_optional =
true;
96 for (
unsigned int i = 0; NULL != spec[i].
parser; i++)
121 json_t **json = scls;
124 *json = json_loads (
value,
125 JSON_REJECT_DUPLICATES,
130 _ (
"Failed to parse JSON in option `%s': %s (%s)\n"),
152 .require_argument = 1,
154 .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.