diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2020-08-04 19:40:23 +0200 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2020-08-04 19:40:23 +0200 |
commit | 815ded19f106990a37bbacec83546b1b897491f6 (patch) | |
tree | 9f9b013616809dad4cec996f96d0ca5e59331410 /src/peerinfo-tool | |
parent | 080519e980d8f8a3b138c733f837417bdb1b6757 (diff) | |
download | gnunet-815ded19f106990a37bbacec83546b1b897491f6.tar.gz gnunet-815ded19f106990a37bbacec83546b1b897491f6.zip |
rest: fix #6462
Diffstat (limited to 'src/peerinfo-tool')
-rw-r--r-- | src/peerinfo-tool/plugin_rest_peerinfo.c | 66 |
1 files changed, 27 insertions, 39 deletions
diff --git a/src/peerinfo-tool/plugin_rest_peerinfo.c b/src/peerinfo-tool/plugin_rest_peerinfo.c index 1ab6d6f75..1d7461b1a 100644 --- a/src/peerinfo-tool/plugin_rest_peerinfo.c +++ b/src/peerinfo-tool/plugin_rest_peerinfo.c | |||
@@ -70,7 +70,12 @@ const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
70 | /** | 70 | /** |
71 | * HTTP methods allows for this plugin | 71 | * HTTP methods allows for this plugin |
72 | */ | 72 | */ |
73 | static char*allow_methods; | 73 | static char *allow_methods; |
74 | |||
75 | /** | ||
76 | * Handle to PEERINFO | ||
77 | */ | ||
78 | static struct GNUNET_PEERINFO_Handle *peerinfo_handle; | ||
74 | 79 | ||
75 | /** | 80 | /** |
76 | * @brief struct returned by the initialization function of the plugin | 81 | * @brief struct returned by the initialization function of the plugin |
@@ -204,10 +209,6 @@ struct RequestHandle | |||
204 | */ | 209 | */ |
205 | struct GNUNET_PEERINFO_IteratorContext *list_it; | 210 | struct GNUNET_PEERINFO_IteratorContext *list_it; |
206 | 211 | ||
207 | /** | ||
208 | * Handle to PEERINFO | ||
209 | */ | ||
210 | struct GNUNET_PEERINFO_Handle *peerinfo_handle; | ||
211 | 212 | ||
212 | /** | 213 | /** |
213 | * Rest connection | 214 | * Rest connection |
@@ -294,10 +295,10 @@ cleanup_handle (void *cls) | |||
294 | GNUNET_PEERINFO_iterate_cancel (handle->list_it); | 295 | GNUNET_PEERINFO_iterate_cancel (handle->list_it); |
295 | handle->list_it = NULL; | 296 | handle->list_it = NULL; |
296 | } | 297 | } |
297 | if (NULL != handle->peerinfo_handle) | 298 | if (NULL != peerinfo_handle) |
298 | { | 299 | { |
299 | GNUNET_PEERINFO_disconnect (handle->peerinfo_handle); | 300 | GNUNET_PEERINFO_disconnect (peerinfo_handle); |
300 | handle->peerinfo_handle = NULL; | 301 | peerinfo_handle = NULL; |
301 | } | 302 | } |
302 | 303 | ||
303 | GNUNET_free (handle); | 304 | GNUNET_free (handle); |
@@ -664,7 +665,7 @@ peerinfo_get (struct GNUNET_REST_RequestHandle *con_handle, | |||
664 | // specific_peer = GNUNET_PEER_resolve2(peer_id); | 665 | // specific_peer = GNUNET_PEER_resolve2(peer_id); |
665 | } | 666 | } |
666 | 667 | ||
667 | handle->list_it = GNUNET_PEERINFO_iterate (handle->peerinfo_handle, | 668 | handle->list_it = GNUNET_PEERINFO_iterate (peerinfo_handle, |
668 | include_friend_only, | 669 | include_friend_only, |
669 | specific_peer, | 670 | specific_peer, |
670 | &peerinfo_list_iteration, | 671 | &peerinfo_list_iteration, |
@@ -699,32 +700,6 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
699 | 700 | ||
700 | 701 | ||
701 | /** | 702 | /** |
702 | * Handle rest request | ||
703 | * | ||
704 | * @param handle the request handle | ||
705 | */ | ||
706 | static void | ||
707 | init_cont (struct RequestHandle *handle) | ||
708 | { | ||
709 | struct GNUNET_REST_RequestHandlerError err; | ||
710 | static const struct GNUNET_REST_RequestHandler handlers[] = { | ||
711 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_PEERINFO, &peerinfo_get }, | ||
712 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_PEERINFO, &options_cont }, | ||
713 | GNUNET_REST_HANDLER_END | ||
714 | }; | ||
715 | |||
716 | if (GNUNET_NO == GNUNET_REST_handle_request (handle->rest_handle, | ||
717 | handlers, | ||
718 | &err, | ||
719 | handle)) | ||
720 | { | ||
721 | handle->response_code = err.error_code; | ||
722 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
723 | } | ||
724 | } | ||
725 | |||
726 | |||
727 | /** | ||
728 | * Function processing the REST call | 703 | * Function processing the REST call |
729 | * | 704 | * |
730 | * @param method HTTP method | 705 | * @param method HTTP method |
@@ -735,12 +710,18 @@ init_cont (struct RequestHandle *handle) | |||
735 | * @param proc_cls closure for callback function | 710 | * @param proc_cls closure for callback function |
736 | * @return GNUNET_OK if request accepted | 711 | * @return GNUNET_OK if request accepted |
737 | */ | 712 | */ |
738 | static void | 713 | static enum GNUNET_GenericReturnValue |
739 | rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | 714 | rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, |
740 | GNUNET_REST_ResultProcessor proc, | 715 | GNUNET_REST_ResultProcessor proc, |
741 | void *proc_cls) | 716 | void *proc_cls) |
742 | { | 717 | { |
743 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); | 718 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); |
719 | struct GNUNET_REST_RequestHandlerError err; | ||
720 | static const struct GNUNET_REST_RequestHandler handlers[] = { | ||
721 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_PEERINFO, &peerinfo_get }, | ||
722 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_PEERINFO, &options_cont }, | ||
723 | GNUNET_REST_HANDLER_END | ||
724 | }; | ||
744 | 725 | ||
745 | handle->response_code = 0; | 726 | handle->response_code = 0; |
746 | handle->timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 727 | handle->timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, |
@@ -753,14 +734,20 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
753 | if (handle->url[strlen (handle->url) - 1] == '/') | 734 | if (handle->url[strlen (handle->url) - 1] == '/') |
754 | handle->url[strlen (handle->url) - 1] = '\0'; | 735 | handle->url[strlen (handle->url) - 1] = '\0'; |
755 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 736 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); |
756 | handle->peerinfo_handle = GNUNET_PEERINFO_connect (cfg); | 737 | if (GNUNET_NO == GNUNET_REST_handle_request (handle->rest_handle, |
757 | init_cont (handle); | 738 | handlers, |
739 | &err, | ||
740 | handle)) | ||
741 | { | ||
742 | cleanup_handle (handle); | ||
743 | return GNUNET_NO; | ||
744 | } | ||
758 | handle->timeout_task = | 745 | handle->timeout_task = |
759 | GNUNET_SCHEDULER_add_delayed (handle->timeout, | 746 | GNUNET_SCHEDULER_add_delayed (handle->timeout, |
760 | &do_error, | 747 | &do_error, |
761 | handle); | 748 | handle); |
762 | |||
763 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); | 749 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); |
750 | return GNUNET_YES; | ||
764 | } | 751 | } |
765 | 752 | ||
766 | 753 | ||
@@ -792,6 +779,7 @@ libgnunet_plugin_rest_peerinfo_init (void *cls) | |||
792 | MHD_HTTP_METHOD_PUT, | 779 | MHD_HTTP_METHOD_PUT, |
793 | MHD_HTTP_METHOD_DELETE, | 780 | MHD_HTTP_METHOD_DELETE, |
794 | MHD_HTTP_METHOD_OPTIONS); | 781 | MHD_HTTP_METHOD_OPTIONS); |
782 | peerinfo_handle = GNUNET_PEERINFO_connect (cfg); | ||
795 | 783 | ||
796 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 784 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
797 | _ ("Peerinfo REST API initialized\n")); | 785 | _ ("Peerinfo REST API initialized\n")); |