diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-05-04 09:44:35 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-05-04 09:44:35 +0000 |
commit | 493305a0d4e9d7f9bdc35fabfd8027a487586e47 (patch) | |
tree | ec05c1bde5b5cfb7937de6f06dc3586f26f557f9 /src/namestore | |
parent | 8e9bb50b7543608c2c1a833a5b92f19941ed7a0a (diff) | |
download | gnunet-493305a0d4e9d7f9bdc35fabfd8027a487586e47.tar.gz gnunet-493305a0d4e9d7f9bdc35fabfd8027a487586e47.zip |
- rework rest/jsonapi API; bugfixes
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/plugin_rest_namestore.c | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c index c47a6a3c8..76a1126a5 100644 --- a/src/namestore/plugin_rest_namestore.c +++ b/src/namestore/plugin_rest_namestore.c | |||
@@ -111,7 +111,7 @@ struct RequestHandle | |||
111 | /** | 111 | /** |
112 | * Rest connection | 112 | * Rest connection |
113 | */ | 113 | */ |
114 | struct RestConnectionDataHandle *conndata_handle; | 114 | struct GNUNET_REST_RequestHandle *rest_handle; |
115 | 115 | ||
116 | /** | 116 | /** |
117 | * Handle to GNS service. | 117 | * Handle to GNS service. |
@@ -224,19 +224,14 @@ struct RequestHandle | |||
224 | char *url; | 224 | char *url; |
225 | 225 | ||
226 | /** | 226 | /** |
227 | * The data from the REST request | 227 | * Cfg |
228 | */ | 228 | */ |
229 | const char* data; | 229 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
230 | 230 | ||
231 | /** | 231 | /** |
232 | * the length of the REST data | 232 | * HTTP response code |
233 | */ | 233 | */ |
234 | size_t data_size; | 234 | int response_code; |
235 | |||
236 | /** | ||
237 | * Cfg | ||
238 | */ | ||
239 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
240 | 235 | ||
241 | }; | 236 | }; |
242 | 237 | ||
@@ -364,7 +359,7 @@ do_error (void *cls) | |||
364 | struct RequestHandle *handle = cls; | 359 | struct RequestHandle *handle = cls; |
365 | struct MHD_Response *resp = GNUNET_REST_create_json_response (NULL); | 360 | struct MHD_Response *resp = GNUNET_REST_create_json_response (NULL); |
366 | 361 | ||
367 | handle->proc (handle->proc_cls, resp, MHD_HTTP_BAD_REQUEST); | 362 | handle->proc (handle->proc_cls, resp, handle->response_code); |
368 | cleanup_handle (handle); | 363 | cleanup_handle (handle); |
369 | } | 364 | } |
370 | 365 | ||
@@ -596,7 +591,7 @@ del_cont (void *cls, | |||
596 | } | 591 | } |
597 | 592 | ||
598 | static void | 593 | static void |
599 | namestore_delete_cont (struct RestConnectionDataHandle *con, | 594 | namestore_delete_cont (struct GNUNET_REST_RequestHandle *con, |
600 | const char *url, | 595 | const char *url, |
601 | void *cls) | 596 | void *cls) |
602 | { | 597 | { |
@@ -718,7 +713,7 @@ json_to_gnsrecord (const json_t *records_json, | |||
718 | } | 713 | } |
719 | 714 | ||
720 | static void | 715 | static void |
721 | namestore_create_cont (struct RestConnectionDataHandle *con, | 716 | namestore_create_cont (struct GNUNET_REST_RequestHandle *con, |
722 | const char *url, | 717 | const char *url, |
723 | void *cls) | 718 | void *cls) |
724 | { | 719 | { |
@@ -728,7 +723,7 @@ namestore_create_cont (struct RestConnectionDataHandle *con, | |||
728 | struct GNUNET_JSONAPI_Resource *json_res; | 723 | struct GNUNET_JSONAPI_Resource *json_res; |
729 | json_t *name_json; | 724 | json_t *name_json; |
730 | json_t *records_json; | 725 | json_t *records_json; |
731 | char term_data[handle->data_size+1]; | 726 | char term_data[handle->rest_handle->data_size+1]; |
732 | 727 | ||
733 | if (strlen (GNUNET_REST_API_NS_NAMESTORE) != strlen (handle->url)) | 728 | if (strlen (GNUNET_REST_API_NS_NAMESTORE) != strlen (handle->url)) |
734 | { | 729 | { |
@@ -737,13 +732,15 @@ namestore_create_cont (struct RestConnectionDataHandle *con, | |||
737 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 732 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
738 | return; | 733 | return; |
739 | } | 734 | } |
740 | if (0 >= handle->data_size) | 735 | if (0 >= handle->rest_handle->data_size) |
741 | { | 736 | { |
742 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 737 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
743 | return; | 738 | return; |
744 | } | 739 | } |
745 | term_data[handle->data_size] = '\0'; | 740 | term_data[handle->rest_handle->data_size] = '\0'; |
746 | memcpy (term_data, handle->data, handle->data_size); | 741 | memcpy (term_data, |
742 | handle->rest_handle->data, | ||
743 | handle->rest_handle->data_size); | ||
747 | GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_object_parse (term_data, | 744 | GNUNET_assert (GNUNET_OK == GNUNET_JSONAPI_object_parse (term_data, |
748 | &json_obj)); | 745 | &json_obj)); |
749 | if (NULL == json_obj) | 746 | if (NULL == json_obj) |
@@ -853,7 +850,7 @@ namestore_zkey_response (void *cls, | |||
853 | } | 850 | } |
854 | 851 | ||
855 | static void | 852 | static void |
856 | namestore_zkey_cont (struct RestConnectionDataHandle *con, | 853 | namestore_zkey_cont (struct GNUNET_REST_RequestHandle *con, |
857 | const char *url, | 854 | const char *url, |
858 | void *cls) | 855 | void *cls) |
859 | { | 856 | { |
@@ -865,7 +862,7 @@ namestore_zkey_cont (struct RestConnectionDataHandle *con, | |||
865 | strlen (GNUNET_REST_JSONAPI_NAMESTORE_ZKEY), | 862 | strlen (GNUNET_REST_JSONAPI_NAMESTORE_ZKEY), |
866 | &key); | 863 | &key); |
867 | if ( GNUNET_NO == | 864 | if ( GNUNET_NO == |
868 | GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map, | 865 | GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle->url_param_map, |
869 | &key) ) | 866 | &key) ) |
870 | { | 867 | { |
871 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 868 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -873,7 +870,7 @@ namestore_zkey_cont (struct RestConnectionDataHandle *con, | |||
873 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 870 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
874 | return; | 871 | return; |
875 | } | 872 | } |
876 | handle->zkey_str = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map, | 873 | handle->zkey_str = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map, |
877 | &key); | 874 | &key); |
878 | if (GNUNET_OK != | 875 | if (GNUNET_OK != |
879 | GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->zkey_str, | 876 | GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->zkey_str, |
@@ -893,7 +890,7 @@ namestore_zkey_cont (struct RestConnectionDataHandle *con, | |||
893 | } | 890 | } |
894 | 891 | ||
895 | static void | 892 | static void |
896 | namestore_info_cont (struct RestConnectionDataHandle *con, | 893 | namestore_info_cont (struct GNUNET_REST_RequestHandle *con, |
897 | const char *url, | 894 | const char *url, |
898 | void *cls) | 895 | void *cls) |
899 | { | 896 | { |
@@ -920,7 +917,7 @@ get_name_from_url (const char* url) | |||
920 | * @param cls the RequestHandle | 917 | * @param cls the RequestHandle |
921 | */ | 918 | */ |
922 | static void | 919 | static void |
923 | options_cont (struct RestConnectionDataHandle *con_handle, | 920 | options_cont (struct GNUNET_REST_RequestHandle *con_handle, |
924 | const char* url, | 921 | const char* url, |
925 | void *cls) | 922 | void *cls) |
926 | { | 923 | { |
@@ -950,7 +947,8 @@ testservice_task (void *cls, | |||
950 | int result) | 947 | int result) |
951 | { | 948 | { |
952 | struct RequestHandle *handle = cls; | 949 | struct RequestHandle *handle = cls; |
953 | static const struct GNUNET_REST_RestConnectionHandler handlers[] = { | 950 | struct GNUNET_REST_RequestHandlerError err; |
951 | static const struct GNUNET_REST_RequestHandler handlers[] = { | ||
954 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE_ZKEY, &namestore_zkey_cont}, //reverse | 952 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE_ZKEY, &namestore_zkey_cont}, //reverse |
955 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_info_cont}, //list | 953 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_info_cont}, //list |
956 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_create_cont}, //create | 954 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_create_cont}, //create |
@@ -976,8 +974,14 @@ testservice_task (void *cls, | |||
976 | return; | 974 | return; |
977 | } | 975 | } |
978 | 976 | ||
979 | if (GNUNET_NO == GNUNET_REST_handle_request (handle->conndata_handle, handlers, handle)) | 977 | if (GNUNET_OK != GNUNET_JSONAPI_handle_request (handle->rest_handle, |
978 | handlers, | ||
979 | &err, | ||
980 | handle)) | ||
981 | { | ||
982 | handle->response_code = err.error_code; | ||
980 | GNUNET_SCHEDULER_add_now (&do_error, (void*) handle); | 983 | GNUNET_SCHEDULER_add_now (&do_error, (void*) handle); |
984 | } | ||
981 | 985 | ||
982 | } | 986 | } |
983 | 987 | ||
@@ -1079,10 +1083,10 @@ testservice_id_task (void *cls, int result) | |||
1079 | strlen (GNUNET_REST_JSONAPI_NAMESTORE_EGO), | 1083 | strlen (GNUNET_REST_JSONAPI_NAMESTORE_EGO), |
1080 | &key); | 1084 | &key); |
1081 | if ( GNUNET_YES == | 1085 | if ( GNUNET_YES == |
1082 | GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map, | 1086 | GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle->url_param_map, |
1083 | &key) ) | 1087 | &key) ) |
1084 | { | 1088 | { |
1085 | ego = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map, | 1089 | ego = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map, |
1086 | &key); | 1090 | &key); |
1087 | } | 1091 | } |
1088 | 1092 | ||
@@ -1091,10 +1095,10 @@ testservice_id_task (void *cls, int result) | |||
1091 | strlen (GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE), | 1095 | strlen (GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE), |
1092 | &key); | 1096 | &key); |
1093 | if ( GNUNET_YES == | 1097 | if ( GNUNET_YES == |
1094 | GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map, | 1098 | GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle->url_param_map, |
1095 | &key) ) | 1099 | &key) ) |
1096 | { | 1100 | { |
1097 | type = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map, | 1101 | type = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map, |
1098 | &key); | 1102 | &key); |
1099 | 1103 | ||
1100 | handle->type = GNUNET_GNSRECORD_typename_to_number (type); | 1104 | handle->type = GNUNET_GNSRECORD_typename_to_number (type); |
@@ -1134,7 +1138,7 @@ testservice_id_task (void *cls, int result) | |||
1134 | * @return GNUNET_OK if request accepted | 1138 | * @return GNUNET_OK if request accepted |
1135 | */ | 1139 | */ |
1136 | static void | 1140 | static void |
1137 | rest_identity_process_request(struct RestConnectionDataHandle *conndata_handle, | 1141 | rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle, |
1138 | GNUNET_REST_ResultProcessor proc, | 1142 | GNUNET_REST_ResultProcessor proc, |
1139 | void *proc_cls) | 1143 | void *proc_cls) |
1140 | { | 1144 | { |
@@ -1143,10 +1147,8 @@ rest_identity_process_request(struct RestConnectionDataHandle *conndata_handle, | |||
1143 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 1147 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
1144 | handle->proc_cls = proc_cls; | 1148 | handle->proc_cls = proc_cls; |
1145 | handle->proc = proc; | 1149 | handle->proc = proc; |
1146 | handle->conndata_handle = conndata_handle; | 1150 | handle->rest_handle = rest_handle; |
1147 | handle->data = conndata_handle->data; | 1151 | GNUNET_asprintf (&handle->url, "%s", rest_handle->url); |
1148 | handle->data_size = conndata_handle->data_size; | ||
1149 | GNUNET_asprintf (&handle->url, "%s", conndata_handle->url); | ||
1150 | if (handle->url[strlen (handle->url)-1] == '/') | 1152 | if (handle->url[strlen (handle->url)-1] == '/') |
1151 | handle->url[strlen (handle->url)-1] = '\0'; | 1153 | handle->url[strlen (handle->url)-1] = '\0'; |
1152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |