diff options
author | Schanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de> | 2018-01-22 17:41:14 +0100 |
---|---|---|
committer | Schanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de> | 2018-01-22 17:41:14 +0100 |
commit | b8810222ee74c1216b18da9749522710c155c9be (patch) | |
tree | 96d4774f75f71eb2d6c8ca29a0b7d552632d9c94 /src/rest/gnunet-rest-server.c | |
parent | 4fce9ab87811196126dc64afa905cb72688728ea (diff) | |
download | gnunet-b8810222ee74c1216b18da9749522710c155c9be.tar.gz gnunet-b8810222ee74c1216b18da9749522710c155c9be.zip |
fix rest header parsing as well
Diffstat (limited to 'src/rest/gnunet-rest-server.c')
-rw-r--r-- | src/rest/gnunet-rest-server.c | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/rest/gnunet-rest-server.c b/src/rest/gnunet-rest-server.c index 072f24cb2..c79c807a6 100644 --- a/src/rest/gnunet-rest-server.c +++ b/src/rest/gnunet-rest-server.c | |||
@@ -203,6 +203,14 @@ cleanup_handle (struct MhdConnectionHandle *handle) | |||
203 | MHD_destroy_response (handle->response); | 203 | MHD_destroy_response (handle->response); |
204 | if (NULL != handle->data_handle) | 204 | if (NULL != handle->data_handle) |
205 | { | 205 | { |
206 | |||
207 | if (NULL != handle->data_handle->header_param_map) | ||
208 | { | ||
209 | GNUNET_CONTAINER_multihashmap_iterate (handle->data_handle->header_param_map, | ||
210 | &cleanup_url_map, | ||
211 | NULL); | ||
212 | GNUNET_CONTAINER_multihashmap_destroy (handle->data_handle->header_param_map); | ||
213 | } | ||
206 | if (NULL != handle->data_handle->url_param_map) | 214 | if (NULL != handle->data_handle->url_param_map) |
207 | { | 215 | { |
208 | GNUNET_CONTAINER_multihashmap_iterate (handle->data_handle->url_param_map, | 216 | GNUNET_CONTAINER_multihashmap_iterate (handle->data_handle->url_param_map, |
@@ -215,6 +223,31 @@ cleanup_handle (struct MhdConnectionHandle *handle) | |||
215 | GNUNET_free (handle); | 223 | GNUNET_free (handle); |
216 | } | 224 | } |
217 | 225 | ||
226 | static int | ||
227 | header_iterator (void *cls, | ||
228 | enum MHD_ValueKind kind, | ||
229 | const char *key, | ||
230 | const char *value) | ||
231 | { | ||
232 | struct GNUNET_REST_RequestHandle *handle = cls; | ||
233 | struct GNUNET_HashCode hkey; | ||
234 | char *val; | ||
235 | |||
236 | GNUNET_CRYPTO_hash (key, strlen (key), &hkey); | ||
237 | GNUNET_asprintf (&val, "%s", value); | ||
238 | if (GNUNET_OK != | ||
239 | GNUNET_CONTAINER_multihashmap_put (handle->header_param_map, | ||
240 | &hkey, | ||
241 | val, | ||
242 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
243 | { | ||
244 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
245 | "Could not load add header `%s'=%s\n", | ||
246 | key, value); | ||
247 | } | ||
248 | return MHD_YES; | ||
249 | } | ||
250 | |||
218 | 251 | ||
219 | static int | 252 | static int |
220 | url_iterator (void *cls, | 253 | url_iterator (void *cls, |
@@ -358,15 +391,17 @@ create_response (void *cls, | |||
358 | rest_conndata_handle->data_size = *upload_data_size; | 391 | rest_conndata_handle->data_size = *upload_data_size; |
359 | rest_conndata_handle->url_param_map = GNUNET_CONTAINER_multihashmap_create (16, | 392 | rest_conndata_handle->url_param_map = GNUNET_CONTAINER_multihashmap_create (16, |
360 | GNUNET_NO); | 393 | GNUNET_NO); |
394 | rest_conndata_handle->header_param_map = GNUNET_CONTAINER_multihashmap_create (16, | ||
395 | GNUNET_NO); | ||
361 | con_handle->data_handle = rest_conndata_handle; | 396 | con_handle->data_handle = rest_conndata_handle; |
362 | MHD_get_connection_values (con, | 397 | MHD_get_connection_values (con, |
363 | MHD_GET_ARGUMENT_KIND, | 398 | MHD_GET_ARGUMENT_KIND, |
364 | &url_iterator, | 399 | &url_iterator, |
365 | rest_conndata_handle); | 400 | rest_conndata_handle); |
366 | con_handle->pp = MHD_create_post_processor(con, | 401 | con_handle->pp = MHD_create_post_processor(con, |
367 | 4000, | 402 | 4000, |
368 | post_data_iter, | 403 | post_data_iter, |
369 | rest_conndata_handle); | 404 | rest_conndata_handle); |
370 | if (*upload_data_size) | 405 | if (*upload_data_size) |
371 | { | 406 | { |
372 | MHD_post_process(con_handle->pp, upload_data, *upload_data_size); | 407 | MHD_post_process(con_handle->pp, upload_data, *upload_data_size); |
@@ -375,6 +410,10 @@ create_response (void *cls, | |||
375 | { | 410 | { |
376 | MHD_destroy_post_processor(con_handle->pp); | 411 | MHD_destroy_post_processor(con_handle->pp); |
377 | } | 412 | } |
413 | MHD_get_connection_values (con, | ||
414 | MHD_HEADER_KIND, | ||
415 | &header_iterator, | ||
416 | rest_conndata_handle); | ||
378 | con_handle->state = GN_REST_STATE_PROCESSING; | 417 | con_handle->state = GN_REST_STATE_PROCESSING; |
379 | con_handle->plugin->process_request (rest_conndata_handle, | 418 | con_handle->plugin->process_request (rest_conndata_handle, |
380 | &plugin_callback, | 419 | &plugin_callback, |