GNUnet  0.11.x
Functions
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 int 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 int 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 int 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 int parse_object (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a JSON object. More...
 
static void clean_object (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. More...
 
static int 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 int 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 int 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 int 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 int 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 int 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 int parse_abs_time (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_absolute_time (const char *name, struct GNUNET_TIME_Absolute *at)
 Absolute time. More...
 
static int parse_abs_time_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_absolute_time_nbo (const char *name, struct GNUNET_TIME_AbsoluteNBO *at)
 Absolute time in network byte order. More...
 
static int 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 int 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 int 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 int 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 35 of file json_helper.c.

References GNUNET_JSON_Specification::parser, and ret.

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

36 {
38  .parser = NULL,
39  .cleaner = NULL,
40  .cls = NULL
41  };
42 
43  return ret;
44 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
Here is the caller graph for this function:

◆ parse_fixed_data()

static int 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 56 of file json_helper.c.

References enc, GNUNET_break_op, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, len, GNUNET_JSON_Specification::ptr, and GNUNET_JSON_Specification::ptr_size.

Referenced by GNUNET_JSON_spec_fixed().

59 {
60  const char *enc;
61  unsigned int len;
62 
63  if (NULL == (enc = json_string_value (root)))
64  {
65  GNUNET_break_op (0);
66  return GNUNET_SYSERR;
67  }
68  len = strlen (enc);
69  if (((len * 5) / 8) != spec->ptr_size)
70  {
71  GNUNET_break_op (0);
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 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
static OpusEncoder * enc
OPUS encoder.
size_t ptr_size
Number of bytes available in ptr.
int 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:972
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 96 of file json_helper.c.

References name, parse_fixed_data(), GNUNET_JSON_Specification::parser, ret, and size.

99 {
100  struct GNUNET_JSON_Specification ret = {
101  .parser = &parse_fixed_data,
102  .cleaner = NULL,
103  .cls = NULL,
104  .field = name,
105  .ptr = obj,
106  .ptr_size = size,
107  .size_ptr = NULL
108  };
109 
110  return ret;
111 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static unsigned int size
Size of the "table".
Definition: peer.c:67
const char * name
static int 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:56
Here is the call graph for this function:

◆ parse_variable_data()

static int 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 123 of file json_helper.c.

References data, GNUNET_break_op, GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, GNUNET_JSON_Specification::ptr, res, size, and GNUNET_JSON_Specification::size_ptr.

Referenced by GNUNET_JSON_spec_varsize().

126 {
127  const char *str;
128  size_t size;
129  void *data;
130  int res;
131 
132  str = json_string_value (root);
133  if (NULL == str)
134  {
135  GNUNET_break_op (0);
136  return GNUNET_SYSERR;
137  }
138  size = (strlen (str) * 5) / 8;
139  if (size >= 1024)
140  {
141  GNUNET_break_op (0);
142  return GNUNET_SYSERR;
143  }
144  data = GNUNET_malloc (size);
146  strlen (str),
147  data,
148  size);
149  if (GNUNET_OK != res)
150  {
151  GNUNET_break_op (0);
152  GNUNET_free (data);
153  return GNUNET_SYSERR;
154  }
155  *(void **) spec->ptr = data;
156  *spec->size_ptr = size;
157  return GNUNET_OK;
158 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
static int res
static unsigned int size
Size of the "table".
Definition: peer.c:67
void * ptr
Pointer, details specific to the parser.
size_t * size_ptr
Where should we store the final size of ptr.
uint32_t data
The data value.
#define GNUNET_malloc(size)
Wrapper around malloc.
int 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:972
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 168 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_varsize().

170 {
171  if (0 != *spec->size_ptr)
172  {
173  GNUNET_free (*(void **) spec->ptr);
174  *(void **) spec->ptr = NULL;
175  *spec->size_ptr = 0;
176  }
177 }
void * ptr
Pointer, details specific to the parser.
size_t * size_ptr
Where should we store the final size of ptr.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ 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 189 of file json_helper.c.

References clean_variable_data(), name, parse_variable_data(), GNUNET_JSON_Specification::parser, ret, and size.

192 {
193  struct GNUNET_JSON_Specification ret = {
194  .parser = &parse_variable_data,
195  .cleaner = &clean_variable_data,
196  .cls = NULL,
197  .field = name,
198  .ptr = obj,
199  .ptr_size = 0,
200  .size_ptr = size
201  };
202 
203  *obj = NULL;
204  *size = 0;
205  return ret;
206 }
static void clean_variable_data(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing variable size data.
Definition: json_helper.c:168
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static unsigned int size
Size of the "table".
Definition: peer.c:67
static int 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:123
const char * name
Here is the call graph for this function:

◆ parse_string()

static int 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 218 of file json_helper.c.

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_string().

221 {
222  const char *str;
223 
224  str = json_string_value (root);
225  if (NULL == str)
226  {
227  GNUNET_break_op (0);
228  return GNUNET_SYSERR;
229  }
230  *(const char **) spec->ptr = str;
231  return GNUNET_OK;
232 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Here is the caller graph for this function:

◆ 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 242 of file json_helper.c.

References name, parse_string(), GNUNET_JSON_Specification::parser, and ret.

244 {
245  struct GNUNET_JSON_Specification ret = {
246  .parser = &parse_string,
247  .cleaner = NULL,
248  .cls = NULL,
249  .field = name,
250  .ptr = strptr,
251  .ptr_size = 0,
252  .size_ptr = NULL
253  };
254 
255  *strptr = NULL;
256  return ret;
257 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_string(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to string.
Definition: json_helper.c:218
const char * name
Here is the call graph for this function:

◆ parse_object()

static int parse_object ( 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 269 of file json_helper.c.

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_json().

272 {
273  if (! (json_is_object (root) || json_is_array (root)))
274  {
275  GNUNET_break_op (0);
276  return GNUNET_SYSERR;
277  }
278  json_incref (root);
279  *(json_t **) spec->ptr = root;
280  return GNUNET_OK;
281 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Here is the caller graph for this function:

◆ clean_object()

static void clean_object ( 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 291 of file json_helper.c.

References GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_json().

293 {
294  json_t **ptr = (json_t **) spec->ptr;
295 
296  if (NULL != *ptr)
297  {
298  json_decref (*ptr);
299  *ptr = NULL;
300  }
301 }
void * ptr
Pointer, details specific to the parser.
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_json()

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

JSON object.

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

Definition at line 311 of file json_helper.c.

References clean_object(), name, parse_object(), GNUNET_JSON_Specification::parser, and ret.

313 {
314  struct GNUNET_JSON_Specification ret = {
315  .parser = &parse_object,
316  .cleaner = &clean_object,
317  .cls = NULL,
318  .field = name,
319  .ptr = jsonp,
320  .ptr_size = 0,
321  .size_ptr = NULL
322  };
323 
324  *jsonp = NULL;
325  return ret;
326 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_object(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a JSON object.
Definition: json_helper.c:269
static void clean_object(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing JSON object.
Definition: json_helper.c:291
const char * name
Here is the call graph for this function:

◆ parse_bool()

static int 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 338 of file json_helper.c.

References testconfigure::b, GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_bool().

341 {
342  bool *b = spec->ptr;
343 
344  if (json_true () == root)
345  {
346  *b = true;
347  return GNUNET_OK;
348  }
349  if (json_false () == root)
350  {
351  *b = false;
352  return GNUNET_OK;
353  }
354  GNUNET_break_op (0);
355  return GNUNET_SYSERR;
356 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Here is the caller graph for this function:

◆ 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 366 of file json_helper.c.

References testconfigure::b, name, parse_bool(), GNUNET_JSON_Specification::parser, ret, and GNUNET_JSON_Specification::size_ptr.

368 {
369  struct GNUNET_JSON_Specification ret = {
370  .parser = &parse_bool,
371  .cleaner = NULL,
372  .cls = NULL,
373  .field = name,
374  .ptr = b,
375  .ptr_size = sizeof(bool),
376  .size_ptr = NULL
377  };
378 
379  return ret;
380 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_bool(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a bool.
Definition: json_helper.c:338
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
Here is the call graph for this function:

◆ parse_u8()

static int 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 392 of file json_helper.c.

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_uint8().

395 {
396  json_int_t val;
397  uint8_t *up = spec->ptr;
398 
399  if (! json_is_integer (root))
400  {
401  GNUNET_break_op (0);
402  return GNUNET_SYSERR;
403  }
404  val = json_integer_value (root);
405  if ((0 > val) || (val > UINT8_MAX))
406  {
407  GNUNET_break_op (0);
408  return GNUNET_SYSERR;
409  }
410  *up = (uint8_t) val;
411  return GNUNET_OK;
412 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Here is the caller graph for this function:

◆ 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 422 of file json_helper.c.

References name, parse_u8(), GNUNET_JSON_Specification::parser, ret, and GNUNET_JSON_Specification::size_ptr.

424 {
425  struct GNUNET_JSON_Specification ret = {
426  .parser = &parse_u8,
427  .cleaner = NULL,
428  .cls = NULL,
429  .field = name,
430  .ptr = u8,
431  .ptr_size = sizeof(uint8_t),
432  .size_ptr = NULL
433  };
434 
435  return ret;
436 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
static int parse_u8(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint8_t.
Definition: json_helper.c:392
Here is the call graph for this function:

◆ parse_u16()

static int 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 448 of file json_helper.c.

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_uint16().

451 {
452  json_int_t val;
453  uint16_t *up = spec->ptr;
454 
455  if (! json_is_integer (root))
456  {
457  GNUNET_break_op (0);
458  return GNUNET_SYSERR;
459  }
460  val = json_integer_value (root);
461  if ((0 > val) || (val > UINT16_MAX))
462  {
463  GNUNET_break_op (0);
464  return GNUNET_SYSERR;
465  }
466  *up = (uint16_t) val;
467  return GNUNET_OK;
468 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Here is the caller graph for this function:

◆ 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 478 of file json_helper.c.

References name, parse_u16(), GNUNET_JSON_Specification::parser, ret, and GNUNET_JSON_Specification::size_ptr.

480 {
481  struct GNUNET_JSON_Specification ret = {
482  .parser = &parse_u16,
483  .cleaner = NULL,
484  .cls = NULL,
485  .field = name,
486  .ptr = u16,
487  .ptr_size = sizeof(uint16_t),
488  .size_ptr = NULL
489  };
490 
491  return ret;
492 }
static int parse_u16(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint16_t.
Definition: json_helper.c:448
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
Here is the call graph for this function:

◆ parse_u32()

static int 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 504 of file json_helper.c.

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_uint32().

507 {
508  json_int_t val;
509  uint32_t *up = spec->ptr;
510 
511  if (! json_is_integer (root))
512  {
513  GNUNET_break_op (0);
514  return GNUNET_SYSERR;
515  }
516  val = json_integer_value (root);
517  if ((0 > val) || (val > UINT32_MAX))
518  {
519  GNUNET_break_op (0);
520  return GNUNET_SYSERR;
521  }
522  *up = (uint32_t) val;
523  return GNUNET_OK;
524 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Here is the caller graph for this function:

◆ 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 534 of file json_helper.c.

References name, parse_u32(), GNUNET_JSON_Specification::parser, ret, and GNUNET_JSON_Specification::size_ptr.

536 {
537  struct GNUNET_JSON_Specification ret = {
538  .parser = &parse_u32,
539  .cleaner = NULL,
540  .cls = NULL,
541  .field = name,
542  .ptr = u32,
543  .ptr_size = sizeof(uint32_t),
544  .size_ptr = NULL
545  };
546 
547  return ret;
548 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_u32(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint32_t.
Definition: json_helper.c:504
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
Here is the call graph for this function:

◆ parse_u64()

static int 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 560 of file json_helper.c.

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_uint64().

563 {
564  json_int_t val;
565  uint64_t *up = spec->ptr;
566 
567  if (! json_is_integer (root))
568  {
569  GNUNET_break_op (0);
570  return GNUNET_SYSERR;
571  }
572  val = json_integer_value (root);
573  *up = (uint64_t) val;
574  return GNUNET_OK;
575 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Here is the caller graph for this function:

◆ 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 585 of file json_helper.c.

References name, parse_u64(), GNUNET_JSON_Specification::parser, ret, and GNUNET_JSON_Specification::size_ptr.

587 {
588  struct GNUNET_JSON_Specification ret = {
589  .parser = &parse_u64,
590  .cleaner = NULL,
591  .cls = NULL,
592  .field = name,
593  .ptr = u64,
594  .ptr_size = sizeof(uint64_t),
595  .size_ptr = NULL
596  };
597 
598  return ret;
599 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_u64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint64_t.
Definition: json_helper.c:560
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
Here is the call graph for this function:

◆ parse_i64()

static int 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 611 of file json_helper.c.

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_int64().

614 {
615  json_int_t val;
616  int64_t *up = spec->ptr;
617 
618  if (! json_is_integer (root))
619  {
620  GNUNET_break_op (0);
621  return GNUNET_SYSERR;
622  }
623  val = json_integer_value (root);
624  *up = (int64_t) val;
625  return GNUNET_OK;
626 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Here is the caller graph for this function:

◆ 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 636 of file json_helper.c.

References name, parse_i64(), GNUNET_JSON_Specification::parser, ret, and GNUNET_JSON_Specification::size_ptr.

638 {
639  struct GNUNET_JSON_Specification ret = {
640  .parser = &parse_i64,
641  .cleaner = NULL,
642  .cls = NULL,
643  .field = name,
644  .ptr = i64,
645  .ptr_size = sizeof(int64_t),
646  .size_ptr = NULL
647  };
648 
649  return ret;
650 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_i64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a int64_t.
Definition: json_helper.c:611
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
Here is the call graph for this function:

◆ parse_abs_time()

static int parse_abs_time ( 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 664 of file json_helper.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_ABS, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_absolute_time(), and parse_abs_time_nbo().

667 {
668  struct GNUNET_TIME_Absolute *abs = spec->ptr;
669  json_t *json_t_ms;
670  unsigned long long int tval;
671 
672  if (! json_is_object (root))
673  {
674  GNUNET_break_op (0);
675  return GNUNET_SYSERR;
676  }
677  json_t_ms = json_object_get (root, "t_ms");
678  if (json_is_integer (json_t_ms))
679  {
680  tval = json_integer_value (json_t_ms);
681  /* Time is in milliseconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
682  abs->abs_value_us = tval * 1000LL;
683  if ((abs->abs_value_us) / 1000LL != tval)
684  {
685  /* Integer overflow */
686  GNUNET_break_op (0);
687  return GNUNET_SYSERR;
688  }
689  return GNUNET_OK;
690  }
691  if (json_is_string (json_t_ms))
692  {
693  const char *val;
694  val = json_string_value (json_t_ms);
695  if ((0 == strcasecmp (val, "never")))
696  {
698  return GNUNET_OK;
699  }
700  GNUNET_break_op (0);
701  return GNUNET_SYSERR;
702  }
703  GNUNET_break_op (0);
704  return GNUNET_SYSERR;
705 }
uint64_t abs_value_us
The actual value.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Time for absolute times used by GNUnet, in microseconds.
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_absolute_time()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_absolute_time ( const char *  name,
struct GNUNET_TIME_Absolute at 
)

Absolute time.

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

Definition at line 715 of file json_helper.c.

References name, parse_abs_time(), GNUNET_JSON_Specification::parser, and ret.

717 {
718  struct GNUNET_JSON_Specification ret = {
719  .parser = &parse_abs_time,
720  .cleaner = NULL,
721  .cls = NULL,
722  .field = name,
723  .ptr = at,
724  .ptr_size = sizeof(struct GNUNET_TIME_Absolute),
725  .size_ptr = NULL
726  };
727 
728  return ret;
729 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
const char * name
Time for absolute times used by GNUnet, in microseconds.
static int parse_abs_time(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to absolute time.
Definition: json_helper.c:664
Here is the call graph for this function:

◆ parse_abs_time_nbo()

static int parse_abs_time_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 741 of file json_helper.c.

References GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_absolute_hton(), parse_abs_time(), GNUNET_JSON_Specification::parser, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_absolute_time_nbo().

744 {
745  struct GNUNET_TIME_AbsoluteNBO *abs = spec->ptr;
746  struct GNUNET_TIME_Absolute a;
747  struct GNUNET_JSON_Specification ispec;
748 
749  ispec = *spec;
750  ispec.parser = &parse_abs_time;
751  ispec.ptr = &a;
752  if (GNUNET_OK !=
753  parse_abs_time (NULL,
754  root,
755  &ispec))
756  return GNUNET_SYSERR;
757  *abs = GNUNET_TIME_absolute_hton (a);
758  return GNUNET_OK;
759 }
Entry in parser specification for GNUNET_JSON_parse().
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
GNUNET_JSON_Parser parser
Function for how to parse this type of entry.
void * ptr
Pointer, details specific to the parser.
Time for absolute times used by GNUnet, in microseconds.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
static int parse_abs_time(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to absolute time.
Definition: json_helper.c:664
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_absolute_time_nbo()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_absolute_time_nbo ( const char *  name,
struct GNUNET_TIME_AbsoluteNBO at 
)

Absolute time in network byte order.

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

Definition at line 769 of file json_helper.c.

References name, parse_abs_time_nbo(), GNUNET_JSON_Specification::parser, and ret.

771 {
772  struct GNUNET_JSON_Specification ret = {
773  .parser = &parse_abs_time_nbo,
774  .cleaner = NULL,
775  .cls = NULL,
776  .field = name,
777  .ptr = at,
778  .ptr_size = sizeof(struct GNUNET_TIME_AbsoluteNBO),
779  .size_ptr = NULL
780  };
781 
782  return ret;
783 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
const char * name
static int parse_abs_time_nbo(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to absolute time.
Definition: json_helper.c:741
Here is the call graph for this function:

◆ parse_rel_time()

static int 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 795 of file json_helper.c.

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_JSON_Specification::ptr, and GNUNET_TIME_Relative::rel_value_us.

Referenced by GNUNET_JSON_spec_relative_time().

798 {
799  struct GNUNET_TIME_Relative *rel = spec->ptr;
800  json_t *json_d_ms;
801  unsigned long long int tval;
802 
803  if (! json_is_object (root))
804  {
805  GNUNET_break_op (0);
806  return GNUNET_SYSERR;
807  }
808  json_d_ms = json_object_get (root, "d_ms");
809  if (json_is_integer (json_d_ms))
810  {
811  tval = json_integer_value (json_d_ms);
812  /* Time is in milliseconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
813  rel->rel_value_us = tval * 1000LL;
814  if ((rel->rel_value_us) / 1000LL != tval)
815  {
816  /* Integer overflow */
817  GNUNET_break_op (0);
818  return GNUNET_SYSERR;
819  }
820  return GNUNET_OK;
821  }
822  if (json_is_string (json_d_ms))
823  {
824  const char *val;
825  val = json_string_value (json_d_ms);
826  if ((0 == strcasecmp (val, "forever")))
827  {
829  return GNUNET_OK;
830  }
831  GNUNET_break_op (0);
832  return GNUNET_SYSERR;
833  }
834  GNUNET_break_op (0);
835  return GNUNET_SYSERR;
836 }
uint64_t rel_value_us
The actual value.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
void * ptr
Pointer, details specific to the parser.
Time for relative time used by GNUnet, in microseconds.
Here is the caller graph for this function:

◆ 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 846 of file json_helper.c.

References name, parse_rel_time(), GNUNET_JSON_Specification::parser, and ret.

848 {
849  struct GNUNET_JSON_Specification ret = {
850  .parser = &parse_rel_time,
851  .cleaner = NULL,
852  .cls = NULL,
853  .field = name,
854  .ptr = rt,
855  .ptr_size = sizeof(struct GNUNET_TIME_Relative),
856  .size_ptr = NULL
857  };
858 
859  return ret;
860 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_rel_time(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to relative time.
Definition: json_helper.c:795
const char * name
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:

◆ parse_rsa_public_key()

static int 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 872 of file json_helper.c.

References buf, enc, GNUNET_break_op, GNUNET_CRYPTO_rsa_public_key_decode(), GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, len, pk, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_rsa_public_key().

875 {
876  struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
877  const char *enc;
878  char *buf;
879  size_t len;
880  size_t buf_len;
881 
882  if (NULL == (enc = json_string_value (root)))
883  {
884  GNUNET_break_op (0);
885  return GNUNET_SYSERR;
886  }
887  len = strlen (enc);
888  buf_len = (len * 5) / 8;
889  buf = GNUNET_malloc (buf_len);
890  if (GNUNET_OK !=
892  len,
893  buf,
894  buf_len))
895  {
896  GNUNET_break_op (0);
897  GNUNET_free (buf);
898  return GNUNET_SYSERR;
899  }
900  if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode (buf,
901  buf_len)))
902  {
903  GNUNET_break_op (0);
904  GNUNET_free (buf);
905  return GNUNET_SYSERR;
906  }
907  GNUNET_free (buf);
908  return GNUNET_OK;
909 }
The public information of an RSA key pair.
Definition: crypto_rsa.c:51
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
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:443
static char buf[2048]
void * ptr
Pointer, details specific to the parser.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
static OpusEncoder * enc
OPUS encoder.
#define GNUNET_malloc(size)
Wrapper around malloc.
int 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:972
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 919 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_rsa_public_key().

921 {
922  struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
923 
924  if (NULL != *pk)
925  {
927  *pk = NULL;
928  }
929 }
The public information of an RSA key pair.
Definition: crypto_rsa.c:51
void * ptr
Pointer, details specific to the parser.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
Definition: crypto_rsa.c:305
Here is the call graph for this function:
Here is the caller 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 939 of file json_helper.c.

References clean_rsa_public_key(), name, parse_rsa_public_key(), GNUNET_JSON_Specification::parser, pk, and ret.

941 {
942  struct GNUNET_JSON_Specification ret = {
943  .parser = &parse_rsa_public_key,
944  .cleaner = &clean_rsa_public_key,
945  .cls = NULL,
946  .field = name,
947  .ptr = pk,
948  .ptr_size = 0,
949  .size_ptr = NULL
950  };
951 
952  *pk = NULL;
953  return ret;
954 }
static int 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:872
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
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:919
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
const char * name
Here is the call graph for this function:

◆ parse_rsa_signature()

static int 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 966 of file json_helper.c.

References buf, GNUNET_break_op, GNUNET_CRYPTO_rsa_signature_decode(), GNUNET_free, GNUNET_malloc, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, GNUNET_JSON_Specification::ptr, res, and size.

Referenced by GNUNET_JSON_spec_rsa_signature().

969 {
970  struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
971  size_t size;
972  const char *str;
973  int res;
974  void *buf;
975 
976  str = json_string_value (root);
977  if (NULL == str)
978  {
979  GNUNET_break_op (0);
980  return GNUNET_SYSERR;
981  }
982  size = (strlen (str) * 5) / 8;
983  buf = GNUNET_malloc (size);
985  strlen (str),
986  buf,
987  size);
988  if (GNUNET_OK != res)
989  {
990  GNUNET_free (buf);
991  GNUNET_break_op (0);
992  return GNUNET_SYSERR;
993  }
994  if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode (buf,
995  size)))
996  {
997  GNUNET_break_op (0);
998  GNUNET_free (buf);
999  return GNUNET_SYSERR;
1000  }
1001  GNUNET_free (buf);
1002  return GNUNET_OK;
1003 }
an RSA signature
Definition: crypto_rsa.c:63
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:1124
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
static char buf[2048]
static int res
static unsigned int size
Size of the "table".
Definition: peer.c:67
void * ptr
Pointer, details specific to the parser.
#define GNUNET_malloc(size)
Wrapper around malloc.
int 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:972
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 1013 of file json_helper.c.

References GNUNET_CRYPTO_rsa_signature_free(), and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_rsa_signature().

1015 {
1016  struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
1017 
1018  if (NULL != *sig)
1019  {
1021  *sig = NULL;
1022  }
1023 }
an RSA signature
Definition: crypto_rsa.c:63
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.
Definition: crypto_rsa.c:1061
void * ptr
Pointer, details specific to the parser.
Here is the call graph for this function:
Here is the caller 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 1033 of file json_helper.c.

References clean_rsa_signature(), name, parse_rsa_signature(), GNUNET_JSON_Specification::parser, and ret.

1035 {
1036  struct GNUNET_JSON_Specification ret = {
1037  .parser = &parse_rsa_signature,
1038  .cleaner = &clean_rsa_signature,
1039  .cls = NULL,
1040  .field = name,
1041  .ptr = sig,
1042  .ptr_size = 0,
1043  .size_ptr = NULL
1044  };
1045 
1046  *sig = NULL;
1047  return ret;
1048 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_rsa_signature(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to RSA signature.
Definition: json_helper.c:966
static void clean_rsa_signature(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA signature.
Definition: json_helper.c:1013
const char * name
Here is the call graph for this function:

◆ parse_boolean()

static int 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 1060 of file json_helper.c.

References GNUNET_break_op, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_boolean().

1063 {
1064  int *bp = spec->ptr;
1065 
1066  if (! json_is_boolean (root))
1067  {
1068  GNUNET_break_op (0);
1069  return GNUNET_SYSERR;
1070  }
1071  *bp = json_boolean_value (root) ? GNUNET_YES : GNUNET_NO;
1072  return GNUNET_OK;
1073 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Here is the caller graph for this function:

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

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 1083 of file json_helper.c.

References name, parse_boolean(), GNUNET_JSON_Specification::parser, ret, and GNUNET_JSON_Specification::size_ptr.

1085 {
1086  struct GNUNET_JSON_Specification ret = {
1087  .parser = &parse_boolean,
1088  .cleaner = NULL,
1089  .cls = NULL,
1090  .field = name,
1091  .ptr = boolean,
1092  .ptr_size = sizeof(int),
1093  .size_ptr = NULL
1094  };
1095 
1096  return ret;
1097 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int 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:1060
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
Here is the call graph for this function: