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_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 uint8_t. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint64 (const char *name, uint64_t *u64)
 64-bit 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_attestation_cont(), add_attestation_ref_cont(), add_attribute_cont(), consume_ticket_cont(), delete_attestation_ref_cont(), namestore_add(), 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_OK
Named constants for return values.
Definition: gnunet_common.h:83
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
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:952
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_OK
Named constants for return values.
Definition: gnunet_common.h:83
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
static int res
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
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:952
#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_OK
Named constants for return values.
Definition: gnunet_common.h:83
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
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_OK
Named constants for return values.
Definition: gnunet_common.h:83
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
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_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 338 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_uint8().

341 {
342  json_int_t val;
343  uint8_t *up = spec->ptr;
344 
345  if (! json_is_integer (root))
346  {
347  GNUNET_break_op (0);
348  return GNUNET_SYSERR;
349  }
350  val = json_integer_value (root);
351  if ((0 > val) || (val > UINT8_MAX))
352  {
353  GNUNET_break_op (0);
354  return GNUNET_SYSERR;
355  }
356  *up = (uint8_t) val;
357  return GNUNET_OK;
358 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
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 368 of file json_helper.c.

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

370 {
371  struct GNUNET_JSON_Specification ret = {
372  .parser = &parse_u8,
373  .cleaner = NULL,
374  .cls = NULL,
375  .field = name,
376  .ptr = u8,
377  .ptr_size = sizeof(uint8_t),
378  .size_ptr = NULL
379  };
380 
381  return ret;
382 }
uint8_t u8
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:338
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 394 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_uint16().

397 {
398  json_int_t val;
399  uint16_t *up = spec->ptr;
400 
401  if (! json_is_integer (root))
402  {
403  GNUNET_break_op (0);
404  return GNUNET_SYSERR;
405  }
406  val = json_integer_value (root);
407  if ((0 > val) || (val > UINT16_MAX))
408  {
409  GNUNET_break_op (0);
410  return GNUNET_SYSERR;
411  }
412  *up = (uint16_t) val;
413  return GNUNET_OK;
414 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
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 424 of file json_helper.c.

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

426 {
427  struct GNUNET_JSON_Specification ret = {
428  .parser = &parse_u16,
429  .cleaner = NULL,
430  .cls = NULL,
431  .field = name,
432  .ptr = u16,
433  .ptr_size = sizeof(uint16_t),
434  .size_ptr = NULL
435  };
436 
437  return ret;
438 }
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:394
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 450 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_uint32().

453 {
454  json_int_t val;
455  uint32_t *up = spec->ptr;
456 
457  if (! json_is_integer (root))
458  {
459  GNUNET_break_op (0);
460  return GNUNET_SYSERR;
461  }
462  val = json_integer_value (root);
463  if ((0 > val) || (val > UINT32_MAX))
464  {
465  GNUNET_break_op (0);
466  return GNUNET_SYSERR;
467  }
468  *up = (uint32_t) val;
469  return GNUNET_OK;
470 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
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 480 of file json_helper.c.

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

482 {
483  struct GNUNET_JSON_Specification ret = {
484  .parser = &parse_u32,
485  .cleaner = NULL,
486  .cls = NULL,
487  .field = name,
488  .ptr = u32,
489  .ptr_size = sizeof(uint32_t),
490  .size_ptr = NULL
491  };
492 
493  return ret;
494 }
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:450
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
uint32_t u32
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 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 506 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_uint64().

509 {
510  json_int_t val;
511  uint64_t *up = spec->ptr;
512 
513  if (! json_is_integer (root))
514  {
515  GNUNET_break_op (0);
516  return GNUNET_SYSERR;
517  }
518  val = json_integer_value (root);
519  *up = (uint64_t) val;
520  return GNUNET_OK;
521 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
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 531 of file json_helper.c.

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

533 {
534  struct GNUNET_JSON_Specification ret = {
535  .parser = &parse_u64,
536  .cleaner = NULL,
537  .cls = NULL,
538  .field = name,
539  .ptr = u64,
540  .ptr_size = sizeof(uint64_t),
541  .size_ptr = NULL
542  };
543 
544  return ret;
545 }
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 uint8_t.
Definition: json_helper.c:506
const char * name
uint64_t u64
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 559 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().

562 {
563  struct GNUNET_TIME_Absolute *abs = spec->ptr;
564  json_t *json_t_ms;
565  unsigned long long int tval;
566 
567  if (! json_is_object (root))
568  {
569  GNUNET_break_op (0);
570  return GNUNET_SYSERR;
571  }
572  json_t_ms = json_object_get (root, "t_ms");
573  if (json_is_integer (json_t_ms))
574  {
575  tval = json_integer_value (json_t_ms);
576  /* Time is in milliseconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
577  abs->abs_value_us = tval * 1000LL;
578  if ((abs->abs_value_us) / 1000LL != tval)
579  {
580  /* Integer overflow */
581  GNUNET_break_op (0);
582  return GNUNET_SYSERR;
583  }
584  return GNUNET_OK;
585  }
586  if (json_is_string (json_t_ms))
587  {
588  const char *val;
589  val = json_string_value (json_t_ms);
590  if ((0 == strcasecmp (val, "never")))
591  {
593  return GNUNET_OK;
594  }
595  GNUNET_break_op (0);
596  return GNUNET_SYSERR;
597  }
598  GNUNET_break_op (0);
599  return GNUNET_SYSERR;
600 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
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.
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
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 610 of file json_helper.c.

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

612 {
613  struct GNUNET_JSON_Specification ret = {
614  .parser = &parse_abs_time,
615  .cleaner = NULL,
616  .cls = NULL,
617  .field = name,
618  .ptr = at,
619  .ptr_size = sizeof(uint64_t),
620  .size_ptr = NULL
621  };
622 
623  return ret;
624 }
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_abs_time(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to absolute time.
Definition: json_helper.c:559
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 636 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().

639 {
640  struct GNUNET_TIME_AbsoluteNBO *abs = spec->ptr;
641  struct GNUNET_TIME_Absolute a;
642  struct GNUNET_JSON_Specification ispec;
643 
644  ispec = *spec;
645  ispec.parser = &parse_abs_time;
646  ispec.ptr = &a;
647  if (GNUNET_OK !=
648  parse_abs_time (NULL,
649  root,
650  &ispec))
651  return GNUNET_SYSERR;
652  *abs = GNUNET_TIME_absolute_hton (a);
653  return GNUNET_OK;
654 }
Entry in parser specification for GNUNET_JSON_parse().
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
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.
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
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:559
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 664 of file json_helper.c.

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

666 {
667  struct GNUNET_JSON_Specification ret = {
668  .parser = &parse_abs_time_nbo,
669  .cleaner = NULL,
670  .cls = NULL,
671  .field = name,
672  .ptr = at,
673  .ptr_size = sizeof(uint64_t),
674  .size_ptr = NULL
675  };
676 
677  return ret;
678 }
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_abs_time_nbo(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to absolute time.
Definition: json_helper.c:636
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 690 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().

693 {
694  struct GNUNET_TIME_Relative *rel = spec->ptr;
695  json_t *json_d_ms;
696  unsigned long long int tval;
697 
698  if (! json_is_object (root))
699  {
700  GNUNET_break_op (0);
701  return GNUNET_SYSERR;
702  }
703  json_d_ms = json_object_get (root, "d_ms");
704  if (json_is_integer (json_d_ms))
705  {
706  tval = json_integer_value (json_d_ms);
707  /* Time is in milliseconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
708  rel->rel_value_us = tval * 1000LL;
709  if ((rel->rel_value_us) / 1000LL != tval)
710  {
711  /* Integer overflow */
712  GNUNET_break_op (0);
713  return GNUNET_SYSERR;
714  }
715  return GNUNET_OK;
716  }
717  if (json_is_string (json_d_ms))
718  {
719  const char *val;
720  val = json_string_value (json_d_ms);
721  if ((0 == strcasecmp (val, "forever")))
722  {
724  return GNUNET_OK;
725  }
726  GNUNET_break_op (0);
727  return GNUNET_SYSERR;
728  }
729  GNUNET_break_op (0);
730  return GNUNET_SYSERR;
731 }
uint64_t rel_value_us
The actual value.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
#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".
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
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 741 of file json_helper.c.

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

743 {
744  struct GNUNET_JSON_Specification ret = {
745  .parser = &parse_rel_time,
746  .cleaner = NULL,
747  .cls = NULL,
748  .field = name,
749  .ptr = rt,
750  .ptr_size = sizeof(uint64_t),
751  .size_ptr = NULL
752  };
753 
754  return ret;
755 }
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:690
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_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 767 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().

770 {
771  struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
772  const char *enc;
773  char *buf;
774  size_t len;
775  size_t buf_len;
776 
777  if (NULL == (enc = json_string_value (root)))
778  {
779  GNUNET_break_op (0);
780  return GNUNET_SYSERR;
781  }
782  len = strlen (enc);
783  buf_len = (len * 5) / 8;
784  buf = GNUNET_malloc (buf_len);
785  if (GNUNET_OK !=
787  len,
788  buf,
789  buf_len))
790  {
791  GNUNET_break_op (0);
792  GNUNET_free (buf);
793  return GNUNET_SYSERR;
794  }
795  if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode (buf,
796  buf_len)))
797  {
798  GNUNET_break_op (0);
799  GNUNET_free (buf);
800  return GNUNET_SYSERR;
801  }
802  GNUNET_free (buf);
803  return GNUNET_OK;
804 }
static struct GNUNET_CRYPTO_EddsaPrivateKey * pk
Private key of this peer.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
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]
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
void * ptr
Pointer, details specific to the parser.
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:952
#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 814 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().

816 {
817  struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
818 
819  if (NULL != *pk)
820  {
822  *pk = NULL;
823  }
824 }
static struct GNUNET_CRYPTO_EddsaPrivateKey * pk
Private key of this peer.
The public information of an RSA key pair.
Definition: crypto_rsa.c:51
void * ptr
Pointer, details specific to the parser.
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 834 of file json_helper.c.

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

836 {
837  struct GNUNET_JSON_Specification ret = {
838  .parser = &parse_rsa_public_key,
839  .cleaner = &clean_rsa_public_key,
840  .cls = NULL,
841  .field = name,
842  .ptr = pk,
843  .ptr_size = 0,
844  .size_ptr = NULL
845  };
846 
847  *pk = NULL;
848  return ret;
849 }
static struct GNUNET_CRYPTO_EddsaPrivateKey * pk
Private key of this peer.
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:767
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:814
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 861 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().

864 {
865  struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
866  size_t size;
867  const char *str;
868  int res;
869  void *buf;
870 
871  str = json_string_value (root);
872  if (NULL == str)
873  {
874  GNUNET_break_op (0);
875  return GNUNET_SYSERR;
876  }
877  size = (strlen (str) * 5) / 8;
878  buf = GNUNET_malloc (size);
880  strlen (str),
881  buf,
882  size);
883  if (GNUNET_OK != res)
884  {
885  GNUNET_free (buf);
886  GNUNET_break_op (0);
887  return GNUNET_SYSERR;
888  }
889  if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode (buf,
890  size)))
891  {
892  GNUNET_break_op (0);
893  GNUNET_free (buf);
894  return GNUNET_SYSERR;
895  }
896  GNUNET_free (buf);
897  return GNUNET_OK;
898 }
an RSA signature
Definition: crypto_rsa.c:63
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
static char buf[2048]
static int res
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
static unsigned int size
Size of the "table".
Definition: peer.c:67
void * ptr
Pointer, details specific to the parser.
struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_signature_decode(const char *buf, size_t len)
Decode the signature from the data-format back to the "normal", internal format.
Definition: crypto_rsa.c:1121
#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:952
#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 908 of file json_helper.c.

