GNUnet  0.11.x
Functions
json_helper.c File Reference

functions to generate specifciations for JSON parsing More...

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

Go to the source code of this file.

Functions

struct GNUNET_JSON_Specification GNUNET_JSON_spec_end ()
 End of a parser specification. More...
 
static int parse_fixed_data (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to fixed size data. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_fixed (const char *name, void *obj, size_t size)
 Variable size object (in network byte order, encoded using Crockford Base32hex encoding). More...
 
static int parse_variable_data (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to variable size data. More...
 
static void clean_variable_data (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing variable size data. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_varsize (const char *name, void **obj, size_t *size)
 Variable size object (in network byte order, encoded using Crockford Base32hex encoding). More...
 
static int parse_string (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to string. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_string (const char *name, const char **strptr)
 The expected field stores a string. More...
 
static int parse_object (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a JSON object. More...
 
static void clean_object (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing JSON object. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_json (const char *name, json_t **jsonp)
 JSON object. More...
 
static int parse_bool (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a bool. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_bool (const char *name, bool *b)
 boolean. More...
 
static int parse_u8 (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a uint8_t. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint8 (const char *name, uint8_t *u8)
 8-bit integer. More...
 
static int parse_u16 (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a uint16_t. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint16 (const char *name, uint16_t *u16)
 16-bit integer. More...
 
static int parse_u32 (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a uint32_t. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint32 (const char *name, uint32_t *u32)
 32-bit integer. More...
 
static int parse_u64 (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a uint64_t. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint64 (const char *name, uint64_t *u64)
 64-bit integer. More...
 
static int parse_i64 (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a int64_t. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_int64 (const char *name, int64_t *i64)
 64-bit signed integer. More...
 
static int parse_abs_time (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to absolute time. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_absolute_time (const char *name, struct GNUNET_TIME_Absolute *at)
 Absolute time. More...
 
static int parse_abs_time_nbo (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to absolute time. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_absolute_time_nbo (const char *name, struct GNUNET_TIME_AbsoluteNBO *at)
 Absolute time in network byte order. More...
 
static int parse_rel_time (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to relative time. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_relative_time (const char *name, struct GNUNET_TIME_Relative *rt)
 Relative time. More...
 
static int parse_rsa_public_key (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to RSA public key. More...
 
static void clean_rsa_public_key (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing RSA public key. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_public_key (const char *name, struct GNUNET_CRYPTO_RsaPublicKey **pk)
 Specification for parsing an RSA public key. More...
 
static int parse_rsa_signature (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to RSA signature. More...
 
static void clean_rsa_signature (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing RSA signature. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_signature (const char *name, struct GNUNET_CRYPTO_RsaSignature **sig)
 Specification for parsing an RSA signature. More...
 
static int parse_boolean (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to an int as a boolean. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_boolean (const char *name, int *boolean)
 Boolean (true mapped to GNUNET_YES, false mapped to GNUNET_NO). More...
 

Detailed Description

functions to generate specifciations for JSON parsing

Author
Florian Dold
Benedikt Mueller
Christian Grothoff

Definition in file json_helper.c.

Function Documentation

◆ GNUNET_JSON_spec_end()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_end ( void  )

End of a parser specification.

Definition at line 32 of file json_helper.c.

References GNUNET_JSON_Specification::parser, and ret.

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

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

56 {
57  const char *enc;
58  unsigned int len;
59 
60  if (NULL == (enc = json_string_value (root)))
61  {
62  GNUNET_break_op (0);
63  return GNUNET_SYSERR;
64  }
65  len = strlen (enc);
66  if (((len * 5) / 8) != spec->ptr_size)
67  {
68  GNUNET_break_op (0);
69  return GNUNET_SYSERR;
70  }
71  if (GNUNET_OK !=
73  len,
74  spec->ptr,
75  spec->ptr_size))
76  {
77  GNUNET_break_op (0);
78  return GNUNET_SYSERR;
79  }
80  return GNUNET_OK;
81 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
static OpusEncoder * enc
OPUS encoder.
size_t ptr_size
Number of bytes available in ptr.
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:972
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_fixed()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_fixed ( const char *  name,
void *  obj,
size_t  size 
)

Variable size object (in network byte order, encoded using Crockford Base32hex encoding).

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

Definition at line 85 of file json_helper.c.

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

88 {
90  .parser = &parse_fixed_data,
91  .cleaner = NULL,
92  .cls = NULL,
93  .field = name,
94  .ptr = obj,
95  .ptr_size = size,
96  .size_ptr = NULL
97  };
98 
99  return ret;
100 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static unsigned int size
Size of the "table".
Definition: peer.c:67
const char * name
static int parse_fixed_data(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to fixed size data.
Definition: json_helper.c:53
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 112 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().

115 {
116  const char *str;
117  size_t size;
118  void *data;
119  int res;
120 
121  str = json_string_value (root);
122  if (NULL == str)
123  {
124  GNUNET_break_op (0);
125  return GNUNET_SYSERR;
126  }
127  size = (strlen (str) * 5) / 8;
128  if (size >= 1024)
129  {
130  GNUNET_break_op (0);
131  return GNUNET_SYSERR;
132  }
133  data = GNUNET_malloc (size);
135  strlen (str),
136  data,
137  size);
138  if (GNUNET_OK != res)
139  {
140  GNUNET_break_op (0);
141  GNUNET_free (data);
142  return GNUNET_SYSERR;
143  }
144  *(void **) spec->ptr = data;
145  *spec->size_ptr = size;
146  return GNUNET_OK;
147 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
static int res
static unsigned int size
Size of the "table".
Definition: peer.c:67
void * ptr
Pointer, details specific to the parser.
size_t * size_ptr
Where should we store the final size of ptr.
uint32_t data
The data value.
#define GNUNET_malloc(size)
Wrapper around malloc.
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:972
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean_variable_data()

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

Cleanup data left from parsing variable size data.

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

Definition at line 157 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_varsize().

159 {
160  (void) cls;
161  if (0 != *spec->size_ptr)
162  {
163  GNUNET_free (*(void **) spec->ptr);
164  *(void **) spec->ptr = NULL;
165  *spec->size_ptr = 0;
166  }
167 }
void * cls
Closure for parser and cleaner.
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 171 of file json_helper.c.

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

174 {
175  struct GNUNET_JSON_Specification ret = {
176  .parser = &parse_variable_data,
177  .cleaner = &clean_variable_data,
178  .cls = NULL,
179  .field = name,
180  .ptr = obj,
181  .ptr_size = 0,
182  .size_ptr = size
183  };
184 
185  *obj = NULL;
186  *size = 0;
187  return ret;
188 }
static void clean_variable_data(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing variable size data.
Definition: json_helper.c:157
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static unsigned int size
Size of the "table".
Definition: peer.c:67
static int parse_variable_data(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to variable size data.
Definition: json_helper.c:112
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 200 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_string().

203 {
204  const char *str;
205 
206  (void) cls;
207  str = json_string_value (root);
208  if (NULL == str)
209  {
210  GNUNET_break_op (0);
211  return GNUNET_SYSERR;
212  }
213  *(const char **) spec->ptr = str;
214  return GNUNET_OK;
215 }
void * cls
Closure for parser and cleaner.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_string()

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

The expected field stores a string.

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

Definition at line 219 of file json_helper.c.

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

221 {
222  struct GNUNET_JSON_Specification ret = {
223  .parser = &parse_string,
224  .cleaner = NULL,
225  .cls = NULL,
226  .field = name,
227  .ptr = strptr,
228  .ptr_size = 0,
229  .size_ptr = NULL
230  };
231 
232  *strptr = NULL;
233  return ret;
234 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_string(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to string.
Definition: json_helper.c:200
const char * name
Here is the call graph for this function:

◆ parse_object()

static int parse_object ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a JSON object.

(Yes, trivial.)

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

Definition at line 246 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_json().

249 {
250  if (! (json_is_object (root) || json_is_array (root)))
251  {
252  GNUNET_break_op (0);
253  return GNUNET_SYSERR;
254  }
255  json_incref (root);
256  *(json_t **) spec->ptr = root;
257  return GNUNET_OK;
258 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Here is the caller graph for this function:

◆ clean_object()

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

Cleanup data left from parsing JSON object.

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

Definition at line 268 of file json_helper.c.

References GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_json().

270 {
271  json_t **ptr = (json_t **) spec->ptr;
272 
273  if (NULL != *ptr)
274  {
275  json_decref (*ptr);
276  *ptr = NULL;
277  }
278 }
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 282 of file json_helper.c.

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

284 {
285  struct GNUNET_JSON_Specification ret = {
286  .parser = &parse_object,
287  .cleaner = &clean_object,
288  .cls = NULL,
289  .field = name,
290  .ptr = jsonp,
291  .ptr_size = 0,
292  .size_ptr = NULL
293  };
294 
295  *jsonp = NULL;
296  return ret;
297 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_object(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a JSON object.
Definition: json_helper.c:246
static void clean_object(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing JSON object.
Definition: json_helper.c:268
const char * name
Here is the call graph for this function:

◆ parse_bool()

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

Parse given JSON object to a bool.

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

Definition at line 309 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_bool().

312 {
313  bool *b = spec->ptr;
314 
315  if (json_true () == root)
316  {
317  *b = true;
318  return GNUNET_OK;
319  }
320  if (json_false () == root)
321  {
322  *b = false;
323  return GNUNET_OK;
324  }
325  GNUNET_break_op (0);
326  return GNUNET_SYSERR;
327 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_bool()

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

boolean.

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

Definition at line 331 of file json_helper.c.

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

333 {
334  struct GNUNET_JSON_Specification ret = {
335  .parser = &parse_bool,
336  .cleaner = NULL,
337  .cls = NULL,
338  .field = name,
339  .ptr = b,
340  .ptr_size = sizeof(bool),
341  .size_ptr = NULL
342  };
343 
344  return ret;
345 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_bool(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a bool.
Definition: json_helper.c:309
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
Here is the call graph for this function:

◆ parse_u8()

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

Parse given JSON object to a uint8_t.

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

Definition at line 357 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_uint8().

360 {
361  json_int_t val;
362  uint8_t *up = spec->ptr;
363 
364  if (! json_is_integer (root))
365  {
366  GNUNET_break_op (0);
367  return GNUNET_SYSERR;
368  }
369  val = json_integer_value (root);
370  if ((0 > val) || (val > UINT8_MAX))
371  {
372  GNUNET_break_op (0);
373  return GNUNET_SYSERR;
374  }
375  *up = (uint8_t) val;
376  return GNUNET_OK;
377 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_uint8()

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

8-bit integer.

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

Definition at line 381 of file json_helper.c.

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

383 {
384  struct GNUNET_JSON_Specification ret = {
385  .parser = &parse_u8,
386  .cleaner = NULL,
387  .cls = NULL,
388  .field = name,
389  .ptr = u8,
390  .ptr_size = sizeof(uint8_t),
391  .size_ptr = NULL
392  };
393 
394  return ret;
395 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
static int parse_u8(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint8_t.
Definition: json_helper.c:357
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 407 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_uint16().

410 {
411  json_int_t val;
412  uint16_t *up = spec->ptr;
413 
414  if (! json_is_integer (root))
415  {
416  GNUNET_break_op (0);
417  return GNUNET_SYSERR;
418  }
419  val = json_integer_value (root);
420  if ((0 > val) || (val > UINT16_MAX))
421  {
422  GNUNET_break_op (0);
423  return GNUNET_SYSERR;
424  }
425  *up = (uint16_t) val;
426  return GNUNET_OK;
427 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_uint16()

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

16-bit integer.

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

Definition at line 431 of file json_helper.c.

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

433 {
434  struct GNUNET_JSON_Specification ret = {
435  .parser = &parse_u16,
436  .cleaner = NULL,
437  .cls = NULL,
438  .field = name,
439  .ptr = u16,
440  .ptr_size = sizeof(uint16_t),
441  .size_ptr = NULL
442  };
443 
444  return ret;
445 }
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:407
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
Here is the call graph for this function:

◆ parse_u32()

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

Parse given JSON object to a uint32_t.

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

Definition at line 457 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_uint32().

460 {
461  json_int_t val;
462  uint32_t *up = spec->ptr;
463 
464  if (! json_is_integer (root))
465  {
466  GNUNET_break_op (0);
467  return GNUNET_SYSERR;
468  }
469  val = json_integer_value (root);
470  if ((0 > val) || (val > UINT32_MAX))
471  {
472  GNUNET_break_op (0);
473  return GNUNET_SYSERR;
474  }
475  *up = (uint32_t) val;
476  return GNUNET_OK;
477 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_uint32()

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

32-bit integer.

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

Definition at line 481 of file json_helper.c.

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

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

◆ parse_u64()

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

Parse given JSON object to a uint64_t.

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

Definition at line 507 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_uint64().

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

◆ GNUNET_JSON_spec_uint64()

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

64-bit integer.

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

Definition at line 526 of file json_helper.c.

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

528 {
529  struct GNUNET_JSON_Specification ret = {
530  .parser = &parse_u64,
531  .cleaner = NULL,
532  .cls = NULL,
533  .field = name,
534  .ptr = u64,
535  .ptr_size = sizeof(uint64_t),
536  .size_ptr = NULL
537  };
538 
539  return ret;
540 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_u64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint64_t.
Definition: json_helper.c:507
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
Here is the call graph for this function:

◆ parse_i64()

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

Parse given JSON object to a int64_t.

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

Definition at line 552 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_int64().

555 {
556  json_int_t val;
557  int64_t *up = spec->ptr;
558 
559  if (! json_is_integer (root))
560  {
561  GNUNET_break_op (0);
562  return GNUNET_SYSERR;
563  }
564  val = json_integer_value (root);
565  *up = (int64_t) val;
566  return GNUNET_OK;
567 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_int64()

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

64-bit signed integer.

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

Definition at line 571 of file json_helper.c.

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

573 {
574  struct GNUNET_JSON_Specification ret = {
575  .parser = &parse_i64,
576  .cleaner = NULL,
577  .cls = NULL,
578  .field = name,
579  .ptr = i64,
580  .ptr_size = sizeof(int64_t),
581  .size_ptr = NULL
582  };
583 
584  return ret;
585 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_i64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a int64_t.
Definition: json_helper.c:552
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
Here is the call graph for this function:

◆ parse_abs_time()

static int parse_abs_time ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to absolute time.

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

Definition at line 599 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_absolute_time(), and parse_abs_time_nbo().

602 {
603  struct GNUNET_TIME_Absolute *abs = spec->ptr;
604  json_t *json_t_ms;
605  unsigned long long int tval;
606 
607  if (! json_is_object (root))
608  {
609  GNUNET_break_op (0);
610  return GNUNET_SYSERR;
611  }
612  json_t_ms = json_object_get (root, "t_ms");
613  if (json_is_integer (json_t_ms))
614  {
615  tval = json_integer_value (json_t_ms);
616  /* Time is in milliseconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
617  abs->abs_value_us = tval * 1000LL;
618  if ((abs->abs_value_us) / 1000LL != tval)
619  {
620  /* Integer overflow */
621  GNUNET_break_op (0);
622  return GNUNET_SYSERR;
623  }
624  return GNUNET_OK;
625  }
626  if (json_is_string (json_t_ms))
627  {
628  const char *val;
629  val = json_string_value (json_t_ms);
630  if ((0 == strcasecmp (val, "never")))
631  {
633  return GNUNET_OK;
634  }
635  GNUNET_break_op (0);
636  return GNUNET_SYSERR;
637  }
638  GNUNET_break_op (0);
639  return GNUNET_SYSERR;
640 }
uint64_t abs_value_us
The actual value.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Time for absolute times used by GNUnet, in microseconds.
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_absolute_time()

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

Absolute time.

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

Definition at line 644 of file json_helper.c.

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

646 {
647  struct GNUNET_JSON_Specification ret = {
648  .parser = &parse_abs_time,
649  .cleaner = NULL,
650  .cls = NULL,
651  .field = name,
652  .ptr = at,
653  .ptr_size = sizeof(struct GNUNET_TIME_Absolute),
654  .size_ptr = NULL
655  };
656 
657  return ret;
658 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
const char * name
Time for absolute times used by GNUnet, in microseconds.
static int parse_abs_time(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to absolute time.
Definition: json_helper.c:599
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 670 of file json_helper.c.

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

Referenced by GNUNET_JSON_spec_absolute_time_nbo().

673 {
674  struct GNUNET_TIME_AbsoluteNBO *abs = spec->ptr;
675  struct GNUNET_TIME_Absolute a;
676  struct GNUNET_JSON_Specification ispec;
677 
678  ispec = *spec;
679  ispec.parser = &parse_abs_time;
680  ispec.ptr = &a;
681  if (GNUNET_OK !=
682  parse_abs_time (NULL,
683  root,
684  &ispec))
685  return GNUNET_SYSERR;
686  *abs = GNUNET_TIME_absolute_hton (a);
687  return GNUNET_OK;
688 }
Entry in parser specification for GNUNET_JSON_parse().
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
GNUNET_JSON_Parser parser
Function for how to parse this type of entry.
void * ptr
Pointer, details specific to the parser.
Time for absolute times used by GNUnet, in microseconds.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:464
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:599
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 692 of file json_helper.c.

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

694 {
695  struct GNUNET_JSON_Specification ret = {
696  .parser = &parse_abs_time_nbo,
697  .cleaner = NULL,
698  .cls = NULL,
699  .field = name,
700  .ptr = at,
701  .ptr_size = sizeof(struct GNUNET_TIME_AbsoluteNBO),
702  .size_ptr = NULL
703  };
704 
705  return ret;
706 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
const char * name
static int parse_abs_time_nbo(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to absolute time.
Definition: json_helper.c:670
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 718 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().

721 {
722  struct GNUNET_TIME_Relative *rel = spec->ptr;
723  json_t *json_d_ms;
724  unsigned long long int tval;
725 
726  if (! json_is_object (root))
727  {
728  GNUNET_break_op (0);
729  return GNUNET_SYSERR;
730  }
731  json_d_ms = json_object_get (root, "d_ms");
732  if (json_is_integer (json_d_ms))
733  {
734  tval = json_integer_value (json_d_ms);
735  /* Time is in milliseconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
736  rel->rel_value_us = tval * 1000LL;
737  if ((rel->rel_value_us) / 1000LL != tval)
738  {
739  /* Integer overflow */
740  GNUNET_break_op (0);
741  return GNUNET_SYSERR;
742  }
743  return GNUNET_OK;
744  }
745  if (json_is_string (json_d_ms))
746  {
747  const char *val;
748  val = json_string_value (json_d_ms);
749  if ((0 == strcasecmp (val, "forever")))
750  {
752  return GNUNET_OK;
753  }
754  GNUNET_break_op (0);
755  return GNUNET_SYSERR;
756  }
757  GNUNET_break_op (0);
758  return GNUNET_SYSERR;
759 }
uint64_t rel_value_us
The actual value.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
void * ptr
Pointer, details specific to the parser.
Time for relative time used by GNUnet, in microseconds.
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_relative_time()

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

Relative time.

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

Definition at line 763 of file json_helper.c.

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

765 {
766  struct GNUNET_JSON_Specification ret = {
767  .parser = &parse_rel_time,
768  .cleaner = NULL,
769  .cls = NULL,
770  .field = name,
771  .ptr = rt,
772  .ptr_size = sizeof(struct GNUNET_TIME_Relative),
773  .size_ptr = NULL
774  };
775 
776  return ret;
777 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_rel_time(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to relative time.
Definition: json_helper.c:718
const char * name
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:

◆ parse_rsa_public_key()

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

Parse given JSON object to RSA public key.

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

Definition at line 789 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().

792 {
793  struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
794  const char *enc;
795  char *buf;
796  size_t len;
797  size_t buf_len;
798 
799  if (NULL == (enc = json_string_value (root)))
800  {
801  GNUNET_break_op (0);
802  return GNUNET_SYSERR;
803  }
804  len = strlen (enc);
805  buf_len = (len * 5) / 8;
806  buf = GNUNET_malloc (buf_len);
807  if (GNUNET_OK !=
809  len,
810  buf,
811  buf_len))
812  {
813  GNUNET_break_op (0);
814  GNUNET_free (buf);
815  return GNUNET_SYSERR;
816  }
817  if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode (buf,
818  buf_len)))
819  {
820  GNUNET_break_op (0);
821  GNUNET_free (buf);
822  return GNUNET_SYSERR;
823  }
824  GNUNET_free (buf);
825  return GNUNET_OK;
826 }
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:383
static char buf[2048]
void * ptr
Pointer, details specific to the parser.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
static OpusEncoder * enc
OPUS encoder.
#define GNUNET_malloc(size)
Wrapper around malloc.
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:972
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean_rsa_public_key()

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

Cleanup data left from parsing RSA public key.

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

Definition at line 836 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().

838 {
839  struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
840 
841  if (NULL != *pk)
842  {
844  *pk = NULL;
845  }
846 }
The public information of an RSA key pair.
Definition: crypto_rsa.c:51
void * ptr
Pointer, details specific to the parser.
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
Definition: crypto_rsa.c:267
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 850 of file json_helper.c.

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

852 {
853  struct GNUNET_JSON_Specification ret = {
854  .parser = &parse_rsa_public_key,
855  .cleaner = &clean_rsa_public_key,
856  .cls = NULL,
857  .field = name,
858  .ptr = pk,
859  .ptr_size = 0,
860  .size_ptr = NULL
861  };
862 
863  *pk = NULL;
864  return ret;
865 }
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:789
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static void clean_rsa_public_key(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA public key.
Definition: json_helper.c:836
struct GNUNET_IDENTITY_PrivateKey pk
Private key from command line option, or NULL.
const char * name
Here is the call graph for this function:

◆ parse_rsa_signature()

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

Parse given JSON object to RSA signature.

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

Definition at line 877 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().

880 {
881  struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
882  size_t size;
883  const char *str;
884  int res;
885  void *buf;
886 
887  str = json_string_value (root);
888  if (NULL == str)
889  {
890  GNUNET_break_op (0);
891  return GNUNET_SYSERR;
892  }
893  size = (strlen (str) * 5) / 8;
894  buf = GNUNET_malloc (size);
896  strlen (str),
897  buf,
898  size);
899  if (GNUNET_OK != res)
900  {
901  GNUNET_free (buf);
902  GNUNET_break_op (0);
903  return GNUNET_SYSERR;
904  }
905  if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode (buf,
906  size)))
907  {
908  GNUNET_break_op (0);
909  GNUNET_free (buf);
910  return GNUNET_SYSERR;
911  }
912  GNUNET_free (buf);
913  return GNUNET_OK;
914 }
an RSA signature
Definition: crypto_rsa.c:63
struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_signature_decode(const void *buf, size_t buf_size)
Decode the signature from the data-format back to the "normal", internal format.
Definition: crypto_rsa.c:993
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
static char buf[2048]
static int res
static unsigned int size
Size of the "table".
Definition: peer.c:67
void * ptr
Pointer, details specific to the parser.
#define GNUNET_malloc(size)
Wrapper around malloc.
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:972
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean_rsa_signature()

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

Cleanup data left from parsing RSA signature.

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

Definition at line 924 of file json_helper.c.

References GNUNET_CRYPTO_rsa_signature_free(), and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_rsa_signature().

926 {
927  struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
928 
929  if (NULL != *sig)
930  {
932  *sig = NULL;
933  }
934 }
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:945
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 938 of file json_helper.c.

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

940 {
941  struct GNUNET_JSON_Specification ret = {
942  .parser = &parse_rsa_signature,
943  .cleaner = &clean_rsa_signature,
944  .cls = NULL,
945  .field = name,
946  .ptr = sig,
947  .ptr_size = 0,
948  .size_ptr = NULL
949  };
950 
951  *sig = NULL;
952  return ret;
953 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_rsa_signature(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to RSA signature.
Definition: json_helper.c:877
static void clean_rsa_signature(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA signature.
Definition: json_helper.c:924
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 965 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().

968 {
969  int *bp = spec->ptr;
970 
971  if (! json_is_boolean (root))
972  {
973  GNUNET_break_op (0);
974  return GNUNET_SYSERR;
975  }
976  *bp = json_boolean_value (root) ? GNUNET_YES : GNUNET_NO;
977  return GNUNET_OK;
978 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
void * ptr
Pointer, details specific to the parser.
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_boolean()

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

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

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 consensus-simulation::int, 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 
995  return ret;
996 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_boolean(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to an int as a boolean.
Definition: json_helper.c:965
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
Here is the call graph for this function: