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 
43  return ret;
44 }
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 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:75
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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:953
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 }
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:66
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:75
#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:76
static unsigned int size
Size of the "table".
Definition: peer.c:66
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:953
#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
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:66
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:75
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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 }
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:218
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:75
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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 }
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: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:75
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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 }
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: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:75
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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
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 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:75
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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 }
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:450
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 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:75
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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 }
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:506
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().

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

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

611 {
612  struct GNUNET_JSON_Specification ret = {
613  .parser = &parse_abs_time,
614  .cleaner = NULL,
615  .cls = NULL,
616  .field = name,
617  .ptr = at,
618  .ptr_size = sizeof(uint64_t),
619  .size_ptr = NULL
620  };
621 
622  return ret;
623 }
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: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 635 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().

638 {
639  struct GNUNET_TIME_AbsoluteNBO *abs = spec->ptr;
640  const char *val;
641  unsigned long long int tval;
642  struct GNUNET_TIME_Absolute a;
643 
644  val = json_string_value(root);
645  if (NULL == val)
646  {
647  GNUNET_break_op(0);
648  return GNUNET_SYSERR;
649  }
650  if ((0 == strcasecmp(val,
651  "/forever/")) ||
652  (0 == strcasecmp(val,
653  "/end of time/")) ||
654  (0 == strcasecmp(val,
655  "/never/")))
656  {
658  return GNUNET_OK;
659  }
660  if (1 != sscanf(val,
661  "/Date(%llu)/",
662  &tval))
663  {
664  GNUNET_break_op(0);
665  return GNUNET_SYSERR;
666  }
667  /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
668  a.abs_value_us = tval * 1000LL * 1000LL;
669  if ((a.abs_value_us) / 1000LL / 1000LL != tval)
670  {
671  /* Integer overflow */
672  GNUNET_break_op(0);
673  return GNUNET_SYSERR;
674  }
675  *abs = GNUNET_TIME_absolute_hton(a);
676  return GNUNET_OK;
677 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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:76
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:655
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 687 of file json_helper.c.

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

689 {
690  struct GNUNET_JSON_Specification ret = {
691  .parser = &parse_abs_time_nbo,
692  .cleaner = NULL,
693  .cls = NULL,
694  .field = name,
695  .ptr = at,
696  .ptr_size = sizeof(uint64_t),
697  .size_ptr = NULL
698  };
699 
700  return ret;
701 }
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:635
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 713 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().

716 {
717  struct GNUNET_TIME_Relative *rel = spec->ptr;
718  const char *val;
719  unsigned long long int tval;
720 
721  val = json_string_value(root);
722  if (NULL == val)
723  {
724  GNUNET_break_op(0);
725  return GNUNET_SYSERR;
726  }
727  if ((0 == strcasecmp(val,
728  "/forever/")))
729  {
731  return GNUNET_OK;
732  }
733  if (1 != sscanf(val,
734  "/Delay(%llu)/",
735  &tval))
736  {
737  GNUNET_break_op(0);
738  return GNUNET_SYSERR;
739  }
740  /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Relative */
741  rel->rel_value_us = tval * 1000LL * 1000LL;
742  if ((rel->rel_value_us) / 1000LL / 1000LL != tval)
743  {
744  /* Integer overflow */
745  GNUNET_break_op(0);
746  return GNUNET_SYSERR;
747  }
748  return GNUNET_OK;
749 }
uint64_t rel_value_us
The actual value.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#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:76
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 759 of file json_helper.c.

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

761 {
762  struct GNUNET_JSON_Specification ret = {
763  .parser = &parse_rel_time,
764  .cleaner = NULL,
765  .cls = NULL,
766  .field = name,
767  .ptr = rt,
768  .ptr_size = sizeof(uint64_t),
769  .size_ptr = NULL
770  };
771 
772  return ret;
773 }
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:713
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 785 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().

788 {
789  struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
790  const char *enc;
791  char *buf;
792  size_t len;
793  size_t buf_len;
794 
795  if (NULL == (enc = json_string_value(root)))
796  {
797  GNUNET_break_op(0);
798  return GNUNET_SYSERR;
799  }
800  len = strlen(enc);
801  buf_len = (len * 5) / 8;
802  buf = GNUNET_malloc(buf_len);
803  if (GNUNET_OK !=
805  len,
806  buf,
807  buf_len))
808  {
809  GNUNET_break_op(0);
810  GNUNET_free(buf);
811  return GNUNET_SYSERR;
812  }
813  if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode(buf,
814  buf_len)))
815  {
816  GNUNET_break_op(0);
817  GNUNET_free(buf);
818  return GNUNET_SYSERR;
819  }
820  GNUNET_free(buf);
821  return GNUNET_OK;
822 }
static struct GNUNET_CRYPTO_EddsaPrivateKey * pk
Private key of this peer.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
The public information of an RSA key pair.
Definition: crypto_rsa.c:50
#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:367
static char buf[2048]
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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:953
#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 832 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().

