diff options
author | Phil <phil.buschmann@tum.de> | 2018-08-11 14:21:58 +0200 |
---|---|---|
committer | Phil <phil.buschmann@tum.de> | 2018-08-11 14:21:58 +0200 |
commit | 4898de50936164f8adb067c4f32fab62bec92e19 (patch) | |
tree | 62b707d372685f2ebc8b56026caaa4f5238aa294 /src/identity | |
parent | bcda92da22a3c1824f966d4593492e8a446fd070 (diff) | |
download | gnunet-4898de50936164f8adb067c4f32fab62bec92e19.tar.gz gnunet-4898de50936164f8adb067c4f32fab62bec92e19.zip |
split namespace of put request in identity rest api
Diffstat (limited to 'src/identity')
-rw-r--r-- | src/identity/plugin_rest_identity.c | 278 | ||||
-rwxr-xr-x | src/identity/test_plugin_rest_identity.sh | 15 |
2 files changed, 188 insertions, 105 deletions
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index 9a05a2054..89f6e7f8b 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c | |||
@@ -77,12 +77,22 @@ | |||
77 | /** | 77 | /** |
78 | * Error message Unknown Error | 78 | * Error message Unknown Error |
79 | */ | 79 | */ |
80 | #define GNUNET_REST_IDENTITY_ERROR_UNKNOWN "Unknown error" | 80 | #define GNUNET_REST_IDENTITY_ERROR_UNKNOWN "Unknown Error" |
81 | 81 | ||
82 | /** | 82 | /** |
83 | * Error message Resource location invalid | 83 | * Error message No identity found |
84 | */ | 84 | */ |
85 | #define GNUNET_REST_ERROR_RESOURCE_INVALID "Resource location invalid" | 85 | #define GNUNET_REST_IDENTITY_NOT_FOUND "No identity found" |
86 | |||
87 | /** | ||
88 | * Error message Missing identity name | ||
89 | */ | ||
90 | #define GNUNET_REST_IDENTITY_MISSING_NAME "Missing identity name" | ||
91 | |||
92 | /** | ||
93 | * Error message Missing identity name | ||
94 | */ | ||
95 | #define GNUNET_REST_IDENTITY_MISSING_PUBKEY "Missing identity public key" | ||
86 | 96 | ||
87 | /** | 97 | /** |
88 | * Error message No data | 98 | * Error message No data |
@@ -235,7 +245,7 @@ struct RequestHandle | |||
235 | char *emsg; | 245 | char *emsg; |
236 | 246 | ||
237 | /** | 247 | /** |
238 | * Reponse code | 248 | * Response code |
239 | */ | 249 | */ |
240 | int response_code; | 250 | int response_code; |
241 | 251 | ||
@@ -373,7 +383,8 @@ ego_get_for_subsystem (void *cls, | |||
373 | 383 | ||
374 | if(NULL == ego) | 384 | if(NULL == ego) |
375 | { | 385 | { |
376 | handle->emsg = GNUNET_strdup("No identity found for subsystem"); | 386 | handle->response_code = MHD_HTTP_NOT_FOUND; |
387 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
377 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 388 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
378 | return; | 389 | return; |
379 | } | 390 | } |
@@ -418,7 +429,7 @@ ego_get_subsystem (struct GNUNET_REST_RequestHandle *con_handle, | |||
418 | 429 | ||
419 | if (strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen (handle->url)) | 430 | if (strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen (handle->url)) |
420 | { | 431 | { |
421 | handle->emsg = GNUNET_strdup("Missing subsystem"); | 432 | handle->emsg = GNUNET_strdup("Missing subsystem name"); |
422 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 433 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
423 | return; | 434 | return; |
424 | } | 435 | } |
@@ -434,7 +445,8 @@ ego_get_subsystem (struct GNUNET_REST_RequestHandle *con_handle, | |||
434 | 445 | ||
435 | if (NULL == handle->op) | 446 | if (NULL == handle->op) |
436 | { | 447 | { |
437 | handle->emsg = GNUNET_strdup("No identity found for subsystem"); | 448 | handle->response_code = MHD_HTTP_NOT_FOUND; |
449 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
438 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 450 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
439 | return; | 451 | return; |
440 | } | 452 | } |
@@ -479,7 +491,8 @@ ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, | |||
479 | if ((size_t) 0 == json_array_size (json_root)) | 491 | if ((size_t) 0 == json_array_size (json_root)) |
480 | { | 492 | { |
481 | json_decref (json_root); | 493 | json_decref (json_root); |
482 | handle->emsg = GNUNET_strdup("No identities found!"); | 494 | handle->response_code = MHD_HTTP_NOT_FOUND; |
495 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
483 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 496 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
484 | return; | 497 | return; |
485 | } | 498 | } |
@@ -547,7 +560,7 @@ ego_get_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
547 | 560 | ||
548 | if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) | 561 | if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) |
549 | { | 562 | { |
550 | handle->emsg = GNUNET_strdup("Missing public key"); | 563 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_PUBKEY); |
551 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 564 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
552 | return; | 565 | return; |
553 | } | 566 | } |
@@ -556,7 +569,8 @@ ego_get_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
556 | 569 | ||
557 | if (NULL == ego_entry) | 570 | if (NULL == ego_entry) |
558 | { | 571 | { |
559 | handle->emsg = GNUNET_strdup("No identity found for public key"); | 572 | handle->response_code = MHD_HTTP_NOT_FOUND; |
573 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
560 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 574 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
561 | return; | 575 | return; |
562 | } | 576 | } |
@@ -584,7 +598,7 @@ ego_get_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
584 | 598 | ||
585 | if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) | 599 | if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) |
586 | { | 600 | { |
587 | handle->emsg = GNUNET_strdup("Missing name"); | 601 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_NAME); |
588 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 602 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
589 | return; | 603 | return; |
590 | } | 604 | } |
@@ -593,7 +607,8 @@ ego_get_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
593 | 607 | ||
594 | if (NULL == ego_entry) | 608 | if (NULL == ego_entry) |
595 | { | 609 | { |
596 | handle->emsg = GNUNET_strdup("No identity found for name"); | 610 | handle->response_code = MHD_HTTP_NOT_FOUND; |
611 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
597 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 612 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
598 | return; | 613 | return; |
599 | } | 614 | } |
@@ -644,7 +659,6 @@ ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) | |||
644 | struct MHD_Response *resp; | 659 | struct MHD_Response *resp; |
645 | json_t *data_js; | 660 | json_t *data_js; |
646 | json_error_t err; | 661 | json_error_t err; |
647 | char *newsubsys; | ||
648 | char *newname; | 662 | char *newname; |
649 | char term_data[handle->data_size + 1]; | 663 | char term_data[handle->data_size + 1]; |
650 | int json_state; | 664 | int json_state; |
@@ -676,95 +690,56 @@ ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) | |||
676 | GNUNET_REST_IDENTITY_PARAM_NEWNAME, | 690 | GNUNET_REST_IDENTITY_PARAM_NEWNAME, |
677 | &newname); | 691 | &newname); |
678 | //Change name with pubkey or name identifier | 692 | //Change name with pubkey or name identifier |
679 | if (0 == json_state) | 693 | if (0 != json_state) |
680 | { | 694 | { |
681 | if (NULL == newname) | ||
682 | { | ||
683 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); | ||
684 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
685 | json_decref (data_js); | ||
686 | return; | ||
687 | } | ||
688 | 695 | ||
689 | if (0 >= strlen(newname)) | 696 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
690 | { | 697 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
691 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); | ||
692 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
693 | json_decref (data_js); | ||
694 | return; | ||
695 | } | ||
696 | GNUNET_STRINGS_utf8_tolower(newname,newname); | ||
697 | ego_entry_tmp = get_egoentry(handle,NULL,newname); | ||
698 | if (NULL != ego_entry_tmp) | ||
699 | { | ||
700 | //Ego with same name not allowed (even if its the ego we change) | ||
701 | resp = GNUNET_REST_create_response (NULL); | ||
702 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); | ||
703 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | ||
704 | json_decref (data_js); | ||
705 | return; | ||
706 | } | ||
707 | handle->op = GNUNET_IDENTITY_rename (handle->identity_handle, | ||
708 | ego_entry->identifier, | ||
709 | newname, | ||
710 | &do_finished, | ||
711 | handle); | ||
712 | if (NULL == handle->op) | ||
713 | { | ||
714 | handle->emsg = GNUNET_strdup("Rename was not possible"); | ||
715 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
716 | return; | ||
717 | } | ||
718 | json_decref (data_js); | 698 | json_decref (data_js); |
719 | return; | 699 | return; |
720 | } | 700 | } |
721 | 701 | ||
722 | newsubsys = NULL; | 702 | if (NULL == newname) |
723 | //SUBSYSTEM | ||
724 | json_state = 0; | ||
725 | json_state = json_unpack(data_js, | ||
726 | "{s:s!}", | ||
727 | GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM, | ||
728 | &newsubsys); | ||
729 | //Change subsystem with pubkey or name identifier | ||
730 | if (0 == json_state) | ||
731 | { | 703 | { |
732 | if (NULL == newsubsys) | 704 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
733 | { | 705 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
734 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); | 706 | json_decref (data_js); |
735 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 707 | return; |
736 | json_decref (data_js); | 708 | } |
737 | return; | ||
738 | } | ||
739 | |||
740 | if (0 >= strlen(newsubsys)) | ||
741 | { | ||
742 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); | ||
743 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
744 | json_decref (data_js); | ||
745 | return; | ||
746 | } | ||
747 | 709 | ||
748 | handle->response_code = MHD_HTTP_NO_CONTENT; | 710 | if (0 >= strlen (newname)) |
749 | handle->op = GNUNET_IDENTITY_set (handle->identity_handle, | 711 | { |
750 | newsubsys, | 712 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
751 | ego_entry->ego, | 713 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
752 | &do_finished, | ||
753 | handle); | ||
754 | if (NULL == handle->op) | ||
755 | { | ||
756 | handle->emsg = GNUNET_strdup("Setting subsystem was not possible"); | ||
757 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
758 | return; | ||
759 | } | ||
760 | json_decref (data_js); | 714 | json_decref (data_js); |
761 | return; | 715 | return; |
762 | } | 716 | } |
763 | 717 | ||
764 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); | 718 | ego_entry_tmp = get_egoentry (handle, NULL, newname); |
765 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 719 | if (NULL != ego_entry_tmp) |
720 | { | ||
721 | //Ego with same name not allowed (even if its the ego we change) | ||
722 | resp = GNUNET_REST_create_response (NULL); | ||
723 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); | ||
724 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | ||
725 | json_decref (data_js); | ||
726 | return; | ||
727 | } | ||
728 | handle->op = GNUNET_IDENTITY_rename (handle->identity_handle, | ||
729 | ego_entry->identifier, | ||
730 | newname, | ||
731 | &do_finished, | ||
732 | handle); | ||
733 | if (NULL == handle->op) | ||
734 | { | ||
735 | handle->emsg = GNUNET_strdup("Rename failed"); | ||
736 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
737 | json_decref (data_js); | ||
738 | return; | ||
739 | } | ||
766 | json_decref (data_js); | 740 | json_decref (data_js); |
767 | return; | 741 | return; |
742 | |||
768 | } | 743 | } |
769 | 744 | ||
770 | 745 | ||
@@ -789,7 +764,7 @@ ego_edit_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
789 | if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) | 764 | if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) |
790 | { | 765 | { |
791 | handle->response_code = MHD_HTTP_NOT_FOUND; | 766 | handle->response_code = MHD_HTTP_NOT_FOUND; |
792 | handle->emsg = GNUNET_strdup("Missing public key"); | 767 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_PUBKEY); |
793 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 768 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
794 | return; | 769 | return; |
795 | } | 770 | } |
@@ -799,7 +774,7 @@ ego_edit_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
799 | if (NULL == ego_entry) | 774 | if (NULL == ego_entry) |
800 | { | 775 | { |
801 | handle->response_code = MHD_HTTP_NOT_FOUND; | 776 | handle->response_code = MHD_HTTP_NOT_FOUND; |
802 | handle->emsg = GNUNET_strdup("No identity found for public key"); | 777 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); |
803 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 778 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
804 | return; | 779 | return; |
805 | } | 780 | } |
@@ -828,7 +803,7 @@ ego_edit_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
828 | if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) | 803 | if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) |
829 | { | 804 | { |
830 | handle->response_code = MHD_HTTP_NOT_FOUND; | 805 | handle->response_code = MHD_HTTP_NOT_FOUND; |
831 | handle->emsg = GNUNET_strdup("Missing name"); | 806 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_NAME); |
832 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 807 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
833 | return; | 808 | return; |
834 | } | 809 | } |
@@ -838,7 +813,7 @@ ego_edit_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
838 | if (NULL == ego_entry) | 813 | if (NULL == ego_entry) |
839 | { | 814 | { |
840 | handle->response_code = MHD_HTTP_NOT_FOUND; | 815 | handle->response_code = MHD_HTTP_NOT_FOUND; |
841 | handle->emsg = GNUNET_strdup("No identity found for name"); | 816 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); |
842 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 817 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
843 | return; | 818 | return; |
844 | } | 819 | } |
@@ -847,6 +822,115 @@ ego_edit_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
847 | } | 822 | } |
848 | 823 | ||
849 | /** | 824 | /** |
825 | * Handle identity subsystem PUT request with name | ||
826 | * | ||
827 | * @param con_handle the connection handle | ||
828 | * @param url the url | ||
829 | * @param cls the RequestHandle | ||
830 | */ | ||
831 | void | ||
832 | ego_edit_subsystem (struct GNUNET_REST_RequestHandle *con_handle, | ||
833 | const char* url, | ||
834 | void *cls) | ||
835 | { | ||
836 | struct RequestHandle *handle = cls; | ||
837 | struct EgoEntry *ego_entry; | ||
838 | json_t *data_js; | ||
839 | json_error_t err; | ||
840 | char *newsubsys; | ||
841 | char *name; | ||
842 | char term_data[handle->data_size + 1]; | ||
843 | int json_state; | ||
844 | |||
845 | name = NULL; | ||
846 | |||
847 | if (strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen (handle->url)) | ||
848 | { | ||
849 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
850 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_NAME); | ||
851 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
852 | return; | ||
853 | } | ||
854 | name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM)+1]; | ||
855 | ego_entry = get_egoentry(handle, NULL, name); | ||
856 | |||
857 | if (NULL == ego_entry) | ||
858 | { | ||
859 | handle->response_code = MHD_HTTP_NOT_FOUND; | ||
860 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); | ||
861 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
862 | return; | ||
863 | } | ||
864 | |||
865 | //if no data | ||
866 | if (0 >= handle->data_size) | ||
867 | { | ||
868 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_NO_DATA); | ||
869 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
870 | return; | ||
871 | } | ||
872 | //if not json | ||
873 | term_data[handle->data_size] = '\0'; | ||
874 | GNUNET_memcpy(term_data, handle->data, handle->data_size); | ||
875 | data_js = json_loads (term_data,JSON_DECODE_ANY,&err); | ||
876 | |||
877 | if (NULL == data_js) | ||
878 | { | ||
879 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_NO_DATA); | ||
880 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
881 | return; | ||
882 | } | ||
883 | |||
884 | newsubsys = NULL; | ||
885 | //SUBSYSTEM | ||
886 | json_state = 0; | ||
887 | json_state = json_unpack(data_js, | ||
888 | "{s:s!}", | ||
889 | GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM, | ||
890 | &newsubsys); | ||
891 | //Change subsystem with pubkey or name identifier | ||
892 | if (0 != json_state) | ||
893 | { | ||
894 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); | ||
895 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
896 | json_decref (data_js); | ||
897 | return; | ||
898 | } | ||
899 | |||
900 | if (NULL == newsubsys) | ||
901 | { | ||
902 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); | ||
903 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
904 | json_decref (data_js); | ||
905 | return; | ||
906 | } | ||
907 | |||
908 | if (0 >= strlen (newsubsys)) | ||
909 | { | ||
910 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); | ||
911 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
912 | json_decref (data_js); | ||
913 | return; | ||
914 | } | ||
915 | |||
916 | handle->response_code = MHD_HTTP_NO_CONTENT; | ||
917 | handle->op = GNUNET_IDENTITY_set (handle->identity_handle, | ||
918 | newsubsys, | ||
919 | ego_entry->ego, | ||
920 | &do_finished, | ||
921 | handle); | ||
922 | if (NULL == handle->op) | ||
923 | { | ||
924 | handle->emsg = GNUNET_strdup("Setting subsystem failed"); | ||
925 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
926 | return; | ||
927 | } | ||
928 | json_decref (data_js); | ||
929 | return; | ||
930 | |||
931 | } | ||
932 | |||
933 | /** | ||
850 | * Handle identity POST request | 934 | * Handle identity POST request |
851 | * | 935 | * |
852 | * @param con_handle the connection handle | 936 | * @param con_handle the connection handle |
@@ -869,7 +953,6 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
869 | 953 | ||
870 | if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url)) | 954 | if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url)) |
871 | { | 955 | { |
872 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_RESOURCE_INVALID); | ||
873 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 956 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
874 | return; | 957 | return; |
875 | } | 958 | } |
@@ -907,7 +990,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
907 | 990 | ||
908 | if (NULL == egoname) | 991 | if (NULL == egoname) |
909 | { | 992 | { |
910 | handle->emsg = GNUNET_strdup("No name provided"); | 993 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
911 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 994 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
912 | json_decref (data_js); | 995 | json_decref (data_js); |
913 | return; | 996 | return; |
@@ -915,7 +998,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
915 | if (0 >= strlen (egoname)) | 998 | if (0 >= strlen (egoname)) |
916 | { | 999 | { |
917 | json_decref (data_js); | 1000 | json_decref (data_js); |
918 | handle->emsg = GNUNET_strdup("No name provided"); | 1001 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
919 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1002 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
920 | return; | 1003 | return; |
921 | } | 1004 | } |
@@ -961,7 +1044,7 @@ ego_delete_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
961 | if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) | 1044 | if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) |
962 | { | 1045 | { |
963 | handle->response_code = MHD_HTTP_NOT_FOUND; | 1046 | handle->response_code = MHD_HTTP_NOT_FOUND; |
964 | handle->emsg = GNUNET_strdup("Missing public key"); | 1047 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_PUBKEY); |
965 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1048 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
966 | return; | 1049 | return; |
967 | } | 1050 | } |
@@ -1006,7 +1089,7 @@ ego_delete_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
1006 | if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) | 1089 | if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) |
1007 | { | 1090 | { |
1008 | handle->response_code = MHD_HTTP_NOT_FOUND; | 1091 | handle->response_code = MHD_HTTP_NOT_FOUND; |
1009 | handle->emsg = GNUNET_strdup("Missing public key"); | 1092 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_NAME); |
1010 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1093 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1011 | return; | 1094 | return; |
1012 | } | 1095 | } |
@@ -1067,6 +1150,7 @@ init_cont (struct RequestHandle *handle) | |||
1067 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, &ego_get_subsystem }, | 1150 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, &ego_get_subsystem }, |
1068 | { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_PUBKEY, &ego_edit_pubkey }, | 1151 | { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_PUBKEY, &ego_edit_pubkey }, |
1069 | { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name }, | 1152 | { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name }, |
1153 | { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, &ego_edit_subsystem }, | ||
1070 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create }, | 1154 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create }, |
1071 | { MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_IDENTITY_PUBKEY, &ego_delete_pubkey }, | 1155 | { MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_IDENTITY_PUBKEY, &ego_delete_pubkey }, |
1072 | { MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_delete_name }, | 1156 | { MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_delete_name }, |
diff --git a/src/identity/test_plugin_rest_identity.sh b/src/identity/test_plugin_rest_identity.sh index 3eac0950c..a5879dd7e 100755 --- a/src/identity/test_plugin_rest_identity.sh +++ b/src/identity/test_plugin_rest_identity.sh | |||
@@ -122,19 +122,18 @@ curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"newname":"test_pl | |||
122 | curl_put "${identity_link}/name/test_plugin_rest_identity" '{"newnam":"test_plugin_rest_identityfail"}' "error" | 122 | curl_put "${identity_link}/name/test_plugin_rest_identity" '{"newnam":"test_plugin_rest_identityfail"}' "error" |
123 | 123 | ||
124 | #Test subsystem | 124 | #Test subsystem |
125 | curl_put "${identity_link}/name/test_plugin_rest_identity" '{"subsystem":"namestore"}' "HTTP/1.1 204" | 125 | curl_put "${identity_link}/subsystem/test_plugin_rest_identity" '{"subsystem":"namestore"}' "HTTP/1.1 204" |
126 | curl_put "${identity_link}/name/test_plugin_rest_identity" '{"subsystem":"namestore"}' "HTTP/1.1 204" | 126 | curl_put "${identity_link}/subsystem/test_plugin_rest_identity" '{"subsystem":"namestore"}' "HTTP/1.1 204" |
127 | curl_get "${identity_link}/subsystem/namestore" "test_plugin_rest_identity" | 127 | curl_get "${identity_link}/subsystem/namestore" "test_plugin_rest_identity" |
128 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 201 Created" | ||
129 | public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $3}')" | 128 | public="$(gnunet-identity -d | grep "test_plugin_rest_identity" | awk 'NR==1{print $3}')" |
130 | curl_put "${identity_link}/pubkey/$public" '{"subsystem":"namestore"}' "HTTP/1.1 204" | 129 | curl_put "${identity_link}/subsystem/$public" '{"subsystem":"namestore"}' "HTTP/1.1 404" |
131 | curl_get "${identity_link}/subsystem/namestore" "test_plugin_rest_identity1" | 130 | curl_post "${identity_link}" '{"name":"test_plugin_rest_identity1"}' "HTTP/1.1 201 Created" |
132 | curl_get "${identity_link}/subsystem/test_plugin_rest_identity_no_subsystem" "error" | 131 | curl_get "${identity_link}/subsystem/test_plugin_rest_identity_no_subsystem" "error" |
133 | curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"subsystem":"test_plugin_rest_identity_no_subsystem"}' "HTTP/1.1 204" | 132 | curl_put "${identity_link}/subsystem/test_plugin_rest_identity1" '{"subsystem":"test_plugin_rest_identity_no_subsystem"}' "HTTP/1.1 204" |
134 | curl_get "${identity_link}/subsystem/test_plugin_rest_identity_no_subsystem" "test_plugin_rest_identity1" | 133 | curl_get "${identity_link}/subsystem/test_plugin_rest_identity_no_subsystem" "test_plugin_rest_identity1" |
135 | 134 | ||
136 | curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"subsyste":"test_plugin_rest_identity_no_subsystem"}' "error" | 135 | curl_put "${identity_link}/subsystem/test_plugin_rest_identity1" '{"subsyste":"test_plugin_rest_identity_no_subsystem"}' "error" |
137 | curl_put "${identity_link}/name/test_plugin_rest_identity1" '{"subsystem":"test_plugin_rest_identity_no_subsystem"}' "HTTP/1.1 204" | 136 | curl_put "${identity_link}/subsystem/test_plugin_rest_identity1" '{"subsystem":"test_plugin_rest_identity_no_subsystem"}' "HTTP/1.1 204" |
138 | 137 | ||
139 | #Test DELETE | 138 | #Test DELETE |
140 | curl_delete "${identity_link}/name/test_plugin_rest_identity" "HTTP/1.1 204" | 139 | curl_delete "${identity_link}/name/test_plugin_rest_identity" "HTTP/1.1 204" |