diff options
Diffstat (limited to 'src/rest-plugins/plugin_rest_namestore.c')
-rw-r--r-- | src/rest-plugins/plugin_rest_namestore.c | 193 |
1 files changed, 146 insertions, 47 deletions
diff --git a/src/rest-plugins/plugin_rest_namestore.c b/src/rest-plugins/plugin_rest_namestore.c index 1d72d13ff..2926f4b90 100644 --- a/src/rest-plugins/plugin_rest_namestore.c +++ b/src/rest-plugins/plugin_rest_namestore.c | |||
@@ -458,10 +458,7 @@ namestore_list_finished (void *cls) | |||
458 | handle->list_it = NULL; | 458 | handle->list_it = NULL; |
459 | 459 | ||
460 | if (NULL == handle->resp_object) | 460 | if (NULL == handle->resp_object) |
461 | { | 461 | handle->resp_object = json_array(); |
462 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
463 | return; | ||
464 | } | ||
465 | 462 | ||
466 | result_str = json_dumps (handle->resp_object, 0); | 463 | result_str = json_dumps (handle->resp_object, 0); |
467 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 464 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
@@ -508,6 +505,48 @@ namestore_list_iteration (void *cls, | |||
508 | GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1); | 505 | GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1); |
509 | } | 506 | } |
510 | 507 | ||
508 | /** | ||
509 | * @param cls closure | ||
510 | * @param ego ego handle | ||
511 | * @param ctx context for application to store data for this ego | ||
512 | * (during the lifetime of this process, initially NULL) | ||
513 | * @param identifier identifier assigned by the user for this ego, | ||
514 | * NULL if the user just deleted the ego and it | ||
515 | * must thus no longer be used | ||
516 | */ | ||
517 | static void | ||
518 | default_ego_get (void *cls, | ||
519 | struct GNUNET_IDENTITY_Ego *ego, | ||
520 | void **ctx, | ||
521 | const char *identifier) | ||
522 | { | ||
523 | struct RequestHandle *handle = cls; | ||
524 | handle->op = NULL; | ||
525 | |||
526 | if (ego == NULL) | ||
527 | { | ||
528 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE); | ||
529 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
530 | return; | ||
531 | } | ||
532 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego); | ||
533 | |||
534 | handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, | ||
535 | handle->zone_pkey, | ||
536 | &namestore_iteration_error, | ||
537 | handle, | ||
538 | &namestore_list_iteration, | ||
539 | handle, | ||
540 | &namestore_list_finished, | ||
541 | handle); | ||
542 | if (NULL == handle->list_it) | ||
543 | { | ||
544 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | ||
545 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
546 | return; | ||
547 | } | ||
548 | } | ||
549 | |||
511 | 550 | ||
512 | /** | 551 | /** |
513 | * Handle namestore GET request | 552 | * Handle namestore GET request |
@@ -546,10 +585,13 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle, | |||
546 | { | 585 | { |
547 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); | 586 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key(ego_entry->ego); |
548 | } | 587 | } |
588 | |||
549 | if (NULL == handle->zone_pkey) | 589 | if (NULL == handle->zone_pkey) |
550 | { | 590 | { |
551 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE); | 591 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, |
552 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 592 | "namestore", |
593 | &default_ego_get, | ||
594 | handle); | ||
553 | return; | 595 | return; |
554 | } | 596 | } |
555 | handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, | 597 | handle->list_it = GNUNET_NAMESTORE_zone_iteration_start (handle->ns_handle, |
@@ -570,6 +612,48 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle, | |||
570 | 612 | ||
571 | 613 | ||
572 | /** | 614 | /** |
615 | * @param cls closure | ||
616 | * @param ego ego handle | ||
617 | * @param ctx context for application to store data for this ego | ||
618 | * (during the lifetime of this process, initially NULL) | ||
619 | * @param identifier identifier assigned by the user for this ego, | ||
620 | * NULL if the user just deleted the ego and it | ||
621 | * must thus no longer be used | ||
622 | */ | ||
623 | static void | ||
624 | default_ego_post (void *cls, | ||
625 | struct GNUNET_IDENTITY_Ego *ego, | ||
626 | void **ctx, | ||
627 | const char *identifier) | ||
628 | { | ||
629 | struct RequestHandle *handle = cls; | ||
630 | handle->op = NULL; | ||
631 | |||
632 | if (ego == NULL) | ||
633 | { | ||
634 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE); | ||
635 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
636 | return; | ||
637 | } | ||
638 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego); | ||
639 | |||
640 | handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, | ||
641 | handle->zone_pkey, | ||
642 | handle->record_name, | ||
643 | 1, | ||
644 | handle->rd, | ||
645 | &create_finished, | ||
646 | handle); | ||
647 | if (NULL == handle->add_qe) | ||
648 | { | ||
649 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | ||
650 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
651 | return; | ||
652 | } | ||
653 | } | ||
654 | |||
655 | |||
656 | /** | ||
573 | * Handle namestore POST request | 657 | * Handle namestore POST request |
574 | * | 658 | * |
575 | * @param con_handle the connection handle | 659 | * @param con_handle the connection handle |
@@ -663,17 +747,61 @@ namestore_add (struct GNUNET_REST_RequestHandle *con_handle, | |||
663 | } | 747 | } |
664 | if (NULL == handle->zone_pkey) | 748 | if (NULL == handle->zone_pkey) |
665 | { | 749 | { |
750 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, | ||
751 | "namestore", | ||
752 | &default_ego_post, | ||
753 | handle); | ||
754 | return; | ||
755 | } | ||
756 | handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, | ||
757 | handle->zone_pkey, | ||
758 | handle->record_name, | ||
759 | 1, | ||
760 | handle->rd, | ||
761 | &create_finished, | ||
762 | handle); | ||
763 | if (NULL == handle->add_qe) | ||
764 | { | ||
765 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | ||
766 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
767 | return; | ||
768 | } | ||
769 | } | ||
770 | |||
771 | |||
772 | /** | ||
773 | * @param cls closure | ||
774 | * @param ego ego handle | ||
775 | * @param ctx context for application to store data for this ego | ||
776 | * (during the lifetime of this process, initially NULL) | ||
777 | * @param identifier identifier assigned by the user for this ego, | ||
778 | * NULL if the user just deleted the ego and it | ||
779 | * must thus no longer be used | ||
780 | */ | ||
781 | static void | ||
782 | default_ego_delete (void *cls, | ||
783 | struct GNUNET_IDENTITY_Ego *ego, | ||
784 | void **ctx, | ||
785 | const char *identifier) | ||
786 | { | ||
787 | struct RequestHandle *handle = cls; | ||
788 | handle->op = NULL; | ||
789 | |||
790 | if (ego == NULL) | ||
791 | { | ||
666 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE); | 792 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE); |
667 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 793 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
668 | return; | 794 | return; |
669 | } | 795 | } |
796 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego); | ||
797 | |||
670 | handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, | 798 | handle->add_qe = GNUNET_NAMESTORE_records_store (handle->ns_handle, |
671 | handle->zone_pkey, | 799 | handle->zone_pkey, |
672 | handle->record_name, | 800 | handle->record_name, |
673 | 1, | 801 | 0, |
674 | handle->rd, | 802 | NULL, |
675 | &create_finished, | 803 | &del_finished, |
676 | handle); | 804 | handle); |
677 | if (NULL == handle->add_qe) | 805 | if (NULL == handle->add_qe) |
678 | { | 806 | { |
679 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); | 807 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_FAILED); |
@@ -736,8 +864,10 @@ namestore_delete (struct GNUNET_REST_RequestHandle *con_handle, | |||
736 | 864 | ||
737 | if (NULL == handle->zone_pkey) | 865 | if (NULL == handle->zone_pkey) |
738 | { | 866 | { |
739 | handle->emsg = GNUNET_strdup(GNUNET_REST_NAMESTORE_NO_DEFAULT_ZONE); | 867 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, |
740 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 868 | "namestore", |
869 | &default_ego_delete, | ||
870 | handle); | ||
741 | return; | 871 | return; |
742 | } | 872 | } |
743 | 873 | ||
@@ -811,30 +941,6 @@ init_cont (struct RequestHandle *handle) | |||
811 | } | 941 | } |
812 | } | 942 | } |
813 | 943 | ||
814 | /** | ||
815 | * @param cls closure | ||
816 | * @param ego ego handle | ||
817 | * @param ctx context for application to store data for this ego | ||
818 | * (during the lifetime of this process, initially NULL) | ||
819 | * @param identifier identifier assigned by the user for this ego, | ||
820 | * NULL if the user just deleted the ego and it | ||
821 | * must thus no longer be used | ||
822 | */ | ||
823 | static void | ||
824 | default_ego_cb (void *cls, | ||
825 | struct GNUNET_IDENTITY_Ego *ego, | ||
826 | void **ctx, | ||
827 | const char *identifier) | ||
828 | { | ||
829 | struct RequestHandle *handle = cls; | ||
830 | handle->op = NULL; | ||
831 | |||
832 | if (ego != NULL) | ||
833 | { | ||
834 | handle->zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego); | ||
835 | } | ||
836 | } | ||
837 | |||
838 | 944 | ||
839 | /** | 945 | /** |
840 | * This function is initially called for all egos and then again | 946 | * This function is initially called for all egos and then again |
@@ -877,17 +983,10 @@ id_connect_cb (void *cls, | |||
877 | struct EgoEntry *ego_entry; | 983 | struct EgoEntry *ego_entry; |
878 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 984 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; |
879 | 985 | ||
880 | if ((NULL == ego) && (NULL == handle->zone_pkey)) | ||
881 | { | ||
882 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, | ||
883 | "namestore", | ||
884 | &default_ego_cb, | ||
885 | handle); | ||
886 | } | ||
887 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) | 986 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) |
888 | { | 987 | { |
889 | handle->state = ID_REST_STATE_POST_INIT; | 988 | handle->state = ID_REST_STATE_POST_INIT; |
890 | init_cont (handle); | 989 | init_cont(handle); |
891 | return; | 990 | return; |
892 | } | 991 | } |
893 | if (ID_REST_STATE_INIT == handle->state) | 992 | if (ID_REST_STATE_INIT == handle->state) |
@@ -934,8 +1033,8 @@ rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, | |||
934 | handle->url[strlen (handle->url)-1] = '\0'; | 1033 | handle->url[strlen (handle->url)-1] = '\0'; |
935 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 1034 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); |
936 | 1035 | ||
937 | handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &id_connect_cb, handle); | ||
938 | handle->ns_handle = GNUNET_NAMESTORE_connect (cfg); | 1036 | handle->ns_handle = GNUNET_NAMESTORE_connect (cfg); |
1037 | handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &id_connect_cb, handle); | ||
939 | handle->timeout_task = | 1038 | handle->timeout_task = |
940 | GNUNET_SCHEDULER_add_delayed (handle->timeout, | 1039 | GNUNET_SCHEDULER_add_delayed (handle->timeout, |
941 | &do_error, | 1040 | &do_error, |