From 5da3c7cf721ee3f6fe6efe515b39e4a370650366 Mon Sep 17 00:00:00 2001 From: "Schanzenbach, Martin" Date: Mon, 11 Dec 2017 13:01:03 +0100 Subject: [PATCH] -add header map to rest handle --- src/include/gnunet_rest_lib.h | 24 ++++++++++++++++++++++++ src/rest/gnunet-rest-server.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) 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 @@ struct GNUNET_REST_RequestHandle { + /** + * Map of url parameters + */ struct GNUNET_CONTAINER_MultiHashMap *url_param_map; + + /** + * Map of headers + */ + struct GNUNET_CONTAINER_MultiHashMap *header_param_map; + + /** + * The HTTP method as MHD value (see microhttpd.h) + */ const char *method; + + /** + * The url as string + */ const char *url; + + /** + * The POST data + */ const char *data; + + /** + * The POST data size + */ size_t data_size; }; 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) GNUNET_free (handle); } +static int +header_iterator (void *cls, + enum MHD_ValueKind kind, + const char *key, + const char *value) +{ + struct GNUNET_REST_RequestHandle *handle = cls; + struct GNUNET_HashCode hkey; + char *val; + + GNUNET_CRYPTO_hash (key, strlen (key), &hkey); + GNUNET_asprintf (&val, "%s", value); + if (GNUNET_OK != + GNUNET_CONTAINER_multihashmap_put (handle->header_param_map, + &hkey, + val, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not load add header `%s'=%s\n", + key, value); + } + return MHD_YES; +} + static int url_iterator (void *cls, @@ -318,11 +343,17 @@ create_response (void *cls, rest_conndata_handle->data_size = *upload_data_size; rest_conndata_handle->url_param_map = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_NO); + rest_conndata_handle->header_param_map = GNUNET_CONTAINER_multihashmap_create (16, + GNUNET_NO); con_handle->data_handle = rest_conndata_handle; MHD_get_connection_values (con, MHD_GET_ARGUMENT_KIND, &url_iterator, rest_conndata_handle); + MHD_get_connection_values (con, + MHD_HEADER_KIND, + &header_iterator, + rest_conndata_handle); con_handle->state = GN_REST_STATE_PROCESSING; con_handle->plugin->process_request (rest_conndata_handle, &plugin_callback, -- 2.25.1