GNUnet 0.21.1
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...
 
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...
 

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 469 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 480 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:30
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 685 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 854 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 885 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 638 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 538 of file gnunet_json_lib.h.

539{
544
549
554
559
564};
@ 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(), 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 32 of file json_helper.c.

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

References ret.

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

Here is the caller graph for this function:

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

96{
98 .parser = &parse_fixed_data,
99 .cleaner = NULL,
100 .cls = NULL,
101 .field = name,
102 .ptr = obj,
103 .ptr_size = size,
104 .size_ptr = NULL
105 };
106
107 return ret;
108}
static char * name
Name (label) of the records to list.
static enum GNUNET_GenericReturnValue parse_fixed_data(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to fixed size data.
Definition: json_helper.c:53
static unsigned int size
Size of the "table".
Definition: peer.c:68

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

Here is the call graph for this function:

◆ GNUNET_JSON_spec_fixed64()

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

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

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

Definition at line 157 of file json_helper.c.

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

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

Here is the call graph for this function:

◆ GNUNET_JSON_spec_varsize()

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

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

Parameters
namename of the JSON field
[out]objpointer where to write the data, will be allocated
[out]sizewhere to store the number of bytes allocated for obj

Definition at line 234 of file json_helper.c.

237{
239 .parser = &parse_variable_data,
240 .cleaner = &clean_variable_data,
241 .cls = NULL,
242 .field = name,
243 .ptr = obj,
244 .ptr_size = 0,
245 .size_ptr = size
246 };
247
248 *obj = NULL;
249 *size = 0;
250 return ret;
251}
static void clean_variable_data(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing variable size data.
Definition: json_helper.c:220
static enum GNUNET_GenericReturnValue parse_variable_data(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to variable size data.
Definition: json_helper.c:184

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

Here is the call graph for this function:

◆ GNUNET_JSON_spec_string()

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

The expected field stores a string.

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

Definition at line 282 of file json_helper.c.

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

References name, parse_string(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_json()

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

JSON object or array.

Reference counter is incremented.

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

Definition at line 341 of file json_helper.c.

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

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

Here is the call graph for this function:

◆ GNUNET_JSON_spec_object_const()

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

JSON object, reference counter not incremented.

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

Definition at line 385 of file json_helper.c.

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

References name, parse_object_const(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_array_const()

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

JSON array, reference counter not incremented.

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

Definition at line 428 of file json_helper.c.

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

References name, parse_array_const(), and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_bool()

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

boolean.

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

Definition at line 476 of file json_helper.c.

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

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

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

Here is the call graph for this function:

◆ GNUNET_JSON_spec_uint8()

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

8-bit integer.

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

Definition at line 569 of file json_helper.c.

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

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

Here is the call graph for this function:

◆ GNUNET_JSON_spec_uint16()

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

16-bit integer.

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

Definition at line 619 of file json_helper.c.

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

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

Here is the call graph for this function:

◆ GNUNET_JSON_spec_uint32()

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

32-bit integer.

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

Definition at line 669 of file json_helper.c.

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

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

Here is the call graph for this function:

◆ GNUNET_JSON_spec_uint64()

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

64-bit integer.

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

Definition at line 714 of file json_helper.c.

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

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

Here is the call graph for this function:

◆ GNUNET_JSON_spec_int64()

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

64-bit signed integer.

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

Definition at line 759 of file json_helper.c.

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

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

Here is the call graph for this function:

◆ GNUNET_JSON_spec_boolean()

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

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

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

Definition at line 1166 of file json_helper.c.

1168{
1170 .parser = &parse_boolean,
1171 .cleaner = NULL,
1172 .cls = NULL,
1173 .field = name,
1174 .ptr = boolean,
1175 .ptr_size = sizeof(int),
1176 .size_ptr = NULL
1177 };
1178
1179 return ret;
1180}
static enum GNUNET_GenericReturnValue parse_boolean(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to an int as a boolean.
Definition: json_helper.c:1149

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

Here is the call graph for this function:

◆ GNUNET_JSON_spec_timestamp()

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

Timestamp.

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

Definition at line 838 of file json_helper.c.

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

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

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

1039{
1041 .parser = &parse_rsa_public_key,
1042 .cleaner = &clean_rsa_public_key,
1043 .field = name,
1044 .ptr = pk
1045 };
1046
1047 *pk = NULL;
1048 return ret;
1049}
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:1023
static enum GNUNET_GenericReturnValue parse_rsa_public_key(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to RSA public key.
Definition: json_helper.c:976

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

Here is the call graph for this function:

◆ GNUNET_JSON_spec_rsa_signature()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_signature ( const char *  name,
struct GNUNET_CRYPTO_RsaSignature **  sig 
)

Specification for parsing an RSA signature.

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

Definition at line 1122 of file json_helper.c.

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

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

Here is the call graph for this function:

◆ 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 30 of file json_pack.c.

31{
32 json_t *ret;
33
34 if (NULL == spec[0].field_name)
35 {
36 ret = spec[0].object;
37 spec[0].object = NULL;
38 return ret;
39 }
40 ret = json_object ();
41 GNUNET_assert (NULL != ret);
42 for (unsigned int i = 0;
43 NULL != spec[i].field_name;
44 i++)
45 {
46 if (NULL == spec[i].object)
47 {
48 if (! spec[i].allow_null)
49 {
51 "NULL not allowed for `%s'\n",
52 spec[i].field_name);
53 GNUNET_assert (0);
54 }
55 }
56 else
57 {
58 GNUNET_assert (0 ==
59 json_object_set_new (ret,
60 spec[i].field_name,
61 spec[i].object));
62 spec[i].object = NULL;
63 }
64 }
65 return ret;
66}
@ 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 70 of file json_pack.c.

71{
72 struct GNUNET_JSON_PackSpec ps = {
73 .field_name = NULL
74 };
75
76 return ps;
77}
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 81 of file json_pack.c.

82{
83 in.allow_null = true;
84 return in;
85}
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 89 of file json_pack.c.

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

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 102 of file json_pack.c.

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

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 115 of file json_pack.c.

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

References name, and ps.

◆ 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 128 of file json_pack.c.

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

References GNUNET_assert, name, and ps.

◆ 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 146 of file json_pack.c.

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

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 166 of file json_pack.c.

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

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 188 of file json_pack.c.

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

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 211 of file json_pack.c.

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

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 233 of file json_pack.c.

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

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 256 of file json_pack.c.

259{
260 struct GNUNET_JSON_PackSpec ps = {
261 .field_name = name,
262 .object = (NULL != blob)
263 ? GNUNET_JSON_from_data (blob,
264 blob_size)
265 : NULL
266 };
267
268 return ps;
269}
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.

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

276{
277 struct GNUNET_JSON_PackSpec ps = {
278 .field_name = name,
279 .object = (NULL != blob)
281 blob_size)
282 : NULL
283 };
284
285 return ps;
286}
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 290 of file json_pack.c.

292{
293 struct GNUNET_JSON_PackSpec ps = {
294 .field_name = name
295 };
296
297 if (! GNUNET_TIME_absolute_is_zero (t.abs_time))
298 {
300 GNUNET_assert (NULL != ps.object);
301 }
302 else
303 {
304 ps.object = NULL;
305 }
306 return ps;
307}
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 311 of file json_pack.c.

313{
316}
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:290

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 320 of file json_pack.c.

322{
323 json_t *json;
324
325 json = GNUNET_JSON_from_time_rel (rt);
326 GNUNET_assert (NULL != json);
328 json);
329}
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:166

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 333 of file json_pack.c.

335{
338}
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:320

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 342 of file json_pack.c.

344{
345 struct GNUNET_JSON_PackSpec ps = {
346 .field_name = name,
348 };
349
350 return ps;
351}
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 355 of file json_pack.c.

357{
358 struct GNUNET_JSON_PackSpec ps = {
359 .field_name = name,
360 .object = GNUNET_JSON_from_rsa_signature (sig)
361 };
362
363 return ps;
364}
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.

Here is the call graph for this function: