aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/json_reclaim.c
diff options
context:
space:
mode:
authorxrs <xrs@mail36.net>2020-01-16 17:12:09 +0100
committerxrs <xrs@mail36.net>2020-01-16 17:12:09 +0100
commit32b55237f2b94b4940d7031a0bc1adcf8b63824a (patch)
tree92766aa532ef2c674192dc3bd0e9b71a99829fa1 /src/reclaim/json_reclaim.c
parentec78709681261eaddedbed6484dd95849f180f92 (diff)
parent5177efb74f9301bbffd79d63f47eb78611e6abba (diff)
downloadgnunet-32b55237f2b94b4940d7031a0bc1adcf8b63824a.tar.gz
gnunet-32b55237f2b94b4940d7031a0bc1adcf8b63824a.zip
Merge branch 'master' of ssh://git.gnunet.org/gnunet
Diffstat (limited to 'src/reclaim/json_reclaim.c')
-rw-r--r--src/reclaim/json_reclaim.c221
1 files changed, 219 insertions, 2 deletions
diff --git a/src/reclaim/json_reclaim.c b/src/reclaim/json_reclaim.c
index e029fdfb6..a464a9088 100644
--- a/src/reclaim/json_reclaim.c
+++ b/src/reclaim/json_reclaim.c
@@ -48,6 +48,7 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
48 const char *val_str = NULL; 48 const char *val_str = NULL;
49 const char *type_str = NULL; 49 const char *type_str = NULL;
50 const char *id_str = NULL; 50 const char *id_str = NULL;
51 const char *flag_str = NULL;
51 char *data; 52 char *data;
52 int unpack_state; 53 int unpack_state;
53 uint32_t type; 54 uint32_t type;
@@ -63,7 +64,7 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
63 } 64 }
64 // interpret single attribute 65 // interpret single attribute
65 unpack_state = json_unpack (root, 66 unpack_state = json_unpack (root,
66 "{s:s, s?s, s:s, s:s!}", 67 "{s:s, s?s, s:s, s:s, s?s!}",
67 "name", 68 "name",
68 &name_str, 69 &name_str,
69 "id", 70 "id",
@@ -71,7 +72,9 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
71 "type", 72 "type",
72 &type_str, 73 &type_str,
73 "value", 74 "value",
74 &val_str); 75 &val_str,
76 "flag",
77 &flag_str);
75 if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) || 78 if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) ||
76 (NULL == type_str)) 79 (NULL == type_str))
77 { 80 {
@@ -264,3 +267,217 @@ GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket)
264 *ticket = NULL; 267 *ticket = NULL;
265 return ret; 268 return ret;
266} 269}
270
271/**
272 * Parse given JSON object to an attestation claim
273 *
274 * @param cls closure, NULL
275 * @param root the json object representing data
276 * @param spec where to write the data
277 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
278 */
279static int
280parse_attest (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
281{
282 struct GNUNET_RECLAIM_ATTESTATION_Claim *attr;
283 const char *name_str = NULL;
284 const char *val_str = NULL;
285 const char *type_str = NULL;
286 const char *id_str = NULL;
287 char *data;
288 int unpack_state;
289 uint32_t type;
290 size_t data_size;
291
292 GNUNET_assert (NULL != root);
293
294 if (! json_is_object (root))
295 {
296 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
297 "Error json is not array nor object!\n");
298 return GNUNET_SYSERR;
299 }
300 // interpret single attribute
301 unpack_state = json_unpack (root,
302 "{s:s, s?s, s:s, s:s!}",
303 "name",
304 &name_str,
305 "id",
306 &id_str,
307 "type",
308 &type_str,
309 "value",
310 &val_str);
311 if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) ||
312 (NULL == type_str))
313 {
314 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
315 "Error json object has a wrong format!\n");
316 return GNUNET_SYSERR;
317 }
318 type = GNUNET_RECLAIM_ATTESTATION_typename_to_number (type_str);
319 if (GNUNET_SYSERR ==
320 (GNUNET_RECLAIM_ATTESTATION_string_to_value (type,
321 val_str,
322 (void **) &data,
323 &data_size)))
324 {
325 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attestation value invalid!\n");
326 return GNUNET_SYSERR;
327 }
328 attr = GNUNET_RECLAIM_ATTESTATION_claim_new (name_str, type, data, data_size);
329 if ((NULL == id_str) || (0 == strlen (id_str)))
330 attr->id = 0;
331 else
332 GNUNET_STRINGS_string_to_data (id_str,
333 strlen (id_str),
334 &attr->id,
335 sizeof(uint64_t));
336
337 *(struct GNUNET_RECLAIM_ATTESTATION_Claim **) spec->ptr = attr;
338 return GNUNET_OK;
339}
340
341/**
342 * Cleanup data left from parsing RSA public key.
343 *
344 * @param cls closure, NULL
345 * @param[out] spec where to free the data
346 */
347static void
348clean_attest (void *cls, struct GNUNET_JSON_Specification *spec)
349{
350 struct GNUNET_RECLAIM_ATTESTATION_Claim **attr;
351
352 attr = (struct GNUNET_RECLAIM_ATTESTATION_Claim **) spec->ptr;
353 if (NULL != *attr)
354 {
355 GNUNET_free (*attr);
356 *attr = NULL;
357 }
358}
359/**
360 * JSON Specification for Reclaim attestation claims.
361 *
362 * @param ticket struct of GNUNET_RECLAIM_ATTESTATION_Claim to fill
363 * @return JSON Specification
364 */
365struct GNUNET_JSON_Specification
366GNUNET_RECLAIM_JSON_spec_claim_attest (struct
367 GNUNET_RECLAIM_ATTESTATION_Claim **attr)
368{
369 struct GNUNET_JSON_Specification ret = { .parser = &parse_attest,
370 .cleaner = &clean_attest,
371 .cls = NULL,
372 .field = NULL,
373 .ptr = attr,
374 .ptr_size = 0,
375 .size_ptr = NULL };
376
377 *attr = NULL;
378 return ret;
379}
380
381/**
382 * Parse given JSON object to an attestation claim
383 *
384 * @param cls closure, NULL
385 * @param root the json object representing data
386 * @param spec where to write the data
387 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
388 */
389static int
390parse_attest_ref (void *cls, json_t *root, struct
391 GNUNET_JSON_Specification *spec)
392{
393 struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr;
394 const char *name_str = NULL;
395 const char *ref_val_str = NULL;
396 const char *ref_id_str = NULL;
397 const char *id_str = NULL;
398 int unpack_state;
399
400 GNUNET_assert (NULL != root);
401
402 if (! json_is_object (root))
403 {
404 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
405 "Error json is not array nor object!\n");
406 return GNUNET_SYSERR;
407 }
408 // interpret single reference
409 unpack_state = json_unpack (root,
410 "{s:s, s?s, s:s, s:s!}",
411 "name",
412 &name_str,
413 "id",
414 &id_str,
415 "ref_id",
416 &ref_id_str,
417 "ref_value",
418 &ref_val_str);
419 if ((0 != unpack_state) || (NULL == name_str) || (NULL == ref_val_str) ||
420 (NULL == ref_id_str))
421 {
422 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
423 "Error json object has a wrong format!\n");
424 return GNUNET_SYSERR;
425 }
426
427 attr = GNUNET_RECLAIM_ATTESTATION_reference_new (name_str, ref_val_str);
428
429 attr->id = 0;
430
431 if ((NULL == ref_id_str) || (0 == strlen (ref_id_str)))
432 attr->id_attest = 0;
433 else
434 GNUNET_STRINGS_string_to_data (ref_id_str,
435 strlen (ref_id_str),
436 &attr->id_attest,
437 sizeof(uint64_t));
438
439 *(struct GNUNET_RECLAIM_ATTESTATION_REFERENCE **) spec->ptr = attr;
440 return GNUNET_OK;
441}
442
443/**
444 * Cleanup data left from parsing RSA public key.
445 *
446 * @param cls closure, NULL
447 * @param[out] spec where to free the data
448 */
449static void
450clean_attest_ref (void *cls, struct GNUNET_JSON_Specification *spec)
451{
452 struct GNUNET_RECLAIM_ATTESTATION_REFERENCE **attr;
453
454 attr = (struct GNUNET_RECLAIM_ATTESTATION_REFERENCE **) spec->ptr;
455 if (NULL != *attr)
456 {
457 GNUNET_free (*attr);
458 *attr = NULL;
459 }
460}
461
462/**
463 * JSON Specification for Reclaim attestation references.
464 *
465 * @param ticket struct of GNUNET_RECLAIM_ATTESTATION_REFERENCE to fill
466 * @return JSON Specification
467 */
468struct GNUNET_JSON_Specification
469GNUNET_RECLAIM_JSON_spec_claim_attest_ref (struct
470 GNUNET_RECLAIM_ATTESTATION_REFERENCE
471 **attr)
472{
473 struct GNUNET_JSON_Specification ret = { .parser = &parse_attest_ref,
474 .cleaner = &clean_attest_ref,
475 .cls = NULL,
476 .field = NULL,
477 .ptr = attr,
478 .ptr_size = 0,
479 .size_ptr = NULL };
480
481 *attr = NULL;
482 return ret;
483} \ No newline at end of file