aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/json_reclaim.c
diff options
context:
space:
mode:
authorMarkus Voggenreiter <Markus.Voggenreiter@tum.de>2019-10-09 21:10:14 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2020-01-13 13:31:01 +0100
commite6eb523e12729ef1d6a6ee3f140671e5e51d8d1c (patch)
tree746c6b899bc5fdc491ad477463dda3b56295304e /src/reclaim/json_reclaim.c
parent60d2660de243053bc0f41657ad9d67537723276c (diff)
downloadgnunet-e6eb523e12729ef1d6a6ee3f140671e5e51d8d1c.tar.gz
gnunet-e6eb523e12729ef1d6a6ee3f140671e5e51d8d1c.zip
Adapted JSON Conversion and Serialization
Diffstat (limited to 'src/reclaim/json_reclaim.c')
-rw-r--r--src/reclaim/json_reclaim.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/src/reclaim/json_reclaim.c b/src/reclaim/json_reclaim.c
index e029fdfb6..a0016bac8 100644
--- a/src/reclaim/json_reclaim.c
+++ b/src/reclaim/json_reclaim.c
@@ -264,3 +264,113 @@ GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket)
264 *ticket = NULL; 264 *ticket = NULL;
265 return ret; 265 return ret;
266} 266}
267
268/**
269 * Parse given JSON object to an attestation claim
270 *
271 * @param cls closure, NULL
272 * @param root the json object representing data
273 * @param spec where to write the data
274 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
275 */
276static int
277parse_attest (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
278{
279 struct GNUNET_RECLAIM_ATTESTATION_Claim *attr;
280 const char *name_str = NULL;
281 const char *val_str = NULL;
282 const char *type_str = NULL;
283 const char *id_str = NULL;
284 char *data;
285 int unpack_state;
286 uint32_t type;
287 size_t data_size;
288
289 GNUNET_assert (NULL != root);
290
291 if (! json_is_object (root))
292 {
293 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
294 "Error json is not array nor object!\n");
295 return GNUNET_SYSERR;
296 }
297 // interpret single attribute
298 unpack_state = json_unpack (root,
299 "{s:s, s?s, s:s, s:s!}",
300 "name",
301 &name_str,
302 "id",
303 &id_str,
304 "type",
305 &type_str,
306 "value",
307 &val_str);
308 if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) ||
309 (NULL == type_str))
310 {
311 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
312 "Error json object has a wrong format!\n");
313 return GNUNET_SYSERR;
314 }
315 type = GNUNET_RECLAIM_ATTESTATION_typename_to_number (type_str);
316 if (GNUNET_SYSERR ==
317 (GNUNET_RECLAIM_ATTESTATION_string_to_value (type,
318 val_str,
319 (void **) &data,
320 &data_size)))
321 {
322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n");
323 return GNUNET_SYSERR;
324 }
325 attr = GNUNET_RECLAIM_ATTESTATION_claim_new (name_str, type, data, data_size);
326 if ((NULL == id_str) || (0 == strlen (id_str)))
327 attr->id = 0;
328 else
329 GNUNET_STRINGS_string_to_data (id_str,
330 strlen (id_str),
331 &attr->id,
332 sizeof(uint64_t));
333
334 *(struct GNUNET_RECLAIM_ATTESTATION_Claim **) spec->ptr = attr;
335 return GNUNET_OK;
336}
337
338/**
339 * Cleanup data left from parsing RSA public key.
340 *
341 * @param cls closure, NULL
342 * @param[out] spec where to free the data
343 */
344static void
345clean_attest (void *cls, struct GNUNET_JSON_Specification *spec)
346{
347 struct GNUNET_RECLAIM_ATTESTATION_Claim **attr;
348
349 attr = (struct GNUNET_RECLAIM_ATTESTATION_Claim **) spec->ptr;
350 if (NULL != *attr)
351 {
352 GNUNET_free (*attr);
353 *attr = NULL;
354 }
355}
356/**
357 * JSON Specification for Reclaim attestation claims.
358 *
359 * @param ticket struct of GNUNET_RECLAIM_ATTESTATION_Claim to fill
360 * @return JSON Specification
361 */
362struct GNUNET_JSON_Specification
363GNUNET_RECLAIM_JSON_spec_claim_attest (struct
364 GNUNET_RECLAIM_ATTESTATION_Claim **attr)
365{
366 struct GNUNET_JSON_Specification ret = { .parser = &parse_attest,
367 .cleaner = &clean_attest,
368 .cls = NULL,
369 .field = NULL,
370 .ptr = attr,
371 .ptr_size = 0,
372 .size_ptr = NULL };
373
374 *attr = NULL;
375 return ret;
376}