libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit b14541751ff614f00867ceaf4c0fa21f7c484c58
parent 0849d359802d7b02d188230bcda269b330b3b1f0
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed, 14 Feb 2018 04:46:37 +0100

more work on new src/lib/

Diffstat:
M.gitignore | 1+
Msrc/include/microhttpd2.h | 12++++++++++++
Msrc/lib/action_continue.c | 2++
Msrc/lib/action_from_response.c | 4++--
Msrc/lib/action_suspend.c | 6++++--
Msrc/lib/connection_options.c | 9++++++---
Msrc/lib/daemon_create.c | 9++++-----
Msrc/lib/daemon_options.c | 2+-
Msrc/lib/internal.h | 123++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------
9 files changed, 122 insertions(+), 46 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -44,3 +44,4 @@ po/Makevars.template po/POTFILES po/configargs.stamp **~ +doc/libmicrohttpd.log diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h @@ -2969,6 +2969,18 @@ MHD_set_panic_func (MHD_PanicCallback cb, void *cls); +/** + * Process escape sequences ('%HH') Updates val in place; the + * result should be UTF-8 encoded and cannot be larger than the input. + * The result must also still be 0-terminated. + * + * @param val value to unescape (modified in the process) + * @return length of the resulting val (`strlen(val)` may be + * shorter afterwards due to elimination of escape sequences) + */ +_MHD_EXTERN size_t +MHD_http_unescape (char *val); + /** * Types of information about MHD features, diff --git a/src/lib/action_continue.c b/src/lib/action_continue.c @@ -37,6 +37,8 @@ static enum MHD_StatusCode cont_action (void *cls, struct MHD_Request *request) { + (void) cls; + (void) request; /* not sure yet, but this function body may just legitimately stay empty... */ return MHD_SC_OK; diff --git a/src/lib/action_from_response.c b/src/lib/action_from_response.c @@ -80,8 +80,8 @@ response_action (void *cls, request->response_write_position = response->total_size; } if ( (MHD_REQUEST_HEADERS_PROCESSED == request->state) && - (MHD_METHOD_POST == request->method) || - (MHD_METHOD_PUT == request->method) ) + ( (MHD_METHOD_POST == request->method) || + (MHD_METHOD_PUT == request->method) ) ) { /* response was queued "early", refuse to read body / footers or further requests! */ diff --git a/src/lib/action_suspend.c b/src/lib/action_suspend.c @@ -37,6 +37,7 @@ static enum MHD_StatusCode suspend_action (void *cls, struct MHD_Request *request) { + (void) cls; struct MHD_Connection *connection = request->connection; struct MHD_Daemon *daemon = connection->daemon; @@ -48,9 +49,10 @@ suspend_action (void *cls, MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); return MHD_SC_OK; } - if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) + if (daemon->threading_model != MHD_TM_THREAD_PER_CONNECTION) { - if (connection->connection_timeout == daemon->connection_timeout) + if (connection->connection_timeout == + daemon->connection_default_timeout) XDLL_remove (daemon->normal_timeout_head, daemon->normal_timeout_tail, connection); diff --git a/src/lib/connection_options.c b/src/lib/connection_options.c @@ -50,7 +50,8 @@ MHD_connection_set_timeout (struct MHD_Connection *connection, MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); if (! connection->suspended) { - if (connection->connection_timeout == daemon->connection_timeout) + if (connection->connection_timeout == + daemon->connection_default_timeout) XDLL_remove (daemon->normal_timeout_head, daemon->normal_timeout_tail, connection); @@ -62,7 +63,8 @@ MHD_connection_set_timeout (struct MHD_Connection *connection, connection->connection_timeout = (time_t) timeout_s; if (! connection->suspended) { - if (connection->connection_timeout == daemon->connection_timeout) + if (connection->connection_timeout == + daemon->connection_default_timeout) XDLL_insert (daemon->normal_timeout_head, daemon->normal_timeout_tail, connection); @@ -97,7 +99,8 @@ MHD_update_last_activity_ (struct MHD_Connection *connection) if (MHD_TM_THREAD_PER_CONNECTION == daemon->threading_model) return; /* each connection has personal timeout */ - if (connection->connection_timeout != daemon->connection_timeout) + if (connection->connection_timeout != + daemon->connection_default_timeout) return; /* custom timeout, no need to move it in "normal" DLL */ MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex); diff --git a/src/lib/daemon_create.c b/src/lib/daemon_create.c @@ -100,8 +100,7 @@ MHD_daemon_create (MHD_RequestCallback cb, daemon->logger = &file_logger; daemon->logger_cls = stderr; daemon->unescape_cb = &unescape_wrapper; - daemon->tls_ciphers = TLS_CIPHERS_DEFAULT; - daemon->connection_memory_limit_b = MHD_POOL_SIZE_DEFAULT; + daemon->connection_memory_limit_b = POOL_SIZE_DEFAULT; daemon->connection_memory_increment_b = BUF_INC_SIZE_DEFAULT; #if ENABLE_DAUTH daemon->digest_nc_length = DIGEST_NC_LENGTH_DEFAULT; @@ -117,15 +116,15 @@ MHD_daemon_create (MHD_RequestCallback cb, } if (! MHD_mutex_init_ (&daemon->per_ip_connection_mutex)) { - MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); + (void) MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); free (daemon); return NULL; } #ifdef DAUTH_SUPPORT if (! MHD_mutex_init_ (&daemon->nnc_lock)) { - MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); - MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); + (void) MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); + (void) MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); free (daemon); return NULL; } diff --git a/src/lib/daemon_options.c b/src/lib/daemon_options.c @@ -644,7 +644,7 @@ void MHD_daemon_connection_default_timeout (struct MHD_Daemon *daemon, unsigned int timeout_s) { - daemon->connection_default_timeout_s = timeout_s; + daemon->connection_default_timeout = (time_t) timeout_s; } diff --git a/src/lib/internal.h b/src/lib/internal.h @@ -33,6 +33,7 @@ #include "microhttpd_tls.h" #include "mhd_assert.h" #include "mhd_compat.h" +#include "mhd_mono_clock.h" #include "memorypool.h" #ifdef HTTPS_SUPPORT @@ -748,34 +749,6 @@ struct MHD_Connection struct MHD_Request request; /** - * Is the connection suspended? - */ - bool suspended; - - /** - * Is the connection wanting to resume? - */ - bool resuming; - - /** - * Set to `true` if the thread has been joined. - */ - bool thread_joined; - - /** - * true if #socket_fd is non-blocking, false otherwise. - */ - bool sk_nonblck; - - /** - * Has this socket been closed for reading (i.e. other side closed - * the connection)? If so, we must completely close the connection - * once we are done sending our response (and stop trying to read - * from this socket). - */ - bool read_closed; - - /** * Length of the foreign address. */ socklen_t addr_len; @@ -799,7 +772,6 @@ struct MHD_Connection */ MHD_socket socket_fd; - #ifdef EPOLL_SUPPORT /** * What is the state of this socket in relation to epoll? @@ -807,11 +779,35 @@ struct MHD_Connection enum MHD_EpollState epoll_state; #endif - -}; + /** + * Is the connection suspended? + */ + bool suspended; + /** + * Is the connection wanting to resume? + */ + bool resuming; + /** + * Set to `true` if the thread has been joined. + */ + bool thread_joined; + + /** + * true if #socket_fd is non-blocking, false otherwise. + */ + bool sk_nonblck; + /** + * Has this socket been closed for reading (i.e. other side closed + * the connection)? If so, we must completely close the connection + * once we are done sending our response (and stop trying to read + * from this socket). + */ + bool read_closed; + +}; /** @@ -1002,6 +998,35 @@ struct MHD_Daemon #endif /* UPGRADE_SUPPORT */ #endif /* EPOLL_SUPPORT */ +#ifdef DAUTH_SUPPORT + + /** + * Character array of random values. + */ + const char *digest_auth_random; + + /** + * An array that contains the map nonce-nc. + */ + struct MHD_NonceNc *nnc; + + /** + * A rw-lock for synchronizing access to @e nnc. + */ + MHD_mutex_ nnc_lock; + + /** + * Size of `digest_auth_random. + */ + size_t digest_auth_rand_size; + + /** + * Size of the nonce-nc array. + */ + unsigned int nonce_nc_size; + +#endif + /** * Socket address to bind to for the listen socket. */ @@ -1024,9 +1049,13 @@ struct MHD_Daemon */ size_t listen_sa_len; +/** + * Default size of the per-connection memory pool. + */ +#define POOL_SIZE_DEFAULT (32 * 1024) /** * Buffer size to use for each connection. Default - * is #MHD_POOL_SIZE_DEFAULT. + * is #POOL_SIZE_DEFAULT. */ size_t connection_memory_limit_b; @@ -1108,7 +1137,7 @@ struct MHD_Daemon /** * Default timeout in seconds for idle connections. */ - unsigned int connection_default_timeout_s; + time_t connection_default_timeout; /** * Listen socket we should use, MHD_INVALID_SOCKET means @@ -1116,6 +1145,34 @@ struct MHD_Daemon */ MHD_socket listen_socket; +#ifdef EPOLL_SUPPORT + /** + * File descriptor associated with our epoll loop. + */ + int epoll_fd; + + /** + * true if the listen socket is in the 'epoll' set, + * false if not. + */ + bool listen_socket_in_epoll; + +#if defined(HTTPS_SUPPORT) && defined(UPGRADE_SUPPORT) + /** + * File descriptor associated with the #run_epoll_for_upgrade() loop. + * Only available if #MHD_USE_HTTPS_EPOLL_UPGRADE is set. + */ + int epoll_upgrade_fd; + + /** + * true if @e epoll_upgrade_fd is in the 'epoll' set, + * false if not. + */ + bool upgrade_fd_in_epoll; +#endif /* HTTPS_SUPPORT && UPGRADE_SUPPORT */ + +#endif + /** * Inter-thread communication channel. */