GNUnet  0.10.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_attribute_cont(), consume_ticket_cont(), namestore_add(), revoke_ticket_cont(), and verify_cred_cont().

36 {
38  .parser = NULL,
39  .cleaner = NULL,
40  .cls = NULL
41  };
42  return ret;
43 }
Entry in parser specification for GNUNET_JSON_parse().
static int ret
Final status code.
Definition: gnunet-arm.c:89
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 55 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().

58 {
59  const char *enc;
60  unsigned int len;
61 
62  if (NULL == (enc = json_string_value (root)))
63  {
64  GNUNET_break_op (0);
65  return GNUNET_SYSERR;
66  }
67  len = strlen (enc);
68  if (((len * 5) / 8) != spec->ptr_size)
69  {
70  GNUNET_break_op (0);
71  return GNUNET_SYSERR;
72  }
73  if (GNUNET_OK !=
75  len,
76  spec->ptr,
77  spec->ptr_size))
78  {
79  GNUNET_break_op (0);
80  return GNUNET_SYSERR;
81  }
82  return GNUNET_OK;
83 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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:1021
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 95 of file json_helper.c.

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

98 {
100  .parser = &parse_fixed_data,
101  .cleaner = NULL,
102  .cls = NULL,
103  .field = name,
104  .ptr = obj,
105  .ptr_size = size,
106  .size_ptr = NULL
107  };
108  return ret;
109 }
Entry in parser specification for GNUNET_JSON_parse().
static int ret
Final status code.
Definition: gnunet-arm.c:89
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:55
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 121 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().

124 {
125  const char *str;
126  size_t size;
127  void *data;
128  int res;
129 
130  str = json_string_value (root);
131  if (NULL == str)
132  {
133  GNUNET_break_op (0);
134  return GNUNET_SYSERR;
135  }
136  size = (strlen (str) * 5) / 8;
137  if (size >= 1024)
138  {
139  GNUNET_break_op (0);
140  return GNUNET_SYSERR;
141  }
142  data = GNUNET_malloc (size);
144  strlen (str),
145  data,
146  size);
147  if (GNUNET_OK != res)
148  {
149  GNUNET_break_op (0);
150  GNUNET_free (data);
151  return GNUNET_SYSERR;
152  }
153  *(void**) spec->ptr = data;
154  *spec->size_ptr = size;
155  return GNUNET_OK;
156 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#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:79
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:1021
#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 166 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_varsize().

168 {
169  if (0 != *spec->size_ptr)
170  {
171  GNUNET_free (*(void **) spec->ptr);
172  *(void**) spec->ptr = NULL;
173  *spec->size_ptr = 0;
174  }
175 }
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 187 of file json_helper.c.

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

190 {
191  struct GNUNET_JSON_Specification ret = {
192  .parser = &parse_variable_data,
193  .cleaner = &clean_variable_data,
194  .cls = NULL,
195  .field = name,
196  .ptr = obj,
197  .ptr_size = 0,
198  .size_ptr = size
199  };
200  *obj = NULL;
201  *size = 0;
202  return ret;
203 }
static void clean_variable_data(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing variable size data.
Definition: json_helper.c:166
Entry in parser specification for GNUNET_JSON_parse().
static int ret
Final status code.
Definition: gnunet-arm.c:89
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:121
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 215 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_string().

218 {
219  const char *str;
220 
221  str = json_string_value (root);
222  if (NULL == str)
223  {
224  GNUNET_break_op (0);
225  return GNUNET_SYSERR;
226  }
227  *(const char **) spec->ptr = str;
228  return GNUNET_OK;
229 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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 239 of file json_helper.c.

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

241 {
242  struct GNUNET_JSON_Specification ret = {
243  .parser = &parse_string,
244  .cleaner = NULL,
245  .cls = NULL,
246  .field = name,
247  .ptr = strptr,
248  .ptr_size = 0,
249  .size_ptr = NULL
250  };
251  *strptr = NULL;
252  return ret;
253 }
Entry in parser specification for GNUNET_JSON_parse().
static int ret
Final status code.
Definition: gnunet-arm.c:89
const char * name
static int parse_string(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to string.
Definition: json_helper.c:215
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 265 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_json().

268 {
269  if (! (json_is_object (root) || json_is_array (root)) )
270  {
271  GNUNET_break_op (0);
272  return GNUNET_SYSERR;
273  }
274  json_incref (root);
275  *(json_t **) spec->ptr = root;
276  return GNUNET_OK;
277 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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 287 of file json_helper.c.

References GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_json().

289 {
290  json_t **ptr = (json_t **) spec->ptr;
291 
292  if (NULL != *ptr)
293  {
294  json_decref (*ptr);
295  *ptr = NULL;
296  }
297 }
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 307 of file json_helper.c.

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

309 {
310  struct GNUNET_JSON_Specification ret = {
311  .parser = &parse_object,
312  .cleaner = &clean_object,
313  .cls = NULL,
314  .field = name,
315  .ptr = jsonp,
316  .ptr_size = 0,
317  .size_ptr = NULL
318  };
319  *jsonp = NULL;
320  return ret;
321 }
Entry in parser specification for GNUNET_JSON_parse().
static int ret
Final status code.
Definition: gnunet-arm.c:89
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:265
static void clean_object(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing JSON object.
Definition: json_helper.c:287
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 333 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_uint8().

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

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

365 {
366  struct GNUNET_JSON_Specification ret = {
367  .parser = &parse_u8,
368  .cleaner = NULL,
369  .cls = NULL,
370  .field = name,
371  .ptr = u8,
372  .ptr_size = sizeof (uint8_t),
373  .size_ptr = NULL
374  };
375  return ret;
376 }
Entry in parser specification for GNUNET_JSON_parse().
static int ret
Final status code.
Definition: gnunet-arm.c:89
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:333
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 388 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_uint16().

391 {
392  json_int_t val;
393  uint16_t *up = spec->ptr;
394 
395  if (! json_is_integer (root))
396  {
397  GNUNET_break_op (0);
398  return GNUNET_SYSERR;
399  }
400  val = json_integer_value (root);
401  if ( (0 > val) || (val > UINT16_MAX) )
402  {
403  GNUNET_break_op (0);
404  return GNUNET_SYSERR;
405  }
406  *up = (uint16_t) val;
407  return GNUNET_OK;
408 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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 418 of file json_helper.c.

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

420 {
421  struct GNUNET_JSON_Specification ret = {
422  .parser = &parse_u16,
423  .cleaner = NULL,
424  .cls = NULL,
425  .field = name,
426  .ptr = u16,
427  .ptr_size = sizeof (uint16_t),
428  .size_ptr = NULL
429  };
430  return ret;
431 }
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:388
Entry in parser specification for GNUNET_JSON_parse().
static int ret
Final status code.
Definition: gnunet-arm.c:89
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 443 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_uint32().

446 {
447  json_int_t val;
448  uint32_t *up = spec->ptr;
449 
450  if (! json_is_integer (root))
451  {
452  GNUNET_break_op (0);
453  return GNUNET_SYSERR;
454  }
455  val = json_integer_value (root);
456  if ( (0 > val) || (val > UINT32_MAX) )
457  {
458  GNUNET_break_op (0);
459  return GNUNET_SYSERR;
460  }
461  *up = (uint32_t) val;
462  return GNUNET_OK;
463 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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 473 of file json_helper.c.

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

475 {
476  struct GNUNET_JSON_Specification ret = {
477  .parser = &parse_u32,
478  .cleaner = NULL,
479  .cls = NULL,
480  .field = name,
481  .ptr = u32,
482  .ptr_size = sizeof (uint32_t),
483  .size_ptr = NULL
484  };
485  return ret;
486 }
Entry in parser specification for GNUNET_JSON_parse().
static int ret
Final status code.
Definition: gnunet-arm.c:89
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:443
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 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 498 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_uint64().

501 {
502  json_int_t val;
503  uint64_t *up = spec->ptr;
504 
505  if (! json_is_integer (root))
506  {
507  GNUNET_break_op (0);
508  return GNUNET_SYSERR;
509  }
510  val = json_integer_value (root);
511  *up = (uint64_t) val;
512  return GNUNET_OK;
513 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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 523 of file json_helper.c.

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

525 {
526  struct GNUNET_JSON_Specification ret = {
527  .parser = &parse_u64,
528  .cleaner = NULL,
529  .cls = NULL,
530  .field = name,
531  .ptr = u64,
532  .ptr_size = sizeof (uint64_t),
533  .size_ptr = NULL
534  };
535  return ret;
536 }
Entry in parser specification for GNUNET_JSON_parse().
static int ret
Final status code.
Definition: gnunet-arm.c:89
const char * name
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:498
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 550 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().

553 {
554  struct GNUNET_TIME_Absolute *abs = spec->ptr;
555  const char *val;
556  unsigned long long int tval;
557 
558  val = json_string_value (root);
559  if (NULL == val)
560  {
561  GNUNET_break_op (0);
562  return GNUNET_SYSERR;
563  }
564  if ( (0 == strcasecmp (val,
565  "/forever/")) ||
566  (0 == strcasecmp (val,
567  "/end of time/")) ||
568  (0 == strcasecmp (val,
569  "/never/")) )
570  {
572  return GNUNET_OK;
573  }
574  if (1 != sscanf (val,
575  "/Date(%llu)/",
576  &tval))
577  {
578  GNUNET_break_op (0);
579  return GNUNET_SYSERR;
580  }
581  /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
582  abs->abs_value_us = tval * 1000LL * 1000LL;
583  if ( (abs->abs_value_us) / 1000LL / 1000LL != tval)
584  {
585  /* Integer overflow */
586  GNUNET_break_op (0);
587  return GNUNET_SYSERR;
588  }
589  return GNUNET_OK;
590 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
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:79
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 600 of file json_helper.c.

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

602 {
603  struct GNUNET_JSON_Specification ret = {
604  .parser = &parse_abs_time,
605  .cleaner = NULL,
606  .cls = NULL,
607  .field = name,
608  .ptr = at,
609  .ptr_size = sizeof (uint64_t),
610  .size_ptr = NULL
611  };
612  return ret;
613 }
Entry in parser specification for GNUNET_JSON_parse().
static int ret
Final status code.
Definition: gnunet-arm.c:89
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:550
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 625 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_absolute_time_nbo().

628 {
629  struct GNUNET_TIME_AbsoluteNBO *abs = spec->ptr;
630  const char *val;
631  unsigned long long int tval;
632  struct GNUNET_TIME_Absolute a;
633 
634  val = json_string_value (root);
635  if (NULL == val)
636  {
637  GNUNET_break_op (0);
638  return GNUNET_SYSERR;
639  }
640  if ( (0 == strcasecmp (val,
641  "/forever/")) ||
642  (0 == strcasecmp (val,
643  "/end of time/")) ||
644  (0 == strcasecmp (val,
645  "/never/")) )
646  {
648  return GNUNET_OK;
649  }
650  if (1 != sscanf (val,
651  "/Date(%llu)/",
652  &tval))
653  {
654  GNUNET_break_op (0);
655  return GNUNET_SYSERR;
656  }
657  /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
658  a.abs_value_us = tval * 1000LL * 1000LL;
659  if ( (a.abs_value_us) / 1000LL / 1000LL != tval)
660  {
661  /* Integer overflow */
662  GNUNET_break_op (0);
663  return GNUNET_SYSERR;
664  }
665  *abs = GNUNET_TIME_absolute_hton (a);
666  return GNUNET_OK;
667 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
#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:79
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:654
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 677 of file json_helper.c.

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

679 {
680  struct GNUNET_JSON_Specification ret = {
681  .parser = &parse_abs_time_nbo,
682  .cleaner = NULL,
683  .cls = NULL,
684  .field = name,
685  .ptr = at,
686  .ptr_size = sizeof (uint64_t),
687  .size_ptr = NULL
688  };
689  return ret;
690 }
Entry in parser specification for GNUNET_JSON_parse().
static int ret
Final status code.
Definition: gnunet-arm.c:89
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:625
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 702 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().

705 {
706  struct GNUNET_TIME_Relative *rel = spec->ptr;
707  const char *val;
708  unsigned long long int tval;
709 
710  val = json_string_value (root);
711  if (NULL == val)
712  {
713  GNUNET_break_op (0);
714  return GNUNET_SYSERR;
715  }
716  if ( (0 == strcasecmp (val,
717  "/forever/")) )
718  {
720  return GNUNET_OK;
721  }
722  if (1 != sscanf (val,
723  "/Delay(%llu)/",
724  &tval))
725  {
726  GNUNET_break_op (0);
727  return GNUNET_SYSERR;
728  }
729  /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Relative */
730  rel->rel_value_us = tval * 1000LL * 1000LL;
731  if ( (rel->rel_value_us) / 1000LL / 1000LL != tval)
732  {
733  /* Integer overflow */
734  GNUNET_break_op (0);
735  return GNUNET_SYSERR;
736  }
737  return GNUNET_OK;
738 }
uint64_t rel_value_us
The actual value.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#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:79
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 748 of file json_helper.c.

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

750 {
751  struct GNUNET_JSON_Specification ret = {
752  .parser = &parse_rel_time,
753  .cleaner = NULL,
754  .cls = NULL,
755  .field = name,
756  .ptr = rt,
757  .ptr_size = sizeof (uint64_t),
758  .size_ptr = NULL
759  };
760  return ret;
761 }
Entry in parser specification for GNUNET_JSON_parse().
static int ret
Final status code.
Definition: gnunet-arm.c:89
const char * name
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:702
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 773 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().

776 {
777  struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
778  const char *enc;
779  char *buf;
780  size_t len;
781  size_t buf_len;
782 
783  if (NULL == (enc = json_string_value (root)))
784  {
785  GNUNET_break_op (0);
786  return GNUNET_SYSERR;
787  }
788  len = strlen (enc);
789  buf_len = (len * 5) / 8;
790  buf = GNUNET_malloc (buf_len);
791  if (GNUNET_OK !=
793  len,
794  buf,
795  buf_len))
796  {
797  GNUNET_break_op (0);
798  GNUNET_free (buf);
799  return GNUNET_SYSERR;
800  }
801  if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode (buf,
802  buf_len)))
803  {
804  GNUNET_break_op (0);
805  GNUNET_free (buf);
806  return GNUNET_SYSERR;
807  }
808  GNUNET_free (buf);
809  return GNUNET_OK;
810 }
static struct GNUNET_CRYPTO_EddsaPrivateKey * pk
Private key of this peer.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
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:370
static char buf[2048]
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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:1021
#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 820 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().

822 {
823  struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
824 
825  if (NULL != *pk)
826  {
828  *pk = NULL;
829  }
830 }
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:302
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 840 of file json_helper.c.

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

842 {
843  struct GNUNET_JSON_Specification ret = {
844  .parser = &parse_rsa_public_key,
845  .cleaner = &clean_rsa_public_key,
846  .cls = NULL,
847  .field = name,
848  .ptr = pk,
849  .ptr_size = 0,
850  .size_ptr = NULL
851  };
852  *pk = NULL;
853  return ret;
854 }
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:773
Entry in parser specification for GNUNET_JSON_parse().
static int ret
Final status code.
Definition: gnunet-arm.c:89
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:820
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 866 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().

869 {
870  struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
871  size_t size;
872  const char *str;
873  int res;
874  void *buf;
875 
876  str = json_string_value (root);
877  if (NULL == str)
878  {
879  GNUNET_break_op (0);
880  return GNUNET_SYSERR;
881  }
882  size = (strlen (str) * 5) / 8;
883  buf = GNUNET_malloc (size);
885  strlen (str),
886  buf,
887  size);
888  if (GNUNET_OK != res)
889  {
890  GNUNET_free (buf);
891  GNUNET_break_op (0);
892  return GNUNET_SYSERR;
893  }
894  if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode (buf,
895  size)))
896  {
897  GNUNET_break_op (0);
898  GNUNET_free (buf);
899  return GNUNET_SYSERR;
900  }
901  GNUNET_free (buf);
902  return GNUNET_OK;
903 }
an RSA signature
Definition: crypto_rsa.c:63
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#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:79
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:996
#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:1021
#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 913 of file json_helper.c.

References GNUNET_CRYPTO_rsa_signature_free(), and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_rsa_signature().

915 {
916  struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
917 
918  if (NULL != *sig)
919  {
921  *sig = NULL;
922  }
923 }
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:951
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 933 of file json_helper.c.

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

935 {
936  struct GNUNET_JSON_Specification ret = {
937  .parser = &parse_rsa_signature,
938  .cleaner = &clean_rsa_signature,
939  .cls = NULL,
940  .field = name,
941  .ptr = sig,
942  .ptr_size = 0,
943  .size_ptr = NULL
944  };
945  *sig = NULL;
946  return ret;
947 }
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:866
static void clean_rsa_signature(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA signature.
Definition: json_helper.c:913
static int ret
Final status code.
Definition: gnunet-arm.c:89
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 959 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().

962 {
963  int *bp = spec->ptr;
964 
965  if (! json_is_boolean (root))
966  {
967  GNUNET_break_op (0);
968  return GNUNET_SYSERR;
969  }
970  *bp = json_boolean_value (root) ? GNUNET_YES : GNUNET_NO;
971  return GNUNET_OK;
972 }
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
void * ptr
Pointer, details specific to the parser.
#define GNUNET_YES
Definition: gnunet_common.h:80
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).

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

Definition at line 982 of file json_helper.c.

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

984 {
985  struct GNUNET_JSON_Specification ret = {
986  .parser = &parse_boolean,
987  .cleaner = NULL,
988  .cls = NULL,
989  .field = name,
990  .ptr = boolean,
991  .ptr_size = sizeof (int),
992  .size_ptr = NULL
993  };
994  return ret;
995 }
Entry in parser specification for GNUNET_JSON_parse().
static int ret
Final status code.
Definition: gnunet-arm.c:89
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:959
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
Here is the call graph for this function: