aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/plugin_rest_namestore.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-10-23 15:58:23 +0000
committerChristian Grothoff <christian@grothoff.org>2016-10-23 15:58:23 +0000
commit3ecbb9b47c2f8c1ed5e9dbed4803999420dbd6ac (patch)
treef6266a7b908593cb99992fb6da539f7f6e6c8220 /src/namestore/plugin_rest_namestore.c
parent1358762d69a894017d1be7d3d55367e492deb111 (diff)
downloadgnunet-3ecbb9b47c2f8c1ed5e9dbed4803999420dbd6ac.tar.gz
gnunet-3ecbb9b47c2f8c1ed5e9dbed4803999420dbd6ac.zip
simplify gnunet-namestore / namestore_rest_plugin to avoid deprecated CLIENT_service_test
Diffstat (limited to 'src/namestore/plugin_rest_namestore.c')
-rw-r--r--src/namestore/plugin_rest_namestore.c151
1 files changed, 53 insertions, 98 deletions
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c
index 58ab46ca9..0d36cf445 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -967,22 +967,22 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
967 allow_methods); 967 allow_methods);
968 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); 968 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
969 cleanup_handle (handle); 969 cleanup_handle (handle);
970 return;
971} 970}
972 971
972
973/** 973/**
974 * Function called with the result from the check if the namestore 974 * Callback invoked from identity service with ego information.
975 * service is actually running. If it is, we start the actual 975 * An @a ego of NULL means the ego was not found.
976 * operation.
977 * 976 *
978 * @param cls closure with our configuration 977 * @param cls closure with the configuration
979 * @param result #GNUNET_YES if the namestore service is running 978 * @param ego an ego known to identity service, or NULL
980 */ 979 */
981static void 980static void
982testservice_task (void *cls, 981identity_cb (void *cls,
983 int result) 982 const struct GNUNET_IDENTITY_Ego *ego)
984{ 983{
985 struct RequestHandle *handle = cls; 984 struct RequestHandle *handle = cls;
985 struct MHD_Response *resp;
986 struct GNUNET_REST_RequestHandlerError err; 986 struct GNUNET_REST_RequestHandlerError err;
987 static const struct GNUNET_REST_RequestHandler handlers[] = { 987 static const struct GNUNET_REST_RequestHandler handlers[] = {
988 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE_ZKEY, &namestore_zkey_cont}, //reverse 988 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE_ZKEY, &namestore_zkey_cont}, //reverse
@@ -994,13 +994,21 @@ testservice_task (void *cls,
994 GNUNET_REST_HANDLER_END 994 GNUNET_REST_HANDLER_END
995 }; 995 };
996 996
997 if (GNUNET_YES != result) 997 handle->ego_lookup = NULL;
998 if (NULL == ego)
998 { 999 {
999 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Service `%s' is not running\n"), 1000 if (NULL != handle->ego_name)
1000 "namestore"); 1001 {
1001 GNUNET_SCHEDULER_add_now (&do_error, handle); 1002 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1003 _("Ego `%s' not known to identity service\n"),
1004 handle->ego_name);
1005 }
1006 resp = GNUNET_REST_create_response (NULL);
1007 handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
1008 cleanup_handle (handle);
1002 return; 1009 return;
1003 } 1010 }
1011 handle->zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
1004 handle->ns_handle = GNUNET_NAMESTORE_connect (cfg); 1012 handle->ns_handle = GNUNET_NAMESTORE_connect (cfg);
1005 if (NULL == handle->ns_handle) 1013 if (NULL == handle->ns_handle)
1006 { 1014 {
@@ -1010,51 +1018,18 @@ testservice_task (void *cls,
1010 return; 1018 return;
1011 } 1019 }
1012 1020
1013 if (GNUNET_OK != GNUNET_JSONAPI_handle_request (handle->rest_handle, 1021 if (GNUNET_OK !=
1014 handlers, 1022 GNUNET_JSONAPI_handle_request (handle->rest_handle,
1015 &err, 1023 handlers,
1016 handle)) 1024 &err,
1025 handle))
1017 { 1026 {
1018 handle->response_code = err.error_code; 1027 handle->response_code = err.error_code;
1019 GNUNET_SCHEDULER_add_now (&do_error, (void*) handle); 1028 GNUNET_SCHEDULER_add_now (&do_error,
1029 (void *) handle);
1020 } 1030 }
1021
1022} 1031}
1023 1032
1024/**
1025 * Callback invoked from identity service with ego information.
1026 * An @a ego of NULL means the ego was not found.
1027 *
1028 * @param cls closure with the configuration
1029 * @param ego an ego known to identity service, or NULL
1030 */
1031static void
1032identity_cb (void *cls,
1033 const struct GNUNET_IDENTITY_Ego *ego)
1034{
1035 struct RequestHandle *handle = cls;
1036 struct MHD_Response *resp;
1037
1038 handle->ego_lookup = NULL;
1039 if (NULL == ego)
1040 {
1041 if (NULL != handle->ego_name)
1042 {
1043 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1044 _("Ego `%s' not known to identity service\n"),
1045 handle->ego_name);
1046 }
1047 resp = GNUNET_REST_create_response (NULL);
1048 handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND);
1049 cleanup_handle (handle);
1050 return;
1051 }
1052 handle->zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
1053 GNUNET_CLIENT_service_test ("namestore", handle->cfg,
1054 GNUNET_TIME_UNIT_SECONDS,
1055 &testservice_task,
1056 (void *) handle);
1057}
1058 1033
1059static void 1034static void
1060default_ego_cb (void *cls, 1035default_ego_cb (void *cls,
@@ -1095,25 +1070,40 @@ id_connect_cb (void *cls,
1095 } 1070 }
1096} 1071}
1097 1072
1073
1074/**
1075 * Function processing the REST call
1076 *
1077 * @param method HTTP method
1078 * @param url URL of the HTTP request
1079 * @param data body of the HTTP request (optional)
1080 * @param data_size length of the body
1081 * @param proc callback function for the result
1082 * @param proc_cls closure for callback function
1083 * @return #GNUNET_OK if request accepted
1084 */
1098static void 1085static void
1099testservice_id_task (void *cls, int result) 1086rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
1087 GNUNET_REST_ResultProcessor proc,
1088 void *proc_cls)
1100{ 1089{
1101 struct RequestHandle *handle = cls; 1090 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1102 struct MHD_Response *resp; 1091 struct MHD_Response *resp;
1103 struct GNUNET_HashCode key; 1092 struct GNUNET_HashCode key;
1104 char *ego; 1093 char *ego;
1105 char *name; 1094 char *name;
1106 char *type; 1095 char *type;
1107 1096
1108 if (result != GNUNET_YES) 1097 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
1109 { 1098 handle->proc_cls = proc_cls;
1110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1099 handle->proc = proc;
1111 _("Identity service is not running\n")); 1100 handle->rest_handle = rest_handle;
1112 resp = GNUNET_REST_create_response (NULL); 1101 handle->url = GNUNET_strdup (rest_handle->url);
1113 handle->proc (handle->proc_cls, resp, MHD_HTTP_NOT_FOUND); 1102 if (handle->url[strlen (handle->url)-1] == '/')
1114 cleanup_handle (handle); 1103 handle->url[strlen (handle->url)-1] = '\0';
1115 return; 1104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1116 } 1105 "Connecting...\n");
1106 handle->cfg = cfg;
1117 ego = NULL; 1107 ego = NULL;
1118 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_NAMESTORE_EGO, 1108 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_NAMESTORE_EGO,
1119 strlen (GNUNET_REST_JSONAPI_NAMESTORE_EGO), 1109 strlen (GNUNET_REST_JSONAPI_NAMESTORE_EGO),
@@ -1160,41 +1150,6 @@ testservice_id_task (void *cls, int result)
1160 handle->ego_name, 1150 handle->ego_name,
1161 &identity_cb, 1151 &identity_cb,
1162 handle); 1152 handle);
1163}
1164
1165/**
1166 * Function processing the REST call
1167 *
1168 * @param method HTTP method
1169 * @param url URL of the HTTP request
1170 * @param data body of the HTTP request (optional)
1171 * @param data_size length of the body
1172 * @param proc callback function for the result
1173 * @param proc_cls closure for callback function
1174 * @return GNUNET_OK if request accepted
1175 */
1176static void
1177rest_identity_process_request(struct GNUNET_REST_RequestHandle *rest_handle,
1178 GNUNET_REST_ResultProcessor proc,
1179 void *proc_cls)
1180{
1181 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1182
1183 handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
1184 handle->proc_cls = proc_cls;
1185 handle->proc = proc;
1186 handle->rest_handle = rest_handle;
1187 handle->url = GNUNET_strdup (rest_handle->url);
1188 if (handle->url[strlen (handle->url)-1] == '/')
1189 handle->url[strlen (handle->url)-1] = '\0';
1190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1191 "Connecting...\n");
1192 handle->cfg = cfg;
1193 GNUNET_CLIENT_service_test ("identity",
1194 cfg,
1195 GNUNET_TIME_UNIT_SECONDS,
1196 &testservice_id_task,
1197 handle);
1198 handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout, 1153 handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout,
1199 &do_timeout, 1154 &do_timeout,
1200 handle); 1155 handle);