diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-05-04 17:18:02 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-05-04 17:18:02 +0000 |
commit | a44744499d8f3df64cc1d15cd6b40b4b0e4a3683 (patch) | |
tree | 27621a6ee20cbe8e344ffdc18c05754e67d67bf3 /src/namestore | |
parent | ca11046195a840932edb04900669a38cd60ae682 (diff) | |
download | gnunet-a44744499d8f3df64cc1d15cd6b40b4b0e4a3683.tar.gz gnunet-a44744499d8f3df64cc1d15cd6b40b4b0e4a3683.zip |
Update jsonapi to current specs, refactor
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/plugin_rest_namestore.c | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c index 76a1126a5..c20ef8e8a 100644 --- a/src/namestore/plugin_rest_namestore.c +++ b/src/namestore/plugin_rest_namestore.c | |||
@@ -106,7 +106,7 @@ struct RequestHandle | |||
106 | /** | 106 | /** |
107 | * JSON response object | 107 | * JSON response object |
108 | */ | 108 | */ |
109 | struct GNUNET_JSONAPI_Object *resp_object; | 109 | struct GNUNET_JSONAPI_Document *resp_object; |
110 | 110 | ||
111 | /** | 111 | /** |
112 | * Rest connection | 112 | * Rest connection |
@@ -251,7 +251,7 @@ cleanup_handle (struct RequestHandle *handle) | |||
251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
252 | "Cleaning up\n"); | 252 | "Cleaning up\n"); |
253 | if (NULL != handle->resp_object) | 253 | if (NULL != handle->resp_object) |
254 | GNUNET_JSONAPI_object_delete (handle->resp_object); | 254 | GNUNET_JSONAPI_document_delete (handle->resp_object); |
255 | if (NULL != handle->name) | 255 | if (NULL != handle->name) |
256 | GNUNET_free (handle->name); | 256 | GNUNET_free (handle->name); |
257 | if (NULL != handle->timeout_task) | 257 | if (NULL != handle->timeout_task) |
@@ -407,13 +407,13 @@ namestore_list_response (void *cls, | |||
407 | char *result; | 407 | char *result; |
408 | 408 | ||
409 | if (NULL == handle->resp_object) | 409 | if (NULL == handle->resp_object) |
410 | handle->resp_object = GNUNET_JSONAPI_object_new (); | 410 | handle->resp_object = GNUNET_JSONAPI_document_new (); |
411 | 411 | ||
412 | if (NULL == rname) | 412 | if (NULL == rname) |
413 | { | 413 | { |
414 | handle->list_it = NULL; | 414 | handle->list_it = NULL; |
415 | //Handle response | 415 | //Handle response |
416 | if (GNUNET_SYSERR == GNUNET_JSONAPI_data_serialize (handle->resp_object, &result)) | 416 | if (GNUNET_SYSERR == GNUNET_JSONAPI_document_serialize (handle->resp_object, &result)) |
417 | { | 417 | { |
418 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 418 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
419 | return; | 419 | return; |
@@ -456,7 +456,7 @@ namestore_list_response (void *cls, | |||
456 | GNUNET_JSONAPI_resource_add_attr (json_resource, | 456 | GNUNET_JSONAPI_resource_add_attr (json_resource, |
457 | GNUNET_REST_JSONAPI_NAMESTORE_RECORD, | 457 | GNUNET_REST_JSONAPI_NAMESTORE_RECORD, |
458 | result_array); | 458 | result_array); |
459 | GNUNET_JSONAPI_object_resource_add (handle->resp_object, json_resource); | 459 | GNUNET_JSONAPI_document_resource_add (handle->resp_object, json_resource); |
460 | } | 460 | } |
461 | 461 | ||
462 | json_decref (result_array); | 462 | json_decref (result_array); |
@@ -658,7 +658,7 @@ json_to_gnsrecord (const json_t *records_json, | |||
658 | "Value property is no string\n"); | 658 | "Value property is no string\n"); |
659 | return GNUNET_SYSERR; | 659 | return GNUNET_SYSERR; |
660 | } | 660 | } |
661 | GNUNET_asprintf (&value, "%s", json_string_value (value_json)); | 661 | value = GNUNET_strdup (json_string_value (value_json)); |
662 | if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value ((*rd)[i].record_type, | 662 | if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value ((*rd)[i].record_type, |
663 | value, | 663 | value, |
664 | &rdata, | 664 | &rdata, |
@@ -719,9 +719,8 @@ namestore_create_cont (struct GNUNET_REST_RequestHandle *con, | |||
719 | { | 719 | { |
720 | struct RequestHandle *handle = cls; | 720 | struct RequestHandle *handle = cls; |
721 | struct MHD_Response *resp; | 721 | struct MHD_Response *resp; |
722 | struct GNUNET_JSONAPI_Object *json_obj; | 722 | struct GNUNET_JSONAPI_Document *json_obj; |
723 | struct GNUNET_JSONAPI_Resource *json_res; | 723 | struct GNUNET_JSONAPI_Resource *json_res; |
724 | json_t *name_json; | ||
725 | json_t *records_json; | 724 | json_t *records_json; |
726 | char term_data[handle->rest_handle->data_size+1]; | 725 | char term_data[handle->rest_handle->data_size+1]; |
727 | 726 | ||
@@ -741,7 +740,7 @@ namestore_create_cont (struct GNUNET_REST_RequestHandle *con, | |||
741 | memcpy (term_data, | 740 | memcpy (term_data, |
742 | handle->rest_handle->data, | 741 | handle->rest_handle->data, |
743 | handle->rest_handle->data_size); | 742 | handle->rest_handle->data_size); |
744 | GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_object_parse (term_data, | 743 | GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_document_parse (term_data, |
745 | &json_obj)); | 744 | &json_obj)); |
746 | if (NULL == json_obj) | 745 | if (NULL == json_obj) |
747 | { | 746 | { |
@@ -751,54 +750,45 @@ namestore_create_cont (struct GNUNET_REST_RequestHandle *con, | |||
751 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 750 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
752 | return; | 751 | return; |
753 | } | 752 | } |
754 | if (1 != GNUNET_JSONAPI_object_resource_count (json_obj)) | 753 | if (1 != GNUNET_JSONAPI_document_resource_count (json_obj)) |
755 | { | 754 | { |
756 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 755 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
757 | "Cannot create more than 1 resource! (Got %d)\n", | 756 | "Cannot create more than 1 resource! (Got %d)\n", |
758 | GNUNET_JSONAPI_object_resource_count (json_obj)); | 757 | GNUNET_JSONAPI_document_resource_count (json_obj)); |
759 | GNUNET_JSONAPI_object_delete (json_obj); | 758 | GNUNET_JSONAPI_document_delete (json_obj); |
760 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 759 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
761 | return; | 760 | return; |
762 | } | 761 | } |
763 | json_res = GNUNET_JSONAPI_object_get_resource (json_obj, 0); | 762 | json_res = GNUNET_JSONAPI_document_get_resource (json_obj, 0); |
764 | if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (json_res, | 763 | if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (json_res, |
765 | GNUNET_REST_JSONAPI_NAMESTORE_RECORD)) | 764 | GNUNET_REST_JSONAPI_NAMESTORE_RECORD)) |
766 | { | 765 | { |
767 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 766 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
768 | "Unsupported JSON data type\n"); | 767 | "Unsupported JSON data type\n"); |
769 | GNUNET_JSONAPI_object_delete (json_obj); | 768 | GNUNET_JSONAPI_document_delete (json_obj); |
770 | resp = GNUNET_REST_create_json_response (NULL); | 769 | resp = GNUNET_REST_create_json_response (NULL); |
771 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); | 770 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); |
772 | cleanup_handle (handle); | 771 | cleanup_handle (handle); |
773 | return; | 772 | return; |
774 | } | 773 | } |
775 | name_json = GNUNET_JSONAPI_resource_get_id (json_res); | 774 | handle->name = GNUNET_strdup (GNUNET_JSONAPI_resource_get_id (json_res)); |
776 | if (!json_is_string (name_json)) | ||
777 | { | ||
778 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
779 | "Name property is no string\n"); | ||
780 | GNUNET_JSONAPI_object_delete (json_obj); | ||
781 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
782 | return; | ||
783 | } | ||
784 | GNUNET_asprintf (&handle->name, "%s", json_string_value (name_json)); | ||
785 | records_json = GNUNET_JSONAPI_resource_read_attr (json_res, | 775 | records_json = GNUNET_JSONAPI_resource_read_attr (json_res, |
786 | GNUNET_REST_JSONAPI_NAMESTORE_RECORD); | 776 | GNUNET_REST_JSONAPI_NAMESTORE_RECORD); |
787 | if (NULL == records_json) | 777 | if (NULL == records_json) |
788 | { | 778 | { |
789 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 779 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
790 | "No records given\n"); | 780 | "No records given\n"); |
791 | GNUNET_JSONAPI_object_delete (json_obj); | 781 | GNUNET_JSONAPI_document_delete (json_obj); |
792 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 782 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
793 | return; | 783 | return; |
794 | } | 784 | } |
795 | if (GNUNET_SYSERR == json_to_gnsrecord (records_json, &handle->rd, &handle->rd_count)) | 785 | if (GNUNET_SYSERR == json_to_gnsrecord (records_json, &handle->rd, &handle->rd_count)) |
796 | { | 786 | { |
797 | GNUNET_JSONAPI_object_delete (json_obj); | 787 | GNUNET_JSONAPI_document_delete (json_obj); |
798 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 788 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
799 | return; | 789 | return; |
800 | } | 790 | } |
801 | GNUNET_JSONAPI_object_delete (json_obj); | 791 | GNUNET_JSONAPI_document_delete (json_obj); |
802 | 792 | ||
803 | handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, | 793 | handle->add_qe = GNUNET_NAMESTORE_records_lookup (handle->ns_handle, |
804 | &handle->zone_pkey, | 794 | &handle->zone_pkey, |
@@ -815,13 +805,13 @@ namestore_zkey_response (void *cls, | |||
815 | { | 805 | { |
816 | struct RequestHandle *handle = cls; | 806 | struct RequestHandle *handle = cls; |
817 | struct MHD_Response *resp; | 807 | struct MHD_Response *resp; |
818 | struct GNUNET_JSONAPI_Object *json_obj; | 808 | struct GNUNET_JSONAPI_Document *json_obj; |
819 | struct GNUNET_JSONAPI_Resource *json_res; | 809 | struct GNUNET_JSONAPI_Resource *json_res; |
820 | json_t *name_json; | 810 | json_t *name_json; |
821 | char* result; | 811 | char* result; |
822 | 812 | ||
823 | handle->reverse_qe = NULL; | 813 | handle->reverse_qe = NULL; |
824 | json_obj = GNUNET_JSONAPI_object_new (); | 814 | json_obj = GNUNET_JSONAPI_document_new (); |
825 | if (NULL != label) | 815 | if (NULL != label) |
826 | { | 816 | { |
827 | name_json = json_string (label); | 817 | name_json = json_string (label); |
@@ -830,19 +820,19 @@ namestore_zkey_response (void *cls, | |||
830 | GNUNET_JSONAPI_resource_add_attr (json_res, | 820 | GNUNET_JSONAPI_resource_add_attr (json_res, |
831 | GNUNET_REST_JSONAPI_NAMESTORE_NAME, | 821 | GNUNET_REST_JSONAPI_NAMESTORE_NAME, |
832 | name_json); | 822 | name_json); |
833 | GNUNET_JSONAPI_object_resource_add (json_obj, json_res); | 823 | GNUNET_JSONAPI_document_resource_add (json_obj, json_res); |
834 | json_decref (name_json); | 824 | json_decref (name_json); |
835 | } | 825 | } |
836 | //Handle response | 826 | //Handle response |
837 | if (GNUNET_SYSERR == GNUNET_JSONAPI_data_serialize (json_obj, &result)) | 827 | if (GNUNET_SYSERR == GNUNET_JSONAPI_document_serialize (json_obj, &result)) |
838 | { | 828 | { |
839 | GNUNET_JSONAPI_object_delete (json_obj); | 829 | GNUNET_JSONAPI_document_delete (json_obj); |
840 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 830 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
841 | return; | 831 | return; |
842 | } | 832 | } |
843 | resp = GNUNET_REST_create_json_response (result); | 833 | resp = GNUNET_REST_create_json_response (result); |
844 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 834 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
845 | GNUNET_JSONAPI_object_delete (json_obj); | 835 | GNUNET_JSONAPI_document_delete (json_obj); |
846 | GNUNET_free (result); | 836 | GNUNET_free (result); |
847 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); | 837 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); |
848 | return; | 838 | return; |
@@ -1105,9 +1095,9 @@ testservice_id_task (void *cls, int result) | |||
1105 | } | 1095 | } |
1106 | name = get_name_from_url (handle->url); | 1096 | name = get_name_from_url (handle->url); |
1107 | if (NULL != ego) | 1097 | if (NULL != ego) |
1108 | GNUNET_asprintf (&handle->ego_name, "%s", ego); | 1098 | handle->ego_name = GNUNET_strdup (ego); |
1109 | if (NULL != name) | 1099 | if (NULL != name) |
1110 | GNUNET_asprintf (&handle->name, "%s", name); | 1100 | handle->name = GNUNET_strdup (name); |
1111 | if (NULL == handle->ego_name) | 1101 | if (NULL == handle->ego_name) |
1112 | { | 1102 | { |
1113 | handle->identity_handle = GNUNET_IDENTITY_connect (handle->cfg, &id_connect_cb, handle); | 1103 | handle->identity_handle = GNUNET_IDENTITY_connect (handle->cfg, &id_connect_cb, handle); |
@@ -1148,7 +1138,7 @@ rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle, | |||
1148 | handle->proc_cls = proc_cls; | 1138 | handle->proc_cls = proc_cls; |
1149 | handle->proc = proc; | 1139 | handle->proc = proc; |
1150 | handle->rest_handle = rest_handle; | 1140 | handle->rest_handle = rest_handle; |
1151 | GNUNET_asprintf (&handle->url, "%s", rest_handle->url); | 1141 | handle->url = GNUNET_strdup (rest_handle->url); |
1152 | if (handle->url[strlen (handle->url)-1] == '/') | 1142 | if (handle->url[strlen (handle->url)-1] == '/') |
1153 | handle->url[strlen (handle->url)-1] = '\0'; | 1143 | handle->url[strlen (handle->url)-1] = '\0'; |
1154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |