GNUnet 0.22.2
json_reclaim.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_json_lib.h"
#include "gnunet_reclaim_lib.h"
#include "gnunet_reclaim_service.h"
#include "json_reclaim.h"
Include dependency graph for json_reclaim.c:

Go to the source code of this file.

Functions

static int parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a claim. More...
 
static void clean_attr (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing RSA public key. More...
 
struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_attribute (struct GNUNET_RECLAIM_Attribute **attr)
 JSON Specification for Reclaim claims. More...
 
static int parse_ticket (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a ticket. More...
 
static void clean_ticket (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing RSA public key. More...
 
struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket)
 JSON Specification for Reclaim tickets. More...
 
static int parse_credential (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
 Parse given JSON object to a credential claim. More...
 
static void clean_credential (void *cls, struct GNUNET_JSON_Specification *spec)
 Cleanup data left from parsing RSA public key. More...
 
struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_credential (struct GNUNET_RECLAIM_Credential **cred)
 JSON Specification for credential claims. More...
 

Function Documentation

◆ parse_attr()

static int parse_attr ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a claim.

Parameters
clsclosure, NULL
rootthe json object representing data
specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 42 of file json_reclaim.c.

43{
44 struct GNUNET_RECLAIM_Attribute *attr;
45 const char *name_str = NULL;
46 const char *val_str = NULL;
47 const char *type_str = NULL;
48 const char *id_str = NULL;
49 const char *cred_str = NULL;
50 const char *flag_str = NULL;
51 char *data;
52 int unpack_state;
53 uint32_t type;
54 size_t data_size;
55
56 GNUNET_assert (NULL != root);
57
58 if (! json_is_object (root))
59 {
61 "Error json is not array nor object!\n");
62 return GNUNET_SYSERR;
63 }
64 // interpret single attribute
65 unpack_state = json_unpack (root,
66 "{s:s, s?s, s?s, s:s, s:s, s?s!}",
67 "name",
68 &name_str,
69 "id",
70 &id_str,
71 "credential",
72 &cred_str,
73 "type",
74 &type_str,
75 "value",
76 &val_str,
77 "flag",
78 &flag_str);
79 if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) ||
80 (NULL == type_str))
81 {
83 "Error json object has a wrong format!\n");
84 return GNUNET_SYSERR;
85 }
87 if (GNUNET_SYSERR ==
89 val_str,
90 (void **) &data,
91 &data_size)))
92 {
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n");
94 return GNUNET_SYSERR;
95 }
96 attr = GNUNET_RECLAIM_attribute_new (name_str, NULL,
99 if ((NULL != cred_str) && (0 != strlen (cred_str)))
100 {
102 strlen (cred_str),
103 &attr->credential,
104 sizeof(attr->credential));
105 }
106 if ((NULL == id_str) || (0 == strlen (id_str)))
107 memset (&attr->id, 0, sizeof (attr->id));
108 else
110 strlen (id_str),
111 &attr->id,
112 sizeof(attr->id));
113
114 *(struct GNUNET_RECLAIM_Attribute **) spec->ptr = attr;
115 return GNUNET_OK;
116}
static char * data
The data to insert into the dht.
static uint32_t type
Type string converted to DNS type value.
static size_t data_size
Number of bytes in data.
static char * type_str
Attribute type.
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
int GNUNET_RECLAIM_attribute_string_to_value(uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of a 'claim' of an attribute to the binary representation.
struct GNUNET_RECLAIM_Attribute * GNUNET_RECLAIM_attribute_new(const char *attr_name, const struct GNUNET_RECLAIM_Identifier *credential, uint32_t type, const void *data, size_t data_size)
Create a new attribute claim.
uint32_t GNUNET_RECLAIM_attribute_typename_to_number(const char *typename)
Convert a type name to the corresponding number.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:812
void * ptr
Pointer, details specific to the parser.
struct GNUNET_RECLAIM_Identifier credential
Referenced ID of credential (may be GNUNET_RECLAIM_ID_ZERO if self-creded)
struct GNUNET_RECLAIM_Identifier id
ID.

References GNUNET_RECLAIM_Attribute::credential, data, data_size, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_RECLAIM_attribute_new(), GNUNET_RECLAIM_attribute_string_to_value(), GNUNET_RECLAIM_attribute_typename_to_number(), GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, GNUNET_RECLAIM_Attribute::id, GNUNET_JSON_Specification::ptr, type, and type_str.

Referenced by GNUNET_RECLAIM_JSON_spec_attribute().

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

◆ clean_attr()

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

Cleanup data left from parsing RSA public key.

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

Definition at line 126 of file json_reclaim.c.

127{
128 struct GNUNET_RECLAIM_Attribute **attr;
129
130 attr = (struct GNUNET_RECLAIM_Attribute **) spec->ptr;
131 if (NULL != *attr)
132 {
133 GNUNET_free (*attr);
134 *attr = NULL;
135 }
136}

References GNUNET_free, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_RECLAIM_JSON_spec_attribute().

Here is the caller graph for this function:

◆ GNUNET_RECLAIM_JSON_spec_attribute()

struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_attribute ( struct GNUNET_RECLAIM_Attribute **  attr)

JSON Specification for Reclaim claims.

Parameters
ticketstruct of GNUNET_RECLAIM_Attribute to fill
Returns
JSON Specification

Definition at line 146 of file json_reclaim.c.

147{
148 struct GNUNET_JSON_Specification ret = { .parser = &parse_attr,
149 .cleaner = &clean_attr,
150 .cls = NULL,
151 .field = NULL,
152 .ptr = attr,
153 .ptr_size = 0,
154 .size_ptr = NULL };
155
156 *attr = NULL;
157 return ret;
158}
static int ret
Final status code.
Definition: gnunet-arm.c:93
static void clean_attr(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA public key.
Definition: json_reclaim.c:126
static int parse_attr(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a claim.
Definition: json_reclaim.c:42
Entry in parser specification for GNUNET_JSON_parse().

References clean_attr(), parse_attr(), and ret.

Referenced by add_attribute_cont().

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

◆ parse_ticket()

static int parse_ticket ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a ticket.

Parameters
clsclosure, NULL
rootthe json object representing data
specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 170 of file json_reclaim.c.

171{
173 const char *gns_str;
174 int unpack_state;
175
176 GNUNET_assert (NULL != root);
177
178 if (! json_is_object (root))
179 {
181 "Error json is not array nor object!\n");
182 return GNUNET_SYSERR;
183 }
184 // interpret single ticket
185 unpack_state = json_unpack (root,
186 "{s:s}",
187 "gns_name",
188 &gns_str);
189 if (0 != unpack_state)
190 {
192 "Error json object has a wrong format!\n");
193 return GNUNET_SYSERR;
194 }
196 strncpy (ticket->gns_name, gns_str, sizeof (ticket->gns_name));
197
198 *(struct GNUNET_RECLAIM_Ticket **) spec->ptr = ticket;
199 return GNUNET_OK;
200}
static struct GNUNET_RECLAIM_Ticket ticket
Ticket to consume.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
The authorization ticket.
char gns_name[63 *2+2]
The ticket.

References GNUNET_RECLAIM_Ticket::gns_name, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_new, GNUNET_OK, GNUNET_SYSERR, GNUNET_JSON_Specification::ptr, and ticket.

Referenced by GNUNET_RECLAIM_JSON_spec_ticket().

Here is the caller graph for this function:

◆ clean_ticket()

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

Cleanup data left from parsing RSA public key.

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

Definition at line 210 of file json_reclaim.c.

211{
213
214 ticket = (struct GNUNET_RECLAIM_Ticket **) spec->ptr;
215 if (NULL != *ticket)
216 {
218 *ticket = NULL;
219 }
220}

References GNUNET_free, GNUNET_JSON_Specification::ptr, and ticket.

Referenced by GNUNET_RECLAIM_JSON_spec_ticket().

Here is the caller graph for this function:

◆ GNUNET_RECLAIM_JSON_spec_ticket()

struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_ticket ( struct GNUNET_RECLAIM_Ticket **  ticket)

JSON Specification for Reclaim tickets.

Parameters
ticketstruct of GNUNET_RECLAIM_Ticket to fill
Returns
JSON Specification

Definition at line 230 of file json_reclaim.c.

231{
232 struct GNUNET_JSON_Specification ret = { .parser = &parse_ticket,
233 .cleaner = &clean_ticket,
234 .cls = NULL,
235 .field = NULL,
236 .ptr = ticket,
237 .ptr_size = 0,
238 .size_ptr = NULL };
239
240 *ticket = NULL;
241 return ret;
242}
static int parse_ticket(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a ticket.
Definition: json_reclaim.c:170
static void clean_ticket(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA public key.
Definition: json_reclaim.c:210

References clean_ticket(), parse_ticket(), ret, and ticket.

Referenced by consume_ticket_cont(), and revoke_ticket_cont().

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

◆ parse_credential()

static int parse_credential ( void *  cls,
json_t *  root,
struct GNUNET_JSON_Specification spec 
)
static

Parse given JSON object to a credential claim.

Parameters
clsclosure, NULL
rootthe json object representing data
specwhere to write the data
Returns
GNUNET_OK upon successful parsing; GNUNET_SYSERR upon error

Definition at line 254 of file json_reclaim.c.

256{
258 const char *name_str = NULL;
259 const char *type_str = NULL;
260 const char *id_str = NULL;
261 json_t *val_json;
262 char *data = NULL;
263 char *val_str = NULL;
264 int unpack_state;
265 uint32_t type;
266 size_t data_size;
267
268 GNUNET_assert (NULL != root);
269
270 if (! json_is_object (root))
271 {
273 "Error json is not array nor object!\n");
274 return GNUNET_SYSERR;
275 }
276 // interpret single attribute
277 unpack_state = json_unpack (root,
278 "{s:s, s?s, s:s, s:o!}",
279 "name",
280 &name_str,
281 "id",
282 &id_str,
283 "type",
284 &type_str,
285 "value",
286 &val_json);
287 if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_json) ||
288 (NULL == type_str))
289 {
291 "Error json object has a wrong format!\n");
292 return GNUNET_SYSERR;
293 }
294 if (json_is_string (val_json))
295 {
296 val_str = GNUNET_strdup (json_string_value (val_json));
297 }
298 else
299 {
300 val_str = json_dumps (val_json, JSON_COMPACT);
301 }
303 if (GNUNET_SYSERR ==
305 val_str,
306 (void **) &data,
307 &data_size)))
308 {
309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Credential value invalid!\n");
310 return GNUNET_SYSERR;
311 }
314 if ((NULL == id_str) || (0 == strlen (id_str)))
315 memset (&cred->id, 0, sizeof (cred->id));
316 else
318 strlen (id_str),
319 &cred->id,
320 sizeof(cred->id));
321
322 *(struct GNUNET_RECLAIM_Credential **) spec->ptr = cred;
323 return GNUNET_OK;
324}
static gnutls_certificate_credentials_t cred
The credential.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
int GNUNET_RECLAIM_credential_string_to_value(uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of a 'claim' of an credential to the binary representation.
uint32_t GNUNET_RECLAIM_credential_typename_to_number(const char *typename)
Convert an credential type name to the corresponding number.
struct GNUNET_RECLAIM_Credential * GNUNET_RECLAIM_credential_new(const char *name, uint32_t type, const void *data, size_t data_size)
Create a new credential.

References cred, data, data_size, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_RECLAIM_credential_new(), GNUNET_RECLAIM_credential_string_to_value(), GNUNET_RECLAIM_credential_typename_to_number(), GNUNET_strdup, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, GNUNET_JSON_Specification::ptr, type, and type_str.

Referenced by GNUNET_RECLAIM_JSON_spec_credential().

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

◆ clean_credential()

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

Cleanup data left from parsing RSA public key.

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

Definition at line 334 of file json_reclaim.c.

335{
336 struct GNUNET_RECLAIM_Credential **attr;
337
338 attr = (struct GNUNET_RECLAIM_Credential **) spec->ptr;
339 if (NULL != *attr)
340 {
341 GNUNET_free (*attr);
342 *attr = NULL;
343 }
344}

References GNUNET_free, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_RECLAIM_JSON_spec_credential().

Here is the caller graph for this function:

◆ GNUNET_RECLAIM_JSON_spec_credential()

struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_credential ( struct GNUNET_RECLAIM_Credential **  cred)

JSON Specification for credential claims.

JSON Specification for credentials.

Parameters
attrstruct of GNUNET_RECLAIM_Credential to fill
Returns
JSON Specification

Definition at line 354 of file json_reclaim.c.

356{
357 struct GNUNET_JSON_Specification ret = { .parser = &parse_credential,
358 .cleaner = &clean_credential,
359 .cls = NULL,
360 .field = NULL,
361 .ptr = cred,
362 .ptr_size = 0,
363 .size_ptr = NULL };
364
365 *cred = NULL;
366 return ret;
367}
static int parse_credential(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a credential claim.
Definition: json_reclaim.c:254
static void clean_credential(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA public key.
Definition: json_reclaim.c:334

References clean_credential(), cred, parse_credential(), and ret.

Referenced by add_credential_cont().

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