GNUnet 0.21.2
gnunet_json_lib.h File Reference

functions to parse JSON objects into GNUnet objects More...

#include "gnunet_util_lib.h"
#include <jansson.h>
#include <microhttpd.h>
Include dependency graph for gnunet_json_lib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GNUNET_JSON_Specification
 Entry in parser specification for GNUNET_JSON_parse(). More...
 
struct  GNUNET_JSON_PackSpec
 Element in the array to give to the packer. More...
 

Macros

#define GNUNET_JSON_spec_fixed_auto(name, obj)    GNUNET_JSON_spec_fixed (name, obj, sizeof(*obj))
 Fixed size object (in network byte order, encoded using Crockford Base32hex encoding). More...
 
#define GNUNET_JSON_spec_fixed64_auto(name, obj)    GNUNET_JSON_spec_fixed (name, obj, sizeof(*obj))
 Fixed size object (in network byte order, encoded using base64 encoding). More...
 
#define GNUNET_JSON_from_data_auto(ptr)    GNUNET_JSON_from_data (ptr, sizeof(*ptr))
 Convert binary data to a JSON string with the base32crockford encoding. More...
 
#define GNUNET_JSON_from_data64_auto(ptr)    GNUNET_JSON_from_data64 (ptr, sizeof(*ptr))
 Convert binary data to a JSON string with base64 encoding. More...
 
#define GNUNET_JSON_PACK(...)
 Pack a JSON object from a spec. More...
 
#define GNUNET_JSON_pack_data_auto(name, blob)    GNUNET_JSON_pack_data_varsize (name, blob, sizeof (*blob))
 Generate packer instruction for a JSON field where the size is automatically determined from the argument. More...
 
#define GNUNET_JSON_pack_data64_auto(name, blob)    GNUNET_JSON_pack_data64_varsize (name, blob, sizeof (*blob))
 Generate packer instruction for a JSON field where the size is automatically determined from the argument. More...
 

Typedefs

typedef enum GNUNET_GenericReturnValue(* GNUNET_JSON_Parser) (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Function called to parse JSON argument. More...
 
typedef void(* GNUNET_JSON_Cleaner) (void *cls, struct GNUNET_JSON_Specification *spec)
 Function called to clean up data from earlier parsing. More...
 
typedef json_t *(* GNUNET_JSON_PackCallback) (const struct GNUNET_JSON_PackSpec *se)
 Function called to pack an element into the JSON object as part of GNUNET_JSON_pack_(). More...
 

Enumerations

enum  GNUNET_JSON_PostResult {
  GNUNET_JSON_PR_SUCCESS , GNUNET_JSON_PR_CONTINUE , GNUNET_JSON_PR_OUT_OF_MEMORY , GNUNET_JSON_PR_REQUEST_TOO_LARGE ,
  GNUNET_JSON_PR_JSON_INVALID
}
 Return codes from GNUNET_JSON_post_parser(). More...
 

Functions

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. More...
 
void GNUNET_JSON_parse_free (struct GNUNET_JSON_Specification *spec)
 Frees all elements allocated during a GNUNET_JSON_parse() operation. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_end (void)
 End of a parser specification. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_mark_optional (struct GNUNET_JSON_Specification spec, bool *missing)
 Set the "optional" flag for a parser specification entry. 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...
 
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...
 
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...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_string (const char *name, const char **strptr)
 The expected field stores a string. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_json (const char *name, json_t **jsonp)
 JSON object or array. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_object_const (const char *name, const json_t **jsonp)
 JSON object, reference counter not incremented. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_array_const (const char *name, const json_t **jsonp)
 JSON array, reference counter not incremented. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_bool (const char *name, bool *b)
 boolean. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_double (const char *name, double *f)
 double. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint8 (const char *name, uint8_t *u8)
 8-bit integer. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint16 (const char *name, uint16_t *u16)
 16-bit integer. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint32 (const char *name, uint32_t *u32)
 32-bit integer. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint64 (const char *name, uint64_t *u64)
 64-bit integer. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_int64 (const char *name, int64_t *i64)
 64-bit signed integer. 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...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp (const char *name, struct GNUNET_TIME_Timestamp *t)
 Timestamp. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp_nbo (const char *name, struct GNUNET_TIME_TimestampNBO *tn)
 Timestamp in network byte order. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_relative_time (const char *name, struct GNUNET_TIME_Relative *rt)
 Relative time. 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...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_signature (const char *name, struct GNUNET_CRYPTO_RsaSignature **sig)
 Specification for parsing an RSA signature. 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...
 
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...
 
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...
 
json_t * GNUNET_JSON_from_data (const void *data, size_t size)
 Convert binary data to a JSON string with the base32crockford encoding. More...
 
json_t * GNUNET_JSON_from_data64 (const void *data, size_t size)
 Convert binary data to a JSON string with base64 encoding. More...
 
json_t * GNUNET_JSON_from_timestamp (struct GNUNET_TIME_Timestamp stamp)
 Convert timestamp to a json string. More...
 
json_t * GNUNET_JSON_from_timestamp_nbo (struct GNUNET_TIME_TimestampNBO stamp)
 Convert timestamp to a json string. More...
 
json_t * GNUNET_JSON_from_time_rel (struct GNUNET_TIME_Relative stamp)
 Convert relative timestamp to a json string. More...
 
json_t * GNUNET_JSON_from_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *pk)
 Convert RSA public key to JSON. More...
 
json_t * GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig)
 Convert RSA signature to JSON. More...
 
enum GNUNET_JSON_PostResult GNUNET_JSON_post_parser (size_t buffer_max, struct MHD_Connection *connection, void **con_cls, const char *upload_data, size_t *upload_data_size, json_t **json)
 Process a POST request containing a JSON object. More...
 
void GNUNET_JSON_post_parser_cleanup (void *con_cls)
 Function called whenever we are done with a request to clean up our state. More...
 
struct GNUNET_GETOPT_CommandLineOption GNUNET_JSON_getopt (char shortName, const char *name, const char *argumentHelp, const char *description, json_t **json)
 Allow user to specify a JSON input value. More...
 
json_t * GNUNET_JSON_pack_ (struct GNUNET_JSON_PackSpec spec[])
 Pack a JSON object from a spec. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_end_ (void)
 Do not use directly. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_allow_null (struct GNUNET_JSON_PackSpec in)
 Modify packer instruction to allow NULL as a value. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_bool (const char *name, bool b)
 Generate packer instruction for a JSON field of type bool. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_double (const char *name, double f)
 Generate packer instruction for a JSON field of type double. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_string (const char *name, const char *s)
 Generate packer instruction for a JSON field of type string. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_uint64 (const char *name, uint64_t num)
 Generate packer instruction for a JSON field of type unsigned integer. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_int64 (const char *name, int64_t num)
 Generate packer instruction for a JSON field of type signed integer. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_object_steal (const char *name, json_t *o)
 Generate packer instruction for a JSON field of type JSON object where the reference is taken over by the packer. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_object_incref (const char *name, json_t *o)
 Generate packer instruction for a JSON field of type JSON object where the reference counter is incremented by the packer. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_array_steal (const char *name, json_t *a)
 Generate packer instruction for a JSON field of type JSON array where the reference is taken over by the packer. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_array_incref (const char *name, json_t *a)
 Generate packer instruction for a JSON field of type JSON array where the reference counter is incremented by the packer. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_data_varsize (const char *name, const void *blob, size_t blob_size)
 Generate packer instruction for a JSON field of type variable size binary blob. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_data64_varsize (const char *name, const void *blob, size_t blob_size)
 Generate packer instruction for a JSON field of type variable size binary blob. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_timestamp (const char *name, struct GNUNET_TIME_Timestamp at)
 Generate packer instruction for a JSON field of type timestamp. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_timestamp_nbo (const char *name, struct GNUNET_TIME_TimestampNBO at)
 Generate packer instruction for a JSON field of type timestamp in network byte order. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rel (const char *name, struct GNUNET_TIME_Relative rt)
 Generate packer instruction for a JSON field of type relative time. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rel_nbo (const char *name, struct GNUNET_TIME_RelativeNBO rt)
 Generate packer instruction for a JSON field of type relative time in network byte order. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_rsa_public_key (const char *name, const struct GNUNET_CRYPTO_RsaPublicKey *pk)
 Generate packer instruction for a JSON field of type RSA public key. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_rsa_signature (const char *name, const struct GNUNET_CRYPTO_RsaSignature *sig)
 Generate packer instruction for a JSON field of type RSA signature. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_unblinded_signature (const char *name, const struct GNUNET_CRYPTO_UnblindedSignature *sig)
 Generate packer instruction for a JSON field of type unblinded signature. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_blinded_message (const char *name, const struct GNUNET_CRYPTO_BlindedMessage *msg)
 Generate packer instruction for a JSON field of type blinded message. More...
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_blinded_sig (const char *name, const struct GNUNET_CRYPTO_BlindedSignature *sig)
 Generate packer instruction for a JSON field of type blinded signature. More...
 

Detailed Description

functions to parse JSON objects into GNUnet objects

Author
Florian Dold
Benedikt Mueller
Christian Grothoff

Definition in file gnunet_json_lib.h.

Macro Definition Documentation

◆ GNUNET_JSON_spec_fixed_auto

#define GNUNET_JSON_spec_fixed_auto (   name,
  obj 
)     GNUNET_JSON_spec_fixed (name, obj, sizeof(*obj))

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

Parameters
namename of the JSON field
objpointer where to write the data (type of *obj will determine size)

Definition at line 202 of file gnunet_json_lib.h.

◆ GNUNET_JSON_spec_fixed64_auto

#define GNUNET_JSON_spec_fixed64_auto (   name,
  obj 
)     GNUNET_JSON_spec_fixed (name, obj, sizeof(*obj))

Fixed size object (in network byte order, encoded using base64 encoding).

Parameters
namename of the JSON field
objpointer where to write the data (type of *obj will determine size)

Definition at line 225 of file gnunet_json_lib.h.

◆ GNUNET_JSON_from_data_auto

#define GNUNET_JSON_from_data_auto (   ptr)     GNUNET_JSON_from_data (ptr, sizeof(*ptr))

Convert binary data to a JSON string with the base32crockford encoding.

Parameters
ptrbinary data, sizeof (*ptr) must yield correct size
Returns
json string that encodes data

Definition at line 502 of file gnunet_json_lib.h.

◆ GNUNET_JSON_from_data64_auto

#define GNUNET_JSON_from_data64_auto (   ptr)     GNUNET_JSON_from_data64 (ptr, sizeof(*ptr))

Convert binary data to a JSON string with base64 encoding.

Parameters
ptrbinary data, sizeof (*ptr) must yield correct size
Returns
json string that encodes data

Definition at line 513 of file gnunet_json_lib.h.

◆ GNUNET_JSON_PACK

#define GNUNET_JSON_PACK (   ...)
Value:
GNUNET_JSON_pack_ ((struct GNUNET_JSON_PackSpec[]) {__VA_ARGS__, \
GNUNET_JSON_pack_end_ ()})
json_t * GNUNET_JSON_pack_(struct GNUNET_JSON_PackSpec spec[])
Pack a JSON object from a spec.
Definition: json_pack.c:29
Element in the array to give to the packer.

Pack a JSON object from a spec.

Aborts if packing fails.

Parameters
...list of specification objects
Returns
JSON object

Definition at line 718 of file gnunet_json_lib.h.

◆ GNUNET_JSON_pack_data_auto

#define GNUNET_JSON_pack_data_auto (   name,
  blob 
)     GNUNET_JSON_pack_data_varsize (name, blob, sizeof (*blob))

Generate packer instruction for a JSON field where the size is automatically determined from the argument.

Parameters
namename of the field to add to the object
blobdata to pack, must not be an array
Returns
json pack specification

Definition at line 887 of file gnunet_json_lib.h.

◆ GNUNET_JSON_pack_data64_auto

#define GNUNET_JSON_pack_data64_auto (   name,
  blob 
)     GNUNET_JSON_pack_data64_varsize (name, blob, sizeof (*blob))

Generate packer instruction for a JSON field where the size is automatically determined from the argument.

Use base64-encoding, instead of the more common Crockford base32-encoding.

Parameters
namename of the field to add to the object
blobdata to pack, must not be an array
Returns
json pack specification

Definition at line 918 of file gnunet_json_lib.h.

Typedef Documentation

◆ GNUNET_JSON_Parser

typedef enum GNUNET_GenericReturnValue(* GNUNET_JSON_Parser) (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)

Function called to parse JSON argument.

Parameters
clsclosure
rootJSON to parse
specour specification entry with further details
Returns
GNUNET_SYSERR on error, GNUNET_OK on success

Definition at line 1 of file gnunet_json_lib.h.

◆ GNUNET_JSON_Cleaner

typedef void(* GNUNET_JSON_Cleaner) (void *cls, struct GNUNET_JSON_Specification *spec)

Function called to clean up data from earlier parsing.

Parameters
clsclosure
specour specification entry with data to clean.

Definition at line 64 of file gnunet_json_lib.h.

◆ GNUNET_JSON_PackCallback

typedef json_t *(* GNUNET_JSON_PackCallback) (const struct GNUNET_JSON_PackSpec *se)

Function called to pack an element into the JSON object as part of GNUNET_JSON_pack_().

Parameters
sepack specification to execute
Returns
json object to pack, NULL to pack nothing

Definition at line 671 of file gnunet_json_lib.h.

Enumeration Type Documentation

◆ GNUNET_JSON_PostResult

Return codes from GNUNET_JSON_post_parser().

Enumerator
GNUNET_JSON_PR_SUCCESS 

Parsing successful, JSON result is in *json.

GNUNET_JSON_PR_CONTINUE 

Parsing continues, call again soon!

GNUNET_JSON_PR_OUT_OF_MEMORY 

Sorry, memory allocation (malloc()) failed.

GNUNET_JSON_PR_REQUEST_TOO_LARGE 

Request size exceeded buffer_max argument.

GNUNET_JSON_PR_JSON_INVALID 

JSON parsing failed.

This was not a JSON upload.

Definition at line 571 of file gnunet_json_lib.h.

572{
577
582
587
592
597};
@ GNUNET_JSON_PR_CONTINUE
Parsing continues, call again soon!
@ GNUNET_JSON_PR_OUT_OF_MEMORY
Sorry, memory allocation (malloc()) failed.
@ GNUNET_JSON_PR_JSON_INVALID
JSON parsing failed.
@ GNUNET_JSON_PR_REQUEST_TOO_LARGE
Request size exceeded buffer_max argument.
@ GNUNET_JSON_PR_SUCCESS
Parsing successful, JSON result is in *json.

Function Documentation

◆ GNUNET_JSON_parse()

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.

Tries to parse the root to find all of the values given in the spec. If one of the entries in spec cannot be found or parsed, the name of the JSON field is returned in error_json_name, and the offset of the entry in spec is returned in error_line.

Parameters
rootthe JSON node to start the navigation at.
specparse specification array
[out]error_json_namewhich JSON field was problematic
[out]error_linewhich index into spec did we encounter an error
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 32 of file json.c.

36{
37 if (NULL == root)
38 return GNUNET_SYSERR;
39 for (unsigned int i = 0; NULL != spec[i].parser; i++)
40 {
41 json_t *pos;
42
43 if (NULL == spec[i].field)
44 pos = (json_t *) root;
45 else
46 pos = json_object_get (root,
47 spec[i].field);
48 if ( ( (NULL == pos) ||
49 (json_is_null (pos) ) ) &&
50 (spec[i].is_optional) )
51 {
52 if (NULL != spec[i].missing)
53 *spec[i].missing = true;
54 continue;
55 }
56 if ( (NULL == pos) ||
57 (GNUNET_OK !=
58 spec[i].parser (spec[i].cls,
59 pos,
60 &spec[i])) )
61 {
62 if (NULL != error_json_name)
63 *error_json_name = spec[i].field;
64 else
66 "Parsing failed for field `%s:%u`\n",
67 spec[i].field,
68 i);
69 if (NULL != error_line)
70 *error_line = i;
72 return GNUNET_SYSERR;
73 }
74 if (NULL != spec[i].missing)
75 *spec[i].missing = false;
76 }
77 return GNUNET_OK; /* all OK! */
78}
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_WARNING
void GNUNET_JSON_parse_free(struct GNUNET_JSON_Specification *spec)
Frees all elements allocated during a GNUNET_JSON_parse() operation.
Definition: json.c:94
bool * missing
Pointer to set to true if this argument is indeed missing.
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...
GNUNET_JSON_Parser parser
Function for how to parse this type of entry.

References GNUNET_JSON_Specification::field, GNUNET_ERROR_TYPE_WARNING, GNUNET_JSON_parse_free(), GNUNET_log, GNUNET_OK, GNUNET_SYSERR, GNUNET_JSON_Specification::missing, consensus-simulation::parser, and GNUNET_JSON_Specification::parser.

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 call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_parse_free()

void GNUNET_JSON_parse_free ( struct GNUNET_JSON_Specification spec)

Frees all elements allocated during a GNUNET_JSON_parse() operation.

Convenience function to be called if cleaning up all heap-allocated data from a GNUNET_JSON_parse() is desired. The function does not have to be called if no data was heap-allocated (e.g. only integers, strings and fixed-sized data was used), or if the application calls the respective code to free the heap (not always GNUNET_free(), depends on the data type!) on the returned heap-allocated data itself.

Parameters
specspecification of the parse operation

Definition at line 94 of file json.c.

95{
96 for (unsigned int i = 0; NULL != spec[i].parser; i++)
97 if (NULL != spec[i].cleaner)
98 spec[i].cleaner (spec[i].cls,
99 &spec[i]);
100}
GNUNET_JSON_Cleaner cleaner
Function for how to clean up this type of entry.

References GNUNET_JSON_Specification::cleaner, GNUNET_JSON_Specification::cls, and GNUNET_JSON_Specification::parser.

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

Here is the caller graph for this function:

◆ 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 .cleaner = NULL,
38 .cls = NULL
39 };
40
41 return ret;
42}
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(), parse_blinded_message(), parse_blinded_sig(), parse_unblinded_sig(), and revoke_ticket_cont().

Here is the caller graph for this function:

◆ GNUNET_JSON_spec_mark_optional()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_mark_optional ( struct GNUNET_JSON_Specification  spec,
bool *  missing 
)

Set the "optional" flag for a parser specification entry.

Parameters
specspecification to modify
[out]missingset to true if the argument is missing, NULL is allowed.
Returns
spec copy of spec with optional bit set

Definition at line 82 of file json.c.

84{
85 struct GNUNET_JSON_Specification ret = spec;
86
87 ret.is_optional = true;
88 ret.missing = missing;
89 return ret;
90}

References GNUNET_JSON_Specification::missing, and ret.

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

120{
122 .parser = &parse_fixed_data,
123 .cleaner = NULL,
124 .cls = NULL,
125 .field = name,
126 .ptr = obj,
127 .ptr_size = size,
128 .size_ptr = NULL
129 };
130
131 return ret;
132}
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:77
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:

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

184{
186 .parser = &parse_fixed64_data,
187 .cleaner = NULL,
188 .cls = NULL,
189 .field = name,
190 .ptr = obj,
191 .ptr_size = size,
192 .size_ptr = NULL
193 };
194
195 return ret;
196}
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:144

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

Here is the call 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 258 of file json_helper.c.

261{
263 .parser = &parse_variable_data,
264 .cleaner = &clean_variable_data,
265 .cls = NULL,
266 .field = name,
267 .ptr = obj,
268 .ptr_size = 0,
269 .size_ptr = size
270 };
271
272 *obj = NULL;
273 *size = 0;
274 return ret;
275}
static void clean_variable_data(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing variable size data.
Definition: json_helper.c:244
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:208

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:

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

308{
310 .parser = &parse_string,
311 .field = name,
312 .ptr = strptr
313 };
314
315 *strptr = NULL;
316 return ret;
317}
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:287

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:

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

367{
369 .parser = &parse_json,
370 .cleaner = &clean_json,
371 .cls = NULL,
372 .field = name,
373 .ptr = jsonp,
374 .ptr_size = 0,
375 .size_ptr = NULL
376 };
377
378 *jsonp = NULL;
379 return ret;
380}
static void clean_json(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing JSON object.
Definition: json_helper.c:351
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:329

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

Here is the call 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 409 of file json_helper.c.

411{
413 .parser = &parse_object_const,
414 .cls = NULL,
415 .field = name,
416 .ptr = jsonp,
417 .ptr_size = 0,
418 .size_ptr = NULL
419 };
420
421 *jsonp = NULL;
422 return ret;
423}
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:392

References name, parse_object_const(), and ret.

Here is the call 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 452 of file json_helper.c.

454{
456 .parser = &parse_array_const,
457 .cls = NULL,
458 .field = name,
459 .ptr = jsonp,
460 .ptr_size = 0,
461 .size_ptr = NULL
462 };
463
464 *jsonp = NULL;
465 return ret;
466}
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:435

References name, parse_array_const(), and ret.

Here is the call 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 500 of file json_helper.c.

502{
504 .parser = &parse_bool,
505 .cleaner = NULL,
506 .cls = NULL,
507 .field = name,
508 .ptr = b,
509 .ptr_size = sizeof(bool),
510 .size_ptr = NULL
511 };
512
513 return ret;
514}
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:478
size_t * size_ptr
Where should we store the final size of ptr.

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

Here is the call 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 543 of file json_helper.c.

545{
547 .parser = &parse_double,
548 .cleaner = NULL,
549 .cls = NULL,
550 .field = name,
551 .ptr = f,
552 .ptr_size = sizeof(double),
553 .size_ptr = NULL
554 };
555
556 return ret;
557}
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:526

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

Here is the call 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 593 of file json_helper.c.

595{
597 .parser = &parse_u8,
598 .cleaner = NULL,
599 .cls = NULL,
600 .field = name,
601 .ptr = u8,
602 .ptr_size = sizeof(uint8_t),
603 .size_ptr = NULL
604 };
605
606 return ret;
607}
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:569

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

Here is the call 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 643 of file json_helper.c.

645{
647 .parser = &parse_u16,
648 .cleaner = NULL,
649 .cls = NULL,
650 .field = name,
651 .ptr = u16,
652 .ptr_size = sizeof(uint16_t),
653 .size_ptr = NULL
654 };
655
656 return ret;
657}
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:619

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

Here is the call 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 693 of file json_helper.c.

695{
697 .parser = &parse_u32,
698 .cleaner = NULL,
699 .cls = NULL,
700 .field = name,
701 .ptr = u32,
702 .ptr_size = sizeof(uint32_t),
703 .size_ptr = NULL
704 };
705
706 return ret;
707}
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:669

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

Referenced by parse_blinded_sig().

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

740{
742 .parser = &parse_u64,
743 .cleaner = NULL,
744 .cls = NULL,
745 .field = name,
746 .ptr = u64,
747 .ptr_size = sizeof(uint64_t),
748 .size_ptr = NULL
749 };
750
751 return ret;
752}
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:719

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

Here is the call 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 783 of file json_helper.c.

785{
787 .parser = &parse_i64,
788 .cleaner = NULL,
789 .cls = NULL,
790 .field = name,
791 .ptr = i64,
792 .ptr_size = sizeof(int64_t),
793 .size_ptr = NULL
794 };
795
796 return ret;
797}
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:764

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

Here is the call 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 1190 of file json_helper.c.

1192{
1194 .parser = &parse_boolean,
1195 .cleaner = NULL,
1196 .cls = NULL,
1197 .field = name,
1198 .ptr = boolean,
1199 .ptr_size = sizeof(int),
1200 .size_ptr = NULL
1201 };
1202
1203 return ret;
1204}
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:1173

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

Here is the call 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 862 of file json_helper.c.

864{
866 .parser = &parse_timestamp,
867 .field = name,
868 .ptr = t,
869 .ptr_size = sizeof(struct GNUNET_TIME_Timestamp)
870 };
871
872 return ret;
873}
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:811
Rounded time for timestamps used by GNUnet, in seconds.

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

Here is the call 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 907 of file json_helper.c.

909{
911 .parser = &parse_timestamp_nbo,
912 .field = name,
913 .ptr = at,
914 .ptr_size = sizeof(struct GNUNET_TIME_TimestampNBO)
915 };
916
917 return ret;
918}
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:885
Time for timestamps used by GNUnet, in seconds and in network byte order.

References name, parse_timestamp_nbo(), and ret.

Here is the call 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 977 of file json_helper.c.

979{
981 .parser = &parse_rel_time,
982 .field = name,
983 .ptr = rt,
984 .ptr_size = sizeof(struct GNUNET_TIME_Relative)
985 };
986
987 return ret;
988}
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:930
Time for relative time used by GNUnet, in microseconds.

References name, parse_rel_time(), and ret.

Here is the call 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 1061 of file json_helper.c.

1063{
1065 .parser = &parse_rsa_public_key,
1066 .cleaner = &clean_rsa_public_key,
1067 .field = name,
1068 .ptr = pk
1069 };
1070
1071 *pk = NULL;
1072 return ret;
1073}
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
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:1047
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:1000

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

Here is the call 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 1146 of file json_helper.c.

1148{
1150 .parser = &parse_rsa_signature,
1151 .cleaner = &clean_rsa_signature,
1152 .cls = NULL,
1153 .field = name,
1154 .ptr = sig,
1155 .ptr_size = 0,
1156 .size_ptr = NULL
1157 };
1158
1159 *sig = NULL;
1160 return ret;
1161}
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:1085
static void clean_rsa_signature(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA signature.
Definition: json_helper.c:1132

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:

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

1331{
1333 .parser = &parse_blinded_message,
1334 .cleaner = &clean_blinded_message,
1335 .cls = NULL,
1336 .field = name,
1337 .ptr = msg,
1338 .ptr_size = 0,
1339 .size_ptr = NULL
1340 };
1341
1342 *msg = NULL;
1343 return ret;
1344}
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:1216
static void clean_blinded_message(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing blinded message.
Definition: json_helper.c:1314

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

Here is the call 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 1464 of file json_helper.c.

1466{
1468 .parser = &parse_blinded_sig,
1469 .cleaner = &clean_blinded_sig,
1470 .field = field,
1471 .ptr = b_sig
1472 };
1473
1474 *b_sig = NULL;
1475 return ret;
1476}
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:1356
static void clean_blinded_sig(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing blinded sig.
Definition: json_helper.c:1448

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

Here is the call 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 1595 of file json_helper.c.

1597{
1599 .parser = &parse_unblinded_sig,
1600 .cleaner = &clean_unblinded_sig,
1601 .field = field,
1602 .ptr = ub_sig
1603 };
1604
1605 *ub_sig = NULL;
1606 return ret;
1607}
static void clean_unblinded_sig(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing unblinded signature.
Definition: json_helper.c:1580
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:1487

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

Here is the call graph for this function:

◆ GNUNET_JSON_from_data()

json_t * GNUNET_JSON_from_data ( const void *  data,
size_t  size 
)

Convert binary data to a JSON string with the base32crockford encoding.

Parameters
databinary data
sizesize of data in bytes
Returns
json string that encodes data

Definition at line 31 of file json_generator.c.

33{
34 char *buf;
35 json_t *json;
36
37 if (size >= ( (GNUNET_MAX_MALLOC_CHECKED - 1) * 5) - 4 / 8)
38 {
39 GNUNET_break (0);
40 return NULL;
41 }
43 size);
44 json = json_string (buf);
45 GNUNET_free (buf);
46 GNUNET_break (NULL != json);
47 return json;
48}
static char * data
The data to insert into the dht.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_MAX_MALLOC_CHECKED
Maximum allocation with GNUNET_malloc macro.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:764

References data, GNUNET_break, GNUNET_free, GNUNET_MAX_MALLOC_CHECKED, GNUNET_STRINGS_data_to_string_alloc(), and size.

Referenced by GNUNET_JSON_from_rsa_public_key(), GNUNET_JSON_from_rsa_signature(), and GNUNET_JSON_pack_data_varsize().

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

◆ GNUNET_JSON_from_data64()

json_t * GNUNET_JSON_from_data64 ( const void *  data,
size_t  size 
)

Convert binary data to a JSON string with base64 encoding.

Parameters
databinary data
sizesize of data in bytes
Returns
json string that encodes data

Definition at line 52 of file json_generator.c.

54{
55 char *buf = NULL;
56 json_t *json;
57 size_t len;
58
59 if (size >= ( ( (GNUNET_MAX_MALLOC_CHECKED - 1) * 6) - 5) / 8)
60 {
61 GNUNET_break (0);
62 return NULL;
63 }
65 size,
66 &buf);
67 if (NULL == buf)
68 {
69 GNUNET_break (0);
70 return NULL;
71 }
72 json = json_stringn (buf,
73 len);
74 GNUNET_free (buf);
75 GNUNET_break (NULL != json);
76 return json;
77}
size_t GNUNET_STRINGS_base64_encode(const void *in, size_t len, char **output)
Encode into Base64.
Definition: strings.c:1622

References data, GNUNET_break, GNUNET_free, GNUNET_MAX_MALLOC_CHECKED, GNUNET_STRINGS_base64_encode(), and size.

Referenced by GNUNET_JSON_pack_data64_varsize().

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

◆ GNUNET_JSON_from_timestamp()

json_t * GNUNET_JSON_from_timestamp ( struct GNUNET_TIME_Timestamp  stamp)

Convert timestamp to a json string.

Parameters
stampthe time stamp
Returns
a json string with the timestamp in stamp

Definition at line 81 of file json_generator.c.

82{
83 json_t *j;
84
85 j = json_object ();
86 if (NULL == j)
87 {
88 GNUNET_break (0);
89 return NULL;
90 }
92 {
93 if (0 !=
94 json_object_set_new (j,
95 "t_s",
96 json_string ("never")))
97 {
98 GNUNET_break (0);
99 json_decref (j);
100 return NULL;
101 }
102 return j;
103 }
105 0 ==
107 % GNUNET_TIME_UNIT_SECONDS.rel_value_us));
108 if (0 !=
109 json_object_set_new (
110 j,
111 "t_s",
112 json_integer (
113 (json_int_t) (stamp.abs_time.abs_value_us
114 / GNUNET_TIME_UNIT_SECONDS.rel_value_us))))
115 {
116 GNUNET_break (0);
117 json_decref (j);
118 return NULL;
119 }
120 return j;
121}
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_TIME_UNIT_SECONDS
One second.
bool GNUNET_TIME_absolute_is_never(struct GNUNET_TIME_Absolute abs)
Test if abs is never.
Definition: time.c:648
uint64_t abs_value_us
The actual value.
struct GNUNET_TIME_Absolute abs_time
The actual value.

References GNUNET_TIME_Timestamp::abs_time, GNUNET_TIME_Absolute::abs_value_us, GNUNET_assert, GNUNET_break, GNUNET_TIME_absolute_is_never(), and GNUNET_TIME_UNIT_SECONDS.

Referenced by GNUNET_JSON_from_timestamp_nbo(), and GNUNET_JSON_pack_timestamp().

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

◆ GNUNET_JSON_from_timestamp_nbo()

json_t * GNUNET_JSON_from_timestamp_nbo ( struct GNUNET_TIME_TimestampNBO  stamp)

Convert timestamp to a json string.

Parameters
stampthe time stamp
Returns
a json string with the timestamp in stamp

Definition at line 125 of file json_generator.c.

126{
128}
struct GNUNET_TIME_Timestamp GNUNET_TIME_timestamp_ntoh(struct GNUNET_TIME_TimestampNBO tn)
Convert timestamp from network byte order.
Definition: time.c:101
json_t * GNUNET_JSON_from_timestamp(struct GNUNET_TIME_Timestamp stamp)
Convert timestamp to a json string.

References GNUNET_JSON_from_timestamp(), and GNUNET_TIME_timestamp_ntoh().

Here is the call graph for this function:

◆ GNUNET_JSON_from_time_rel()

json_t * GNUNET_JSON_from_time_rel ( struct GNUNET_TIME_Relative  stamp)

Convert relative timestamp to a json string.

Parameters
stampthe time stamp
Returns
a json string with the timestamp in stamp

Definition at line 132 of file json_generator.c.

133{
134 json_t *j;
135
136 j = json_object ();
137 if (NULL == j)
138 {
139 GNUNET_break (0);
140 return NULL;
141 }
143 {
144 if (0 !=
145 json_object_set_new (j,
146 "d_us",
147 json_string ("forever")))
148 {
149 GNUNET_break (0);
150 json_decref (j);
151 return NULL;
152 }
153 return j;
154 }
155 if (stamp.rel_value_us >= (1LLU << 53))
156 {
157 /* value is larger than allowed */
158 GNUNET_break (0);
159 return NULL;
160 }
161 if (0 !=
162 json_object_set_new (
163 j,
164 "d_us",
165 json_integer ((json_int_t) stamp.rel_value_us)))
166 {
167 GNUNET_break (0);
168 json_decref (j);
169 return NULL;
170 }
171 return j;
172}
bool GNUNET_TIME_relative_is_forever(struct GNUNET_TIME_Relative rel)
Test if rel is forever.
Definition: time.c:655
uint64_t rel_value_us
The actual value.

References GNUNET_break, GNUNET_TIME_relative_is_forever(), and GNUNET_TIME_Relative::rel_value_us.

Referenced by GNUNET_JSON_pack_time_rel().

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

◆ GNUNET_JSON_from_rsa_public_key()

json_t * GNUNET_JSON_from_rsa_public_key ( const struct GNUNET_CRYPTO_RsaPublicKey pk)

Convert RSA public key to JSON.

Parameters
pkpublic key to convert
Returns
corresponding JSON encoding

Definition at line 176 of file json_generator.c.

177{
178 void *buf;
179 size_t buf_len;
180 json_t *ret;
181
183 &buf);
185 buf_len);
186 GNUNET_free (buf);
187 return ret;
188}
size_t GNUNET_CRYPTO_rsa_public_key_encode(const struct GNUNET_CRYPTO_RsaPublicKey *key, void **buffer)
Encode the public key in a format suitable for storing it into a file.
Definition: crypto_rsa.c:325
json_t * GNUNET_JSON_from_data(const void *data, size_t size)
Convert binary data to a JSON string with the base32crockford encoding.

References GNUNET_CRYPTO_rsa_public_key_encode(), GNUNET_free, GNUNET_JSON_from_data(), pk, and ret.

Referenced by GNUNET_JSON_pack_rsa_public_key().

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

◆ GNUNET_JSON_from_rsa_signature()

json_t * GNUNET_JSON_from_rsa_signature ( const struct GNUNET_CRYPTO_RsaSignature sig)

Convert RSA signature to JSON.

Parameters
sigsignature to convert
Returns
corresponding JSON encoding

Definition at line 192 of file json_generator.c.

193{
194 void *buf;
195 size_t buf_len;
196 json_t *ret;
197
199 &buf);
201 buf_len);
202 GNUNET_free (buf);
203 return ret;
204}
size_t GNUNET_CRYPTO_rsa_signature_encode(const struct GNUNET_CRYPTO_RsaSignature *sig, void **buffer)
Encode the given signature in a format suitable for storing it into a file.
Definition: crypto_rsa.c:1023

References GNUNET_CRYPTO_rsa_signature_encode(), GNUNET_free, GNUNET_JSON_from_data(), and ret.

Referenced by GNUNET_JSON_pack_rsa_signature().

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

◆ GNUNET_JSON_post_parser()

enum GNUNET_JSON_PostResult GNUNET_JSON_post_parser ( size_t  buffer_max,
struct MHD_Connection *  connection,
void **  con_cls,
const char *  upload_data,
size_t *  upload_data_size,
json_t **  json 
)

Process a POST request containing a JSON object.

This function realizes an MHD POST processor that will (incrementally) process JSON data uploaded to the HTTP server. It will store the required state in the con_cls, which must be cleaned up using #GNUNET_JSON_post_parser_callback().

Parameters
buffer_maxmaximum allowed size for the buffer
connectionMHD connection handle (for meta data about the upload)
con_clsthe closure (will point to a struct Buffer *)
upload_datathe POST data
upload_data_sizenumber of bytes in upload_data
jsonthe JSON object for a completed request
Returns
result code indicating the status of the operation

Definition at line 265 of file json_mhd.c.

271{
272 struct Buffer *r = *con_cls;
273 const char *ce;
274 int ret;
275
276 *json = NULL;
277 if (NULL == *con_cls)
278 {
279 /* We are seeing a fresh POST request. */
280 r = GNUNET_new (struct Buffer);
281 if (GNUNET_OK != buffer_init (r,
282 upload_data,
283 *upload_data_size,
285 buffer_max))
286 {
287 *con_cls = NULL;
288 buffer_deinit (r);
289 GNUNET_free (r);
291 }
292 /* everything OK, wait for more POST data */
293 *upload_data_size = 0;
294 *con_cls = r;
296 }
297 if (0 != *upload_data_size)
298 {
299 /* We are seeing an old request with more data available. */
300
301 if (GNUNET_OK !=
302 buffer_append (r, upload_data, *upload_data_size, buffer_max))
303 {
304 /* Request too long */
305 *con_cls = NULL;
306 buffer_deinit (r);
307 GNUNET_free (r);
309 }
310 /* everything OK, wait for more POST data */
311 *upload_data_size = 0;
313 }
314
315 /* We have seen the whole request. */
316 ce = MHD_lookup_connection_value (connection,
317 MHD_HEADER_KIND,
318 MHD_HTTP_HEADER_CONTENT_ENCODING);
319 if ((NULL != ce) && (0 == strcasecmp ("deflate", ce)))
320 {
321 ret = inflate_data (r);
323 {
324 buffer_deinit (r);
325 GNUNET_free (r);
326 *con_cls = NULL;
327 return ret;
328 }
329 }
330
331 {
332 json_error_t err;
333
334 *json = json_loadb (r->data,
335 r->fill,
336 0,
337 &err);
338 if (NULL == *json)
339 {
341 "Failed to parse JSON request body of %u byte at offset %d: %s\n",
342 (unsigned int) r->fill,
343 err.position,
344 err.text);
345 buffer_deinit (r);
346 GNUNET_free (r);
347 *con_cls = NULL;
349 }
350 }
351 buffer_deinit (r);
352 GNUNET_free (r);
353 *con_cls = NULL;
354
356}
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int buffer_init(struct Buffer *buf, const void *data, size_t data_size, size_t alloc_size, size_t max_size)
Initialize a buffer.
Definition: json_mhd.c:78
#define REQUEST_BUFFER_INITIAL
Initial size for POST request buffers.
Definition: json_mhd.c:37
static enum GNUNET_JSON_PostResult inflate_data(struct Buffer *buf)
Decompress data in buf.
Definition: json_mhd.c:156
static void buffer_deinit(struct Buffer *buf)
Free the data in a buffer.
Definition: json_mhd.c:104
static int buffer_append(struct Buffer *buf, const void *data, size_t data_size, size_t max_size)
Append data to a buffer, growing the buffer if necessary.
Definition: json_mhd.c:122
Buffer for POST requests.
Definition: json_mhd.c:44
size_t fill
Number of valid bytes in buffer.
Definition: json_mhd.c:53
char * data
Allocated memory.
Definition: json_mhd.c:48

References buffer_append(), buffer_deinit(), buffer_init(), Buffer::data, Buffer::fill, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_JSON_PR_CONTINUE, GNUNET_JSON_PR_JSON_INVALID, GNUNET_JSON_PR_OUT_OF_MEMORY, GNUNET_JSON_PR_REQUEST_TOO_LARGE, GNUNET_JSON_PR_SUCCESS, GNUNET_log, GNUNET_new, GNUNET_OK, inflate_data(), REQUEST_BUFFER_INITIAL, and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_post_parser_cleanup()

void GNUNET_JSON_post_parser_cleanup ( void *  con_cls)

Function called whenever we are done with a request to clean up our state.

Parameters
con_clsvalue as it was left by GNUNET_JSON_post_parser(), to be cleaned up

Definition at line 367 of file json_mhd.c.

368{
369 struct Buffer *r = con_cls;
370
371 if (NULL != r)
372 {
373 buffer_deinit (r);
374 GNUNET_free (r);
375 }
376}

References buffer_deinit(), and GNUNET_free.

Here is the call graph for this function:

◆ GNUNET_JSON_getopt()

struct GNUNET_GETOPT_CommandLineOption GNUNET_JSON_getopt ( char  shortName,
const char *  name,
const char *  argumentHelp,
const char *  description,
json_t **  json 
)

Allow user to specify a JSON input value.

Parameters
shortNameshort name of the option
namelong name of the option
argumentHelphelp text for the option argument
descriptionlong help text for the option
[out]valset to the JSON specified at the command line

Definition at line 141 of file json.c.

146{
149 .name = name,
150 .argumentHelp = argumentHelp,
151 .description = description,
152 .require_argument = 1,
153 .processor = &set_json,
154 .scls = (void *) json
155 };
156
157 return clo;
158}
static enum GNUNET_GenericReturnValue set_json(struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, void *scls, const char *option, const char *value)
Set an option with a JSON value from the command line.
Definition: json.c:116
Definition of a command line option.
const char * description
Help text for the option (description)
const char * argumentHelp
Name of the argument for the user in help text.
const char shortName
Short name of the option.

References GNUNET_GETOPT_CommandLineOption::argumentHelp, GNUNET_GETOPT_CommandLineOption::description, name, set_json(), and GNUNET_GETOPT_CommandLineOption::shortName.

Here is the call graph for this function:

◆ GNUNET_JSON_pack_()

json_t * GNUNET_JSON_pack_ ( struct GNUNET_JSON_PackSpec  spec[])

Pack a JSON object from a spec.

Aborts if packing fails.

Parameters
specspecification object
Returns
JSON object

Definition at line 29 of file json_pack.c.

30{
31 json_t *ret;
32
33 if (NULL == spec[0].field_name)
34 {
35 ret = spec[0].object;
36 spec[0].object = NULL;
37 return ret;
38 }
39 ret = json_object ();
40 GNUNET_assert (NULL != ret);
41 for (unsigned int i = 0;
42 NULL != spec[i].field_name;
43 i++)
44 {
45 if (NULL == spec[i].object)
46 {
47 if (! spec[i].allow_null)
48 {
50 "NULL not allowed for `%s'\n",
51 spec[i].field_name);
52 GNUNET_assert (0);
53 }
54 }
55 else
56 {
57 GNUNET_assert (0 ==
58 json_object_set_new (ret,
59 spec[i].field_name,
60 spec[i].object));
61 spec[i].object = NULL;
62 }
63 }
64 return ret;
65}
@ GNUNET_ERROR_TYPE_ERROR
json_t * object
Object to pack.
const char * field_name
Name of the field to pack.

References GNUNET_JSON_PackSpec::field_name, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_JSON_PackSpec::object, and ret.

◆ GNUNET_JSON_pack_end_()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_end_ ( void  )

Do not use directly.

Use GNUNET_JSON_PACK.

Returns
array terminator

Definition at line 69 of file json_pack.c.

70{
71 struct GNUNET_JSON_PackSpec ps = {
72 .field_name = NULL
73 };
74
75 return ps;
76}
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.

References ps.

◆ GNUNET_JSON_pack_allow_null()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_allow_null ( struct GNUNET_JSON_PackSpec  in)

Modify packer instruction to allow NULL as a value.

Parameters
injson pack specification to modify
Returns
json pack specification

Definition at line 80 of file json_pack.c.

81{
82 in.allow_null = true;
83 return in;
84}
bool allow_null
True if a NULL (or 0) argument is allowed.

References GNUNET_JSON_PackSpec::allow_null.

◆ GNUNET_JSON_pack_bool()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_bool ( const char *  name,
bool  b 
)

Generate packer instruction for a JSON field of type bool.

Parameters
namename of the field to add to the object
bboolean value
Returns
json pack specification

Definition at line 88 of file json_pack.c.

90{
91 struct GNUNET_JSON_PackSpec ps = {
92 .field_name = name,
93 .object = json_boolean (b)
94 };
95
96 return ps;
97}

References name, and ps.

◆ GNUNET_JSON_pack_double()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_double ( const char *  name,
double  f 
)

Generate packer instruction for a JSON field of type double.

Parameters
namename of the field to add to the object
fdouble value
Returns
json pack specification

Definition at line 101 of file json_pack.c.

103{
104 struct GNUNET_JSON_PackSpec ps = {
105 .field_name = name,
106 .object = json_real (f)
107 };
108
109 return ps;
110}

References removetrailingwhitespace::f, name, and ps.

◆ GNUNET_JSON_pack_string()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_string ( const char *  name,
const char *  s 
)

Generate packer instruction for a JSON field of type string.

Parameters
namename of the field to add to the object
sstring value
Returns
json pack specification

Definition at line 114 of file json_pack.c.

116{
117 struct GNUNET_JSON_PackSpec ps = {
118 .field_name = name,
119 .object = json_string (s)
120 };
121
122 return ps;
123}

References name, and ps.

Referenced by GNUNET_JSON_pack_blinded_message(), GNUNET_JSON_pack_blinded_sig(), and GNUNET_JSON_pack_unblinded_signature().

Here is the caller graph for this function:

◆ GNUNET_JSON_pack_uint64()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_uint64 ( const char *  name,
uint64_t  num 
)

Generate packer instruction for a JSON field of type unsigned integer.

Note that the maximum allowed value is still limited by JSON and not UINT64_MAX.

Parameters
namename of the field to add to the object
numnumeric value
Returns
json pack specification

Definition at line 127 of file json_pack.c.

129{
130 struct GNUNET_JSON_PackSpec ps = {
131 .field_name = name,
132 .object = json_integer ((json_int_t) num)
133 };
134
135#if JSON_INTEGER_IS_LONG_LONG
136 GNUNET_assert (num <= LLONG_MAX);
137#else
138 GNUNET_assert (num <= LONG_MAX);
139#endif
140 return ps;
141}

References GNUNET_assert, name, and ps.

Referenced by GNUNET_JSON_pack_blinded_sig().

Here is the caller graph for this function:

◆ GNUNET_JSON_pack_int64()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_int64 ( const char *  name,
int64_t  num 
)

Generate packer instruction for a JSON field of type signed integer.

Parameters
namename of the field to add to the object
numnumeric value
Returns
json pack specification

Definition at line 145 of file json_pack.c.

147{
148 struct GNUNET_JSON_PackSpec ps = {
149 .field_name = name,
150 .object = json_integer ((json_int_t) num)
151 };
152
153#if JSON_INTEGER_IS_LONG_LONG
154 GNUNET_assert (num <= LLONG_MAX);
155 GNUNET_assert (num >= LLONG_MIN);
156#else
157 GNUNET_assert (num <= LONG_MAX);
158 GNUNET_assert (num >= LONG_MIN);
159#endif
160 return ps;
161}

References GNUNET_assert, name, and ps.

◆ GNUNET_JSON_pack_object_steal()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_object_steal ( const char *  name,
json_t *  o 
)

Generate packer instruction for a JSON field of type JSON object where the reference is taken over by the packer.

Parameters
namename of the field to add to the object
oobject to steal
Returns
json pack specification

Definition at line 165 of file json_pack.c.

167{
168 struct GNUNET_JSON_PackSpec ps = {
169 .field_name = name,
170 .object = o
171 };
172
173 if (NULL == o)
174 return ps;
175 if (! json_is_object (o))
176 {
178 "Expected JSON object for field `%s'\n",
179 name);
180 GNUNET_assert (0);
181 }
182 return ps;
183}

References GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, name, and ps.

Referenced by GNUNET_JSON_pack_time_rel().

Here is the caller graph for this function:

◆ GNUNET_JSON_pack_object_incref()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_object_incref ( const char *  name,
json_t *  o 
)

Generate packer instruction for a JSON field of type JSON object where the reference counter is incremented by the packer.

Note that a deep copy is not performed.

Parameters
namename of the field to add to the object
oobject to increment reference counter of
Returns
json pack specification

Definition at line 187 of file json_pack.c.

189{
190 struct GNUNET_JSON_PackSpec ps = {
191 .field_name = name,
192 .object = o
193 };
194
195 if (NULL == o)
196 return ps;
197 (void) json_incref (o);
198 if (! json_is_object (o))
199 {
201 "Expected JSON object for field `%s'\n",
202 name);
203 GNUNET_assert (0);
204 }
205 return ps;
206}

References GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, name, and ps.

◆ GNUNET_JSON_pack_array_steal()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_array_steal ( const char *  name,
json_t *  a 
)

Generate packer instruction for a JSON field of type JSON array where the reference is taken over by the packer.

Parameters
namename of the field to add to the object
aarray to steal
Returns
json pack specification

Definition at line 210 of file json_pack.c.

212{
213 struct GNUNET_JSON_PackSpec ps = {
214 .field_name = name,
215 .object = a
216 };
217
218 if (NULL == a)
219 return ps;
220 if (! json_is_array (a))
221 {
223 "Expected JSON array for field `%s'\n",
224 name);
225 GNUNET_assert (0);
226 }
227 return ps;
228}

References GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, name, and ps.

◆ GNUNET_JSON_pack_array_incref()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_array_incref ( const char *  name,
json_t *  a 
)

Generate packer instruction for a JSON field of type JSON array where the reference counter is incremented by the packer.

Note that a deep copy is not performed.

Parameters
namename of the field to add to the object
aarray to increment reference counter of
Returns
json pack specification

Definition at line 232 of file json_pack.c.

234{
235 struct GNUNET_JSON_PackSpec ps = {
236 .field_name = name,
237 .object = a
238 };
239
240 if (NULL == a)
241 return ps;
242 (void) json_incref (a);
243 if (! json_is_array (a))
244 {
246 "Expected JSON array for field `%s'\n",
247 name);
248 GNUNET_assert (0);
249 }
250 return ps;
251}

References GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, name, and ps.

◆ GNUNET_JSON_pack_data_varsize()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_data_varsize ( const char *  name,
const void *  blob,
size_t  blob_size 
)

Generate packer instruction for a JSON field of type variable size binary blob.

Parameters
namename of the field to add to the object
blobbinary data to pack
blob_sizenumber of bytes in blob
Returns
json pack specification

Definition at line 255 of file json_pack.c.

258{
259 struct GNUNET_JSON_PackSpec ps = {
260 .field_name = name,
261 .object = (NULL != blob)
262 ? GNUNET_JSON_from_data (blob,
263 blob_size)
264 : NULL
265 };
266
267 return ps;
268}
json_t * GNUNET_JSON_from_data(const void *data, size_t size)
Convert binary data to a JSON string with the base32crockford encoding.

References GNUNET_JSON_from_data(), name, and ps.

Referenced by GNUNET_JSON_pack_blinded_message().

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

◆ GNUNET_JSON_pack_data64_varsize()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_data64_varsize ( const char *  name,
const void *  blob,
size_t  blob_size 
)

Generate packer instruction for a JSON field of type variable size binary blob.

Use base64-encoding, instead of the more common Crockford base32-encoding.

Parameters
namename of the field to add to the object
blobbinary data to pack
blob_sizenumber of bytes in blob
Returns
json pack specification

Definition at line 272 of file json_pack.c.

275{
276 struct GNUNET_JSON_PackSpec ps = {
277 .field_name = name,
278 .object = (NULL != blob)
280 blob_size)
281 : NULL
282 };
283
284 return ps;
285}
json_t * GNUNET_JSON_from_data64(const void *data, size_t size)
Convert binary data to a JSON string with base64 encoding.

References GNUNET_JSON_from_data64(), name, and ps.

Here is the call graph for this function:

◆ GNUNET_JSON_pack_timestamp()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_timestamp ( const char *  name,
struct GNUNET_TIME_Timestamp  at 
)

Generate packer instruction for a JSON field of type timestamp.

Parameters
namename of the field to add to the object
attimestamp pack, a value of 0 is only allowed with GNUNET_JSON_pack_allow_null()!
Returns
json pack specification

Definition at line 289 of file json_pack.c.

291{
292 struct GNUNET_JSON_PackSpec ps = {
293 .field_name = name
294 };
295
296 if (! GNUNET_TIME_absolute_is_zero (t.abs_time))
297 {
299 GNUNET_assert (NULL != ps.object);
300 }
301 else
302 {
303 ps.object = NULL;
304 }
305 return ps;
306}
json_t * GNUNET_JSON_from_timestamp(struct GNUNET_TIME_Timestamp stamp)
Convert timestamp to a json string.
bool GNUNET_TIME_absolute_is_zero(struct GNUNET_TIME_Absolute abs)
Test if abs is truly zero.
Definition: time.c:844

References GNUNET_assert, GNUNET_JSON_from_timestamp(), GNUNET_TIME_absolute_is_zero(), name, ps, and t.

Referenced by GNUNET_JSON_pack_timestamp_nbo().

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

◆ GNUNET_JSON_pack_timestamp_nbo()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_timestamp_nbo ( const char *  name,
struct GNUNET_TIME_TimestampNBO  at 
)

Generate packer instruction for a JSON field of type timestamp in network byte order.

Parameters
namename of the field to add to the object
attimestamp to pack, a value of 0 is only allowed with GNUNET_JSON_pack_allow_null()!
Returns
json pack specification

Definition at line 310 of file json_pack.c.

312{
315}
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_timestamp(const char *name, struct GNUNET_TIME_Timestamp t)
Generate packer instruction for a JSON field of type timestamp.
Definition: json_pack.c:289

References GNUNET_JSON_pack_timestamp(), GNUNET_TIME_timestamp_ntoh(), and name.

Here is the call graph for this function:

◆ GNUNET_JSON_pack_time_rel()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rel ( const char *  name,
struct GNUNET_TIME_Relative  rt 
)

Generate packer instruction for a JSON field of type relative time.

Parameters
namename of the field to add to the object
rtrelative time to pack
Returns
json pack specification

Definition at line 319 of file json_pack.c.

321{
322 json_t *json;
323
324 json = GNUNET_JSON_from_time_rel (rt);
325 GNUNET_assert (NULL != json);
327 json);
328}
json_t * GNUNET_JSON_from_time_rel(struct GNUNET_TIME_Relative stamp)
Convert relative timestamp to a json string.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_object_steal(const char *name, json_t *o)
Generate packer instruction for a JSON field of type JSON object where the reference is taken over by...
Definition: json_pack.c:165

References GNUNET_assert, GNUNET_JSON_from_time_rel(), GNUNET_JSON_pack_object_steal(), and name.

Referenced by GNUNET_JSON_pack_time_rel_nbo().

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

◆ GNUNET_JSON_pack_time_rel_nbo()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rel_nbo ( const char *  name,
struct GNUNET_TIME_RelativeNBO  rt 
)

Generate packer instruction for a JSON field of type relative time in network byte order.

Parameters
namename of the field to add to the object
rtrelative time to pack
Returns
json pack specification

Definition at line 332 of file json_pack.c.

334{
337}
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:628
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rel(const char *name, struct GNUNET_TIME_Relative rt)
Generate packer instruction for a JSON field of type relative time.
Definition: json_pack.c:319

References GNUNET_JSON_pack_time_rel(), GNUNET_TIME_relative_ntoh(), and name.

Here is the call graph for this function:

◆ GNUNET_JSON_pack_rsa_public_key()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_rsa_public_key ( const char *  name,
const struct GNUNET_CRYPTO_RsaPublicKey pk 
)

Generate packer instruction for a JSON field of type RSA public key.

Parameters
namename of the field to add to the object
pkRSA public key
Returns
json pack specification

Definition at line 341 of file json_pack.c.

343{
344 struct GNUNET_JSON_PackSpec ps = {
345 .field_name = name,
347 };
348
349 return ps;
350}
json_t * GNUNET_JSON_from_rsa_public_key(const struct GNUNET_CRYPTO_RsaPublicKey *pk)
Convert RSA public key to JSON.

References GNUNET_JSON_from_rsa_public_key(), name, pk, and ps.

Here is the call graph for this function:

◆ GNUNET_JSON_pack_rsa_signature()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_rsa_signature ( const char *  name,
const struct GNUNET_CRYPTO_RsaSignature sig 
)

Generate packer instruction for a JSON field of type RSA signature.

Parameters
namename of the field to add to the object
sigRSA signature
Returns
json pack specification

Definition at line 354 of file json_pack.c.

356{
357 struct GNUNET_JSON_PackSpec ps = {
358 .field_name = name,
359 .object = GNUNET_JSON_from_rsa_signature (sig)
360 };
361
362 return ps;
363}
json_t * GNUNET_JSON_from_rsa_signature(const struct GNUNET_CRYPTO_RsaSignature *sig)
Convert RSA signature to JSON.

References GNUNET_JSON_from_rsa_signature(), name, and ps.

Referenced by GNUNET_JSON_pack_blinded_sig(), and GNUNET_JSON_pack_unblinded_signature().

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

◆ GNUNET_JSON_pack_unblinded_signature()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_unblinded_signature ( const char *  name,
const struct GNUNET_CRYPTO_UnblindedSignature sig 
)

Generate packer instruction for a JSON field of type unblinded signature.

Parameters
namename of the field to add to the object
sigunblinded signature
Returns
json pack specification

Definition at line 367 of file json_pack.c.

369{
370 struct GNUNET_JSON_PackSpec ps = {
371 .field_name = name
372 };
373
374 if (NULL == sig)
375 return ps;
376
377 switch (sig->cipher)
378 {
380 break;
382 ps.object = GNUNET_JSON_PACK (
383 GNUNET_JSON_pack_string ("cipher",
384 "RSA"),
385 GNUNET_JSON_pack_rsa_signature ("rsa_signature",
386 sig->details.rsa_signature));
387 return ps;
389 ps.object = GNUNET_JSON_PACK (
390 GNUNET_JSON_pack_string ("cipher",
391 "CS"),
392 GNUNET_JSON_pack_data_auto ("cs_signature_r",
394 GNUNET_JSON_pack_data_auto ("cs_signature_s",
396 return ps;
397 }
398 GNUNET_assert (0);
399 return ps;
400}
#define GNUNET_JSON_PACK(...)
Pack a JSON object from a spec.
#define GNUNET_JSON_pack_data_auto(name, blob)
Generate packer instruction for a JSON field where the size is automatically determined from the argu...
@ GNUNET_CRYPTO_BSA_INVALID
Invalid type of signature.
@ GNUNET_CRYPTO_BSA_CS
Clause Blind Schnorr signature.
@ GNUNET_CRYPTO_BSA_RSA
RSA blind signature.
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_rsa_signature(const char *name, const struct GNUNET_CRYPTO_RsaSignature *sig)
Generate packer instruction for a JSON field of type RSA signature.
Definition: json_pack.c:354
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_string(const char *name, const char *s)
Generate packer instruction for a JSON field of type string.
Definition: json_pack.c:114
struct GNUNET_CRYPTO_CsS s_scalar
Schnorr signatures are composed of a scalar s and a curve point.
struct GNUNET_CRYPTO_CsRPublic r_point
Curve point of the Schnorr signature.
struct GNUNET_CRYPTO_RsaSignature * rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
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_assert, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_JSON_PACK, GNUNET_JSON_pack_data_auto, GNUNET_JSON_pack_rsa_signature(), GNUNET_JSON_pack_string(), name, and ps.

Here is the call graph for this function:

◆ GNUNET_JSON_pack_blinded_message()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_blinded_message ( const char *  name,
const struct GNUNET_CRYPTO_BlindedMessage msg 
)

Generate packer instruction for a JSON field of type blinded message.

Parameters
namename of the field to add to the object
msgblinded message
Returns
json pack specification

Definition at line 404 of file json_pack.c.

406{
407 struct GNUNET_JSON_PackSpec ps = {
408 .field_name = name,
409 };
410
411 switch (msg->cipher)
412 {
414 break;
416 ps.object = GNUNET_JSON_PACK (
417 GNUNET_JSON_pack_string ("cipher",
418 "RSA"),
420 "rsa_blinded_planchet",
421 msg->details.rsa_blinded_message.blinded_msg,
422 msg->details.rsa_blinded_message.blinded_msg_size));
423 return ps;
425 ps.object = GNUNET_JSON_PACK (
426 GNUNET_JSON_pack_string ("cipher",
427 "CS"),
429 "cs_nonce",
430 &msg->details.cs_blinded_message.nonce),
432 "cs_blinded_c0",
433 &msg->details.cs_blinded_message.c[0]),
435 "cs_blinded_c1",
436 &msg->details.cs_blinded_message.c[1]));
437 return ps;
438 }
439 GNUNET_assert (0);
440 return ps;
441}
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_data_varsize(const char *name, const void *blob, size_t blob_size)
Generate packer instruction for a JSON field of type variable size binary blob.
Definition: json_pack.c:255

References GNUNET_assert, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_JSON_PACK, GNUNET_JSON_pack_data_auto, GNUNET_JSON_pack_data_varsize(), GNUNET_JSON_pack_string(), msg, name, and ps.

Here is the call graph for this function:

◆ GNUNET_JSON_pack_blinded_sig()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_blinded_sig ( const char *  name,
const struct GNUNET_CRYPTO_BlindedSignature sig 
)

Generate packer instruction for a JSON field of type blinded signature.

Parameters
namename of the field to add to the object
sigblinded signature
Returns
json pack specification

Definition at line 445 of file json_pack.c.

448{
449 struct GNUNET_JSON_PackSpec ps = {
450 .field_name = name,
451 };
452
453 if (NULL == sig)
454 return ps;
455 switch (sig->cipher)
456 {
458 break;
460 ps.object = GNUNET_JSON_PACK (
461 GNUNET_JSON_pack_string ("cipher",
462 "RSA"),
463 GNUNET_JSON_pack_rsa_signature ("blinded_rsa_signature",
465 return ps;
467 ps.object = GNUNET_JSON_PACK (
468 GNUNET_JSON_pack_string ("cipher",
469 "CS"),
474 return ps;
475 }
476 GNUNET_assert (0);
477 return ps;
478}
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_uint64(const char *name, uint64_t num)
Generate packer instruction for a JSON field of type unsigned integer.
Definition: json_pack.c:127
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.
struct GNUNET_CRYPTO_CsBlindS s_scalar
The blinded s scalar calculated from c_b.
unsigned int b
To make ROS problem harder, the signer chooses an unpredictable b and only calculates signature of c_...

References GNUNET_assert, GNUNET_CRYPTO_BSA_CS, GNUNET_CRYPTO_BSA_INVALID, GNUNET_CRYPTO_BSA_RSA, GNUNET_JSON_PACK, GNUNET_JSON_pack_data_auto, GNUNET_JSON_pack_rsa_signature(), GNUNET_JSON_pack_string(), GNUNET_JSON_pack_uint64(), name, and ps.

Here is the call graph for this function: