GNUnet  0.11.x
Data Structures | Macros | Typedefs | Enumerations | Functions
gnunet_json_lib.h File Reference

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

#include "gnunet_util_lib.h"
#include "gnunet_gnsrecord_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...
 

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_from_data_auto(ptr)   GNUNET_JSON_from_data (ptr, sizeof(*ptr))
 Convert binary data to a JSON string with the base32crockford encoding. More...
 

Typedefs

typedef int(* 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...
 

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

int 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)
 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_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. 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_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_absolute_time (const char *name, struct GNUNET_TIME_Absolute *at)
 Absolute time. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_absolute_time_nbo (const char *name, struct GNUNET_TIME_AbsoluteNBO *at)
 Absolute time in network byte order. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_relative_time (const char *name, struct GNUNET_TIME_Relative *rt)
 Relative time. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_public_key (const char *name, struct GNUNET_CRYPTO_RsaPublicKey **pk)
 Specification for parsing an RSA public key. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_signature (const char *name, struct GNUNET_CRYPTO_RsaSignature **sig)
 Specification for parsing an RSA signature. More...
 
struct GNUNET_JSON_Specification GNUNET_JSON_spec_gnsrecord (struct GNUNET_GNSRECORD_Data **rd, unsigned int *rd_count, char **name)
 JSON Specification for GNS Records. 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_time_abs (struct GNUNET_TIME_Absolute stamp)
 Convert absolute timestamp to a json string. More...
 
json_t * GNUNET_JSON_from_time_abs_nbo (struct GNUNET_TIME_AbsoluteNBO stamp)
 Convert absolute 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...
 
json_t * GNUNET_JSON_from_gnsrecord (const char *rname, const struct GNUNET_GNSRECORD_Data *rd, unsigned int rd_count)
 Convert Gns record 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...
 

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

Typedef Documentation

◆ GNUNET_JSON_Parser

typedef int(* 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 52 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 63 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 430 of file gnunet_json_lib.h.

431 {
436 
441 
446 
451 
456 };
JSON parsing failed.
Parsing successful, JSON result is in *json.
Sorry, memory allocation (malloc()) failed.
Request size exceeded buffer_max argument.
Parsing continues, call again soon!

Function Documentation

◆ GNUNET_JSON_parse()

int 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]whichindex into spec did we encounter an error
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 45 of file json.c.

References GNUNET_JSON_Specification::field, GNUNET_JSON_parse_free(), GNUNET_OK, GNUNET_SYSERR, and GNUNET_JSON_Specification::parser.

Referenced by add_attribute_cont(), consume_ticket_cont(), namestore_add(), and revoke_ticket_cont().

49 {
50  if (NULL == root)
51  return GNUNET_SYSERR;
52  for (unsigned int i = 0; NULL != spec[i].parser; i++)
53  {
54  json_t *pos;
55 
56  if (NULL == spec[i].field)
57  pos = (json_t *) root;
58  else
59  pos = json_object_get (root, spec[i].field);
60  if ((NULL == pos) && (spec[i].is_optional))
61  continue;
62  if ((NULL == pos) ||
63  (GNUNET_OK != spec[i].parser (spec[i].cls, pos, &spec[i])))
64  {
65  if (NULL != error_json_name)
66  *error_json_name = spec[i].field;
67  if (NULL != error_line)
68  *error_line = i;
70  return GNUNET_SYSERR;
71  }
72  }
73  return GNUNET_OK; /* all OK! */
74 }
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...
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GNUNET_JSON_parse_free(struct GNUNET_JSON_Specification *spec)
Frees all elements allocated during a GNUNET_JSON_parse() operation.
Definition: json.c:100
GNUNET_JSON_Parser parser
Function for how to parse this type of entry.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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.

Parameters
specspecification of the parse operation

Definition at line 100 of file json.c.

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

Referenced by add_attribute_cont(), consume_ticket_cont(), GNUNET_JSON_parse(), namestore_add(), and revoke_ticket_cont().

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, &spec[i]);
105 }
GNUNET_JSON_Parser parser
Function for how to parse this type of entry.
GNUNET_JSON_Cleaner cleaner
Function for how to clean up this type of entry.
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 35 of file json_helper.c.

References GNUNET_JSON_Specification::parser, and ret.

Referenced by add_attribute_cont(), consume_ticket_cont(), namestore_add(), and revoke_ticket_cont().

36 {
38  .parser = NULL,
39  .cleaner = NULL,
40  .cls = NULL
41  };
42 
43  return ret;
44 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
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)

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

Parameters
specspecification to modify
Returns
spec copy of spec with optional bit set

Definition at line 84 of file json.c.

References GNUNET_YES, GNUNET_JSON_Specification::is_optional, and ret.

85 {
86  struct GNUNET_JSON_Specification ret = spec;
87 
88  ret.is_optional = GNUNET_YES;
89  return ret;
90 }
int is_optional
Set to GNUNET_YES if this component is optional.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
#define GNUNET_YES
Definition: gnunet_common.h:77

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

References name, parse_fixed_data(), GNUNET_JSON_Specification::parser, ret, and size.

99 {
100  struct GNUNET_JSON_Specification ret = {
101  .parser = &parse_fixed_data,
102  .cleaner = NULL,
103  .cls = NULL,
104  .field = name,
105  .ptr = obj,
106  .ptr_size = size,
107  .size_ptr = NULL
108  };
109 
110  return ret;
111 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static unsigned int size
Size of the "table".
Definition: peer.c:67
const char * name
static int 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:56
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 189 of file json_helper.c.

References clean_variable_data(), name, parse_variable_data(), GNUNET_JSON_Specification::parser, ret, and size.

192 {
193  struct GNUNET_JSON_Specification ret = {
194  .parser = &parse_variable_data,
195  .cleaner = &clean_variable_data,
196  .cls = NULL,
197  .field = name,
198  .ptr = obj,
199  .ptr_size = 0,
200  .size_ptr = size
201  };
202 
203  *obj = NULL;
204  *size = 0;
205  return ret;
206 }
static void clean_variable_data(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing variable size data.
Definition: json_helper.c:168
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static unsigned int size
Size of the "table".
Definition: peer.c:67
static int 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:123
const char * name
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 242 of file json_helper.c.

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

244 {
245  struct GNUNET_JSON_Specification ret = {
246  .parser = &parse_string,
247  .cleaner = NULL,
248  .cls = NULL,
249  .field = name,
250  .ptr = strptr,
251  .ptr_size = 0,
252  .size_ptr = NULL
253  };
254 
255  *strptr = NULL;
256  return ret;
257 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_string(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to string.
Definition: json_helper.c:218
const char * name
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.

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

Definition at line 311 of file json_helper.c.

References clean_object(), name, parse_object(), GNUNET_JSON_Specification::parser, and ret.

313 {
314  struct GNUNET_JSON_Specification ret = {
315  .parser = &parse_object,
316  .cleaner = &clean_object,
317  .cls = NULL,
318  .field = name,
319  .ptr = jsonp,
320  .ptr_size = 0,
321  .size_ptr = NULL
322  };
323 
324  *jsonp = NULL;
325  return ret;
326 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_object(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a JSON object.
Definition: json_helper.c:269
static void clean_object(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing JSON object.
Definition: json_helper.c:291
const char * name
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 368 of file json_helper.c.

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

370 {
371  struct GNUNET_JSON_Specification ret = {
372  .parser = &parse_u8,
373  .cleaner = NULL,
374  .cls = NULL,
375  .field = name,
376  .ptr = u8,
377  .ptr_size = sizeof(uint8_t),
378  .size_ptr = NULL
379  };
380 
381  return ret;
382 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
static int parse_u8(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint8_t.
Definition: json_helper.c:338
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 424 of file json_helper.c.

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

426 {
427  struct GNUNET_JSON_Specification ret = {
428  .parser = &parse_u16,
429  .cleaner = NULL,
430  .cls = NULL,
431  .field = name,
432  .ptr = u16,
433  .ptr_size = sizeof(uint16_t),
434  .size_ptr = NULL
435  };
436 
437  return ret;
438 }
static int parse_u16(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint16_t.
Definition: json_helper.c:394
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
const char * name
size_t * size_ptr
Where should we store the final size of 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 480 of file json_helper.c.

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

482 {
483  struct GNUNET_JSON_Specification ret = {
484  .parser = &parse_u32,
485  .cleaner = NULL,
486  .cls = NULL,
487  .field = name,
488  .ptr = u32,
489  .ptr_size = sizeof(uint32_t),
490  .size_ptr = NULL
491  };
492 
493  return ret;
494 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_u32(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint32_t.
Definition: json_helper.c:450
const char * name
size_t * size_ptr
Where should we store the final size of 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 531 of file json_helper.c.

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

533 {
534  struct GNUNET_JSON_Specification ret = {
535  .parser = &parse_u64,
536  .cleaner = NULL,
537  .cls = NULL,
538  .field = name,
539  .ptr = u64,
540  .ptr_size = sizeof(uint64_t),
541  .size_ptr = NULL
542  };
543 
544  return ret;
545 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_u64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint8_t.
Definition: json_helper.c:506
const char * name
size_t * size_ptr
Where should we store the final size of 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

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

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

998 {
999  struct GNUNET_JSON_Specification ret = {
1000  .parser = &parse_boolean,
1001  .cleaner = NULL,
1002  .cls = NULL,
1003  .field = name,
1004  .ptr = boolean,
1005  .ptr_size = sizeof(int),
1006  .size_ptr = NULL
1007  };
1008 
1009  return ret;
1010 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int 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:973
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
Here is the call graph for this function:

◆ GNUNET_JSON_spec_absolute_time()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_absolute_time ( const char *  name,
struct GNUNET_TIME_Absolute at 
)

Absolute time.

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

Definition at line 609 of file json_helper.c.

References name, parse_abs_time(), GNUNET_JSON_Specification::parser, ret, and GNUNET_JSON_Specification::size_ptr.

611 {
612  struct GNUNET_JSON_Specification ret = {
613  .parser = &parse_abs_time,
614  .cleaner = NULL,
615  .cls = NULL,
616  .field = name,
617  .ptr = at,
618  .ptr_size = sizeof(uint64_t),
619  .size_ptr = NULL
620  };
621 
622  return ret;
623 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
static int parse_abs_time(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to absolute time.
Definition: json_helper.c:559
Here is the call graph for this function:

◆ GNUNET_JSON_spec_absolute_time_nbo()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_absolute_time_nbo ( const char *  name,
struct GNUNET_TIME_AbsoluteNBO at 
)

Absolute time in network byte order.

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

Definition at line 687 of file json_helper.c.

References name, parse_abs_time_nbo(), GNUNET_JSON_Specification::parser, ret, and GNUNET_JSON_Specification::size_ptr.

689 {
690  struct GNUNET_JSON_Specification ret = {
691  .parser = &parse_abs_time_nbo,
692  .cleaner = NULL,
693  .cls = NULL,
694  .field = name,
695  .ptr = at,
696  .ptr_size = sizeof(uint64_t),
697  .size_ptr = NULL
698  };
699 
700  return ret;
701 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
static int parse_abs_time_nbo(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to absolute time.
Definition: json_helper.c:635
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 759 of file json_helper.c.

References name, parse_rel_time(), GNUNET_JSON_Specification::parser, ret, and GNUNET_JSON_Specification::size_ptr.

761 {
762  struct GNUNET_JSON_Specification ret = {
763  .parser = &parse_rel_time,
764  .cleaner = NULL,
765  .cls = NULL,
766  .field = name,
767  .ptr = rt,
768  .ptr_size = sizeof(uint64_t),
769  .size_ptr = NULL
770  };
771 
772  return ret;
773 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_rel_time(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to relative time.
Definition: json_helper.c:713
const char * name
size_t * size_ptr
Where should we store the final size of ptr.
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 852 of file json_helper.c.

References clean_rsa_public_key(), name, parse_rsa_public_key(), GNUNET_JSON_Specification::parser, pk, and ret.

854 {
855  struct GNUNET_JSON_Specification ret = {
856  .parser = &parse_rsa_public_key,
857  .cleaner = &clean_rsa_public_key,
858  .cls = NULL,
859  .field = name,
860  .ptr = pk,
861  .ptr_size = 0,
862  .size_ptr = NULL
863  };
864 
865  *pk = NULL;
866  return ret;
867 }
static struct GNUNET_CRYPTO_EddsaPrivateKey * pk
Private key of this peer.
static int 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:785
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
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:832
const char * name
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 946 of file json_helper.c.

References clean_rsa_signature(), name, parse_rsa_signature(), GNUNET_JSON_Specification::parser, and ret.

948 {
949  struct GNUNET_JSON_Specification ret = {
950  .parser = &parse_rsa_signature,
951  .cleaner = &clean_rsa_signature,
952  .cls = NULL,
953  .field = name,
954  .ptr = sig,
955  .ptr_size = 0,
956  .size_ptr = NULL
957  };
958 
959  *sig = NULL;
960  return ret;
961 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static int parse_rsa_signature(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to RSA signature.
Definition: json_helper.c:879
static void clean_rsa_signature(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA signature.
Definition: json_helper.c:926
const char * name
Here is the call graph for this function:

◆ GNUNET_JSON_spec_gnsrecord()

struct GNUNET_JSON_Specification GNUNET_JSON_spec_gnsrecord ( struct GNUNET_GNSRECORD_Data **  rd,
unsigned int *  rd_count,
char **  name 
)

JSON Specification for GNS Records.

Parameters
gnsrecord_objectstruct of GNUNET_GNSRECORD_Data to fill
Returns
JSON Specification

Definition at line 239 of file json_gnsrecord.c.

References clean_gnsrecordobject(), GNUNET_new, GnsRecordInfo::name, parse_gnsrecordobject(), GNUNET_JSON_Specification::parser, GnsRecordInfo::rd, GnsRecordInfo::rd_count, and ret.

Referenced by namestore_add().

242 {
243  struct GnsRecordInfo *gnsrecord_info = GNUNET_new (struct GnsRecordInfo);
244 
245  gnsrecord_info->rd = rd;
246  gnsrecord_info->name = name;
247  gnsrecord_info->rd_count = rd_count;
249  .cleaner = &clean_gnsrecordobject,
250  .cls = NULL,
251  .field = NULL,
252  .ptr = (struct GnsRecordInfo *)
253  gnsrecord_info,
254  .ptr_size = 0,
255  .size_ptr = NULL };
256  return ret;
257 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int parse_gnsrecordobject(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
unsigned int * rd_count
const char * name
static void clean_gnsrecordobject(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing the record.
struct GNUNET_GNSRECORD_Data ** rd
Here is the call graph for this function:
Here is the caller 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 39 of file json_generator.c.

References buf, GNUNET_free, and GNUNET_STRINGS_data_to_string_alloc().

Referenced by GNUNET_JSON_from_rsa_public_key(), and GNUNET_JSON_from_rsa_signature().

41 {
42  char *buf;
43  json_t *json;
44 
46  json = json_string (buf);
47  GNUNET_free (buf);
48  return json;
49 }
static char buf[2048]
static unsigned int size
Size of the "table".
Definition: peer.c:67
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:920
uint32_t data
The data value.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_from_time_abs()

json_t* GNUNET_JSON_from_time_abs ( struct GNUNET_TIME_Absolute  stamp)

Convert absolute timestamp to a json string.

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

Definition at line 59 of file json_generator.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_asprintf(), GNUNET_assert, GNUNET_free, GNUNET_OK, GNUNET_TIME_round_abs(), GNUNET_TIME_UNIT_FOREVER_ABS, and ret.

Referenced by GNUNET_JSON_from_time_abs_nbo().

60 {
61  json_t *j;
62  char *mystr;
63  int ret;
64 
66  GNUNET_TIME_round_abs (&stamp));
67  if (stamp.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
68  return json_string ("/never/");
69  ret = GNUNET_asprintf (&mystr,
70  "/Date(%llu)/",
71  (unsigned long long) (stamp.abs_value_us / (1000LL
72  * 1000LL)));
73  GNUNET_assert (ret > 0);
74  j = json_string (mystr);
75  GNUNET_free (mystr);
76  return j;
77 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint64_t abs_value_us
The actual value.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
int GNUNET_TIME_round_abs(struct GNUNET_TIME_Absolute *at)
Round a time value so that it is suitable for transmission via JSON encodings.
Definition: time.c:80
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_JSON_from_time_abs_nbo()

json_t* GNUNET_JSON_from_time_abs_nbo ( struct GNUNET_TIME_AbsoluteNBO  stamp)

Convert absolute timestamp to a json string.

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

Definition at line 87 of file json_generator.c.

References GNUNET_JSON_from_time_abs(), and GNUNET_TIME_absolute_ntoh().

88 {
90 }
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
json_t * GNUNET_JSON_from_time_abs(struct GNUNET_TIME_Absolute stamp)
Convert absolute timestamp to a json string.
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 100 of file json_generator.c.

References GNUNET_asprintf(), GNUNET_assert, GNUNET_free, GNUNET_OK, GNUNET_TIME_round_rel(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_Relative::rel_value_us, and ret.

101 {
102  json_t *j;
103  char *mystr;
104  int ret;
105 
107  GNUNET_TIME_round_rel (&stamp));
108  if (stamp.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
109  return json_string ("/forever/");
110  ret = GNUNET_asprintf (&mystr,
111  "/Delay(%llu)/",
112  (unsigned long long) (stamp.rel_value_us / (1000LL
113  * 1000LL)));
114  GNUNET_assert (ret > 0);
115  j = json_string (mystr);
116  GNUNET_free (mystr);
117  return j;
118 }
uint64_t rel_value_us
The actual value.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
int GNUNET_TIME_round_rel(struct GNUNET_TIME_Relative *rt)
Round a time value so that it is suitable for transmission via JSON encodings.
Definition: time.c:100
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call 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 128 of file json_generator.c.

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

129 {
130  char *buf;
131  size_t buf_len;
132  json_t *ret;
133 
135  &buf);
136  ret = GNUNET_JSON_from_data (buf,
137  buf_len);
138  GNUNET_free (buf);
139  return ret;
140 }
size_t GNUNET_CRYPTO_rsa_public_key_encode(const struct GNUNET_CRYPTO_RsaPublicKey *key, char **buffer)
Encode the public key in a format suitable for storing it into a file.
Definition: crypto_rsa.c:348
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static char buf[2048]
#define GNUNET_free(ptr)
Wrapper around free.
json_t * GNUNET_JSON_from_data(const void *data, size_t size)
Convert binary data to a JSON string with the base32crockford encoding.
Here is the call 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 150 of file json_generator.c.

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

151 {
152  char *buf;
153  size_t buf_len;
154  json_t *ret;
155 
156  buf_len = GNUNET_CRYPTO_rsa_signature_encode (sig,
157  &buf);
158  ret = GNUNET_JSON_from_data (buf,
159  buf_len);
160  GNUNET_free (buf);
161  return ret;
162 }
size_t GNUNET_CRYPTO_rsa_signature_encode(const struct GNUNET_CRYPTO_RsaSignature *sig, char **buffer)
Encode the given signature in a format suitable for storing it into a file.
Definition: crypto_rsa.c:1127
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static char buf[2048]
#define GNUNET_free(ptr)
Wrapper around free.
json_t * GNUNET_JSON_from_data(const void *data, size_t size)
Convert binary data to a JSON string with the base32crockford encoding.
Here is the call graph for this function:

◆ GNUNET_JSON_from_gnsrecord()

json_t* GNUNET_JSON_from_gnsrecord ( const char *  rname,
const struct GNUNET_GNSRECORD_Data rd,
unsigned int  rd_count 
)

Convert Gns record to JSON.

Parameters
rnamename of record
rdrecord data
Returns
corresponding JSON encoding

Convert Gns record to JSON.

Parameters
rnamename of record
rdrecord data
Returns
corresponding JSON encoding

Definition at line 173 of file json_generator.c.

References data, data_size, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNSRECORD_number_to_typename(), GNUNET_GNSRECORD_record_get_expiration_time(), GNUNET_GNSRECORD_value_to_string(), GNUNET_log, GNUNET_STRINGS_absolute_time_to_string(), record(), and records.

Referenced by handle_gns_response(), and namestore_list_iteration().

176 {
177  struct GNUNET_TIME_Absolute expiration_time;
178  const char *expiration_time_str;
179  const char *record_type_str;
180  char *value_str;
181  json_t *data;
182  json_t *record;
183  json_t *records;
184 
185  data = json_object ();
186  json_object_set_new (data,
187  "record_name",
188  json_string (rname));
189  records = json_array ();
190  for (int i = 0; i < rd_count; i++)
191  {
192  value_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
193  rd[i].data,
194  rd[i].data_size);
195  expiration_time = GNUNET_GNSRECORD_record_get_expiration_time (1, &rd[i]);
196  expiration_time_str = GNUNET_STRINGS_absolute_time_to_string (
197  expiration_time);
198  record_type_str = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
200  "Packing %s %s %s %d\n",
201  value_str, record_type_str, expiration_time_str, rd[i].flags);
202  record = json_pack ("{s:s,s:s,s:s,s:i}",
203  "value",
204  value_str,
205  "record_type",
206  record_type_str,
207  "expiration_time",
208  expiration_time_str,
209  "flag",
210  rd[i].flags);
211  GNUNET_assert (NULL != record);
212  GNUNET_free (value_str);
213  json_array_append_new (records, record);
214  }
215  json_object_set_new (data, "data", records);
216  return data;
217 }
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static unsigned int records
Number of records we found.
struct GNUNET_TIME_Absolute GNUNET_GNSRECORD_record_get_expiration_time(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Returns the expiration time of the given block of records.
#define GNUNET_log(kind,...)
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
Time for absolute times used by GNUnet, in microseconds.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:742
uint32_t data
The data value.
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the &#39;value&#39; of a record to a string.
Definition: gnsrecord.c:143
const char * GNUNET_GNSRECORD_number_to_typename(uint32_t type)
Convert a type number (i.e.
Definition: gnsrecord.c:231
#define GNUNET_free(ptr)
Wrapper around free.
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 264 of file json_mhd.c.

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.

270 {
271  struct Buffer *r = *con_cls;
272  const char *ce;
273  int ret;
274 
275  *json = NULL;
276  if (NULL == *con_cls)
277  {
278  /* We are seeing a fresh POST request. */
279  r = GNUNET_new (struct Buffer);
280  if (GNUNET_OK != buffer_init (r,
281  upload_data,
282  *upload_data_size,
284  buffer_max))
285  {
286  *con_cls = NULL;
287  buffer_deinit (r);
288  GNUNET_free (r);
290  }
291  /* everything OK, wait for more POST data */
292  *upload_data_size = 0;
293  *con_cls = r;
295  }
296  if (0 != *upload_data_size)
297  {
298  /* We are seeing an old request with more data available. */
299 
300  if (GNUNET_OK !=
301  buffer_append (r, upload_data, *upload_data_size, buffer_max))
302  {
303  /* Request too long */
304  *con_cls = NULL;
305  buffer_deinit (r);
306  GNUNET_free (r);
308  }
309  /* everything OK, wait for more POST data */
310  *upload_data_size = 0;
312  }
313 
314  /* We have seen the whole request. */
315  ce = MHD_lookup_connection_value (connection,
316  MHD_HEADER_KIND,
317  MHD_HTTP_HEADER_CONTENT_ENCODING);
318  if ((NULL != ce) && (0 == strcasecmp ("deflate", ce)))
319  {
320  ret = inflate_data (r);
321  if (GNUNET_JSON_PR_SUCCESS != ret)
322  {
323  buffer_deinit (r);
324  GNUNET_free (r);
325  *con_cls = NULL;
326  return ret;
327  }
328  }
329 
330  *json = json_loadb (r->data, r->fill, 0, NULL);
331  if (NULL == *json)
332  {
334  "Failed to parse JSON request body\n");
335  buffer_deinit (r);
336  GNUNET_free (r);
337  *con_cls = NULL;
339  }
340  buffer_deinit (r);
341  GNUNET_free (r);
342  *con_cls = NULL;
343 
344  return GNUNET_JSON_PR_SUCCESS;
345 }
JSON parsing failed.
static enum GNUNET_JSON_PostResult inflate_data(struct Buffer *buf)
Decompress data in buf.
Definition: json_mhd.c:156
Buffer for POST requests.
Definition: json_mhd.c:43
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
size_t fill
Number of valid bytes in buffer.
Definition: json_mhd.c:53
Parsing successful, JSON result is in *json.
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
Sorry, memory allocation (malloc()) failed.
Request size exceeded buffer_max argument.
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
char * data
Allocated memory.
Definition: json_mhd.c:48
#define REQUEST_BUFFER_INITIAL
Initial size for POST request buffers.
Definition: json_mhd.c:37
Parsing continues, call again soon!
#define GNUNET_log(kind,...)
static void buffer_deinit(struct Buffer *buf)
Free the data in a buffer.
Definition: json_mhd.c:104
#define GNUNET_free(ptr)
Wrapper around free.
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 356 of file json_mhd.c.

References buffer_deinit(), and GNUNET_free.

357 {
358  struct Buffer *r = con_cls;
359 
360  if (NULL != r)
361  {
362  buffer_deinit (r);
363  GNUNET_free (r);
364  }
365 }
Buffer for POST requests.
Definition: json_mhd.c:43
static void buffer_deinit(struct Buffer *buf)
Free the data in a buffer.
Definition: json_mhd.c:104
#define GNUNET_free(ptr)
Wrapper around 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 153 of file json.c.

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

158 {
160  .name = name,
161  .argumentHelp = argumentHelp,
162  .description = description,
163  .require_argument = 1,
164  .processor = &set_json,
165  .scls = (void *) json };
166 
167  return clo;
168 }
const char * argumentHelp
Name of the argument for the user in help text.
const char * description
Help text for the option (description)
Definition of a command line option.
const char shortName
Short name of the option.
static int 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:121
const char * name
Here is the call graph for this function: