GNU libmicrohttpd 0.9.77
Loading...
Searching...
No Matches
daemon_options.c File Reference

boring functions to manipulate daemon options More...

#include "internal.h"
Include dependency graph for daemon_options.c:

Go to the source code of this file.

Functions

void MHD_daemon_set_logger (struct MHD_Daemon *daemon, MHD_LoggingCallback logger, void *logger_cls)
 
void MHD_daemon_suppress_date_no_clock (struct MHD_Daemon *daemon)
 
void MHD_daemon_disable_itc (struct MHD_Daemon *daemon)
 
void MHD_daemon_enable_turbo (struct MHD_Daemon *daemon)
 
void MHD_daemon_disallow_suspend_resume (struct MHD_Daemon *daemon)
 
void MHD_daemon_disallow_upgrade (struct MHD_Daemon *daemon)
 
enum MHD_Bool MHD_daemon_tcp_fastopen (struct MHD_Daemon *daemon, enum MHD_FastOpenMethod fom, unsigned int queue_length)
 
void MHD_daemon_bind_port (struct MHD_Daemon *daemon, enum MHD_AddressFamily af, uint16_t port)
 
void MHD_daemon_bind_socket_address (struct MHD_Daemon *daemon, const struct sockaddr *sa, size_t sa_len)
 
void MHD_daemon_listen_backlog (struct MHD_Daemon *daemon, int listen_backlog)
 
void MHD_daemon_listen_allow_address_reuse (struct MHD_Daemon *daemon)
 
_MHD_EXTERN void MHD_daemon_enable_shoutcast (struct MHD_Daemon *daemon)
 
void MHD_daemon_listen_socket (struct MHD_Daemon *daemon, MHD_socket listen_socket)
 
enum MHD_Bool MHD_daemon_event_loop (struct MHD_Daemon *daemon, enum MHD_EventLoopSyscall els)
 
void MHD_daemon_protocol_strict_level (struct MHD_Daemon *daemon, enum MHD_ProtocolStrictLevel sl)
 
enum MHD_StatusCode MHD_daemon_set_tls_backend (struct MHD_Daemon *daemon, const char *tls_backend, const char *ciphers)
 
enum MHD_StatusCode MHD_daemon_tls_key_and_cert_from_memory (struct MHD_Daemon *daemon, const char *mem_key, const char *mem_cert, const char *pass)
 
enum MHD_StatusCode MHD_daemon_tls_mem_dhparams (struct MHD_Daemon *daemon, const char *dh)
 
enum MHD_StatusCode MHD_daemon_tls_mem_trust (struct MHD_Daemon *daemon, const char *mem_trust)
 
enum MHD_StatusCode MHD_daemon_gnutls_credentials (struct MHD_Daemon *daemon, int gnutls_credentials)
 
enum MHD_StatusCode MHD_daemon_gnutls_key_and_cert_from_callback (struct MHD_Daemon *daemon, void *cb)
 
void MHD_daemon_threading_mode (struct MHD_Daemon *daemon, enum MHD_ThreadingMode tm)
 
void MHD_daemon_accept_policy (struct MHD_Daemon *daemon, MHD_AcceptPolicyCallback apc, void *apc_cls)
 
void MHD_daemon_set_early_uri_logger (struct MHD_Daemon *daemon, MHD_EarlyUriLogCallback cb, void *cb_cls)
 
void MHD_daemon_set_notify_connection (struct MHD_Daemon *daemon, MHD_NotifyConnectionCallback ncc, void *ncc_cls)
 
void MHD_daemon_connection_memory_limit (struct MHD_Daemon *daemon, size_t memory_limit_b, size_t memory_increment_b)
 
void MHD_daemon_thread_stack_size (struct MHD_Daemon *daemon, size_t stack_limit_b)
 
void MHD_daemon_connection_limits (struct MHD_Daemon *daemon, unsigned int global_connection_limit, unsigned int ip_connection_limit)
 
void MHD_daemon_connection_default_timeout (struct MHD_Daemon *daemon, unsigned int timeout_s)
 
void MHD_daemon_unescape_cb (struct MHD_Daemon *daemon, MHD_UnescapeCallback unescape_cb, void *unescape_cb_cls)
 
void MHD_daemon_digest_auth_random (struct MHD_Daemon *daemon, size_t buf_size, const void *buf)
 
enum MHD_StatusCode MHD_daemon_digest_auth_nc_length (struct MHD_Daemon *daemon, size_t nc_length)
 

Detailed Description

boring functions to manipulate daemon options

Author
Christian Grothoff

Definition in file daemon_options.c.

Function Documentation

◆ MHD_daemon_accept_policy()

void MHD_daemon_accept_policy ( struct MHD_Daemon daemon,
MHD_AcceptPolicyCallback  apc,
void *  apc_cls 
)

Set a policy callback that accepts/rejects connections based on the client's IP address. This function will be called before a connection object is created.

Parameters
daemondaemon to set policy for
apcfunction to call to check the policy
apc_clsclosure for apc

Definition at line 560 of file daemon_options.c.

References MHD_Daemon::accept_policy_cb, and MHD_Daemon::accept_policy_cb_cls.

◆ MHD_daemon_bind_port()

void MHD_daemon_bind_port ( struct MHD_Daemon daemon,
enum MHD_AddressFamily  af,
uint16_t  port 
)

Bind to the given TCP port and address family.

Ineffective in conjunction with MHD_daemon_listen_socket(). Ineffective in conjunction with #MHD_daemon_bind_sa().

If neither this option nor the other two mentioned above is specified, MHD will simply not listen on any socket!

Parameters
daemonwhich instance to configure the TCP port for
afaddress family to use
portport to use, 0 to bind to a random (free) port

Definition at line 187 of file daemon_options.c.

References MHD_Daemon::listen_af, and MHD_Daemon::listen_port.

◆ MHD_daemon_bind_socket_address()

void MHD_daemon_bind_socket_address ( struct MHD_Daemon daemon,
const struct sockaddr *  sa,
size_t  sa_len 
)

Bind to the given socket address. Ineffective in conjunction with MHD_daemon_listen_socket().

Parameters
daemonwhich instance to configure the binding address for
saaddress to bind to; can be IPv4 (AF_INET), IPv6 (AF_INET6) or even a UNIX domain socket (AF_UNIX)
sa_lennumber of bytes in sa

Definition at line 206 of file daemon_options.c.

References MHD_Daemon::listen_sa, and MHD_Daemon::listen_sa_len.

◆ MHD_daemon_connection_default_timeout()

void MHD_daemon_connection_default_timeout ( struct MHD_Daemon daemon,
unsigned int  timeout_s 
)

After how many seconds of inactivity should a connection automatically be timed out? Use zero for no timeout, which is also the (unsafe!) default.

Parameters
daemondaemon to configure
timeout_snumber of seconds of timeout to use

Definition at line 679 of file daemon_options.c.

References MHD_Daemon::connection_default_timeout.

◆ MHD_daemon_connection_limits()

void MHD_daemon_connection_limits ( struct MHD_Daemon daemon,
unsigned int  global_connection_limit,
unsigned int  ip_connection_limit 
)

Set maximum number of concurrent connections to accept. If not given, MHD will not enforce any limits (modulo running into OS limits). Values of 0 mean no limit.

Parameters
daemondaemon to configure
global_connection_limitmaximum number of (concurrent) connections
ip_connection_limitlimit on the number of (concurrent) connections made to the server from the same IP address. Can be used to prevent one IP from taking over all of the allowed connections. If the same IP tries to establish more than the specified number of connections, they will be immediately rejected.

Definition at line 661 of file daemon_options.c.

References MHD_Daemon::global_connection_limit, and MHD_Daemon::ip_connection_limit.

◆ MHD_daemon_connection_memory_limit()

void MHD_daemon_connection_memory_limit ( struct MHD_Daemon daemon,
size_t  memory_limit_b,
size_t  memory_increment_b 
)

Maximum memory size per connection. Default is 32 kb (MHD_POOL_SIZE_DEFAULT). Values above 128k are unlikely to result in much benefit, as half of the memory will be typically used for IO, and TCP buffers are unlikely to support window sizes above 64k on most systems.

Parameters
daemondaemon to configure
memory_limit_bconnection memory limit to use in bytes
memory_increment_bincrement to use when growing the read buffer, must be smaller than memory_limit_b

Definition at line 618 of file daemon_options.c.

References MHD_Daemon::connection_memory_increment_b, MHD_Daemon::connection_memory_limit_b, and MHD_PANIC.

◆ MHD_daemon_digest_auth_nc_length()

enum MHD_StatusCode MHD_daemon_digest_auth_nc_length ( struct MHD_Daemon daemon,
size_t  nc_length 
)

Length of the internal array holding the map of the nonce and the nonce counter.

Parameters
daemondaemon to configure
nc_lengthdesired array length

Definition at line 741 of file daemon_options.c.

References _, MHD_strerror_, and NULL.

◆ MHD_daemon_digest_auth_random()

void MHD_daemon_digest_auth_random ( struct MHD_Daemon daemon,
size_t  buf_size,
const void *  buf 
)

Set random values to be used by the Digest Auth module. Note that the application must ensure that buf remains allocated and unmodified while the daemon is running.

Parameters
daemondaemon to configure
buf_sizenumber of bytes in buf
bufentropy buffer

Definition at line 717 of file daemon_options.c.

References MHD_PANIC.

◆ MHD_daemon_disable_itc()

void MHD_daemon_disable_itc ( struct MHD_Daemon daemon)

Disable use of inter-thread communication channel. MHD_daemon_disable_itc() can be used with #MHD_daemon_thread_internal() to perform some additional optimizations (in particular, not creating a pipe for IPC signalling). If it is used, certain functions like MHD_daemon_quiesce() or #MHD_connection_add() or MHD_action_suspend() cannot be used anymore. MHD_daemon_disable_itc() is not beneficial on platforms where select()/poll()/other signal shutdown() of a listen socket.

You should only use this function if you are sure you do satisfy all of its requirements and need a generally minor boost in performance.

Parameters
daemonwhich instance to disable itc for

Definition at line 79 of file daemon_options.c.

References MHD_Daemon::disable_itc.

◆ MHD_daemon_disallow_suspend_resume()

void MHD_daemon_disallow_suspend_resume ( struct MHD_Daemon daemon)

Disable MHD_action_suspend() functionality.

You should only use this function if you are sure you do satisfy all of its requirements and need a generally minor boost in performance.

Parameters
daemonwhich instance to disable suspend for

Definition at line 110 of file daemon_options.c.

References MHD_Daemon::disallow_suspend_resume.

◆ MHD_daemon_disallow_upgrade()

void MHD_daemon_disallow_upgrade ( struct MHD_Daemon daemon)

You need to set this option if you want to disable use of HTTP "Upgrade". "Upgrade" may require usage of additional internal resources, which we can avoid providing if they will not be used.

You should only use this function if you are sure you do satisfy all of its requirements and need a generally minor boost in performance.

Parameters
daemonwhich instance to enable suspend/resume for

Definition at line 128 of file daemon_options.c.

References MHD_Daemon::disallow_upgrade.

◆ MHD_daemon_enable_shoutcast()

_MHD_EXTERN void MHD_daemon_enable_shoutcast ( struct MHD_Daemon daemon)

Use SHOUTcast. This will cause the response to begin with the SHOUTcast "ICY" line instead of "HTTP".

Parameters
daemondaemon to set SHOUTcast option for

Definition at line 256 of file daemon_options.c.

References MHD_Daemon::enable_shoutcast.

◆ MHD_daemon_enable_turbo()

void MHD_daemon_enable_turbo ( struct MHD_Daemon daemon)

Enable turbo. Disables certain calls to shutdown(), enables aggressive non-blocking optimistic reads and other potentially unsafe optimizations. Most effects only happen with #MHD_ELS_EPOLL.

Parameters
daemonwhich instance to enable turbo for

Definition at line 94 of file daemon_options.c.

References MHD_Daemon::enable_turbo.

◆ MHD_daemon_event_loop()

enum MHD_Bool MHD_daemon_event_loop ( struct MHD_Daemon daemon,
enum MHD_EventLoopSyscall  els 
)

Force use of a particular event loop system call.

Parameters
daemondaemon to set event loop style for
elsevent loop syscall to use
Returns
MHD_NO on failure, MHD_YES on success

Definition at line 292 of file daemon_options.c.

References MHD_Daemon::event_loop_syscall, MHD_NO, and MHD_YES.

◆ MHD_daemon_gnutls_credentials()

enum MHD_StatusCode MHD_daemon_gnutls_credentials ( struct MHD_Daemon daemon,
int  gnutls_credentials 
)

Configure daemon credentials type for GnuTLS.

Parameters
gnutls_credentialsmust be a value of type gnutls_credentials_type_t
Returns
#MHD_SC_OK upon success; TODO: define failure modes

Definition at line 487 of file daemon_options.c.

References NULL.

◆ MHD_daemon_gnutls_key_and_cert_from_callback()

enum MHD_StatusCode MHD_daemon_gnutls_key_and_cert_from_callback ( struct MHD_Daemon daemon,
void *  cb 
)

Provide TLS key and certificate data via callback.

Use a callback to determine which X.509 certificate should be used for a given HTTPS connection. This option provides an alternative to MHD_daemon_tls_key_and_cert_from_memory(). You must use this version if multiple domains are to be hosted at the same IP address using TLS's Server Name Indication (SNI) extension. In this case, the callback is expected to select the correct certificate based on the SNI information provided. The callback is expected to access the SNI data using gnutls_server_name_get(). Using this option requires GnuTLS 3.0 or higher.

Parameters
daemondaemon to configure callback for
cbmust be of type gnutls_certificate_retrieve_function2 *.
Returns
#MHD_SC_OK on success

Definition at line 520 of file daemon_options.c.

References NULL.

◆ MHD_daemon_listen_allow_address_reuse()

void MHD_daemon_listen_allow_address_reuse ( struct MHD_Daemon daemon)

If present true, allow reusing address:port socket (by using SO_REUSEPORT on most platform, or platform-specific ways). If present and set to false, disallow reusing address:port socket (does nothing on most platform, but uses SO_EXCLUSIVEADDRUSE on Windows). Ineffective in conjunction with MHD_daemon_listen_socket().

Parameters
daemondaemon to configure address reuse for

Definition at line 243 of file daemon_options.c.

References MHD_Daemon::allow_address_reuse.

◆ MHD_daemon_listen_backlog()

void MHD_daemon_listen_backlog ( struct MHD_Daemon daemon,
int  listen_backlog 
)

Use the given backlog for the listen() call. Ineffective in conjunction with MHD_daemon_listen_socket().

Parameters
daemonwhich instance to configure the backlog for
listen_backlogbacklog to use

Definition at line 225 of file daemon_options.c.

References MHD_Daemon::listen_backlog.

◆ MHD_daemon_listen_socket()

void MHD_daemon_listen_socket ( struct MHD_Daemon daemon,
MHD_socket  listen_socket 
)

Accept connections from the given socket. Socket must be a TCP or UNIX domain (stream) socket.

Unless -1 is given, this disables other listen options, including #MHD_daemon_bind_sa(), MHD_daemon_bind_port(), #MHD_daemon_listen_queue() and MHD_daemon_listen_allow_address_reuse().

Parameters
daemondaemon to set listen socket for
listen_socketlisten socket to use, MHD_INVALID_SOCKET value will cause this call to be ignored (other binding options may still be effective)

Definition at line 277 of file daemon_options.c.

References MHD_Daemon::listen_socket.

◆ MHD_daemon_protocol_strict_level()

void MHD_daemon_protocol_strict_level ( struct MHD_Daemon daemon,
enum MHD_ProtocolStrictLevel  sl 
)

Set how strictly MHD will enforce the HTTP protocol.

Parameters
daemondaemon to configure strictness for
slhow strict should we be

Definition at line 328 of file daemon_options.c.

References MHD_Daemon::protocol_strict_level.

◆ MHD_daemon_set_early_uri_logger()

void MHD_daemon_set_early_uri_logger ( struct MHD_Daemon daemon,
MHD_EarlyUriLogCallback  cb,
void *  cb_cls 
)

Register a callback to be called first for every request (before any parsing of the header). Makes it easy to log the full URL.

Parameters
daemondaemon for which to set the logger
cbfunction to call
cb_clsclosure for cb

Definition at line 579 of file daemon_options.c.

References MHD_Daemon::early_uri_logger_cb, and MHD_Daemon::early_uri_logger_cb_cls.

◆ MHD_daemon_set_logger()

void MHD_daemon_set_logger ( struct MHD_Daemon daemon,
MHD_LoggingCallback  logger,
void *  logger_cls 
)

Set logging method. Specify NULL to disable logging entirely. By default (if this option is not given), we log error messages to stderr.

Parameters
daemonwhich instance to setup logging for
loggerfunction to invoke
logger_clsclosure for logger

Definition at line 40 of file daemon_options.c.

References MHD_Daemon::logger, and MHD_Daemon::logger_cls.

◆ MHD_daemon_set_notify_connection()

void MHD_daemon_set_notify_connection ( struct MHD_Daemon daemon,
MHD_NotifyConnectionCallback  ncc,
void *  ncc_cls 
)

Register a function that should be called whenever a connection is started or closed.

Parameters
daemondaemon to set callback for
nccfunction to call to check the policy
ncc_clsclosure for apc

Definition at line 597 of file daemon_options.c.

References MHD_Daemon::notify_connection_cb, and MHD_Daemon::notify_connection_cb_cls.

◆ MHD_daemon_set_tls_backend()

enum MHD_StatusCode MHD_daemon_set_tls_backend ( struct MHD_Daemon daemon,
const char *  tls_backend,
const char *  ciphers 
)

Enable and configure TLS.

Parameters
daemonwhich instance should be configured
tls_backendwhich TLS backend should be used, currently only "gnutls" is supported. You can also specify NULL for best-available (which is the default).
cipherswhich ciphers should be used by TLS, default is "NORMAL"
Returns
status code, #MHD_SC_OK upon success #MHD_TLS_BACKEND_UNSUPPORTED if the backend is unknown #MHD_TLS_DISABLED if this build of MHD does not support TLS #MHD_TLS_CIPHERS_INVALID if the given ciphers are not supported by this backend

Definition at line 351 of file daemon_options.c.

References MHD_TLS_ABI_VERSION_STR, and NULL.

◆ MHD_daemon_suppress_date_no_clock()

void MHD_daemon_suppress_date_no_clock ( struct MHD_Daemon daemon)

Suppress use of "Date" header as this system has no RTC.

Parameters
daemonwhich instance to disable clock for.

Definition at line 55 of file daemon_options.c.

References MHD_Daemon::suppress_date.

◆ MHD_daemon_tcp_fastopen()

enum MHD_Bool MHD_daemon_tcp_fastopen ( struct MHD_Daemon daemon,
enum MHD_FastOpenMethod  fom,
unsigned int  queue_length 
)

Configure TCP_FASTOPEN option, including setting a custom queue_length.

Note that having a larger queue size can cause resource exhaustion attack as the TCP stack has to now allocate resources for the SYN packet along with its DATA.

Parameters
daemonwhich instance to configure TCP_FASTOPEN for
fomunder which conditions should we use TCP_FASTOPEN?
queue_lengthqueue length to use, default is 50 if this option is never given.
Returns
MHD_YES upon success, MHD_NO if #MHD_FOM_REQUIRE was given, but TCP_FASTOPEN is not available on the platform

Definition at line 150 of file daemon_options.c.

References MHD_Daemon::fast_open_method, MHD_Daemon::fo_queue_length, MHD_NO, and MHD_YES.

◆ MHD_daemon_thread_stack_size()

void MHD_daemon_thread_stack_size ( struct MHD_Daemon daemon,
size_t  stack_limit_b 
)

Desired size of the stack for threads created by MHD. Use 0 for system default. Only useful if the selected threading mode is not #MHD_TM_EXTERNAL_EVENT_LOOP.

Parameters
daemondaemon to configure
stack_limit_bstack size to use in bytes

Definition at line 638 of file daemon_options.c.

References MHD_Daemon::thread_stack_limit_b.

◆ MHD_daemon_threading_mode()

void MHD_daemon_threading_mode ( struct MHD_Daemon daemon,
enum MHD_ThreadingMode  tm 
)

Specify threading mode to use.

Parameters
daemondaemon to configure
tmmode to use (positive values indicate the number of worker threads to be used)

Definition at line 543 of file daemon_options.c.

References MHD_Daemon::threading_mode.

◆ MHD_daemon_tls_key_and_cert_from_memory()

enum MHD_StatusCode MHD_daemon_tls_key_and_cert_from_memory ( struct MHD_Daemon daemon,
const char *  mem_key,
const char *  mem_cert,
const char *  pass 
)

Provide TLS key and certificate data in-memory.

Parameters
daemonwhich instance should be configured
mem_keyprivate key (key.pem) to be used by the HTTPS daemon. Must be the actual data in-memory, not a filename.
mem_certcertificate (cert.pem) to be used by the HTTPS daemon. Must be the actual data in-memory, not a filename.
passpassphrase phrase to decrypt 'key.pem', NULL if
mem_keyis in cleartext already
Returns
#MHD_SC_OK upon success; MHD_BACKEND_UNINITIALIZED if the TLS backend is not yet setup.

Definition at line 407 of file daemon_options.c.

References MHD_TLS_Plugin::cls, MHD_TLS_Plugin::init_kcp, and NULL.

◆ MHD_daemon_tls_mem_dhparams()

enum MHD_StatusCode MHD_daemon_tls_mem_dhparams ( struct MHD_Daemon daemon,
const char *  dh 
)

Configure DH parameters (dh.pem) to use for the TLS key exchange.

Parameters
daemondaemon to configure tls for
dhparameters to use
Returns
#MHD_SC_OK upon success; MHD_BACKEND_UNINITIALIZED if the TLS backend is not yet setup.

Definition at line 437 of file daemon_options.c.

References MHD_TLS_Plugin::cls, MHD_TLS_Plugin::init_dhparams, and NULL.

◆ MHD_daemon_tls_mem_trust()

enum MHD_StatusCode MHD_daemon_tls_mem_trust ( struct MHD_Daemon daemon,
const char *  mem_trust 
)

Memory pointer for the certificate (ca.pem) to be used by the HTTPS daemon for client authentication.

Parameters
daemondaemon to configure tls for
mem_trustmemory pointer to the certificate
Returns
#MHD_SC_OK upon success; MHD_BACKEND_UNINITIALIZED if the TLS backend is not yet setup.

Definition at line 463 of file daemon_options.c.

References MHD_TLS_Plugin::cls, MHD_TLS_Plugin::init_mem_trust, and NULL.

◆ MHD_daemon_unescape_cb()

void MHD_daemon_unescape_cb ( struct MHD_Daemon daemon,
MHD_UnescapeCallback  unescape_cb,
void *  unescape_cb_cls 
)

Specify a function that should be called for unescaping escape sequences in URIs and URI arguments. Note that this function will NOT be used by the struct MHD_PostProcessor. If this option is not specified, the default method will be used which decodes escape sequences of the form "%HH".

Parameters
daemondaemon to configure
unescape_cbfunction to use, NULL for default
unescape_cb_clsclosure for unescape_cb

Definition at line 698 of file daemon_options.c.

References MHD_Daemon::unescape_cb, and MHD_Daemon::unescape_cb_cls.