GNUnet 0.21.1
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 enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue parse_fixed64_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_fixed64 (const char *name, void *obj, size_t size)
 Variable size object (in network byte order, encoded using base64 encoding). More...
 
static enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue parse_json (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a JSON object. More...
 
static void clean_json (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 or array. More...
 
static enum GNUNET_GenericReturnValue parse_object_const (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a JSON object. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_object_const (const char *name, const json_t **jsonp)
 JSON object, reference counter not incremented. More...
 
static enum GNUNET_GenericReturnValue parse_array_const (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON to a JSON array. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_array_const (const char *name, const json_t **jsonp)
 JSON array, reference counter not incremented. More...
 
static enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue parse_double (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a double. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_double (const char *name, double *f)
 double. More...
 
static enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue parse_timestamp (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a timestamp. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp (const char *name, struct GNUNET_TIME_Timestamp *t)
 Timestamp. More...
 
static enum GNUNET_GenericReturnValue parse_timestamp_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_timestamp_nbo (const char *name, struct GNUNET_TIME_TimestampNBO *at)
 Timestamp in network byte order. More...
 
static enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue 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 enum GNUNET_GenericReturnValue 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.

33{
35 .parser = NULL,
36 .cleaner = NULL,
37 .cls = NULL
38 };
39
40 return ret;
41}
static int ret
Final status code.
Definition: gnunet-arm.c:94
Entry in parser specification for GNUNET_JSON_parse().

References ret.

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

Here is the caller graph for this function:

◆ parse_fixed_data()

static enum GNUNET_GenericReturnValue 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.

56{
57 const char *enc;
58 size_t len;
59
60 if (NULL == (enc = json_string_value (root)))
61 {
63 return GNUNET_SYSERR;
64 }
65 len = strlen (enc);
66 if (len >= SIZE_MAX / 5)
67 {
69 return GNUNET_SYSERR;
70 }
71 if (((len * 5) / 8) != spec->ptr_size)
72 {
75 "Field `%s' has wrong length\n",
76 spec->field);
77 return GNUNET_SYSERR;
78 }
79 if (GNUNET_OK !=
81 len,
82 spec->ptr,
83 spec->ptr_size))
84 {
86 return GNUNET_SYSERR;
87 }
88 return GNUNET_OK;
89}
static OpusEncoder * enc
OPUS encoder.
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
@ GNUNET_ERROR_TYPE_WARNING
enum GNUNET_GenericReturnValue 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:789
#define SIZE_MAX
Definition: platform.h:208
void * ptr
Pointer, details specific to the parser.
const char * field
Name of the field to parse, use NULL to get the JSON of the main object instead of the JSON of an ind...
size_t ptr_size
Number of bytes available in ptr.

References enc, GNUNET_JSON_Specification::field, GNUNET_break_op, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, GNUNET_JSON_Specification::ptr, GNUNET_JSON_Specification::ptr_size, and SIZE_MAX.

Referenced by GNUNET_JSON_spec_fixed().

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

96{
98 .parser = &parse_fixed_data,
99 .cleaner = NULL,
100 .cls = NULL,
101 .field = name,
102 .ptr = obj,
103 .ptr_size = size,
104 .size_ptr = NULL
105 };
106
107 return ret;
108}
static char * name
Name (label) of the records to list.
static enum GNUNET_GenericReturnValue 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
static unsigned int size
Size of the "table".
Definition: peer.c:68

References name, parse_fixed_data(), ret, and size.

Here is the call graph for this function:

◆ parse_fixed64_data()

static enum GNUNET_GenericReturnValue parse_fixed64_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 120 of file json_helper.c.

123{
124 const char *enc;
125 unsigned int len;
126 void *output;
127 size_t olen;
128
129 if (NULL == (enc = json_string_value (root)))
130 {
131 GNUNET_break_op (0);
132 return GNUNET_SYSERR;
133 }
134 len = strlen (enc);
135 output = NULL;
137 len,
138 &output);
139 if (olen != spec->ptr_size)
140 {
141 GNUNET_break_op (0);
143 "Field `%s' has wrong length\n",
144 spec->field);
145 GNUNET_free (output);
146 return GNUNET_SYSERR;
147 }
148 memcpy (spec->ptr,
149 output,
150 olen);
151 GNUNET_free (output);
152 return GNUNET_OK;
153}
#define GNUNET_free(ptr)
Wrapper around free.
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1724

References enc, GNUNET_JSON_Specification::field, GNUNET_break_op, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_STRINGS_base64_decode(), GNUNET_SYSERR, GNUNET_JSON_Specification::ptr, and GNUNET_JSON_Specification::ptr_size.

Referenced by GNUNET_JSON_spec_fixed64().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_fixed64()

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

Variable size object (in network byte order, encoded using base64 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 157 of file json_helper.c.

160{
162 .parser = &parse_fixed64_data,
163 .cleaner = NULL,
164 .cls = NULL,
165 .field = name,
166 .ptr = obj,
167 .ptr_size = size,
168 .size_ptr = NULL
169 };
170
171 return ret;
172}
static enum GNUNET_GenericReturnValue parse_fixed64_data(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to fixed size data.
Definition: json_helper.c:120

References name, parse_fixed64_data(), ret, and size.

Here is the call graph for this function:

◆ parse_variable_data()

static enum GNUNET_GenericReturnValue 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 184 of file json_helper.c.

187{
188 const char *str;
189 size_t size;
190 void *data;
191
192 str = json_string_value (root);
193 if (NULL == str)
194 {
195 GNUNET_break_op (0);
196 return GNUNET_SYSERR;
197 }
198 if (GNUNET_OK !=
200 strlen (str),
201 &data,
202 &size))
203 {
204 GNUNET_break_op (0);
205 return GNUNET_SYSERR;
206 }
207 *(void **) spec->ptr = data;
208 *spec->size_ptr = size;
209 return GNUNET_OK;
210}
static char * data
The data to insert into the dht.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data_alloc(const char *enc, size_t enclen, void **out, size_t *out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:855
size_t * size_ptr
Where should we store the final size of ptr.

References data, GNUNET_break_op, GNUNET_OK, GNUNET_STRINGS_string_to_data_alloc(), GNUNET_SYSERR, GNUNET_JSON_Specification::ptr, size, and GNUNET_JSON_Specification::size_ptr.

Referenced by GNUNET_JSON_spec_varsize().

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

222{
223 (void) cls;
224 if (0 != *spec->size_ptr)
225 {
226 GNUNET_free (*(void **) spec->ptr);
227 *(void **) spec->ptr = NULL;
228 *spec->size_ptr = 0;
229 }
230}

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

Referenced by GNUNET_JSON_spec_varsize().

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

237{
239 .parser = &parse_variable_data,
240 .cleaner = &clean_variable_data,
241 .cls = NULL,
242 .field = name,
243 .ptr = obj,
244 .ptr_size = 0,
245 .size_ptr = size
246 };
247
248 *obj = NULL;
249 *size = 0;
250 return ret;
251}
static void clean_variable_data(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing variable size data.
Definition: json_helper.c:220
static enum GNUNET_GenericReturnValue 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:184

References clean_variable_data(), name, parse_variable_data(), ret, and size.

Here is the call graph for this function:

◆ parse_string()

static enum GNUNET_GenericReturnValue 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 263 of file json_helper.c.

266{
267 const char *str;
268
269 (void) cls;
270 str = json_string_value (root);
271 if (NULL == str)
272 {
273 GNUNET_break_op (0);
274 return GNUNET_SYSERR;
275 }
276 *(const char **) spec->ptr = str;
277 return GNUNET_OK;
278}

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

Referenced by GNUNET_JSON_spec_string().

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

284{
286 .parser = &parse_string,
287 .field = name,
288 .ptr = strptr
289 };
290
291 *strptr = NULL;
292 return ret;
293}
static enum GNUNET_GenericReturnValue parse_string(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to string.
Definition: json_helper.c:263

References name, parse_string(), and ret.

Here is the call graph for this function:

◆ parse_json()

static enum GNUNET_GenericReturnValue parse_json ( 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 305 of file json_helper.c.

308{
309 if (! (json_is_object (root) || json_is_array (root)))
310 {
311 GNUNET_break_op (0);
312 return GNUNET_SYSERR;
313 }
314 json_incref (root);
315 *(json_t **) spec->ptr = root;
316 return GNUNET_OK;
317}

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

Referenced by GNUNET_JSON_spec_json().

Here is the caller graph for this function:

◆ clean_json()

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

329{
330 json_t **ptr = (json_t **) spec->ptr;
331
332 if (NULL != *ptr)
333 {
334 json_decref (*ptr);
335 *ptr = NULL;
336 }
337}

References GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_json().

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 or array.

Reference counter is incremented.

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

Definition at line 341 of file json_helper.c.

343{
345 .parser = &parse_json,
346 .cleaner = &clean_json,
347 .cls = NULL,
348 .field = name,
349 .ptr = jsonp,
350 .ptr_size = 0,
351 .size_ptr = NULL
352 };
353
354 *jsonp = NULL;
355 return ret;
356}
static void clean_json(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing JSON object.
Definition: json_helper.c:327
static enum GNUNET_GenericReturnValue parse_json(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a JSON object.
Definition: json_helper.c:305

References clean_json(), name, parse_json(), and ret.

Here is the call graph for this function:

◆ parse_object_const()

static enum GNUNET_GenericReturnValue parse_object_const ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a JSON object.

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

371{
372 if (NULL == root)
373 return GNUNET_OK;
374 if (! json_is_object (root))
375 {
376 GNUNET_break_op (0);
377 return GNUNET_SYSERR;
378 }
379 *(const json_t **) spec->ptr = (const json_t *) root;
380 return GNUNET_OK;
381}

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

Referenced by GNUNET_JSON_spec_object_const().

Here is the caller graph for this function:

◆ GNUNET_JSON_spec_object_const()

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

JSON object, reference counter not incremented.

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

Definition at line 385 of file json_helper.c.

387{
389 .parser = &parse_object_const,
390 .cls = NULL,
391 .field = name,
392 .ptr = jsonp,
393 .ptr_size = 0,
394 .size_ptr = NULL
395 };
396
397 *jsonp = NULL;
398 return ret;
399}
static enum GNUNET_GenericReturnValue parse_object_const(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a JSON object.
Definition: json_helper.c:368

References name, parse_object_const(), and ret.

Here is the call graph for this function:

◆ parse_array_const()

static enum GNUNET_GenericReturnValue parse_array_const ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON to a JSON array.

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

414{
415 if (NULL == root)
416 return GNUNET_OK;
417 if (! json_is_array (root))
418 {
419 GNUNET_break_op (0);
420 return GNUNET_SYSERR;
421 }
422 *(const json_t **) spec->ptr = (const json_t *) root;
423 return GNUNET_OK;
424}

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

Referenced by GNUNET_JSON_spec_array_const().

Here is the caller graph for this function:

◆ GNUNET_JSON_spec_array_const()

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

JSON array, reference counter not incremented.

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

Definition at line 428 of file json_helper.c.

430{
432 .parser = &parse_array_const,
433 .cls = NULL,
434 .field = name,
435 .ptr = jsonp,
436 .ptr_size = 0,
437 .size_ptr = NULL
438 };
439
440 *jsonp = NULL;
441 return ret;
442}
static enum GNUNET_GenericReturnValue parse_array_const(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON to a JSON array.
Definition: json_helper.c:411

References name, parse_array_const(), and ret.

Here is the call graph for this function:

◆ parse_bool()

static enum GNUNET_GenericReturnValue 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 454 of file json_helper.c.

457{
458 bool *b = spec->ptr;
459
460 if (json_true () == root)
461 {
462 *b = true;
463 return GNUNET_OK;
464 }
465 if (json_false () == root)
466 {
467 *b = false;
468 return GNUNET_OK;
469 }
470 GNUNET_break_op (0);
471 return GNUNET_SYSERR;
472}

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

Referenced by GNUNET_JSON_spec_bool().

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

478{
480 .parser = &parse_bool,
481 .cleaner = NULL,
482 .cls = NULL,
483 .field = name,
484 .ptr = b,
485 .ptr_size = sizeof(bool),
486 .size_ptr = NULL
487 };
488
489 return ret;
490}
static enum GNUNET_GenericReturnValue parse_bool(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a bool.
Definition: json_helper.c:454

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

Here is the call graph for this function:

◆ parse_double()

static enum GNUNET_GenericReturnValue parse_double ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a double.

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

505{
506 double *f = spec->ptr;
507
508 if (! json_is_real (root))
509 {
510 GNUNET_break_op (0);
511 return GNUNET_SYSERR;
512 }
513 *f = json_real_value (root);
514 return GNUNET_OK;
515}

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

Referenced by GNUNET_JSON_spec_double().

Here is the caller graph for this function:

◆ GNUNET_JSON_spec_double()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_double ( const char *  name,
double *  f 
)

double.

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

Definition at line 519 of file json_helper.c.

521{
523 .parser = &parse_double,
524 .cleaner = NULL,
525 .cls = NULL,
526 .field = name,
527 .ptr = f,
528 .ptr_size = sizeof(double),
529 .size_ptr = NULL
530 };
531
532 return ret;
533}
static enum GNUNET_GenericReturnValue parse_double(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a double.
Definition: json_helper.c:502

References removetrailingwhitespace::f, name, parse_double(), ret, and GNUNET_JSON_Specification::size_ptr.

Here is the call graph for this function:

◆ parse_u8()

static enum GNUNET_GenericReturnValue 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 545 of file json_helper.c.

548{
549 json_int_t val;
550 uint8_t *up = spec->ptr;
551
552 if (! json_is_integer (root))
553 {
554 GNUNET_break_op (0);
555 return GNUNET_SYSERR;
556 }
557 val = json_integer_value (root);
558 if ((0 > val) || (val > UINT8_MAX))
559 {
560 GNUNET_break_op (0);
561 return GNUNET_SYSERR;
562 }
563 *up = (uint8_t) val;
564 return GNUNET_OK;
565}

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

Referenced by GNUNET_JSON_spec_uint8().

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

571{
573 .parser = &parse_u8,
574 .cleaner = NULL,
575 .cls = NULL,
576 .field = name,
577 .ptr = u8,
578 .ptr_size = sizeof(uint8_t),
579 .size_ptr = NULL
580 };
581
582 return ret;
583}
static enum GNUNET_GenericReturnValue parse_u8(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint8_t.
Definition: json_helper.c:545

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

Here is the call graph for this function:

◆ parse_u16()

static enum GNUNET_GenericReturnValue 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 595 of file json_helper.c.

598{
599 json_int_t val;
600 uint16_t *up = spec->ptr;
601
602 if (! json_is_integer (root))
603 {
604 GNUNET_break_op (0);
605 return GNUNET_SYSERR;
606 }
607 val = json_integer_value (root);
608 if ((0 > val) || (val > UINT16_MAX))
609 {
610 GNUNET_break_op (0);
611 return GNUNET_SYSERR;
612 }
613 *up = (uint16_t) val;
614 return GNUNET_OK;
615}

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

Referenced by GNUNET_JSON_spec_uint16().

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

621{
623 .parser = &parse_u16,
624 .cleaner = NULL,
625 .cls = NULL,
626 .field = name,
627 .ptr = u16,
628 .ptr_size = sizeof(uint16_t),
629 .size_ptr = NULL
630 };
631
632 return ret;
633}
static enum GNUNET_GenericReturnValue parse_u16(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint16_t.
Definition: json_helper.c:595

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

Here is the call graph for this function:

◆ parse_u32()

static enum GNUNET_GenericReturnValue 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 645 of file json_helper.c.

648{
649 json_int_t val;
650 uint32_t *up = spec->ptr;
651
652 if (! json_is_integer (root))
653 {
654 GNUNET_break_op (0);
655 return GNUNET_SYSERR;
656 }
657 val = json_integer_value (root);
658 if ((0 > val) || (val > UINT32_MAX))
659 {
660 GNUNET_break_op (0);
661 return GNUNET_SYSERR;
662 }
663 *up = (uint32_t) val;
664 return GNUNET_OK;
665}

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

Referenced by GNUNET_JSON_spec_uint32().

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

671{
673 .parser = &parse_u32,
674 .cleaner = NULL,
675 .cls = NULL,
676 .field = name,
677 .ptr = u32,
678 .ptr_size = sizeof(uint32_t),
679 .size_ptr = NULL
680 };
681
682 return ret;
683}
static enum GNUNET_GenericReturnValue parse_u32(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint32_t.
Definition: json_helper.c:645

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

Here is the call graph for this function:

◆ parse_u64()

static enum GNUNET_GenericReturnValue 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 695 of file json_helper.c.

698{
699 json_int_t val;
700 uint64_t *up = spec->ptr;
701
702 if (! json_is_integer (root))
703 {
704 GNUNET_break_op (0);
705 return GNUNET_SYSERR;
706 }
707 val = json_integer_value (root);
708 *up = (uint64_t) val;
709 return GNUNET_OK;
710}

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

Referenced by GNUNET_JSON_spec_uint64().

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

716{
718 .parser = &parse_u64,
719 .cleaner = NULL,
720 .cls = NULL,
721 .field = name,
722 .ptr = u64,
723 .ptr_size = sizeof(uint64_t),
724 .size_ptr = NULL
725 };
726
727 return ret;
728}
static enum GNUNET_GenericReturnValue parse_u64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint64_t.
Definition: json_helper.c:695

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

Here is the call graph for this function:

◆ parse_i64()

static enum GNUNET_GenericReturnValue 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 740 of file json_helper.c.

743{
744 json_int_t val;
745 int64_t *up = spec->ptr;
746
747 if (! json_is_integer (root))
748 {
749 GNUNET_break_op (0);
750 return GNUNET_SYSERR;
751 }
752 val = json_integer_value (root);
753 *up = (int64_t) val;
754 return GNUNET_OK;
755}

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

Referenced by GNUNET_JSON_spec_int64().

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

761{
763 .parser = &parse_i64,
764 .cleaner = NULL,
765 .cls = NULL,
766 .field = name,
767 .ptr = i64,
768 .ptr_size = sizeof(int64_t),
769 .size_ptr = NULL
770 };
771
772 return ret;
773}
static enum GNUNET_GenericReturnValue parse_i64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a int64_t.
Definition: json_helper.c:740

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

Here is the call graph for this function:

◆ parse_timestamp()

static enum GNUNET_GenericReturnValue parse_timestamp ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a timestamp.

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

790{
791 struct GNUNET_TIME_Timestamp *ts = spec->ptr;
792 json_t *json_t_s;
793 unsigned long long int tval;
794
795 if (! json_is_object (root))
796 {
797 GNUNET_break_op (0);
798 return GNUNET_SYSERR;
799 }
800 json_t_s = json_object_get (root,
801 "t_s");
802 if (json_is_integer (json_t_s))
803 {
804 tval = json_integer_value (json_t_s);
805 /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
807 = tval * GNUNET_TIME_UNIT_SECONDS.rel_value_us;
808 if (ts->abs_time.abs_value_us
809 / GNUNET_TIME_UNIT_SECONDS.rel_value_us
810 != tval)
811 {
812 /* Integer overflow */
813 GNUNET_break_op (0);
814 return GNUNET_SYSERR;
815 }
816 return GNUNET_OK;
817 }
818 if (json_is_string (json_t_s))
819 {
820 const char *val;
821
822 val = json_string_value (json_t_s);
823 if ((0 == strcasecmp (val,
824 "never")))
825 {
827 return GNUNET_OK;
828 }
829 GNUNET_break_op (0);
830 return GNUNET_SYSERR;
831 }
832 GNUNET_break_op (0);
833 return GNUNET_SYSERR;
834}
#define GNUNET_TIME_UNIT_SECONDS
One second.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
uint64_t abs_value_us
The actual value.
Rounded time for timestamps used by GNUnet, in seconds.
struct GNUNET_TIME_Absolute abs_time
The actual value.

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

Referenced by GNUNET_JSON_spec_timestamp(), and parse_timestamp_nbo().

Here is the caller graph for this function:

◆ GNUNET_JSON_spec_timestamp()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp ( const char *  name,
struct GNUNET_TIME_Timestamp t 
)

Timestamp.

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

Definition at line 838 of file json_helper.c.

840{
842 .parser = &parse_timestamp,
843 .field = name,
844 .ptr = t,
845 .ptr_size = sizeof(struct GNUNET_TIME_Timestamp)
846 };
847
848 return ret;
849}
static struct GNUNET_SCHEDULER_Task * t
Main task.
static enum GNUNET_GenericReturnValue parse_timestamp(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a timestamp.
Definition: json_helper.c:787

References name, parse_timestamp(), ret, and t.

Here is the call graph for this function:

◆ parse_timestamp_nbo()

static enum GNUNET_GenericReturnValue parse_timestamp_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 861 of file json_helper.c.

864{
865 struct GNUNET_TIME_TimestampNBO *ts = spec->ptr;
866 struct GNUNET_TIME_Timestamp a;
867 struct GNUNET_JSON_Specification ispec;
868
869 ispec = *spec;
870 ispec.parser = &parse_timestamp;
871 ispec.ptr = &a;
872 if (GNUNET_OK !=
873 parse_timestamp (NULL,
874 root,
875 &ispec))
876 return GNUNET_SYSERR;
878 return GNUNET_OK;
879}
struct GNUNET_TIME_TimestampNBO GNUNET_TIME_timestamp_hton(struct GNUNET_TIME_Timestamp t)
Convert timestamp to network byte order.
Definition: time.c:91
GNUNET_JSON_Parser parser
Function for how to parse this type of entry.
Time for timestamps used by GNUnet, in seconds and in network byte order.

References GNUNET_OK, GNUNET_SYSERR, GNUNET_TIME_timestamp_hton(), parse_timestamp(), GNUNET_JSON_Specification::parser, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_timestamp_nbo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_spec_timestamp_nbo()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp_nbo ( const char *  name,
struct GNUNET_TIME_TimestampNBO tn 
)

Timestamp in network byte order.

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

Definition at line 883 of file json_helper.c.

885{
887 .parser = &parse_timestamp_nbo,
888 .field = name,
889 .ptr = at,
890 .ptr_size = sizeof(struct GNUNET_TIME_TimestampNBO)
891 };
892
893 return ret;
894}
static enum GNUNET_GenericReturnValue parse_timestamp_nbo(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to absolute time.
Definition: json_helper.c:861

References name, parse_timestamp_nbo(), and ret.

Here is the call graph for this function:

◆ parse_rel_time()

static enum GNUNET_GenericReturnValue 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 906 of file json_helper.c.

909{
910 struct GNUNET_TIME_Relative *rel = spec->ptr;
911 json_t *json_d_us;
912 unsigned long long int tval;
913
914 if (! json_is_object (root))
915 {
916 GNUNET_break_op (0);
917 return GNUNET_SYSERR;
918 }
919 json_d_us = json_object_get (root,
920 "d_us");
921 if (json_is_integer (json_d_us))
922 {
923 tval = json_integer_value (json_d_us);
924 if (tval >= (1LLU << 53))
925 {
926 /* value is larger than allowed */
927 GNUNET_break_op (0);
928 return GNUNET_SYSERR;
929 }
930 rel->rel_value_us = tval;
931 return GNUNET_OK;
932 }
933 if (json_is_string (json_d_us))
934 {
935 const char *val;
936
937 val = json_string_value (json_d_us);
938 if ((0 == strcasecmp (val,
939 "forever")))
940 {
942 return GNUNET_OK;
943 }
944 GNUNET_break_op (0);
945 return GNUNET_SYSERR;
946 }
947 GNUNET_break_op (0);
948 return GNUNET_SYSERR;
949}
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.

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

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

955{
957 .parser = &parse_rel_time,
958 .field = name,
959 .ptr = rt,
960 .ptr_size = sizeof(struct GNUNET_TIME_Relative)
961 };
962
963 return ret;
964}
static enum GNUNET_GenericReturnValue parse_rel_time(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to relative time.
Definition: json_helper.c:906

References name, parse_rel_time(), and ret.

Here is the call graph for this function:

◆ parse_rsa_public_key()

static enum GNUNET_GenericReturnValue 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 976 of file json_helper.c.

979{
980 struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
981 const char *enc;
982 char *buf;
983 size_t len;
984 size_t buf_len;
985
986 if (NULL == (enc = json_string_value (root)))
987 {
988 GNUNET_break_op (0);
989 return GNUNET_SYSERR;
990 }
991 len = strlen (enc);
992 buf_len = (len * 5) / 8;
993 buf = GNUNET_malloc (buf_len);
994 if (GNUNET_OK !=
996 len,
997 buf,
998 buf_len))
999 {
1000 GNUNET_break_op (0);
1001 GNUNET_free (buf);
1002 return GNUNET_SYSERR;
1003 }
1004 if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode (buf,
1005 buf_len)))
1006 {
1007 GNUNET_break_op (0);
1008 GNUNET_free (buf);
1009 return GNUNET_SYSERR;
1010 }
1011 GNUNET_free (buf);
1012 return GNUNET_OK;
1013}
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
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:423
#define GNUNET_malloc(size)
Wrapper around malloc.
The public information of an RSA key pair.
Definition: crypto_rsa.c:53

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

Referenced by GNUNET_JSON_spec_rsa_public_key().

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

1025{
1026 struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
1027
1028 if (NULL != *pk)
1029 {
1031 *pk = NULL;
1032 }
1033}
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
Definition: crypto_rsa.c:268

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

Referenced by GNUNET_JSON_spec_rsa_public_key().

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

1039{
1041 .parser = &parse_rsa_public_key,
1042 .cleaner = &clean_rsa_public_key,
1043 .field = name,
1044 .ptr = pk
1045 };
1046
1047 *pk = NULL;
1048 return ret;
1049}
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:1023
static enum GNUNET_GenericReturnValue 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:976

References clean_rsa_public_key(), name, parse_rsa_public_key(), pk, and ret.

Here is the call graph for this function:

◆ parse_rsa_signature()

static enum GNUNET_GenericReturnValue 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 1061 of file json_helper.c.

1064{
1065 struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
1066 size_t size;
1067 const char *str;
1068 int res;
1069 void *buf;
1070
1071 str = json_string_value (root);
1072 if (NULL == str)
1073 {
1074 GNUNET_break_op (0);
1075 return GNUNET_SYSERR;
1076 }
1077 size = (strlen (str) * 5) / 8;
1078 buf = GNUNET_malloc (size);
1080 strlen (str),
1081 buf,
1082 size);
1083 if (GNUNET_OK != res)
1084 {
1085 GNUNET_free (buf);
1086 GNUNET_break_op (0);
1087 return GNUNET_SYSERR;
1088 }
1089 if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode (buf,
1090 size)))
1091 {
1092 GNUNET_break_op (0);
1093 GNUNET_free (buf);
1094 return GNUNET_SYSERR;
1095 }
1096 GNUNET_free (buf);
1097 return GNUNET_OK;
1098}
static char * res
Currently read line or NULL on EOF.
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:1063
an RSA signature
Definition: crypto_rsa.c:65