References GNUNET_CRYPTO_rsa_signature_free(), and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_rsa_signature().

910 {
911  struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
912 
913  if (NULL != *sig)
914  {
916  *sig = NULL;
917  }
918 }
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:1058
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 928 of file json_helper.c.

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

930 {
931  struct GNUNET_JSON_Specification ret = {
932  .parser = &parse_rsa_signature,
933  .cleaner = &clean_rsa_signature,
934  .cls = NULL,
935  .field = name,
936  .ptr = sig,
937  .ptr_size = 0,
938  .size_ptr = NULL
939  };
940 
941  *sig = NULL;
942  return ret;
943 }
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:861
static void clean_rsa_signature(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA signature.
Definition: json_helper.c:908
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 955 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().

958 {
959  int *bp = spec->ptr;
960 
961  if (! json_is_boolean (root))
962  {
963  GNUNET_break_op (0);
964  return GNUNET_SYSERR;
965  }
966  *bp = json_boolean_value (root) ? GNUNET_YES : GNUNET_NO;
967  return GNUNET_OK;
968 }
#define GNUNET_NO
Definition: gnunet_common.h:86
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:84
void * ptr
Pointer, details specific to the parser.
#define GNUNET_YES
Definition: gnunet_common.h:85
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 978 of file json_helper.c.

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

980 {
981  struct GNUNET_JSON_Specification ret = {
982  .parser = &parse_boolean,
983  .cleaner = NULL,
984  .cls = NULL,
985  .field = name,
986  .ptr = boolean,
987  .ptr_size = sizeof(int),
988  .size_ptr = NULL
989  };
990 
991  return ret;
992 }
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:955
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
Here is the call graph for this function: