GNUnet  0.11.x
Functions
json_reclaim.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_json_lib.h"
#include "gnunet_reclaim_attribute_lib.h"
#include "gnunet_reclaim_service.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_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **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...
 

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 44 of file json_reclaim.c.

References data, data_size, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_OK, GNUNET_RECLAIM_ATTRIBUTE_claim_new(), GNUNET_RECLAIM_ATTRIBUTE_string_to_value(), GNUNET_RECLAIM_ATTRIBUTE_typename_to_number(), GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, GNUNET_RECLAIM_ATTRIBUTE_Claim::id, GNUNET_JSON_Specification::ptr, type, and type_str.

Referenced by GNUNET_RECLAIM_JSON_spec_claim().

45 {
46  struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr;
47  const char *name_str = NULL;
48  const char *val_str = NULL;
49  const char *type_str = NULL;
50  const char *id_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!}",
67  "name",
68  &name_str,
69  "id",
70  &id_str,
71  "type",
72  &type_str,
73  "value",
74  &val_str);
75  if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) ||
76  (NULL == type_str))
77  {
79  "Error json object has a wrong format!\n");
80  return GNUNET_SYSERR;
81  }
83  if (GNUNET_SYSERR ==
85  val_str,
86  (void **) &data,
87  &data_size)))
88  {
89  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n");
90  return GNUNET_SYSERR;
91  }
92  attr = GNUNET_RECLAIM_ATTRIBUTE_claim_new (name_str, type, data, data_size);
93  if ((NULL == id_str) || (0 == strlen (id_str)))
94  attr->id = 0;
95  else
97  strlen (id_str),
98  &attr->id,
99  sizeof(uint64_t));
100 
101  *(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr = attr;
102  return GNUNET_OK;
103 }
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.
uint32_t GNUNET_RECLAIM_ATTRIBUTE_typename_to_number(const char *typename)
Convert a type name to the corresponding number.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static char * type_str
Attribute type.
void * ptr
Pointer, details specific to the parser.
struct GNUNET_RECLAIM_ATTRIBUTE_Claim * GNUNET_RECLAIM_ATTRIBUTE_claim_new(const char *attr_name, uint32_t type, const void *data, size_t data_size)
Create a new attribute claim.
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint32_t data
The data value.
int 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:952
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 113 of file json_reclaim.c.

References GNUNET_free, and GNUNET_JSON_Specification::ptr.

Referenced by GNUNET_RECLAIM_JSON_spec_claim().

114 {
115  struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr;
116 
117  attr = (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr;
118  if (NULL != *attr)
119  {
120  GNUNET_free (*attr);
121  *attr = NULL;
122  }
123 }
void * ptr
Pointer, details specific to the parser.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GNUNET_RECLAIM_JSON_spec_claim()

struct GNUNET_JSON_Specification GNUNET_RECLAIM_JSON_spec_claim ( struct GNUNET_RECLAIM_ATTRIBUTE_Claim **  attr)

JSON Specification for Reclaim claims.

Parameters
ticketstruct of GNUNET_RECLAIM_ATTRIBUTE_Claim to fill
Returns
JSON Specification

Definition at line 133 of file json_reclaim.c.

References clean_attr(), parse_attr(), GNUNET_JSON_Specification::parser, and ret.

Referenced by add_attribute_cont().

134 {
135  struct GNUNET_JSON_Specification ret = { .parser = &parse_attr,
136  .cleaner = &clean_attr,
137  .cls = NULL,
138  .field = NULL,
139  .ptr = attr,
140  .ptr_size = 0,
141  .size_ptr = NULL };
142 
143  *attr = NULL;
144  return ret;
145 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static void clean_attr(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA public key.
Definition: json_reclaim.c:113
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:44
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 157 of file json_reclaim.c.

References GNUNET_RECLAIM_Ticket::audience, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_new, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, GNUNET_RECLAIM_Ticket::identity, GNUNET_JSON_Specification::ptr, GNUNET_RECLAIM_Ticket::rnd, and ticket.

Referenced by GNUNET_RECLAIM_JSON_spec_ticket().

158 {
160  const char *rnd_str;
161  const char *aud_str;
162  const char *id_str;
163  int unpack_state;
164 
165  GNUNET_assert (NULL != root);
166 
167  if (! json_is_object (root))
168  {
170  "Error json is not array nor object!\n");
171  return GNUNET_SYSERR;
172  }
173  // interpret single ticket
174  unpack_state = json_unpack (root,
175  "{s:s, s:s, s:s!}",
176  "rnd",
177  &rnd_str,
178  "audience",
179  &aud_str,
180  "issuer",
181  &id_str);
182  if (0 != unpack_state)
183  {
185  "Error json object has a wrong format!\n");
186  return GNUNET_SYSERR;
187  }
188  ticket = GNUNET_new (struct GNUNET_RECLAIM_Ticket);
190  strlen (rnd_str),
191  &ticket->rnd,
192  sizeof(uint64_t)))
193  {
194  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Rnd invalid\n");
195  GNUNET_free (ticket);
196  return GNUNET_SYSERR;
197  }
198  if (GNUNET_OK !=
200  strlen (id_str),
201  &ticket->identity,
202  sizeof(
204  {
205  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity invalid\n");
206  GNUNET_free (ticket);
207  return GNUNET_SYSERR;
208  }
209 
210  if (GNUNET_OK !=
212  strlen (aud_str),
213  &ticket->audience,
214  sizeof(struct
216  {
217  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Audience invalid\n");
218  GNUNET_free (ticket);
219  return GNUNET_SYSERR;
220  }
221 
222  *(struct GNUNET_RECLAIM_Ticket **) spec->ptr = ticket;
223  return GNUNET_OK;
224 }
The authorization ticket.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#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.
static struct GNUNET_RECLAIM_Ticket ticket
Ticket to consume.
struct GNUNET_CRYPTO_EcdsaPublicKey identity
The ticket issuer (= the user)
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
uint64_t rnd
The ticket random (NBO)
void * ptr
Pointer, details specific to the parser.
struct GNUNET_CRYPTO_EcdsaPublicKey audience
The ticket audience (= relying party)
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_log(kind,...)
int 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:952
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
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 234 of file json_reclaim.c.

References GNUNET_free, GNUNET_JSON_Specification::ptr, and ticket.

Referenced by GNUNET_RECLAIM_JSON_spec_ticket().

235 {
236  struct GNUNET_RECLAIM_Ticket **ticket;
237 
238  ticket = (struct GNUNET_RECLAIM_Ticket **) spec->ptr;
239  if (NULL != *ticket)
240  {
241  GNUNET_free (*ticket);
242  *ticket = NULL;
243  }
244 }
The authorization ticket.
static struct GNUNET_RECLAIM_Ticket ticket
Ticket to consume.
void * ptr
Pointer, details specific to the parser.
#define GNUNET_free(ptr)
Wrapper around free.
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 254 of file json_reclaim.c.

References clean_ticket(), parse_ticket(), GNUNET_JSON_Specification::parser, ret, and ticket.

Referenced by consume_ticket_cont(), and revoke_ticket_cont().

255 {
256  struct GNUNET_JSON_Specification ret = { .parser = &parse_ticket,
257  .cleaner = &clean_ticket,
258  .cls = NULL,
259  .field = NULL,
260  .ptr = ticket,
261  .ptr_size = 0,
262  .size_ptr = NULL };
263 
264  *ticket = NULL;
265  return ret;
266 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
Entry in parser specification for GNUNET_JSON_parse().
static struct GNUNET_RECLAIM_Ticket ticket
Ticket to consume.
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:157
static void clean_ticket(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA public key.
Definition: json_reclaim.c:234
Here is the call graph for this function:
Here is the caller graph for this function: