diff options
Diffstat (limited to 'src/identity/plugin_rest_identity.c')
-rw-r--r-- | src/identity/plugin_rest_identity.c | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index 6859396d6..d86d29e36 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c | |||
@@ -191,6 +191,16 @@ struct EgoEntry | |||
191 | struct RequestHandle | 191 | struct RequestHandle |
192 | { | 192 | { |
193 | /** | 193 | /** |
194 | * DLL | ||
195 | */ | ||
196 | struct RequestHandle *next; | ||
197 | |||
198 | /** | ||
199 | * DLL | ||
200 | */ | ||
201 | struct RequestHandle *prev; | ||
202 | |||
203 | /** | ||
194 | * The data from the REST request | 204 | * The data from the REST request |
195 | */ | 205 | */ |
196 | const char *data; | 206 | const char *data; |
@@ -252,6 +262,16 @@ struct RequestHandle | |||
252 | }; | 262 | }; |
253 | 263 | ||
254 | /** | 264 | /** |
265 | * DLL | ||
266 | */ | ||
267 | static struct RequestHandle *requests_head; | ||
268 | |||
269 | /** | ||
270 | * DLL | ||
271 | */ | ||
272 | static struct RequestHandle *requests_tail; | ||
273 | |||
274 | /** | ||
255 | * Cleanup lookup handle | 275 | * Cleanup lookup handle |
256 | * @param handle Handle to clean up | 276 | * @param handle Handle to clean up |
257 | */ | 277 | */ |
@@ -273,7 +293,9 @@ cleanup_handle (void *cls) | |||
273 | GNUNET_free (handle->emsg); | 293 | GNUNET_free (handle->emsg); |
274 | if (NULL != handle->name) | 294 | if (NULL != handle->name) |
275 | GNUNET_free (handle->name); | 295 | GNUNET_free (handle->name); |
276 | 296 | GNUNET_CONTAINER_DLL_remove (requests_head, | |
297 | requests_tail, | ||
298 | handle); | ||
277 | GNUNET_free (handle); | 299 | GNUNET_free (handle); |
278 | } | 300 | } |
279 | 301 | ||
@@ -1274,13 +1296,13 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
1274 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); | 1296 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); |
1275 | struct GNUNET_REST_RequestHandlerError err; | 1297 | struct GNUNET_REST_RequestHandlerError err; |
1276 | static const struct GNUNET_REST_RequestHandler handlers[] = | 1298 | static const struct GNUNET_REST_RequestHandler handlers[] = |
1277 | { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_get_all }, | 1299 | { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY, |
1278 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY, | ||
1279 | &ego_get_pubkey }, | 1300 | &ego_get_pubkey }, |
1280 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name }, | 1301 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name }, |
1281 | { MHD_HTTP_METHOD_GET, | 1302 | { MHD_HTTP_METHOD_GET, |
1282 | GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, | 1303 | GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, |
1283 | &ego_get_subsystem }, | 1304 | &ego_get_subsystem }, |
1305 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_get_all }, | ||
1284 | { MHD_HTTP_METHOD_PUT, | 1306 | { MHD_HTTP_METHOD_PUT, |
1285 | GNUNET_REST_API_NS_IDENTITY_PUBKEY, | 1307 | GNUNET_REST_API_NS_IDENTITY_PUBKEY, |
1286 | &ego_edit_pubkey }, | 1308 | &ego_edit_pubkey }, |
@@ -1310,6 +1332,11 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
1310 | handle->url = GNUNET_strdup (rest_handle->url); | 1332 | handle->url = GNUNET_strdup (rest_handle->url); |
1311 | if (handle->url[strlen (handle->url) - 1] == '/') | 1333 | if (handle->url[strlen (handle->url) - 1] == '/') |
1312 | handle->url[strlen (handle->url) - 1] = '\0'; | 1334 | handle->url[strlen (handle->url) - 1] = '\0'; |
1335 | handle->timeout_task = | ||
1336 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_error, handle); | ||
1337 | GNUNET_CONTAINER_DLL_insert (requests_head, | ||
1338 | requests_tail, | ||
1339 | handle); | ||
1313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 1340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); |
1314 | if (GNUNET_NO == | 1341 | if (GNUNET_NO == |
1315 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) | 1342 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) |
@@ -1318,8 +1345,6 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
1318 | return GNUNET_NO; | 1345 | return GNUNET_NO; |
1319 | } | 1346 | } |
1320 | 1347 | ||
1321 | handle->timeout_task = | ||
1322 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_error, handle); | ||
1323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); | 1348 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); |
1324 | return GNUNET_YES; | 1349 | return GNUNET_YES; |
1325 | } | 1350 | } |
@@ -1353,6 +1378,7 @@ libgnunet_plugin_rest_identity_init (void *cls) | |||
1353 | MHD_HTTP_METHOD_PUT, | 1378 | MHD_HTTP_METHOD_PUT, |
1354 | MHD_HTTP_METHOD_DELETE, | 1379 | MHD_HTTP_METHOD_DELETE, |
1355 | MHD_HTTP_METHOD_OPTIONS); | 1380 | MHD_HTTP_METHOD_OPTIONS); |
1381 | state = ID_REST_STATE_INIT; | ||
1356 | identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL); | 1382 | identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL); |
1357 | 1383 | ||
1358 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Identity REST API initialized\n")); | 1384 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Identity REST API initialized\n")); |
@@ -1375,6 +1401,8 @@ libgnunet_plugin_rest_identity_done (void *cls) | |||
1375 | struct EgoEntry *ego_tmp; | 1401 | struct EgoEntry *ego_tmp; |
1376 | 1402 | ||
1377 | plugin->cfg = NULL; | 1403 | plugin->cfg = NULL; |
1404 | while (NULL != requests_head) | ||
1405 | cleanup_handle (requests_head); | ||
1378 | if (NULL != identity_handle) | 1406 | if (NULL != identity_handle) |
1379 | GNUNET_IDENTITY_disconnect (identity_handle); | 1407 | GNUNET_IDENTITY_disconnect (identity_handle); |
1380 | 1408 | ||