diff options
author | Phil <phil.buschmann@tum.de> | 2018-06-04 23:50:00 +0200 |
---|---|---|
committer | Phil <phil.buschmann@tum.de> | 2018-06-04 23:50:00 +0200 |
commit | 4ab30f893f22c75d1aafcc9584cd7eac6c4d82a0 (patch) | |
tree | 91884385bc421f43ef3cb27d3b98493bee4bc9d1 /src/identity/plugin_rest_identity.c | |
parent | 320c62a4f5b7dac08394cd6f6b82666df4d499e9 (diff) | |
download | gnunet-4ab30f893f22c75d1aafcc9584cd7eac6c4d82a0.tar.gz gnunet-4ab30f893f22c75d1aafcc9584cd7eac6c4d82a0.zip |
identity rest api - finished and added test_script
Diffstat (limited to 'src/identity/plugin_rest_identity.c')
-rw-r--r-- | src/identity/plugin_rest_identity.c | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index 3fe749a52..49d7b58af 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c | |||
@@ -492,7 +492,7 @@ do_finished (void *cls, const char *emsg) | |||
492 | return; | 492 | return; |
493 | } | 493 | } |
494 | resp = GNUNET_REST_create_response (NULL); | 494 | resp = GNUNET_REST_create_response (NULL); |
495 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CREATED); | 495 | handle->proc (handle->proc_cls, resp, handle->response_code); |
496 | cleanup_handle (handle); | 496 | cleanup_handle (handle); |
497 | } | 497 | } |
498 | 498 | ||
@@ -616,15 +616,16 @@ ego_create_cont (struct GNUNET_REST_RequestHandle *con, | |||
616 | //instead of parse | 616 | //instead of parse |
617 | if (!json_is_object(data_js)) | 617 | if (!json_is_object(data_js)) |
618 | { | 618 | { |
619 | json_decref(data_js); | ||
619 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 620 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); |
620 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 621 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
621 | return; | 622 | return; |
622 | } | 623 | } |
623 | 624 | ||
624 | if (1 != json_object_size(data_js)) | 625 | if (1 != json_object_size (data_js)) |
625 | { | 626 | { |
626 | json_decref (data_js); | 627 | json_decref (data_js); |
627 | handle->emsg = GNUNET_strdup ("Provided resource count invalid"); | 628 | handle->emsg = GNUNET_strdup("Provided resource count invalid"); |
628 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 629 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
629 | return; | 630 | return; |
630 | } | 631 | } |
@@ -638,6 +639,13 @@ ego_create_cont (struct GNUNET_REST_RequestHandle *con, | |||
638 | return; | 639 | return; |
639 | } | 640 | } |
640 | egoname = json_string_value (egoname_json); | 641 | egoname = json_string_value (egoname_json); |
642 | if(0 >= strlen(egoname)) | ||
643 | { | ||
644 | json_decref (data_js); | ||
645 | handle->emsg = GNUNET_strdup ("No name provided"); | ||
646 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
647 | return; | ||
648 | } | ||
641 | for (ego_entry = handle->ego_head; | 649 | for (ego_entry = handle->ego_head; |
642 | NULL != ego_entry; | 650 | NULL != ego_entry; |
643 | ego_entry = ego_entry->next) | 651 | ego_entry = ego_entry->next) |
@@ -653,6 +661,7 @@ ego_create_cont (struct GNUNET_REST_RequestHandle *con, | |||
653 | } | 661 | } |
654 | GNUNET_asprintf (&handle->name, "%s", egoname); | 662 | GNUNET_asprintf (&handle->name, "%s", egoname); |
655 | json_decref (data_js); | 663 | json_decref (data_js); |
664 | handle->response_code = MHD_HTTP_CREATED; | ||
656 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, | 665 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, |
657 | handle->name, | 666 | handle->name, |
658 | &do_finished, | 667 | &do_finished, |
@@ -752,6 +761,13 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con, | |||
752 | if ((NULL != name_json) && json_is_string (name_json)) | 761 | if ((NULL != name_json) && json_is_string (name_json)) |
753 | { | 762 | { |
754 | newname = json_string_value (name_json); | 763 | newname = json_string_value (name_json); |
764 | if(0 >= strlen(newname)) | ||
765 | { | ||
766 | json_decref (data_js); | ||
767 | handle->emsg = GNUNET_strdup ("No name provided"); | ||
768 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
769 | return; | ||
770 | } | ||
755 | for (ego_entry_tmp = handle->ego_head; | 771 | for (ego_entry_tmp = handle->ego_head; |
756 | NULL != ego_entry_tmp; | 772 | NULL != ego_entry_tmp; |
757 | ego_entry_tmp = ego_entry_tmp->next) | 773 | ego_entry_tmp = ego_entry_tmp->next) |
@@ -767,6 +783,7 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con, | |||
767 | return; | 783 | return; |
768 | } | 784 | } |
769 | } | 785 | } |
786 | handle->response_code = MHD_HTTP_NO_CONTENT; | ||
770 | handle->op = GNUNET_IDENTITY_rename (handle->identity_handle, | 787 | handle->op = GNUNET_IDENTITY_rename (handle->identity_handle, |
771 | ego_entry->identifier, | 788 | ego_entry->identifier, |
772 | newname, | 789 | newname, |
@@ -781,8 +798,16 @@ ego_edit_cont (struct GNUNET_REST_RequestHandle *con, | |||
781 | if ( (NULL != subsys_json) && json_is_string (subsys_json)) | 798 | if ( (NULL != subsys_json) && json_is_string (subsys_json)) |
782 | { | 799 | { |
783 | subsys = json_string_value (subsys_json); | 800 | subsys = json_string_value (subsys_json); |
801 | if(0 >= strlen(subsys)) | ||
802 | { | ||
803 | json_decref (data_js); | ||
804 | handle->emsg = GNUNET_strdup ("No name provided"); | ||
805 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
806 | return; | ||
807 | } | ||
784 | GNUNET_asprintf (&handle->subsys, "%s", subsys); | 808 | GNUNET_asprintf (&handle->subsys, "%s", subsys); |
785 | json_decref (data_js); | 809 | json_decref (data_js); |
810 | handle->response_code = MHD_HTTP_NO_CONTENT; | ||
786 | handle->op = GNUNET_IDENTITY_set (handle->identity_handle, | 811 | handle->op = GNUNET_IDENTITY_set (handle->identity_handle, |
787 | handle->subsys, | 812 | handle->subsys, |
788 | ego_entry->ego, | 813 | ego_entry->ego, |
@@ -837,6 +862,7 @@ ego_delete_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
837 | cleanup_handle (handle); | 862 | cleanup_handle (handle); |
838 | return; | 863 | return; |
839 | } | 864 | } |
865 | handle->response_code = MHD_HTTP_NO_CONTENT; | ||
840 | handle->op = GNUNET_IDENTITY_delete (handle->identity_handle, | 866 | handle->op = GNUNET_IDENTITY_delete (handle->identity_handle, |
841 | ego_entry->identifier, | 867 | ego_entry->identifier, |
842 | &do_finished, | 868 | &do_finished, |
@@ -980,7 +1006,7 @@ rest_identity_process_request(struct GNUNET_REST_RequestHandle *conndata_handle, | |||
980 | 1006 | ||
981 | 1007 | ||
982 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 1008 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
983 | 1009 | handle->response_code = MHD_HTTP_OK; | |
984 | handle->proc_cls = proc_cls; | 1010 | handle->proc_cls = proc_cls; |
985 | handle->proc = proc; | 1011 | handle->proc = proc; |
986 | handle->state = ID_REST_STATE_INIT; | 1012 | handle->state = ID_REST_STATE_INIT; |