23#if defined(__GNUC__) || defined(__MINGW32__)
25 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
26#if GCC_VERSION >= 40500
32#if defined(GCC_DIAGNOSTIC)
35#pragma GCC diagnostic ignored "-Wunused-macros"
37#pragma GCC diagnostic ignored "-Wpadded"
44#pragma GCC diagnostic push
45#pragma GCC diagnostic ignored "-Wreserved-id-macro"
49#if !defined(_CRT_SECURE_NO_WARNINGS)
50#define _CRT_SECURE_NO_WARNINGS
52#if !defined(_WIN32_WINNT)
53#define _WIN32_WINNT 0x0502
56#if !defined(_GNU_SOURCE)
59#if defined(__linux__) && !defined(_XOPEN_SOURCE)
60#define _XOPEN_SOURCE 600
62#if defined(__LSB_VERSION__) || defined(__sun)
66#if !defined(_LARGEFILE_SOURCE)
67#define _LARGEFILE_SOURCE
69#if !defined(_FILE_OFFSET_BITS)
70#define _FILE_OFFSET_BITS 64
72#if !defined(__STDC_FORMAT_MACROS)
73#define __STDC_FORMAT_MACROS
75#if !defined(__STDC_LIMIT_MACROS)
76#define __STDC_LIMIT_MACROS
78#if !defined(_DARWIN_UNLIMITED_SELECT)
79#define _DARWIN_UNLIMITED_SELECT
83#define __inline inline
89#pragma GCC diagnostic pop
99#pragma warning(disable : 4306)
101#pragma warning(disable : 4127)
103#pragma warning(disable : 4204)
105#pragma warning(disable : 4820)
107#pragma warning(disable : 4668)
109#pragma warning(disable : 4255)
111#pragma warning(disable : 4711)
118#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 201100L
119#define mg_static_assert _Static_assert
120#elif defined(__cplusplus) && __cplusplus >= 201103L
121#define mg_static_assert static_assert
124#define mg_static_assert(cond, txt) \
125 extern char static_assert_replacement[(cond) ? 1 : -1]
129 "int data type size check");
131 "pointer data type size check");
143#if defined(NO_ALTERNATIVE_QUEUE) && defined(ALTERNATIVE_QUEUE)
146 "Define ALTERNATIVE_QUEUE or NO_ALTERNATIVE_QUEUE (or none of them), but not both"
148#if !defined(NO_ALTERNATIVE_QUEUE) && !defined(ALTERNATIVE_QUEUE)
150#define NO_ALTERNATIVE_QUEUE
153#if defined(NO_FILESYSTEMS) && !defined(NO_FILES)
168#error "Inconsistent build flags, NO_FILESYSTEMS requires NO_FILES"
172#if !defined(WIN32_LEAN_AND_MEAN)
173#define WIN32_LEAN_AND_MEAN
176#if defined(__SYMBIAN32__)
181#error "Symbian is no longer maintained. CivetWeb no longer supports Symbian."
184#if defined(__ZEPHYR__)
188#include <net/socket.h>
189#include <posix/pthread.h>
190#include <posix/time.h>
198#include <libc_extensions.h>
203#define MAX_WORKER_THREADS (CONFIG_MAX_PTHREAD_COUNT - 2)
205#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
206#define ZEPHYR_STACK_SIZE USE_STACK_SIZE
208#define ZEPHYR_STACK_SIZE (1024 * 16)
220#if !defined(CIVETWEB_HEADER_INCLUDED)
226#if !defined(DEBUG_TRACE)
233#define DEBUG_TRACE(fmt, ...) \
234 DEBUG_TRACE_FUNC(__func__, __LINE__, fmt, __VA_ARGS__)
236#define NEED_DEBUG_TRACE_FUNC
237#if !defined(DEBUG_TRACE_STREAM)
238#define DEBUG_TRACE_STREAM stdout
242#define DEBUG_TRACE(fmt, ...) \
249#if !defined(DEBUG_ASSERT)
252#define DEBUG_ASSERT(cond) \
255 DEBUG_TRACE("ASSERTION FAILED: %s", #cond); \
260#define DEBUG_ASSERT(cond)
265#if defined(__GNUC__) && defined(GCC_INSTRUMENTATION)
290#if !defined(IGNORE_UNUSED_RESULT)
291#define IGNORE_UNUSED_RESULT(a) ((void)((a) && 1))
295#if defined(__GNUC__) || defined(__MINGW32__)
311#pragma GCC diagnostic ignored "-Wunused-function"
313#define FUNCTION_MAY_BE_UNUSED
316#define FUNCTION_MAY_BE_UNUSED
321#if !defined(_WIN32_WCE) && !defined(__ZEPHYR__)
327#include <sys/types.h>
331#if defined(__clang__)
335#pragma clang diagnostic ignored "-Wdisabled-macro-expansion"
338#if defined(__GNUC__) || defined(__MINGW32__)
357#if defined(__clang__)
358#if (__clang_major__ == 3) && ((__clang_minor__ == 7) || (__clang_minor__ == 8))
360#pragma clang diagnostic ignored "-Wno-reserved-id-macro"
361#pragma clang diagnostic ignored "-Wno-keyword-macro"
365#ifndef CLOCK_MONOTONIC
366#define CLOCK_MONOTONIC (1)
368#ifndef CLOCK_REALTIME
369#define CLOCK_REALTIME (2)
372#include <mach/clock.h>
373#include <mach/mach.h>
374#include <mach/mach_time.h>
375#include <sys/errno.h>
389 t->tv_sec =
now.tv_sec;
390 t->tv_nsec =
now.tv_usec * 1000;
413 t->tv_sec =
now / 1000000000;
414 t->tv_nsec =
now % 1000000000;
421#if defined(__CLOCK_AVAILABILITY)
433#define clock_gettime _civet_safe_clock_gettime
435#define clock_gettime _civet_clock_gettime
445#define ERROR_TRY_AGAIN(err) \
446 (((err) == EAGAIN) || ((err) == EWOULDBLOCK) || ((err) == EINTR))
462#if !defined(MAX_WORKER_THREADS)
463#define MAX_WORKER_THREADS (1024 * 64)
470#if !defined(SOCKET_TIMEOUT_QUANTUM)
471#define SOCKET_TIMEOUT_QUANTUM (2000)
475#if !defined(MG_FILE_COMPRESSION_SIZE_LIMIT)
476#define MG_FILE_COMPRESSION_SIZE_LIMIT (1024)
479#if !defined(PASSWORDS_FILE_NAME)
480#define PASSWORDS_FILE_NAME ".htpasswd"
485#if !defined(CGI_ENVIRONMENT_SIZE)
486#define CGI_ENVIRONMENT_SIZE (4096)
490#if !defined(MAX_CGI_ENVIR_VARS)
491#define MAX_CGI_ENVIR_VARS (256)
495#if !defined(MG_BUF_LEN)
496#define MG_BUF_LEN (1024 * 8)
503#if !defined(ARRAY_SIZE)
504#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
510#if !defined(INT64_MAX)
511#define INT64_MAX (9223372036854775807)
514#define SHUTDOWN_RD (0)
515#define SHUTDOWN_WR (1)
516#define SHUTDOWN_BOTH (2)
519 "worker threads must be a positive number");
522 "size_t data type size check");
540#define UTF8_PATH_MAX (3 * 260)
543#define UTF16_PATH_MAX (260)
545#if !defined(_IN_PORT_T)
546#if !defined(in_port_t)
547#define in_port_t u_short
551#if defined(_WIN32_WCE)
552#error "WinCE support has ended"
560#define MAKEUQUAD(lo, hi) \
561 ((uint64_t)(((uint32_t)(lo)) | ((uint64_t)((uint32_t)(hi))) << 32))
562#define RATE_DIFF (10000000)
563#define EPOCH_DIFF (MAKEUQUAD(0xd53e8000, 0x019db1de))
564#define SYS2UNIX_TIME(lo, hi) \
565 ((time_t)((MAKEUQUAD((lo), (hi)) - EPOCH_DIFF) / RATE_DIFF))
573#define STR(x) STRX(x)
574#define __func__ __FILE__ ":" STR(__LINE__)
575#define strtoull(x, y, z) ((unsigned __int64)_atoi64(x))
576#define strtoll(x, y, z) (_atoi64(x))
578#define __func__ __FUNCTION__
579#define strtoull(x, y, z) (_strtoui64(x, y, z))
580#define strtoll(x, y, z) (_strtoi64(x, y, z))
584#define ERRNO ((int)(GetLastError()))
588#if defined(_WIN64) || defined(__MINGW64__)
591#if defined(OPENSSL_API_3_0)
592#define SSL_LIB "libssl-3-x64.dll"
593#define CRYPTO_LIB "libcrypto-3-x64.dll"
596#if defined(OPENSSL_API_1_1)
597#define SSL_LIB "libssl-1_1-x64.dll"
598#define CRYPTO_LIB "libcrypto-1_1-x64.dll"
601#if defined(OPENSSL_API_1_0)
602#define SSL_LIB "ssleay64.dll"
603#define CRYPTO_LIB "libeay64.dll"
610#if defined(OPENSSL_API_3_0)
611#define SSL_LIB "libssl-3.dll"
612#define CRYPTO_LIB "libcrypto-3.dll"
615#if defined(OPENSSL_API_1_1)
616#define SSL_LIB "libssl-1_1.dll"
617#define CRYPTO_LIB "libcrypto-1_1.dll"
620#if defined(OPENSSL_API_1_0)
621#define SSL_LIB "ssleay32.dll"
622#define CRYPTO_LIB "libeay32.dll"
629#define O_NONBLOCK (0)
634#define INT64_FMT "I64d"
635#define UINT64_FMT "I64u"
637#define WINCDECL __cdecl
638#define vsnprintf_impl _vsnprintf
639#define access _access
640#define mg_sleep(x) (Sleep(x))
642#define pipe(x) _pipe(x, MG_BUF_LEN, _O_BINARY)
644#define popen(x, y) (_popen(x, y))
647#define pclose(x) (_pclose(x))
649#define close(x) (_close(x))
650#define dlsym(x, y) (GetProcAddress((HINSTANCE)(x), (y)))
652#define fseeko(x, y, z) ((_lseeki64(_fileno(x), (y), (z)) == -1) ? -1 : 0)
653#define fdopen(x, y) (_fdopen((x), (y)))
654#define write(x, y, z) (_write((x), (y), (unsigned)z))
655#define read(x, y, z) (_read((x), (y), (unsigned)z))
656#define flockfile(x) ((void)pthread_mutex_lock(&global_log_file_lock))
657#define funlockfile(x) ((void)pthread_mutex_unlock(&global_log_file_lock))
658#define sleep(x) (Sleep((x)*1000))
659#define rmdir(x) (_rmdir(x))
660#if defined(_WIN64) || !defined(__MINGW32__)
662#define timegm(x) (_mkgmtime(x))
670#define fileno(x) (_fileno(x))
674 CRITICAL_SECTION
sec;
677typedef HANDLE pthread_t;
683#if !defined(__clockid_t_defined)
686#if !defined(CLOCK_MONOTONIC)
687#define CLOCK_MONOTONIC (1)
689#if !defined(CLOCK_REALTIME)
690#define CLOCK_REALTIME (2)
692#if !defined(CLOCK_THREAD)
693#define CLOCK_THREAD (3)
695#if !defined(CLOCK_PROCESS)
696#define CLOCK_PROCESS (4)
700#if defined(_MSC_VER) && (_MSC_VER >= 1900)
701#define _TIMESPEC_DEFINED
703#if !defined(_TIMESPEC_DEFINED)
710#if !defined(WIN_PTHREADS_TIME_H)
711#define MUST_IMPLEMENT_CLOCK_GETTIME
714#if defined(MUST_IMPLEMENT_CLOCK_GETTIME)
715#define clock_gettime mg_clock_gettime
724 static BOOL initialized =
FALSE;
739 li.LowPart =
ft.dwLowDateTime;
740 li.HighPart =
ft.dwHighDateTime;
741 li.QuadPart -= 116444736000000000;
742 tp->tv_sec = (time_t)(
li.QuadPart / 10000000);
743 tp->tv_nsec = (long)(
li.QuadPart % 10000000) * 100;
752 tp->tv_sec = (time_t)
d;
754 tp->tv_nsec = (long)(
d * 1.0E9);
768 li.HighPart =
t_user.dwHighDateTime;
771 li.QuadPart +=
li2.QuadPart;
772 tp->tv_sec = (time_t)(
li.QuadPart / 10000000);
773 tp->tv_nsec = (long)(
li.QuadPart % 10000000) * 100;
788 li.HighPart =
t_user.dwHighDateTime;
791 li.QuadPart +=
li2.QuadPart;
792 tp->tv_sec = (time_t)(
li.QuadPart / 10000000);
793 tp->tv_nsec = (long)(
li.QuadPart % 10000000) * 100;
838#if defined(HAVE_POLL)
839#define mg_pollfd pollfd
850#pragma comment(lib, "Ws2_32.lib")
858#define UTF8_PATH_MAX (PATH_MAX)
866#if !defined(__ZEPHYR__)
867#include <arpa/inet.h>
873#include <netinet/in.h>
874#include <netinet/tcp.h>
883#include <sys/socket.h>
885#include <sys/utsname.h>
889#if defined(USE_X_DOM_SOCKET)
894#define vsnprintf_impl vsnprintf
896#if !defined(NO_SSL_DL) && !defined(NO_SSL)
901#define SSL_LIB "libssl.dylib"
902#define CRYPTO_LIB "libcrypto.dylib"
905#define SSL_LIB "libssl.so"
907#if !defined(CRYPTO_LIB)
908#define CRYPTO_LIB "libcrypto.so"
911#if !defined(O_BINARY)
914#define closesocket(a) (close(a))
915#define mg_mkdir(conn, path, mode) (mkdir(path, mode))
916#define mg_remove(conn, x) (remove(x))
917#define mg_sleep(x) (usleep((x)*1000))
918#define mg_opendir(conn, x) (opendir(x))
919#define mg_closedir(x) (closedir(x))
920#define mg_readdir(x) (readdir(x))
922#define INVALID_SOCKET (-1)
923#define INT64_FMT PRId64
924#define UINT64_FMT PRIu64
930#if !defined(CLOCK_MONOTONIC)
931#define CLOCK_MONOTONIC CLOCK_REALTIME
945#define mg_pollfd pollfd
950#if defined(NEED_TIMEGM)
954 return (
y % 4 == 0 &&
y % 100 != 0) ||
y % 400 == 0;
960 return (
y - 1969) / 4 - (
y - 1901) / 100 + (
y - 1601) / 400;
966 static const unsigned short ydays[] = {
967 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
968 int year =
tm->tm_year + 1900;
969 int mon =
tm->tm_mon;
970 int mday =
tm->tm_mday - 1;
972 int min =
tm->tm_min;
973 int sec =
tm->tm_sec;
978 ||
hour < 0 ||
hour > 23 || min < 0 || min > 59 ||
sec < 0 ||
sec > 60)
981 time_t res =
year - 1970;
1000#define va_copy(x, y) ((x) = (y))
1007#if defined(GCC_DIAGNOSTIC)
1009#pragma GCC diagnostic push
1010#pragma GCC diagnostic ignored "-Wunused-function"
1064#if defined(GCC_DIAGNOSTIC)
1066#pragma GCC diagnostic pop
1075#if defined(GCC_DIAGNOSTIC)
1077#pragma GCC diagnostic push
1078#pragma GCC diagnostic ignored "-Wunused-function"
1080#if defined(__clang__)
1082#pragma clang diagnostic push
1083#pragma clang diagnostic ignored "-Wunused-function"
1107#elif defined(_WIN32)
1122#if defined(_WIN64) && !defined(NO_ATOMICS)
1124#elif defined(_WIN32) && !defined(NO_ATOMICS)
1126#elif defined(__GNUC__) \
1127 && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 0))) \
1128 && !defined(NO_ATOMICS)
1145#if defined(_WIN64) && !defined(NO_ATOMICS)
1147#elif defined(_WIN32) && !defined(NO_ATOMICS)
1149#elif defined(__GNUC__) \
1150 && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 0))) \
1151 && !defined(NO_ATOMICS)
1162#if defined(USE_SERVER_STATS) || defined(STOP_FLAG_NEEDS_LOCK)
1168#if defined(_WIN64) && !defined(NO_ATOMICS)
1170#elif defined(_WIN32) && !defined(NO_ATOMICS)
1172#elif defined(__GNUC__) \
1173 && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 0))) \
1174 && !defined(NO_ATOMICS)
1194#if defined(_WIN64) && !defined(NO_ATOMICS)
1196#elif defined(_WIN32) && !defined(NO_ATOMICS)
1198#elif defined(__GNUC__) \
1199 && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 0))) \
1200 && !defined(NO_ATOMICS)
1217 register ptrdiff_t
tmp = *
addr;
1219#if defined(_WIN64) && !defined(NO_ATOMICS)
1220 while (tmp <
value) {
1223#elif defined(_WIN32) && !defined(NO_ATOMICS)
1224 while (tmp <
value) {
1227#elif defined(__GNUC__) \
1228 && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 0))) \
1229 && !defined(NO_ATOMICS)
1230 while (tmp <
value) {
1248#if defined(_WIN64) && !defined(NO_ATOMICS)
1250#elif defined(_WIN32) && !defined(NO_ATOMICS)
1252#elif defined(__GNUC__) \
1253 && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 0))) \
1254 && !defined(NO_ATOMICS)
1267#if defined(GCC_DIAGNOSTIC)
1269#pragma GCC diagnostic pop
1271#if defined(__clang__)
1273#pragma clang diagnostic pop
1277#if defined(USE_SERVER_STATS)
1299#if defined(MEMORY_DEBUGGING)
1316#if defined(MEMORY_DEBUGGING)
1318 "MEM: %p %5lu alloc %7lu %4lu --- %s:%u\n",
1320 (
unsigned long)
size,
1321 (
unsigned long)
mstat->totalMemUsed,
1322 (
unsigned long)
mstat->blockCount,
1351#if defined(MEMORY_DEBUGGING)
1366#if defined(MEMORY_DEBUGGING)
1368 "MEM: %p %5lu free %7lu %4lu --- %s:%u\n",
1370 (
unsigned long)
size,
1371 (
unsigned long)
mstat->totalMemUsed,
1372 (
unsigned long)
mstat->blockCount,
1393#if defined(MEMORY_DEBUGGING)
1411#if defined(MEMORY_DEBUGGING)
1413 "MEM: %p %5lu r-free %7lu %4lu --- %s:%u\n",
1416 (
unsigned long)
mstat->totalMemUsed,
1417 (
unsigned long)
mstat->blockCount,
1424#if defined(MEMORY_DEBUGGING)
1426 "MEM: %p %5lu r-alloc %7lu %4lu --- %s:%u\n",
1429 (
unsigned long)
mstat->totalMemUsed,
1430 (
unsigned long)
mstat->blockCount,
1438#if defined(MEMORY_DEBUGGING)
1457#define mg_malloc(a) mg_malloc_ex(a, NULL, __FILE__, __LINE__)
1458#define mg_calloc(a, b) mg_calloc_ex(a, b, NULL, __FILE__, __LINE__)
1459#define mg_realloc(a, b) mg_realloc_ex(a, b, NULL, __FILE__, __LINE__)
1460#define mg_free(a) mg_free_ex(a, __FILE__, __LINE__)
1462#define mg_malloc_ctx(a, c) mg_malloc_ex(a, c, __FILE__, __LINE__)
1463#define mg_calloc_ctx(a, b, c) mg_calloc_ex(a, b, c, __FILE__, __LINE__)
1464#define mg_realloc_ctx(a, b, c) mg_realloc_ex(a, b, c, __FILE__, __LINE__)
1494#define mg_malloc_ctx(a, c) mg_malloc(a)
1495#define mg_calloc_ctx(a, b, c) mg_calloc(a, b)
1496#define mg_realloc_ctx(a, b, c) mg_realloc(a, b)
1497#define mg_free_ctx(a, c) mg_free(a)
1530#if defined(snprintf)
1533#if defined(vsnprintf)
1536#define malloc DO_NOT_USE_THIS_FUNCTION__USE_mg_malloc
1537#define calloc DO_NOT_USE_THIS_FUNCTION__USE_mg_calloc
1538#define realloc DO_NOT_USE_THIS_FUNCTION__USE_mg_realloc
1539#define free DO_NOT_USE_THIS_FUNCTION__USE_mg_free
1540#define snprintf DO_NOT_USE_THIS_FUNCTION__USE_mg_snprintf
1544#define vsnprintf DO_NOT_USE_THIS_FUNCTION__USE_mg_vsnprintf
1552#if defined(OPENSSL_API_1_0) || defined(OPENSSL_API_1_1) \
1553 || defined(OPENSSL_API_3_0)
1556#if !defined(OPENSSL_API_1_0) && !defined(OPENSSL_API_1_1) \
1557 && !defined(OPENSSL_API_3_0) && !defined(USE_MBEDTLS)
1558#error "Please define OPENSSL_API_1_0 or OPENSSL_API_1_1"
1560#if defined(OPENSSL_API_1_0) && defined(OPENSSL_API_1_1) \
1561 && defined(OPENSSL_API_3_0)
1562#error "Multiple OPENSSL_API versions defined"
1564#if (defined(OPENSSL_API_1_0) || defined(OPENSSL_API_1_1) \
1565 || defined(OPENSSL_API_3_0)) \
1566 && defined(USE_MBEDTLS)
1567#error "Multiple SSL libraries defined"
1575#if defined(MG_LEGACY_INTERFACE)
1576#define MG_ALLOW_USING_GET_REQUEST_INFO_FOR_RESPONSE
1588#if defined(MG_ALLOW_USING_GET_REQUEST_INFO_FOR_RESPONSE)
1594#if defined(GCC_DIAGNOSTIC)
1596#pragma GCC diagnostic push
1597#pragma GCC diagnostic ignored "-Wunused-function"
1599#if defined(__clang__)
1601#pragma clang diagnostic push
1602#pragma clang diagnostic ignored "-Wunused-function"
1624#if defined(__clang__)
1625#pragma clang diagnostic push
1626#pragma clang diagnostic ignored "-Wunreachable-code"
1634 if (
sizeof(pthread_t) >
sizeof(
unsigned long)) {
1643 tls->is_master = -2;
1647 return tls->thread_idx;
1652 unsigned long ret = 0;
1658#if defined(__clang__)
1659#pragma clang diagnostic pop
1672 return (((uint64_t)
tsnow.tv_sec) * 1000000000) + (uint64_t)
tsnow.tv_nsec;
1676#if defined(GCC_DIAGNOSTIC)
1678#pragma GCC diagnostic pop
1680#if defined(__clang__)
1682#pragma clang diagnostic pop
1686#if defined(NEED_DEBUG_TRACE_FUNC)
1700 "*** %lu.%09lu %lu %s:%u: ",
1701 (
unsigned long)
tsnow.tv_sec,
1702 (
unsigned long)
tsnow.tv_nsec,
1716#define MD5_STATIC static
1720#if defined(NO_SOCKLEN_T)
1724#define IP_ADDR_STR_LEN (50)
1726#if !defined(MSG_NOSIGNAL)
1727#define MSG_NOSIGNAL (0)
1732#if defined(USE_MBEDTLS)
1734#include "mod_mbedtls.inl"
1736#elif defined(NO_SSL)
1741#elif defined(NO_SSL_DL)
1743#include <openssl/bn.h>
1744#include <openssl/conf.h>
1745#include <openssl/crypto.h>
1746#include <openssl/dh.h>
1747#include <openssl/engine.h>
1748#include <openssl/err.h>
1749#include <openssl/opensslv.h>
1750#include <openssl/pem.h>
1751#include <openssl/ssl.h>
1752#include <openssl/tls1.h>
1753#include <openssl/x509.h>
1755#if defined(WOLFSSL_VERSION)
1758#include "wolfssl_extras.inl"
1761#if defined(OPENSSL_IS_BORINGSSL)
1772#define CONF_modules_unload(a) ((void)0)
1773#define ENGINE_cleanup() ((void)0)
1777#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
1778#if !defined(OPENSSL_API_3_0)
1779#define OPENSSL_API_3_0
1781#define OPENSSL_REMOVE_THREAD_STATE()
1783#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
1784#if !defined(OPENSSL_API_1_1)
1785#define OPENSSL_API_1_1
1787#define OPENSSL_REMOVE_THREAD_STATE()
1789#if !defined(OPENSSL_API_1_0)
1790#define OPENSSL_API_1_0
1792#define OPENSSL_REMOVE_THREAD_STATE() ERR_remove_thread_state(NULL)
1806#if !defined(NO_CACHING)
1827#if defined(USE_IPV6)
1830#if defined(USE_X_DOM_SOCKET)
1835#if defined(USE_X_DOM_SOCKET)
1836static unsigned short
1840 return s->
sin.sin_port;
1841#if defined(USE_IPV6)
1843 return s->sin6.sin6_port;
1848#if defined(USE_IPV6)
1849#define USA_IN_PORT_UNSAFE(s) \
1850 (((s)->sa.sa_family == AF_INET6) ? (s)->sin6.sin6_port : (s)->sin.sin_port)
1852#define USA_IN_PORT_UNSAFE(s) ((s)->sin.sin_port)
1883#define STRUCT_FILE_INITIALIZER \
1885 {(uint64_t)0, (time_t)0, 0, 0, 0}, \
1921#if defined(__linux__)
1931#if defined(USE_WEBSOCKET)
1941#if defined(USE_HTTP2)
1955#if defined(USE_TIMERS)
1963#if defined(USE_TIMERS)
1967#if defined(USE_4_CGI)
1972#if defined(USE_TIMERS)
1980#if defined(USE_TIMERS)
2013#if defined(MG_EXPERIMENTAL_INTERFACES)
2017#if defined(USE_DUKTAPE)
2021#if defined(USE_WEBSOCKET)
2024#if defined(USE_LUA) && defined(USE_WEBSOCKET)
2033#if !defined(NO_CACHING)
2061#if defined(__linux__)
2071#if defined(USE_WEBSOCKET)
2081#if defined(USE_HTTP2)
2095#if defined(USE_TIMERS)
2103#if defined(USE_TIMERS)
2107#if defined(USE_4_CGI)
2112#if defined(USE_TIMERS)
2120#if defined(USE_TIMERS)
2135 "index.xhtml,index.html,index.htm,"
2136 "index.lp,index.lsp,index.lua,index.cgi,"
2137 "index.shtml,index.php"},
2139 "index.xhtml,index.html,index.htm,index.cgi,index.shtml,index.php"},
2167#if defined(MG_EXPERIMENTAL_INTERFACES)
2171#if defined(USE_DUKTAPE)
2177#if defined(USE_WEBSOCKET)
2180#if defined(USE_LUA) && defined(USE_WEBSOCKET)
2188#if !defined(NO_CACHING)
2205 "config_options and enum not sync");
2262#if defined(USE_LUA) && defined(USE_WEBSOCKET)
2275#if defined(STOP_FLAG_NEEDS_LOCK)
2305#define STOP_FLAG_IS_ZERO(f) ((*(f)) == 0)
2306#define STOP_FLAG_IS_TWO(f) ((*(f)) == 2)
2307#define STOP_FLAG_ASSIGN(f, v) ((*(f)) = (v))
2330#if defined(USE_SERVER_STATS)
2350#if defined(ALTERNATIVE_QUEUE)
2362#if defined(USE_SERVER_STATS)
2370#if defined(USE_SERVER_STATS)
2379#if defined(USE_TIMERS)
2410#if defined(USE_SERVER_STATS)
2417 return &(ctx->ctx_memory);
2436#if defined(USE_HTTP2)
2437#if !defined(HTTP2_DYN_TABLE_SIZE)
2438#define HTTP2_DYN_TABLE_SIZE (256)
2454#if defined(USE_HTTP2)
2464#if defined(USE_SERVER_STATS)
2474#if defined(USE_SERVER_STATS)
2503#if defined(USE_WEBSOCKET)
2506#if defined(USE_ZLIB) && defined(USE_WEBSOCKET) \
2507 && defined(MG_EXPERIMENTAL_INTERFACES)
2531#if defined(USE_LUA) && defined(USE_WEBSOCKET)
2548#define mg_cry_internal(conn, fmt, ...) \
2549 mg_cry_internal_wrap(conn, NULL, __func__, __LINE__, fmt, __VA_ARGS__)
2551#define mg_cry_ctx_internal(ctx, fmt, ...) \
2552 mg_cry_internal_wrap(NULL, ctx, __func__, __LINE__, fmt, __VA_ARGS__)
2562#if !defined(NO_THREAD_NAME)
2563#if defined(_WIN32) && defined(_MSC_VER)
2567#pragma pack(push, 8)
2576#elif defined(__linux__)
2578#include <sys/prctl.h>
2579#include <sys/sendfile.h>
2580#if defined(ALTERNATIVE_QUEUE)
2581#include <sys/eventfd.h>
2585#if defined(ALTERNATIVE_QUEUE)
2623 if (s !=
sizeof(
u)) {
2645 if (s !=
sizeof(
u)) {
2674#if !defined(__linux__) && !defined(_WIN32) && defined(ALTERNATIVE_QUEUE)
2677 pthread_mutex_t mutex;
2712 while (!
ev->signaled) {
2753#if defined(_MSC_VER)
2757 info.dwType = 0x1000;
2759 info.dwThreadID = ~0U;
2768#elif defined(__MINGW32__)
2771#elif defined(_GNU_SOURCE) && defined(__GLIBC__) \
2772 && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 12)))
2774#if defined(__MACH__)
2780#elif defined(__linux__)
2805#define MG_FOPEN_MODE_NONE (0)
2808#define MG_FOPEN_MODE_READ (1)
2811#define MG_FOPEN_MODE_WRITE (2)
2814#define MG_FOPEN_MODE_APPEND (4)
2828#if !defined(NO_FILESYSTEMS)
2838 const uint8_t *
c = (
const uint8_t *)path;
2841 if ((
c ==
NULL) || (
c[0] == 0)) {
2852 if ((*
c ==
'>') || (*
c ==
'<') || (*
c ==
'|')) {
2856 if ((*
c ==
'*') || (*
c ==
'?')) {
2969 for (; *
src !=
'\0' &&
n > 1;
n--) {
2979 return tolower((
unsigned char)*s);
2991 }
while (
diff == 0 &&
s1[-1] !=
'\0' && --
len > 0);
3005 }
while (
diff == 0 &&
s1[-1] !=
'\0');
3075#if defined(__clang__)
3076#pragma clang diagnostic push
3077#pragma clang diagnostic ignored "-Wformat-nonliteral"
3083 ok = (
n >= 0) && ((
size_t)
n < buflen);
3085#if defined(__clang__)
3086#pragma clang diagnostic pop
3098 "truncating vsnprintf buffer: [%.*s]",
3099 (
int)((buflen > 200) ? 200 : (buflen - 1)),
3101 n = (
int)buflen - 1;
3143 }
else if (!ctx || ctx->
dd.config[i] ==
NULL) {
3146 return ctx->
dd.config[i];
3150#define mg_get_option DO_NOT_USE_THIS_FUNCTION_INTERNALLY__access_directly
3184 return tls->user_ptr;
3239 ports[cnt].protocol = 1;
3243 ports[cnt].protocol = 3;
3252#if defined(USE_X_DOM_SOCKET) && !defined(UNIX_DOMAIN_SOCKET_SERVER_NAME)
3253#define UNIX_DOMAIN_SOCKET_SERVER_NAME "*"
3274#if defined(USE_IPV6)
3285#if defined(USE_X_DOM_SOCKET)
3309#if !defined(REENTRANT_TIME)
3338#if defined(MG_EXTERNAL_FUNCTION_mg_cry_internal_impl)
3344#include "external_mg_cry_internal_impl.inl"
3345#elif !defined(NO_FILESYSTEMS)
3363#if defined(GCC_DIAGNOSTIC)
3364#pragma GCC diagnostic push
3365#pragma GCC diagnostic ignored "-Wformat-nonliteral"
3370#if defined(GCC_DIAGNOSTIC)
3371#pragma GCC diagnostic pop
3374 buf[
sizeof(buf) - 1] = 0;
3387 || (conn->
phys_ctx->callbacks.log_message(conn, buf) == 0)) {
3401 if (
fi.access.fp !=
NULL) {
3407 "[%010lu] [error] [client %s] ",
3430#error Must either enable filesystems or provide a custom mg_cry_internal_impl implementation
3442 fc->dom_ctx = &(ctx->
dd);
3477#define mg_cry DO_NOT_USE_THIS_FUNCTION__USE_mg_cry_internal
3493#if defined(MG_ALLOW_USING_GET_REQUEST_INFO_FOR_RESPONSE)
3508 ((
struct mg_connection *)conn)->request_info.local_uri_raw =
3543#if defined(__clang__)
3544#pragma clang diagnostic push
3545#pragma clang diagnostic ignored "-Wunreachable-code"
3556 ? (ri->
is_ssl ?
"wss" :
"ws")
3557 : (ri->
is_ssl ?
"https" :
"http"));
3561#if defined(__clang__)
3562#pragma clang diagnostic pop
3575 if ((buflen < 1) || (buf == 0) || (conn == 0)) {
3594#if defined(USE_X_DOM_SOCKET)
3632#if defined(USE_IPV6)
3740#if defined(GCC_DIAGNOSTIC)
3742#pragma GCC diagnostic push
3743#pragma GCC diagnostic ignored "-Wsign-conversion"
3748#if defined(GCC_DIAGNOSTIC)
3749#pragma GCC diagnostic pop
3768 for (i = 0; i <
num_hdr; i++) {
3770 return hdr[i].value;
3778#if defined(USE_WEBSOCKET)
3851 if (val ==
NULL || list ==
NULL || *list ==
'\0') {
3857 while (*list ==
' ' || *list ==
'\t')
3863 val->
len = ((size_t)(list - val->
ptr));
3868 val->
len = ((size_t)(list - val->
ptr));
3873 while (end >= 0 && ((val->
ptr[end] ==
' ') || (val->
ptr[end] ==
'\t')))
3875 val->
len = (size_t)(end) + (size_t)(1);
3877 if (val->
len == 0) {
3925 ptrdiff_t i,
j,
len, res;
3929 return (res > 0) ? res
3936 for (i = 0,
j = 0; (i < (ptrdiff_t)
pattern_len); i++,
j++) {
3937 if ((pattern[i] ==
'?') && (str[
j] !=
'\0')) {
3939 }
else if (pattern[i] ==
'$') {
3940 return (str[
j] ==
'\0') ?
j : -1;
3941 }
else if (pattern[i] ==
'*') {
3943 if (pattern[i] ==
'*') {
3956 }
while (res == -1 &&
len-- > 0);
3957 return (res == -1) ? -1 :
j + res +
len;
3962 return (ptrdiff_t)
j;
3969 if (pattern ==
NULL) {
3982 const char *http_version;
4008 if (http_version && (0 ==
strcmp(http_version,
"1.1"))) {
4021 if (!conn || !conn->
dom_ctx) {
4032 if (!conn || !conn->
dom_ctx) {
4057 "no-cache, no-store, "
4058 "must-revalidate, private, max-age=0",
4072#if !defined(NO_CACHING)
4107 conn,
NULL, val,
sizeof(val),
"max-age=%lu", (
unsigned long)
max_age);
4138 if (header && header[0]) {
4144#if !defined(NO_FILESYSTEMS)
4163 return "Switching Protocols";
4165 return "Processing";
4175 return "Non-Authoritative Information";
4177 return "No Content";
4179 return "Reset Content";
4181 return "Partial Content";
4183 return "Multi-Status";
4186 return "Already Reported";
4193 return "Multiple Choices";
4195 return "Moved Permanently";
4201 return "Not Modified";
4205 return "Temporary Redirect";
4207 return "Permanent Redirect";
4211 return "Bad Request";
4213 return "Unauthorized";
4215 return "Payment Required";
4221 return "Method Not Allowed";
4223 return "Not Acceptable";
4225 return "Proxy Authentication Required";
4227 return "Request Time-out";
4233 return "Length Required";
4235 return "Precondition Failed";
4237 return "Request Entity Too Large";
4239 return "Request-URI Too Large";
4241 return "Unsupported Media Type";
4243 return "Requested range not satisfiable";
4246 return "Expectation Failed";
4249 return "Misdirected Request";
4251 return "Unproccessable entity";
4256 return "Failed Dependency";
4260 return "Upgrade Required";
4263 return "Precondition Required";
4265 return "Too Many Requests";
4268 return "Request Header Fields Too Large";
4271 return "Unavailable For Legal Reasons";
4276 return "Internal Server Error";
4278 return "Not Implemented";
4280 return "Bad Gateway";
4282 return "Service Unavailable";
4284 return "Gateway Time-out";
4286 return "HTTP Version not supported";
4288 return "Variant Also Negotiates";
4290 return "Insufficient Storage";
4293 return "Loop Detected";
4296 return "Not Extended";
4298 return "Network Authentication Required";
4304 return "I am a teapot";
4306 return "Authentication Timeout";
4308 return "Enhance Your Calm";
4310 return "Login Timeout";
4312 return "Bandwidth Limit Exceeded";
4318 "Unknown HTTP response code: %u",
4325 return "Information";
4333 return "Redirection";
4337 return "Client Error";
4341 return "Server Error";
4360#if !defined(NO_FILESYSTEMS)
4377 has_body = ((status > 199) && (status != 204) && (status != 304));
4408 "Recursion when handling error %u - fall back to default",
4410#if !defined(NO_FILESYSTEMS)
4470 (i < 32) && (tstr[i] != 0) && (tstr[i] !=
',');
4493 tstr =
strchr(tstr + i,
'.');
4515 "text/plain; charset=utf-8",
4524 mg_printf(conn,
"Error %d: %s\n", status, status_text);
4553 long long content_length)
4564 if (content_length < 0) {
4578 (uint64_t)content_length);
4609 size_t content_len = 0;
4610#if defined(MG_SEND_REDIRECT_BODY)
4635#if defined(MG_SEND_REDIRECT_BODY)
4663 "<html><head>%s</head><body><a href=\"%s\">%s</a></body></html>",
4673 "HTTP/1.1 %i %s\r\n"
4675 "Content-Length: %u\r\n"
4676 "Connection: %s\r\n\r\n",
4680 (
unsigned int)content_len,
4683#if defined(MG_SEND_REDIRECT_BODY)
4693 return (
ret > 0) ?
ret : -1;
4700#if defined(GCC_DIAGNOSTIC)
4702#pragma GCC diagnostic push
4703#pragma GCC diagnostic ignored "-Wunused-function"
4747 cv->waiting_thread =
NULL;
4755 pthread_mutex_t *mutex,
4767 ptls = &cv->waiting_thread;
4768 for (; *
ptls !=
NULL;
ptls = &(*ptls)->next_waiting_thread)
4770 tls->next_waiting_thread =
NULL;
4793 ptls = &cv->waiting_thread;
4794 for (; *
ptls !=
NULL;
ptls = &(*ptls)->next_waiting_thread) {
4796 *
ptls =
tls->next_waiting_thread;
4830 if (cv->waiting_thread) {
4831 wkup = cv->waiting_thread->pthread_cond_helper_mutex;
4832 cv->waiting_thread = cv->waiting_thread->next_waiting_thread;
4834 ok = SetEvent(
wkup);
4848 while (cv->waiting_thread) {
4870#if defined(ALTERNATIVE_QUEUE)
4892 return (
int)SetEvent((HANDLE)
eventhdl);
4905#if defined(GCC_DIAGNOSTIC)
4907#pragma GCC diagnostic pop
4917 for (i = 0; path[i] !=
'\0'; i++) {
4918 if (path[i] ==
'/') {
4924 if ((i > 0) && (path[i] ==
'\')) {
4925 while ((path[i + 1] ==
'\') || (path[i + 1] ==
'/')) {
4926 (void)
memmove(path + i + 1, path + i + 2,
strlen(path + i + 1));
4940 - ((*
s2 >=
L'A') && (*
s2 <=
L'Z') ? (*
s2 -
L'A' +
L'a') : *
s2);
4943 }
while ((
diff == 0) && (
s1[-1] != L
'\0'));
5011#if !defined(NO_FILESYSTEMS)
5037 if ((
len > 0) && (path[
len - 1] !=
' ') && (path[
len - 1] !=
'.')
5040 filep->last_modified =
5042 info.ftLastWriteTime.dwHighDateTime);
5049 info.ftCreationTime.dwHighDateTime);
5084#if defined(GCC_DIAGNOSTIC)
5086#pragma GCC diagnostic push
5087#pragma GCC diagnostic ignored "-Wunused-function"
5111 dir->result.d_name[0] =
'\0';
5153 dir->info.cFileName,
5176#if !defined(HAVE_POLL)
5205 for (i = 0; i <
n; i++) {
5224 for (i = 0; i <
n; i++) {
5249#if defined(GCC_DIAGNOSTIC)
5251#pragma GCC diagnostic pop
5270#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
5329#if !defined(NO_SSL_DL) && !defined(NO_SSL)
5333#if defined(GCC_DIAGNOSTIC)
5335#pragma GCC diagnostic push
5336#pragma GCC diagnostic ignored "-Wunused-function"
5367#if defined(GCC_DIAGNOSTIC)
5369#pragma GCC diagnostic pop
5388#if !defined(WNOHANG)
5394waitpid(pid_t pid,
int *status,
int flags)
5420 while ((
e > s) &&
isspace((
unsigned char)
e[-1])) {
5501 buf[0] = buf[1] =
'\0';
5508 pi.hProcess = (pid_t)-1;
5518 buf[
sizeof(buf) - 1] =
'\0';
5521 if ((buf[0] ==
'#') && (buf[1] ==
'!')) {
5538 "\"%s\" %s \"%s\%s\"",
5565 pi.hProcess = (pid_t)-1;
5583 pi.hProcess = (pid_t)-1;
5591 if (pi.hThread !=
NULL) {
5595 return (pid_t)pi.hProcess;
5619#if !defined(NO_FILESYSTEMS)
5635 if (0 == stat(path, &
st)) {
5636 filep->size = (uint64_t)(
st.st_size);
5637 filep->last_modified =
st.st_mtime;
5652#if defined(__ZEPHYR__)
5661 "%s: fcntl(F_SETFD FD_CLOEXEC) failed: %s",
5680#if defined(__ZEPHYR__)
5682#elif defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
5707#if defined(__ZEPHYR__)
5711#elif defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
5754 if ((pid =
fork()) == -1) {
5757 }
else if (pid != 0) {
5768 }
else if (
dup2(
fdin[0], 0) == -1) {
5770 "%s: dup2(%d, 0): %s",
5776 "%s: dup2(%d, 1): %s",
5782 "%s: dup2(%d, 2): %s",
5792 (void)close(
fdin[0]);
5793 (void)close(
fdout[1]);
5794 (void)close(
fderr[1]);
5797 (void)close(
fdin[1]);
5798 (void)close(
fdout[0]);
5799 (void)close(
fderr[0]);
5806 memset(&sa, 0,
sizeof(sa));
5815 "%s: execle(%s): %s",
5831 "%s: execle(%s %s): %s",
5882 static uint64_t
lfsr = 0;
5883 static uint64_t
lcg = 0;
5896 lcg =
lcg * 6364136223846793005LL + 1442695040888963407LL;
5986 typedef size_t len_t;
5999#if defined(NO_SSL) && !defined(USE_MBEDTLS)
6009#if defined(USE_MBEDTLS)
6025#elif !defined(NO_SSL)
6049 n = (
int)fwrite(buf, 1, (
size_t)
len, fp);
6058 err = (
n < 0) ?
ERRNO : 0;
6080 if ((
n > 0) || ((
n == 0) && (
len == 0))) {
6166 }
else if (
n == 0) {
6196 typedef size_t len_t;
6217#if defined(USE_MBEDTLS)
6218 }
else if (conn->
ssl !=
NULL) {
6272#elif !defined(NO_SSL)
6273 }
else if (conn->
ssl !=
NULL) {
6437 }
else if (
n == -1) {
6446 }
else if (
n == 0) {
6463 while (
mg_read(conn, buf,
sizeof(buf)) > 0)
6485 if (content_len < 0) {
6539#if defined(USE_SERVER_STATS)
6541 conn->conn_state = 4;
6547#if defined(USE_SERVER_STATS)
6548 conn->conn_state = 5;
6568#if defined(USE_HTTP2)
6570#error "HTTP2 requires ALPN, APLN requires SSL/TLS"
6573#include "mod_http2.inl"
6577 if (conn->protocol_type == PROTOCOL_TYPE_HTTP2) { \
6578 http2_must_use_http1(conn); \
6630 || (
x[1] !=
'\n')) {
6644 for (i = 0; i < (
sizeof(lenbuf) - 1); i++) {
6649 if ((i > 0) && (lenbuf[i] ==
'\r')
6650 && (lenbuf[i - 1] !=
'\r')) {
6653 if ((i > 1) && (lenbuf[i] ==
'\n')
6654 && (lenbuf[i - 1] ==
'\r')) {
6663 if (!
isxdigit((
unsigned char)lenbuf[i])) {
6669 if ((end ==
NULL) || (*end !=
'\r')) {
6678 && (lenbuf[0] ==
'\r') && (lenbuf[1] ==
'\n')) {
6710#if defined(USE_HTTP2)
6722 if (allowed > (
int)
len) {
6733 if (
total == allowed) {
6735 buf = (
const char *)buf +
total;
6756 buf = (
const char *)buf +
n;
6813#if defined(GCC_DIAGNOSTIC)
6816#pragma GCC diagnostic push
6817#pragma GCC diagnostic ignored "-Wformat-nonliteral"
6844 (*buf)[
size - 1] = 0;
6912#if defined(GCC_DIAGNOSTIC)
6914#pragma GCC diagnostic pop
6958#define HEXTOI(x) (isdigit(x) ? (x - '0') : (x - 'W'))
7009 const char *
p, *
e, *s;
7020 e =
data + data_len;
7032 s = (
const char *)
memchr(
p,
'&', (
size_t)(
e -
p));
7096 while ((*
data ==
' ') || (*
data ==
'\t')) {
7108 while ((*
b != 0) && (*
b !=
'&') && (*
b !=
'=')) {
7115 }
else if (*
b ==
'&') {
7143 for (i = 0; i < num; i++) {
7164 const char *s, *
p, *end;
7189 if ((*s ==
'"') && (
p[-1] ==
'"') && (
p > s + 1)) {
7207#if defined(USE_WEBSOCKET) || defined(USE_LUA)
7211 static const char *
b64 =
7212 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
7215 for (i =
j = 0; i <
src_len; i += 3) {
7221 dst[
j++] =
b64[((
a & 3) << 4) | (
b >> 4)];
7223 dst[
j++] =
b64[(
b & 15) << 2 | (
c >> 6)];
7229 while (
j % 4 != 0) {
7245 return letter -
'a' + 26;
7248 return letter -
'0' + 52;
7267 unsigned char a,
b,
c,
d;
7271 for (i = 0; i <
src_len; i += 4) {
7292 dst[(*dst_len)++] = (
a << 2) + (
b >> 4);
7294 dst[(*dst_len)++] = (
b << 4) + (
c >> 2);
7296 dst[(*dst_len)++] = (
c << 6) +
d;
7318#if !defined(NO_FILES)
7336#if defined(USE_DUKTAPE)
7403 while ((
n > 0) && (path[
n - 1] ==
'/')) {
7451#if !defined(NO_FILES)
7459#if !defined(NO_CGI) || defined(USE_LUA) || defined(USE_DUKTAPE)
7480#if defined(USE_WEBSOCKET)
7482#if !defined(NO_FILES)
7499#if !defined(NO_FILES)
7636#if !defined(NO_CGI) || defined(USE_LUA) || defined(USE_DUKTAPE)
7691 DEBUG_TRACE(
"Substitute script %s serving path %s",
7738#if !defined(NO_FILES)
7759 for (i = 0; i < buflen; i++) {
7761 const unsigned char c = (
unsigned char)buf[i];
7763 if ((
c < 128) && ((char)
c !=
'\r') && ((char)
c !=
'\n')
7769 if (i < buflen - 1) {
7770 if ((buf[i] ==
'\n') && (buf[i + 1] ==
'\n')) {
7777 if (i < buflen - 3) {
7778 if ((buf[i] ==
'\r') && (buf[i + 1] ==
'\n') && (buf[i + 2] ==
'\r')
7779 && (buf[i + 3] ==
'\n')) {
7790#if !defined(NO_CACHING)
7813 time_t
result = (time_t)0;
7817 "%d/%3s/%d %d:%d:%d",
7826 "%d %3s %d %d:%d:%d",
7835 "%*3s, %d %3s %d %d:%d:%d",
7844 "%d-%3s-%d %d:%d:%d",
7855 tm.tm_year =
year - 1900;
7913 }
else if (!
strncmp(in,
"./", 2)) {
7922 else if (!
strncmp(in,
"/./", 3)) {
7924 }
else if (!
strcmp(in,
"/.")) {
7935 else if (!
strncmp(in,
"/../", 4)) {
7943 }
else if (!
strcmp(in,
"/..")) {
7972 }
while ((*in != 0) && (*in !=
'/'));
8010 }
else if (*in ==
'/') {
8015 }
while (*in ==
'/');
8025static const struct {
8033 {
".bin", 4,
"application/octet-stream"},
8034 {
".deb", 4,
"application/octet-stream"},
8035 {
".dmg", 4,
"application/octet-stream"},
8036 {
".dll", 4,
"application/octet-stream"},
8037 {
".doc", 4,
"application/msword"},
8038 {
".eps", 4,
"application/postscript"},
8039 {
".exe", 4,
"application/octet-stream"},
8040 {
".iso", 4,
"application/octet-stream"},
8041 {
".js", 3,
"application/javascript"},
8042 {
".json", 5,
"application/json"},
8043 {
".msi", 4,
"application/octet-stream"},
8044 {
".pdf", 4,
"application/pdf"},
8045 {
".ps", 3,
"application/postscript"},
8046 {
".rtf", 4,
"application/rtf"},
8047 {
".xhtml", 6,
"application/xhtml+xml"},
8048 {
".xsl", 4,
"application/xml"},
8049 {
".xslt", 5,
"application/xml"},
8052 {
".ttf", 4,
"application/font-sfnt"},
8053 {
".cff", 4,
"application/font-sfnt"},
8054 {
".otf", 4,
"application/font-sfnt"},
8055 {
".aat", 4,
"application/font-sfnt"},
8056 {
".sil", 4,
"application/font-sfnt"},
8057 {
".pfr", 4,
"application/font-tdpfr"},
8058 {
".woff", 5,
"application/font-woff"},
8059 {
".woff2", 6,
"application/font-woff2"},
8062 {
".mp3", 4,
"audio/mpeg"},
8063 {
".oga", 4,
"audio/ogg"},
8064 {
".ogg", 4,
"audio/ogg"},
8067 {
".gif", 4,
"image/gif"},
8068 {
".ief", 4,
"image/ief"},
8069 {
".jpeg", 5,
"image/jpeg"},
8070 {
".jpg", 4,
"image/jpeg"},
8071 {
".jpm", 4,
"image/jpm"},
8072 {
".jpx", 4,
"image/jpx"},
8073 {
".png", 4,
"image/png"},
8074 {
".svg", 4,
"image/svg+xml"},
8075 {
".tif", 4,
"image/tiff"},
8076 {
".tiff", 5,
"image/tiff"},
8079 {
".wrl", 4,
"model/vrml"},
8082 {
".css", 4,
"text/css"},
8083 {
".csv", 4,
"text/csv"},
8084 {
".htm", 4,
"text/html"},
8085 {
".html", 5,
"text/html"},
8086 {
".sgm", 4,
"text/sgml"},
8087 {
".shtm", 5,
"text/html"},
8088 {
".shtml", 6,
"text/html"},
8089 {
".txt", 4,
"text/plain"},
8090 {
".xml", 4,
"text/xml"},
8093 {
".mov", 4,
"video/quicktime"},
8094 {
".mp4", 4,
"video/mp4"},
8095 {
".mpeg", 5,
"video/mpeg"},
8096 {
".mpg", 4,
"video/mpeg"},
8097 {
".ogv", 4,
"video/ogg"},
8098 {
".qt", 3,
"video/quicktime"},
8103 {
".arj", 4,
"application/x-arj-compressed"},
8104 {
".gz", 3,
"application/x-gunzip"},
8105 {
".rar", 4,
"application/x-arj-compressed"},
8106 {
".swf", 4,
"application/x-shockwave-flash"},
8107 {
".tar", 4,
"application/x-tar"},
8108 {
".tgz", 4,
"application/x-tar-gz"},
8109 {
".torrent", 8,
"application/x-bittorrent"},
8110 {
".ppt", 4,
"application/x-mspowerpoint"},
8111 {
".xls", 4,
"application/x-msexcel"},
8112 {
".zip", 4,
"application/x-zip-compressed"},
8116 {
".flac", 5,
"audio/flac"},
8117 {
".aif", 4,
"audio/x-aif"},
8118 {
".m3u", 4,
"audio/x-mpegurl"},
8119 {
".mid", 4,
"audio/x-midi"},
8120 {
".ra", 3,
"audio/x-pn-realaudio"},
8121 {
".ram", 4,
"audio/x-pn-realaudio"},
8122 {
".wav", 4,
"audio/x-wav"},
8123 {
".bmp", 4,
"image/bmp"},
8124 {
".ico", 4,
"image/x-icon"},
8125 {
".pct", 4,
"image/x-pct"},
8126 {
".pict", 5,
"image/pict"},
8127 {
".rgb", 4,
"image/x-rgb"},
8128 {
".webm", 5,
"video/webm"},
8129 {
".asf", 4,
"video/x-ms-asf"},
8130 {
".avi", 4,
"video/x-msvideo"},
8131 {
".m4v", 4,
"video/x-m4v"},
8151 return "text/plain";
8161 const char *list, *
ext;
8195 static const char *hex =
"0123456789abcdef";
8197 for (;
len--;
p++) {
8198 *
to++ = hex[
p[0] >> 4];
8199 *
to++ = hex[
p[0] & 0x0f];
8238 const char *response)
8244 || (qop ==
NULL) || (response ==
NULL)) {
8249 if (
strlen(response) != 32) {
8272#if !defined(NO_FILESYSTEMS)
8301 &&
filep->stat.is_directory) {
8382 while (
isspace((
unsigned char)*s)) {
8398 if (*
name ==
'\0') {
8419#if !defined(NO_NONCE_CHECK)
8426 if ((s ==
NULL) || (*s != 0)) {
8431 nonce ^= conn->
dom_ctx->auth_nonce_mask;
8441 if (nonce < (uint64_t)conn->
phys_ctx->start_time) {
8448 if (nonce >= ((uint64_t)conn->
phys_ctx->start_time
8449 + conn->
dom_ctx->nonce_count)) {
8488#define INITIAL_DEPTH 9
8489#if INITIAL_DEPTH <= 0
8490#error Bad INITIAL_DEPTH for recursion, set to at least 1
8493#if !defined(NO_FILESYSTEMS)
8560 "%s: cannot open authorization file: %s",
8569 "%s: syntax error in authorization file: %s",
8578 "%s: syntax error in authorization file: %s",
8589 "%s: syntax error in authorization file: %s",
8671#if !defined(NO_FILESYSTEMS)
8678 if (!conn || !conn->
dom_ctx) {
8696 "%s: cannot open %s: %s",
8727 uint64_t nonce = (uint64_t)(conn->
phys_ctx->start_time);
8736 nonce += conn->
dom_ctx->nonce_count;
8740 nonce ^= conn->
dom_ctx->auth_nonce_mask;
8754 "Digest qop=\"auth\", realm=\"%s\", "
8784#if !defined(NO_FILES)
8843 for (i = 0; ((i < 255) && (user[i] != 0)); i++) {
8844 if (
iscntrl((
unsigned char)user[i])) {
8851 for (i = 0; ((i < 255) && (domain[i] != 0)); i++) {
8852 if (
iscntrl((
unsigned char)domain[i])) {
8885 if (
sscanf(
line,
"%255[^:]:%255[^:]:%*s",
u,
d) != 2) {
8949 return (port <= 0xffff);
8981 if ((
dstlen >= (
size_t)res->ai_addrlen)
8982 && (res->ai_addr->sa_family ==
af)) {
8983 memcpy(
dst, res->ai_addr, res->ai_addrlen);
9010 memset(sa, 0,
sizeof(*sa));
9026#if defined(USE_X_DOM_SOCKET)
9030 if (
hostlen >=
sizeof(sa->sun.sun_path)) {
9036 "host length exceeds limit");
9051#if !defined(NO_SSL) && !defined(USE_MBEDTLS) && !defined(NO_SSL_DL)
9052#if defined(OPENSSL_API_1_1) || defined(OPENSSL_API_3_0)
9059 "SSL is not initialized");
9069 "SSL is not initialized");
9078#if defined(USE_X_DOM_SOCKET)
9084 memset(sa->sun.sun_path, 0,
sizeof(sa->sun.sun_path));
9089 sa->
sin.sin_port =
htons((uint16_t)port);
9091#if defined(USE_IPV6)
9093 sa->sin6.sin6_port =
htons((uint16_t)port);
9095 }
else if (host[0] ==
'[') {
9103 sa->sin6.sin6_port =
htons((uint16_t)port);
9124#if defined(USE_IPV6)
9129#if defined(USE_X_DOM_SOCKET)
9130 else if (
ip_ver == -99) {
9150 "Cannot set socket to non-blocking: %s",
9165#if defined(USE_IPV6)
9169 (
struct sockaddr *)((
void *)&sa->sin6),
9173#if defined(USE_X_DOM_SOCKET)
9174 else if (
ip_ver == -99) {
9177 (
struct sockaddr *)((
void *)&sa->sun),
9223 "connect(%s:%d): timeout",
9248 "connect(%s:%d): error %s",
9265 static const char *hex =
"0123456789abcdef";
9269 for (; ((*
src !=
'\0') && (pos < end));
src++, pos++) {
9273 }
else if (pos + 2 < end) {
9275 pos[1] = hex[(
unsigned char)*
src >> 4];
9276 pos[2] = hex[(
unsigned char)*
src & 0xf];
9284 return (*
src ==
'\0') ? (
int)(pos -
dst) : -1;
9295#if defined(REENTRANT_TIME)
9318 }
else if (*
p ==
'<') {
9320 }
else if (*
p ==
'>') {
9326 if (
de->
file.is_directory) {
9336 if (
de->
file.size < 1024) {
9343 }
else if (
de->
file.size < 0x100000) {
9349 (
double)
de->
file.size / 1024.0);
9350 }
else if (
de->
file.size < 0x40000000) {
9356 (
double)
de->
file.size / 1048576);
9363 (
double)
de->
file.size / 1073741824);
9370#if defined(REENTRANT_TIME)
9379 mod[
sizeof(
mod) - 1] =
'\0';
9382 "<tr><td><a href=\"%s%s\">%s%s</a></td>"
9383 "<td> %s</td><td> %s</td></tr>\n",
9385 de->
file.is_directory ?
"/" :
"",
9387 de->
file.is_directory ?
"/" :
"",
9403 const struct de *
a = (
const struct de *)
p1, *
b = (
const struct de *)
p2;
9404 const char *query_string =
a->conn->request_info.query_string;
9407 if ((query_string ==
NULL) || (query_string[0] ==
'\0')) {
9411 if (
a->file.is_directory && !
b->file.is_directory) {
9413 }
else if (!
a->file.is_directory &&
b->file.is_directory) {
9415 }
else if (*query_string ==
'n') {
9417 }
else if (*query_string ==
's') {
9420 : ((
a->file.size >
b->file.size) ? 1 : -1);
9421 }
else if (*query_string ==
'd') {
9423 (
a->file.last_modified ==
b->file.last_modified)
9425 : ((
a->file.last_modified >
b->file.last_modified) ? 1
9448#if !defined(NO_FILESYSTEMS)
9453 int (*cb)(
struct de *,
void *))
9490 "%s: mg_stat(%s) failed: %s",
9508#if !defined(NO_FILES)
9549 "%s: mg_stat(%s) failed: %s",
9556 if (
de.
file.is_directory) {
9584#if !defined(NO_FILESYSTEMS)
9589 struct de *entries =
dsd->entries;
9591 if ((entries ==
NULL) || (
dsd->num_entries >=
dsd->arr_size)) {
9596 dsd->arr_size * 2 *
sizeof(entries[0]));
9597 if (entries ==
NULL) {
9601 dsd->entries = entries;
9634 "Error: Cannot open directory\nopendir(%s): %s",
9644 if (title[
strcspn(title,
"&<>")]) {
9652 }
else if (*
p ==
'<') {
9654 }
else if (*
p ==
'>') {
9677 "text/html; charset=utf-8",
9685 "<html><head><title>Index of %s</title>"
9686 "<style>th {text-align: left;}</style></head>"
9687 "<body><h1>Index of %s</h1><pre><table cellpadding=\"0\">"
9688 "<tr><th><a href=\"?n%c\">Name</a></th>"
9689 "<th><a href=\"?d%c\">Modified</a></th>"
9690 "<th><a href=\"?s%c\">Size</a></th></tr>"
9691 "<tr><td colspan=\"3\"><hr></td></tr>",
9701 "<tr><td><a href=\"%s\">%s</a></td>"
9702 "<td> %s</td><td> %s</td></tr>\n",
9712 sizeof(
data.entries[0]),
9714 for (i = 0; i <
data.num_entries; i++) {
9721 mg_printf(conn,
"%s",
"</table></pre></body></html>");
9738 if (!
filep || !conn) {
9744 : (int64_t)(
filep->stat.size);
9749#if defined(__linux__)
9763 (size_t)((
len < 0x7FFFF000) ?
len : 0x7FFFF000);
9795 "%s: fseeko() failed: %s",
9802 "Error: Unable to access file at requested position.");
9853 (
unsigned long)
filestat->last_modified,
9868 "%s: fcntl(F_SETFD FD_CLOEXEC) failed: %s",
9877#if defined(USE_ZLIB)
9878#include "mod_zlib.inl"
9882#if !defined(NO_FILESYSTEMS)
9897 const char *encoding = 0;
9903#if defined(USE_ZLIB)
9925 "Error: File size is too large to send\n%" INT64_FMT,
9929 cl = (int64_t)
filep->stat.size;
9933#if defined(USE_ZLIB)
9946 if (
filep->stat.is_gzipped) {
9952 "Error: Path of zipped file too long (%s)",
9960#if defined(USE_ZLIB)
9974 cl = (int64_t)
filep->stat.size;
9978#if defined(USE_ZLIB)
9988 "Error: Cannot open file\nfopen(%s): %s",
10004 if (
filep->stat.is_gzipped) {
10009 "Error: Range requests in gzipped files are not supported");
10015 cl = (
n == 2) ? (((
r2 > cl) ? cl :
r2) -
r1 + 1) : (cl -
r1);
10026#if defined(USE_ZLIB)
10034#if defined(USE_ZLIB)
10050 cors1 =
"Access-Control-Allow-Origin";
10059 cors3 =
"Access-Control-Allow-Credentials";
10077 if (
cors1[0] != 0) {
10080 if (
cors3[0] != 0) {
10086#if defined(USE_ZLIB)
10117 if (
range[0] != 0) {
10131#if defined(USE_ZLIB)
10161#if !defined(NO_CACHING)
10204#if !defined(NO_FILESYSTEMS)
10235#if !defined(NO_CACHING)
10241 if (file.
stat.is_directory) {
10249 "Error: Directory listing denied");
10276 for (s =
p = path + 2; (
p =
strchr(s,
'/')) !=
NULL; s = ++
p) {
10277 len = (size_t)(
p - path);
10278 if (
len >=
sizeof(buf)) {
10295 if (
p[1] ==
'\0') {
10310 "%s: Cannot remove invalid file %s",
10347 n = (
int)fwrite(buf, 1, (
size_t)
ret,
fi.access.fp);
10387 if ((**
ppw !=
'\r') && (**
ppw !=
'\n')) {
10392 if (**
ppw !=
' ') {
10424 int num_headers = 0;
10430 while ((*
dp !=
':') && (*
dp >= 33) && (*
dp <= 126)) {
10439 while (*
dp ==
' ') {
10451 hdr[i].name = *buf;
10456 }
while ((*
dp ==
' ') || (*
dp ==
'\t'));
10462 while ((*
dp != 0) && (*
dp !=
'\r') && (*
dp !=
'\n')) {
10478 num_headers = i + 1;
10485 if ((
dp[0] ==
'\r') || (
dp[0] ==
'\n')) {
10494 return num_headers;
10511 {
"GET", 0, 1, 1, 1, 1},
10512 {
"POST", 1, 1, 0, 0, 0},
10513 {
"PUT", 1, 0, 0, 1, 0},
10514 {
"DELETE", 0, 0, 0, 1, 0},
10515 {
"HEAD", 0, 0, 1, 1, 1},
10516 {
"OPTIONS", 0, 0, 1, 1, 0},
10517 {
"CONNECT", 1, 1, 0, 0, 0},
10521 {
"PATCH", 1, 0, 0, 0, 0},
10525 {
"PROPFIND", 0, 1, 1, 1, 0},
10531 {
"MKCOL", 0, 0, 0, 1, 0},
10544 {
"LOCK", 1, 1, 0, 0, 0},
10545 {
"UNLOCK", 1, 0, 0, 0, 0},
10546 {
"PROPPATCH", 1, 1, 0, 0, 0},
10558 {
"REPORT", 1, 1, 1, 1, 1},
10565 {
NULL, 0, 0, 0, 0, 0}
10620 while ((
len > 0) &&
isspace((
unsigned char)*buf)) {
10632 if (
iscntrl((
unsigned char)*buf)) {
10643 if ((*buf == 0) || (*buf ==
'\r') || (*buf ==
'\n')) {
10706 while ((
len > 0) &&
isspace((
unsigned char)*buf)) {
10718 if (
iscntrl((
unsigned char)*buf)) {
10729 if ((*buf == 0) || (*buf ==
'\r') || (*buf ==
'\n')) {
10735 if (
strncmp(buf,
"HTTP/", 5) != 0) {
10740 if (!
isgraph((
unsigned char)buf[0])) {
10758 if ((
l < 100) || (
l >= 1000) || ((
tmp2 - tmp) != 3) || (*
tmp2 != 0)) {
10769 while (
isprint((
unsigned char)*buf)) {
10772 if ((*buf !=
'\r') && (*buf !=
'\n')) {
10779 }
while (
isspace((
unsigned char)*buf));
10805 int request_len,
n = 0;
10834 while (request_len == 0) {
10870 return request_len;
10874#if !defined(NO_CGI) || !defined(NO_FILES)
10899 (void)
mg_printf(conn,
"%s",
"HTTP/1.1 100 Continue\r\n\r\n");
10937#if defined(USE_TIMERS)
10939#define TIMER_API static
10940#include "timer.inl"
10945#if !defined(NO_CGI)
10978 size_t i,
n, space;
10983 if ((env->varlen - env->varused) < 2) {
10985 "%s: Cannot register CGI variable [%s]",
10992 space = (env->buflen - env->bufused);
11004 "%s: Cannot allocate memory for CGI variable [%s]",
11012 for (i = 0,
n = 0; i < env->varused; i++) {
11013 env->var[i] = added +
n;
11016 space = (env->buflen - env->bufused);
11020 added = env->buf + env->bufused;
11039 env->var[env->varused] = added;
11066 "%s: Not enough memory for environmental buffer",
11076 "%s: Not enough memory for environmental variables",
11088 addenv(env,
"%s",
"GATEWAY_INTERFACE=CGI/1.1");
11089 addenv(env,
"%s",
"SERVER_PROTOCOL=HTTP/1.1");
11090 addenv(env,
"%s",
"REDIRECT_STATUS=200");
11107 if (conn->
request_info.local_uri[uri_len - 1] !=
'/') {
11115 "SCRIPT_NAME=%s%s",
11123 "SCRIPT_NAME=%.*s",
11133 "PATH_TRANSLATED=%s%s",
11138 addenv(env,
"HTTPS=%s", (conn->
ssl ==
NULL) ?
"off" :
"on");
11141 addenv(env,
"CONTENT_TYPE=%s", s);
11147 addenv(env,
"CONTENT_LENGTH=%s", s);
11150 addenv(env,
"PATH=%s", s);
11163 addenv(env,
"COMSPEC=%s", s);
11166 addenv(env,
"SYSTEMROOT=%s", s);
11169 addenv(env,
"SystemDrive=%s", s);
11172 addenv(env,
"ProgramFiles=%s", s);
11174 if ((s =
getenv(
"ProgramFiles(x86)")) !=
NULL) {
11175 addenv(env,
"ProgramFiles(x86)=%s", s);
11178 if ((s =
getenv(
"LD_LIBRARY_PATH")) !=
NULL) {
11179 addenv(env,
"LD_LIBRARY_PATH=%s", s);
11184 addenv(env,
"PERLLIB=%s", s);
11189 addenv(env,
"%s",
"AUTH_TYPE=Digest");
11193 for (i = 0; i < conn->
request_info.num_headers; i++) {
11204 "%s: HTTP header variable too long [%s]",
11255 if ((
ret_pid != (pid_t)-1) && (status == 0)) {
11261 while (
waitpid(
proc->pid, &status, 0) != (pid_t)-1)
11264 DEBUG_TRACE(
"CGI timer: Child process %d already stopped\n",
proc->pid);
11286 int fdin[2] = {-1, -1},
fdout[2] = {-1, -1},
fderr[2] = {-1, -1};
11293 pid_t pid = (pid_t)-1;
11296#if defined(USE_TIMERS)
11310 buflen = conn->
phys_ctx->max_request_size;
11341 "Error: CGI program \"%s\": Can not create CGI pipes: %s",
11346 "Error: Cannot create CGI pipe: %s",
11363 if (
pid == (pid_t)-1) {
11367 "Error: CGI program \"%s\": Can not spawn CGI process: %s",
11378 proc->references = 1;
11380#if defined(USE_TIMERS)
11382 proc->references = 2;
11399 (void)close(
fdin[0]);
11400 (void)close(
fdout[1]);
11401 (void)close(
fderr[1]);
11409 "Error: CGI program \"%s\": Can not open fd: %s",
11414 "Error: CGI can not open fd\nfdopen: %s",
11422 fout.access.fp = out;
11433 "Error: CGI program \"%s\": Forward body data failed",
11453 "Error: Not enough memory for CGI buffer (%u bytes)",
11454 (
unsigned int)buflen);
11457 "Error: CGI program \"%s\": Not enough memory for buffer (%u "
11460 (
unsigned int)buflen);
11472 i =
pull_all(err, conn, buf, (
int)buflen);
11477 "Error: CGI program \"%s\" sent error "
11485 "Error: CGI program \"%s\" failed.",
11491 "Error: CGI program sent malformed or too big "
11492 "(>%u bytes) HTTP headers: [%.*s]",
11499 "Error: CGI program sent malformed or too big "
11500 "(>%u bytes) HTTP headers: [%.*s]",
11515 status_text =
"OK";
11519 status_text = status;
11520 while (
isdigit((
unsigned char)*status_text) || *status_text ==
' ') {
11563 if (
pid != (pid_t)-1) {
11567 if (
fdin[0] != -1) {
11570 if (
fdout[1] != -1) {
11573 if (
fderr[1] != -1) {
11579 }
else if (
fdin[1] != -1) {
11585 }
else if (
fdout[0] != -1) {
11591 }
else if (
fderr[0] != -1) {
11600#if !defined(NO_FILES)
11617 "%s: mg_stat(%s) failed: %s",
11623 if (
de.
file.last_modified) {
11678 if (conn ==
NULL) {
11686 if (file.
stat.is_directory) {
11703 "Error: Put not possible\nReplacing %s is not allowed",
11735 "Error: Path too long\nput_dir(%s): %s",
11745 "Error: Can not create directory\nput_dir(%s): %s",
11758 "Error: Can not create file\nfopen(%s): %s",
11806 "Error: Cannot delete file\nFile %s not found",
11811 if (
de.
file.is_directory) {
11824 if (access(path,
W_OK) != 0) {
11829 "Error: Delete not possible\nDeleting %s is not allowed",
11847 "Error: Cannot delete file\nremove(%s): %s",
11855#if !defined(NO_FILESYSTEMS)
11871 if (conn ==
NULL) {
11878 if (
sscanf(tag,
" virtual=\"%511[^\"]\"", file_name) == 1) {
11880 file_name[511] = 0;
11889 }
else if (
sscanf(tag,
" abspath=\"%511[^\"]\"", file_name) == 1) {
11892 file_name[511] = 0;
11896 }
else if ((
sscanf(tag,
" file=\"%511[^\"]\"", file_name) == 1)
11897 || (
sscanf(tag,
" \"%511[^\"]\"", file_name) == 1)) {
11899 file_name[511] = 0;
11910 sizeof(path) -
len,
11921 mg_cry_internal(conn,
"SSI #include path length overflow: [%s]", tag);
11927 "Cannot open SSI #include: [%s]: fopen(%s): %s",
11944#if !defined(NO_POPEN)
11948 char cmd[1024] =
"";
11951 if (
sscanf(tag,
" \"%1023[^\"]\"", cmd) != 1) {
11957 "Cannot SSI #exec: [%s]: %s",
12014 if ((
len > 12) && !
memcmp(buf + 5,
"include", 7)) {
12016#if !defined(NO_POPEN)
12017 }
else if ((
len > 9) && !
memcmp(buf + 5,
"exec", 4)) {
12040 buf[
len++] = (char)(ch & 0xff);
12042 if ((
len == 5) && !
memcmp(buf,
"<!--#", 5)) {
12047 if ((
len + 2) > (
int)
sizeof(buf)) {
12073 buf[
len++] = (char)(ch & 0xff);
12075 if (
len == (
int)
sizeof(buf)) {
12107 cors1 =
"Access-Control-Allow-Origin";
12116 cors3 =
"Access-Control-Allow-Credentials";
12127 "Error: Cannot read file\nfopen(%s): %s",
12158#if !defined(NO_FILES)
12177 "GET, POST, HEAD, CONNECT, PUT, DELETE, OPTIONS, PROPFIND, MKCOL",
12198 char *
href, mtime[64];
12215 for (i =
j = 0;
href[i];
j++) {
12228 "<d:href>%s</d:href>"
12231 "<d:resourcetype>%s</d:resourcetype>"
12232 "<d:getcontentlength>%" INT64_FMT "</d:getcontentlength>"
12233 "<d:getlastmodified>%s</d:getlastmodified>"
12235 "<d:status>HTTP/1.1 200 OK</d:status>"
12239 filep->is_directory ?
"<d:collection/>" :
"",
12287 "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
12288 "<d:multistatus xmlns:d='DAV:'>\n");
12295 if (
filep->is_directory
12302 mg_printf(conn,
"%s\n",
"</d:multistatus>");
12339#if defined(USE_LUA)
12340#include "mod_lua.inl"
12343#if defined(USE_DUKTAPE)
12344#include "mod_duktape.inl"
12347#if defined(USE_WEBSOCKET)
12349#if !defined(NO_SSL_DL)
12350#if !defined(OPENSSL_API_3_0)
12351#define SHA_API static
12359 static const char *
magic =
"258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
12361#if !defined(OPENSSL_API_3_0)
12375#if defined(OPENSSL_API_3_0)
12385 "HTTP/1.1 101 Switching Protocols\r\n"
12386 "Upgrade: websocket\r\n"
12387 "Connection: Upgrade\r\n"
12388 "Sec-WebSocket-Accept: %s\r\n",
12391#if defined(USE_ZLIB) && defined(MG_EXPERIMENTAL_INTERFACES)
12396 if (conn->
request_info.acceptedWebSocketSubprotocol) {
12398 "Sec-WebSocket-Protocol: %s\r\n\r\n",
12408#if !defined(MG_MAX_UNANSWERED_PING)
12414#define MG_MAX_UNANSWERED_PING (5)
12421 void *callback_data)
12441 unsigned char mask[4];
12446 unsigned char mem[4096];
12472 DEBUG_TRACE(
"Websocket connection %s:%u start data processing loop",
12475 conn->in_websocket_handling = 1;
12503 if (
data_len > (uint64_t)0x7FFF0000ul) {
12508 "websocket out of memory; closing connection");
12527 "websocket out of memory; closing connection");
12557 }
else if (
n > 0) {
12568 "Websocket pull failed; closing connection");
12601 for (i = 0; i < (size_t)
data_len; i++) {
12635#if defined(USE_ZLIB) && defined(MG_EXPERIMENTAL_INTERFACES)
12638 if (!conn->websocket_deflate_initialized) {
12650 conn->websocket_inflate_state.avail_in =
12652 conn->websocket_inflate_state.next_in =
data;
12672 "Out of memory: Cannot allocate "
12673 "inflate buffer of %lu bytes",
12679 conn->websocket_inflate_state.avail_out =
12682 conn->websocket_inflate_state.next_out =
12684 ret =
inflate(&conn->websocket_inflate_state,
12690 "ZLIB inflate error: %i %s",
12692 (conn->websocket_inflate_state.msg
12693 ? conn->websocket_inflate_state.msg
12694 :
"<no error message>"));
12700 }
while (conn->websocket_inflate_state.avail_out
12703 conn->websocket_inflate_state.avail_out;
12731 DEBUG_TRACE(
"Callback requests to close connection from %s:%u",
12738 DEBUG_TRACE(
"Message requests to close connection from %s:%u",
12769 DEBUG_TRACE(
"Too many (%i) unanswered ping from %s:%u "
12770 "- closing connection",
12802 conn->in_websocket_handling = 0;
12803 DEBUG_TRACE(
"Websocket connection %s:%u left data processing loop",
12816 unsigned char header[14];
12820#if defined(GCC_DIAGNOSTIC)
12822#pragma GCC diagnostic push
12823#pragma GCC diagnostic ignored "-Wconversion"
12839#if defined(USE_ZLIB) && defined(MG_EXPERIMENTAL_INTERFACES)
12846 if (!conn->websocket_deflate_initialized) {
12852 header[0] = 0xC0u | (
unsigned char)((
unsigned)opcode & 0xf);
12853 conn->websocket_deflate_state.avail_in = (
uInt)
dataLen;
12854 conn->websocket_deflate_state.next_in = (
unsigned char *)
data;
12860 "Out of memory: Cannot allocate deflate buffer of %lu bytes",
12866 conn->websocket_deflate_state.next_out =
deflated;
12867 deflate(&conn->websocket_deflate_state, conn->websocket_deflate_flush);
12872 header[0] = 0x80u | (
unsigned char)((
unsigned)opcode & 0xf);
12874#if defined(GCC_DIAGNOSTIC)
12875#pragma GCC diagnostic pop
12881 header[1] = (
unsigned char)
dataLen;
12883 }
else if (
dataLen <= 0xFFFF) {
12912#if defined(USE_ZLIB) && defined(MG_EXPERIMENTAL_INTERFACES)
12945 if ((
in_len > 3) && ((ptrdiff_t)in % 4) == 0) {
12947 while (i < (
in_len - 3)) {
12948 *(uint32_t *)(
void *)(
out + i) =
12956 *(uint8_t *)(
void *)(
out + i) =
12957 *(uint8_t *)(
void *)(in + i)
12980 "Cannot allocate buffer for masked websocket response: "
13015#if !defined(USE_LUA)
13040 "Protocol upgrade to RFC 6455 required");
13065 "Sec-WebSocket-Protocol",
13073 *acceptedWebSocketSubprotocol =
NULL;
13083 len =
sep ? (
unsigned long)(sep - protocol)
13084 : (unsigned long)
strlen(protocol);
13085 while (sep &&
isspace((
unsigned char)*++sep))
13095 acceptedWebSocketSubprotocol =
13100 }
while (sep && !acceptedWebSocketSubprotocol);
13102 && !acceptedWebSocketSubprotocol);
13105 acceptedWebSocketSubprotocol;
13117 conn->
request_info.acceptedWebSocketSubprotocol = protocol;
13127 while (
isspace((
unsigned char)*++sep)) {
13134#if defined(USE_ZLIB) && defined(MG_EXPERIMENTAL_INTERFACES)
13149#if defined(USE_LUA)
13161 if (!conn->lua_websocket_state) {
13190#if defined(USE_LUA)
13202#if defined(USE_LUA)
13208#if defined(USE_ZLIB) && defined(MG_EXPERIMENTAL_INTERFACES)
13210 if (conn->websocket_deflate_initialized) {
13293 if ((
n > 0) && ((
size_t)
n ==
vec->
len)) {
13294 if ((
a < 256) && (
b < 256) && (
c < 256) && (
d < 256) && (
slash < 33)) {
13297 uint32_t
ip =
ntohl(sa->
sin.sin_addr.s_addr);
13298 uint32_t net = ((uint32_t)
a << 24) | ((uint32_t)
b << 16)
13299 | ((uint32_t)
c << 8) | (uint32_t)
d;
13301 return (
ip &
mask) == net;
13306#if defined(USE_IPV6)
13322 if (((
size_t)(
p -
vec->
ptr) <
sizeof(
ad))
13329 }
else if (
vec->
len <
sizeof(
ad)) {
13340 while (
isxdigit((
unsigned char)*
p) || (*
p ==
'.') || (*
p ==
':')) {
13341 if (*(
p++) ==
':') {
13345 if ((*
p ==
'\0') && (
c >= 2)) {
13355 for (i = 0; i < 16; i++) {
13356 uint8_t
ip = sa->sin6.sin6_addr.s6_addr[i];
13357 uint8_t net =
sin6.sin6_addr.s6_addr[i];
13360 if (8 * i + 8 <
slash) {
13362 }
else if (8 * i <
slash) {
13363 mask = (uint8_t)(0xFFu << (8 * i + 8 -
slash));
13365 if ((
ip &
mask) != net) {
13400 && (
mult !=
','))) {
13435 for (i = 0; ((idx == -1) && (
i < ctx->num_listening_sockets)); i++) {
13462 DEBUG_TRACE(
"%s",
"Host name format error '[' without ']'");
13499 DEBUG_TRACE(
"Host mismatch: SNI: %s, HTTPS: %.*s",
13530 conn->
ssl ?
"S" :
"",
13662 if (!phys_ctx || !dom_ctx) {
13739 "Cannot create new request handler struct, OOM");
13748 "Cannot create new request handler struct, OOM");
13882 if (request_info) {
13883 const char *uri = request_info->
local_uri;
13894 for (step = 0; step < 3; step++) {
13904 }
else if (step == 1) {
13964#if defined(USE_WEBSOCKET) && defined(MG_EXPERIMENTAL_INTERFACES)
14030 void *callback_data =
NULL;
14063 "Error: SSL forward not configured properly");
14066 "Can not redirect to SSL, no SSL port available");
14108 if (conn->
phys_ctx->callbacks.begin_request !=
NULL) {
14112 i = conn->
phys_ctx->callbacks.begin_request(conn);
14121 }
else if (i == 0) {
14149 "Access-Control-Request-Method");
14162 "Access-Control-Request-Headers");
14166 "HTTP/1.1 200 OK\r\n"
14168 "Access-Control-Allow-Origin: %s\r\n"
14169 "Access-Control-Allow-Methods: %s\r\n"
14170 "Content-Length: 0\r\n"
14171 "Connection: %s\r\n",
14189 "Access-Control-Allow-Headers: %s\r\n",
14196 "Access-Control-Allow-Credentials: %s\r\n",
14200 mg_printf(conn,
"Access-Control-Max-Age: 60\r\n");
14213#if defined(USE_WEBSOCKET)
14284#if defined(NO_FILES)
14296 "%s method not allowed",
14301#if !defined(NO_FILES)
14385#if defined(USE_WEBSOCKET)
14401#if defined(USE_WEBSOCKET)
14428#if defined(NO_FILES)
14472 "%s method not allowed",
14485 if (file.
stat.is_directory && (uri_len > 0)
14486 && (ri->
local_uri[uri_len - 1] !=
'/')) {
14529 "%s method not allowed",
14535 if (file.
stat.is_directory) {
14546 "Error: Directory listing denied");
14559#if !defined(NO_CACHING)
14574#if !defined(NO_FILESYSTEMS)
14580#if !defined(NO_CGI)
14584 if (!conn || !conn->
dom_ctx) {
14588#if defined(USE_LUA)
14617#if defined(USE_DUKTAPE)
14632#if !defined(NO_CGI)
14664#if !defined(NO_CACHING)
14687#if defined(USE_X_DOM_SOCKET)
14725 unsigned int a,
b,
c,
d;
14731#if defined(USE_IPV6)
14732 char buf[100] = {0};
14738 memset(so, 0,
sizeof(*so));
14748 "%u.%u.%u.%u:%u%n",
14759 so->
lsa.sin.sin_addr.s_addr =
14760 htonl((
a << 24) | (
b << 16) | (
c << 8) |
d);
14761 so->
lsa.sin.sin_port =
htons((uint16_t)port);
14764#if defined(USE_IPV6)
14772 so->
lsa.sin6.sin6_port =
htons((uint16_t)port);
14776 }
else if ((
vec->
ptr[0] ==
'+')
14787#if defined(USE_IPV6)
14790 so->
lsa.sin6.sin6_port =
htons((uint16_t)port);
14794 so->
lsa.sin.sin_port =
htons((uint16_t)port);
14801 port = (uint16_t)
portUL;
14803 so->
lsa.sin.sin_port =
htons((uint16_t)port);
14829 if (
sscanf(cb + 1,
"%u%n", &port, &
len)
14835 so->
lsa.sin.sin_port =
htons((uint16_t)port);
14840#if defined(USE_IPV6)
14844 sizeof(so->
lsa.sin6),
14846 if (
sscanf(cb + 1,
"%u%n", &port, &
len) == 1) {
14848 so->
lsa.sin6.sin6_port =
htons((uint16_t)port);
14858#if defined(USE_X_DOM_SOCKET)
14860 }
else if (
vec->
ptr[0] ==
'x') {
14862 if (
vec->
len <
sizeof(so->
lsa.sun.sun_path)) {
14865 memset(so->
lsa.sun.sun_path, 0,
sizeof(so->
lsa.sun.sun_path));
14886 so->
is_ssl = (ch ==
's');
14888 if ((ch ==
'\0') || (ch ==
's') || (ch ==
'r')) {
14962#if defined(USE_IPV6)
14983 memset(&so, 0,
sizeof(so));
14995 "%.*s: invalid port spec (entry %i). Expecting list of: %s",
14999 "[IP_ADDRESS:]PORT[s|r]");
15003#if !defined(NO_SSL)
15007 "Cannot add SSL socket (entry %i)",
15023 "cannot create socket (entry %i)",
15048 "cannot set socket option SO_EXCLUSIVEADDRUSE (entry %i)",
15062 "cannot set socket option SO_REUSEADDR (entry %i)",
15067#if defined(USE_X_DOM_SOCKET)
15075#if defined(USE_IPV6)
15087 "cannot set socket option "
15088 "IPV6_V6ONLY=off (entry %i)",
15102 "cannot set socket option "
15103 "IPV6_V6ONLY=on (entry %i)",
15117 len =
sizeof(so.
lsa.sin);
15120 "cannot bind to %.*s: %d (%s)",
15130#if defined(USE_IPV6)
15133 len =
sizeof(so.
lsa.sin6);
15136 "cannot bind to IPv6 %.*s: %d (%s)",
15147#if defined(USE_X_DOM_SOCKET)
15150 len =
sizeof(so.
lsa.sun);
15153 "cannot bind to unix socket %s: %d (%s)",
15154 so.
lsa.sun.sun_path,
15166 "cannot bind: address family not supported (entry %i)",
15177 "%s value \"%s\" is invalid",
15188 "cannot listen to %.*s: %d (%s)",
15199 || (
usa.
sa.sa_family != so.
lsa.sa.sa_family)) {
15203 "call to getsockname failed %.*s: %d (%s)",
15214#if defined(USE_IPV6)
15216 so.
lsa.sin6.sin6_port =
usa.sin6.sin6_port;
15220 so.
lsa.sin.sin_port =
usa.
sin.sin_port;
15223 if ((ptr = (
struct socket *)
15280#if defined(MG_EXTERNAL_FUNCTION_log_access)
15281#include "external_log_access.inl"
15282#elif !defined(NO_FILESYSTEMS)
15297 if (!conn || !conn->
dom_ctx) {
15304#if defined(USE_LUA)
15305 if (conn->
phys_ctx->lua_bg_log_available) {
15328 if ((
len == 0) || (*
txt == 0)) {
15361 if ((
fi.access.fp ==
NULL)
15386 "%s - %s [%s] \"%s %s%s%s HTTP/%s\" %d %" INT64_FMT
15403 if (conn->
phys_ctx->callbacks.log_access) {
15406 if (
fi.access.fp) {
15414 if (
fi.access.fp) {
15429 "Error writing log file %s",
15435#error "Either enable filesystems or provide a custom log_access implementation"
15452 allowed = (list ==
NULL) ?
'+' :
'-';
15464 "%s: subnet must be [+|-]IP-addr[/x]",
15473 return allowed ==
'+';
15479#if !defined(_WIN32) && !defined(__ZEPHYR__)
15496 "%s: unknown user [%s]",
15508 "%s: setgid(%s): %s",
15514 "%s: setgroups(): %s",
15519 "%s: setuid(%s): %s",
15541 if (
tls->is_master == 2) {
15542 tls->is_master = -3;
15550#if defined(USE_MBEDTLS)
15561 dom_ctx = &(phys_ctx->
dd);
15581#elif !defined(NO_SSL)
15586 const char *
chain);
15618 if ((t != 0) && (conn->
dom_ctx->ssl_cert_last_mtime != t)) {
15619 conn->
dom_ctx->ssl_cert_last_mtime = t;
15643 "SSL_CTX_load_verify_locations error: %s "
15644 "ssl_verify_peer requires setting "
15645 "either ssl_ca_path or ssl_ca_file. Is any of them "
15663#if defined(OPENSSL_API_1_1)
15670 int (*func)(
SSL *),
15731 for (i = 0; i <=
timeout; i += 50) {
15734 ret = func(conn->ssl);
15754 pfd.fd = conn->client.sock;
15760 mg_poll(&
pfd, 1, 50, &(conn->phys_ctx->stop_flag));
15811 const char hexdigit[] =
"0123456789abcdef";
15813 if ((
memlen <= 0) || (buflen <= 0)) {
15816 if (buflen < (3 *
memlen)) {
15820 for (i = 0; i <
memlen; i++) {
15822 buf[3 * i - 1] =
' ';
15824 buf[3 * i] =
hexdigit[(((uint8_t *)
mem)[i] >> 4) & 0xF];
15825 buf[3 * i + 1] =
hexdigit[((uint8_t *)
mem)[i] & 0xF];
15827 buf[3 *
memlen - 1] = 0;
15840 unsigned char buf[256];
15845 unsigned char *
tmp_p;
15908#if defined(OPENSSL_API_1_1)
15926#if !defined(NO_SSL_DL)
15949 "%s: cannot load %s",
15970 if (
u.fp ==
NULL) {
15984 "%s: %s: cannot find %s",
16025#if defined(SSL_ALREADY_INITIALIZED)
16037#if !defined(OPENSSL_API_1_1) && !defined(OPENSSL_API_3_0)
16046#if !defined(NO_SSL_DL)
16056 "%s: error loading library %s",
16069#if !defined(OPENSSL_API_1_1) && !defined(OPENSSL_API_3_0)
16093 "%s: cannot allocate mutexes: %s",
16107 "%s: error initializing mutex %i of %i",
16122#if !defined(NO_SSL_DL)
16127#if !defined(OPENSSL_API_1_1)
16136#if (defined(OPENSSL_API_1_1) || defined(OPENSSL_API_3_0)) \
16137 && !defined(NO_SSL_DL)
16161 "%s: cannot open certificate file %s: %s",
16171 "%s: cannot open private key file %s: %s",
16180 "%s: certificate and private key do not match: %s",
16197 "%s: cannot use certificate chain file %s: %s",
16208#if defined(OPENSSL_API_1_1)
16209static unsigned long
16223#if defined(SSL_OP_NO_TLSv1_3)
16244#if defined(SSL_OP_NO_TLSv1_3)
16282#if defined(GCC_DIAGNOSTIC)
16283#pragma GCC diagnostic push
16284#pragma GCC diagnostic ignored "-Wcast-align"
16290#if defined(GCC_DIAGNOSTIC)
16291#pragma GCC diagnostic pop
16312 DEBUG_TRACE(
"%s",
"SSL connection not supporting SNI");
16347#if defined(USE_ALPN)
16348static const char alpn_proto_list[] =
"\x02h2\x08http/1.1\x08http/1.0";
16352#if defined(USE_HTTP2)
16361 const unsigned char **out,
16363 const unsigned char *in,
16364 unsigned int inlen,
16382#if defined(USE_HTTP2)
16393 for (i = 0; i <
inlen; i++) {
16410 const unsigned char **
data,
16434 "SSL_CTX_set_alpn_protos error: %s",
16471#if (defined(OPENSSL_API_1_1) || defined(OPENSSL_API_3_0)) \
16472 && !defined(NO_SSL_DL)
16475 "SSL_CTX_new (server) error: %s",
16482 "SSL_CTX_new (server) error: %s",
16488#if defined(SSL_OP_NO_TLSv1_3)
16507#if defined(SSL_OP_NO_RENEGOTIATION)
16511#if !defined(NO_SSL_DL)
16544 "SSL callback returned error: %i",
16556 : (phys_ctx->
callbacks.init_ssl_domain(
16566 "Domain SSL callback returned error: %i",
16628 "SSL_CTX_load_verify_locations error: %s "
16629 "ssl_verify_peer requires setting "
16630 "either ssl_ca_path or ssl_ca_file. "
16631 "Is any of them present in the "
16649 "SSL_CTX_set_default_verify_paths error: %s",
16665 "SSL_CTX_set_cipher_list error: %s",
16681#if defined(USE_ALPN)
16683#if !defined(NO_SSL_DL)
16712 dom_ctx = &(phys_ctx->
dd);
16724 : (phys_ctx->
callbacks.external_ssl_ctx(&ssl_ctx,
16730 "external_ssl_ctx callback returned error: %i",
16749 : (phys_ctx->
callbacks.external_ssl_ctx_domain(
16758 "external_ssl_ctx_domain callback returned error: %i",
16782 "Initializing SSL failed: -%s is not set",
16810#if defined(OPENSSL_API_1_1) || defined(OPENSSL_API_3_0)
16848#if !defined(NO_FILESYSTEMS)
16863 "Cannot open %s: %s",
16880#if defined(USE_IPV6)
16925#if defined(USE_SERVER_STATS)
16926 conn->processing_time = 0;
16952#if !defined(__ZEPHYR__)
16961 int error_code = 0;
17000#if defined(_MSC_VER)
17001#pragma warning(push)
17002#pragma warning(disable : 4244)
17004#if defined(GCC_DIAGNOSTIC)
17005#pragma GCC diagnostic push
17006#pragma GCC diagnostic ignored "-Wconversion"
17014#if defined(GCC_DIAGNOSTIC)
17015#pragma GCC diagnostic pop
17017#if defined(_MSC_VER)
17018#pragma warning(pop)
17032 (
char *)&error_code,
17042 "%s: getsockopt(SOL_SOCKET SO_ERROR) failed: %s",
17063 "%s: setsockopt(SOL_SOCKET SO_LINGER(%i,%i)) failed: %s",
17081#if defined(USE_SERVER_STATS)
17082 conn->conn_state = 6;
17085#if defined(USE_LUA) && defined(USE_WEBSOCKET)
17086 if (conn->lua_websocket_state) {
17088 conn->lua_websocket_state =
NULL;
17098 if (conn->
phys_ctx->callbacks.connection_close !=
NULL) {
17100 conn->
phys_ctx->callbacks.connection_close(conn);
17110#if defined(USE_SERVER_STATS)
17111 conn->conn_state = 7;
17114#if defined(USE_MBEDTLS)
17119#elif !defined(NO_SSL)
17130#if defined(__ZEPHYR__)
17139 if (conn->
phys_ctx->callbacks.connection_closed !=
NULL) {
17141 conn->
phys_ctx->callbacks.connection_closed(conn);
17147#if defined(USE_SERVER_STATS)
17148 conn->conn_state = 8;
17160#if defined(USE_WEBSOCKET)
17162 if (conn->in_websocket_handling) {
17182 for (i = 0; i < conn->
phys_ctx->cfg_worker_threads; i++) {
17190#if !defined(NO_SSL) && !defined(USE_MBEDTLS)
17198#if defined(USE_WEBSOCKET)
17239 if (conn ==
NULL) {
17249#if defined(GCC_DIAGNOSTIC)
17250#pragma GCC diagnostic push
17251#pragma GCC diagnostic ignored "-Wcast-align"
17257#if defined(GCC_DIAGNOSTIC)
17258#pragma GCC diagnostic pop
17280#if !defined(NO_SSL) && !defined(USE_MBEDTLS)
17281#if (defined(OPENSSL_API_1_1) || defined(OPENSSL_API_3_0)) \
17282 && !defined(NO_SSL_DL)
17290 "SSL_CTX_new error: %s",
17304 "SSL_CTX_new error: %s",
17314#if defined(USE_IPV6)
17316 :
sizeof(conn->
client.rsa.sin6);
17325 conn->
client.sock = sock;
17330 "%s: getsockname() failed: %s",
17341 "Can not create mutex");
17342#if !defined(NO_SSL) && !defined(USE_MBEDTLS)
17351#if !defined(NO_SSL) && !defined(USE_MBEDTLS)
17369 "Can not use SSL client certificate");
17383 "SSL_CTX_load_verify_locations error: %s ",
17400 "SSL connection error");
17443#if defined(MG_EXPERIMENTAL_INTERFACES)
17446 const char *protocol,
17455 if (error !=
NULL) {
17462 if ((host ==
NULL) || (protocol ==
NULL)) {
17469 "Invalid parameters");
17481#if defined(USE_WEBSOCKET)
17495 "Protocol %s not supported",
17504#if defined(USE_WEBSOCKET)
17512 ((error !=
NULL) ? error->text_buffer_size : 0),
17513 (path ? path :
""),
17517 (void *)init->callbacks);
17529 ((error !=
NULL) ? error->text_buffer_size
17535static const struct {
17540 {
"https://", 8, 443},
17542 {
"wss://", 6, 443},
17558 unsigned long port;
17564 if ((uri[0] ==
'*') && (uri[1] ==
'\0')) {
17575 for (i = 0; uri[i] != 0; i++) {
17584 if (uri[0] ==
'/') {
17628 unsigned long port = 0;
17760 "Invalid message size");
17771 "Message too large");
17783 "Malformed message");
17793 "No data received");
17834 "Bad request: Host mismatch");
17842 "Accept-Encoding"))
17844 &&
strstr(cl,
"gzip")) {
17850 "Transfer-Encoding"))
17922 "Transfer-Encoding"))
18000 "Parameter error");
18027 return (
ret == 0) ? -1 : +1;
18054 if (conn !=
NULL) {
18062 "Error sending request");
18074 if ((
ebuf[0] !=
'\0') && (conn !=
NULL)) {
18092#if defined(USE_WEBSOCKET)
18105#if !defined(_WIN32) && !defined(__ZEPHYR__)
18109 memset(&sa, 0,
sizeof(sa));
18116 if (
cdata->conn->phys_ctx) {
18117 if (
cdata->conn->phys_ctx->callbacks.init_thread) {
18121 cdata->conn->phys_ctx, 3);
18127 DEBUG_TRACE(
"%s",
"Websocket client thread exited\n");
18137 if (
cdata->conn->phys_ctx->callbacks.exit_thread) {
18138 cdata->conn->phys_ctx->callbacks.exit_thread(
cdata->conn->phys_ctx,
18168#if defined(USE_WEBSOCKET)
18170 static const char *
magic =
"x3JJHMbDL1EzLkh9GBhXDw==";
18175#if defined(__clang__)
18176#pragma clang diagnostic push
18177#pragma clang diagnostic ignored "-Wformat-nonliteral"
18195 "Unexpected error");
18203 "GET %s HTTP/1.1\r\n"
18205 "Upgrade: websocket\r\n"
18206 "Connection: Upgrade\r\n"
18207 "Sec-WebSocket-Key: %s\r\n"
18208 "Sec-WebSocket-Version: 13\r\n"
18209 "Sec-WebSocket-Extensions: %s\r\n"
18219 "GET %s HTTP/1.1\r\n"
18221 "Upgrade: websocket\r\n"
18222 "Connection: Upgrade\r\n"
18223 "Sec-WebSocket-Key: %s\r\n"
18224 "Sec-WebSocket-Version: 13\r\n"
18236 "GET %s HTTP/1.1\r\n"
18238 "Upgrade: websocket\r\n"
18239 "Connection: Upgrade\r\n"
18240 "Sec-WebSocket-Key: %s\r\n"
18241 "Sec-WebSocket-Version: 13\r\n"
18242 "Sec-WebSocket-Extensions: %s\r\n"
18250 "GET %s HTTP/1.1\r\n"
18252 "Upgrade: websocket\r\n"
18253 "Connection: Upgrade\r\n"
18254 "Sec-WebSocket-Key: %s\r\n"
18255 "Sec-WebSocket-Version: 13\r\n"
18268 "Error sending request");
18273 conn->data_len = 0;
18278 conn->request_info.local_uri_raw =
conn->request_info.request_uri;
18279 conn->request_info.local_uri =
conn->request_info.local_uri_raw;
18281#if defined(__clang__)
18282#pragma clang diagnostic pop
18285 if (
conn->response_info.status_code != 101) {
18296 "Unexpected server reply");
18317 conn->phys_ctx->worker_threadids =
18319 if (!
conn->phys_ctx->worker_threadids) {
18327 conn->phys_ctx->user_data = user_data;
18329 conn->phys_ctx->cfg_worker_threads = 1;
18336 conn->phys_ctx->worker_threadids)
18338 conn->phys_ctx->cfg_worker_threads = 0;
18343 "Websocket client connect thread could not be started\r\n");
18496#if defined(USE_SERVER_STATS)
18497 conn->conn_state = 2;
18501 if (conn->
phys_ctx->callbacks.init_connection !=
NULL) {
18503 void *conn_data =
NULL;
18504 conn->
phys_ctx->callbacks.init_connection(conn, &conn_data);
18525#if defined(USE_SERVER_STATS)
18531 DEBUG_TRACE(
"Start processing connection from %s",
18537 DEBUG_TRACE(
"calling get_request (%i times for this connection)",
18540#if defined(USE_SERVER_STATS)
18541 conn->conn_state = 3;
18560 "Bad HTTP version: [%s]",
18565 if (
ebuf[0] ==
'\0') {
18603 if (
ebuf[0] !=
'\0') {
18625 if (
ebuf[0] ==
'\0') {
18685 DEBUG_TRACE(
"internal error: data_len = %li, buf_size = %li",
18693 DEBUG_TRACE(
"Done processing connection from %s (%f sec)",
18699#if defined(USE_SERVER_STATS)
18706#if defined(ALTERNATIVE_QUEUE)
18716 if (ctx->client_socks[i].in_use == 2) {
18718 if ((ctx->client_socks[i].in_use == 2) && !ctx->
stop_flag) {
18719 ctx->client_socks[i] = *
sp;
18720 ctx->client_socks[i].in_use = 1;
18752 if (
sp->in_use == 1) {
18760 if (
sp->in_use == 1) {
18822#if defined(USE_SERVER_STATS)
18840#if defined(USE_SERVER_STATS)
18885 "Internal error: Invalid worker index %i",
18897 "Out of memory: Cannot allocate buffer for worker %i",
18917#if defined(USE_SERVER_STATS)
18918 conn->conn_state = 1;
18929#if defined(USE_SERVER_STATS)
18930 conn->conn_close_time = 0;
18949 (conn->
client.is_ssl ?
"SSL " :
""),
18954 if (conn->
client.is_ssl) {
18956#if defined(USE_MBEDTLS)
18960 (
int *)&(conn->
client.sock),
18974#elif !defined(NO_SSL)
18986#if defined(USE_HTTP2)
18988 && (!
memcmp(
tls.alpn_proto,
"\x02h2", 3))) {
19041#if defined(USE_SERVER_STATS)
19042 conn->conn_close_time = time(
NULL);
19069#if defined(USE_SERVER_STATS)
19070 conn->conn_state = 9;
19088#if !defined(__ZEPHYR__)
19092 memset(&sa, 0,
sizeof(sa));
19111#if !defined(__ZEPHYR__)
19114 memset(&so, 0,
sizeof(so));
19121 "%s: %s is not allowed to connect",
19133 "%s: getsockname() failed: %s",
19138#if !defined(__ZEPHYR__)
19156 "%s: setsockopt(SOL_SOCKET SO_KEEPALIVE) failed: %s",
19175 "%s: setsockopt(IPPROTO_TCP TCP_NODELAY) failed: %s",
19209#elif defined(USE_MASTER_THREAD_PRIORITY)
19236#if defined(USE_LUA)
19237 if (ctx->lua_background_state) {
19250 "lua_background_script",
19260 ctx->lua_bg_log_available = 1;
19305#if defined(ALTERNATIVE_QUEUE)
19323#if defined(USE_LUA)
19325 if (ctx->lua_background_state) {
19327 ctx->lua_bg_log_available = 0;
19339 "lua_background_script",
19345 ctx->lua_background_state = 0;
19381#if !defined(__ZEPHYR__)
19385 memset(&sa, 0,
sizeof(sa));
19416#if defined(ALTERNATIVE_QUEUE)
19418 if (ctx->client_wait_events !=
NULL) {
19419 for (i = 0; (unsigned)
i < ctx->cfg_worker_threads; i++) {
19422 mg_free(ctx->client_wait_events);
19433#if defined(USE_LUA)
19439 if (ctx->
dd.config[i] !=
NULL) {
19440#if defined(_MSC_VER)
19441#pragma warning(suppress : 6001)
19448 while (ctx->
dd.handlers) {
19455#if defined(USE_MBEDTLS)
19456 if (ctx->
dd.ssl_ctx !=
NULL) {
19462#elif !defined(NO_SSL)
19464 if (ctx->
dd.ssl_ctx !=
NULL) {
19465 void *ssl_ctx = (
void *)ctx->
dd.ssl_ctx;
19514#if defined(USE_TIMERS)
19527#if defined(USE_LUA)
19547#if defined(_MSC_VER)
19548#pragma warning(push)
19550#pragma warning(disable : 4996)
19553#if defined(_MSC_VER)
19554#pragma warning(pop)
19573#elif defined(__ZEPHYR__)
19616 const char *
name, *
value, *default_value;
19621 const char **options =
19626 if (error !=
NULL) {
19646 "Library uninitialized");
19665 ctx->
dd.auth_nonce_mask =
19666 (uint64_t)
get_random() ^ (uint64_t)(ptrdiff_t)(options);
19672 tls.is_master = -1;
19675 tls.pthread_cond_helper_mutex =
NULL;
19680#if !defined(ALTERNATIVE_QUEUE)
19686#if defined(USE_LUA)
19691 "Cannot initialize thread synchronization objects";
19720 ctx->
dd.handlers =
NULL;
19723#if defined(USE_LUA)
19728 while (options && (
name = *options++) !=
NULL) {
19736 "Invalid configuration option: %s",
19742 }
else if ((
value = *options++) ==
NULL) {
19749 "Invalid configuration option value: %s",
19756 if (ctx->
dd.config[idx] !=
NULL) {
19769 if ((ctx->
dd.config[i] ==
NULL) && (default_value !=
NULL)) {
19785 "Invalid configuration option value: %s",
19795#if !defined(ALTERNATIVE_QUEUE)
19806 "Invalid configuration option value: %s",
19817 "Out of memory: Cannot allocate %s",
19824 "Out of memory: Cannot allocate %s",
19848 "Invalid configuration option value: %s",
19857#if defined(NO_FILES)
19865 "Invalid configuration option value: %s",
19876#if defined(USE_LUA)
19878 ctx->lua_bg_log_available = 0;
19893 "lua_background_script load error: %s",
19900 "Error in script %s: %s",
19937 "lua_background_script start error: %s",
19944 "Error in script %s: %s",
19956 ctx->lua_background_state = (
void *)state;
19960 ctx->lua_background_state = 0;
19965#if !defined(NO_FILESYSTEMS)
19967 const char *
err_msg =
"Invalid global password file";
19985#if defined(USE_MBEDTLS)
19987 const char *
err_msg =
"Error initializing SSL context";
20004#elif !defined(NO_SSL)
20006 const char *
err_msg =
"Error initializing SSL context";
20025 const char *
err_msg =
"Failed to setup server ports";
20043#if !defined(_WIN32) && !defined(__ZEPHYR__)
20045 const char *
err_msg =
"Failed to run as configured user";
20064 const char *
err_msg =
"Failed to setup access control list";
20087 const char *
err_msg =
"Not enough memory for worker thread ID array";
20108 "Not enough memory for worker thread connection array";
20124#if defined(ALTERNATIVE_QUEUE)
20125 ctx->client_wait_events =
20127 sizeof(ctx->client_wait_events[0]),
20129 if (ctx->client_wait_events ==
NULL) {
20130 const char *
err_msg =
"Not enough memory for worker event array";
20147 ctx->client_socks =
20149 sizeof(ctx->client_socks[0]),
20151 if (ctx->client_socks ==
NULL) {
20152 const char *
err_msg =
"Not enough memory for worker socket array";
20154 mg_free(ctx->client_wait_events);
20170 for (i = 0; (unsigned)
i < ctx->cfg_worker_threads; i++) {
20172 if (ctx->client_wait_events[i] == 0) {
20173 const char *
err_msg =
"Error creating worker event %i";
20180 mg_free(ctx->client_wait_events);
20198#if defined(USE_TIMERS)
20200 const char *
err_msg =
"Error creating timers";
20243 "Cannot start worker thread %i: error %ld",
20256 "Cannot create threads: error %ld",
20265 "Cannot create first worker thread: error %ld",
20287 const char **options)
20301 const char **options,
20306 const char *default_value;
20311 if (error !=
NULL) {
20318 if ((ctx ==
NULL) || (options ==
NULL)) {
20325 "Invalid parameters");
20337 "Server already stopped");
20359 while (options && (
name = *options++) !=
NULL) {
20367 "Invalid option: %s",
20372 }
else if ((
value = *options++) ==
NULL) {
20379 "Invalid option value: %s",
20403 "Mandatory option %s missing",
20413 default_value = ctx->
dd.config[i];
20425#if defined(USE_LUA) && defined(USE_WEBSOCKET)
20429#if !defined(NO_SSL) && !defined(USE_MBEDTLS)
20438 "Initializing SSL context failed");
20455 "domain %s already in use",
20462 "Domain %s specified by %s is already in use",
20503#if !defined(NO_FILES)
20506#if !defined(NO_SSL) || defined(USE_MBEDTLS)
20509#if !defined(NO_CGI)
20512#if defined(USE_IPV6)
20515#if defined(USE_WEBSOCKET)
20518#if defined(USE_LUA)
20521#if defined(USE_DUKTAPE)
20524#if !defined(NO_CACHING)
20527#if defined(USE_SERVER_STATS)
20530#if defined(USE_ZLIB)
20533#if defined(USE_HTTP2)
20536#if defined(USE_X_DOM_SOCKET)
20542#if defined(MG_LEGACY_INTERFACE)
20545#if defined(MG_EXPERIMENTAL_INTERFACES)
20548#if !defined(NO_RESPONSE_BUFFERING)
20551#if defined(MEMORY_DEBUGGING)
20565 if ((
size_t)(end - *
dst) >
len) {
20585 static const char eol[] =
"\r\n",
eoobj[] =
"\r\n}\r\n";
20587 static const char eol[] =
"\n",
eoobj[] =
"\n}\n";
20590 if ((buffer ==
NULL) || (buflen < 1)) {
20595 end = buffer + buflen;
20597 if (buflen > (
int)(
sizeof(
eoobj) - 1)) {
20601 end -=
sizeof(
eoobj) - 1;
20614 "%s\"version\" : \"%s\"",
20630#if defined(_MSC_VER)
20631#pragma warning(push)
20633#pragma warning(disable : 4996)
20636#if defined(_MSC_VER)
20637#pragma warning(pop)
20647 ",%s\"os\" : \"Windows %u.%u\"",
20657 ",%s\"cpu\" : \"type %u, cores %u, mask %x\"",
20659 (
unsigned)
si.wProcessorArchitecture,
20660 (
unsigned)
si.dwNumberOfProcessors,
20661 (
unsigned)
si.dwActiveProcessorMask);
20663#elif defined(__ZEPHYR__)
20668 ",%s\"os\" : \"%s %s\"",
20682 ",%s\"os\" : \"%s %s (%s) - %s\"",
20698 ",%s\"features\" : %lu"
20699 ",%s\"feature_list\" : \"Server:%s%s%s%s%s%s%s%s%s\"",
20715#if defined(USE_LUA)
20720 ",%s\"lua_version\" : \"%u (%s)\"",
20726#if defined(USE_DUKTAPE)
20731 ",%s\"javascript\" : \"Duktape %u.%u.%u\"",
20742#if defined(BUILD_DATE)
20745#if defined(GCC_DIAGNOSTIC)
20746#if GCC_VERSION >= 40900
20747#pragma GCC diagnostic push
20751#pragma GCC diagnostic ignored "-Wdate-time"
20755#if defined(GCC_DIAGNOSTIC)
20756#if GCC_VERSION >= 40900
20757#pragma GCC diagnostic pop
20772#if defined(_MSC_VER)
20777 ",%s\"compiler\" : \"MSC: %u (%u)\"",
20782#elif defined(__MINGW64__)
20787 ",%s\"compiler\" : \"MinGW64: %u.%u\"",
20796 ",%s\"compiler\" : \"MinGW32: %u.%u\"",
20801#elif defined(__MINGW32__)
20806 ",%s\"compiler\" : \"MinGW32: %u.%u\"",
20811#elif defined(__clang__)
20816 ",%s\"compiler\" : \"clang: %u.%u.%u (%s)\"",
20823#elif defined(__GNUC__)
20828 ",%s\"compiler\" : \"gcc: %u.%u.%u\"",
20834#elif defined(__INTEL_COMPILER)
20839 ",%s\"compiler\" : \"Intel C/C++: %u\"",
20843#elif defined(__BORLANDC__)
20848 ",%s\"compiler\" : \"Borland C: 0x%x\"",
20852#elif defined(__SUNPRO_C)
20857 ",%s\"compiler\" : \"Solaris: 0x%x\"",
20866 ",%s\"compiler\" : \"other\"",
20879 ",%s\"data_model\" : \"int:%u/%u/%u/%u, float:%u/%u/%u, "
20881 "ptr:%u, size:%u, time:%u\"",
20883 (
unsigned)
sizeof(
short),
20884 (
unsigned)
sizeof(
int),
20885 (
unsigned)
sizeof(
long),
20886 (
unsigned)
sizeof(
long long),
20887 (
unsigned)
sizeof(
float),
20888 (
unsigned)
sizeof(
double),
20889 (
unsigned)
sizeof(
long double),
20890 (
unsigned)
sizeof(
char),
20891 (
unsigned)
sizeof(
wchar_t),
20892 (
unsigned)
sizeof(
void *),
20893 (
unsigned)
sizeof(
size_t),
20894 (
unsigned)
sizeof(time_t));
20913#if defined(USE_SERVER_STATS)
20918 static const char eol[] =
"\r\n",
eoobj[] =
"\r\n}\r\n";
20920 static const char eol[] =
"\n",
eoobj[] =
"\n}\n";
20924 if ((buffer ==
NULL) || (buflen < 1)) {
20929 end = buffer + buflen;
20931 if (buflen > (
int)(
sizeof(
eoobj) - 1)) {
20934 end -=
sizeof(
eoobj) - 1;
20952 "%s\"memory\" : {%s"
20953 "\"blocks\" : %i,%s"
20991 ",%s\"connections\" : {%s"
20992 "\"active\" : %i,%s"
20993 "\"maxActive\" : %i,%s"
21007#if !defined(ALTERNATIVE_QUEUE)
21012 ",%s\"queue\" : {%s"
21013 "\"length\" : %i,%s"
21014 "\"filled\" : %i,%s"
21015 "\"maxFilled\" : %i,%s"
21036 ",%s\"requests\" : {%s"
21037 "\"total\" : %lu%s"
21041 (
unsigned long)ctx->total_requests,
21054 ",%s\"data\" : {%s"
21076 ",%s\"time\" : {%s"
21077 "\"uptime\" : %.0f,%s"
21078 "\"start\" : \"%s\",%s"
21079 "\"now\" : \"%s\"%s"
21101 if ((buffer !=
NULL) && (buflen > 0)) {
21113 if (conn !=
NULL) {
21119#if defined(MG_EXPERIMENTAL_INTERFACES)
21136 static const char eol[] =
"\r\n",
eoobj[] =
"\r\n}\r\n";
21138 static const char eol[] =
"\n",
eoobj[] =
"\n}\n";
21141 if ((buffer ==
NULL) || (buflen < 1)) {
21146 end = buffer + buflen;
21148 if (buflen > (
int)(
sizeof(
eoobj) - 1)) {
21154 if ((ctx ==
NULL) || (idx < 0)) {
21174#if defined(USE_SERVER_STATS)
21175 state = conn->conn_state;
21213 if ((state >= 3) && (state < 9)) {
21218 "%s\"connection\" : {%s"
21220 "\"protocol\" : \"%s\",%s"
21221 "\"addr\" : \"%s\",%s"
21224 "\"handled_requests\" : %u%s"
21242 if ((state >= 4) && (state < 6)) {
21247 "%s%s\"request_info\" : {%s"
21248 "\"method\" : \"%s\",%s"
21249 "\"uri\" : \"%s\",%s"
21250 "\"query\" : %s%s%s%s"
21267 if ((state >= 2) && (state < 9)) {
21277#if defined(USE_SERVER_STATS)
21295 "%s%s\"time\" : {%s"
21296 "\"uptime\" : %.0f,%s"
21297 "\"start\" : \"%s\",%s"
21298 "\"closed\" : \"%s\"%s"
21318 "%s%s\"user\" : {%s"
21319 "\"name\" : \"%s\",%s"
21335 "%s%s\"data\" : {%s"
21342 conn->consumed_content,
21344 conn->num_bytes_sent,
21354 "%s%s\"state\" : \"%s\"",
21438#if defined(USE_LUA)
21445#if (defined(OPENSSL_API_1_0) || defined(OPENSSL_API_1_1) \
21446 || defined(OPENSSL_API_3_0)) \
21447 && !defined(NO_SSL)
21488#if (defined(OPENSSL_API_1_0) || defined(OPENSSL_API_1_1)) && !defined(NO_SSL)
21504#if defined(USE_LUA)
static int esc(const char **)
Map escape sequences into their equivalent symbols.
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
static unsigned int total
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
#define INVALID_HANDLE_VALUE
R__EXTERN C unsigned int sleep(unsigned int seconds)
static void process_new_connection(struct mg_connection *conn)
static int is_authorized_for_put(struct mg_connection *conn)
static int consume_socket(struct mg_context *ctx, struct socket *sp, int thread_index)
static int parse_http_request(char *buf, int len, struct mg_request_info *ri)
void mg_send_mime_file2(struct mg_connection *conn, const char *path, const char *mime_type, const char *additional_headers)
static pthread_key_t sTlsKey
static int modify_passwords_file(const char *fname, const char *domain, const char *user, const char *pass, const char *ha1)
static void sockaddr_to_string(char *buf, size_t len, const union usa *usa)
static void open_auth_file(struct mg_connection *conn, const char *path, struct mg_file *filep)
int mg_strncasecmp(const char *s1, const char *s2, size_t len)
static int check_authorization(struct mg_connection *conn, const char *path)
#define mg_malloc_ctx(a, c)
static void redirect_to_https_port(struct mg_connection *conn, int port)
static int should_switch_to_protocol(const struct mg_connection *conn)
void mg_unlock_connection(struct mg_connection *conn)
static void mkcol(struct mg_connection *conn, const char *path)
static void remove_bad_file(const struct mg_connection *conn, const char *path)
const struct mg_option * mg_get_valid_options(void)
static int mg_path_suspicious(const struct mg_connection *conn, const char *path)
static int set_non_blocking_mode(SOCKET sock)
static void ssl_locking_callback(int mode, int mutex_num, const char *file, int line)
int mg_send_http_error(struct mg_connection *conn, int status, const char *fmt,...)
static const char * get_rel_url_at_current_server(const char *uri, const struct mg_connection *conn)
static void mg_cry_internal_impl(const struct mg_connection *conn, const char *func, unsigned line, const char *fmt, va_list ap)
void mg_lock_context(struct mg_context *ctx)
#define MAX_WORKER_THREADS
@ PROTOCOL_TYPE_WEBSOCKET
static void put_file(struct mg_connection *conn, const char *path)
static void do_ssi_exec(struct mg_connection *conn, char *tag)
static void tls_dtor(void *key)
const void * SOCK_OPT_TYPE
static int header_has_option(const char *header, const char *option)
int mg_send_http_redirect(struct mg_connection *conn, const char *target_url, int redirect_code)
int mg_get_cookie(const char *cookie_header, const char *var_name, char *dst, size_t dst_size)
static int ssl_get_client_cert_info(const struct mg_connection *conn, struct mg_client_cert *client_cert)
#define mg_cry_ctx_internal(ctx, fmt,...)
static void mg_snprintf(const struct mg_connection *conn, int *truncated, char *buf, size_t buflen, const char *fmt,...)
#define mg_opendir(conn, x)
static char * mg_strndup_ctx(const char *ptr, size_t len, struct mg_context *ctx)
static int put_dir(struct mg_connection *conn, const char *path)
static void send_static_cache_header(struct mg_connection *conn)
static void handle_cgi_request(struct mg_connection *conn, const char *prog, unsigned char cgi_config_idx)
static ptrdiff_t mg_atomic_dec(volatile ptrdiff_t *addr)
static int print_dav_dir_entry(struct de *de, void *data)
static void delete_file(struct mg_connection *conn, const char *path)
#define mg_calloc_ctx(a, b, c)
struct mg_connection * mg_connect_websocket_client_secure(const struct mg_client_options *client_options, char *error_buffer, size_t error_buffer_size, const char *path, const char *origin, mg_websocket_data_handler data_func, mg_websocket_close_handler close_func, void *user_data)
int mg_get_server_ports(const struct mg_context *ctx, int size, struct mg_server_port *ports)
static ptrdiff_t mg_atomic_inc(volatile ptrdiff_t *addr)
int mg_printf(struct mg_connection *conn, const char *fmt,...)
static int abort_cgi_process(void *data)
static int should_keep_alive(const struct mg_connection *conn)
static __inline void * mg_malloc(size_t a)
static int mg_fopen(const struct mg_connection *conn, const char *path, int mode, struct mg_file *filep)
void mg_disable_connection_keep_alive(struct mg_connection *conn)
static void mg_global_lock(void)
static void handle_static_file_request(struct mg_connection *conn, const char *path, struct mg_file *filep, const char *mime_type, const char *additional_headers)
static int ssl_use_pem_file(struct mg_context *phys_ctx, struct mg_domain_context *dom_ctx, const char *pem, const char *chain)
static const char * ssl_error(void)
static int must_hide_file(struct mg_connection *conn, const char *path)
static void log_access(const struct mg_connection *)
struct mg_connection * mg_connect_client_secure(const struct mg_client_options *client_options, char *error_buffer, size_t error_buffer_size)
#define mg_remove(conn, x)
int mg_send_http_ok(struct mg_connection *conn, const char *mime_type, long long content_length)
static void close_all_listening_sockets(struct mg_context *ctx)
void mg_send_file(struct mg_connection *conn, const char *path)
static void send_authorization_request(struct mg_connection *conn, const char *realm)
static pid_t spawn_process(struct mg_connection *conn, const char *prog, char *envblk, char *envp[], int fdin[2], int fdout[2], int fderr[2], const char *dir, unsigned char cgi_config_idx)
static int check_password(const char *method, const char *ha1, const char *uri, const char *nonce, const char *nc, const char *cnonce, const char *qop, const char *response)
static int check_acl(struct mg_context *phys_ctx, const union usa *sa)
static const struct mg_option config_options[]
static const struct mg_http_method_info * get_http_method_info(const char *method)
#define STOP_FLAG_IS_ZERO(f)
const char * mg_get_response_code_text(const struct mg_connection *conn, int response_code)
static int get_response(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int *err)
static void mg_cry_internal_wrap(const struct mg_connection *conn, struct mg_context *ctx, const char *func, unsigned line, const char *fmt,...)
static int set_uid_option(struct mg_context *phys_ctx)
static int switch_domain_context(struct mg_connection *conn)
static struct mg_connection * fake_connection(struct mg_connection *fc, struct mg_context *ctx)
static void reset_per_request_attributes(struct mg_connection *conn)
static void handle_file_based_request(struct mg_connection *conn, const char *path, struct mg_file *filep)
#define FUNCTION_MAY_BE_UNUSED
static pthread_mutex_t * ssl_mutexes
static int get_option_index(const char *name)
static char * mg_strdup(const char *str)
static void send_no_cache_header(struct mg_connection *conn)
static void master_thread_run(struct mg_context *ctx)
static int prepare_cgi_environment(struct mg_connection *conn, const char *prog, struct cgi_environment *env, unsigned char cgi_config_idx)
static const char month_names[][4]
const struct mg_response_info * mg_get_response_info(const struct mg_connection *conn)
static __inline void * mg_realloc(void *a, size_t b)
static void accept_new_connection(const struct socket *listener, struct mg_context *ctx)
static volatile ptrdiff_t cryptolib_users
static int get_message(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int *err)
static pthread_mutex_t global_lock_mutex
struct mg_context * mg_start2(struct mg_init_data *init, struct mg_error_data *error)
#define CGI_ENVIRONMENT_SIZE
static int parse_http_headers(char **buf, struct mg_header hdr[(64)])
static long ssl_get_protocol(int version_id)
void * mg_get_user_context_data(const struct mg_connection *conn)
static int mg_init_library_called
long long mg_store_body(struct mg_connection *conn, const char *path)
struct mg_connection * mg_download(const char *host, int port, int use_ssl, char *ebuf, size_t ebuf_len, const char *fmt,...)
#define DEBUG_ASSERT(cond)
static size_t mg_str_append(char **dst, char *end, const char *src)
static int pull_inner(FILE *fp, struct mg_connection *conn, char *buf, int len, double timeout)
int mg_get_response(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int timeout)
#define MG_FILE_COMPRESSION_SIZE_LIMIT
#define USA_IN_PORT_UNSAFE(s)
static struct mg_connection * mg_connect_client_impl(const struct mg_client_options *client_options, int use_ssl, char *ebuf, size_t ebuf_len)
unsigned mg_check_feature(unsigned feature)
static int mg_read_inner(struct mg_connection *conn, void *buf, size_t len)
static int mg_send_http_error_impl(struct mg_connection *conn, int status, const char *fmt, va_list args)
struct mg_context * mg_start(const struct mg_callbacks *callbacks, void *user_data, const char **options)
#define MG_FOPEN_MODE_READ
#define STOP_FLAG_ASSIGN(f, v)
static int extention_matches_script(struct mg_connection *conn, const char *filename)
static void get_host_from_request_info(struct vec *host, const struct mg_request_info *ri)
void mg_set_websocket_handler(struct mg_context *ctx, const char *uri, mg_websocket_connect_handler connect_handler, mg_websocket_ready_handler ready_handler, mg_websocket_data_handler data_handler, mg_websocket_close_handler close_handler, void *cbdata)
int mg_start_domain(struct mg_context *ctx, const char **options)
static pthread_mutexattr_t pthread_mutex_attr
void mg_unlock_context(struct mg_context *ctx)
static int ssl_servername_callback(SSL *ssl, int *ad, void *arg)
int mg_modify_passwords_file(const char *fname, const char *domain, const char *user, const char *pass)
static char * skip_quoted(char **buf, const char *delimiters, const char *whitespace, char quotechar)
static void fclose_on_exec(struct mg_file_access *filep, struct mg_connection *conn)
int mg_start_thread(mg_thread_func_t func, void *param)
static const char * get_header(const struct mg_header *hdr, int num_hdr, const char *name)
static int mg_inet_pton(int af, const char *src, void *dst, size_t dstlen, int resolve_src)
static int init_ssl_ctx_impl(struct mg_context *phys_ctx, struct mg_domain_context *dom_ctx, const char *pem, const char *chain)
static int connect_socket(struct mg_context *ctx, const char *host, int port, int use_ssl, char *ebuf, size_t ebuf_len, SOCKET *sock, union usa *sa)
unsigned mg_init_library(unsigned features)
struct mg_connection * mg_connect_client(const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size)
static int forward_body_data(struct mg_connection *conn, FILE *fp, SOCKET sock, SSL *ssl)
static int set_gpass_option(struct mg_context *phys_ctx, struct mg_domain_context *dom_ctx)
static int skip_to_end_of_word_and_terminate(char **ppw, int eol)
static int get_request(struct mg_connection *conn, char *ebuf, size_t ebuf_len, int *err)
static int set_tcp_nodelay(const struct socket *so, int nodelay_on)
int mg_get_var(const char *data, size_t data_len, const char *name, char *dst, size_t dst_len)
#define ARRAY_SIZE(array)
static int parse_port_string(const struct vec *vec, struct socket *so, int *ip_version)
static int get_first_ssl_listener_index(const struct mg_context *ctx)
void mg_send_mime_file(struct mg_connection *conn, const char *path, const char *mime_type)
const char * mg_get_header(const struct mg_connection *conn, const char *name)
#define mg_mkdir(conn, path, mode)
int mg_split_form_urlencoded(char *data, struct mg_header *form_fields, unsigned num_form_fields)
static int hexdump2string(void *mem, int memlen, char *buf, int buflen)
static const struct mg_http_method_info http_methods[]
static int mg_poll(struct pollfd *pfd, unsigned int n, int milliseconds, const stop_flag_t *stop_flag)
static void handle_directory_request(struct mg_connection *conn, const char *dir)
static int set_ports_option(struct mg_context *phys_ctx)
static int read_auth_file(struct mg_file *filep, struct read_auth_file_struct *workdata, int depth)
static int mg_start_thread_with_id(mg_thread_func_t func, void *param, pthread_t *threadidptr)
unsigned mg_exit_library(void)
static void * load_tls_dll(char *ebuf, size_t ebuf_len, const char *dll_name, struct ssl_func *sw, int *feature_missing)
static void gmt_time_string(char *buf, size_t buf_len, time_t *t)
int mg_send_digest_access_authentication_request(struct mg_connection *conn, const char *realm)
static const char * mg_strcasestr(const char *big_str, const char *small_str)
struct mg_connection * mg_connect_websocket_client(const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size, const char *path, const char *origin, mg_websocket_data_handler data_func, mg_websocket_close_handler close_func, void *user_data)
static int pull_all(FILE *fp, struct mg_connection *conn, char *buf, int len)
static void handle_ssi_file_request(struct mg_connection *conn, const char *path, struct mg_file *filep)
int mg_write(struct mg_connection *conn, const void *buf, size_t len)
static int set_throttle(const char *spec, const union usa *rsa, const char *uri)
static void ssl_info_callback(const SSL *ssl, int what, int ret)
static void bin2str(char *to, const unsigned char *p, size_t len)
const struct mg_request_info * mg_get_request_info(const struct mg_connection *conn)
#define MG_FOPEN_MODE_APPEND
char * mg_md5(char buf[33],...)
#define STOP_FLAG_IS_TWO(f)
static const char * next_option(const char *list, struct vec *val, struct vec *eq_val)
static const char * suggest_connection_header(const struct mg_connection *conn)
static ptrdiff_t match_prefix_strlen(const char *pattern, const char *str)
static int alloc_vprintf(char **out_buf, char *prealloc_buf, size_t prealloc_size, const char *fmt, va_list ap)
static time_t parse_date_string(const char *datetime)
static void do_ssi_include(struct mg_connection *conn, const char *ssi, char *tag, int include_level)
static void uninitialize_openssl(void)
int mg_get_request_link(const struct mg_connection *conn, char *buf, size_t buflen)
static int parse_match_net(const struct vec *vec, const union usa *sa, int no_strict)
static const struct @143 abs_uri_protocols[]
int mg_modify_passwords_file_ha1(const char *fname, const char *domain, const char *user, const char *ha1)
static void send_options(struct mg_connection *conn)
static int lowercase(const char *s)
static void release_handler_ref(struct mg_connection *conn, struct mg_handler_info *handler_info)
static int parse_range_header(const char *header, int64_t *a, int64_t *b)
static int mg_stat(const struct mg_connection *conn, const char *path, struct mg_file_stat *filep)
static int get_uri_type(const char *uri)
#define DEBUG_TRACE(fmt,...)
static void get_system_name(char **sysName)
int mg_url_encode(const char *src, char *dst, size_t dst_len)
static const char * header_val(const struct mg_connection *conn, const char *header)
#define mg_cry_internal(conn, fmt,...)
static int set_acl_option(struct mg_context *phys_ctx)
static void mg_set_thread_name(const char *name)
static void get_mime_type(struct mg_connection *conn, const char *path, struct vec *vec)
static int set_blocking_mode(SOCKET sock)
static void send_file_data(struct mg_connection *conn, struct mg_file *filep, int64_t offset, int64_t len)
#define MAX_CGI_ENVIR_VARS
static char * mg_strdup_ctx(const char *str, struct mg_context *ctx)
struct mg_connection * mg_connect_websocket_client_extensions(const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size, const char *path, const char *origin, const char *extensions, mg_websocket_data_handler data_func, mg_websocket_close_handler close_func, void *user_data)
int mg_url_decode(const char *src, int src_len, char *dst, int dst_len, int is_form_url_encoded)
static int parse_auth_header(struct mg_connection *conn, char *buf, size_t buf_size, struct ah *ah)
void mg_set_user_connection_data(const struct mg_connection *const_conn, void *data)
int mg_get_var2(const char *data, size_t data_len, const char *name, char *dst, size_t dst_len, size_t occurrence)
static int is_not_modified(const struct mg_connection *conn, const struct mg_file_stat *filestat)
static void worker_thread_run(struct mg_connection *conn)
static void interpret_uri(struct mg_connection *conn, char *filename, size_t filename_buf_len, struct mg_file_stat *filestat, int *is_found, int *is_script_resource, int *is_websocket_request, int *is_put_or_delete_request, int *is_template_text)
static const char * get_proto_name(const struct mg_connection *conn)
static void * master_thread(void *thread_func_param)
static void mg_set_handler_type(struct mg_context *phys_ctx, struct mg_domain_context *dom_ctx, const char *uri, int handler_type, int is_delete_request, mg_request_handler handler, struct mg_websocket_subprotocols *subprotocols, mg_websocket_connect_handler connect_handler, mg_websocket_ready_handler ready_handler, mg_websocket_data_handler data_handler, mg_websocket_close_handler close_handler, mg_authorization_handler auth_handler, void *cbdata)
static int is_file_opened(const struct mg_file_access *fileacc)
static int get_http_header_len(const char *buf, int buflen)
struct mg_connection * mg_connect_websocket_client_secure_extensions(const struct mg_client_options *client_options, char *error_buffer, size_t error_buffer_size, const char *path, const char *origin, const char *extensions, mg_websocket_data_handler data_func, mg_websocket_close_handler close_func, void *user_data)
void mg_close_connection(struct mg_connection *conn)
static int is_valid_port(unsigned long port)
static void handle_propfind(struct mg_connection *conn, const char *path, struct mg_file_stat *filep)
static int mg_vprintf(struct mg_connection *conn, const char *fmt, va_list ap)
#define mg_realloc_ctx(a, b, c)
static void send_additional_header(struct mg_connection *conn)
static int push_all(struct mg_context *ctx, FILE *fp, SOCKET sock, SSL *ssl, const char *buf, int len)
static int is_put_or_delete_method(const struct mg_connection *conn)
static int read_message(FILE *fp, struct mg_connection *conn, char *buf, int bufsiz, int *nread)
static int print_dir_entry(struct de *de)
#define MG_FOPEN_MODE_WRITE
void * mg_get_user_connection_data(const struct mg_connection *conn)
static int authorize(struct mg_connection *conn, struct mg_file *filep, const char *realm)
static void send_ssi_file(struct mg_connection *, const char *, struct mg_file *, int)
#define mg_static_assert(cond, txt)
#define SOCKET_TIMEOUT_QUANTUM
static void produce_socket(struct mg_context *ctx, const struct socket *sp)
static ptrdiff_t match_prefix(const char *pattern, size_t pattern_len, const char *str)
int mg_send_chunk(struct mg_connection *conn, const char *chunk, unsigned int chunk_len)
static void remove_dot_segments(char *inout)
static int get_request_handler(struct mg_connection *conn, int handler_type, mg_request_handler *handler, struct mg_websocket_subprotocols **subprotocols, mg_websocket_connect_handler *connect_handler, mg_websocket_ready_handler *ready_handler, mg_websocket_data_handler *data_handler, mg_websocket_close_handler *close_handler, mg_authorization_handler *auth_handler, void **cbdata, struct mg_handler_info **handler_info)
void mg_set_auth_handler(struct mg_context *ctx, const char *uri, mg_authorization_handler handler, void *cbdata)
int mg_start_domain2(struct mg_context *ctx, const char **options, struct mg_error_data *error)
static int alloc_vprintf2(char **buf, const char *fmt, va_list ap)
static const struct @142 builtin_mime_types[]
static int extention_matches_template_text(struct mg_connection *conn, const char *filename)
static int is_in_script_path(const struct mg_connection *conn, const char *path)
static int should_decode_query_string(const struct mg_connection *conn)
static double mg_difftimespec(const struct timespec *ts_now, const struct timespec *ts_before)
static void free_context(struct mg_context *ctx)
static int sslize(struct mg_connection *conn, int(*func)(SSL *), const struct mg_client_options *client_options)
static void legacy_init(const char **options)
static void construct_etag(char *buf, size_t buf_len, const struct mg_file_stat *filestat)
int mg_get_context_info(const struct mg_context *ctx, char *buffer, int buflen)
static int refresh_trust(struct mg_connection *conn)
void * mg_get_thread_pointer(const struct mg_connection *conn)
static int compare_dir_entries(const void *p1, const void *p2)
static void mg_vsnprintf(const struct mg_connection *conn, int *truncated, char *buf, size_t buflen, const char *fmt, va_list ap)
static int should_decode_url(const struct mg_connection *conn)
static int mg_construct_local_link(const struct mg_connection *conn, char *buf, size_t buflen, const char *define_proto, int define_port, const char *define_uri)
char static_assert_replacement[1]
#define ERROR_TRY_AGAIN(err)
static unsigned long mg_current_thread_id(void)
static void mg_strlcpy(char *dst, const char *src, size_t n)
static int remove_directory(struct mg_connection *conn, const char *dir)
static const char * get_http_version(const struct mg_connection *conn)
static __inline void * mg_calloc(size_t a, size_t b)
static void handle_request(struct mg_connection *)
static int parse_http_response(char *buf, int len, struct mg_response_info *ri)
static void * cryptolib_dll_handle
static uint64_t mg_get_current_time_ns(void)
const char * mg_get_builtin_mime_type(const char *path)
static const char * mg_fgets(char *buf, size_t size, struct mg_file *filep)
int mg_read(struct mg_connection *conn, void *buf, size_t len)
#define IGNORE_UNUSED_RESULT(a)
static void addenv(struct cgi_environment *env, const char *fmt,...)
static void discard_unread_request_data(struct mg_connection *conn)
int mg_strcasecmp(const char *s1, const char *s2)
static int mg_fclose(struct mg_file_access *fileacc)
static struct mg_connection * mg_connect_websocket_client_impl(const struct mg_client_options *client_options, int use_ssl, char *error_buffer, size_t error_buffer_size, const char *path, const char *origin, const char *extensions, mg_websocket_data_handler data_func, mg_websocket_close_handler close_func, void *user_data)
void mg_set_request_handler(struct mg_context *ctx, const char *uri, mg_request_handler handler, void *cbdata)
static void * worker_thread(void *thread_func_param)
static __inline void mg_free(void *a)
static void handle_request_stat_log(struct mg_connection *conn)
int mg_check_digest_access_authentication(struct mg_connection *conn, const char *realm, const char *filename)
static int mg_join_thread(pthread_t threadid)
static void mg_global_unlock(void)
int mg_get_system_info(char *buffer, int buflen)
static void handle_not_modified_static_file_request(struct mg_connection *conn, struct mg_file *filep)
static int init_ssl_ctx(struct mg_context *phys_ctx, struct mg_domain_context *dom_ctx)
static void close_socket_gracefully(struct mg_connection *conn)
struct mg_context * mg_get_context(const struct mg_connection *conn)
static int is_ssl_port_used(const char *ports)
static void init_connection(struct mg_connection *conn)
static int print_props(struct mg_connection *conn, const char *uri, const char *name, struct mg_file_stat *filep)
static int dir_scan_callback(struct de *de, void *data)
static void set_close_on_exec(int fd, const struct mg_connection *conn, struct mg_context *ctx)
static int get_month_index(const char *s)
void mg_set_websocket_handler_with_subprotocols(struct mg_context *ctx, const char *uri, struct mg_websocket_subprotocols *subprotocols, mg_websocket_connect_handler connect_handler, mg_websocket_ready_handler ready_handler, mg_websocket_data_handler data_handler, mg_websocket_close_handler close_handler, void *cbdata)
static void * ssllib_dll_handle
static int mg_fgetc(struct mg_file *filep)
@ CONNECTION_TYPE_RESPONSE
@ CONNECTION_TYPE_INVALID
@ CONNECTION_TYPE_REQUEST
#define PASSWORDS_FILE_NAME
static void close_connection(struct mg_connection *conn)
@ ENABLE_DIRECTORY_LISTING
@ ACCESS_CONTROL_ALLOW_ORIGIN
@ ALLOW_INDEX_SCRIPT_SUB_RES
@ ACCESS_CONTROL_ALLOW_HEADERS
@ SSL_DEFAULT_VERIFY_PATHS
@ ACCESS_CONTROL_ALLOW_METHODS
@ STATIC_FILE_CACHE_CONTROL
@ PUT_DELETE_PASSWORDS_FILE
@ ENABLE_AUTH_DOMAIN_CHECK
@ ACCESS_CONTROL_ALLOW_CREDENTIALS
static int initialize_openssl(char *ebuf, size_t ebuf_len)
static int substitute_index_file(struct mg_connection *conn, char *path, size_t path_len, struct mg_file_stat *filestat)
void mg_stop(struct mg_context *ctx)
#define STRUCT_FILE_INITIALIZER
static volatile ptrdiff_t thread_idx_max
void * mg_get_user_data(const struct mg_context *ctx)
static int scan_directory(struct mg_connection *conn, const char *dir, void *data, int(*cb)(struct de *, void *))
static int push_inner(struct mg_context *ctx, FILE *fp, SOCKET sock, SSL *ssl, const char *buf, int len, double timeout)
const char * mg_version(void)
static uint64_t get_random(void)
void mg_lock_connection(struct mg_connection *conn)
int mg_send_file_body(struct mg_connection *conn, const char *path)
static int is_valid_http_method(const char *method)
static void url_decode_in_place(char *buf)
int mg_websocket_client_write(struct mg_connection *conn, int opcode, const char *data, size_t data_len)
int mg_response_header_add(struct mg_connection *conn, const char *header, const char *value, int value_len)
void *(* mg_thread_func_t)(void *)
int mg_response_header_send(struct mg_connection *conn)
int mg_websocket_write(struct mg_connection *conn, int opcode, const char *data, size_t data_len)
#define PRINTF_FORMAT_STRING(s)
int(* mg_authorization_handler)(struct mg_connection *conn, void *cbdata)
@ MG_CONFIG_TYPE_DIRECTORY
@ MG_CONFIG_TYPE_EXT_PATTERN
@ MG_CONFIG_TYPE_STRING_MULTILINE
@ MG_CONFIG_TYPE_STRING_LIST
@ MG_CONFIG_TYPE_YES_NO_OPTIONAL
@ MG_FEATURES_X_DOMAIN_SOCKET
@ MG_FEATURES_COMPRESSION
@ MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE
@ MG_WEBSOCKET_OPCODE_PONG
@ MG_WEBSOCKET_OPCODE_PING
void(* mg_websocket_ready_handler)(struct mg_connection *, void *)
int mg_response_header_add_lines(struct mg_connection *conn, const char *http1_headers)
#define PRINTF_ARGS(x, y)
int(* mg_websocket_data_handler)(struct mg_connection *, int, char *, size_t, void *)
int(* mg_request_handler)(struct mg_connection *conn, void *cbdata)
int mg_response_header_start(struct mg_connection *conn, int status)
void(* mg_websocket_close_handler)(const struct mg_connection *, void *)
int(* mg_websocket_connect_handler)(const struct mg_connection *, void *)
MD5_STATIC void md5_finish(md5_state_t *pms, md5_byte_t digest[16])
MD5_STATIC void md5_init(md5_state_t *pms)
MD5_STATIC void md5_append(md5_state_t *pms, const md5_byte_t *data, size_t nbytes)
RooArgList L(Args_t &&... args)
#define SSL_OP_CIPHER_SERVER_PREFERENCE
struct ssl_ctx_st SSL_CTX
#define SSL_OP_NO_TLSv1_3
#define SSL_OP_SINGLE_DH_USE
#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT
#define SSL_SESS_CACHE_BOTH
#define SSL_TLSEXT_ERR_OK
#define SSL_TLSEXT_ERR_NOACK
#define OPENSSL_INIT_LOAD_CRYPTO_STRINGS
#define SSL_OP_NO_COMPRESSION
#define SSL_ERROR_SYSCALL
#define SSL_ERROR_WANT_READ
#define SSL_ERROR_WANT_ACCEPT
#define SSL_ERROR_WANT_X509_LOOKUP
#define SSL_CB_HANDSHAKE_START
#define SSL_ERROR_WANT_CONNECT
#define SSL_OP_NO_TLSv1_2
#define SSL_OP_NO_RENEGOTIATION
#define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
#define TLSEXT_NAMETYPE_host_name
#define SSL_CB_HANDSHAKE_DONE
#define OPENSSL_INIT_LOAD_SSL_STRINGS
#define SSL_OP_NO_TLSv1_1
static int tls_feature_missing[TLS_END_OF_LIST]
#define SSL_ERROR_WANT_WRITE
static void free_buffered_response_header_list(struct mg_connection *conn)
SHA_API void SHA1_Init(SHA_CTX *context)
SHA_API void SHA1_Update(SHA_CTX *context, const uint8_t *data, const uint32_t len)
SHA_API void SHA1_Final(unsigned char *digest, SHA_CTX *context)
struct mg_connection * conn
struct mg_connection * conn
time_t last_throttle_time
struct mg_response_info response_info
struct mg_request_info request_info
struct mg_context * phys_ctx
struct mg_domain_context * dom_ctx
pthread_t * worker_threadids
unsigned long starter_thread_idx
struct mg_connection * worker_connections
struct socket * listening_sockets
pthread_mutex_t thread_mutex
struct mg_callbacks callbacks
struct mg_domain_context dd
struct pollfd * listening_socket_fds
unsigned int num_listening_sockets
unsigned int max_request_size
unsigned int cfg_worker_threads
pthread_mutex_t nonce_mutex
char * config[NUM_OPTIONS]
unsigned long nonce_count
int64_t ssl_cert_last_mtime
struct mg_domain_context * next
struct mg_handler_info * handlers
struct mg_file_access access
mg_request_handler handler
mg_authorization_handler auth_handler
mg_websocket_close_handler close_handler
struct mg_handler_info * next
mg_websocket_connect_handler connect_handler
struct mg_websocket_subprotocols * subprotocols
mg_websocket_data_handler data_handler
mg_websocket_ready_handler ready_handler
const struct mg_callbacks * callbacks
const char ** configuration_options
struct mg_header http_headers[(64)]
const char * local_uri_raw
const char * request_method
const char * query_string
const char * http_version
struct mg_header http_headers[(64)]
const char * http_version
const char ** subprotocols
struct mg_connection * conn
enum ssl_func_category required
mg_websocket_close_handler close_handler
mg_websocket_data_handler data_handler
struct mg_connection * conn