834 {
835  struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
836 
837  if (NULL != *pk)
838  {
840  *pk = NULL;
841  }
842 }
static struct GNUNET_CRYPTO_EddsaPrivateKey * pk
Private key of this peer.
The public information of an RSA key pair.
Definition: crypto_rsa.c:50
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:299
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 852 of file json_helper.c.

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

854 {
855  struct GNUNET_JSON_Specification ret = {
856  .parser = &parse_rsa_public_key,
857  .cleaner = &clean_rsa_public_key,
858  .cls = NULL,
859  .field = name,
860  .ptr = pk,
861  .ptr_size = 0,
862  .size_ptr = NULL
863  };
864 
865  *pk = NULL;
866  return ret;
867 }
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:785
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:832
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 879 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().

882 {
883  struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
884  size_t size;
885  const char *str;
886  int res;
887  void *buf;
888 
889  str = json_string_value(root);
890  if (NULL == str)
891  {
892  GNUNET_break_op(0);
893  return GNUNET_SYSERR;
894  }
895  size = (strlen(str) * 5) / 8;
896  buf = GNUNET_malloc(size);
898  strlen(str),
899  buf,
900  size);
901  if (GNUNET_OK != res)
902  {
903  GNUNET_free(buf);
904  GNUNET_break_op(0);
905  return GNUNET_SYSERR;
906  }
907  if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode(buf,
908  size)))
909  {
910  GNUNET_break_op(0);
911  GNUNET_free(buf);
912  return GNUNET_SYSERR;
913  }
914  GNUNET_free(buf);
915  return GNUNET_OK;
916 }
an RSA signature
Definition: crypto_rsa.c:61
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#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:76
static unsigned int size
Size of the "table".
Definition: peer.c:66
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:995
#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:953
#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 926 of file json_helper.c.

References GNUNET_CRYPTO_rsa_signature_free(), and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_rsa_signature().

928 {
929  struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
930 
931  if (NULL != *sig)
932  {
934  *sig = NULL;
935  }
936 }
an RSA signature
Definition: crypto_rsa.c:61
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.
Definition: crypto_rsa.c:950
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 946 of file json_helper.c.

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

948 {
949  struct GNUNET_JSON_Specification ret = {
950  .parser = &parse_rsa_signature,
951  .cleaner = &clean_rsa_signature,
952  .cls = NULL,
953  .field = name,
954  .ptr = sig,
955  .ptr_size = 0,
956  .size_ptr = NULL
957  };
958 
959  *sig = NULL;
960  return ret;
961 }
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:879
static void clean_rsa_signature(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA signature.
Definition: json_helper.c:926
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 973 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().

976 {
977  int *bp = spec->ptr;
978 
979  if (!json_is_boolean(root))
980  {
981  GNUNET_break_op(0);
982  return GNUNET_SYSERR;
983  }
984  *bp = json_boolean_value(root) ? GNUNET_YES : GNUNET_NO;
985  return GNUNET_OK;
986 }
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
void * ptr
Pointer, details specific to the parser.
#define GNUNET_YES
Definition: gnunet_common.h:77
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 996 of file json_helper.c.

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

998 {
999  struct GNUNET_JSON_Specification ret = {
1000  .parser = &parse_boolean,
1001  .cleaner = NULL,
1002  .cls = NULL,
1003  .field = name,
1004  .ptr = boolean,
1005  .ptr_size = sizeof(int),
1006  .size_ptr = NULL
1007  };
1008 
1009  return ret;
1010 }
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:973
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
Here is the call graph for this function: