diff options
author | Markus Voggenreiter <Markus.Voggenreiter@tum.de> | 2019-10-23 21:50:46 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-01-13 13:31:03 +0100 |
commit | bb286cb253251e8210ed686dbde3dc8ecee16420 (patch) | |
tree | 4e7f625480adb0397df002f6e26bb6a3755ff3cc /src/reclaim/plugin_rest_reclaim.c | |
parent | c136a16600cd4f72d7def1af7b4aa7592310c898 (diff) | |
download | gnunet-bb286cb253251e8210ed686dbde3dc8ecee16420.tar.gz gnunet-bb286cb253251e8210ed686dbde3dc8ecee16420.zip |
Preparation for Reference Type
Diffstat (limited to 'src/reclaim/plugin_rest_reclaim.c')
-rw-r--r-- | src/reclaim/plugin_rest_reclaim.c | 94 |
1 files changed, 93 insertions, 1 deletions
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index 5908a38dd..b52cf9650 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c | |||
@@ -455,13 +455,105 @@ ticket_collect (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | |||
455 | 455 | ||
456 | 456 | ||
457 | static void | 457 | static void |
458 | add_attestation_ref_cont (struct GNUNET_REST_RequestHandle *con_handle, | ||
459 | const char *url, | ||
460 | void *cls) | ||
461 | { | ||
462 | struct RequestHandle *handle = cls; | ||
463 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; | ||
464 | const char *identity; | ||
465 | struct EgoEntry *ego_entry; | ||
466 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attribute; | ||
467 | struct GNUNET_TIME_Relative exp; | ||
468 | char term_data[handle->rest_handle->data_size + 1]; | ||
469 | json_t *data_json; | ||
470 | json_error_t err; | ||
471 | struct GNUNET_JSON_Specification attrspec[] = | ||
472 | { GNUNET_RECLAIM_JSON_spec_claim_attest_ref (&attribute), | ||
473 | GNUNET_JSON_spec_end () }; | ||
474 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
475 | "Adding an attestation reference for %s.\n", | ||
476 | handle->url); | ||
477 | if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + strlen ( | ||
478 | "reference/") + 1 >= strlen ( | ||
479 | handle->url)) | ||
480 | { | ||
481 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); | ||
482 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
483 | return; | ||
484 | } | ||
485 | identity = handle->url + strlen ( | ||
486 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + strlen ("reference/") + 1; | ||
487 | for (ego_entry = handle->ego_head; NULL != ego_entry; | ||
488 | ego_entry = ego_entry->next) | ||
489 | if (0 == strcmp (identity, ego_entry->identifier)) | ||
490 | break; | ||
491 | if (NULL == ego_entry) | ||
492 | { | ||
493 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Identity unknown (%s)\n", identity); | ||
494 | return; | ||
495 | } | ||
496 | identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | ||
497 | if (0 >= handle->rest_handle->data_size) | ||
498 | { | ||
499 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
500 | return; | ||
501 | } | ||
502 | |||
503 | term_data[handle->rest_handle->data_size] = '\0'; | ||
504 | GNUNET_memcpy (term_data, | ||
505 | handle->rest_handle->data, | ||
506 | handle->rest_handle->data_size); | ||
507 | data_json = json_loads (term_data, JSON_DECODE_ANY, &err); | ||
508 | GNUNET_assert (GNUNET_OK == | ||
509 | GNUNET_JSON_parse (data_json, attrspec, NULL, NULL)); | ||
510 | json_decref (data_json); | ||
511 | if (NULL == attribute) | ||
512 | { | ||
513 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
514 | "Unable to parse attestation reference from %s\n", | ||
515 | term_data); | ||
516 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
517 | return; | ||
518 | } | ||
519 | /** | ||
520 | * New ID for attribute | ||
521 | */ | ||
522 | if (0 == attribute->id) | ||
523 | attribute->id = attribute->id_attest; | ||
524 | handle->idp = GNUNET_RECLAIM_connect (cfg); | ||
525 | exp = GNUNET_TIME_UNIT_HOURS; | ||
526 | handle->idp_op = GNUNET_RECLAIM_attestation_reference_store (handle->idp, | ||
527 | identity_priv, | ||
528 | attribute, | ||
529 | &exp, | ||
530 | &finished_cont, | ||
531 | handle); | ||
532 | GNUNET_JSON_parse_free (attrspec); | ||
533 | } | ||
534 | |||
535 | |||
536 | static void | ||
458 | add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | 537 | add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, |
459 | const char *url, | 538 | const char *url, |
460 | void *cls) | 539 | void *cls) |
461 | { | 540 | { |
541 | struct RequestHandle *handle = cls; | ||
542 | /* Check for substring "reference" */ | ||
543 | if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) < strlen ( | ||
544 | handle->url)) | ||
545 | { | ||
546 | if ( strncmp ("reference/", (handle->url + strlen ( | ||
547 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) | ||
548 | + 1), strlen ( | ||
549 | "reference/")) == 0) | ||
550 | { | ||
551 | add_attestation_ref_cont (con_handle,url,cls); | ||
552 | return; | ||
553 | } | ||
554 | } | ||
462 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; | 555 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity_priv; |
463 | const char *identity; | 556 | const char *identity; |
464 | struct RequestHandle *handle = cls; | ||
465 | struct EgoEntry *ego_entry; | 557 | struct EgoEntry *ego_entry; |
466 | struct GNUNET_RECLAIM_ATTESTATION_Claim *attribute; | 558 | struct GNUNET_RECLAIM_ATTESTATION_Claim *attribute; |
467 | struct GNUNET_TIME_Relative exp; | 559 | struct GNUNET_TIME_Relative exp; |