GNU libmicrohttpd  0.9.29
daemon.c File Reference

A minimal-HTTP server library. More...

#include "platform.h"
#include "mhd_threads.h"
#include "internal.h"
#include "response.h"
#include "connection.h"
#include "memorypool.h"
#include "mhd_limits.h"
#include "autoinit_funcs.h"
#include "mhd_mono_clock.h"
#include "mhd_locks.h"
#include "mhd_sockets.h"
#include "mhd_itc.h"
#include "mhd_compat.h"
#include "tsearch.h"
Include dependency graph for daemon.c:

Go to the source code of this file.

Macros

#define MHD_MAX_CONNECTIONS_DEFAULT   (FD_SETSIZE - 4)
 
#define MHD_POOL_SIZE_DEFAULT   (32 * 1024)
 
#define DEBUG_CLOSE   MHD_NO
 
#define DEBUG_CONNECT   MHD_NO
 
#define EXTRA_SLOTS   0
 

Typedefs

typedef void(* VfprintfFunctionPointerType) (void *cls, const char *format, va_list va)
 

Functions

static void mhd_panic_std (void *cls, const char *file, unsigned int line, const char *reason)
 
static struct MHD_DaemonMHD_get_master (struct MHD_Daemon *daemon)
 
static void MHD_ip_count_lock (struct MHD_Daemon *daemon)
 
static void MHD_ip_count_unlock (struct MHD_Daemon *daemon)
 
static int MHD_ip_addr_compare (const void *a1, const void *a2)
 
static int MHD_ip_addr_to_key (const struct sockaddr *addr, socklen_t addrlen, struct MHD_IPCount *key)
 
static int MHD_ip_limit_add (struct MHD_Daemon *daemon, const struct sockaddr *addr, socklen_t addrlen)
 
static void MHD_ip_limit_del (struct MHD_Daemon *daemon, const struct sockaddr *addr, socklen_t addrlen)
 
_MHD_EXTERN int MHD_get_fdset (struct MHD_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, MHD_socket *max_fd)
 
_MHD_EXTERN int MHD_get_fdset2 (struct MHD_Daemon *daemon, fd_set *read_fd_set, fd_set *write_fd_set, fd_set *except_fd_set, MHD_socket *max_fd, unsigned int fd_setsize)
 
static int call_handlers (struct MHD_Connection *con, int read_ready, int write_ready, int force_close)
 
void MHD_cleanup_upgraded_connection_ (struct MHD_Connection *connection)
 
static void thread_main_connection_upgrade (struct MHD_Connection *con)
 
static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_ thread_main_handle_connection (void *data)
 
static ssize_t recv_param_adapter (struct MHD_Connection *connection, void *other, size_t i)
 
static ssize_t send_param_adapter (struct MHD_Connection *connection, const void *other, size_t i)
 
static void MHD_cleanup_connections (struct MHD_Daemon *daemon)
 
static int internal_add_connection (struct MHD_Daemon *daemon, MHD_socket client_socket, const struct sockaddr *addr, socklen_t addrlen, int external_add)
 
void MHD_suspend_connection (struct MHD_Connection *connection)
 
void MHD_resume_connection (struct MHD_Connection *connection)
 
static int resume_suspended_connections (struct MHD_Daemon *daemon)
 
_MHD_EXTERN int MHD_add_connection (struct MHD_Daemon *daemon, MHD_socket client_socket, const struct sockaddr *addr, socklen_t addrlen)
 
static int MHD_accept_connection (struct MHD_Daemon *daemon)
 
_MHD_EXTERN int MHD_get_timeout (struct MHD_Daemon *daemon, MHD_UNSIGNED_LONG_LONG *timeout)
 
_MHD_EXTERN int MHD_run_from_select (struct MHD_Daemon *daemon, const fd_set *read_fd_set, const fd_set *write_fd_set, const fd_set *except_fd_set)
 
static int MHD_select (struct MHD_Daemon *daemon, int may_block)
 
static int MHD_poll (struct MHD_Daemon *daemon, int may_block)
 
_MHD_EXTERN int MHD_run (struct MHD_Daemon *daemon)
 
static void close_connection (struct MHD_Connection *pos)
 
static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_ MHD_select_thread (void *cls)
 
static size_t unescape_wrapper (void *cls, struct MHD_Connection *connection, char *val)
 
_MHD_EXTERN struct MHD_DaemonMHD_start_daemon (unsigned int flags, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls,...)
 
_MHD_EXTERN MHD_socket MHD_quiesce_daemon (struct MHD_Daemon *daemon)
 
static int parse_options_va (struct MHD_Daemon *daemon, const struct sockaddr **servaddr, va_list ap)
 
static int parse_options (struct MHD_Daemon *daemon, const struct sockaddr **servaddr,...)
 
_MHD_EXTERN struct MHD_DaemonMHD_start_daemon_va (unsigned int flags, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls, va_list ap)
 
static void close_all_connections (struct MHD_Daemon *daemon)
 
_MHD_EXTERN void MHD_stop_daemon (struct MHD_Daemon *daemon)
 
_MHD_EXTERN const union MHD_DaemonInfoMHD_get_daemon_info (struct MHD_Daemon *daemon, enum MHD_DaemonInfoType info_type,...)
 
_MHD_EXTERN void MHD_set_panic_func (MHD_PanicCallback cb, void *cls)
 
_MHD_EXTERN const char * MHD_get_version (void)
 
_MHD_EXTERN int MHD_is_feature_supported (enum MHD_FEATURE feature)
 
void MHD_init (void)
 
void MHD_fini (void)
 
 _SET_INIT_AND_DEINIT_FUNCS (MHD_init, MHD_fini)
 

Variables

MHD_PanicCallback mhd_panic
 
void * mhd_panic_cls
 

Detailed Description

A minimal-HTTP server library.

Author
Daniel Pittman
Christian Grothoff

Definition in file daemon.c.

Macro Definition Documentation

◆ DEBUG_CLOSE

#define DEBUG_CLOSE   MHD_NO

Print extra messages with reasons for closing sockets? (only adds non-error messages).

Definition at line 81 of file daemon.c.

◆ DEBUG_CONNECT

#define DEBUG_CONNECT   MHD_NO

Print extra messages when establishing connections? (only adds non-error messages).

Definition at line 87 of file daemon.c.

◆ EXTRA_SLOTS

#define EXTRA_SLOTS   0

◆ MHD_MAX_CONNECTIONS_DEFAULT

#define MHD_MAX_CONNECTIONS_DEFAULT   (FD_SETSIZE - 4)

Default connection limit.

Definition at line 67 of file daemon.c.

Referenced by MHD_start_daemon_va().

◆ MHD_POOL_SIZE_DEFAULT

#define MHD_POOL_SIZE_DEFAULT   (32 * 1024)

Default memory allowed per connection.

Definition at line 75 of file daemon.c.

Referenced by MHD_start_daemon_va().

Typedef Documentation

◆ VfprintfFunctionPointerType

typedef void(* VfprintfFunctionPointerType) (void *cls, const char *format, va_list va)

Signature of the MHD custom logger function.

Parameters
clsclosure
formatformat string
vaarguments to the format string (fprintf-style)

Definition at line 3897 of file daemon.c.

Function Documentation

◆ _SET_INIT_AND_DEINIT_FUNCS()

_SET_INIT_AND_DEINIT_FUNCS ( MHD_init  ,
MHD_fini   
)

Referenced by MHD_fini().

Here is the caller graph for this function:

◆ call_handlers()

static int call_handlers ( struct MHD_Connection con,
int  read_ready,
int  write_ready,
int  force_close 
)
static

Call the handlers for a connection in the appropriate order based on the readiness as detected by the event loop.

Parameters
conconnection to handle
read_readyset if the socket is ready for reading
write_readyset if the socket is ready for writing
force_closeset if a hard error was detected on the socket; if this information is not available, simply pass MHD_NO
Returns
MHD_YES to continue normally, MHD_NO if a serious error was encountered and the connection is to be closed.

Definition at line 871 of file daemon.c.

References MHD_Connection::daemon, MHD_Connection::idle_handler, MHD_connection_close_(), MHD_NO, MHD_REQUEST_TERMINATED_WITH_ERROR, MHD_USE_EPOLL_TURBO, MHD_YES, NULL, MHD_Daemon::options, MHD_Connection::read_handler, MHD_Connection::response, and MHD_Connection::write_handler.

Referenced by MHD_poll(), MHD_run_from_select(), MHD_select(), and thread_main_handle_connection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ close_all_connections()

static void close_all_connections ( struct MHD_Daemon daemon)
static

Close all connections for the daemon; must only be called after all of the threads have been joined and there is no more concurrent activity on the connection lists.

Parameters
daemondaemon to close down

Definition at line 5176 of file daemon.c.

References _, MHD_Daemon::cleanup_connection_mutex, close_connection(), MHD_Daemon::connections_head, MHD_Daemon::itc, MHD_cleanup_connections(), MHD_ITC_IS_INVALID_, MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_PANIC, MHD_USE_THREAD_PER_CONNECTION, MHD_YES, MHD_Connection::next, NULL, MHD_Daemon::options, MHD_Connection::pid, resume_suspended_connections(), MHD_Connection::socket_fd, MHD_Daemon::suspended_connections_head, and MHD_Connection::thread_joined.

Referenced by MHD_stop_daemon().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ close_connection()

static void close_connection ( struct MHD_Connection pos)
static

◆ internal_add_connection()

static int internal_add_connection ( struct MHD_Daemon daemon,
MHD_socket  client_socket,
const struct sockaddr *  addr,
socklen_t  addrlen,
int  external_add 
)
static

Add another client connection to the set of connections managed by MHD. This API is usually not needed (since MHD will accept inbound connections on the server socket). Use this API in special cases, for example if your HTTP server is behind NAT and needs to connect out to the HTTP client.

The given client socket will be managed (and closed!) by MHD after this call and must no longer be used directly by the application afterwards.

Per-IP connection limits are ignored when using this API.

Parameters
daemondaemon that manages the connection
client_socketsocket to manage (MHD will expect to receive an HTTP request from this socket next).
addrIP address of the client
addrlennumber of bytes in addr
external_addperform additional operations needed due to the application calling us directly
Returns
MHD_YES on success, MHD_NO if this daemon could not handle the connection (i.e. malloc failed, etc). The socket will be closed in any case; 'errno' is set to indicate further details about the error.

Definition at line 1766 of file daemon.c.

References _, MHD_Connection::addr, MHD_Connection::addr_len, MHD_Daemon::apc, MHD_Daemon::apc_cls, MHD_Daemon::cleanup_connection_mutex, MHD_Daemon::connection_limit, MHD_Connection::connection_timeout, MHD_Daemon::connection_timeout, MHD_Daemon::connections, MHD_Daemon::connections_head, MHD_Daemon::connections_tail, MHD_Connection::daemon, DLL_insert, DLL_remove, EDLL_insert, MHD_Daemon::itc, MHD_Connection::last_activity, MHD_CONNECTION_NOTIFY_CLOSED, MHD_CONNECTION_NOTIFY_STARTED, MHD_create_named_thread_, MHD_EPOLL_STATE_IN_EPOLL_SET, MHD_EPOLL_STATE_IN_EREADY_EDLL, MHD_EPOLL_STATE_READ_READY, MHD_EPOLL_STATE_WRITE_READY, MHD_ip_limit_add(), MHD_ip_limit_del(), MHD_monotonic_sec_counter(), MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_NO, MHD_PANIC, MHD_pool_create(), MHD_pool_destroy(), MHD_SCKT_FD_FITS_FDSET_, MHD_set_http_callbacks_(), MHD_set_https_callbacks(), MHD_socket_close_chk_, MHD_socket_last_strerr_, MHD_socket_nonblocking_(), MHD_strerror_, MHD_TLS_CONNECTION_INIT, MHD_USE_EPOLL, MHD_USE_EPOLL_TURBO, MHD_USE_POLL, MHD_USE_THREAD_PER_CONNECTION, MHD_USE_TLS, MHD_YES, MHD_Daemon::normal_timeout_head, MHD_Daemon::normal_timeout_tail, MHD_Daemon::notify_connection, MHD_Daemon::notify_connection_cls, NULL, MHD_Daemon::options, MHD_Connection::pid, MHD_Connection::pool, MHD_Daemon::pool_size, MHD_Connection::recv_cls, recv_param_adapter(), MHD_Connection::send_cls, send_param_adapter(), MHD_Connection::socket_context, MHD_Connection::socket_fd, MHD_Connection::state, thread_main_handle_connection(), MHD_Daemon::thread_stack_size, MHD_Daemon::worker_pool, MHD_Daemon::worker_pool_size, XDLL_insert, and XDLL_remove.

Referenced by MHD_accept_connection(), and MHD_add_connection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_accept_connection()

static int MHD_accept_connection ( struct MHD_Daemon daemon)
static

Accept an incoming connection and create the MHD_Connection object for it. This function also enforces policy by way of checking with the accept policy callback.

Parameters
daemonhandle with the listen socket
Returns
MHD_YES on success (connections denied by policy or due to 'out of memory' and similar errors) are still considered successful as far as MHD_accept_connection() is concerned); a return code of MHD_NO only refers to the actual accept() system call.

Definition at line 2399 of file daemon.c.

References _, MHD_Daemon::at_limit, MHD_Daemon::connections, fd, internal_add_connection(), MAYBE_SOCK_CLOEXEC, MAYBE_SOCK_NONBLOCK, MHD_INVALID_SOCKET, MHD_NO, MHD_SCKT_EINVAL_, MHD_SCKT_ERR_IS_, MHD_SCKT_ERR_IS_DISCNN_BEFORE_ACCEPT_, MHD_SCKT_ERR_IS_EAGAIN_, MHD_SCKT_ERR_IS_LOW_RESOURCES_, MHD_socket_close_chk_, MHD_socket_get_error_, MHD_socket_last_strerr_, MHD_socket_nonblocking_(), MHD_socket_noninheritable_(), MHD_socket_strerr_, MHD_YES, and MHD_Daemon::socket_fd.

Referenced by MHD_poll(), MHD_run_from_select(), and MHD_select().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_cleanup_connections()

◆ MHD_cleanup_upgraded_connection_()

void MHD_cleanup_upgraded_connection_ ( struct MHD_Connection connection)

◆ MHD_fini()

void MHD_fini ( void  )

Definition at line 5753 of file daemon.c.

References _SET_INIT_AND_DEINIT_FUNCS(), MHD_init(), and MHD_monotonic_sec_counter_finish().

Here is the call graph for this function:

◆ MHD_get_master()

static struct MHD_Daemon* MHD_get_master ( struct MHD_Daemon daemon)
static

Trace up to and return master daemon. If the supplied daemon is a master, then return the daemon itself.

Parameters
daemonhandle to a daemon
Returns
master daemon handle

Definition at line 142 of file daemon.c.

References MHD_Daemon::master, and NULL.

Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().

Here is the caller graph for this function:

◆ MHD_init()

void MHD_init ( void  )

Initialize do setup work.

Definition at line 5715 of file daemon.c.

References _, MHD_monotonic_sec_counter_init(), MHD_PANIC, mhd_panic, mhd_panic_cls, mhd_panic_std(), and NULL.

Referenced by MHD_fini().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_ip_addr_compare()

static int MHD_ip_addr_compare ( const void *  a1,
const void *  a2 
)
static

Tree comparison function for IP addresses (supplied to tsearch() family). We compare everything in the struct up through the beginning of the 'count' field.

Parameters
a1first address to compare
a2second address to compare
Returns
-1, 0 or 1 depending on result of compare

Definition at line 218 of file daemon.c.

Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().

Here is the caller graph for this function:

◆ MHD_ip_addr_to_key()

static int MHD_ip_addr_to_key ( const struct sockaddr *  addr,
socklen_t  addrlen,
struct MHD_IPCount *  key 
)
static

Parse address and initialize key using the address.

Parameters
addraddress to parse
addrlennumber of bytes in addr
keywhere to store the parsed address
Returns
MHD_YES on success and MHD_NO otherwise (e.g., invalid address type)

Definition at line 237 of file daemon.c.

References MHD_NO, and MHD_YES.

Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().

Here is the caller graph for this function:

◆ MHD_ip_count_lock()

static void MHD_ip_count_lock ( struct MHD_Daemon daemon)
static

Lock shared structure for IP connection counts and connection DLLs.

Parameters
daemonhandle to daemon where lock is

Definition at line 190 of file daemon.c.

References MHD_mutex_lock_chk_, and MHD_Daemon::per_ip_connection_mutex.

Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().

Here is the caller graph for this function:

◆ MHD_ip_count_unlock()

static void MHD_ip_count_unlock ( struct MHD_Daemon daemon)
static

Unlock shared structure for IP connection counts and connection DLLs.

Parameters
daemonhandle to daemon where lock is

Definition at line 202 of file daemon.c.

References MHD_mutex_unlock_chk_, and MHD_Daemon::per_ip_connection_mutex.

Referenced by MHD_ip_limit_add(), and MHD_ip_limit_del().

Here is the caller graph for this function:

◆ MHD_ip_limit_add()

static int MHD_ip_limit_add ( struct MHD_Daemon daemon,
const struct sockaddr *  addr,
socklen_t  addrlen 
)
static

Check if IP address is over its limit in terms of the number of allowed concurrent connections. If the IP is still allowed, increments the connection counter.

Parameters
daemonhandle to daemon where connection counts are tracked
addraddress to add (or increment counter)
addrlennumber of bytes in addr
Returns
Return MHD_YES if IP below limit, MHD_NO if IP has surpassed limit. Also returns MHD_NO if fails to allocate memory.

Definition at line 288 of file daemon.c.

References _, MHD_get_master(), MHD_ip_addr_compare(), MHD_ip_addr_to_key(), MHD_ip_count_lock(), MHD_ip_count_unlock(), MHD_NO, MHD_YES, NULL, MHD_Daemon::per_ip_connection_count, MHD_Daemon::per_ip_connection_limit, and tsearch().

Referenced by internal_add_connection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_ip_limit_del()

static void MHD_ip_limit_del ( struct MHD_Daemon daemon,
const struct sockaddr *  addr,
socklen_t  addrlen 
)
static

Decrement connection count for IP address, removing from table count reaches 0.

Parameters
daemonhandle to daemon where connection counts are tracked
addraddress to remove (or decrement counter)
addrlennumber of bytes in addr

Definition at line 354 of file daemon.c.

References _, MHD_Connection::daemon, MHD_EPOLL_STATE_READ_READY, MHD_EPOLL_STATE_WRITE_READY, MHD_get_master(), MHD_ip_addr_compare(), MHD_ip_addr_to_key(), MHD_ip_count_lock(), MHD_ip_count_unlock(), MHD_NO, MHD_PANIC, MHD_SCKT_ECONNRESET_, MHD_SCKT_EINTR_, MHD_socket_set_error_, MHD_YES, NULL, MHD_Daemon::per_ip_connection_count, MHD_Daemon::per_ip_connection_limit, tdelete(), and tfind().

Referenced by internal_add_connection(), and MHD_cleanup_connections().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mhd_panic_std()

static void mhd_panic_std ( void *  cls,
const char *  file,
unsigned int  line,
const char *  reason 
)
static

Default implementation of the panic function, prints an error message and aborts.

Parameters
clsunused
filename of the file with the problem
lineline number with the problem
reasonerror message with details

Definition at line 100 of file daemon.c.

References _.

Referenced by MHD_init().

Here is the caller graph for this function:

◆ MHD_poll()

◆ MHD_resume_connection()

void MHD_resume_connection ( struct MHD_Connection connection)

Resume handling of network data for suspended connection. It is safe to resume a suspended connection at any time. Calling this function on a connection that was not previously suspended will result in undefined behavior.

Parameters
connectionthe connection to resume

Definition at line 2223 of file daemon.c.

References _, MHD_Daemon::cleanup_connection_mutex, MHD_Connection::daemon, MHD_Daemon::itc, MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_PANIC, MHD_USE_SUSPEND_RESUME, MHD_USE_THREAD_PER_CONNECTION, MHD_YES, MHD_Daemon::options, MHD_Connection::resuming, and MHD_Daemon::resuming.

Referenced by MHD_cleanup_upgraded_connection_().

Here is the caller graph for this function:

◆ MHD_select()

static int MHD_select ( struct MHD_Daemon daemon,
int  may_block 
)
static

◆ MHD_select_thread()

static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_ MHD_select_thread ( void *  cls)
static

Thread that runs the select loop until the daemon is explicitly shut down.

Parameters
clsstruct MHD_Deamon to run select loop in a thread for
Returns
always 0 (on shutdown)

Definition at line 3708 of file daemon.c.

References close_connection(), MHD_Daemon::connections_head, MHD_cleanup_connections(), MHD_poll(), MHD_select(), MHD_USE_EPOLL, MHD_USE_POLL, MHD_USE_THREAD_PER_CONNECTION, MHD_YES, NULL, MHD_Daemon::options, resume_suspended_connections(), and MHD_Daemon::shutdown.

Referenced by MHD_start_daemon_va().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MHD_suspend_connection()

void MHD_suspend_connection ( struct MHD_Connection connection)

Suspend handling of network data for a given connection. This can be used to dequeue a connection from MHD's event loop (external select, internal select or thread pool; not applicable to thread-per-connection!) for a while.

If you use this API in conjunction with a internal select or a thread pool, you must set the option MHD_USE_ITC to ensure that a resumed connection is immediately processed by MHD.

Suspended connections continue to count against the total number of connections allowed (per daemon, as well as per IP, if such limits are set). Suspended connections will NOT time out; timeouts will restart when the connection handling is resumed. While a connection is suspended, MHD will not detect disconnects by the client.

The only safe time to suspend a connection is from the MHD_AccessHandlerCallback.

Finally, it is an API violation to call MHD_stop_daemon while having suspended connections (this will at least create memory and socket leaks or lead to undefined behavior). You must explicitly resume all connections before stopping the daemon.

Parameters
connectionthe connection to suspend

Definition at line 2158 of file daemon.c.

References _, MHD_Daemon::cleanup_connection_mutex, MHD_Connection::connection_timeout, MHD_Daemon::connection_timeout, MHD_Daemon::connections_head, MHD_Daemon::connections_tail, MHD_Connection::daemon, DLL_insert, DLL_remove, EDLL_remove, MHD_Daemon::manual_timeout_head, MHD_Daemon::manual_timeout_tail, MHD_EPOLL_STATE_IN_EPOLL_SET, MHD_EPOLL_STATE_IN_EREADY_EDLL, MHD_EPOLL_STATE_SUSPENDED, MHD_mutex_lock_chk_, MHD_mutex_unlock_chk_, MHD_PANIC, MHD_USE_EPOLL, MHD_USE_SUSPEND_RESUME, MHD_USE_THREAD_PER_CONNECTION, MHD_YES, MHD_Daemon::normal_timeout_head, MHD_Daemon::normal_timeout_tail, NULL, MHD_Daemon::options, MHD_Connection::socket_fd, MHD_Connection::suspended, MHD_Daemon::suspended_connections_head, MHD_Daemon::suspended_connections_tail, and XDLL_remove.

Referenced by MHD_response_execute_upgrade_().

Here is the caller graph for this function:

◆ parse_options()

static int parse_options ( struct MHD_Daemon daemon,
const struct sockaddr **  servaddr,
  ... 
)
static

Parse a list of options given as varargs.

Parameters
daemonthe daemon to initialize
servaddrwhere to store the server's listen address
...the options
Returns
MHD_YES on success, MHD_NO on error

Definition at line 3925 of file daemon.c.

References parse_options_va().

Referenced by parse_options_va().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_options_va()

static int parse_options_va ( struct MHD_Daemon daemon,
const struct sockaddr **  servaddr,
va_list  ap 
)
static

Parse a list of options given as varargs.

Parameters
daemonthe daemon to initialize
servaddrwhere to store the server's listen address
apthe options
Returns
MHD_YES on success, MHD_NO on error

Definition at line 3950 of file daemon.c.

References _, MHD_Daemon::connection_limit, MHD_Daemon::connection_timeout, fd, MHD_Daemon::itc, MHD_Daemon::listen_backlog_size, MHD_Daemon::listening_address_reuse, MHD_INVALID_SOCKET, MHD_NO, MHD_OPTION_ARRAY, MHD_OPTION_CONNECTION_LIMIT, MHD_OPTION_CONNECTION_MEMORY_INCREMENT, MHD_OPTION_CONNECTION_MEMORY_LIMIT, MHD_OPTION_CONNECTION_TIMEOUT, MHD_OPTION_DIGEST_AUTH_RANDOM, MHD_OPTION_END, MHD_OPTION_EXTERNAL_LOGGER, MHD_OPTION_HTTPS_CERT_CALLBACK, MHD_OPTION_HTTPS_CRED_TYPE, MHD_OPTION_HTTPS_KEY_PASSWORD, MHD_OPTION_HTTPS_MEM_CERT, MHD_OPTION_HTTPS_MEM_DHPARAMS, MHD_OPTION_HTTPS_MEM_KEY, MHD_OPTION_HTTPS_MEM_TRUST, MHD_OPTION_HTTPS_PRIORITIES, MHD_OPTION_LISTEN_BACKLOG_SIZE, MHD_OPTION_LISTEN_SOCKET, MHD_OPTION_LISTENING_ADDRESS_REUSE, MHD_OPTION_NONCE_NC_SIZE, MHD_OPTION_NOTIFY_COMPLETED, MHD_OPTION_NOTIFY_CONNECTION, MHD_OPTION_PER_IP_CONNECTION_LIMIT, MHD_OPTION_SOCK_ADDR, MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE, MHD_OPTION_THREAD_POOL_SIZE, MHD_OPTION_THREAD_STACK_SIZE, MHD_OPTION_UNESCAPE_CALLBACK, MHD_OPTION_URI_LOG_CALLBACK, MHD_socket_last_strerr_, MHD_socket_noninheritable_(), MHD_USE_SUSPEND_RESUME, MHD_USE_TLS, MHD_USE_TLS_EPOLL_UPGRADE, MHD_YES, MHD_Daemon::notify_completed, MHD_Daemon::notify_completed_cls, MHD_Daemon::notify_connection, MHD_Daemon::notify_connection_cls, NULL, MHD_OptionItem::option, MHD_Daemon::options, parse_options(), MHD_Daemon::per_ip_connection_limit, MHD_Daemon::pool_increment, MHD_Daemon::pool_size, MHD_OptionItem::ptr_value, SIZE_MAX, MHD_Daemon::socket_fd, MHD_Daemon::thread_stack_size, MHD_Daemon::unescape_callback, MHD_Daemon::unescape_callback_cls, MHD_Daemon::uri_log_callback, MHD_Daemon::uri_log_callback_cls, MHD_OptionItem::value, and MHD_Daemon::worker_pool_size.

Referenced by MHD_start_daemon_va(), and parse_options().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ recv_param_adapter()

static ssize_t recv_param_adapter ( struct MHD_Connection connection,
void *  other,
size_t  i 
)
static

Callback for receiving data from the socket.

Parameters
connectionthe MHD connection structure
otherwhere to write received data to
imaximum size of other (in bytes)
Returns
number of bytes actually received

Definition at line 1581 of file daemon.c.

References MHD_CONNECTION_CLOSED, MHD_EPOLL_STATE_READ_READY, MHD_INVALID_SOCKET, MHD_recv_, MHD_SCKT_ENOTCONN_, MHD_SCKT_ERR_IS_EAGAIN_, MHD_socket_get_error_, MHD_socket_set_error_, MHD_Connection::socket_fd, and MHD_Connection::state.

Referenced by internal_add_connection().

Here is the caller graph for this function:

◆ resume_suspended_connections()

◆ send_param_adapter()

static ssize_t send_param_adapter ( struct MHD_Connection connection,
const void *  other,
size_t  i 
)
static

◆ thread_main_connection_upgrade()

static void thread_main_connection_upgrade ( struct MHD_Connection con)
static

Main function of the thread that handles an individual connection after it was "upgraded" when MHD_USE_THREAD_PER_CONNECTION is set.

Parameters
conthe connection this thread will handle

Definition at line 1152 of file daemon.c.

References _, MHD_UpgradeResponseHandle::connection, MHD_Connection::daemon, MHD_CONNECTION_UPGRADE, MHD_EPOLL_STATE_READ_READY, MHD_EPOLL_STATE_WRITE_READY, MHD_INVALID_SOCKET, MHD_NO, MHD_SCKT_ERR_IS_EINTR_, MHD_socket_get_error_, MHD_socket_strerr_, MHD_SYS_select_, MHD_USE_POLL, MHD_USE_TLS, NULL, MHD_Daemon::options, MHD_Connection::socket_fd, MHD_Connection::state, UINT_MAX, and MHD_Connection::urh.

Referenced by thread_main_handle_connection().

Here is the caller graph for this function:

◆ thread_main_handle_connection()

static MHD_THRD_RTRN_TYPE_ MHD_THRD_CALL_SPEC_ thread_main_handle_connection ( void *  data)
static

Main function of the thread that handles an individual connection when MHD_USE_THREAD_PER_CONNECTION is set.

Parameters
datathe struct MHD_Connection this thread will handle
Returns
always 0

Definition at line 1289 of file daemon.c.

References _, call_handlers(), MHD_Connection::client_aware, MHD_Connection::client_context, MHD_Daemon::connection_timeout, MHD_Connection::daemon, data, MHD_Connection::event_loop_info, MHD_Connection::idle_handler, MHD_Daemon::itc, MHD_Connection::last_activity, MHD_add_to_fd_set_(), MHD_connection_close_(), MHD_CONNECTION_CLOSED, MHD_CONNECTION_IN_CLEANUP, MHD_CONNECTION_UPGRADE, MHD_destroy_response(), MHD_EVENT_LOOP_INFO_BLOCK, MHD_EVENT_LOOP_INFO_CLEANUP, MHD_EVENT_LOOP_INFO_READ, MHD_EVENT_LOOP_INFO_WRITE, MHD_INVALID_SOCKET, MHD_monotonic_sec_counter(), MHD_NO, MHD_REQUEST_TERMINATED_COMPLETED_OK, MHD_REQUEST_TERMINATED_DAEMON_SHUTDOWN, MHD_SCKT_EINTR_, MHD_SCKT_ERR_IS_EINTR_, MHD_SCKT_LAST_ERR_IS_, MHD_socket_close_chk_, MHD_socket_get_error_, MHD_socket_last_strerr_, MHD_socket_strerr_, MHD_SYS_select_, MHD_USE_POLL, MHD_USE_TLS, MHD_YES, MHD_Daemon::notify_completed, MHD_Daemon::notify_completed_cls, NULL, MHD_Daemon::options, MHD_Connection::read_buffer_offset, MHD_Connection::read_buffer_size, MHD_Connection::response, MHD_Daemon::shutdown, MHD_Connection::socket_fd, MHD_Connection::state, thread_main_connection_upgrade(), and TIMEVAL_TV_SEC_MAX.

Referenced by internal_add_connection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unescape_wrapper()

static size_t unescape_wrapper ( void *  cls,
struct MHD_Connection connection,
char *  val 
)
static

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.

Parameters
clsclosure (use NULL)
connectionhandle to connection, not used
valvalue to unescape (modified in the process)
Returns
length of the resulting val (strlen(val) maybe shorter afterwards due to elimination of escape sequences)

Definition at line 3752 of file daemon.c.

References MHD_http_unescape().

Referenced by MHD_start_daemon_va().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ mhd_panic

◆ mhd_panic_cls