GNUnet 0.24.1-15-gab6ed22f1
json_helper.c File Reference

functions to generate specifciations for JSON parsing More...

#include "platform.h"
#include "gnunet_json_lib.h"
#include "gnunet_common.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_CRYPTO_BlindSignatureAlgorithm string_to_cipher (const char *cipher_s)
 Convert string value to numeric cipher value. 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_string_copy (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to string, and make a copy. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_string_copy (const char *name, 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_object_copy (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a JSON object and increment the reference counter. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_object_copy (const char *name, 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_array_copy (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON to a JSON array and increment the reference counter. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_array_copy (const char *name, 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_ui (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to an unsigned int. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint (const char *name, unsigned int *ui)
 Unsigned integer. More...
 
static enum GNUNET_GenericReturnValue parse_ull (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to an unsigned long long. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_ull (const char *name, unsigned long long *ull)
 Unsigned long long. 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_i16 (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a int16_t. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_int16 (const char *name, int16_t *i16)
 16-bit signed 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...
 
static enum GNUNET_GenericReturnValue parse_blinded_message (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a blinded message. More...
 
static void clean_blinded_message (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing blinded message. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_blinded_message (const char *name, struct GNUNET_CRYPTO_BlindedMessage **msg)
 Specification for parsing a blinded message. More...
 
static enum GNUNET_GenericReturnValue parse_blinded_sig (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a blinded signature. More...
 
static void clean_blinded_sig (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing blinded sig. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_blinded_signature (const char *field, struct GNUNET_CRYPTO_BlindedSignature **b_sig)
 Specification for parsing a blinded signature. More...
 
static enum GNUNET_GenericReturnValue parse_unblinded_sig (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to unblinded signature. More...
 
static void clean_unblinded_sig (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing unblinded signature. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_unblinded_signature (const char *field, struct GNUNET_CRYPTO_UnblindedSignature **ub_sig)
 Specification for parsing an unblinded signature. 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 33 of file json_helper.c.

34{
36 .parser = NULL,
37 };
38
39 return ret;
40}
static int ret
Final status code.
Definition: gnunet-arm.c:93
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(), parse_blinded_message(), parse_blinded_sig(), parse_unblinded_sig(), and revoke_ticket_cont().

Here is the caller graph for this function:

◆ string_to_cipher()

static enum GNUNET_CRYPTO_BlindSignatureAlgorithm string_to_cipher ( const char *  cipher_s)
static

Convert string value to numeric cipher value.

Parameters
cipher_sinput string
Returns
numeric cipher value

Definition at line 50 of file json_helper.c.

51{
52 if ((0 == strcasecmp (cipher_s,
53 "RSA")) ||
54 (0 == strcasecmp (cipher_s,
55 "RSA+age_restricted")))
57 if ((0 == strcasecmp (cipher_s,
58 "CS")) ||
59 (0 == strcasecmp (cipher_s,
60 "CS+age_restricted")))
63}
@ GNUNET_CRYPTO_BSA_INVALID
Invalid type of signature.
@ GNUNET_CRYPTO_BSA_CS
Clause Blind Schnorr signature.
@ GNUNET_CRYPTO_BSA_RSA
RSA blind signature.

References GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, and GNUNET_CRYPTO_BSA_RSA.

Referenced by parse_blinded_message(), parse_blinded_sig(), and parse_unblinded_sig().

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

78{
79 const char *enc;
80 size_t len;
81
82 if (NULL == (enc = json_string_value (root)))
83 {
85 return GNUNET_SYSERR;
86 }
87 len = strlen (enc);
88 if (len >= SIZE_MAX / 5)
89 {
91 return GNUNET_SYSERR;
92 }
93 if (((len * 5) / 8) != spec->ptr_size)
94 {
97 "Field `%s' has wrong length\n",
98 spec->field);
99 return GNUNET_SYSERR;
100 }
101 if (GNUNET_OK !=
103 len,
104 spec->ptr,
105 spec->ptr_size))
106 {
107 GNUNET_break_op (0);
108 return GNUNET_SYSERR;
109 }
110 return GNUNET_OK;
111}
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:816
#define SIZE_MAX
Definition: platform.h:209
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 115 of file json_helper.c.

118{
120 .parser = &parse_fixed_data,
121 .field = name,
122 .ptr = obj,
123 .ptr_size = size,
124 };
125
126 return ret;
127}
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:75
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 139 of file json_helper.c.

142{
143 const char *enc;
144 unsigned int len;
145 void *output;
146 size_t olen;
147
148 if (NULL == (enc = json_string_value (root)))
149 {
150 GNUNET_break_op (0);
151 return GNUNET_SYSERR;
152 }
153 len = strlen (enc);
154 output = NULL;
156 len,
157 &output);
158 if (olen != spec->ptr_size)
159 {
160 GNUNET_break_op (0);
162 "Field `%s' has wrong length\n",
163 spec->field);
164 GNUNET_free (output);
165 return GNUNET_SYSERR;
166 }
167 memcpy (spec->ptr,
168 output,
169 olen);
170 GNUNET_free (output);
171 return GNUNET_OK;
172}
#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:1704

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

179{
181 .parser = &parse_fixed64_data,
182 .field = name,
183 .ptr = obj,
184 .ptr_size = size,
185 };
186
187 return ret;
188}
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:139

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

203{
204 const char *str;
205 size_t size;
206 void *data;
207
208 str = json_string_value (root);
209 if (NULL == str)
210 {
211 GNUNET_break_op (0);
212 return GNUNET_SYSERR;
213 }
214 if (GNUNET_OK !=
216 strlen (str),
217 &data,
218 &size))
219 {
220 GNUNET_break_op (0);
221 return GNUNET_SYSERR;
222 }
223 *(void **) spec->ptr = data;
224 *spec->size_ptr = size;
225 return GNUNET_OK;
226}
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:882
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 236 of file json_helper.c.

238{
239 (void) cls;
240 if (0 != *spec->size_ptr)
241 {
242 GNUNET_free (*(void **) spec->ptr);
243 *(void **) spec->ptr = NULL;
244 *spec->size_ptr = 0;
245 }
246}

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

253{
255 .parser = &parse_variable_data,
256 .cleaner = &clean_variable_data,
257 .field = name,
258 .ptr = obj,
259 .size_ptr = size
260 };
261
262 *obj = NULL;
263 *size = 0;
264 return ret;
265}
static void clean_variable_data(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing variable size data.
Definition: json_helper.c:236
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:200

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

Referenced by parse_blinded_message().

Here is the call graph for this function:
Here is the caller 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 277 of file json_helper.c.

280{
281 const char *str;
282
283 (void) cls;
284 str = json_string_value (root);
285 if (NULL == str)
286 {
287 GNUNET_break_op (0);
288 return GNUNET_SYSERR;
289 }
290 *(const char **) spec->ptr = str;
291 return GNUNET_OK;
292}

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

298{
300 .parser = &parse_string,
301 .field = name,
302 .ptr = strptr
303 };
304
305 *strptr = NULL;
306 return ret;
307}
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:277

References name, parse_string(), and ret.

Referenced by consume_ticket_cont(), parse_blinded_message(), parse_blinded_sig(), and parse_unblinded_sig().

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

◆ parse_string_copy()

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

Parse given JSON object to string, and make a copy.

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

322{
323 const char *str;
324
325 (void) cls;
326 str = json_string_value (root);
327 if (NULL == str)
328 {
329 GNUNET_break_op (0);
330 return GNUNET_SYSERR;
331 }
332 *((char **) spec->ptr) = GNUNET_strdup (str);
333 return GNUNET_OK;
334}
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.

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

Referenced by GNUNET_JSON_spec_string_copy().

Here is the caller graph for this function:

◆ GNUNET_JSON_spec_string_copy()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_string_copy ( const char *  name,
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 338 of file json_helper.c.

340{
342 .parser = &parse_string_copy,
343 .field = name,
344 .ptr = strptr
345 };
346
347 *strptr = NULL;
348 return ret;
349}
static enum GNUNET_GenericReturnValue parse_string_copy(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to string, and make a copy.
Definition: json_helper.c:319

References name, parse_string_copy(), 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 361 of file json_helper.c.

364{
365 if (! (json_is_object (root) || json_is_array (root)))
366 {
367 GNUNET_break_op (0);
368 return GNUNET_SYSERR;
369 }
370 *(json_t **) spec->ptr = json_incref (root);
371 return GNUNET_OK;
372}

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

384{
385 json_t **ptr = (json_t **) spec->ptr;
386
387 if (NULL != *ptr)
388 {
389 json_decref (*ptr);
390 *ptr = NULL;
391 }
392}

References GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_array_copy(), GNUNET_JSON_spec_json(), and GNUNET_JSON_spec_object_copy().

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

398{
400 .parser = &parse_json,
401 .cleaner = &clean_json,
402 .field = name,
403 .ptr = jsonp,
404 };
405
406 *jsonp = NULL;
407 return ret;
408}
static void clean_json(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing JSON object.
Definition: json_helper.c:382
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:361

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

423{
424 if (NULL == root)
425 return GNUNET_OK;
426 if (! json_is_object (root))
427 {
428 GNUNET_break_op (0);
429 return GNUNET_SYSERR;
430 }
431 *(const json_t **) spec->ptr = (const json_t *) root;
432 return GNUNET_OK;
433}

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

439{
441 .parser = &parse_object_const,
442 .field = name,
443 .ptr = jsonp,
444 };
445
446 *jsonp = NULL;
447 return ret;
448}
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:420

References name, parse_object_const(), and ret.

Here is the call graph for this function:

◆ parse_object_copy()

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

Parse given JSON object to a JSON object and increment the reference counter.

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

463{
464 if (NULL == root)
465 return GNUNET_OK;
466 if (! json_is_object (root))
467 {
468 GNUNET_break_op (0);
469 return GNUNET_SYSERR;
470 }
471 *((json_t **) spec->ptr) = json_incref (root);
472 return GNUNET_OK;
473}

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

Referenced by GNUNET_JSON_spec_object_copy().

Here is the caller graph for this function:

◆ GNUNET_JSON_spec_object_copy()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_object_copy ( const char *  name,
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 477 of file json_helper.c.

479{
481 .parser = &parse_object_copy,
482 .cls = &clean_json,
483 .field = name,
484 .ptr = jsonp,
485 };
486
487 *jsonp = NULL;
488 return ret;
489}
static enum GNUNET_GenericReturnValue parse_object_copy(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a JSON object and increment the reference counter.
Definition: json_helper.c:460

References clean_json(), name, parse_object_copy(), 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 501 of file json_helper.c.

504{
505 if (NULL == root)
506 return GNUNET_OK;
507 if (! json_is_array (root))
508 {
509 GNUNET_break_op (0);
510 return GNUNET_SYSERR;
511 }
512 *(const json_t **) spec->ptr = (const json_t *) root;
513 return GNUNET_OK;
514}

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

520{
522 .parser = &parse_array_const,
523 .field = name,
524 .ptr = jsonp
525 };
526
527 *jsonp = NULL;
528 return ret;
529}
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:501

References name, parse_array_const(), and ret.

Here is the call graph for this function:

◆ parse_array_copy()

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

Parse given JSON to a JSON array and increment the reference counter.

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

544{
545 if (NULL == root)
546 return GNUNET_OK;
547 if (! json_is_array (root))
548 {
549 GNUNET_break_op (0);
550 return GNUNET_SYSERR;
551 }
552 *((json_t **) spec->ptr) = json_incref (root);
553 return GNUNET_OK;
554}

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

Referenced by GNUNET_JSON_spec_array_copy().

Here is the caller graph for this function:

◆ GNUNET_JSON_spec_array_copy()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_array_copy ( const char *  name,
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 558 of file json_helper.c.

560{
562 .parser = &parse_array_copy,
563 .cleaner = &clean_json,
564 .field = name,
565 .ptr = jsonp
566 };
567
568 *jsonp = NULL;
569 return ret;
570}
static enum GNUNET_GenericReturnValue parse_array_copy(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON to a JSON array and increment the reference counter.
Definition: json_helper.c:541

References clean_json(), name, parse_array_copy(), 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 582 of file json_helper.c.

585{
586 bool *b = spec->ptr;
587
588 if (json_true () == root)
589 {
590 *b = true;
591 return GNUNET_OK;
592 }
593 if (json_false () == root)
594 {
595 *b = false;
596 return GNUNET_OK;
597 }
598 GNUNET_break_op (0);
599 return GNUNET_SYSERR;
600}

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

606{
608 .parser = &parse_bool,
609 .field = name,
610 .ptr = b,
611 .ptr_size = sizeof(bool),
612 };
613
614 return ret;
615}
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:582

References name, parse_bool(), and ret.

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

630{
631 double *f = spec->ptr;
632
633 if (! json_is_real (root))
634 {
635 GNUNET_break_op (0);
636 return GNUNET_SYSERR;
637 }
638 *f = json_real_value (root);
639 return GNUNET_OK;
640}

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

646{
648 .parser = &parse_double,
649 .field = name,
650 .ptr = f,
651 .ptr_size = sizeof(double),
652 };
653
654 return ret;
655}
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:627

References name, parse_double(), and ret.

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

670{
671 json_int_t val;
672 uint8_t *up = spec->ptr;
673
674 if (! json_is_integer (root))
675 {
676 GNUNET_break_op (0);
677 return GNUNET_SYSERR;
678 }
679 val = json_integer_value (root);
680 if ((0 > val) || (val > UINT8_MAX))
681 {
682 GNUNET_break_op (0);
683 return GNUNET_SYSERR;
684 }
685 *up = (uint8_t) val;
686 return GNUNET_OK;
687}

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

693{
695 .parser = &parse_u8,
696 .field = name,
697 .ptr = u8,
698 .ptr_size = sizeof(uint8_t),
699 };
700
701 return ret;
702}
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:667

References name, parse_u8(), and ret.

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

717{
718 json_int_t val;
719 uint16_t *up = spec->ptr;
720
721 if (! json_is_integer (root))
722 {
723 GNUNET_break_op (0);
724 return GNUNET_SYSERR;
725 }
726 val = json_integer_value (root);
727 if ((0 > val) || (val > UINT16_MAX))
728 {
729 GNUNET_break_op (0);
730 return GNUNET_SYSERR;
731 }
732 *up = (uint16_t) val;
733 return GNUNET_OK;
734}

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

740{
742 .parser = &parse_u16,
743 .field = name,
744 .ptr = u16,
745 .ptr_size = sizeof(uint16_t),
746 };
747
748 return ret;
749}
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:714

References name, parse_u16(), and ret.

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

764{
765 json_int_t val;
766 uint32_t *up = spec->ptr;
767
768 if (! json_is_integer (root))
769 {
770 GNUNET_break_op (0);
771 return GNUNET_SYSERR;
772 }
773 val = json_integer_value (root);
774 if ((0 > val) || (val > UINT32_MAX))
775 {
776 GNUNET_break_op (0);
777 return GNUNET_SYSERR;
778 }
779 *up = (uint32_t) val;
780 return GNUNET_OK;
781}

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

787{
789 .parser = &parse_u32,
790 .field = name,
791 .ptr = u32,
792 .ptr_size = sizeof(uint32_t),
793 };
794
795 return ret;
796}
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:761

References name, parse_u32(), and ret.

Referenced by parse_blinded_sig().

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

◆ parse_ui()

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

Parse given JSON object to an unsigned int.

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

811{
812 json_int_t val;
813 unsigned int *up = spec->ptr;
814
815 if (! json_is_integer (root))
816 {
817 GNUNET_break_op (0);
818 return GNUNET_SYSERR;
819 }
820 val = json_integer_value (root);
821 if ((0 > val) || (val > UINT_MAX))
822 {
823 GNUNET_break_op (0);
824 return GNUNET_SYSERR;
825 }
826 *up = (unsigned int) val;
827 return GNUNET_OK;
828}

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

Referenced by GNUNET_JSON_spec_uint().

Here is the caller graph for this function:

◆ GNUNET_JSON_spec_uint()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint ( const char *  name,
unsigned int *  ui 
)

Unsigned integer.

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

Definition at line 832 of file json_helper.c.

834{
836 .parser = &parse_ui,
837 .field = name,
838 .ptr = ui,
839 .ptr_size = sizeof(unsigned int),
840 };
841
842 return ret;
843}
static enum GNUNET_GenericReturnValue parse_ui(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to an unsigned int.
Definition: json_helper.c:808

References name, parse_ui(), and ret.

Here is the call graph for this function:

◆ parse_ull()

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

Parse given JSON object to an unsigned long long.

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

858{
859 json_int_t val;
860 unsigned long long *up = spec->ptr;
861
862 if (! json_is_integer (root))
863 {
864 GNUNET_break_op (0);
865 return GNUNET_SYSERR;
866 }
867 val = json_integer_value (root);
868 if ((0 > val) || (val > ULLONG_MAX))
869 {
870 GNUNET_break_op (0);
871 return GNUNET_SYSERR;
872 }
873 *up = (unsigned long long) val;
874 return GNUNET_OK;
875}

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

Referenced by GNUNET_JSON_spec_ull().

Here is the caller graph for this function:

◆ GNUNET_JSON_spec_ull()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_ull ( const char *  name,
unsigned long long *  ull 
)

Unsigned long long.

Parameters
namename of the JSON field
[out]ullwhere to store the unsigned long long found under name

Definition at line 879 of file json_helper.c.

881{
883 .parser = &parse_ull,
884 .field = name,
885 .ptr = ull,
886 .ptr_size = sizeof(unsigned long long),
887 };
888
889 return ret;
890}
static enum GNUNET_GenericReturnValue parse_ull(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to an unsigned long long.
Definition: json_helper.c:855

References name, parse_ull(), and ret.

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

905{
906 json_int_t val;
907 uint64_t *up = spec->ptr;
908
909 if (! json_is_integer (root))
910 {
911 GNUNET_break_op (0);
912 return GNUNET_SYSERR;
913 }
914 val = json_integer_value (root);
915 *up = (uint64_t) val;
916 return GNUNET_OK;
917}

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

923{
925 .parser = &parse_u64,
926 .field = name,
927 .ptr = u64,
928 .ptr_size = sizeof(uint64_t),
929 };
930
931 return ret;
932}
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:902

References name, parse_u64(), and ret.

Here is the call graph for this function:

◆ parse_i16()

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

Parse given JSON object to a int16_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 944 of file json_helper.c.

947{
948 json_int_t val;
949 int16_t *up = spec->ptr;
950
951 if (! json_is_integer (root))
952 {
953 GNUNET_break_op (0);
954 return GNUNET_SYSERR;
955 }
956 val = json_integer_value (root);
957 if ( (val < INT16_MIN) ||
958 (val > INT16_MAX) )
959 {
960 GNUNET_break_op (0);
961 return GNUNET_SYSERR;
962 }
963 *up = (int16_t) val;
964 return GNUNET_OK;
965}

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

Referenced by GNUNET_JSON_spec_int16().

Here is the caller graph for this function:

◆ GNUNET_JSON_spec_int16()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_int16 ( const char *  name,
int16_t *  i16 
)

16-bit signed integer.

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

Definition at line 969 of file json_helper.c.

971{
973 .parser = &parse_i16,
974 .field = name,
975 .ptr = i16,
976 .ptr_size = sizeof(int16_t),
977 };
978
979 return ret;
980}
static enum GNUNET_GenericReturnValue parse_i16(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a int16_t.
Definition: json_helper.c:944

References name, parse_i16(), and ret.

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

995{
996 json_int_t val;
997 int64_t *up = spec->ptr;
998
999 if (! json_is_integer (root))
1000 {
1001 GNUNET_break_op (0);
1002 return GNUNET_SYSERR;
1003 }
1004 val = json_integer_value (root);
1005 *up = (int64_t) val;
1006 return GNUNET_OK;
1007}

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

1013{
1015 .parser = &parse_i64,
1016 .field = name,
1017 .ptr = i64,
1018 .ptr_size = sizeof(int64_t),
1019 };
1020
1021 return ret;
1022}
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:992

References name, parse_i64(), and ret.

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

1039{
1040 struct GNUNET_TIME_Timestamp *ts = spec->ptr;
1041 json_t *json_t_s;
1042 unsigned long long int tval;
1043
1044 if (! json_is_object (root))
1045 {
1046 GNUNET_break_op (0);
1047 return GNUNET_SYSERR;
1048 }
1049 json_t_s = json_object_get (root,
1050 "t_s");
1051 if (json_is_integer (json_t_s))
1052 {
1053 tval = json_integer_value (json_t_s);
1054 /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
1056 = tval * GNUNET_TIME_UNIT_SECONDS.rel_value_us;
1057 if (ts->abs_time.abs_value_us
1058 / GNUNET_TIME_UNIT_SECONDS.rel_value_us
1059 != tval)
1060 {
1061 /* Integer overflow */
1062 GNUNET_break_op (0);
1063 return GNUNET_SYSERR;
1064 }
1065 return GNUNET_OK;
1066 }
1067 if (json_is_string (json_t_s))
1068 {
1069 const char *val;
1070
1071 val = json_string_value (json_t_s);
1072 if ((0 == strcasecmp (val,
1073 "never")))
1074 {
1076 return GNUNET_OK;
1077 }
1078 GNUNET_break_op (0);
1079 return GNUNET_SYSERR;
1080 }
1081 GNUNET_break_op (0);
1082 return GNUNET_SYSERR;
1083}
#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.
Time for timestamps used by GNUnet, in microseconds rounded to 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 1087 of file json_helper.c.

1089{
1091 .parser = &parse_timestamp,
1092 .field = name,
1093 .ptr = t,
1094 .ptr_size = sizeof(struct GNUNET_TIME_Timestamp)
1095 };
1096
1097 return ret;
1098}
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:1036

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

1113{
1114 struct GNUNET_TIME_TimestampNBO *ts = spec->ptr;
1115 struct GNUNET_TIME_Timestamp a;
1116 struct GNUNET_JSON_Specification ispec;
1117
1118 ispec = *spec;
1119 ispec.parser = &parse_timestamp;
1120 ispec.ptr = &a;
1121 if (GNUNET_OK !=
1122 parse_timestamp (NULL,
1123 root,
1124 &ispec))
1125 return GNUNET_SYSERR;
1127 return GNUNET_OK;
1128}
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 1132 of file json_helper.c.

1134{
1136 .parser = &parse_timestamp_nbo,
1137 .field = name,
1138 .ptr = at,
1139 .ptr_size = sizeof(struct GNUNET_TIME_TimestampNBO)
1140 };
1141
1142 return ret;
1143}
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:1110

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

1158{
1159 struct GNUNET_TIME_Relative *rel = spec->ptr;
1160 json_t *json_d_us;
1161 unsigned long long int tval;
1162
1163 if (! json_is_object (root))
1164 {
1165 GNUNET_break_op (0);
1166 return GNUNET_SYSERR;
1167 }
1168 json_d_us = json_object_get (root,
1169 "d_us");
1170 if (json_is_integer (json_d_us))
1171 {
1172 tval = json_integer_value (json_d_us);
1173 if (tval >= (1LLU << 53))
1174 {
1175 /* value is larger than allowed */
1176 GNUNET_break_op (0);
1177 return GNUNET_SYSERR;
1178 }
1179 rel->rel_value_us = tval;
1180 return GNUNET_OK;
1181 }
1182 if (json_is_string (json_d_us))
1183 {
1184 const char *val;
1185
1186 val = json_string_value (json_d_us);
1187 if ((0 == strcasecmp (val,
1188 "forever")))
1189 {
1191 return GNUNET_OK;
1192 }
1193 GNUNET_break_op (0);
1194 return GNUNET_SYSERR;
1195 }
1196 GNUNET_break_op (0);
1197 return GNUNET_SYSERR;
1198}
#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 1202 of file json_helper.c.

1204{
1206 .parser = &parse_rel_time,
1207 .field = name,
1208 .ptr = rt,
1209 .ptr_size = sizeof(struct GNUNET_TIME_Relative)
1210 };
1211
1212 return ret;
1213}
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:1155

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

1228{
1229 struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
1230 const char *enc;
1231 char *buf;
1232 size_t len;
1233 size_t buf_len;
1234
1235 if (NULL == (enc = json_string_value (root)))
1236 {
1237 GNUNET_break_op (0);
1238 return GNUNET_SYSERR;
1239 }
1240 len = strlen (enc);
1241 buf_len = (len * 5) / 8;
1242 buf = GNUNET_malloc (buf_len);
1243 if (GNUNET_OK !=
1245 len,
1246 buf,
1247 buf_len))
1248 {
1249 GNUNET_break_op (0);
1250 GNUNET_free (buf);
1251 return GNUNET_SYSERR;
1252 }
1253 if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode (buf,
1254 buf_len)))
1255 {
1256 GNUNET_break_op (0);
1257 GNUNET_free (buf);
1258 return GNUNET_SYSERR;
1259 }
1260 GNUNET_free (buf);
1261 return GNUNET_OK;
1262}
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 1272 of file json_helper.c.

1274{
1275 struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
1276
1277 if (NULL != *pk)
1278 {
1280 *pk = NULL;
1281 }
1282}
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 1286 of file json_helper.c.

1288{
1290 .parser = &parse_rsa_public_key,
1291 .cleaner = &clean_rsa_public_key,
1292 .field = name,
1293 .ptr = pk
1294 };
1295
1296 *pk = NULL;
1297 return ret;
1298}
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:1272
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:1225

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

1313{
1314 struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
1315 size_t size;
1316 const char *str;
1317 int res;
1318 void *buf;
1319
1320 str = json_string_value (root);
1321 if (NULL == str)
1322 {
1323 GNUNET_break_op (0);
1324 return GNUNET_SYSERR;
1325 }
1326 size = (strlen (str) * 5) / 8;
1327 buf = GNUNET_malloc (size);
1329 strlen (str),
1330 buf,
1331 size);
1332 if (GNUNET_OK != res)
1333 {
1334 GNUNET_free (buf);
1335 GNUNET_break_op (0);
1336 return GNUNET_SYSERR;
1337 }
1338 if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode (buf,
1339 size)))
1340 {
1341 GNUNET_break_op (0);
1342 GNUNET_free (buf);
1343 return GNUNET_SYSERR;
1344 }
1345 GNUNET_free (buf);
1346 return GNUNET_OK;
1347}
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 1357 of file json_helper.c.

1359{
1360 struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
1361
1362 if (NULL != *sig)
1363 {
1365 *sig = NULL;
1366 }
1367}
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 1371 of file json_helper.c.

1373{
1375 .parser = &parse_rsa_signature,
1376 .cleaner = &clean_rsa_signature,
1377 .cls = NULL,
1378 .field = name,
1379 .ptr = sig,
1380 .ptr_size = 0,
1381 .size_ptr = NULL
1382 };
1383
1384 *sig = NULL;
1385 return ret;
1386}
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:1310
static void clean_rsa_signature(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA signature.
Definition: json_helper.c:1357

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

Referenced by parse_blinded_sig(), and parse_unblinded_sig().

Here is the call graph for this function:
Here is the caller 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 1398 of file json_helper.c.

1401{
1402 int *bp = spec->ptr;
1403
1404 if (! json_is_boolean (root))
1405 {
1406 GNUNET_break_op (0);
1407 return GNUNET_SYSERR;
1408 }
1409 *bp = json_boolean_value (root) ? GNUNET_YES : GNUNET_NO;
1410 return GNUNET_OK;
1411}
@ 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 1415 of file json_helper.c.

1417{
1419 .parser = &parse_boolean,
1420 .field = name,
1421 .ptr = boolean,
1422 .ptr_size = sizeof(int),
1423 };
1424
1425 return ret;
1426}
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:1398

References name, parse_boolean(), and ret.

Here is the call graph for this function:

◆ parse_blinded_message()

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

Parse given JSON object to a blinded message.

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

1441{
1442 struct GNUNET_CRYPTO_BlindedMessage **target = spec->ptr;
1443 struct GNUNET_CRYPTO_BlindedMessage *blinded_message;
1444 const char *cipher;
1445 struct GNUNET_JSON_Specification dspec[] = {
1446 GNUNET_JSON_spec_string ("cipher",
1447 &cipher),
1449 };
1450 const char *emsg;
1451 unsigned int eline;
1452
1453 (void) cls;
1454 if (GNUNET_OK !=
1455 GNUNET_JSON_parse (root,
1456 dspec,
1457 &emsg,
1458 &eline))
1459 {
1460 GNUNET_break_op (0);
1461 return GNUNET_SYSERR;
1462 }
1463 blinded_message = GNUNET_new (struct GNUNET_CRYPTO_BlindedMessage);
1464 blinded_message->rc = 1;
1465 blinded_message->cipher = string_to_cipher (cipher);
1466 switch (blinded_message->cipher)
1467 {
1469 break;
1471 {
1472 struct GNUNET_JSON_Specification ispec[] = {
1474 /* TODO: Change this field name to something
1475 more generic / pass in as argument. */
1476 "rsa_blinded_planchet",
1477 &blinded_message->details.rsa_blinded_message.blinded_msg,
1478 &blinded_message->details.rsa_blinded_message.blinded_msg_size),
1480 };
1481
1482 if (GNUNET_OK !=
1483 GNUNET_JSON_parse (root,
1484 ispec,
1485 &emsg,
1486 &eline))
1487 {
1488 GNUNET_break_op (0);
1489 GNUNET_free (blinded_message);
1490 return GNUNET_SYSERR;
1491 }
1492 *target = blinded_message;
1493 return GNUNET_OK;
1494 }
1496 {
1497 struct GNUNET_JSON_Specification ispec[] = {
1499 "cs_nonce",
1500 &blinded_message->details.cs_blinded_message.nonce),
1502 "cs_blinded_c0",
1503 &blinded_message->details.cs_blinded_message.c[0]),
1505 "cs_blinded_c1",
1506 &blinded_message->details.cs_blinded_message.c[1]),
1508 };
1509
1510 if (GNUNET_OK !=
1511 GNUNET_JSON_parse (root,
1512 ispec,
1513 &emsg,
1514 &eline))
1515 {
1516 GNUNET_break_op (0);
1517 GNUNET_free (blinded_message);
1518 return GNUNET_SYSERR;
1519 }
1520 *target = blinded_message;
1521 return GNUNET_OK;
1522 }
1523 }
1524 GNUNET_break_op (0);
1525 GNUNET_free (blinded_message);
1526 return GNUNET_SYSERR;
1527}
#define GNUNET_JSON_spec_fixed_auto(name, obj)
Fixed size object (in network byte order, encoded using Crockford Base32hex encoding).
enum GNUNET_GenericReturnValue GNUNET_JSON_parse(const json_t *root, struct GNUNET_JSON_Specification *spec, const char **error_json_name, unsigned int *error_line)
Navigate and parse data in a JSON tree.
Definition: json.c:32
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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).
Definition: json_helper.c:250
struct GNUNET_JSON_Specification GNUNET_JSON_spec_end()
End of a parser specification.
Definition: json_helper.c:33
struct GNUNET_JSON_Specification GNUNET_JSON_spec_string(const char *name, const char **strptr)
The expected field stores a string.
Definition: json_helper.c:296
static enum GNUNET_CRYPTO_BlindSignatureAlgorithm string_to_cipher(const char *cipher_s)
Convert string value to numeric cipher value.
Definition: json_helper.c:50
Blinded message ready for blind signing.
unsigned int rc
Reference counter.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the sign blinded message.
struct GNUNET_CRYPTO_CsBlindedMessage cs_blinded_message
If we use GNUNET_CRYPTO_BSA_CS in cipher.
union GNUNET_CRYPTO_BlindedMessage::@18 details
Details, depending on cipher.
struct GNUNET_CRYPTO_RsaBlindedMessage rsa_blinded_message
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
struct GNUNET_CRYPTO_CsC c[2]
The Clause Schnorr c_0 and c_1 containing the blinded message.
struct GNUNET_CRYPTO_CsSessionNonce nonce
Nonce used in initial request.
size_t blinded_msg_size
Size of the blinded_msg to be signed.
void * blinded_msg
Blinded message to be signed Note: is malloc()'ed!
void * cls
Closure for parser and cleaner.

References GNUNET_CRYPTO_RsaBlindedMessage::blinded_msg, GNUNET_CRYPTO_RsaBlindedMessage::blinded_msg_size, GNUNET_CRYPTO_CsBlindedMessage::c, GNUNET_CRYPTO_BlindedMessage::cipher, GNUNET_JSON_Specification::cls, GNUNET_CRYPTO_BlindedMessage::cs_blinded_message, GNUNET_CRYPTO_BlindedMessage::details, GNUNET_break_op, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_free, GNUNET_JSON_parse(), GNUNET_JSON_spec_end(), GNUNET_JSON_spec_fixed_auto, GNUNET_JSON_spec_string(), GNUNET_JSON_spec_varsize(), GNUNET_new, GNUNET_OK, GNUNET_SYSERR, GNUNET_CRYPTO_CsBlindedMessage::nonce, GNUNET_JSON_Specification::ptr, GNUNET_CRYPTO_BlindedMessage::rc, GNUNET_CRYPTO_BlindedMessage::rsa_blinded_message, and string_to_cipher().

Referenced by GNUNET_JSON_spec_blinded_message().

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

◆ clean_blinded_message()

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

Cleanup data left from parsing blinded message.

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

Definition at line 1537 of file json_helper.c.

1539{
1540 struct GNUNET_CRYPTO_BlindedMessage **blinded_message = spec->ptr;
1541
1542 (void) cls;
1543 if (NULL != blinded_message)
1544 {
1545 GNUNET_CRYPTO_blinded_message_decref (*blinded_message);
1546 *blinded_message = NULL;
1547 }
1548}
void GNUNET_CRYPTO_blinded_message_decref(struct GNUNET_CRYPTO_BlindedMessage *bm)
Decrement reference counter of a bm, and free it if it reaches zero.

References GNUNET_CRYPTO_blinded_message_decref(), and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_blinded_message().

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

◆ GNUNET_JSON_spec_blinded_message()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_blinded_message ( const char *  name,
struct GNUNET_CRYPTO_BlindedMessage **  msg 
)

Specification for parsing a blinded message.

Parameters
namename of the JSON field
sigwhere to store the blinded message found under name

Definition at line 1552 of file json_helper.c.

1554{
1556 .parser = &parse_blinded_message,
1557 .cleaner = &clean_blinded_message,
1558 .cls = NULL,
1559 .field = name,
1560 .ptr = msg,
1561 .ptr_size = 0,
1562 .size_ptr = NULL
1563 };
1564
1565 *msg = NULL;
1566 return ret;
1567}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static enum GNUNET_GenericReturnValue parse_blinded_message(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a blinded message.
Definition: json_helper.c:1438
static void clean_blinded_message(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing blinded message.
Definition: json_helper.c:1537

References clean_blinded_message(), msg, name, parse_blinded_message(), and ret.

Here is the call graph for this function:

◆ parse_blinded_sig()

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

Parse given JSON object to a blinded 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 1579 of file json_helper.c.

1582{
1583 struct GNUNET_CRYPTO_BlindedSignature **target = spec->ptr;
1584 struct GNUNET_CRYPTO_BlindedSignature *blinded_sig;
1585 const char *cipher;
1586 struct GNUNET_JSON_Specification dspec[] = {
1587 GNUNET_JSON_spec_string ("cipher",
1588 &cipher),
1590 };
1591 const char *emsg;
1592 unsigned int eline;
1593
1594 (void) cls;
1595 if (GNUNET_OK !=
1596 GNUNET_JSON_parse (root,
1597 dspec,
1598 &emsg,
1599 &eline))
1600 {
1601 GNUNET_break_op (0);
1602 return GNUNET_SYSERR;
1603 }
1604 blinded_sig = GNUNET_new (struct GNUNET_CRYPTO_BlindedSignature);
1605 blinded_sig->cipher = string_to_cipher (cipher);
1606 blinded_sig->rc = 1;
1607 switch (blinded_sig->cipher)
1608 {
1610 break;
1612 {
1613 struct GNUNET_JSON_Specification ispec[] = {
1615 "blinded_rsa_signature",
1616 &blinded_sig->details.blinded_rsa_signature),
1618 };
1619
1620 if (GNUNET_OK !=
1621 GNUNET_JSON_parse (root,
1622 ispec,
1623 &emsg,
1624 &eline))
1625 {
1626 GNUNET_break_op (0);
1627 GNUNET_free (blinded_sig);
1628 return GNUNET_SYSERR;
1629 }
1630 *target = blinded_sig;
1631 return GNUNET_OK;
1632 }
1634 {
1635 struct GNUNET_JSON_Specification ispec[] = {
1637 &blinded_sig->details.blinded_cs_answer.b),
1639 &blinded_sig->details.blinded_cs_answer.
1640 s_scalar),
1642 };
1643
1644 if (GNUNET_OK !=
1645 GNUNET_JSON_parse (root,
1646 ispec,
1647 &emsg,
1648 &eline))
1649 {
1650 GNUNET_break_op (0);
1651 GNUNET_free (blinded_sig);
1652 return GNUNET_SYSERR;
1653 }
1654 *target = blinded_sig;
1655 return GNUNET_OK;
1656 }
1657 }
1658 GNUNET_break_op (0);
1659 GNUNET_free (blinded_sig);
1660 return GNUNET_SYSERR;
1661}
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint32(const char *name, uint32_t *u32)
32-bit integer.
Definition: json_helper.c:785
struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_signature(const char *name, struct GNUNET_CRYPTO_RsaSignature **sig)
Specification for parsing an RSA signature.
Definition: json_helper.c:1371
Type for blinded signatures.
unsigned int rc
Reference counter.
struct GNUNET_CRYPTO_CsBlindSignature blinded_cs_answer
If we use GNUNET_CRYPTO_BSA_CS in cipher.
union GNUNET_CRYPTO_BlindedSignature::@15 details
Details, depending on cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the signature.
struct GNUNET_CRYPTO_RsaSignature * blinded_rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
unsigned int b
To make ROS problem harder, the signer chooses an unpredictable b and only calculates signature of c_...

References GNUNET_CRYPTO_CsBlindSignature::b, GNUNET_CRYPTO_BlindedSignature::blinded_cs_answer, GNUNET_CRYPTO_BlindedSignature::blinded_rsa_signature, GNUNET_CRYPTO_BlindedSignature::cipher, GNUNET_JSON_Specification::cls, GNUNET_CRYPTO_BlindedSignature::details, GNUNET_break_op, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_free, GNUNET_JSON_parse(), GNUNET_JSON_spec_end(), GNUNET_JSON_spec_fixed_auto, GNUNET_JSON_spec_rsa_signature(), GNUNET_JSON_spec_string(), GNUNET_JSON_spec_uint32(), GNUNET_new, GNUNET_OK, GNUNET_SYSERR, GNUNET_JSON_Specification::ptr, GNUNET_CRYPTO_BlindedSignature::rc, and string_to_cipher().

Referenced by GNUNET_JSON_spec_blinded_signature().

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

◆ clean_blinded_sig()

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

Cleanup data left from parsing blinded sig.

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

Definition at line 1671 of file json_helper.c.

1673{
1674 struct GNUNET_CRYPTO_BlindedSignature **b_sig = spec->ptr;
1675
1676 (void) cls;
1677
1678 if (NULL != *b_sig)
1679 {
1681 *b_sig = NULL;
1682 }
1683}
void GNUNET_CRYPTO_blinded_sig_decref(struct GNUNET_CRYPTO_BlindedSignature *blind_sig)
Decrement reference counter of a blind_sig, and free it if it reaches zero.

References GNUNET_CRYPTO_blinded_sig_decref(), and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_blinded_signature().

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

◆ GNUNET_JSON_spec_blinded_signature()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_blinded_signature ( const char *  field,
struct GNUNET_CRYPTO_BlindedSignature **  b_sig 
)

Specification for parsing a blinded signature.

Parameters
namename of the JSON field
sigwhere to store the blinded signature found under name

Definition at line 1687 of file json_helper.c.

1690{
1692 .parser = &parse_blinded_sig,
1693 .cleaner = &clean_blinded_sig,
1694 .field = field,
1695 .ptr = b_sig
1696 };
1697
1698 *b_sig = NULL;
1699 return ret;
1700}
static enum GNUNET_GenericReturnValue parse_blinded_sig(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a blinded signature.
Definition: json_helper.c:1579
static void clean_blinded_sig(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing blinded sig.
Definition: json_helper.c:1671

References clean_blinded_sig(), GNUNET_JSON_Specification::field, parse_blinded_sig(), and ret.

Here is the call graph for this function:

◆ parse_unblinded_sig()

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

Parse given JSON object to unblinded 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 1712 of file json_helper.c.

1715{
1716 struct GNUNET_CRYPTO_UnblindedSignature **target = spec->ptr;
1717 struct GNUNET_CRYPTO_UnblindedSignature *unblinded_sig;
1718 const char *cipher;
1719 struct GNUNET_JSON_Specification dspec[] = {
1720 GNUNET_JSON_spec_string ("cipher",
1721 &cipher),
1723 };
1724 const char *emsg;
1725 unsigned int eline;
1726
1727 (void) cls;
1728 if (GNUNET_OK !=
1729 GNUNET_JSON_parse (root,
1730 dspec,
1731 &emsg,
1732 &eline))
1733 {
1734 GNUNET_break_op (0);
1735 return GNUNET_SYSERR;
1736 }
1737 unblinded_sig = GNUNET_new (struct GNUNET_CRYPTO_UnblindedSignature);
1738 unblinded_sig->cipher = string_to_cipher (cipher);
1739 unblinded_sig->rc = 1;
1740 switch (unblinded_sig->cipher)
1741 {
1743 break;
1745 {
1746 struct GNUNET_JSON_Specification ispec[] = {
1748 "rsa_signature",
1749 &unblinded_sig->details.rsa_signature),
1751 };
1752
1753 if (GNUNET_OK !=
1754 GNUNET_JSON_parse (root,
1755 ispec,
1756 &emsg,
1757 &eline))
1758 {
1759 GNUNET_break_op (0);
1760 GNUNET_free (unblinded_sig);
1761 return GNUNET_SYSERR;
1762 }
1763 *target = unblinded_sig;
1764 return GNUNET_OK;
1765 }
1767 {
1768 struct GNUNET_JSON_Specification ispec[] = {
1769 GNUNET_JSON_spec_fixed_auto ("cs_signature_r",
1770 &unblinded_sig->details.cs_signature.
1771 r_point),
1772 GNUNET_JSON_spec_fixed_auto ("cs_signature_s",
1773 &unblinded_sig->details.cs_signature.
1774 s_scalar),
1776 };
1777
1778 if (GNUNET_OK !=
1779 GNUNET_JSON_parse (root,
1780 ispec,
1781 &emsg,
1782 &eline))
1783 {
1784 GNUNET_break_op (0);
1785 GNUNET_free (unblinded_sig);
1786 return GNUNET_SYSERR;
1787 }
1788 *target = unblinded_sig;
1789 return GNUNET_OK;
1790 }
1791 }
1792 GNUNET_break_op (0);
1793 GNUNET_free (unblinded_sig);
1794 return GNUNET_SYSERR;
1795}
Type of (unblinded) signatures.
struct GNUNET_CRYPTO_RsaSignature * rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
unsigned int rc
Reference counter.
union GNUNET_CRYPTO_UnblindedSignature::@14 details
Details, depending on cipher.
struct GNUNET_CRYPTO_CsSignature cs_signature
If we use GNUNET_CRYPTO_BSA_CS in cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the signature.

References GNUNET_CRYPTO_UnblindedSignature::cipher, GNUNET_JSON_Specification::cls, GNUNET_CRYPTO_UnblindedSignature::cs_signature, GNUNET_CRYPTO_UnblindedSignature::details, GNUNET_break_op, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_free, GNUNET_JSON_parse(), GNUNET_JSON_spec_end(), GNUNET_JSON_spec_fixed_auto, GNUNET_JSON_spec_rsa_signature(), GNUNET_JSON_spec_string(), GNUNET_new, GNUNET_OK, GNUNET_SYSERR, GNUNET_JSON_Specification::ptr, GNUNET_CRYPTO_UnblindedSignature::rc, GNUNET_CRYPTO_UnblindedSignature::rsa_signature, and string_to_cipher().

Referenced by GNUNET_JSON_spec_unblinded_signature().

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

◆ clean_unblinded_sig()

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

Cleanup data left from parsing unblinded signature.

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

Definition at line 1805 of file json_helper.c.

1807{
1808 struct GNUNET_CRYPTO_UnblindedSignature **ub_sig = spec->ptr;
1809
1810 (void) cls;
1811 if (NULL != *ub_sig)
1812 {
1814 *ub_sig = NULL;
1815 }
1816}
void GNUNET_CRYPTO_unblinded_sig_decref(struct GNUNET_CRYPTO_UnblindedSignature *ub_sig)
Decrement reference counter of a ub_sig, and free it if it reaches zero.

References GNUNET_CRYPTO_unblinded_sig_decref(), and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_JSON_spec_unblinded_signature().

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

◆ GNUNET_JSON_spec_unblinded_signature()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_unblinded_signature ( const char *  field,
struct GNUNET_CRYPTO_UnblindedSignature **  ub_sig 
)

Specification for parsing an unblinded signature.

Parameters
namename of the JSON field
sigwhere to store the unblinded signature found under name

Definition at line 1820 of file json_helper.c.

1823{
1825 .parser = &parse_unblinded_sig,
1826 .cleaner = &clean_unblinded_sig,
1827 .field = field,
1828 .ptr = ub_sig
1829 };
1830
1831 *ub_sig = NULL;
1832 return ret;
1833}
static void clean_unblinded_sig(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing unblinded signature.
Definition: json_helper.c:1805
static enum GNUNET_GenericReturnValue parse_unblinded_sig(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to unblinded signature.
Definition: json_helper.c:1712

References clean_unblinded_sig(), GNUNET_JSON_Specification::field, parse_unblinded_sig(), and ret.

Here is the call graph for this function: