GNUnet 0.25.2-12-g8d1cef5f6
 
Loading...
Searching...
No Matches
gnunet_json_lib.h File Reference

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

#include "gnunet_util_lib.h"
#include <jansson.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).
 
#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).
 
#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.
 
#define GNUNET_JSON_from_data64_auto(ptr)    GNUNET_JSON_from_data64 (ptr, sizeof(*(ptr)))
 Convert binary data to a JSON string with base64 encoding.
 
#define GNUNET_JSON_PACK(...)
 Pack a JSON object from a spec.
 
#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.
 
#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.
 

Typedefs

typedef enum GNUNET_GenericReturnValue(* GNUNET_JSON_Parser) (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Function called to parse JSON argument.
 
typedef void(* GNUNET_JSON_Cleaner) (void *cls, struct GNUNET_JSON_Specification *spec)
 Function called to clean up data from earlier parsing.
 
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_().
 

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.
 
void GNUNET_JSON_parse_free (struct GNUNET_JSON_Specification *spec)
 Frees all elements allocated during a GNUNET_JSON_parse() operation.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_end (void)
 End of a parser specification.
 
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.
 
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).
 
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).
 
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).
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_string (const char *name, const char **strptr)
 The expected field stores a string.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_string_copy (const char *name, char **strptr)
 The expected field stores a string.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_json (const char *name, json_t **jsonp)
 JSON object or array.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_object_copy (const char *name, json_t **jsonp)
 JSON object, reference counter incremented.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_array_copy (const char *name, json_t **jsonp)
 JSON array, reference counter incremented.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_object_const (const char *name, const json_t **jsonp)
 JSON object, reference counter not incremented.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_array_const (const char *name, const json_t **jsonp)
 JSON array, reference counter not incremented.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_bool (const char *name, bool *b)
 boolean.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_double (const char *name, double *f)
 double.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint8 (const char *name, uint8_t *u8)
 8-bit integer.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint16 (const char *name, uint16_t *u16)
 16-bit integer.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint32 (const char *name, uint32_t *u32)
 32-bit integer.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint (const char *name, unsigned int *ui)
 Unsigned integer.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_ull (const char *name, unsigned long long *ull)
 Unsigned long long.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint64 (const char *name, uint64_t *u64)
 64-bit integer.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_int16 (const char *name, int16_t *i16)
 16-bit signed integer.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_int64 (const char *name, int64_t *i64)
 64-bit signed integer.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_boolean (const char *name, int *boolean)
 Boolean (true mapped to GNUNET_YES, false mapped to GNUNET_NO).
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp (const char *name, struct GNUNET_TIME_Timestamp *t)
 Timestamp.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp_nbo (const char *name, struct GNUNET_TIME_TimestampNBO *tn)
 Timestamp in network byte order.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_relative_time (const char *name, struct GNUNET_TIME_Relative *rt)
 Relative time.
 
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.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_signature (const char *name, struct GNUNET_CRYPTO_RsaSignature **sig)
 Specification for parsing an RSA signature.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_blinded_message (const char *name, struct GNUNET_CRYPTO_BlindedMessage **msg)
 Specification for parsing a blinded message.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_blinded_signature (const char *field, struct GNUNET_CRYPTO_BlindedSignature **b_sig)
 Specification for parsing a blinded 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.
 
json_t * GNUNET_JSON_from_data (const void *data, size_t size)
 Convert binary data to a JSON string with the base32crockford encoding.
 
json_t * GNUNET_JSON_from_data64 (const void *data, size_t size)
 Convert binary data to a JSON string with base64 encoding.
 
json_t * GNUNET_JSON_from_timestamp (struct GNUNET_TIME_Timestamp stamp)
 Convert timestamp to a json string.
 
json_t * GNUNET_JSON_from_timestamp_nbo (struct GNUNET_TIME_TimestampNBO stamp)
 Convert timestamp to a json string.
 
json_t * GNUNET_JSON_from_time_rel (struct GNUNET_TIME_Relative stamp)
 Convert relative timestamp to a json string.
 
json_t * GNUNET_JSON_from_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *pk)
 Convert RSA public key to JSON.
 
json_t * GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig)
 Convert RSA signature to JSON.
 
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.
 
json_t * GNUNET_JSON_pack_ (struct GNUNET_JSON_PackSpec spec[])
 Pack a JSON object from a spec.
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_end_ (void)
 Do not use directly.
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_allow_null (struct GNUNET_JSON_PackSpec in)
 Modify packer instruction to allow NULL as a value.
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_bool (const char *name, bool b)
 Generate packer instruction for a JSON field of type bool.
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_double (const char *name, double f)
 Generate packer instruction for a JSON field of type double.
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_string (const char *name, const char *s)
 Generate packer instruction for a JSON field of type string.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rounder_interval (const char *name, enum GNUNET_TIME_RounderInterval ri)
 Generate packer instruction of a time rounder interval.
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_time_rounder_interval (const char *name, enum GNUNET_TIME_RounderInterval *ri)
 Provide specification to parse a time rounder interval.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 

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 200 of file gnunet_json_lib.h.

673{
679 const char *field_name;
680
684 json_t *object;
685
692 bool allow_null;
693
697 bool final;
698};
699
700
708json_t *
710
711
719#define GNUNET_JSON_PACK(...) \
720 GNUNET_JSON_pack_ ((struct GNUNET_JSON_PackSpec[]) {__VA_ARGS__, \
721 GNUNET_JSON_pack_end_ ()})
722
723
731
732
741
742
752GNUNET_JSON_pack_bool (const char *name,
753 bool b);
754
755
765GNUNET_JSON_pack_double (const char *name,
766 double f);
767
768
778GNUNET_JSON_pack_string (const char *name,
779 const char *s);
780
781
792GNUNET_JSON_pack_uint64 (const char *name,
793 uint64_t num);
794
795
805GNUNET_JSON_pack_int64 (const char *name,
806 int64_t num);
807
808
821 json_t *o);
822
823
836 json_t *o);
837
838
850 json_t *a);
851
852
864 json_t *a);
865
866
878 const void *blob,
879 size_t blob_size);
880
881
890#define GNUNET_JSON_pack_data_auto(name,blob) \
891 GNUNET_JSON_pack_data_varsize (name, (blob), sizeof (*(blob)))
892
893
907 const void *blob,
908 size_t blob_size);
909
910
921#define GNUNET_JSON_pack_data64_auto(name,blob) \
922 GNUNET_JSON_pack_data64_varsize (name, (blob), sizeof (*(blob)))
923
924
935
936
947 const char *name,
949
950
962 struct GNUNET_TIME_Timestamp at);
963
964
976 struct GNUNET_TIME_TimestampNBO at);
977
978
989 struct GNUNET_TIME_Relative rt);
990
991
1002 struct GNUNET_TIME_RelativeNBO rt);
1003
1004
1015 const struct GNUNET_CRYPTO_RsaPublicKey *pk);
1016
1017
1028 const struct GNUNET_CRYPTO_RsaSignature *sig);
1029
1030
1041 const char *name,
1042 const struct GNUNET_CRYPTO_UnblindedSignature *sig);
1043
1044
1055 const char *name,
1056 const struct GNUNET_CRYPTO_BlindedMessage *msg);
1057
1058
1069 const struct GNUNET_CRYPTO_BlindedSignature *sig);
1070
1071#endif
1072
1073/* end of gnunet_json_lib.h */
struct GNUNET_MessageHeader * msg
Definition 005.c:2
struct GNUNET_CRYPTO_BlindablePrivateKey pk
Private key from command line option, or NULL.
static char * name
Name (label) of the records to list.
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:336
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_end_(void)
Do not use directly.
Definition json_pack.c:76
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 ...
Definition json_pack.c:222
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.
Definition json_pack.c:305
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:269
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_bool(const char *name, bool b)
Generate packer instruction for a JSON field of type bool.
Definition json_pack.c:95
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:177
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 increm...
Definition json_pack.c:245
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_allow_null(struct GNUNET_JSON_PackSpec in)
Modify packer instruction to allow NULL as a value.
Definition json_pack.c:87
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.
Definition json_pack.c:385
json_t * GNUNET_JSON_pack_(struct GNUNET_JSON_PackSpec spec[])
Pack a JSON object from a spec.
Definition json_pack.c:30
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_double(const char *name, double f)
Generate packer instruction for a JSON field of type double.
Definition json_pack.c:109
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.
Definition json_pack.c:423
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.
Definition json_pack.c:327
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.
Definition json_pack.c:465
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:137
struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rounder_interval(const char *name, enum GNUNET_TIME_RounderInterval ri)
Generate packer instruction of a time rounder interval.
Definition json_pack.c:502
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 incre...
Definition json_pack.c:199
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:372
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.
Definition json_pack.c:287
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.
Definition json_pack.c:359
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.
Definition json_pack.c:156
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.
Definition json_pack.c:350
struct GNUNET_JSON_Specification GNUNET_JSON_spec_time_rounder_interval(const char *name, enum GNUNET_TIME_RounderInterval *ri)
Provide specification to parse a time rounder interval.
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:123
GNUNET_TIME_RounderInterval
Quantities by which we support round up absolute time values.
Blinded message ready for blind signing.
Type for blinded signatures.
The public information of an RSA key pair.
Definition crypto_rsa.c:53
Type of (unblinded) signatures.
Element in the array to give to the packer.
Entry in parser specification for GNUNET_JSON_parse().
Time for relative time used by GNUnet, in microseconds and in network byte order.
Time for relative time used by GNUnet, in microseconds.
Time for timestamps used by GNUnet, in seconds and in network byte order.
Time for timestamps used by GNUnet, in microseconds rounded to seconds.
enum GNUNET_TIME_RounderInterval ri
Definition time.c:1251

◆ 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 223 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 566 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 577 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_ ()})

Pack a JSON object from a spec.

Aborts if packing fails.

Parameters
...list of specification objects
Returns
JSON object

Definition at line 720 of file gnunet_json_lib.h.

721 {__VA_ARGS__, \
722 GNUNET_JSON_pack_end_ ()})

◆ 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 891 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 922 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 62 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 666 of file gnunet_json_lib.h.

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.
[in,out]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 {
39 if (NULL != error_json_name)
40 *error_json_name = "root is NULL";
41 if (NULL != error_line)
42 *error_line = 0;
43 return GNUNET_SYSERR;
44 }
45 for (unsigned int i = 0; NULL != spec[i].parser; i++)
46 {
47 json_t *pos;
48
49 if (NULL == spec[i].field)
50 pos = (json_t *) root;
51 else
52 pos = json_object_get (root,
53 spec[i].field);
54 if ( ( (NULL == pos) ||
55 (json_is_null (pos) ) ) &&
56 (spec[i].is_optional) )
57 {
58 if (NULL != spec[i].missing)
59 *spec[i].missing = true;
60 continue;
61 }
62 if ( (NULL == pos) ||
63 (GNUNET_OK !=
64 spec[i].parser (spec[i].cls,
65 pos,
66 &spec[i])) )
67 {
68 if (NULL != error_json_name)
69 *error_json_name = spec[i].field;
70 else
72 "Parsing failed for field `%s:%u`\n",
73 spec[i].field,
74 i);
75 if (NULL != error_line)
76 *error_line = i;
78 return GNUNET_SYSERR;
79 }
80 if (NULL != spec[i].missing)
81 *spec[i].missing = false;
82 }
83 return GNUNET_OK; /* all OK! */
84}
#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:100
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, 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
[in,out]specspecification of the parse operation

Definition at line 100 of file json.c.

101{
102 for (unsigned int i = 0; NULL != spec[i].parser; i++)
103 if (NULL != spec[i].cleaner)
104 spec[i].cleaner (spec[i].cls,
105 &spec[i]);
106}
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 34 of file json_helper.c.

35{
37 .parser = NULL,
38 };
39
40 return ret;
41}
static int ret
Final status code.
Definition gnunet-arm.c:93

References GNUNET_JSON_Specification::parser, and 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 88 of file json.c.

90{
91 struct GNUNET_JSON_Specification ret = spec;
92
93 ret.is_optional = true;
94 ret.missing = missing;
95 return ret;
96}
bool is_optional
Set to true if this component is optional.

References GNUNET_JSON_Specification::is_optional, 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 116 of file json_helper.c.

119{
122 .field = name,
123 .ptr = obj,
124 .ptr_size = size,
125 };
126
127 return ret;
128}
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:76
static unsigned int size
Size of the "table".
Definition peer.c:68

References name, parse_fixed_data(), GNUNET_JSON_Specification::parser, 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 177 of file json_helper.c.

180{
183 .field = name,
184 .ptr = obj,
185 .ptr_size = size,
186 };
187
188 return ret;
189}
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.

References name, parse_fixed64_data(), GNUNET_JSON_Specification::parser, 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 251 of file json_helper.c.

254{
257 .cleaner = &clean_variable_data,
258 .field = name,
259 .ptr = obj,
260 .size_ptr = size
261 };
262
263 *obj = NULL;
264 *size = 0;
265 return ret;
266}
static void clean_variable_data(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing variable size data.
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.

References clean_variable_data(), name, parse_variable_data(), GNUNET_JSON_Specification::parser, 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 297 of file json_helper.c.

299{
302 .field = name,
303 .ptr = strptr
304 };
305
306 *strptr = NULL;
307 return ret;
308}
static enum GNUNET_GenericReturnValue parse_string(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to string.

References name, parse_string(), GNUNET_JSON_Specification::parser, 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_string_copy()

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

The expected field stores a string.

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

Definition at line 339 of file json_helper.c.

341{
344 .field = name,
345 .ptr = strptr
346 };
347
348 *strptr = NULL;
349 return ret;
350}
static enum GNUNET_GenericReturnValue parse_string_copy(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to string, and make a copy.

References name, parse_string_copy(), GNUNET_JSON_Specification::parser, 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 397 of file json_helper.c.

399{
401 .parser = &parse_json,
402 .cleaner = &clean_json,
403 .field = name,
404 .ptr = jsonp,
405 };
406
407 *jsonp = NULL;
408 return ret;
409}
static void clean_json(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing JSON object.
static enum GNUNET_GenericReturnValue parse_json(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a JSON object.

References clean_json(), name, parse_json(), GNUNET_JSON_Specification::parser, and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_object_copy()

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

JSON object, reference counter incremented.

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

Definition at line 478 of file json_helper.c.

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

References clean_json(), name, parse_object_copy(), GNUNET_JSON_Specification::parser, and ret.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_array_copy()

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

JSON array, reference counter incremented.

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

Definition at line 559 of file json_helper.c.

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

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

440{
443 .field = name,
444 .ptr = jsonp,
445 };
446
447 *jsonp = NULL;
448 return ret;
449}
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.

References name, parse_object_const(), GNUNET_JSON_Specification::parser, 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 519 of file json_helper.c.

521{
524 .field = name,
525 .ptr = jsonp
526 };
527
528 *jsonp = NULL;
529 return ret;
530}
static enum GNUNET_GenericReturnValue parse_array_const(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON to a JSON array.

References name, parse_array_const(), GNUNET_JSON_Specification::parser, 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 605 of file json_helper.c.

607{
609 .parser = &parse_bool,
610 .field = name,
611 .ptr = b,
612 .ptr_size = sizeof(bool),
613 };
614
615 return ret;
616}
static enum GNUNET_GenericReturnValue parse_bool(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a bool.

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

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

647{
650 .field = name,
651 .ptr = f,
652 .ptr_size = sizeof(double),
653 };
654
655 return ret;
656}
static enum GNUNET_GenericReturnValue parse_double(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a double.

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

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

694{
696 .parser = &parse_u8,
697 .field = name,
698 .ptr = u8,
699 .ptr_size = sizeof(uint8_t),
700 };
701
702 return ret;
703}
static enum GNUNET_GenericReturnValue parse_u8(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint8_t.

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

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

741{
743 .parser = &parse_u16,
744 .field = name,
745 .ptr = u16,
746 .ptr_size = sizeof(uint16_t),
747 };
748
749 return ret;
750}
static enum GNUNET_GenericReturnValue parse_u16(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint16_t.

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

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

788{
790 .parser = &parse_u32,
791 .field = name,
792 .ptr = u32,
793 .ptr_size = sizeof(uint32_t),
794 };
795
796 return ret;
797}
static enum GNUNET_GenericReturnValue parse_u32(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint32_t.

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

Referenced by parse_blinded_sig().

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

◆ GNUNET_JSON_spec_uint()

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

Unsigned integer.

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

Definition at line 833 of file json_helper.c.

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

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

Here is the call graph for this function:

◆ GNUNET_JSON_spec_ull()

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

Unsigned long long.

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

Definition at line 880 of file json_helper.c.

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

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

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

924{
926 .parser = &parse_u64,
927 .field = name,
928 .ptr = u64,
929 .ptr_size = sizeof(uint64_t),
930 };
931
932 return ret;
933}
static enum GNUNET_GenericReturnValue parse_u64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint64_t.

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

Here is the call graph for this function:

◆ GNUNET_JSON_spec_int16()

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

16-bit signed integer.

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

Definition at line 970 of file json_helper.c.

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

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

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

1014{
1016 .parser = &parse_i64,
1017 .field = name,
1018 .ptr = i64,
1019 .ptr_size = sizeof(int64_t),
1020 };
1021
1022 return ret;
1023}
static enum GNUNET_GenericReturnValue parse_i64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a int64_t.

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

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

1418{
1421 .field = name,
1422 .ptr = boolean,
1423 .ptr_size = sizeof(int),
1424 };
1425
1426 return ret;
1427}
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.

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

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

1090{
1093 .field = name,
1094 .ptr = t,
1095 .ptr_size = sizeof(struct GNUNET_TIME_Timestamp)
1096 };
1097
1098 return ret;
1099}
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.

References name, parse_timestamp(), GNUNET_JSON_Specification::parser, 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 1133 of file json_helper.c.

1135{
1138 .field = name,
1139 .ptr = at,
1140 .ptr_size = sizeof(struct GNUNET_TIME_TimestampNBO)
1141 };
1142
1143 return ret;
1144}
static enum GNUNET_GenericReturnValue parse_timestamp_nbo(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to absolute time.

References name, parse_timestamp_nbo(), GNUNET_JSON_Specification::parser, 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 1203 of file json_helper.c.

1205{
1208 .field = name,
1209 .ptr = rt,
1210 .ptr_size = sizeof(struct GNUNET_TIME_Relative)
1211 };
1212
1213 return ret;
1214}
static enum GNUNET_GenericReturnValue parse_rel_time(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to relative time.

References name, parse_rel_time(), GNUNET_JSON_Specification::parser, 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 1287 of file json_helper.c.

1289{
1292 .cleaner = &clean_rsa_public_key,
1293 .field = name,
1294 .ptr = pk
1295 };
1296
1297 *pk = NULL;
1298 return ret;
1299}
static void clean_rsa_public_key(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA public key.
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.

References clean_rsa_public_key(), name, parse_rsa_public_key(), GNUNET_JSON_Specification::parser, 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 1372 of file json_helper.c.

1374{
1377 .cleaner = &clean_rsa_signature,
1378 .cls = NULL,
1379 .field = name,
1380 .ptr = sig,
1381 .ptr_size = 0,
1382 .size_ptr = NULL
1383 };
1384
1385 *sig = NULL;
1386 return ret;
1387}
static enum GNUNET_GenericReturnValue parse_rsa_signature(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to RSA signature.
static void clean_rsa_signature(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA signature.

References clean_rsa_signature(), name, parse_rsa_signature(), GNUNET_JSON_Specification::parser, 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 1553 of file json_helper.c.

1555{
1558 .cleaner = &clean_blinded_message,
1559 .cls = NULL,
1560 .field = name,
1561 .ptr = msg,
1562 .ptr_size = 0,
1563 .size_ptr = NULL
1564 };
1565
1566 *msg = NULL;
1567 return ret;
1568}
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.
static void clean_blinded_message(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing blinded message.

References clean_blinded_message(), msg, name, parse_blinded_message(), GNUNET_JSON_Specification::parser, 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 1688 of file json_helper.c.

1691{
1694 .cleaner = &clean_blinded_sig,
1695 .field = field,
1696 .ptr = b_sig
1697 };
1698
1699 *b_sig = NULL;
1700 return ret;
1701}
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.
static void clean_blinded_sig(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing blinded sig.

References clean_blinded_sig(), GNUNET_JSON_Specification::field, parse_blinded_sig(), GNUNET_JSON_Specification::parser, 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 1821 of file json_helper.c.

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

References clean_unblinded_sig(), GNUNET_JSON_Specification::field, parse_unblinded_sig(), GNUNET_JSON_Specification::parser, 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:807

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:1618

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:646
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:653
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.

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_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 147 of file json.c.

152{
155 .name = name,
156 .argumentHelp = argumentHelp,
157 .description = description,
158 .require_argument = 1,
159 .processor = &set_json,
160 .scls = (void *) json
161 };
162
163 return clo;
164}
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:122
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 ! spec[i].final;
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 if (NULL == spec[i].field_name)
59 GNUNET_assert (0 ==
60 json_object_update_new (ret,
61 spec[i].object));
62 else
63 GNUNET_assert (0 ==
64 json_object_set_new (ret,
65 spec[i].field_name,
66 spec[i].object));
67
68 spec[i].object = NULL;
69 }
70 }
71 return ret;
72}
@ GNUNET_ERROR_TYPE_ERROR
json_t * object
Object to pack.
bool final
True if last element in the spec array.

References GNUNET_JSON_PackSpec::final, 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 76 of file json_pack.c.

77{
78 struct GNUNET_JSON_PackSpec ps = {
79 .final = true
80 };
81
82 return ps;
83}
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 87 of file json_pack.c.

88{
89 in.allow_null = true;
90 return in;
91}
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 95 of file json_pack.c.

97{
98 struct GNUNET_JSON_PackSpec ps = {
99 .field_name = name,
100 .object = json_boolean (b)
101 };
102
103 GNUNET_assert (NULL != name);
104 return ps;
105}

References GNUNET_assert, 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 109 of file json_pack.c.

111{
112 struct GNUNET_JSON_PackSpec ps = {
113 .field_name = name,
114 .object = json_real (f)
115 };
116
117 GNUNET_assert (NULL != name);
118 return ps;
119}

References GNUNET_assert, 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 123 of file json_pack.c.

125{
126 struct GNUNET_JSON_PackSpec ps = {
127 .field_name = name,
128 .object = json_string (s)
129 };
130
131 GNUNET_assert (NULL != name);
132 return ps;
133}

References GNUNET_assert, name, and ps.

Referenced by GNUNET_JSON_pack_blinded_message(), GNUNET_JSON_pack_blinded_sig(), GNUNET_JSON_pack_time_rounder_interval(), 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 137 of file json_pack.c.

139{
140 struct GNUNET_JSON_PackSpec ps = {
141 .field_name = name,
142 .object = json_integer ((json_int_t) num)
143 };
144
145 GNUNET_assert (NULL != name);
146#if JSON_INTEGER_IS_LONG_LONG
147 GNUNET_assert (num <= LLONG_MAX);
148#else
149 GNUNET_assert (num <= LONG_MAX);
150#endif
151 return ps;
152}

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

158{
159 struct GNUNET_JSON_PackSpec ps = {
160 .field_name = name,
161 .object = json_integer ((json_int_t) num)
162 };
163
164 GNUNET_assert (NULL != name);
165#if JSON_INTEGER_IS_LONG_LONG
166 GNUNET_assert (num <= LLONG_MAX);
167 GNUNET_assert (num >= LLONG_MIN);
168#else
169 GNUNET_assert (num <= LONG_MAX);
170 GNUNET_assert (num >= LONG_MIN);
171#endif
172 return ps;
173}

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, if NULL, the keys of o will be placed in the top level of the resulting object
oobject to steal
Returns
json pack specification

Definition at line 177 of file json_pack.c.

179{
180 struct GNUNET_JSON_PackSpec ps = {
181 .field_name = name,
182 .object = o
183 };
184
185 if (NULL == o)
186 return ps;
187 if (! json_is_object (o))
188 {
190 "Expected JSON object for field `%s'\n",
191 name);
192 GNUNET_assert (0);
193 }
194 return ps;
195}

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, if NULL, the keys of o will be placed in the top level of the resulting object
oobject to increment reference counter of
Returns
json pack specification

