diff options
author | Schanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de> | 2018-01-22 17:34:57 +0100 |
---|---|---|
committer | Schanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de> | 2018-01-22 17:34:57 +0100 |
commit | 4fce9ab87811196126dc64afa905cb72688728ea (patch) | |
tree | fe0768e01bfad74b09d674aa015a45146af8c39c /src/rest | |
parent | 407e79aca5cc2caadb9c9a916fcb91c3e9f3c244 (diff) | |
download | gnunet-4fce9ab87811196126dc64afa905cb72688728ea.tar.gz gnunet-4fce9ab87811196126dc64afa905cb72688728ea.zip |
fix post processing
Diffstat (limited to 'src/rest')
-rw-r--r-- | src/rest/gnunet-rest-server.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/rest/gnunet-rest-server.c b/src/rest/gnunet-rest-server.c index b08aee389..072f24cb2 100644 --- a/src/rest/gnunet-rest-server.c +++ b/src/rest/gnunet-rest-server.c | |||
@@ -131,6 +131,8 @@ struct MhdConnectionHandle | |||
131 | 131 | ||
132 | struct GNUNET_REST_RequestHandle *data_handle; | 132 | struct GNUNET_REST_RequestHandle *data_handle; |
133 | 133 | ||
134 | struct MHD_PostProcessor *pp; | ||
135 | |||
134 | int status; | 136 | int status; |
135 | 137 | ||
136 | int state; | 138 | int state; |
@@ -239,6 +241,40 @@ url_iterator (void *cls, | |||
239 | return MHD_YES; | 241 | return MHD_YES; |
240 | } | 242 | } |
241 | 243 | ||
244 | static int | ||
245 | post_data_iter (void *cls, | ||
246 | enum MHD_ValueKind kind, | ||
247 | const char *key, | ||
248 | const char *filename, | ||
249 | const char *content_type, | ||
250 | const char *transfer_encoding, | ||
251 | const char *data, | ||
252 | uint64_t off, | ||
253 | size_t size) | ||
254 | { | ||
255 | struct GNUNET_REST_RequestHandle *handle = cls; | ||
256 | struct GNUNET_HashCode hkey; | ||
257 | char *val; | ||
258 | |||
259 | if (MHD_POSTDATA_KIND != kind) | ||
260 | return MHD_YES; | ||
261 | |||
262 | GNUNET_CRYPTO_hash (key, strlen (key), &hkey); | ||
263 | GNUNET_asprintf (&val, "%s", data); | ||
264 | if (GNUNET_OK != | ||
265 | GNUNET_CONTAINER_multihashmap_put (handle->url_param_map, | ||
266 | &hkey, | ||
267 | val, | ||
268 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
269 | { | ||
270 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
271 | "Could not load add url param `%s'=%s\n", | ||
272 | key, data); | ||
273 | } | ||
274 | return MHD_YES; | ||
275 | |||
276 | } | ||
277 | |||
242 | /* ********************************* MHD response generation ******************* */ | 278 | /* ********************************* MHD response generation ******************* */ |
243 | 279 | ||
244 | /** | 280 | /** |
@@ -310,6 +346,7 @@ create_response (void *cls, | |||
310 | MHD_HTTP_NOT_FOUND, | 346 | MHD_HTTP_NOT_FOUND, |
311 | failure_response); | 347 | failure_response); |
312 | } | 348 | } |
349 | |||
313 | return MHD_YES; | 350 | return MHD_YES; |
314 | } | 351 | } |
315 | if (GN_REST_STATE_INIT == con_handle->state) | 352 | if (GN_REST_STATE_INIT == con_handle->state) |
@@ -326,6 +363,18 @@ create_response (void *cls, | |||
326 | MHD_GET_ARGUMENT_KIND, | 363 | MHD_GET_ARGUMENT_KIND, |
327 | &url_iterator, | 364 | &url_iterator, |
328 | rest_conndata_handle); | 365 | rest_conndata_handle); |
366 | con_handle->pp = MHD_create_post_processor(con, | ||
367 | 4000, | ||
368 | post_data_iter, | ||
369 | rest_conndata_handle); | ||
370 | if (*upload_data_size) | ||
371 | { | ||
372 | MHD_post_process(con_handle->pp, upload_data, *upload_data_size); | ||
373 | } | ||
374 | else | ||
375 | { | ||
376 | MHD_destroy_post_processor(con_handle->pp); | ||
377 | } | ||
329 | con_handle->state = GN_REST_STATE_PROCESSING; | 378 | con_handle->state = GN_REST_STATE_PROCESSING; |
330 | con_handle->plugin->process_request (rest_conndata_handle, | 379 | con_handle->plugin->process_request (rest_conndata_handle, |
331 | &plugin_callback, | 380 | &plugin_callback, |