diff options
author | Schanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de> | 2017-12-11 13:01:03 +0100 |
---|---|---|
committer | Schanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de> | 2017-12-11 13:01:03 +0100 |
commit | 5da3c7cf721ee3f6fe6efe515b39e4a370650366 (patch) | |
tree | c717d543445ad57ffe152f50ec8a3db3e99160bc /src | |
parent | 3fdb794b668a634824072f57aac27368e9366e16 (diff) | |
download | gnunet-5da3c7cf721ee3f6fe6efe515b39e4a370650366.tar.gz gnunet-5da3c7cf721ee3f6fe6efe515b39e4a370650366.zip |
-add header map to rest handle
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_rest_lib.h | 24 | ||||
-rw-r--r-- | src/rest/gnunet-rest-server.c | 31 |
2 files changed, 55 insertions, 0 deletions
diff --git a/src/include/gnunet_rest_lib.h b/src/include/gnunet_rest_lib.h index 243c38403..5bf04636b 100644 --- a/src/include/gnunet_rest_lib.h +++ b/src/include/gnunet_rest_lib.h | |||
@@ -38,10 +38,34 @@ | |||
38 | 38 | ||
39 | struct GNUNET_REST_RequestHandle | 39 | struct GNUNET_REST_RequestHandle |
40 | { | 40 | { |
41 | /** | ||
42 | * Map of url parameters | ||
43 | */ | ||
41 | struct GNUNET_CONTAINER_MultiHashMap *url_param_map; | 44 | struct GNUNET_CONTAINER_MultiHashMap *url_param_map; |
45 | |||
46 | /** | ||
47 | * Map of headers | ||
48 | */ | ||
49 | struct GNUNET_CONTAINER_MultiHashMap *header_param_map; | ||
50 | |||
51 | /** | ||
52 | * The HTTP method as MHD value (see microhttpd.h) | ||
53 | */ | ||
42 | const char *method; | 54 | const char *method; |
55 | |||
56 | /** | ||
57 | * The url as string | ||
58 | */ | ||
43 | const char *url; | 59 | const char *url; |
60 | |||
61 | /** | ||
62 | * The POST data | ||
63 | */ | ||
44 | const char *data; | 64 | const char *data; |
65 | |||
66 | /** | ||
67 | * The POST data size | ||
68 | */ | ||
45 | size_t data_size; | 69 | size_t data_size; |
46 | }; | 70 | }; |
47 | 71 | ||
diff --git a/src/rest/gnunet-rest-server.c b/src/rest/gnunet-rest-server.c index 5b92c6c43..cb903e388 100644 --- a/src/rest/gnunet-rest-server.c +++ b/src/rest/gnunet-rest-server.c | |||
@@ -210,6 +210,31 @@ cleanup_handle (struct MhdConnectionHandle *handle) | |||
210 | GNUNET_free (handle); | 210 | GNUNET_free (handle); |
211 | } | 211 | } |
212 | 212 | ||
213 | static int | ||
214 | header_iterator (void *cls, | ||
215 | enum MHD_ValueKind kind, | ||
216 | const char *key, | ||
217 | const char *value) | ||
218 | { | ||
219 | struct GNUNET_REST_RequestHandle *handle = cls; | ||
220 | struct GNUNET_HashCode hkey; | ||
221 | char *val; | ||
222 | |||
223 | GNUNET_CRYPTO_hash (key, strlen (key), &hkey); | ||
224 | GNUNET_asprintf (&val, "%s", value); | ||
225 | if (GNUNET_OK != | ||
226 | GNUNET_CONTAINER_multihashmap_put (handle->header_param_map, | ||
227 | &hkey, | ||
228 | val, | ||
229 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
230 | { | ||
231 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
232 | "Could not load add header `%s'=%s\n", | ||
233 | key, value); | ||
234 | } | ||
235 | return MHD_YES; | ||
236 | } | ||
237 | |||
213 | 238 | ||
214 | static int | 239 | static int |
215 | url_iterator (void *cls, | 240 | url_iterator (void *cls, |
@@ -318,11 +343,17 @@ create_response (void *cls, | |||
318 | rest_conndata_handle->data_size = *upload_data_size; | 343 | rest_conndata_handle->data_size = *upload_data_size; |
319 | rest_conndata_handle->url_param_map = GNUNET_CONTAINER_multihashmap_create (16, | 344 | rest_conndata_handle->url_param_map = GNUNET_CONTAINER_multihashmap_create (16, |
320 | GNUNET_NO); | 345 | GNUNET_NO); |
346 | rest_conndata_handle->header_param_map = GNUNET_CONTAINER_multihashmap_create (16, | ||
347 | GNUNET_NO); | ||
321 | con_handle->data_handle = rest_conndata_handle; | 348 | con_handle->data_handle = rest_conndata_handle; |
322 | MHD_get_connection_values (con, | 349 | MHD_get_connection_values (con, |
323 | MHD_GET_ARGUMENT_KIND, | 350 | MHD_GET_ARGUMENT_KIND, |
324 | &url_iterator, | 351 | &url_iterator, |
325 | rest_conndata_handle); | 352 | rest_conndata_handle); |
353 | MHD_get_connection_values (con, | ||
354 | MHD_HEADER_KIND, | ||
355 | &header_iterator, | ||
356 | rest_conndata_handle); | ||
326 | con_handle->state = GN_REST_STATE_PROCESSING; | 357 | con_handle->state = GN_REST_STATE_PROCESSING; |
327 | con_handle->plugin->process_request (rest_conndata_handle, | 358 | con_handle->plugin->process_request (rest_conndata_handle, |
328 | &plugin_callback, | 359 | &plugin_callback, |