Definition at line 199 of file json_pack.c.

201{
202 struct GNUNET_JSON_PackSpec ps = {
203 .field_name = name,
204 .object = o
205 };
206
207 if (NULL == o)
208 return ps;
209 (void) json_incref (o);
210 if (! json_is_object (o))
211 {
213 "Expected JSON object for field `%s'\n",
214 name);
215 GNUNET_assert (0);
216 }
217 return ps;
218}

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

224{
225 struct GNUNET_JSON_PackSpec ps = {
226 .field_name = name,
227 .object = a
228 };
229
230 GNUNET_assert (NULL != name);
231 if (NULL == a)
232 return ps;
233 if (! json_is_array (a))
234 {
236 "Expected JSON array for field `%s'\n",
237 name);
238 GNUNET_assert (0);
239 }
240 return ps;
241}

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

247{
248 struct GNUNET_JSON_PackSpec ps = {
249 .field_name = name,
250 .object = a
251 };
252
253 GNUNET_assert (NULL != name);
254 if (NULL == a)
255 return ps;
256 (void) json_incref (a);
257 if (! json_is_array (a))
258 {
260 "Expected JSON array for field `%s'\n",
261 name);
262 GNUNET_assert (0);
263 }
264 return ps;
265}

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

272{
273 struct GNUNET_JSON_PackSpec ps = {
274 .field_name = name,
275 .object = (NULL != blob)
276 ? GNUNET_JSON_from_data (blob,
277 blob_size)
278 : NULL
279 };
280
281 GNUNET_assert (NULL != name);
282 return ps;
283}
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_assert, 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 287 of file json_pack.c.

290{
291 struct GNUNET_JSON_PackSpec ps = {
292 .field_name = name,
293 .object = (NULL != blob)
295 blob_size)
296 : NULL
297 };
298
299 GNUNET_assert (NULL != name);
300 return ps;
301}
json_t * GNUNET_JSON_from_data64(const void *data, size_t size)
Convert binary data to a JSON string with base64 encoding.

References GNUNET_assert, GNUNET_JSON_from_data64(), name, and ps.

Here is the call graph for this function:

◆ GNUNET_JSON_pack_time_rounder_interval()

struct GNUNET_JSON_PackSpec GNUNET_JSON_pack_time_rounder_interval ( const char *  name,
enum GNUNET_TIME_RounderInterval  ri 
)

Generate packer instruction of a time rounder interval.

Parameters
namename of the field to add to the object
rirounder interval to add
Returns
json pack specification

Definition at line 502 of file json_pack.c.

504{
505 const char *str = "INVALID";
506
508 if (NULL == str)
509 {
510 GNUNET_break (0);
511 str = "INVALID";
512 }
514 str);
515}
const char * GNUNET_TIME_round_interval2s(enum GNUNET_TIME_RounderInterval ri)
Convert rounding interval to string.
Definition time.c:1293
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:123
const char * str
Definition time.c:1252

References GNUNET_break, GNUNET_JSON_pack_string(), GNUNET_TIME_round_interval2s(), name, ri, and str.

Here is the call graph for this function:

◆ GNUNET_JSON_spec_time_rounder_interval()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_time_rounder_interval ( const char *  name,
enum GNUNET_TIME_RounderInterval ri 
)

Provide specification to parse a time rounder interval.

The value must be provided as a descriptive string.

Parameters
namename of the time rounder interval type in the JSON
[out]riwhere to store the time rounder interval
Returns
spec for parsing trigger event type

Definition at line 1878 of file json_helper.c.

1881{
1883 .parser = &parse_tri,
1884 .field = name,
1885 .ptr = ri
1886 };
1887
1889 return ret;
1890
1891}
@ GNUNET_TIME_RI_NONE
No rounding up.
static enum GNUNET_GenericReturnValue parse_tri(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to enum GNUNET_TIME_RounderInterval

References GNUNET_TIME_RI_NONE, name, parse_tri(), GNUNET_JSON_Specification::parser, ret, and ri.

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

307{
308 struct GNUNET_JSON_PackSpec ps = {
309 .field_name = name
310 };
311
312 GNUNET_assert (NULL != name);
313 if (! GNUNET_TIME_absolute_is_zero (t.abs_time))
314 {
316 GNUNET_assert (NULL != ps.object);
317 }
318 else
319 {
320 ps.object = NULL;
321 }
322 return ps;
323}
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 327 of file json_pack.c.

329{
332}
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:305

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

338{
339 json_t *json;
340
341 GNUNET_assert (NULL != name);
342 json = GNUNET_JSON_from_time_rel (rt);
343 GNUNET_assert (NULL != json);
345 json);
346}
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:177

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

352{
355}
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition time.c:626
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:336

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

361{
362 struct GNUNET_JSON_PackSpec ps = {
363 .field_name = name,
365 };
366
367 return ps;
368}
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 372 of file json_pack.c.

374{
375 struct GNUNET_JSON_PackSpec ps = {
376 .field_name = name,
377 .object = GNUNET_JSON_from_rsa_signature (sig)
378 };
379
380 return ps;
381}
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 385 of file json_pack.c.

388{
389 struct GNUNET_JSON_PackSpec ps = {
390 .field_name = name
391 };
392
393 if (NULL == sig)
394 return ps;
395
396 switch (sig->cipher)
397 {
399 break;
401 ps.object = GNUNET_JSON_PACK (
402 GNUNET_JSON_pack_string ("cipher",
403 "RSA"),
404 GNUNET_JSON_pack_rsa_signature ("rsa_signature",
405 sig->details.rsa_signature));
406 return ps;
408 ps.object = GNUNET_JSON_PACK (
409 GNUNET_JSON_pack_string ("cipher",
410 "CS"),
411 GNUNET_JSON_pack_data_auto ("cs_signature_r",
413 GNUNET_JSON_pack_data_auto ("cs_signature_s",
415 return ps;
416 }
417 GNUNET_assert (0);
418 return ps;
419}
#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:372
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.
union GNUNET_CRYPTO_UnblindedSignature::@18 details
Details, depending on cipher.
struct GNUNET_CRYPTO_RsaSignature * rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in 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 423 of file json_pack.c.

426{
427 struct GNUNET_JSON_PackSpec ps = {
428 .field_name = name,
429 };
430
431 switch (msg->cipher)
432 {
434 break;
436 ps.object = GNUNET_JSON_PACK (
437 GNUNET_JSON_pack_string ("cipher",
438 "RSA"),
440 "rsa_blinded_planchet",
441 msg->details.rsa_blinded_message.blinded_msg,
442 msg->details.rsa_blinded_message.blinded_msg_size));
443 return ps;
445 ps.object = GNUNET_JSON_PACK (
446 GNUNET_JSON_pack_string ("cipher",
447 "CS"),
449 "cs_nonce",
450 &msg->details.cs_blinded_message.nonce),
452 "cs_blinded_c0",
453 &msg->details.cs_blinded_message.c[0]),
455 "cs_blinded_c1",
456 &msg->details.cs_blinded_message.c[1]));
457 return ps;
458 }
459 GNUNET_assert (0);
460 return ps;
461}
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:269

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

468{
469 struct GNUNET_JSON_PackSpec ps = {
470 .field_name = name,
471 };
472
473 if (NULL == sig)
474 return ps;
475 switch (sig->cipher)
476 {
478 break;
480 ps.object = GNUNET_JSON_PACK (
481 GNUNET_JSON_pack_string ("cipher",
482 "RSA"),
483 GNUNET_JSON_pack_rsa_signature ("blinded_rsa_signature",
485 return ps;
487 ps.object = GNUNET_JSON_PACK (
488 GNUNET_JSON_pack_string ("cipher",
489 "CS"),
494 return ps;
495 }
496 GNUNET_assert (0);
497 return ps;
498}
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:137
struct GNUNET_CRYPTO_CsBlindSignature blinded_cs_answer
If we use GNUNET_CRYPTO_BSA_CS in 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.
union GNUNET_CRYPTO_BlindedSignature::@19 details
Details, depending on 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: