diff options
Diffstat (limited to 'src/rest/plugin_rest_copying.c')
-rw-r--r-- | src/rest/plugin_rest_copying.c | 112 |
1 files changed, 55 insertions, 57 deletions
diff --git a/src/rest/plugin_rest_copying.c b/src/rest/plugin_rest_copying.c index 92c2c6601..4ebf032a7 100644 --- a/src/rest/plugin_rest_copying.c +++ b/src/rest/plugin_rest_copying.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @author Martin Schanzenbach | 21 | * @author Martin Schanzenbach |
22 | * @file gns/plugin_rest_copying.c | 22 | * @file gns/plugin_rest_copying.c |
@@ -35,15 +35,13 @@ | |||
35 | /** | 35 | /** |
36 | * @brief struct returned by the initialization function of the plugin | 36 | * @brief struct returned by the initialization function of the plugin |
37 | */ | 37 | */ |
38 | struct Plugin | 38 | struct Plugin { |
39 | { | ||
40 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 39 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
41 | }; | 40 | }; |
42 | 41 | ||
43 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 42 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
44 | 43 | ||
45 | struct RequestHandle | 44 | struct RequestHandle { |
46 | { | ||
47 | /** | 45 | /** |
48 | * Handle to rest request | 46 | * Handle to rest request |
49 | */ | 47 | */ |
@@ -63,7 +61,6 @@ struct RequestHandle | |||
63 | * HTTP response code | 61 | * HTTP response code |
64 | */ | 62 | */ |
65 | int response_code; | 63 | int response_code; |
66 | |||
67 | }; | 64 | }; |
68 | 65 | ||
69 | 66 | ||
@@ -73,11 +70,11 @@ struct RequestHandle | |||
73 | * @param handle Handle to clean up | 70 | * @param handle Handle to clean up |
74 | */ | 71 | */ |
75 | static void | 72 | static void |
76 | cleanup_handle (struct RequestHandle *handle) | 73 | cleanup_handle(struct RequestHandle *handle) |
77 | { | 74 | { |
78 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 75 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
79 | "Cleaning up\n"); | 76 | "Cleaning up\n"); |
80 | GNUNET_free (handle); | 77 | GNUNET_free(handle); |
81 | } | 78 | } |
82 | 79 | ||
83 | 80 | ||
@@ -88,14 +85,14 @@ cleanup_handle (struct RequestHandle *handle) | |||
88 | * @param tc scheduler context | 85 | * @param tc scheduler context |
89 | */ | 86 | */ |
90 | static void | 87 | static void |
91 | do_error (void *cls) | 88 | do_error(void *cls) |
92 | { | 89 | { |
93 | struct RequestHandle *handle = cls; | 90 | struct RequestHandle *handle = cls; |
94 | struct MHD_Response *resp; | 91 | struct MHD_Response *resp; |
95 | 92 | ||
96 | resp = GNUNET_REST_create_response (NULL); | 93 | resp = GNUNET_REST_create_response(NULL); |
97 | handle->proc (handle->proc_cls, resp, handle->response_code); | 94 | handle->proc(handle->proc_cls, resp, handle->response_code); |
98 | cleanup_handle (handle); | 95 | cleanup_handle(handle); |
99 | } | 96 | } |
100 | 97 | ||
101 | 98 | ||
@@ -105,18 +102,18 @@ do_error (void *cls) | |||
105 | * @param handle the lookup handle | 102 | * @param handle the lookup handle |
106 | */ | 103 | */ |
107 | static void | 104 | static void |
108 | get_cont (struct GNUNET_REST_RequestHandle *con_handle, | 105 | get_cont(struct GNUNET_REST_RequestHandle *con_handle, |
109 | const char* url, | 106 | const char* url, |
110 | void *cls) | 107 | void *cls) |
111 | { | 108 | { |
112 | struct MHD_Response *resp; | 109 | struct MHD_Response *resp; |
113 | struct RequestHandle *handle = cls; | 110 | struct RequestHandle *handle = cls; |
114 | 111 | ||
115 | resp = GNUNET_REST_create_response (GNUNET_REST_COPYING_TEXT); | 112 | resp = GNUNET_REST_create_response(GNUNET_REST_COPYING_TEXT); |
116 | handle->proc (handle->proc_cls, | 113 | handle->proc(handle->proc_cls, |
117 | resp, | 114 | resp, |
118 | MHD_HTTP_OK); | 115 | MHD_HTTP_OK); |
119 | cleanup_handle (handle); | 116 | cleanup_handle(handle); |
120 | } | 117 | } |
121 | 118 | ||
122 | 119 | ||
@@ -127,21 +124,21 @@ get_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
127 | * @param handle the lookup handle | 124 | * @param handle the lookup handle |
128 | */ | 125 | */ |
129 | static void | 126 | static void |
130 | options_cont (struct GNUNET_REST_RequestHandle *con_handle, | 127 | options_cont(struct GNUNET_REST_RequestHandle *con_handle, |
131 | const char* url, | 128 | const char* url, |
132 | void *cls) | 129 | void *cls) |
133 | { | 130 | { |
134 | struct MHD_Response *resp; | 131 | struct MHD_Response *resp; |
135 | struct RequestHandle *handle = cls; | 132 | struct RequestHandle *handle = cls; |
136 | 133 | ||
137 | resp = GNUNET_REST_create_response (NULL); | 134 | resp = GNUNET_REST_create_response(NULL); |
138 | MHD_add_response_header (resp, | 135 | MHD_add_response_header(resp, |
139 | "Access-Control-Allow-Methods", | 136 | "Access-Control-Allow-Methods", |
140 | MHD_HTTP_METHOD_GET); | 137 | MHD_HTTP_METHOD_GET); |
141 | handle->proc (handle->proc_cls, | 138 | handle->proc(handle->proc_cls, |
142 | resp, | 139 | resp, |
143 | MHD_HTTP_OK); | 140 | MHD_HTTP_OK); |
144 | cleanup_handle (handle); | 141 | cleanup_handle(handle); |
145 | } | 142 | } |
146 | 143 | ||
147 | 144 | ||
@@ -157,30 +154,30 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
157 | * @return #GNUNET_OK if request accepted | 154 | * @return #GNUNET_OK if request accepted |
158 | */ | 155 | */ |
159 | static void | 156 | static void |
160 | rest_copying_process_request (struct GNUNET_REST_RequestHandle *conndata_handle, | 157 | rest_copying_process_request(struct GNUNET_REST_RequestHandle *conndata_handle, |
161 | GNUNET_REST_ResultProcessor proc, | 158 | GNUNET_REST_ResultProcessor proc, |
162 | void *proc_cls) | 159 | void *proc_cls) |
163 | { | 160 | { |
164 | static const struct GNUNET_REST_RequestHandler handlers[] = { | 161 | static const struct GNUNET_REST_RequestHandler handlers[] = { |
165 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_COPYING, &get_cont}, | 162 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_COPYING, &get_cont }, |
166 | {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_COPYING, &options_cont}, | 163 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_COPYING, &options_cont }, |
167 | GNUNET_REST_HANDLER_END | 164 | GNUNET_REST_HANDLER_END |
168 | }; | 165 | }; |
169 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); | 166 | struct RequestHandle *handle = GNUNET_new(struct RequestHandle); |
170 | struct GNUNET_REST_RequestHandlerError err; | 167 | struct GNUNET_REST_RequestHandlerError err; |
171 | 168 | ||
172 | handle->proc_cls = proc_cls; | 169 | handle->proc_cls = proc_cls; |
173 | handle->proc = proc; | 170 | handle->proc = proc; |
174 | handle->rest_handle = conndata_handle; | 171 | handle->rest_handle = conndata_handle; |
175 | 172 | ||
176 | if (GNUNET_NO == GNUNET_REST_handle_request (conndata_handle, | 173 | if (GNUNET_NO == GNUNET_REST_handle_request(conndata_handle, |
177 | handlers, | 174 | handlers, |
178 | &err, | 175 | &err, |
179 | handle)) | 176 | handle)) |
180 | { | 177 | { |
181 | handle->response_code = err.error_code; | 178 | handle->response_code = err.error_code; |
182 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 179 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
183 | } | 180 | } |
184 | } | 181 | } |
185 | 182 | ||
186 | 183 | ||
@@ -191,22 +188,23 @@ rest_copying_process_request (struct GNUNET_REST_RequestHandle *conndata_handle, | |||
191 | * @return NULL on error, otherwise the plugin context | 188 | * @return NULL on error, otherwise the plugin context |
192 | */ | 189 | */ |
193 | void * | 190 | void * |
194 | libgnunet_plugin_rest_copying_init (void *cls) | 191 | libgnunet_plugin_rest_copying_init(void *cls) |
195 | { | 192 | { |
196 | static struct Plugin plugin; | 193 | static struct Plugin plugin; |
194 | |||
197 | cfg = cls; | 195 | cfg = cls; |
198 | struct GNUNET_REST_Plugin *api; | 196 | struct GNUNET_REST_Plugin *api; |
199 | 197 | ||
200 | if (NULL != plugin.cfg) | 198 | if (NULL != plugin.cfg) |
201 | return NULL; /* can only initialize once! */ | 199 | return NULL; /* can only initialize once! */ |
202 | memset (&plugin, 0, sizeof (struct Plugin)); | 200 | memset(&plugin, 0, sizeof(struct Plugin)); |
203 | plugin.cfg = cfg; | 201 | plugin.cfg = cfg; |
204 | api = GNUNET_new (struct GNUNET_REST_Plugin); | 202 | api = GNUNET_new(struct GNUNET_REST_Plugin); |
205 | api->cls = &plugin; | 203 | api->cls = &plugin; |
206 | api->name = GNUNET_REST_API_NS_COPYING; | 204 | api->name = GNUNET_REST_API_NS_COPYING; |
207 | api->process_request = &rest_copying_process_request; | 205 | api->process_request = &rest_copying_process_request; |
208 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 206 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
209 | _("COPYING REST API initialized\n")); | 207 | _("COPYING REST API initialized\n")); |
210 | return api; | 208 | return api; |
211 | } | 209 | } |
212 | 210 | ||
@@ -218,15 +216,15 @@ libgnunet_plugin_rest_copying_init (void *cls) | |||
218 | * @return always NULL | 216 | * @return always NULL |
219 | */ | 217 | */ |
220 | void * | 218 | void * |
221 | libgnunet_plugin_rest_copying_done (void *cls) | 219 | libgnunet_plugin_rest_copying_done(void *cls) |
222 | { | 220 | { |
223 | struct GNUNET_REST_Plugin *api = cls; | 221 | struct GNUNET_REST_Plugin *api = cls; |
224 | struct Plugin *plugin = api->cls; | 222 | struct Plugin *plugin = api->cls; |
225 | 223 | ||
226 | plugin->cfg = NULL; | 224 | plugin->cfg = NULL; |
227 | GNUNET_free (api); | 225 | GNUNET_free(api); |
228 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 226 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
229 | "COPYING REST plugin is finished\n"); | 227 | "COPYING REST plugin is finished\n"); |
230 | return NULL; | 228 | return NULL; |
231 | } | 229 | } |
232 | 230 | ||