diff options
author | t3sserakt <t3ss@posteo.de> | 2020-08-28 17:57:44 +0200 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2020-08-28 17:57:53 +0200 |
commit | 2b552a5f5e85fab1c14af73735c0de61b46cc3dc (patch) | |
tree | 1ed739ddb116d77a7f2dfcc69c013f0eb9f731e7 /src/rest | |
parent | 03f6a0233f72c2c4c3925f0d6f6f7a81987c6530 (diff) | |
parent | bbf9540c93da3c6b950920ee7eaae479c95403c5 (diff) | |
download | gnunet-2b552a5f5e85fab1c14af73735c0de61b46cc3dc.tar.gz gnunet-2b552a5f5e85fab1c14af73735c0de61b46cc3dc.zip |
Merge branch 'master' of ssh://gnunet.org/gnunet
Diffstat (limited to 'src/rest')
-rw-r--r-- | src/rest/gnunet-rest-server.c | 20 | ||||
-rw-r--r-- | src/rest/plugin_rest_config.c | 37 | ||||
-rw-r--r-- | src/rest/plugin_rest_copying.c | 28 |
3 files changed, 75 insertions, 10 deletions
diff --git a/src/rest/gnunet-rest-server.c b/src/rest/gnunet-rest-server.c index 436b5b205..e6e03b16d 100644 --- a/src/rest/gnunet-rest-server.c +++ b/src/rest/gnunet-rest-server.c | |||
@@ -208,6 +208,11 @@ struct AcceptedRequest | |||
208 | * Connection | 208 | * Connection |
209 | */ | 209 | */ |
210 | struct MhdConnectionHandle *con_handle; | 210 | struct MhdConnectionHandle *con_handle; |
211 | |||
212 | /** | ||
213 | * State | ||
214 | */ | ||
215 | int socket_with_mhd; | ||
211 | }; | 216 | }; |
212 | 217 | ||
213 | /** | 218 | /** |
@@ -310,7 +315,13 @@ cleanup_ar (struct AcceptedRequest *ar) | |||
310 | { | 315 | { |
311 | cleanup_handle (ar->con_handle); | 316 | cleanup_handle (ar->con_handle); |
312 | } | 317 | } |
313 | GNUNET_NETWORK_socket_free_memory_only_ (ar->sock); | 318 | if (GNUNET_YES == ar->socket_with_mhd) |
319 | { | ||
320 | GNUNET_NETWORK_socket_free_memory_only_ (ar->sock); | ||
321 | } else { | ||
322 | GNUNET_NETWORK_socket_close (ar->sock); | ||
323 | } | ||
324 | ar->sock = NULL; | ||
314 | GNUNET_CONTAINER_DLL_remove (req_list_head, | 325 | GNUNET_CONTAINER_DLL_remove (req_list_head, |
315 | req_list_tail, | 326 | req_list_tail, |
316 | ar); | 327 | ar); |
@@ -529,7 +540,7 @@ create_response (void *cls, | |||
529 | MHD_suspend_connection (con_handle->con); | 540 | MHD_suspend_connection (con_handle->con); |
530 | return MHD_YES; | 541 | return MHD_YES; |
531 | } | 542 | } |
532 | MHD_resume_connection (con_handle->con); | 543 | //MHD_resume_connection (con_handle->con); |
533 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 544 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
534 | "Queueing response from plugin with MHD\n"); | 545 | "Queueing response from plugin with MHD\n"); |
535 | // Handle Preflights for extensions | 546 | // Handle Preflights for extensions |
@@ -767,7 +778,7 @@ mhd_completed_cb (void *cls, | |||
767 | cleanup_handle (ar->con_handle); | 778 | cleanup_handle (ar->con_handle); |
768 | ar->con_handle = NULL; | 779 | ar->con_handle = NULL; |
769 | } | 780 | } |
770 | schedule_httpd (); | 781 | ar->socket_with_mhd = GNUNET_YES; |
771 | *con_cls = NULL; | 782 | *con_cls = NULL; |
772 | } | 783 | } |
773 | 784 | ||
@@ -882,6 +893,7 @@ do_accept (void *cls) | |||
882 | else | 893 | else |
883 | GNUNET_assert (0); | 894 | GNUNET_assert (0); |
884 | ar = GNUNET_new (struct AcceptedRequest); | 895 | ar = GNUNET_new (struct AcceptedRequest); |
896 | ar->socket_with_mhd = GNUNET_YES; | ||
885 | ar->sock = GNUNET_NETWORK_socket_accept (lsock, NULL, NULL); | 897 | ar->sock = GNUNET_NETWORK_socket_accept (lsock, NULL, NULL); |
886 | if (NULL == ar->sock) | 898 | if (NULL == ar->sock) |
887 | { | 899 | { |
@@ -925,7 +937,7 @@ do_shutdown (void *cls) | |||
925 | GNUNET_CONTAINER_DLL_remove (plugins_head, | 937 | GNUNET_CONTAINER_DLL_remove (plugins_head, |
926 | plugins_tail, | 938 | plugins_tail, |
927 | ple); | 939 | ple); |
928 | GNUNET_PLUGIN_unload (ple->libname, NULL); | 940 | GNUNET_PLUGIN_unload (ple->libname, ple->plugin); |
929 | GNUNET_free (ple->libname); | 941 | GNUNET_free (ple->libname); |
930 | GNUNET_free (ple); | 942 | GNUNET_free (ple); |
931 | } | 943 | } |
diff --git a/src/rest/plugin_rest_config.c b/src/rest/plugin_rest_config.c index d9ae57acd..af833efff 100644 --- a/src/rest/plugin_rest_config.c +++ b/src/rest/plugin_rest_config.c | |||
@@ -45,6 +45,16 @@ const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
45 | struct RequestHandle | 45 | struct RequestHandle |
46 | { | 46 | { |
47 | /** | 47 | /** |
48 | * DLL | ||
49 | */ | ||
50 | struct RequestHandle *next; | ||
51 | |||
52 | /** | ||
53 | * DLL | ||
54 | */ | ||
55 | struct RequestHandle *prev; | ||
56 | |||
57 | /** | ||
48 | * Handle to rest request | 58 | * Handle to rest request |
49 | */ | 59 | */ |
50 | struct GNUNET_REST_RequestHandle *rest_handle; | 60 | struct GNUNET_REST_RequestHandle *rest_handle; |
@@ -70,6 +80,17 @@ struct RequestHandle | |||
70 | char *url; | 80 | char *url; |
71 | }; | 81 | }; |
72 | 82 | ||
83 | /** | ||
84 | * DLL | ||
85 | */ | ||
86 | static struct RequestHandle *requests_head; | ||
87 | |||
88 | /** | ||
89 | * DLL | ||
90 | */ | ||
91 | static struct RequestHandle *requests_tail; | ||
92 | |||
93 | |||
73 | 94 | ||
74 | /** | 95 | /** |
75 | * Cleanup request handle. | 96 | * Cleanup request handle. |
@@ -82,6 +103,9 @@ cleanup_handle (struct RequestHandle *handle) | |||
82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); | 103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); |
83 | if (NULL != handle->url) | 104 | if (NULL != handle->url) |
84 | GNUNET_free (handle->url); | 105 | GNUNET_free (handle->url); |
106 | GNUNET_CONTAINER_DLL_remove (requests_head, | ||
107 | requests_tail, | ||
108 | handle); | ||
85 | GNUNET_free (handle); | 109 | GNUNET_free (handle); |
86 | } | 110 | } |
87 | 111 | ||
@@ -367,7 +391,9 @@ rest_config_process_request (struct GNUNET_REST_RequestHandle *conndata_handle, | |||
367 | handle->url = GNUNET_strdup (conndata_handle->url); | 391 | handle->url = GNUNET_strdup (conndata_handle->url); |
368 | if (handle->url[strlen (handle->url) - 1] == '/') | 392 | if (handle->url[strlen (handle->url) - 1] == '/') |
369 | handle->url[strlen (handle->url) - 1] = '\0'; | 393 | handle->url[strlen (handle->url) - 1] = '\0'; |
370 | 394 | GNUNET_CONTAINER_DLL_insert (requests_head, | |
395 | requests_tail, | ||
396 | handle); | ||
371 | if (GNUNET_NO == | 397 | if (GNUNET_NO == |
372 | GNUNET_REST_handle_request (conndata_handle, handlers, &err, handle)) | 398 | GNUNET_REST_handle_request (conndata_handle, handlers, &err, handle)) |
373 | { | 399 | { |
@@ -392,15 +418,13 @@ libgnunet_plugin_rest_config_init (void *cls) | |||
392 | cfg = cls; | 418 | cfg = cls; |
393 | struct GNUNET_REST_Plugin *api; | 419 | struct GNUNET_REST_Plugin *api; |
394 | 420 | ||
395 | if (NULL != plugin.cfg) | ||
396 | return NULL; /* can only initialize once! */ | ||
397 | memset (&plugin, 0, sizeof(struct Plugin)); | 421 | memset (&plugin, 0, sizeof(struct Plugin)); |
398 | plugin.cfg = cfg; | 422 | plugin.cfg = cfg; |
399 | api = GNUNET_new (struct GNUNET_REST_Plugin); | 423 | api = GNUNET_new (struct GNUNET_REST_Plugin); |
400 | api->cls = &plugin; | 424 | api->cls = &plugin; |
401 | api->name = GNUNET_REST_API_NS_CONFIG; | 425 | api->name = GNUNET_REST_API_NS_CONFIG; |
402 | api->process_request = &rest_config_process_request; | 426 | api->process_request = &rest_config_process_request; |
403 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("CONFIG REST API initialized\n")); | 427 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("CONFIG REST API initialized\n")); |
404 | return api; | 428 | return api; |
405 | } | 429 | } |
406 | 430 | ||
@@ -415,8 +439,11 @@ void * | |||
415 | libgnunet_plugin_rest_config_done (void *cls) | 439 | libgnunet_plugin_rest_config_done (void *cls) |
416 | { | 440 | { |
417 | struct GNUNET_REST_Plugin *api = cls; | 441 | struct GNUNET_REST_Plugin *api = cls; |
418 | struct Plugin *plugin = api->cls; | 442 | struct Plugin *plugin; |
419 | 443 | ||
444 | while (NULL != requests_head) | ||
445 | cleanup_handle (requests_head); | ||
446 | plugin = api->cls; | ||
420 | plugin->cfg = NULL; | 447 | plugin->cfg = NULL; |
421 | GNUNET_free (api); | 448 | GNUNET_free (api); |
422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONFIG REST plugin is finished\n"); | 449 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONFIG REST plugin is finished\n"); |
diff --git a/src/rest/plugin_rest_copying.c b/src/rest/plugin_rest_copying.c index 1649da3bb..6d074d3d1 100644 --- a/src/rest/plugin_rest_copying.c +++ b/src/rest/plugin_rest_copying.c | |||
@@ -46,6 +46,16 @@ const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
46 | struct RequestHandle | 46 | struct RequestHandle |
47 | { | 47 | { |
48 | /** | 48 | /** |
49 | * DLL | ||
50 | */ | ||
51 | struct RequestHandle *next; | ||
52 | |||
53 | /** | ||
54 | * DLL | ||
55 | */ | ||
56 | struct RequestHandle *prev; | ||
57 | |||
58 | /** | ||
49 | * Handle to rest request | 59 | * Handle to rest request |
50 | */ | 60 | */ |
51 | struct GNUNET_REST_RequestHandle *rest_handle; | 61 | struct GNUNET_REST_RequestHandle *rest_handle; |
@@ -66,6 +76,15 @@ struct RequestHandle | |||
66 | int response_code; | 76 | int response_code; |
67 | }; | 77 | }; |
68 | 78 | ||
79 | /** | ||
80 | * DLL | ||
81 | */ | ||
82 | static struct RequestHandle *requests_head; | ||
83 | |||
84 | /** | ||
85 | * DLL | ||
86 | */ | ||
87 | static struct RequestHandle *requests_tail; | ||
69 | 88 | ||
70 | /** | 89 | /** |
71 | * Cleanup request handle. | 90 | * Cleanup request handle. |
@@ -77,6 +96,9 @@ cleanup_handle (struct RequestHandle *handle) | |||
77 | { | 96 | { |
78 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 97 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
79 | "Cleaning up\n"); | 98 | "Cleaning up\n"); |
99 | GNUNET_CONTAINER_DLL_remove (requests_head, | ||
100 | requests_tail, | ||
101 | handle); | ||
80 | GNUNET_free (handle); | 102 | GNUNET_free (handle); |
81 | } | 103 | } |
82 | 104 | ||
@@ -153,7 +175,9 @@ rest_copying_process_request (struct GNUNET_REST_RequestHandle *conndata_handle, | |||
153 | handle->proc_cls = proc_cls; | 175 | handle->proc_cls = proc_cls; |
154 | handle->proc = proc; | 176 | handle->proc = proc; |
155 | handle->rest_handle = conndata_handle; | 177 | handle->rest_handle = conndata_handle; |
156 | 178 | GNUNET_CONTAINER_DLL_insert (requests_head, | |
179 | requests_tail, | ||
180 | handle); | ||
157 | return GNUNET_REST_handle_request (conndata_handle, | 181 | return GNUNET_REST_handle_request (conndata_handle, |
158 | handlers, | 182 | handlers, |
159 | &err, | 183 | &err, |
@@ -201,6 +225,8 @@ libgnunet_plugin_rest_copying_done (void *cls) | |||
201 | struct GNUNET_REST_Plugin *api = cls; | 225 | struct GNUNET_REST_Plugin *api = cls; |
202 | struct Plugin *plugin = api->cls; | 226 | struct Plugin *plugin = api->cls; |
203 | 227 | ||
228 | while (NULL != requests_head) | ||
229 | cleanup_handle (requests_head); | ||
204 | plugin->cfg = NULL; | 230 | plugin->cfg = NULL; |
205 | GNUNET_free (api); | 231 | GNUNET_free (api); |
206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |