GNUnet  0.20.0
json_helper.c File Reference

functions to generate specifciations for JSON parsing More...

#include "platform.h"
#include "gnunet_json_lib.h"
Include dependency graph for json_helper.c:

Go to the source code of this file.

Functions

struct GNUNET_JSON_Specification GNUNET_JSON_spec_end ()
 End of a parser specification. More...
 
static enum GNUNET_GenericReturnValue parse_fixed_data (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to fixed size data. 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...
 
static enum GNUNET_GenericReturnValue parse_fixed64_data (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to fixed size data. 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...
 
static enum GNUNET_GenericReturnValue parse_variable_data (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to variable size data. More...
 
static void clean_variable_data (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing variable size data. 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...
 
static enum GNUNET_GenericReturnValue parse_string (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to string. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_string (const char *name, const char **strptr)
 The expected field stores a string. More...
 
static enum GNUNET_GenericReturnValue parse_json (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a JSON object. More...
 
static void clean_json (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing JSON object. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_json (const char *name, json_t **jsonp)
 JSON object or array. More...
 
static enum GNUNET_GenericReturnValue parse_object_const (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a JSON object. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_object_const (const char *name, const json_t **jsonp)
 JSON object, reference counter not incremented. More...
 
static enum GNUNET_GenericReturnValue parse_array_const (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON to a JSON array. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_array_const (const char *name, const json_t **jsonp)
 JSON array, reference counter not incremented. More...
 
static enum GNUNET_GenericReturnValue parse_bool (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a bool. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_bool (const char *name, bool *b)
 boolean. More...
 
static enum GNUNET_GenericReturnValue parse_u8 (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a uint8_t. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint8 (const char *name, uint8_t *u8)
 8-bit integer. More...
 
static enum GNUNET_GenericReturnValue parse_u16 (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a uint16_t. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint16 (const char *name, uint16_t *u16)
 16-bit integer. More...
 
static enum GNUNET_GenericReturnValue parse_u32 (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a uint32_t. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint32 (const char *name, uint32_t *u32)
 32-bit integer. More...
 
static enum GNUNET_GenericReturnValue parse_u64 (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a uint64_t. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint64 (const char *name, uint64_t *u64)
 64-bit integer. More...
 
static enum GNUNET_GenericReturnValue parse_i64 (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a int64_t. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_int64 (const char *name, int64_t *i64)
 64-bit signed integer. More...
 
static enum GNUNET_GenericReturnValue parse_timestamp (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a timestamp. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp (const char *name, struct GNUNET_TIME_Timestamp *t)
 Timestamp. More...
 
static enum GNUNET_GenericReturnValue parse_timestamp_nbo (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to absolute time. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp_nbo (const char *name, struct GNUNET_TIME_TimestampNBO *at)
 Timestamp in network byte order. More...
 
static enum GNUNET_GenericReturnValue parse_rel_time (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to relative time. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_relative_time (const char *name, struct GNUNET_TIME_Relative *rt)
 Relative time. More...
 
static enum GNUNET_GenericReturnValue parse_rsa_public_key (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to RSA public key. More...
 
static void clean_rsa_public_key (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing RSA public key. 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...
 
static enum GNUNET_GenericReturnValue parse_rsa_signature (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to RSA signature. More...
 
static void clean_rsa_signature (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing RSA signature. 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...
 
static enum GNUNET_GenericReturnValue parse_boolean (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to an int as a boolean. 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...
 

Detailed Description

functions to generate specifciations for JSON parsing

Author
Florian Dold
Benedikt Mueller
Christian Grothoff

Definition in file json_helper.c.

Function Documentation

◆ GNUNET_JSON_spec_end()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_end ( void  )

End of a parser specification.

Definition at line 1 of file json_helper.c.

33 {
35  .parser = NULL,
36  .cleaner = NULL,
37  .cls = NULL
38  };
39 
40  return ret;
41 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().

References ret.

Referenced by add_attribute_cont(), add_credential_cont(), bulk_tx_start(), consume_ticket_cont(), namestore_add_or_update(), and revoke_ticket_cont().

Here is the caller graph for this function:

◆ parse_fixed_data()

static enum GNUNET_GenericReturnValue parse_fixed_data ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to fixed size data.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 1 of file json_helper.c.

56 {
57  const char *enc;
58  unsigned int len;
59 
60  if (NULL == (enc = json_string_value (root)))
61  {
62  GNUNET_break_op (0);
63  return GNUNET_SYSERR;
64  }
65  len = strlen (enc);
66  if (((len * 5) / 8) != spec->ptr_size)
67  {
68  GNUNET_break_op (0);
70  "Field `%s' has wrong length\n",
71  spec->field);
72  return GNUNET_SYSERR;
73  }
74  if (GNUNET_OK !=
76  len,
77  spec->ptr,
78  spec->ptr_size))
79  {
80  GNUNET_break_op (0);
81  return GNUNET_SYSERR;
82  }
83  return GNUNET_OK;
84 }
static OpusEncoder * enc
OPUS encoder.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
@ GNUNET_ERROR_TYPE_WARNING
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:788
void * ptr
Pointer, details specific to the parser.
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...
size_t ptr_size
Number of bytes available in ptr.

◆ GNUNET_JSON_spec_fixed()

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).

Parameters
namename of the JSON field
[out]objpointer where to write the data, must have size bytes
sizenumber of bytes expected in obj

Definition at line 1 of file json_helper.c.

91 {
93  .parser = &parse_fixed_data,
94  .cleaner = NULL,
95  .cls = NULL,
96  .field = name,
97  .ptr = obj,
98  .ptr_size = size,
99  .size_ptr = NULL
100  };
101 
102  return ret;
103 }
static enum GNUNET_GenericReturnValue parse_fixed_data(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to fixed size data.
Definition: json_helper.c:53
static unsigned int size
Size of the "table".
Definition: peer.c:68
const char * name

◆ parse_fixed64_data()

static enum GNUNET_GenericReturnValue parse_fixed64_data ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to fixed size data.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 1 of file json_helper.c.

118 {
119  const char *enc;
120  unsigned int len;
121  void *output;
122  size_t olen;
123 
124  if (NULL == (enc = json_string_value (root)))
125  {
126  GNUNET_break_op (0);
127  return GNUNET_SYSERR;
128  }
129  len = strlen (enc);
130  output = NULL;
132  len,
133  &output);
134  if (olen != spec->ptr_size)
135  {
136  GNUNET_break_op (0);
138  "Field `%s' has wrong length\n",
139  spec->field);
140  GNUNET_free (output);
141  return GNUNET_SYSERR;
142  }
143  memcpy (spec->ptr,
144  output,
145  olen);
146  GNUNET_free (output);
147  return GNUNET_OK;
148 }
#define GNUNET_free(ptr)
Wrapper around free.
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1695

◆ GNUNET_JSON_spec_fixed64()

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).

Parameters
namename of the JSON field
[out]objpointer where to write the data, must have size bytes
sizenumber of bytes expected in obj

Definition at line 1 of file json_helper.c.

155 {
156  struct GNUNET_JSON_Specification ret = {
157  .parser = &parse_fixed64_data,
158  .cleaner = NULL,
159  .cls = NULL,
160  .field = name,
161  .ptr = obj,
162  .ptr_size = size,
163  .size_ptr = NULL
164  };
165 
166  return ret;
167 }
static enum GNUNET_GenericReturnValue parse_fixed64_data(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to fixed size data.
Definition: json_helper.c:115

◆ parse_variable_data()

static enum GNUNET_GenericReturnValue parse_variable_data ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to variable size data.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 1 of file json_helper.c.

182 {
183  const char *str;
184  size_t size;
185  void *data;
186 
187  str = json_string_value (root);
188  if (NULL == str)
189  {
190  GNUNET_break_op (0);
191  return GNUNET_SYSERR;
192  }
193  if (GNUNET_OK !=
195  strlen (str),
196  &data,
197  &size))
198  {
199  GNUNET_break_op (0);
200  return GNUNET_SYSERR;
201  }
202  *(void **) spec->ptr = data;
203  *spec->size_ptr = size;
204  return GNUNET_OK;
205 }
uint32_t data
The data value.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data_alloc(const char *enc, size_t enclen, void **out, size_t *out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:854
size_t * size_ptr
Where should we store the final size of ptr.

◆ clean_variable_data()

static void clean_variable_data ( void *  cls,
struct GNUNET_JSON_Specification spec 
)
static

Cleanup data left from parsing variable size data.

Parameters
clsclosure, NULL
[out]specwhere to free the data

Definition at line 215 of file json_helper.c.

217 {
218  (void) cls;
219  if (0 != *spec->size_ptr)
220  {
221  GNUNET_free (*(void **) spec->ptr);
222  *(void **) spec->ptr = NULL;
223  *spec->size_ptr = 0;
224  }
225 }

References GNUNET_JSON_Specification::cls, GNUNET_free, GNUNET_JSON_Specification::ptr, and GNUNET_JSON_Specification::size_ptr.

◆ GNUNET_JSON_spec_varsize()

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).

Parameters
namename of the JSON field
[out]objpointer where to write the data, will be allocated
[out]sizewhere to store the number of bytes allocated for obj

Definition at line 215 of file json_helper.c.

232 {
233  struct GNUNET_JSON_Specification ret = {
234  .parser = &parse_variable_data,
235  .cleaner = &clean_variable_data,
236  .cls = NULL,
237  .field = name,
238  .ptr = obj,
239  .ptr_size = 0,
240  .size_ptr = size
241  };
242 
243  *obj = NULL;
244  *size = 0;
245  return ret;
246 }
static void clean_variable_data(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing variable size data.
Definition: json_helper.c:215
static enum GNUNET_GenericReturnValue parse_variable_data(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to variable size data.
Definition: json_helper.c:179

◆ parse_string()

static enum GNUNET_GenericReturnValue parse_string ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to string.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 215 of file json_helper.c.

261 {
262  const char *str;
263 
264  (void) cls;
265  str = json_string_value (root);
266  if (NULL == str)
267  {
268  GNUNET_break_op (0);
269  return GNUNET_SYSERR;
270  }
271  *(const char **) spec->ptr = str;
272  return GNUNET_OK;
273 }

◆ GNUNET_JSON_spec_string()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_string ( const char *  name,
const char **  strptr 
)

The expected field stores a string.

Parameters
namename of the JSON field
strptrwhere to store a pointer to the field

Definition at line 215 of file json_helper.c.

279 {
280  struct GNUNET_JSON_Specification ret = {
281  .parser = &parse_string,
282  .cleaner = NULL,
283  .cls = NULL,
284  .field = name,
285  .ptr = strptr,
286  .ptr_size = 0,
287  .size_ptr = NULL
288  };
289 
290  *strptr = NULL;
291  return ret;
292 }
static enum GNUNET_GenericReturnValue parse_string(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to string.
Definition: json_helper.c:258

◆ parse_json()

static enum GNUNET_GenericReturnValue parse_json ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a JSON object.

(Yes, trivial.)

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 215 of file json_helper.c.

307 {
308  if (! (json_is_object (root) || json_is_array (root)))
309  {
310  GNUNET_break_op (0);
311  return GNUNET_SYSERR;
312  }
313  json_incref (root);
314  *(json_t **) spec->ptr = root;
315  return GNUNET_OK;
316 }

◆ clean_json()

static void clean_json ( void *  cls,
struct GNUNET_JSON_Specification spec 
)
static

Cleanup data left from parsing JSON object.

Parameters
clsclosure, NULL
[out]specwhere to free the data

Definition at line 326 of file json_helper.c.

328 {
329  json_t **ptr = (json_t **) spec->ptr;
330 
331  if (NULL != *ptr)
332  {
333  json_decref (*ptr);
334  *ptr = NULL;
335  }
336 }

References GNUNET_JSON_Specification::ptr.

◆ GNUNET_JSON_spec_json()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_json ( const char *  name,
json_t **  jsonp 
)

JSON object or array.

Reference counter is incremented.

Parameters
namename of the JSON field
[out]jsonpwhere to store the JSON found under name

Definition at line 326 of file json_helper.c.

342 {
343  struct GNUNET_JSON_Specification ret = {
344  .parser = &parse_json,
345  .cleaner = &clean_json,
346  .cls = NULL,
347  .field = name,
348  .ptr = jsonp,
349  .ptr_size = 0,
350  .size_ptr = NULL
351  };
352 
353  *jsonp = NULL;
354  return ret;
355 }
static void clean_json(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing JSON object.
Definition: json_helper.c:326
static enum GNUNET_GenericReturnValue parse_json(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a JSON object.
Definition: json_helper.c:304

◆ parse_object_const()

static enum GNUNET_GenericReturnValue parse_object_const ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a JSON object.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 326 of file json_helper.c.

370 {
371  if (NULL == root)
372  return GNUNET_OK;
373  if (! json_is_object (root))
374  {
375  GNUNET_break_op (0);
376  return GNUNET_SYSERR;
377  }
378  *(const json_t **) spec->ptr = (const json_t *) root;
379  return GNUNET_OK;
380 }

◆ GNUNET_JSON_spec_object_const()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_object_const ( const char *  name,
const json_t **  jsonp 
)

JSON object, reference counter not incremented.

Parameters
namename of the JSON field
[out]jsonpwhere to store the JSON found under name

Definition at line 326 of file json_helper.c.

386 {
387  struct GNUNET_JSON_Specification ret = {
388  .parser = &parse_object_const,
389  .cls = NULL,
390  .field = name,
391  .ptr = jsonp,
392  .ptr_size = 0,
393  .size_ptr = NULL
394  };
395 
396  *jsonp = NULL;
397  return ret;
398 }
static enum GNUNET_GenericReturnValue parse_object_const(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a JSON object.
Definition: json_helper.c:367

◆ parse_array_const()

static enum GNUNET_GenericReturnValue parse_array_const ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON to a JSON array.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 326 of file json_helper.c.

413 {
414  if (NULL == root)
415  return GNUNET_OK;
416  if (! json_is_array (root))
417  {
418  GNUNET_break_op (0);
419  return GNUNET_SYSERR;
420  }
421  *(const json_t **) spec->ptr = (const json_t *) root;
422  return GNUNET_OK;
423 }

◆ GNUNET_JSON_spec_array_const()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_array_const ( const char *  name,
const json_t **  jsonp 
)

JSON array, reference counter not incremented.

Parameters
namename of the JSON field
[out]jsonpwhere to store the JSON found under name

Definition at line 326 of file json_helper.c.

429 {
430  struct GNUNET_JSON_Specification ret = {
431  .parser = &parse_array_const,
432  .cls = NULL,
433  .field = name,
434  .ptr = jsonp,
435  .ptr_size = 0,
436  .size_ptr = NULL
437  };
438 
439  *jsonp = NULL;
440  return ret;
441 }
static enum GNUNET_GenericReturnValue parse_array_const(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON to a JSON array.
Definition: json_helper.c:410

◆ parse_bool()

static enum GNUNET_GenericReturnValue parse_bool ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a bool.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 326 of file json_helper.c.

456 {
457  bool *b = spec->ptr;
458 
459  if (json_true () == root)
460  {
461  *b = true;
462  return GNUNET_OK;
463  }
464  if (json_false () == root)
465  {
466  *b = false;
467  return GNUNET_OK;
468  }
469  GNUNET_break_op (0);
470  return GNUNET_SYSERR;
471 }

◆ GNUNET_JSON_spec_bool()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_bool ( const char *  name,
bool *  b 
)

boolean.

Parameters
namename of the JSON field
[out]bwhere to store the boolean found under name

Definition at line 326 of file json_helper.c.

477 {
478  struct GNUNET_JSON_Specification ret = {
479  .parser = &parse_bool,
480  .cleaner = NULL,
481  .cls = NULL,
482  .field = name,
483  .ptr = b,
484  .ptr_size = sizeof(bool),
485  .size_ptr = NULL
486  };
487 
488  return ret;
489 }
static enum GNUNET_GenericReturnValue parse_bool(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a bool.
Definition: json_helper.c:453

◆ parse_u8()

static enum GNUNET_GenericReturnValue parse_u8 ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a uint8_t.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 326 of file json_helper.c.

504 {
505  json_int_t val;
506  uint8_t *up = spec->ptr;
507 
508  if (! json_is_integer (root))
509  {
510  GNUNET_break_op (0);
511  return GNUNET_SYSERR;
512  }
513  val = json_integer_value (root);
514  if ((0 > val) || (val > UINT8_MAX))
515  {
516  GNUNET_break_op (0);
517  return GNUNET_SYSERR;
518  }
519  *up = (uint8_t) val;
520  return GNUNET_OK;
521 }

◆ GNUNET_JSON_spec_uint8()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint8 ( const char *  name,
uint8_t *  u8 
)

8-bit integer.

Parameters
namename of the JSON field
[out]u8where to store the integer found under name

Definition at line 326 of file json_helper.c.

527 {
528  struct GNUNET_JSON_Specification ret = {
529  .parser = &parse_u8,
530  .cleaner = NULL,
531  .cls = NULL,
532  .field = name,
533  .ptr = u8,
534  .ptr_size = sizeof(uint8_t),
535  .size_ptr = NULL
536  };
537 
538  return ret;
539 }
static enum GNUNET_GenericReturnValue parse_u8(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint8_t.
Definition: json_helper.c:501

◆ parse_u16()

static enum GNUNET_GenericReturnValue parse_u16 ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a uint16_t.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 326 of file json_helper.c.

554 {
555  json_int_t val;
556  uint16_t *up = spec->ptr;
557 
558  if (! json_is_integer (root))
559  {
560  GNUNET_break_op (0);
561  return GNUNET_SYSERR;
562  }
563  val = json_integer_value (root);
564  if ((0 > val) || (val > UINT16_MAX))
565  {
566  GNUNET_break_op (0);
567  return GNUNET_SYSERR;
568  }
569  *up = (uint16_t) val;
570  return GNUNET_OK;
571 }

◆ GNUNET_JSON_spec_uint16()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint16 ( const char *  name,
uint16_t *  u16 
)

16-bit integer.

Parameters
namename of the JSON field
[out]u16where to store the integer found under name

Definition at line 326 of file json_helper.c.

577 {
578  struct GNUNET_JSON_Specification ret = {
579  .parser = &parse_u16,
580  .cleaner = NULL,
581  .cls = NULL,
582  .field = name,
583  .ptr = u16,
584  .ptr_size = sizeof(uint16_t),
585  .size_ptr = NULL
586  };
587 
588  return ret;
589 }
static enum GNUNET_GenericReturnValue parse_u16(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint16_t.
Definition: json_helper.c:551

◆ parse_u32()

static enum GNUNET_GenericReturnValue parse_u32 ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a uint32_t.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 326 of file json_helper.c.

604 {
605  json_int_t val;
606  uint32_t *up = spec->ptr;
607 
608  if (! json_is_integer (root))
609  {
610  GNUNET_break_op (0);
611  return GNUNET_SYSERR;
612  }
613  val = json_integer_value (root);
614  if ((0 > val) || (val > UINT32_MAX))
615  {
616  GNUNET_break_op (0);
617  return GNUNET_SYSERR;
618  }
619  *up = (uint32_t) val;
620  return GNUNET_OK;
621 }

◆ GNUNET_JSON_spec_uint32()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint32 ( const char *  name,
uint32_t *  u32 
)

32-bit integer.

Parameters
namename of the JSON field
[out]u32where to store the integer found under name

Definition at line 326 of file json_helper.c.

627 {
628  struct GNUNET_JSON_Specification ret = {
629  .parser = &parse_u32,
630  .cleaner = NULL,
631  .cls = NULL,
632  .field = name,
633  .ptr = u32,
634  .ptr_size = sizeof(uint32_t),
635  .size_ptr = NULL
636  };
637 
638  return ret;
639 }
static enum GNUNET_GenericReturnValue parse_u32(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint32_t.
Definition: json_helper.c:601

◆ parse_u64()

static enum GNUNET_GenericReturnValue parse_u64 ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a uint64_t.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 326 of file json_helper.c.

654 {
655  json_int_t val;
656  uint64_t *up = spec->ptr;
657 
658  if (! json_is_integer (root))
659  {
660  GNUNET_break_op (0);
661  return GNUNET_SYSERR;
662  }
663  val = json_integer_value (root);
664  *up = (uint64_t) val;
665  return GNUNET_OK;
666 }

◆ GNUNET_JSON_spec_uint64()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint64 ( const char *  name,
uint64_t *  u64 
)

64-bit integer.

Parameters
namename of the JSON field
[out]u64where to store the integer found under name

Definition at line 326 of file json_helper.c.

672 {
673  struct GNUNET_JSON_Specification ret = {
674  .parser = &parse_u64,
675  .cleaner = NULL,
676  .cls = NULL,
677  .field = name,
678  .ptr = u64,
679  .ptr_size = sizeof(uint64_t),
680  .size_ptr = NULL
681  };
682 
683  return ret;
684 }
static enum GNUNET_GenericReturnValue parse_u64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint64_t.
Definition: json_helper.c:651

◆ parse_i64()

static enum GNUNET_GenericReturnValue parse_i64 ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a int64_t.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 326 of file json_helper.c.

699 {
700  json_int_t val;
701  int64_t *up = spec->ptr;
702 
703  if (! json_is_integer (root))
704  {
705  GNUNET_break_op (0);
706  return GNUNET_SYSERR;
707  }
708  val = json_integer_value (root);
709  *up = (int64_t) val;
710  return GNUNET_OK;
711 }

◆ GNUNET_JSON_spec_int64()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_int64 ( const char *  name,
int64_t *  i64 
)

64-bit signed integer.

Parameters
namename of the JSON field
[out]i64where to store the integer found under name

Definition at line 326 of file json_helper.c.

717 {
718  struct GNUNET_JSON_Specification ret = {
719  .parser = &parse_i64,
720  .cleaner = NULL,
721  .cls = NULL,
722  .field = name,
723  .ptr = i64,
724  .ptr_size = sizeof(int64_t),
725  .size_ptr = NULL
726  };
727 
728  return ret;
729 }
static enum GNUNET_GenericReturnValue parse_i64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a int64_t.
Definition: json_helper.c:696

◆ parse_timestamp()

static enum GNUNET_GenericReturnValue parse_timestamp ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a timestamp.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 326 of file json_helper.c.

746 {
747  struct GNUNET_TIME_Timestamp *ts = spec->ptr;
748  json_t *json_t_s;
749  unsigned long long int tval;
750 
751  if (! json_is_object (root))
752  {
753  GNUNET_break_op (0);
754  return GNUNET_SYSERR;
755  }
756  json_t_s = json_object_get (root,
757  "t_s");
758  if (json_is_integer (json_t_s))
759  {
760  tval = json_integer_value (json_t_s);
761  /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
763  = tval * GNUNET_TIME_UNIT_SECONDS.rel_value_us;
764  if (ts->abs_time.abs_value_us
765  / GNUNET_TIME_UNIT_SECONDS.rel_value_us
766  != tval)
767  {
768  /* Integer overflow */
769  GNUNET_break_op (0);
770  return GNUNET_SYSERR;
771  }
772  return GNUNET_OK;
773  }
774  if (json_is_string (json_t_s))
775  {
776  const char *val;
777 
778  val = json_string_value (json_t_s);
779  if ((0 == strcasecmp (val,
780  "never")))
781  {
783  return GNUNET_OK;
784  }
785  GNUNET_break_op (0);
786  return GNUNET_SYSERR;
787  }
788  GNUNET_break_op (0);
789  return GNUNET_SYSERR;
790 }
#define GNUNET_TIME_UNIT_SECONDS
One second.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
uint64_t abs_value_us
The actual value.
Rounded time for timestamps used by GNUnet, in seconds.
struct GNUNET_TIME_Absolute abs_time
The actual value.

◆ GNUNET_JSON_spec_timestamp()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp ( const char *  name,
struct GNUNET_TIME_Timestamp t 
)

Timestamp.

Parameters
namename of the JSON field
[out]tat where to store the absolute time found under name

Definition at line 326 of file json_helper.c.

796 {
797  struct GNUNET_JSON_Specification ret = {
798  .parser = &parse_timestamp,
799  .field = name,
800  .ptr = t,
801  .ptr_size = sizeof(struct GNUNET_TIME_Timestamp)
802  };
803 
804  return ret;
805 }
static struct GNUNET_SCHEDULER_Task * t
Main task.
static enum GNUNET_GenericReturnValue parse_timestamp(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a timestamp.
Definition: json_helper.c:743

◆ parse_timestamp_nbo()

static enum GNUNET_GenericReturnValue parse_timestamp_nbo ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to absolute time.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 326 of file json_helper.c.

820 {
821  struct GNUNET_TIME_TimestampNBO *ts = spec->ptr;
822  struct GNUNET_TIME_Timestamp a;
823  struct GNUNET_JSON_Specification ispec;
824 
825  ispec = *spec;
826  ispec.parser = &parse_timestamp;
827  ispec.ptr = &a;
828  if (GNUNET_OK !=
829  parse_timestamp (NULL,
830  root,
831  &ispec))
832  return GNUNET_SYSERR;
833  *ts = GNUNET_TIME_timestamp_hton (a);
834  return GNUNET_OK;
835 }
struct GNUNET_TIME_TimestampNBO GNUNET_TIME_timestamp_hton(struct GNUNET_TIME_Timestamp t)
Convert timestamp to network byte order.
Definition: time.c:91
GNUNET_JSON_Parser parser
Function for how to parse this type of entry.
Time for timestamps used by GNUnet, in seconds and in network byte order.

◆ GNUNET_JSON_spec_timestamp_nbo()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp_nbo ( const char *  name,
struct GNUNET_TIME_TimestampNBO tn 
)

Timestamp in network byte order.

Parameters
namename of the JSON field
[out]tnwhere to store the absolute time found under name

Definition at line 326 of file json_helper.c.

841 {
842  struct GNUNET_JSON_Specification ret = {
843  .parser = &parse_timestamp_nbo,
844  .field = name,
845  .ptr = at,
846  .ptr_size = sizeof(struct GNUNET_TIME_TimestampNBO)
847  };
848 
849  return ret;
850 }
static enum GNUNET_GenericReturnValue parse_timestamp_nbo(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to absolute time.
Definition: json_helper.c:817

◆ parse_rel_time()

static enum GNUNET_GenericReturnValue parse_rel_time ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to relative time.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 326 of file json_helper.c.

865 {
866  struct GNUNET_TIME_Relative *rel = spec->ptr;
867  json_t *json_d_us;
868  unsigned long long int tval;
869 
870  if (! json_is_object (root))
871  {
872  GNUNET_break_op (0);
873  return GNUNET_SYSERR;
874  }
875  json_d_us = json_object_get (root,
876  "d_us");
877  if (json_is_integer (json_d_us))
878  {
879  tval = json_integer_value (json_d_us);
880  if (tval >= (1LLU << 53))
881  {
882  /* value is larger than allowed */
883  GNUNET_break_op (0);
884  return GNUNET_SYSERR;
885  }
886  rel->rel_value_us = tval;
887  return GNUNET_OK;
888  }
889  if (json_is_string (json_d_us))
890  {
891  const char *val;
892 
893  val = json_string_value (json_d_us);
894  if ((0 == strcasecmp (val,
895  "forever")))
896  {
898  return GNUNET_OK;
899  }
900  GNUNET_break_op (0);
901  return GNUNET_SYSERR;
902  }
903  GNUNET_break_op (0);
904  return GNUNET_SYSERR;
905 }
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.

◆ GNUNET_JSON_spec_relative_time()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_relative_time ( const char *  name,
struct GNUNET_TIME_Relative rt 
)

Relative time.

Parameters
namename of the JSON field
[out]rtwhere to store the relative time found under name

Definition at line 326 of file json_helper.c.

911 {
912  struct GNUNET_JSON_Specification ret = {
913  .parser = &parse_rel_time,
914  .field = name,
915  .ptr = rt,
916  .ptr_size = sizeof(struct GNUNET_TIME_Relative)
917  };
918 
919  return ret;
920 }
static enum GNUNET_GenericReturnValue parse_rel_time(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to relative time.
Definition: json_helper.c:862

◆ parse_rsa_public_key()

static enum GNUNET_GenericReturnValue parse_rsa_public_key ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to RSA public key.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 326 of file json_helper.c.

935 {
936  struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
937  const char *enc;
938  char *buf;
939  size_t len;
940  size_t buf_len;
941 
942  if (NULL == (enc = json_string_value (root)))
943  {
944  GNUNET_break_op (0);
945  return GNUNET_SYSERR;
946  }
947  len = strlen (enc);
948  buf_len = (len * 5) / 8;
949  buf = GNUNET_malloc (buf_len);
950  if (GNUNET_OK !=
952  len,
953  buf,
954  buf_len))
955  {
956  GNUNET_break_op (0);
957  GNUNET_free (buf);
958  return GNUNET_SYSERR;
959  }
960  if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode (buf,
961  buf_len)))
962  {
963  GNUNET_break_op (0);
964  GNUNET_free (buf);
965  return GNUNET_SYSERR;
966  }
967  GNUNET_free (buf);
968  return GNUNET_OK;
969 }
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
static char buf[2048]
struct GNUNET_CRYPTO_RsaPublicKey * GNUNET_CRYPTO_rsa_public_key_decode(const char *buf, size_t len)
Decode the public key from the data-format back to the "normal", internal format.
Definition: crypto_rsa.c:423
#define GNUNET_malloc(size)
Wrapper around malloc.
The public information of an RSA key pair.
Definition: crypto_rsa.c:53

◆ clean_rsa_public_key()

static void clean_rsa_public_key ( void *  cls,
struct GNUNET_JSON_Specification spec 
)
static

Cleanup data left from parsing RSA public key.

Parameters
clsclosure, NULL
[out]specwhere to free the data

Definition at line 979 of file json_helper.c.

981 {
982  struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
983 
984  if (NULL != *pk)
985  {
987  *pk = NULL;
988  }
989 }
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
Definition: crypto_rsa.c:268

References GNUNET_CRYPTO_rsa_public_key_free(), pk, and GNUNET_JSON_Specification::ptr.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_rsa_public_key()

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.

Parameters
namename of the JSON field
pkwhere to store the RSA key found under name

Definition at line 979 of file json_helper.c.

995 {
996  struct GNUNET_JSON_Specification ret = {
997  .parser = &parse_rsa_public_key,
998  .cleaner = &clean_rsa_public_key,
999  .field = name,
1000  .ptr = pk
1001  };
1002 
1003  *pk = NULL;
1004  return ret;
1005 }
static void clean_rsa_public_key(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA public key.
Definition: json_helper.c:979
static enum GNUNET_GenericReturnValue parse_rsa_public_key(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to RSA public key.
Definition: json_helper.c:932

◆ parse_rsa_signature()

static enum GNUNET_GenericReturnValue parse_rsa_signature ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to RSA signature.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 979 of file json_helper.c.

1020 {
1021  struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
1022  size_t size;
1023  const char *str;
1024  int res;
1025  void *buf;
1026 
1027  str = json_string_value (root);
1028  if (NULL == str)
1029  {
1030  GNUNET_break_op (0);
1031  return GNUNET_SYSERR;
1032  }
1033  size = (strlen (str) * 5) / 8;
1034  buf = GNUNET_malloc (size);
1036  strlen (str),
1037  buf,
1038  size);
1039  if (GNUNET_OK != res)
1040  {
1041  GNUNET_free (buf);
1042  GNUNET_break_op (0);
1043  return GNUNET_SYSERR;
1044  }
1045  if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode (buf,
1046  size)))
1047  {
1048  GNUNET_break_op (0);
1049  GNUNET_free (buf);
1050  return GNUNET_SYSERR;
1051  }
1052  GNUNET_free (buf);
1053  return GNUNET_OK;
1054 }
static int res
struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_signature_decode(const void *buf, size_t buf_size)
Decode the signature from the data-format back to the "normal", internal format.
Definition: crypto_rsa.c:1039
an RSA signature
Definition: crypto_rsa.c:65

◆ clean_rsa_signature()

static void clean_rsa_signature ( void *  cls,
struct GNUNET_JSON_Specification spec 
)
static

Cleanup data left from parsing RSA signature.

Parameters
clsclosure, NULL
[out]specwhere to free the data

Definition at line 1064 of file json_helper.c.

1066 {
1067  struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
1068 
1069  if (NULL != *sig)
1070  {
1072  *sig = NULL;
1073  }
1074 }
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.
Definition: crypto_rsa.c:991

References GNUNET_CRYPTO_rsa_signature_free(), and GNUNET_JSON_Specification::ptr.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_rsa_signature()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_signature ( const char *  name,
struct GNUNET_CRYPTO_RsaSignature **  sig 
)

Specification for parsing an RSA signature.

Parameters
namename of the JSON field
sigwhere to store the RSA signature found under name

Definition at line 1064 of file json_helper.c.

1080 {
1081  struct GNUNET_JSON_Specification ret = {
1082  .parser = &parse_rsa_signature,
1083  .cleaner = &clean_rsa_signature,
1084  .cls = NULL,
1085  .field = name,
1086  .ptr = sig,
1087  .ptr_size = 0,
1088  .size_ptr = NULL
1089  };
1090 
1091  *sig = NULL;
1092  return ret;
1093 }
static enum GNUNET_GenericReturnValue parse_rsa_signature(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to RSA signature.
Definition: json_helper.c:1017
static void clean_rsa_signature(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA signature.
Definition: json_helper.c:1064

◆ parse_boolean()

static enum GNUNET_GenericReturnValue parse_boolean ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to an int as a boolean.

Parameters
clsclosure, NULL
rootthe json object representing data
[out]specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 1064 of file json_helper.c.

1108 {
1109  int *bp = spec->ptr;
1110 
1111  if (! json_is_boolean (root))
1112  {
1113  GNUNET_break_op (0);
1114  return GNUNET_SYSERR;
1115  }
1116  *bp = json_boolean_value (root) ? GNUNET_YES : GNUNET_NO;
1117  return GNUNET_OK;
1118 }
@ GNUNET_YES
@ GNUNET_NO

◆ GNUNET_JSON_spec_boolean()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_boolean ( const char *  name,
int *  boolean 
)

Boolean (true mapped to GNUNET_YES, false mapped to GNUNET_NO).

Parameters
namename of the JSON field
[out]booleanwhere to store the boolean found under name

Definition at line 1064 of file json_helper.c.

1124 {
1125  struct GNUNET_JSON_Specification ret = {
1126  .parser = &parse_boolean,
1127  .cleaner = NULL,
1128  .cls = NULL,
1129  .field = name,
1130  .ptr = boolean,
1131  .ptr_size = sizeof(int),
1132  .size_ptr = NULL
1133  };
1134 
1135  return ret;
1136 }
static enum GNUNET_GenericReturnValue parse_boolean(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to an int as a boolean.
Definition: json_helper.c:1105