diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-02-04 18:42:04 +0100 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-02-09 20:38:10 +0100 |
commit | 55f6d26b7424d660c99bc89f3677b20294e87a27 (patch) | |
tree | a8080fdcf0d9688c154417e50c58055e364f8b6b /src/reclaim/json_reclaim.c | |
parent | 5b6bb2ce4d60635b2af950d72b45f12686fd5218 (diff) | |
download | gnunet-55f6d26b7424d660c99bc89f3677b20294e87a27.tar.gz gnunet-55f6d26b7424d660c99bc89f3677b20294e87a27.zip |
Refactoring reclaim attestations
Diffstat (limited to 'src/reclaim/json_reclaim.c')
-rw-r--r-- | src/reclaim/json_reclaim.c | 149 |
1 files changed, 29 insertions, 120 deletions
diff --git a/src/reclaim/json_reclaim.c b/src/reclaim/json_reclaim.c index 6ac60a704..4c08430e7 100644 --- a/src/reclaim/json_reclaim.c +++ b/src/reclaim/json_reclaim.c | |||
@@ -43,11 +43,12 @@ | |||
43 | static int | 43 | static int |
44 | parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | 44 | parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) |
45 | { | 45 | { |
46 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; | 46 | struct GNUNET_RECLAIM_Attribute *attr; |
47 | const char *name_str = NULL; | 47 | const char *name_str = NULL; |
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 *attest_str = NULL; | ||
51 | const char *flag_str = NULL; | 52 | const char *flag_str = NULL; |
52 | char *data; | 53 | char *data; |
53 | int unpack_state; | 54 | int unpack_state; |
@@ -64,11 +65,13 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
64 | } | 65 | } |
65 | // interpret single attribute | 66 | // interpret single attribute |
66 | unpack_state = json_unpack (root, | 67 | unpack_state = json_unpack (root, |
67 | "{s:s, s?s, s:s, s:s, s?s!}", | 68 | "{s:s, s?s, s?s, s:s, s:s, s?s!}", |
68 | "name", | 69 | "name", |
69 | &name_str, | 70 | &name_str, |
70 | "id", | 71 | "id", |
71 | &id_str, | 72 | &id_str, |
73 | "attestation", | ||
74 | &attest_str, | ||
72 | "type", | 75 | "type", |
73 | &type_str, | 76 | &type_str, |
74 | "value", | 77 | "value", |
@@ -82,9 +85,9 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
82 | "Error json object has a wrong format!\n"); | 85 | "Error json object has a wrong format!\n"); |
83 | return GNUNET_SYSERR; | 86 | return GNUNET_SYSERR; |
84 | } | 87 | } |
85 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); | 88 | type = GNUNET_RECLAIM_attribute_typename_to_number (type_str); |
86 | if (GNUNET_SYSERR == | 89 | if (GNUNET_SYSERR == |
87 | (GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type, | 90 | (GNUNET_RECLAIM_attribute_string_to_value (type, |
88 | val_str, | 91 | val_str, |
89 | (void **) &data, | 92 | (void **) &data, |
90 | &data_size))) | 93 | &data_size))) |
@@ -92,7 +95,15 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
92 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n"); | 95 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n"); |
93 | return GNUNET_SYSERR; | 96 | return GNUNET_SYSERR; |
94 | } | 97 | } |
95 | attr = GNUNET_RECLAIM_ATTRIBUTE_claim_new (name_str, type, data, data_size); | 98 | attr = GNUNET_RECLAIM_attribute_new (name_str, NULL, |
99 | type, data, data_size); | ||
100 | if ((NULL != attest_str) && (0 != strlen (attest_str))) | ||
101 | { | ||
102 | GNUNET_STRINGS_string_to_data (attest_str, | ||
103 | strlen (attest_str), | ||
104 | &attr->attestation, | ||
105 | sizeof(attr->attestation)); | ||
106 | } | ||
96 | if ((NULL == id_str) || (0 == strlen (id_str))) | 107 | if ((NULL == id_str) || (0 == strlen (id_str))) |
97 | memset (&attr->id, 0, sizeof (attr->id)); | 108 | memset (&attr->id, 0, sizeof (attr->id)); |
98 | else | 109 | else |
@@ -101,7 +112,7 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
101 | &attr->id, | 112 | &attr->id, |
102 | sizeof(attr->id)); | 113 | sizeof(attr->id)); |
103 | 114 | ||
104 | *(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr = attr; | 115 | *(struct GNUNET_RECLAIM_Attribute **) spec->ptr = attr; |
105 | return GNUNET_OK; | 116 | return GNUNET_OK; |
106 | } | 117 | } |
107 | 118 | ||
@@ -115,9 +126,9 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
115 | static void | 126 | static void |
116 | clean_attr (void *cls, struct GNUNET_JSON_Specification *spec) | 127 | clean_attr (void *cls, struct GNUNET_JSON_Specification *spec) |
117 | { | 128 | { |
118 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr; | 129 | struct GNUNET_RECLAIM_Attribute **attr; |
119 | 130 | ||
120 | attr = (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr; | 131 | attr = (struct GNUNET_RECLAIM_Attribute **) spec->ptr; |
121 | if (NULL != *attr) | 132 | if (NULL != *attr) |
122 | { | 133 | { |
123 | GNUNET_free (*attr); | 134 | GNUNET_free (*attr); |
@@ -129,11 +140,11 @@ clean_attr (void *cls, struct GNUNET_JSON_Specification *spec) | |||
129 | /** | 140 | /** |
130 | * JSON Specification for Reclaim claims. | 141 | * JSON Specification for Reclaim claims. |
131 | * | 142 | * |
132 | * @param ticket struct of GNUNET_RECLAIM_ATTRIBUTE_Claim to fill | 143 | * @param ticket struct of GNUNET_RECLAIM_Attribute to fill |
133 | * @return JSON Specification | 144 | * @return JSON Specification |
134 | */ | 145 | */ |
135 | struct GNUNET_JSON_Specification | 146 | struct GNUNET_JSON_Specification |
136 | GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr) | 147 | GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_Attribute **attr) |
137 | { | 148 | { |
138 | struct GNUNET_JSON_Specification ret = { .parser = &parse_attr, | 149 | struct GNUNET_JSON_Specification ret = { .parser = &parse_attr, |
139 | .cleaner = &clean_attr, | 150 | .cleaner = &clean_attr, |
@@ -279,7 +290,7 @@ GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket) | |||
279 | static int | 290 | static int |
280 | parse_attest (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | 291 | parse_attest (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) |
281 | { | 292 | { |
282 | struct GNUNET_RECLAIM_ATTESTATION_Claim *attr; | 293 | struct GNUNET_RECLAIM_Attestation *attr; |
283 | const char *name_str = NULL; | 294 | const char *name_str = NULL; |
284 | const char *val_str = NULL; | 295 | const char *val_str = NULL; |
285 | const char *type_str = NULL; | 296 | const char *type_str = NULL; |
@@ -315,9 +326,9 @@ parse_attest (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
315 | "Error json object has a wrong format!\n"); | 326 | "Error json object has a wrong format!\n"); |
316 | return GNUNET_SYSERR; | 327 | return GNUNET_SYSERR; |
317 | } | 328 | } |
318 | type = GNUNET_RECLAIM_ATTESTATION_typename_to_number (type_str); | 329 | type = GNUNET_RECLAIM_attestation_typename_to_number (type_str); |
319 | if (GNUNET_SYSERR == | 330 | if (GNUNET_SYSERR == |
320 | (GNUNET_RECLAIM_ATTESTATION_string_to_value (type, | 331 | (GNUNET_RECLAIM_attestation_string_to_value (type, |
321 | val_str, | 332 | val_str, |
322 | (void **) &data, | 333 | (void **) &data, |
323 | &data_size))) | 334 | &data_size))) |
@@ -325,7 +336,7 @@ parse_attest (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attestation value invalid!\n"); | 336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attestation value invalid!\n"); |
326 | return GNUNET_SYSERR; | 337 | return GNUNET_SYSERR; |
327 | } | 338 | } |
328 | attr = GNUNET_RECLAIM_ATTESTATION_claim_new (name_str, type, data, data_size); | 339 | attr = GNUNET_RECLAIM_attestation_new (name_str, type, data, data_size); |
329 | if ((NULL == id_str) || (0 == strlen (id_str))) | 340 | if ((NULL == id_str) || (0 == strlen (id_str))) |
330 | memset (&attr->id, 0, sizeof (attr->id)); | 341 | memset (&attr->id, 0, sizeof (attr->id)); |
331 | else | 342 | else |
@@ -334,7 +345,7 @@ parse_attest (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
334 | &attr->id, | 345 | &attr->id, |
335 | sizeof(attr->id)); | 346 | sizeof(attr->id)); |
336 | 347 | ||
337 | *(struct GNUNET_RECLAIM_ATTESTATION_Claim **) spec->ptr = attr; | 348 | *(struct GNUNET_RECLAIM_Attestation **) spec->ptr = attr; |
338 | return GNUNET_OK; | 349 | return GNUNET_OK; |
339 | } | 350 | } |
340 | 351 | ||
@@ -347,9 +358,9 @@ parse_attest (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
347 | static void | 358 | static void |
348 | clean_attest (void *cls, struct GNUNET_JSON_Specification *spec) | 359 | clean_attest (void *cls, struct GNUNET_JSON_Specification *spec) |
349 | { | 360 | { |
350 | struct GNUNET_RECLAIM_ATTESTATION_Claim **attr; | 361 | struct GNUNET_RECLAIM_Attestation **attr; |
351 | 362 | ||
352 | attr = (struct GNUNET_RECLAIM_ATTESTATION_Claim **) spec->ptr; | 363 | attr = (struct GNUNET_RECLAIM_Attestation **) spec->ptr; |
353 | if (NULL != *attr) | 364 | if (NULL != *attr) |
354 | { | 365 | { |
355 | GNUNET_free (*attr); | 366 | GNUNET_free (*attr); |
@@ -364,7 +375,7 @@ clean_attest (void *cls, struct GNUNET_JSON_Specification *spec) | |||
364 | */ | 375 | */ |
365 | struct GNUNET_JSON_Specification | 376 | struct GNUNET_JSON_Specification |
366 | GNUNET_RECLAIM_JSON_spec_claim_attest (struct | 377 | GNUNET_RECLAIM_JSON_spec_claim_attest (struct |
367 | GNUNET_RECLAIM_ATTESTATION_Claim **attr) | 378 | GNUNET_RECLAIM_Attestation **attr) |
368 | { | 379 | { |
369 | struct GNUNET_JSON_Specification ret = { .parser = &parse_attest, | 380 | struct GNUNET_JSON_Specification ret = { .parser = &parse_attest, |
370 | .cleaner = &clean_attest, | 381 | .cleaner = &clean_attest, |
@@ -378,105 +389,3 @@ GNUNET_RECLAIM_JSON_spec_claim_attest (struct | |||
378 | return ret; | 389 | return ret; |
379 | } | 390 | } |
380 | 391 | ||
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 | */ | ||
389 | static int | ||
390 | parse_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 | memset (&attr->id, 0, sizeof (attr->id)); | ||
429 | |||
430 | if ((NULL == ref_id_str) || (0 == strlen (ref_id_str))) | ||
431 | memset (&attr->id_attest, 0, sizeof (attr->id_attest)); | ||
432 | else | ||
433 | GNUNET_STRINGS_string_to_data (ref_id_str, | ||
434 | strlen (ref_id_str), | ||
435 | &attr->id_attest, | ||
436 | sizeof(attr->id_attest)); | ||
437 | |||
438 | *(struct GNUNET_RECLAIM_ATTESTATION_REFERENCE **) spec->ptr = attr; | ||
439 | return GNUNET_OK; | ||
440 | } | ||
441 | |||
442 | /** | ||
443 | * Cleanup data left from parsing RSA public key. | ||
444 | * | ||
445 | * @param cls closure, NULL | ||
446 | * @param[out] spec where to free the data | ||
447 | */ | ||
448 | static void | ||
449 | clean_attest_ref (void *cls, struct GNUNET_JSON_Specification *spec) | ||
450 | { | ||
451 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE **attr; | ||
452 | |||
453 | attr = (struct GNUNET_RECLAIM_ATTESTATION_REFERENCE **) spec->ptr; | ||
454 | if (NULL != *attr) | ||
455 | { | ||
456 | GNUNET_free (*attr); | ||
457 | *attr = NULL; | ||
458 | } | ||
459 | } | ||
460 | |||
461 | /** | ||
462 | * JSON Specification for Reclaim attestation references. | ||
463 | * | ||
464 | * @param ticket struct of GNUNET_RECLAIM_ATTESTATION_REFERENCE to fill | ||
465 | * @return JSON Specification | ||
466 | */ | ||
467 | struct GNUNET_JSON_Specification | ||
468 | GNUNET_RECLAIM_JSON_spec_claim_attest_ref (struct | ||
469 | GNUNET_RECLAIM_ATTESTATION_REFERENCE | ||
470 | **attr) | ||
471 | { | ||
472 | struct GNUNET_JSON_Specification ret = { .parser = &parse_attest_ref, | ||
473 | .cleaner = &clean_attest_ref, | ||
474 | .cls = NULL, | ||
475 | .field = NULL, | ||
476 | .ptr = attr, | ||
477 | .ptr_size = 0, | ||
478 | .size_ptr = NULL }; | ||
479 | |||
480 | *attr = NULL; | ||
481 | return ret; | ||
482 | } | ||