References 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().

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

1110{
1111 struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
1112
1113 if (NULL != *sig)
1114 {
1116 *sig = NULL;
1117 }
1118}
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.
Definition: crypto_rsa.c:1015

References GNUNET_CRYPTO_rsa_signature_free(), and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_rsa_signature().

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

1124{
1126 .parser = &parse_rsa_signature,
1127 .cleaner = &clean_rsa_signature,
1128 .cls = NULL,
1129 .field = name,
1130 .ptr = sig,
1131 .ptr_size = 0,
1132 .size_ptr = NULL
1133 };
1134
1135 *sig = NULL;
1136 return ret;
1137}
static enum GNUNET_GenericReturnValue parse_rsa_signature(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to RSA signature.
Definition: json_helper.c:1061
static void clean_rsa_signature(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA signature.
Definition: json_helper.c:1108

References clean_rsa_signature(), name, parse_rsa_signature(), and ret.

Here is the call graph for this function:

◆ parse_boolean()

static enum GNUNET_GenericReturnValue 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 1149 of file json_helper.c.

1152{
1153 int *bp = spec->ptr;
1154
1155 if (! json_is_boolean (root))
1156 {
1157 GNUNET_break_op (0);
1158 return GNUNET_SYSERR;
1159 }
1160 *bp = json_boolean_value (root) ? GNUNET_YES : GNUNET_NO;
1161 return GNUNET_OK;
1162}
@ GNUNET_YES
@ GNUNET_NO

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

Referenced by GNUNET_JSON_spec_boolean().

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

1168{
1170 .parser = &parse_boolean,
1171 .cleaner = NULL,
1172 .cls = NULL,
1173 .field = name,
1174 .ptr = boolean,
1175 .ptr_size = sizeof(int),
1176 .size_ptr = NULL
1177 };
1178
1179 return ret;
1180}
static enum GNUNET_GenericReturnValue 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:1149

References consensus-simulation::int, name, parse_boolean(), ret, and GNUNET_JSON_Specification::size_ptr.

Here is the call graph for this function: