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/err.h>
1748#include <openssl/opensslv.h>
1749#include <openssl/pem.h>
1750#include <openssl/ssl.h>
1751#include <openssl/tls1.h>
1752#include <openssl/x509.h>
1754#if defined(WOLFSSL_VERSION)
1757#include "wolfssl_extras.inl"
1760#if defined(OPENSSL_IS_BORINGSSL)
1771#define CONF_modules_unload(a) ((void)0)
1772#define ENGINE_cleanup() ((void)0)
1776#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
1777#if !defined(OPENSSL_API_3_0)
1778#define OPENSSL_API_3_0
1780#define OPENSSL_REMOVE_THREAD_STATE()
1782#if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
1783#if !defined(OPENSSL_API_1_1)
1784#define OPENSSL_API_1_1
1786#define OPENSSL_REMOVE_THREAD_STATE()
1788#if !defined(OPENSSL_API_1_0)
1789#define OPENSSL_API_1_0
1791#define OPENSSL_REMOVE_THREAD_STATE() ERR_remove_thread_state(NULL)
1805#if !defined(NO_CACHING)
1826#if defined(USE_IPV6)
1829#if defined(USE_X_DOM_SOCKET)
1834#if defined(USE_X_DOM_SOCKET)
1835static unsigned short
1839 return s->
sin.sin_port;
1840#if defined(USE_IPV6)
1842 return s->sin6.sin6_port;
1847#if defined(USE_IPV6)
1848#define USA_IN_PORT_UNSAFE(s) \
1849 (((s)->sa.sa_family == AF_INET6) ? (s)->sin6.sin6_port : (s)->sin.sin_port)
1851#define USA_IN_PORT_UNSAFE(s) ((s)->sin.sin_port)
1882#define STRUCT_FILE_INITIALIZER \
1884 {(uint64_t)0, (time_t)0, 0, 0, 0}, \
1920#if defined(__linux__)
1930#if defined(USE_WEBSOCKET)
1940#if defined(USE_HTTP2)
1954#if defined(USE_TIMERS)
1962#if defined(USE_TIMERS)
1966#if defined(USE_4_CGI)
1971#if defined(USE_TIMERS)
1979#if defined(USE_TIMERS)
2012#if defined(MG_EXPERIMENTAL_INTERFACES)
2016#if defined(USE_DUKTAPE)
2020#if defined(USE_WEBSOCKET)
2023#if defined(USE_LUA) && defined(USE_WEBSOCKET)
2032#if !defined(NO_CACHING)
2060#if defined(__linux__)
2070#if defined(USE_WEBSOCKET)
2080#if defined(USE_HTTP2)
2094#if defined(USE_TIMERS)
2102#if defined(USE_TIMERS)
2106#if defined(USE_4_CGI)
2111#if defined(USE_TIMERS)
2119#if defined(USE_TIMERS)
2134 "index.xhtml,index.html,index.htm,"
2135 "index.lp,index.lsp,index.lua,index.cgi,"
2136 "index.shtml,index.php"},
2138 "index.xhtml,index.html,index.htm,index.cgi,index.shtml,index.php"},
2166#if defined(MG_EXPERIMENTAL_INTERFACES)
2170#if defined(USE_DUKTAPE)
2176#if defined(USE_WEBSOCKET)
2179#if defined(USE_LUA) && defined(USE_WEBSOCKET)
2187#if !defined(NO_CACHING)
2204 "config_options and enum not sync");
2261#if defined(USE_LUA) && defined(USE_WEBSOCKET)
2274#if defined(STOP_FLAG_NEEDS_LOCK)
2304#define STOP_FLAG_IS_ZERO(f) ((*(f)) == 0)
2305#define STOP_FLAG_IS_TWO(f) ((*(f)) == 2)
2306#define STOP_FLAG_ASSIGN(f, v) ((*(f)) = (v))
2329#if defined(USE_SERVER_STATS)
2349#if defined(ALTERNATIVE_QUEUE)
2361#if defined(USE_SERVER_STATS)
2369#if defined(USE_SERVER_STATS)
2378#if defined(USE_TIMERS)
2409#if defined(USE_SERVER_STATS)
2416 return &(ctx->ctx_memory);
2435#if defined(USE_HTTP2)
2436#if !defined(HTTP2_DYN_TABLE_SIZE)
2437#define HTTP2_DYN_TABLE_SIZE (256)
2453#if defined(USE_HTTP2)
2463#if defined(USE_SERVER_STATS)
2473#if defined(USE_SERVER_STATS)
2502#if defined(USE_WEBSOCKET)
2505#if defined(USE_ZLIB) && defined(USE_WEBSOCKET) \
2506 && defined(MG_EXPERIMENTAL_INTERFACES)
2530#if defined(USE_LUA) && defined(USE_WEBSOCKET)
2547#define mg_cry_internal(conn, fmt, ...) \
2548 mg_cry_internal_wrap(conn, NULL, __func__, __LINE__, fmt, __VA_ARGS__)
2550#define mg_cry_ctx_internal(ctx, fmt, ...) \
2551 mg_cry_internal_wrap(NULL, ctx, __func__, __LINE__, fmt, __VA_ARGS__)
2561#if !defined(NO_THREAD_NAME)
2562#if defined(_WIN32) && defined(_MSC_VER)
2566#pragma pack(push, 8)
2575#elif defined(__linux__)
2577#include <sys/prctl.h>
2578#include <sys/sendfile.h>
2579#if defined(ALTERNATIVE_QUEUE)
2580#include <sys/eventfd.h>
2584#if defined(ALTERNATIVE_QUEUE)
2622 if (s !=
sizeof(
u)) {
2644 if (s !=
sizeof(
u)) {
2673#if !defined(__linux__) && !defined(_WIN32) && defined(ALTERNATIVE_QUEUE)
2676 pthread_mutex_t mutex;
2711 while (!
ev->signaled) {
2752#if defined(_MSC_VER)
2756 info.dwType = 0x1000;
2758 info.dwThreadID = ~0U;
2767#elif defined(__MINGW32__)
2770#elif defined(_GNU_SOURCE) && defined(__GLIBC__) \
2771 && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 12)))
2773#if defined(__MACH__)
2779#elif defined(__linux__)
2804#define MG_FOPEN_MODE_NONE (0)
2807#define MG_FOPEN_MODE_READ (1)
2810#define MG_FOPEN_MODE_WRITE (2)
2813#define MG_FOPEN_MODE_APPEND (4)
2827#if !defined(NO_FILESYSTEMS)
2837 const uint8_t *
c = (
const uint8_t *)path;
2840 if ((
c ==
NULL) || (
c[0] == 0)) {
2851 if ((*
c ==
'>') || (*
c ==
'<') || (*
c ==
'|')) {
2855 if ((*
c ==
'*') || (*
c ==
'?')) {
2968 for (; *
src !=
'\0' &&
n > 1;
n--) {
2978 return tolower((
unsigned char)*s);
2990 }
while (
diff == 0 &&
s1[-1] !=
'\0' && --
len > 0);
3004 }
while (
diff == 0 &&
s1[-1] !=
'\0');
3074#if defined(__clang__)
3075#pragma clang diagnostic push
3076#pragma clang diagnostic ignored "-Wformat-nonliteral"
3082 ok = (
n >= 0) && ((
size_t)
n < buflen);
3084#if defined(__clang__)
3085#pragma clang diagnostic pop
3097 "truncating vsnprintf buffer: [%.*s]",
3098 (
int)((buflen > 200) ? 200 : (buflen - 1)),
3100 n = (
int)buflen - 1;
3142 }
else if (!ctx || ctx->
dd.config[i] ==
NULL) {
3145 return ctx->
dd.config[i];
3149#define mg_get_option DO_NOT_USE_THIS_FUNCTION_INTERNALLY__access_directly
3183 return tls->user_ptr;
3238 ports[cnt].protocol = 1;
3242 ports[cnt].protocol = 3;
3251#if defined(USE_X_DOM_SOCKET) && !defined(UNIX_DOMAIN_SOCKET_SERVER_NAME)
3252#define UNIX_DOMAIN_SOCKET_SERVER_NAME "*"
3273#if defined(USE_IPV6)
3284#if defined(USE_X_DOM_SOCKET)
3308#if !defined(REENTRANT_TIME)
3337#if defined(MG_EXTERNAL_FUNCTION_mg_cry_internal_impl)
3343#include "external_mg_cry_internal_impl.inl"
3344#elif !defined(NO_FILESYSTEMS)
3362#if defined(GCC_DIAGNOSTIC)
3363#pragma GCC diagnostic push
3364#pragma GCC diagnostic ignored "-Wformat-nonliteral"
3369#if defined(GCC_DIAGNOSTIC)
3370#pragma GCC diagnostic pop
3373 buf[
sizeof(buf) - 1] = 0;
3386 || (conn->
phys_ctx->callbacks.log_message(conn, buf) == 0)) {
3400 if (
fi.access.fp !=
NULL) {
3406 "[%010lu] [error] [client %s] ",
3429#error Must either enable filesystems or provide a custom mg_cry_internal_impl implementation
3441 fc->dom_ctx = &(ctx->
dd);
3476#define mg_cry DO_NOT_USE_THIS_FUNCTION__USE_mg_cry_internal
3492#if defined(MG_ALLOW_USING_GET_REQUEST_INFO_FOR_RESPONSE)
3507 ((
struct mg_connection *)conn)->request_info.local_uri_raw =
3542#if defined(__clang__)
3543#pragma clang diagnostic push
3544#pragma clang diagnostic ignored "-Wunreachable-code"
3555 ? (ri->
is_ssl ?
"wss" :
"ws")
3556 : (ri->
is_ssl ?
"https" :
"http"));
3560#if defined(__clang__)
3561#pragma clang diagnostic pop
3574 if ((buflen < 1) || (buf == 0) || (conn == 0)) {
3593#if defined(USE_X_DOM_SOCKET)
3631#if defined(USE_IPV6)
3739#if defined(GCC_DIAGNOSTIC)
3741#pragma GCC diagnostic push
3742#pragma GCC diagnostic ignored "-Wsign-conversion"
3747#if defined(GCC_DIAGNOSTIC)
3748#pragma GCC diagnostic pop
3767 for (i = 0; i <
num_hdr; i++) {
3769 return hdr[i].value;
3777#if defined(USE_WEBSOCKET)
3850 if (val ==
NULL || list ==
NULL || *list ==
'\0') {
3856 while (*list ==
' ' || *list ==
'\t')
3862 val->
len = ((size_t)(list - val->
ptr));
3867 val->
len = ((size_t)(list - val->
ptr));
3872 while (end >= 0 && ((val->
ptr[end] ==
' ') || (val->
ptr[end] ==
'\t')))
3874 val->
len = (size_t)(end) + (size_t)(1);
3876 if (val->
len == 0) {
3924 ptrdiff_t i,
j,
len, res;
3928 return (res > 0) ? res
3935 for (i = 0,
j = 0; (i < (ptrdiff_t)
pattern_len); i++,
j++) {
3936 if ((pattern[i] ==
'?') && (str[
j] !=
'\0')) {
3938 }
else if (pattern[i] ==
'$') {
3939 return (str[
j] ==
'\0') ?
j : -1;
3940 }
else if (pattern[i] ==
'*') {
3942 if (pattern[i] ==
'*') {
3955 }
while (res == -1 &&
len-- > 0);
3956 return (res == -1) ? -1 :
j + res +
len;
3961 return (ptrdiff_t)
j;
3968 if (pattern ==
NULL) {
3981 const char *http_version;
4007 if (http_version && (0 ==
strcmp(http_version,
"1.1"))) {
4020 if (!conn || !conn->
dom_ctx) {
4031 if (!conn || !conn->
dom_ctx) {
4056 "no-cache, no-store, "
4057 "must-revalidate, private, max-age=0",
4071#if !defined(NO_CACHING)
4106 conn,
NULL, val,
sizeof(val),
"max-age=%lu", (
unsigned long)
max_age);
4137 if (header && header[0]) {
4143#if !defined(NO_FILESYSTEMS)
4162 return "Switching Protocols";
4164 return "Processing";
4174 return "Non-Authoritative Information";
4176 return "No Content";
4178 return "Reset Content";
4180 return "Partial Content";
4182 return "Multi-Status";
4185 return "Already Reported";
4192 return "Multiple Choices";
4194 return "Moved Permanently";
4200 return "Not Modified";
4204 return "Temporary Redirect";
4206 return "Permanent Redirect";
4210 return "Bad Request";
4212 return "Unauthorized";
4214 return "Payment Required";
4220 return "Method Not Allowed";
4222 return "Not Acceptable";
4224 return "Proxy Authentication Required";
4226 return "Request Time-out";
4232 return "Length Required";
4234 return "Precondition Failed";
4236 return "Request Entity Too Large";
4238 return "Request-URI Too Large";
4240 return "Unsupported Media Type";
4242 return "Requested range not satisfiable";
4245 return "Expectation Failed";
4248 return "Misdirected Request";
4250 return "Unproccessable entity";
4255 return "Failed Dependency";
4259 return "Upgrade Required";
4262 return "Precondition Required";
4264 return "Too Many Requests";
4267 return "Request Header Fields Too Large";
4270 return "Unavailable For Legal Reasons";
4275 return "Internal Server Error";
4277 return "Not Implemented";
4279 return "Bad Gateway";
4281 return "Service Unavailable";
4283 return "Gateway Time-out";
4285 return "HTTP Version not supported";
4287 return "Variant Also Negotiates";
4289 return "Insufficient Storage";
4292 return "Loop Detected";
4295 return "Not Extended";
4297 return "Network Authentication Required";
4303 return "I am a teapot";
4305 return "Authentication Timeout";
4307 return "Enhance Your Calm";
4309 return "Login Timeout";
4311 return "Bandwidth Limit Exceeded";
4317 "Unknown HTTP response code: %u",
4324 return "Information";
4332 return "Redirection";
4336 return "Client Error";
4340 return "Server Error";
4359#if !defined(NO_FILESYSTEMS)
4376 has_body = ((status > 199) && (status != 204) && (status != 304));
4407 "Recursion when handling error %u - fall back to default",
4409#if !defined(NO_FILESYSTEMS)
4469 (i < 32) && (tstr[i] != 0) && (tstr[i] !=
',');
4492 tstr =
strchr(tstr + i,
'.');
4514 "text/plain; charset=utf-8",
4523 mg_printf(conn,
"Error %d: %s\n", status, status_text);
4552 long long content_length)
4563 if (content_length < 0) {
4577 (uint64_t)content_length);
4608 size_t content_len = 0;
4609#if defined(MG_SEND_REDIRECT_BODY)
4634#if defined(MG_SEND_REDIRECT_BODY)
4662 "<html><head>%s</head><body><a href=\"%s\">%s</a></body></html>",
4672 "HTTP/1.1 %i %s\r\n"
4674 "Content-Length: %u\r\n"
4675 "Connection: %s\r\n\r\n",
4679 (
unsigned int)content_len,
4682#if defined(MG_SEND_REDIRECT_BODY)
4692 return (
ret > 0) ?
ret : -1;
4699#if defined(GCC_DIAGNOSTIC)
4701#pragma GCC diagnostic push
4702#pragma GCC diagnostic ignored "-Wunused-function"
4746 cv->waiting_thread =
NULL;
4754 pthread_mutex_t *mutex,
4766 ptls = &
cv->waiting_thread;
4767 for (; *
ptls !=
NULL;
ptls = &(*ptls)->next_waiting_thread)
4769 tls->next_waiting_thread =
NULL;
4792 ptls = &
cv->waiting_thread;
4793 for (; *
ptls !=
NULL;
ptls = &(*ptls)->next_waiting_thread) {
4795 *
ptls =
tls->next_waiting_thread;
4829 if (
cv->waiting_thread) {
4830 wkup =
cv->waiting_thread->pthread_cond_helper_mutex;
4831 cv->waiting_thread =
cv->waiting_thread->next_waiting_thread;
4833 ok = SetEvent(
wkup);
4847 while (
cv->waiting_thread) {
4869#if defined(ALTERNATIVE_QUEUE)
4891 return (
int)SetEvent((HANDLE)
eventhdl);
4904#if defined(GCC_DIAGNOSTIC)
4906#pragma GCC diagnostic pop
4916 for (i = 0; path[i] !=
'\0'; i++) {
4917 if (path[i] ==
'/') {
4923 if ((i > 0) && (path[i] ==
'\')) {
4924 while ((path[i + 1] ==
'\') || (path[i + 1] ==
'/')) {
4925 (void)
memmove(path + i + 1, path + i + 2,
strlen(path + i + 1));
4939 - ((*
s2 >=
L'A') && (*
s2 <=
L'Z') ? (*
s2 -
L'A' +
L'a') : *
s2);
4942 }
while ((
diff == 0) && (
s1[-1] != L
'\0'));
5010#if !defined(NO_FILESYSTEMS)
5036 if ((
len > 0) && (path[
len - 1] !=
' ') && (path[
len - 1] !=
'.')
5039 filep->last_modified =
5041 info.ftLastWriteTime.dwHighDateTime);
5048 info.ftCreationTime.dwHighDateTime);
5083#if defined(GCC_DIAGNOSTIC)
5085#pragma GCC diagnostic push
5086#pragma GCC diagnostic ignored "-Wunused-function"
5110 dir->result.d_name[0] =
'\0';
5152 dir->info.cFileName,
5175#if !defined(HAVE_POLL)
5204 for (i = 0; i <
n; i++) {
5223 for (i = 0; i <
n; i++) {
5248#if defined(GCC_DIAGNOSTIC)
5250#pragma GCC diagnostic pop
5269#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
5328#if !defined(NO_SSL_DL) && !defined(NO_SSL)
5332#if defined(GCC_DIAGNOSTIC)
5334#pragma GCC diagnostic push
5335#pragma GCC diagnostic ignored "-Wunused-function"
5366#if defined(GCC_DIAGNOSTIC)
5368#pragma GCC diagnostic pop
5387#if !defined(WNOHANG)
5393waitpid(pid_t pid,
int *status,
int flags)
5419 while ((
e > s) &&
isspace((
unsigned char)
e[-1])) {
5500 buf[0] = buf[1] =
'\0';
5507 pi.hProcess = (pid_t)-1;
5517 buf[
sizeof(buf) - 1] =
'\0';
5520 if ((buf[0] ==
'#') && (buf[1] ==
'!')) {
5537 "\"%s\" %s \"%s\%s\"",
5564 pi.hProcess = (pid_t)-1;
5582 pi.hProcess = (pid_t)-1;
5590 if (pi.hThread !=
NULL) {
5594 return (pid_t)pi.hProcess;
5618#if !defined(NO_FILESYSTEMS)
5634 if (0 == stat(path, &
st)) {
5635 filep->size = (uint64_t)(
st.st_size);
5636 filep->last_modified =
st.st_mtime;
5651#if defined(__ZEPHYR__)
5660 "%s: fcntl(F_SETFD FD_CLOEXEC) failed: %s",
5679#if defined(__ZEPHYR__)
5681#elif defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
5706#if defined(__ZEPHYR__)
5710#elif defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
5753 if ((pid =
fork()) == -1) {
5756 }
else if (pid != 0) {
5764 if (
chdir(dir) != 0) {
5767 }
else if (
dup2(
fdin[0], 0) == -1) {
5769 "%s: dup2(%d, 0): %s",
5775 "%s: dup2(%d, 1): %s",
5781 "%s: dup2(%d, 2): %s",
5791 (void)close(
fdin[0]);
5792 (void)close(
fdout[1]);
5793 (void)close(
fderr[1]);
5796 (void)close(
fdin[1]);
5797 (void)close(
fdout[0]);
5798 (void)close(
fderr[0]);
5805 memset(&sa, 0,
sizeof(sa));
5814 "%s: execle(%s): %s",
5830 "%s: execle(%s %s): %s",
5881 static uint64_t
lfsr = 0;
5882 static uint64_t
lcg = 0;
5895 lcg =
lcg * 6364136223846793005LL + 1442695040888963407LL;
5919 if ((
n == 1) && ((
pfd[0].events &
POLLERR) == 0)) {
5985 typedef size_t len_t;
5998#if defined(NO_SSL) && !defined(USE_MBEDTLS)
6008#if defined(USE_MBEDTLS)
6024#elif !defined(NO_SSL)
6048 n = (
int)fwrite(buf, 1, (
size_t)
len, fp);
6057 err = (
n < 0) ?
ERRNO : 0;
6079 if ((
n > 0) || ((
n == 0) && (
len == 0))) {
6165 }
else if (
n == 0) {
6195 typedef size_t len_t;
6216#if defined(USE_MBEDTLS)
6217 }
else if (conn->
ssl !=
NULL) {
6271#elif !defined(NO_SSL)
6272 }
else if (conn->
ssl !=
NULL) {
6436 }
else if (
n == -1) {
6445 }
else if (
n == 0) {
6462 while (
mg_read(conn, buf,
sizeof(buf)) > 0)
6484 if (content_len < 0) {
6538#if defined(USE_SERVER_STATS)
6540 conn->conn_state = 4;
6546#if defined(USE_SERVER_STATS)
6547 conn->conn_state = 5;
6567#if defined(USE_HTTP2)
6569#error "HTTP2 requires ALPN, APLN requires SSL/TLS"
6572#include "mod_http2.inl"
6576 if (conn->protocol_type == PROTOCOL_TYPE_HTTP2) { \
6577 http2_must_use_http1(conn); \
6629 || (
x[1] !=
'\n')) {
6643 for (i = 0; i < (
sizeof(lenbuf) - 1); i++) {
6648 if ((i > 0) && (lenbuf[i] ==
'\r')
6649 && (lenbuf[i - 1] !=
'\r')) {
6652 if ((i > 1) && (lenbuf[i] ==
'\n')
6653 && (lenbuf[i - 1] ==
'\r')) {
6662 if (!
isxdigit((
unsigned char)lenbuf[i])) {
6668 if ((end ==
NULL) || (*end !=
'\r')) {
6677 && (lenbuf[0] ==
'\r') && (lenbuf[1] ==
'\n')) {
6709#if defined(USE_HTTP2)
6734 buf = (
const char *)buf +
total;
6755 buf = (
const char *)buf +
n;
6812#if defined(GCC_DIAGNOSTIC)
6815#pragma GCC diagnostic push
6816#pragma GCC diagnostic ignored "-Wformat-nonliteral"
6843 (*buf)[
size - 1] = 0;
6911#if defined(GCC_DIAGNOSTIC)
6913#pragma GCC diagnostic pop
6957#define HEXTOI(x) (isdigit(x) ? (x - '0') : (x - 'W'))
7008 const char *
p, *
e, *s;
7019 e =
data + data_len;
7031 s = (
const char *)
memchr(
p,
'&', (
size_t)(
e -
p));
7095 while ((*
data ==
' ') || (*
data ==
'\t')) {
7107 while ((*
b != 0) && (*
b !=
'&') && (*
b !=
'=')) {
7114 }
else if (*
b ==
'&') {
7142 for (i = 0; i < num; i++) {
7163 const char *s, *
p, *end;
7188 if ((*s ==
'"') && (
p[-1] ==
'"') && (
p > s + 1)) {
7206#if defined(USE_WEBSOCKET) || defined(USE_LUA)
7210 static const char *
b64 =
7211 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
7214 for (i =
j = 0; i <
src_len; i += 3) {
7220 dst[
j++] =
b64[((
a & 3) << 4) | (
b >> 4)];
7222 dst[
j++] =
b64[(
b & 15) << 2 | (
c >> 6)];
7228 while (
j % 4 != 0) {
7244 return letter -
'a' + 26;
7247 return letter -
'0' + 52;
7266 unsigned char a,
b,
c,
d;
7270 for (i = 0; i <
src_len; i += 4) {
7291 dst[(*dst_len)++] = (
a << 2) + (
b >> 4);
7293 dst[(*dst_len)++] = (
b << 4) + (
c >> 2);
7295 dst[(*dst_len)++] = (
c << 6) +
d;
7317#if !defined(NO_FILES)
7335#if defined(USE_DUKTAPE)
7402 while ((
n > 0) && (path[
n - 1] ==
'/')) {
7450#if !defined(NO_FILES)
7458#if !defined(NO_CGI) || defined(USE_LUA) || defined(USE_DUKTAPE)
7479#if defined(USE_WEBSOCKET)
7481#if !defined(NO_FILES)
7498#if !defined(NO_FILES)
7635#if !defined(NO_CGI) || defined(USE_LUA) || defined(USE_DUKTAPE)
7690 DEBUG_TRACE(
"Substitute script %s serving path %s",
7737#if !defined(NO_FILES)
7758 for (i = 0; i < buflen; i++) {
7760 const unsigned char c = (
unsigned char)buf[i];
7762 if ((
c < 128) && ((char)
c !=
'\r') && ((char)
c !=
'\n')
7768 if (i < buflen - 1) {
7769 if ((buf[i] ==
'\n') && (buf[i + 1] ==
'\n')) {
7776 if (i < buflen - 3) {
7777 if ((buf[i] ==
'\r') && (buf[i + 1] ==
'\n') && (buf[i + 2] ==
'\r')
7778 && (buf[i + 3] ==
'\n')) {
7789#if !defined(NO_CACHING)
7812 time_t
result = (time_t)0;
7816 "%d/%3s/%d %d:%d:%d",
7825 "%d %3s %d %d:%d:%d",
7834 "%*3s, %d %3s %d %d:%d:%d",
7843 "%d-%3s-%d %d:%d:%d",
7854 tm.tm_year =
year - 1900;
7912 }
else if (!
strncmp(in,
"./", 2)) {
7921 else if (!
strncmp(in,
"/./", 3)) {
7923 }
else if (!
strcmp(in,
"/.")) {
7934 else if (!
strncmp(in,
"/../", 4)) {
7942 }
else if (!
strcmp(in,
"/..")) {
7971 }
while ((*in != 0) && (*in !=
'/'));
8009 }
else if (*in ==
'/') {
8014 }
while (*in ==
'/');
8024static const struct {
8032 {
".bin", 4,
"application/octet-stream"},
8033 {
".deb", 4,
"application/octet-stream"},
8034 {
".dmg", 4,
"application/octet-stream"},
8035 {
".dll", 4,
"application/octet-stream"},
8036 {
".doc", 4,
"application/msword"},
8037 {
".eps", 4,
"application/postscript"},
8038 {
".exe", 4,
"application/octet-stream"},
8039 {
".iso", 4,
"application/octet-stream"},
8040 {
".js", 3,
"application/javascript"},
8041 {
".json", 5,
"application/json"},
8042 {
".msi", 4,
"application/octet-stream"},
8043 {
".pdf", 4,
"application/pdf"},
8044 {
".ps", 3,
"application/postscript"},
8045 {
".rtf", 4,
"application/rtf"},
8046 {
".xhtml", 6,
"application/xhtml+xml"},
8047 {
".xsl", 4,
"application/xml"},
8048 {
".xslt", 5,
"application/xml"},
8051 {
".ttf", 4,
"application/font-sfnt"},
8052 {
".cff", 4,
"application/font-sfnt"},
8053 {
".otf", 4,
"application/font-sfnt"},
8054 {
".aat", 4,
"application/font-sfnt"},
8055 {
".sil", 4,
"application/font-sfnt"},
8056 {
".pfr", 4,
"application/font-tdpfr"},
8057 {
".woff", 5,
"application/font-woff"},
8058 {
".woff2", 6,
"application/font-woff2"},
8061 {
".mp3", 4,
"audio/mpeg"},
8062 {
".oga", 4,
"audio/ogg"},
8063 {
".ogg", 4,
"audio/ogg"},
8066 {
".gif", 4,
"image/gif"},
8067 {
".ief", 4,
"image/ief"},
8068 {
".jpeg", 5,
"image/jpeg"},
8069 {
".jpg", 4,
"image/jpeg"},
8070 {
".jpm", 4,
"image/jpm"},
8071 {
".jpx", 4,
"image/jpx"},
8072 {
".png", 4,
"image/png"},
8073 {
".svg", 4,
"image/svg+xml"},
8074 {
".tif", 4,
"image/tiff"},
8075 {
".tiff", 5,
"image/tiff"},
8078 {
".wrl", 4,
"model/vrml"},
8081 {
".css", 4,
"text/css"},
8082 {
".csv", 4,
"text/csv"},
8083 {
".htm", 4,
"text/html"},
8084 {
".html", 5,
"text/html"},
8085 {
".sgm", 4,
"text/sgml"},
8086 {
".shtm", 5,
"text/html"},
8087 {
".shtml", 6,
"text/html"},
8088 {
".txt", 4,
"text/plain"},
8089 {
".xml", 4,
"text/xml"},
8092 {
".mov", 4,
"video/quicktime"},
8093 {
".mp4", 4,
"video/mp4"},
8094 {
".mpeg", 5,
"video/mpeg"},
8095 {
".mpg", 4,
"video/mpeg"},
8096 {
".ogv", 4,
"video/ogg"},
8097 {
".qt", 3,
"video/quicktime"},
8102 {
".arj", 4,
"application/x-arj-compressed"},
8103 {
".gz", 3,
"application/x-gunzip"},
8104 {
".rar", 4,
"application/x-arj-compressed"},
8105 {
".swf", 4,
"application/x-shockwave-flash"},
8106 {
".tar", 4,
"application/x-tar"},
8107 {
".tgz", 4,
"application/x-tar-gz"},
8108 {
".torrent", 8,
"application/x-bittorrent"},
8109 {
".ppt", 4,
"application/x-mspowerpoint"},
8110 {
".xls", 4,
"application/x-msexcel"},
8111 {
".zip", 4,
"application/x-zip-compressed"},
8115 {
".flac", 5,
"audio/flac"},
8116 {
".aif", 4,
"audio/x-aif"},
8117 {
".m3u", 4,
"audio/x-mpegurl"},
8118 {
".mid", 4,
"audio/x-midi"},
8119 {
".ra", 3,
"audio/x-pn-realaudio"},
8120 {
".ram", 4,
"audio/x-pn-realaudio"},
8121 {
".wav", 4,
"audio/x-wav"},
8122 {
".bmp", 4,
"image/bmp"},
8123 {
".ico", 4,
"image/x-icon"},
8124 {
".pct", 4,
"image/x-pct"},
8125 {
".pict", 5,
"image/pict"},
8126 {
".rgb", 4,
"image/x-rgb"},
8127 {
".webm", 5,
"video/webm"},
8128 {
".asf", 4,
"video/x-ms-asf"},
8129 {
".avi", 4,
"video/x-msvideo"},
8130 {
".m4v", 4,
"video/x-m4v"},
8150 return "text/plain";
8160 const char *list, *
ext;
8194 static const char *hex =
"0123456789abcdef";
8196 for (;
len--;
p++) {
8197 *to++ = hex[
p[0] >> 4];
8198 *to++ = hex[
p[0] & 0x0f];
8237 const char *response)
8243 || (qop ==
NULL) || (response ==
NULL)) {
8248 if (
strlen(response) != 32) {
8271#if !defined(NO_FILESYSTEMS)
8300 &&
filep->stat.is_directory) {
8381 while (
isspace((
unsigned char)*s)) {
8397 if (*
name ==
'\0') {
8418#if !defined(NO_NONCE_CHECK)
8425 if ((s ==
NULL) || (*s != 0)) {
8430 nonce ^= conn->
dom_ctx->auth_nonce_mask;
8440 if (nonce < (uint64_t)conn->
phys_ctx->start_time) {
8447 if (nonce >= ((uint64_t)conn->
phys_ctx->start_time
8448 + conn->
dom_ctx->nonce_count)) {
8487#define INITIAL_DEPTH 9
8488#if INITIAL_DEPTH <= 0
8489#error Bad INITIAL_DEPTH for recursion, set to at least 1
8492#if !defined(NO_FILESYSTEMS)
8559 "%s: cannot open authorization file: %s",
8568 "%s: syntax error in authorization file: %s",
8577 "%s: syntax error in authorization file: %s",
8588 "%s: syntax error in authorization file: %s",
8670#if !defined(NO_FILESYSTEMS)
8677 if (!conn || !conn->
dom_ctx) {
8695 "%s: cannot open %s: %s",
8726 uint64_t nonce = (uint64_t)(conn->
phys_ctx->start_time);
8735 nonce += conn->
dom_ctx->nonce_count;
8739 nonce ^= conn->
dom_ctx->auth_nonce_mask;
8753 "Digest qop=\"auth\", realm=\"%s\", "
8783#if !defined(NO_FILES)
8842 for (i = 0; ((i < 255) && (user[i] != 0)); i++) {
8843 if (
iscntrl((
unsigned char)user[i])) {
8850 for (i = 0; ((i < 255) && (domain[i] != 0)); i++) {
8851 if (
iscntrl((
unsigned char)domain[i])) {
8884 if (
sscanf(
line,
"%255[^:]:%255[^:]:%*s",
u,
d) != 2) {
8948 return (port <= 0xffff);
8980 if ((
dstlen >= (
size_t)res->ai_addrlen)
8981 && (res->ai_addr->sa_family ==
af)) {
8982 memcpy(
dst, res->ai_addr, res->ai_addrlen);
9009 memset(sa, 0,
sizeof(*sa));
9025#if defined(USE_X_DOM_SOCKET)
9029 if (
hostlen >=
sizeof(sa->sun.sun_path)) {
9035 "host length exceeds limit");
9050#if !defined(NO_SSL) && !defined(USE_MBEDTLS) && !defined(NO_SSL_DL)
9051#if defined(OPENSSL_API_1_1) || defined(OPENSSL_API_3_0)
9058 "SSL is not initialized");
9068 "SSL is not initialized");
9077#if defined(USE_X_DOM_SOCKET)
9083 memset(sa->sun.sun_path, 0,
sizeof(sa->sun.sun_path));
9088 sa->
sin.sin_port =
htons((uint16_t)port);
9090#if defined(USE_IPV6)
9092 sa->sin6.sin6_port =
htons((uint16_t)port);
9094 }
else if (host[0] ==
'[') {
9102 sa->sin6.sin6_port =
htons((uint16_t)port);
9123#if defined(USE_IPV6)
9128#if defined(USE_X_DOM_SOCKET)
9129 else if (
ip_ver == -99) {
9149 "Cannot set socket to non-blocking: %s",
9164#if defined(USE_IPV6)
9168 (
struct sockaddr *)((
void *)&sa->sin6),
9172#if defined(USE_X_DOM_SOCKET)
9173 else if (
ip_ver == -99) {
9176 (
struct sockaddr *)((
void *)&sa->sun),
9222 "connect(%s:%d): timeout",
9247 "connect(%s:%d): error %s",
9264 static const char *hex =
"0123456789abcdef";
9268 for (; ((*
src !=
'\0') && (pos < end));
src++, pos++) {
9272 }
else if (pos + 2 < end) {
9274 pos[1] = hex[(
unsigned char)*
src >> 4];
9275 pos[2] = hex[(
unsigned char)*
src & 0xf];
9283 return (*
src ==
'\0') ? (
int)(pos -
dst) : -1;
9294#if defined(REENTRANT_TIME)
9317 }
else if (*
p ==
'<') {
9319 }
else if (*
p ==
'>') {
9325 if (
de->
file.is_directory) {
9335 if (
de->
file.size < 1024) {
9342 }
else if (
de->
file.size < 0x100000) {
9348 (
double)
de->
file.size / 1024.0);
9349 }
else if (
de->
file.size < 0x40000000) {
9355 (
double)
de->
file.size / 1048576);
9362 (
double)
de->
file.size / 1073741824);
9369#if defined(REENTRANT_TIME)
9378 mod[
sizeof(
mod) - 1] =
'\0';
9381 "<tr><td><a href=\"%s%s\">%s%s</a></td>"
9382 "<td> %s</td><td> %s</td></tr>\n",
9384 de->
file.is_directory ?
"/" :
"",
9386 de->
file.is_directory ?
"/" :
"",
9402 const struct de *
a = (
const struct de *)
p1, *
b = (
const struct de *)
p2;
9403 const char *query_string =
a->conn->request_info.query_string;
9406 if ((query_string ==
NULL) || (query_string[0] ==
'\0')) {
9410 if (
a->file.is_directory && !
b->file.is_directory) {
9412 }
else if (!
a->file.is_directory &&
b->file.is_directory) {
9414 }
else if (*query_string ==
'n') {
9416 }
else if (*query_string ==
's') {
9419 : ((
a->file.size >
b->file.size) ? 1 : -1);
9420 }
else if (*query_string ==
'd') {
9422 (
a->file.last_modified ==
b->file.last_modified)
9424 : ((
a->file.last_modified >
b->file.last_modified) ? 1
9447#if !defined(NO_FILESYSTEMS)
9452 int (*cb)(
struct de *,
void *))
9489 "%s: mg_stat(%s) failed: %s",
9507#if !defined(NO_FILES)
9548 "%s: mg_stat(%s) failed: %s",
9555 if (
de.
file.is_directory) {
9583#if !defined(NO_FILESYSTEMS)
9588 struct de *entries =
dsd->entries;
9590 if ((entries ==
NULL) || (
dsd->num_entries >=
dsd->arr_size)) {
9595 dsd->arr_size * 2 *
sizeof(entries[0]));
9596 if (entries ==
NULL) {
9600 dsd->entries = entries;
9633 "Error: Cannot open directory\nopendir(%s): %s",
9643 if (title[
strcspn(title,
"&<>")]) {
9651 }
else if (*
p ==
'<') {
9653 }
else if (*
p ==
'>') {
9676 "text/html; charset=utf-8",
9684 "<html><head><title>Index of %s</title>"
9685 "<style>th {text-align: left;}</style></head>"
9686 "<body><h1>Index of %s</h1><pre><table cellpadding=\"0\">"
9687 "<tr><th><a href=\"?n%c\">Name</a></th>"
9688 "<th><a href=\"?d%c\">Modified</a></th>"
9689 "<th><a href=\"?s%c\">Size</a></th></tr>"
9690 "<tr><td colspan=\"3\"><hr></td></tr>",
9700 "<tr><td><a href=\"%s\">%s</a></td>"
9701 "<td> %s</td><td> %s</td></tr>\n",
9711 sizeof(
data.entries[0]),
9713 for (i = 0; i <
data.num_entries; i++) {
9720 mg_printf(conn,
"%s",
"</table></pre></body></html>");
9737 if (!
filep || !conn) {
9743 : (int64_t)(
filep->stat.size);
9748#if defined(__linux__)
9762 (size_t)((
len < 0x7FFFF000) ?
len : 0x7FFFF000);
9794 "%s: fseeko() failed: %s",
9801 "Error: Unable to access file at requested position.");
9852 (
unsigned long)
filestat->last_modified,
9867 "%s: fcntl(F_SETFD FD_CLOEXEC) failed: %s",
9876#if defined(USE_ZLIB)
9877#include "mod_zlib.inl"
9881#if !defined(NO_FILESYSTEMS)
9896 const char *encoding = 0;
9902#if defined(USE_ZLIB)
9924 "Error: File size is too large to send\n%" INT64_FMT,
9928 cl = (int64_t)
filep->stat.size;
9932#if defined(USE_ZLIB)
9945 if (
filep->stat.is_gzipped) {
9951 "Error: Path of zipped file too long (%s)",
9959#if defined(USE_ZLIB)
9973 cl = (int64_t)
filep->stat.size;
9977#if defined(USE_ZLIB)
9987 "Error: Cannot open file\nfopen(%s): %s",
10003 if (
filep->stat.is_gzipped) {
10008 "Error: Range requests in gzipped files are not supported");
10014 cl = (
n == 2) ? (((
r2 > cl) ? cl :
r2) -
r1 + 1) : (cl -
r1);
10025#if defined(USE_ZLIB)
10033#if defined(USE_ZLIB)
10049 cors1 =
"Access-Control-Allow-Origin";
10058 cors3 =
"Access-Control-Allow-Credentials";
10076 if (
cors1[0] != 0) {
10079 if (
cors3[0] != 0) {
10085#if defined(USE_ZLIB)
10116 if (
range[0] != 0) {
10130#if defined(USE_ZLIB)
10160#if !defined(NO_CACHING)
10203#if !defined(NO_FILESYSTEMS)
10234#if !defined(NO_CACHING)
10240 if (file.
stat.is_directory) {
10248 "Error: Directory listing denied");
10275 for (s =
p = path + 2; (
p =
strchr(s,
'/')) !=
NULL; s = ++
p) {
10276 len = (size_t)(
p - path);
10277 if (
len >=
sizeof(buf)) {
10294 if (
p[1] ==
'\0') {
10309 "%s: Cannot remove invalid file %s",
10346 n = (
int)fwrite(buf, 1, (
size_t)
ret,
fi.access.fp);
10386 if ((**
ppw !=
'\r') && (**
ppw !=
'\n')) {
10391 if (**
ppw !=
' ') {
10423 int num_headers = 0;
10429 while ((*
dp !=
':') && (*
dp >= 33) && (*
dp <= 126)) {
10438 while (*
dp ==
' ') {
10450 hdr[i].name = *buf;
10455 }
while ((*
dp ==
' ') || (*
dp ==
'\t'));
10461 while ((*
dp != 0) && (*
dp !=
'\r') && (*
dp !=
'\n')) {
10477 num_headers = i + 1;
10484 if ((
dp[0] ==
'\r') || (
dp[0] ==
'\n')) {
10493 return num_headers;
10510 {
"GET", 0, 1, 1, 1, 1},
10511 {
"POST", 1, 1, 0, 0, 0},
10512 {
"PUT", 1, 0, 0, 1, 0},
10513 {
"DELETE", 0, 0, 0, 1, 0},
10514 {
"HEAD", 0, 0, 1, 1, 1},
10515 {
"OPTIONS", 0, 0, 1, 1, 0},
10516 {
"CONNECT", 1, 1, 0, 0, 0},
10520 {
"PATCH", 1, 0, 0, 0, 0},
10524 {
"PROPFIND", 0, 1, 1, 1, 0},
10530 {
"MKCOL", 0, 0, 0, 1, 0},
10543 {
"LOCK", 1, 1, 0, 0, 0},
10544 {
"UNLOCK", 1, 0, 0, 0, 0},
10545 {
"PROPPATCH", 1, 1, 0, 0, 0},
10557 {
"REPORT", 1, 1, 1, 1, 1},
10564 {
NULL, 0, 0, 0, 0, 0}
10619 while ((
len > 0) &&
isspace((
unsigned char)*buf)) {
10631 if (
iscntrl((
unsigned char)*buf)) {
10642 if ((*buf == 0) || (*buf ==
'\r') || (*buf ==
'\n')) {
10705 while ((
len > 0) &&
isspace((
unsigned char)*buf)) {
10717 if (
iscntrl((
unsigned char)*buf)) {
10728 if ((*buf == 0) || (*buf ==
'\r') || (*buf ==
'\n')) {
10734 if (
strncmp(buf,
"HTTP/", 5) != 0) {
10739 if (!
isgraph((
unsigned char)buf[0])) {
10757 if ((
l < 100) || (
l >= 1000) || ((
tmp2 - tmp) != 3) || (*
tmp2 != 0)) {
10768 while (
isprint((
unsigned char)*buf)) {
10771 if ((*buf !=
'\r') && (*buf !=
'\n')) {
10778 }
while (
isspace((
unsigned char)*buf));
10804 int request_len,
n = 0;
10833 while (request_len == 0) {
10869 return request_len;
10873#if !defined(NO_CGI) || !defined(NO_FILES)
10898 (void)
mg_printf(conn,
"%s",
"HTTP/1.1 100 Continue\r\n\r\n");
10936#if defined(USE_TIMERS)
10938#define TIMER_API static
10939#include "timer.inl"
10944#if !defined(NO_CGI)
10977 size_t i,
n, space;
10982 if ((
env->varlen -
env->varused) < 2) {
10984 "%s: Cannot register CGI variable [%s]",
10991 space = (
env->buflen -
env->bufused);
11003 "%s: Cannot allocate memory for CGI variable [%s]",
11011 for (i = 0,
n = 0; i <
env->varused; i++) {
11015 space = (
env->buflen -
env->bufused);
11065 "%s: Not enough memory for environmental buffer",
11075 "%s: Not enough memory for environmental variables",
11087 addenv(
env,
"%s",
"GATEWAY_INTERFACE=CGI/1.1");
11088 addenv(
env,
"%s",
"SERVER_PROTOCOL=HTTP/1.1");
11089 addenv(
env,
"%s",
"REDIRECT_STATUS=200");
11106 if (conn->
request_info.local_uri[uri_len - 1] !=
'/') {
11114 "SCRIPT_NAME=%s%s",
11122 "SCRIPT_NAME=%.*s",
11132 "PATH_TRANSLATED=%s%s",
11173 if ((s =
getenv(
"ProgramFiles(x86)")) !=
NULL) {
11174 addenv(
env,
"ProgramFiles(x86)=%s", s);
11177 if ((s =
getenv(
"LD_LIBRARY_PATH")) !=
NULL) {
11192 for (i = 0; i < conn->
request_info.num_headers; i++) {
11203 "%s: HTTP header variable too long [%s]",
11230 env->buf[
env->bufused] =
'\0';
11254 if ((
ret_pid != (pid_t)-1) && (status == 0)) {
11260 while (
waitpid(
proc->pid, &status, 0) != (pid_t)-1)
11263 DEBUG_TRACE(
"CGI timer: Child process %d already stopped\n",
proc->pid);
11285 int fdin[2] = {-1, -1},
fdout[2] = {-1, -1},
fderr[2] = {-1, -1};
11292 pid_t pid = (pid_t)-1;
11295#if defined(USE_TIMERS)
11309 buflen = conn->
phys_ctx->max_request_size;
11340 "Error: CGI program \"%s\": Can not create CGI pipes: %s",
11345 "Error: Cannot create CGI pipe: %s",
11362 if (
pid == (pid_t)-1) {
11366 "Error: CGI program \"%s\": Can not spawn CGI process: %s",
11377 proc->references = 1;
11379#if defined(USE_TIMERS)
11381 proc->references = 2;
11398 (void)close(
fdin[0]);
11399 (void)close(
fdout[1]);
11400 (void)close(
fderr[1]);
11408 "Error: CGI program \"%s\": Can not open fd: %s",
11413 "Error: CGI can not open fd\nfdopen: %s",
11421 fout.access.fp = out;
11432 "Error: CGI program \"%s\": Forward body data failed",
11452 "Error: Not enough memory for CGI buffer (%u bytes)",
11453 (
unsigned int)buflen);
11456 "Error: CGI program \"%s\": Not enough memory for buffer (%u "
11459 (
unsigned int)buflen);
11471 i =
pull_all(err, conn, buf, (
int)buflen);
11476 "Error: CGI program \"%s\" sent error "
11484 "Error: CGI program \"%s\" failed.",
11490 "Error: CGI program sent malformed or too big "
11491 "(>%u bytes) HTTP headers: [%.*s]",
11498 "Error: CGI program sent malformed or too big "
11499 "(>%u bytes) HTTP headers: [%.*s]",
11514 status_text =
"OK";
11518 status_text = status;
11519 while (
isdigit((
unsigned char)*status_text) || *status_text ==
' ') {
11562 if (
pid != (pid_t)-1) {
11566 if (
fdin[0] != -1) {
11569 if (
fdout[1] != -1) {
11572 if (
fderr[1] != -1) {
11578 }
else if (
fdin[1] != -1) {
11584 }
else if (
fdout[0] != -1) {
11590 }
else if (
fderr[0] != -1) {
11599#if !defined(NO_FILES)
11616 "%s: mg_stat(%s) failed: %s",
11622 if (
de.
file.last_modified) {
11677 if (conn ==
NULL) {
11685 if (file.
stat.is_directory) {
11702 "Error: Put not possible\nReplacing %s is not allowed",
11734 "Error: Path too long\nput_dir(%s): %s",
11744 "Error: Can not create directory\nput_dir(%s): %s",
11757 "Error: Can not create file\nfopen(%s): %s",
11805 "Error: Cannot delete file\nFile %s not found",
11810 if (
de.
file.is_directory) {
11823 if (access(path,
W_OK) != 0) {
11828 "Error: Delete not possible\nDeleting %s is not allowed",
11846 "Error: Cannot delete file\nremove(%s): %s",
11854#if !defined(NO_FILESYSTEMS)
11870 if (conn ==
NULL) {
11877 if (
sscanf(tag,
" virtual=\"%511[^\"]\"", file_name) == 1) {
11879 file_name[511] = 0;
11888 }
else if (
sscanf(tag,
" abspath=\"%511[^\"]\"", file_name) == 1) {
11891 file_name[511] = 0;
11895 }
else if ((
sscanf(tag,
" file=\"%511[^\"]\"", file_name) == 1)
11896 || (
sscanf(tag,
" \"%511[^\"]\"", file_name) == 1)) {
11898 file_name[511] = 0;
11909 sizeof(path) -
len,
11920 mg_cry_internal(conn,
"SSI #include path length overflow: [%s]", tag);
11926 "Cannot open SSI #include: [%s]: fopen(%s): %s",
11943#if !defined(NO_POPEN)
11947 char cmd[1024] =
"";
11950 if (
sscanf(tag,
" \"%1023[^\"]\"",
cmd) != 1) {
11956 "Cannot SSI #exec: [%s]: %s",
12013 if ((
len > 12) && !
memcmp(buf + 5,
"include", 7)) {
12015#if !defined(NO_POPEN)
12016 }
else if ((
len > 9) && !
memcmp(buf + 5,
"exec", 4)) {
12039 buf[
len++] = (char)(ch & 0xff);
12041 if ((
len == 5) && !
memcmp(buf,
"<!--#", 5)) {
12046 if ((
len + 2) > (
int)
sizeof(buf)) {
12072 buf[
len++] = (char)(ch & 0xff);
12074 if (
len == (
int)
sizeof(buf)) {
12106 cors1 =
"Access-Control-Allow-Origin";
12115 cors3 =
"Access-Control-Allow-Credentials";
12126 "Error: Cannot read file\nfopen(%s): %s",
12157#if !defined(NO_FILES)
12176 "GET, POST, HEAD, CONNECT, PUT, DELETE, OPTIONS, PROPFIND, MKCOL",
12197 char *
href, mtime[64];
12214 for (i =
j = 0;
href[i];
j++) {
12227 "<d:href>%s</d:href>"
12230 "<d:resourcetype>%s</d:resourcetype>"
12231 "<d:getcontentlength>%" INT64_FMT "</d:getcontentlength>"
12232 "<d:getlastmodified>%s</d:getlastmodified>"
12234 "<d:status>HTTP/1.1 200 OK</d:status>"
12238 filep->is_directory ?
"<d:collection/>" :
"",
12286 "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
12287 "<d:multistatus xmlns:d='DAV:'>\n");
12294 if (
filep->is_directory
12301 mg_printf(conn,
"%s\n",
"</d:multistatus>");
12338#if defined(USE_LUA)
12339#include "mod_lua.inl"
12342#if defined(USE_DUKTAPE)
12343#include "mod_duktape.inl"
12346#if defined(USE_WEBSOCKET)
12348#if !defined(NO_SSL_DL)
12349#if !defined(OPENSSL_API_3_0)
12350#define SHA_API static
12358 static const char *
magic =
"258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
12360#if !defined(OPENSSL_API_3_0)
12374#if defined(OPENSSL_API_3_0)
12384 "HTTP/1.1 101 Switching Protocols\r\n"
12385 "Upgrade: websocket\r\n"
12386 "Connection: Upgrade\r\n"
12387 "Sec-WebSocket-Accept: %s\r\n",
12390#if defined(USE_ZLIB) && defined(MG_EXPERIMENTAL_INTERFACES)
12395 if (conn->
request_info.acceptedWebSocketSubprotocol) {
12397 "Sec-WebSocket-Protocol: %s\r\n\r\n",
12407#if !defined(MG_MAX_UNANSWERED_PING)
12413#define MG_MAX_UNANSWERED_PING (5)
12420 void *callback_data)
12440 unsigned char mask[4];
12445 unsigned char mem[4096];
12471 DEBUG_TRACE(
"Websocket connection %s:%u start data processing loop",
12474 conn->in_websocket_handling = 1;
12502 if (
data_len > (uint64_t)0x7FFF0000ul) {
12507 "websocket out of memory; closing connection");
12526 "websocket out of memory; closing connection");
12556 }
else if (
n > 0) {
12567 "Websocket pull failed; closing connection");
12600 for (i = 0; i < (size_t)
data_len; i++) {
12634#if defined(USE_ZLIB) && defined(MG_EXPERIMENTAL_INTERFACES)
12637 if (!conn->websocket_deflate_initialized) {
12649 conn->websocket_inflate_state.avail_in =
12651 conn->websocket_inflate_state.next_in =
data;
12671 "Out of memory: Cannot allocate "
12672 "inflate buffer of %lu bytes",
12678 conn->websocket_inflate_state.avail_out =
12681 conn->websocket_inflate_state.next_out =
12683 ret =
inflate(&conn->websocket_inflate_state,
12689 "ZLIB inflate error: %i %s",
12691 (conn->websocket_inflate_state.msg
12692 ? conn->websocket_inflate_state.msg
12693 :
"<no error message>"));
12699 }
while (conn->websocket_inflate_state.avail_out
12702 conn->websocket_inflate_state.avail_out;
12730 DEBUG_TRACE(
"Callback requests to close connection from %s:%u",
12737 DEBUG_TRACE(
"Message requests to close connection from %s:%u",
12768 DEBUG_TRACE(
"Too many (%i) unanswered ping from %s:%u "
12769 "- closing connection",
12801 conn->in_websocket_handling = 0;
12802 DEBUG_TRACE(
"Websocket connection %s:%u left data processing loop",
12815 unsigned char header[14];
12819#if defined(GCC_DIAGNOSTIC)
12821#pragma GCC diagnostic push
12822#pragma GCC diagnostic ignored "-Wconversion"
12838#if defined(USE_ZLIB) && defined(MG_EXPERIMENTAL_INTERFACES)
12845 if (!conn->websocket_deflate_initialized) {
12851 header[0] = 0xC0u | (
unsigned char)((
unsigned)opcode & 0xf);
12852 conn->websocket_deflate_state.avail_in = (
uInt)
dataLen;
12853 conn->websocket_deflate_state.next_in = (
unsigned char *)
data;
12859 "Out of memory: Cannot allocate deflate buffer of %lu bytes",
12865 conn->websocket_deflate_state.next_out =
deflated;
12866 deflate(&conn->websocket_deflate_state, conn->websocket_deflate_flush);
12871 header[0] = 0x80u | (
unsigned char)((
unsigned)opcode & 0xf);
12873#if defined(GCC_DIAGNOSTIC)
12874#pragma GCC diagnostic pop
12880 header[1] = (
unsigned char)
dataLen;
12882 }
else if (
dataLen <= 0xFFFF) {
12911#if defined(USE_ZLIB) && defined(MG_EXPERIMENTAL_INTERFACES)
12944 if ((
in_len > 3) && ((ptrdiff_t)in % 4) == 0) {
12946 while (i < (
in_len - 3)) {
12947 *(uint32_t *)(
void *)(
out + i) =
12955 *(uint8_t *)(
void *)(
out + i) =
12956 *(uint8_t *)(
void *)(in + i)
12979 "Cannot allocate buffer for masked websocket response: "
13014#if !defined(USE_LUA)
13039 "Protocol upgrade to RFC 6455 required");
13064 "Sec-WebSocket-Protocol",
13072 *acceptedWebSocketSubprotocol =
NULL;
13082 len =
sep ? (
unsigned long)(sep - protocol)
13083 : (unsigned long)
strlen(protocol);
13084 while (sep &&
isspace((
unsigned char)*++sep))
13094 acceptedWebSocketSubprotocol =
13099 }
while (sep && !acceptedWebSocketSubprotocol);
13101 && !acceptedWebSocketSubprotocol);
13104 acceptedWebSocketSubprotocol;
13116 conn->
request_info.acceptedWebSocketSubprotocol = protocol;
13126 while (
isspace((
unsigned char)*++sep)) {
13133#if defined(USE_ZLIB) && defined(MG_EXPERIMENTAL_INTERFACES)
13148#if defined(USE_LUA)
13160 if (!conn->lua_websocket_state) {
13189#if defined(USE_LUA)
13201#if defined(USE_LUA)
13207#if defined(USE_ZLIB) && defined(MG_EXPERIMENTAL_INTERFACES)
13209 if (conn->websocket_deflate_initialized) {
13292 if ((
n > 0) && ((
size_t)
n ==
vec->
len)) {
13293 if ((
a < 256) && (
b < 256) && (
c < 256) && (
d < 256) && (
slash < 33)) {
13296 uint32_t
ip =
ntohl(sa->
sin.sin_addr.s_addr);
13297 uint32_t net = ((uint32_t)
a << 24) | ((uint32_t)
b << 16)
13298 | ((uint32_t)
c << 8) | (uint32_t)
d;
13300 return (
ip &
mask) == net;
13305#if defined(USE_IPV6)
13321 if (((
size_t)(
p -
vec->
ptr) <
sizeof(
ad))
13328 }
else if (
vec->
len <
sizeof(
ad)) {
13339 while (
isxdigit((
unsigned char)*
p) || (*
p ==
'.') || (*
p ==
':')) {
13340 if (*(
p++) ==
':') {
13344 if ((*
p ==
'\0') && (
c >= 2)) {
13354 for (i = 0; i < 16; i++) {
13355 uint8_t
ip = sa->sin6.sin6_addr.s6_addr[i];
13356 uint8_t net =
sin6.sin6_addr.s6_addr[i];
13359 if (8 * i + 8 <
slash) {
13361 }
else if (8 * i <
slash) {
13362 mask = (uint8_t)(0xFFu << (8 * i + 8 -
slash));
13364 if ((
ip &
mask) != net) {
13399 && (
mult !=
','))) {
13434 for (i = 0; ((idx == -1) && (
i < ctx->num_listening_sockets)); i++) {
13461 DEBUG_TRACE(
"%s",
"Host name format error '[' without ']'");
13498 DEBUG_TRACE(
"Host mismatch: SNI: %s, HTTPS: %.*s",
13529 conn->
ssl ?
"S" :
"",
13661 if (!phys_ctx || !dom_ctx) {
13738 "Cannot create new request handler struct, OOM");
13747 "Cannot create new request handler struct, OOM");
13881 if (request_info) {
13882 const char *uri = request_info->
local_uri;
13893 for (step = 0; step < 3; step++) {
13903 }
else if (step == 1) {
13963#if defined(USE_WEBSOCKET) && defined(MG_EXPERIMENTAL_INTERFACES)
14029 void *callback_data =
NULL;
14062 "Error: SSL forward not configured properly");
14065 "Can not redirect to SSL, no SSL port available");
14107 if (conn->
phys_ctx->callbacks.begin_request !=
NULL) {
14111 i = conn->
phys_ctx->callbacks.begin_request(conn);
14120 }
else if (i == 0) {
14148 "Access-Control-Request-Method");
14161 "Access-Control-Request-Headers");
14165 "HTTP/1.1 200 OK\r\n"
14167 "Access-Control-Allow-Origin: %s\r\n"
14168 "Access-Control-Allow-Methods: %s\r\n"
14169 "Content-Length: 0\r\n"
14170 "Connection: %s\r\n",
14188 "Access-Control-Allow-Headers: %s\r\n",
14195 "Access-Control-Allow-Credentials: %s\r\n",
14199 mg_printf(conn,
"Access-Control-Max-Age: 60\r\n");
14212#if defined(USE_WEBSOCKET)
14283#if defined(NO_FILES)
14295 "%s method not allowed",
14300#if !defined(NO_FILES)
14384#if defined(USE_WEBSOCKET)
14400#if defined(USE_WEBSOCKET)
14427#if defined(NO_FILES)
14471 "%s method not allowed",
14484 if (file.
stat.is_directory && (uri_len > 0)
14485 && (ri->
local_uri[uri_len - 1] !=
'/')) {
14528 "%s method not allowed",
14534 if (file.
stat.is_directory) {
14545 "Error: Directory listing denied");
14558#if !defined(NO_CACHING)
14573#if !defined(NO_FILESYSTEMS)
14579#if !defined(NO_CGI)
14583 if (!conn || !conn->
dom_ctx) {
14587#if defined(USE_LUA)
14616#if defined(USE_DUKTAPE)
14631#if !defined(NO_CGI)
14663#if !defined(NO_CACHING)
14686#if defined(USE_X_DOM_SOCKET)
14724 unsigned int a,
b,
c,
d;
14730#if defined(USE_IPV6)
14731 char buf[100] = {0};
14737 memset(so, 0,
sizeof(*so));
14747 "%u.%u.%u.%u:%u%n",
14758 so->
lsa.sin.sin_addr.s_addr =
14759 htonl((
a << 24) | (
b << 16) | (
c << 8) |
d);
14760 so->
lsa.sin.sin_port =
htons((uint16_t)port);
14763#if defined(USE_IPV6)
14771 so->
lsa.sin6.sin6_port =
htons((uint16_t)port);
14775 }
else if ((
vec->
ptr[0] ==
'+')
14786#if defined(USE_IPV6)
14789 so->
lsa.sin6.sin6_port =
htons((uint16_t)port);
14793 so->
lsa.sin.sin_port =
htons((uint16_t)port);
14800 port = (uint16_t)
portUL;
14802 so->
lsa.sin.sin_port =
htons((uint16_t)port);
14828 if (
sscanf(cb + 1,
"%u%n", &port, &
len)
14834 so->
lsa.sin.sin_port =
htons((uint16_t)port);
14839#if defined(USE_IPV6)
14843 sizeof(so->
lsa.sin6),
14845 if (
sscanf(cb + 1,
"%u%n", &port, &
len) == 1) {
14847 so->
lsa.sin6.sin6_port =
htons((uint16_t)port);
14857#if defined(USE_X_DOM_SOCKET)
14859 }
else if (
vec->
ptr[0] ==
'x') {
14861 if (
vec->
len <
sizeof(so->
lsa.sun.sun_path)) {
14864 memset(so->
lsa.sun.sun_path, 0,
sizeof(so->
lsa.sun.sun_path));
14885 so->
is_ssl = (ch ==
's');
14887 if ((ch ==
'\0') || (ch ==
's') || (ch ==
'r')) {
14961#if defined(USE_IPV6)
14982 memset(&so, 0,
sizeof(so));
14994 "%.*s: invalid port spec (entry %i). Expecting list of: %s",
14998 "[IP_ADDRESS:]PORT[s|r]");
15002#if !defined(NO_SSL)
15006 "Cannot add SSL socket (entry %i)",
15022 "cannot create socket (entry %i)",
15047 "cannot set socket option SO_EXCLUSIVEADDRUSE (entry %i)",
15061 "cannot set socket option SO_REUSEADDR (entry %i)",
15066#if defined(USE_X_DOM_SOCKET)
15074#if defined(USE_IPV6)
15086 "cannot set socket option "
15087 "IPV6_V6ONLY=off (entry %i)",
15101 "cannot set socket option "
15102 "IPV6_V6ONLY=on (entry %i)",
15116 len =
sizeof(so.
lsa.sin);
15119 "cannot bind to %.*s: %d (%s)",
15129#if defined(USE_IPV6)
15132 len =
sizeof(so.
lsa.sin6);
15135 "cannot bind to IPv6 %.*s: %d (%s)",
15146#if defined(USE_X_DOM_SOCKET)
15149 len =
sizeof(so.
lsa.sun);
15152 "cannot bind to unix socket %s: %d (%s)",
15153 so.
lsa.sun.sun_path,
15165 "cannot bind: address family not supported (entry %i)",
15176 "%s value \"%s\" is invalid",
15187 "cannot listen to %.*s: %d (%s)",
15198 || (
usa.
sa.sa_family != so.
lsa.sa.sa_family)) {
15202 "call to getsockname failed %.*s: %d (%s)",
15213#if defined(USE_IPV6)
15215 so.
lsa.sin6.sin6_port =
usa.sin6.sin6_port;
15219 so.
lsa.sin.sin_port =
usa.
sin.sin_port;
15222 if ((ptr = (
struct socket *)
15279#if defined(MG_EXTERNAL_FUNCTION_log_access)
15280#include "external_log_access.inl"
15281#elif !defined(NO_FILESYSTEMS)
15296 if (!conn || !conn->
dom_ctx) {
15303#if defined(USE_LUA)
15304 if (conn->
phys_ctx->lua_bg_log_available) {
15327 if ((
len == 0) || (*
txt == 0)) {
15360 if ((
fi.access.fp ==
NULL)
15385 "%s - %s [%s] \"%s %s%s%s HTTP/%s\" %d %" INT64_FMT
15402 if (conn->
phys_ctx->callbacks.log_access) {
15405 if (
fi.access.fp) {
15413 if (
fi.access.fp) {
15428 "Error writing log file %s",
15434#error "Either enable filesystems or provide a custom log_access implementation"
15463 "%s: subnet must be [+|-]IP-addr[/x]",
15478#if !defined(_WIN32) && !defined(__ZEPHYR__)
15495 "%s: unknown user [%s]",
15507 "%s: setgid(%s): %s",
15513 "%s: setgroups(): %s",
15518 "%s: setuid(%s): %s",
15540 if (
tls->is_master == 2) {
15541 tls->is_master = -3;
15549#if defined(USE_MBEDTLS)
15560 dom_ctx = &(phys_ctx->
dd);
15580#elif !defined(NO_SSL)
15585 const char *
chain);
15617 if ((t != 0) && (conn->
dom_ctx->ssl_cert_last_mtime != t)) {
15618 conn->
dom_ctx->ssl_cert_last_mtime = t;
15642 "SSL_CTX_load_verify_locations error: %s "
15643 "ssl_verify_peer requires setting "
15644 "either ssl_ca_path or ssl_ca_file. Is any of them "
15662#if defined(OPENSSL_API_1_1)
15669 int (*func)(
SSL *),
15730 for (i = 0; i <=
timeout; i += 50) {
15733 ret = func(conn->ssl);
15753 pfd.fd = conn->client.sock;
15759 mg_poll(&
pfd, 1, 50, &(conn->phys_ctx->stop_flag));
15810 const char hexdigit[] =
"0123456789abcdef";
15812 if ((
memlen <= 0) || (buflen <= 0)) {
15815 if (buflen < (3 *
memlen)) {
15819 for (i = 0; i <
memlen; i++) {
15821 buf[3 * i - 1] =
' ';
15823 buf[3 * i] =
hexdigit[(((uint8_t *)
mem)[i] >> 4) & 0xF];
15824 buf[3 * i + 1] =
hexdigit[((uint8_t *)
mem)[i] & 0xF];
15826 buf[3 *
memlen - 1] = 0;
15839 unsigned char buf[256];
15844 unsigned char *
tmp_p;
15907#if defined(OPENSSL_API_1_1)
15925#if !defined(NO_SSL_DL)
15948 "%s: cannot load %s",
15969 if (
u.fp ==
NULL) {
15983 "%s: %s: cannot find %s",
16024#if defined(SSL_ALREADY_INITIALIZED)
16036#if !defined(OPENSSL_API_1_1) && !defined(OPENSSL_API_3_0)
16045#if !defined(NO_SSL_DL)
16055 "%s: error loading library %s",
16068#if !defined(OPENSSL_API_1_1) && !defined(OPENSSL_API_3_0)
16092 "%s: cannot allocate mutexes: %s",
16106 "%s: error initializing mutex %i of %i",
16121#if !defined(NO_SSL_DL)
16126#if !defined(OPENSSL_API_1_1)
16135#if (defined(OPENSSL_API_1_1) || defined(OPENSSL_API_3_0)) \
16136 && !defined(NO_SSL_DL)
16160 "%s: cannot open certificate file %s: %s",
16170 "%s: cannot open private key file %s: %s",
16179 "%s: certificate and private key do not match: %s",
16196 "%s: cannot use certificate chain file %s: %s",
16207#if defined(OPENSSL_API_1_1)
16208static unsigned long
16222#if defined(SSL_OP_NO_TLSv1_3)
16243#if defined(SSL_OP_NO_TLSv1_3)
16281#if defined(GCC_DIAGNOSTIC)
16282#pragma GCC diagnostic push
16283#pragma GCC diagnostic ignored "-Wcast-align"
16289#if defined(GCC_DIAGNOSTIC)
16290#pragma GCC diagnostic pop
16311 DEBUG_TRACE(
"%s",
"SSL connection not supporting SNI");
16346#if defined(USE_ALPN)
16347static const char alpn_proto_list[] =
"\x02h2\x08http/1.1\x08http/1.0";
16351#if defined(USE_HTTP2)
16360 const unsigned char **out,
16362 const unsigned char *in,
16363 unsigned int inlen,
16381#if defined(USE_HTTP2)
16392 for (i = 0; i <
inlen; i++) {
16409 const unsigned char **
data,
16433 "SSL_CTX_set_alpn_protos error: %s",
16470#if (defined(OPENSSL_API_1_1) || defined(OPENSSL_API_3_0)) \
16471 && !defined(NO_SSL_DL)
16474 "SSL_CTX_new (server) error: %s",
16481 "SSL_CTX_new (server) error: %s",
16487#if defined(SSL_OP_NO_TLSv1_3)
16506#if defined(SSL_OP_NO_RENEGOTIATION)
16510#if !defined(NO_SSL_DL)
16543 "SSL callback returned error: %i",
16555 : (phys_ctx->
callbacks.init_ssl_domain(
16565 "Domain SSL callback returned error: %i",
16627 "SSL_CTX_load_verify_locations error: %s "
16628 "ssl_verify_peer requires setting "
16629 "either ssl_ca_path or ssl_ca_file. "
16630 "Is any of them present in the "
16648 "SSL_CTX_set_default_verify_paths error: %s",
16664 "SSL_CTX_set_cipher_list error: %s",
16680#if defined(USE_ALPN)
16682#if !defined(NO_SSL_DL)
16711 dom_ctx = &(phys_ctx->
dd);
16723 : (phys_ctx->
callbacks.external_ssl_ctx(&ssl_ctx,
16729 "external_ssl_ctx callback returned error: %i",
16748 : (phys_ctx->
callbacks.external_ssl_ctx_domain(
16757 "external_ssl_ctx_domain callback returned error: %i",
16781 "Initializing SSL failed: -%s is not set",
16809#if defined(OPENSSL_API_1_1) || defined(OPENSSL_API_3_0)
16847#if !defined(NO_FILESYSTEMS)
16862 "Cannot open %s: %s",
16879#if defined(USE_IPV6)
16924#if defined(USE_SERVER_STATS)
16925 conn->processing_time = 0;
16951#if !defined(__ZEPHYR__)
16960 int error_code = 0;
16999#if defined(_MSC_VER)
17000#pragma warning(push)
17001#pragma warning(disable : 4244)
17003#if defined(GCC_DIAGNOSTIC)
17004#pragma GCC diagnostic push
17005#pragma GCC diagnostic ignored "-Wconversion"
17013#if defined(GCC_DIAGNOSTIC)
17014#pragma GCC diagnostic pop
17016#if defined(_MSC_VER)
17017#pragma warning(pop)
17031 (
char *)&error_code,
17041 "%s: getsockopt(SOL_SOCKET SO_ERROR) failed: %s",
17062 "%s: setsockopt(SOL_SOCKET SO_LINGER(%i,%i)) failed: %s",
17080#if defined(USE_SERVER_STATS)
17081 conn->conn_state = 6;
17084#if defined(USE_LUA) && defined(USE_WEBSOCKET)
17085 if (conn->lua_websocket_state) {
17087 conn->lua_websocket_state =
NULL;
17097 if (conn->
phys_ctx->callbacks.connection_close !=
NULL) {
17099 conn->
phys_ctx->callbacks.connection_close(conn);
17109#if defined(USE_SERVER_STATS)
17110 conn->conn_state = 7;
17113#if defined(USE_MBEDTLS)
17118#elif !defined(NO_SSL)
17129#if defined(__ZEPHYR__)
17138 if (conn->
phys_ctx->callbacks.connection_closed !=
NULL) {
17140 conn->
phys_ctx->callbacks.connection_closed(conn);
17146#if defined(USE_SERVER_STATS)
17147 conn->conn_state = 8;
17159#if defined(USE_WEBSOCKET)
17161 if (conn->in_websocket_handling) {
17181 for (i = 0; i < conn->
phys_ctx->cfg_worker_threads; i++) {
17189#if !defined(NO_SSL) && !defined(USE_MBEDTLS)
17197#if defined(USE_WEBSOCKET)
17238 if (conn ==
NULL) {
17248#if defined(GCC_DIAGNOSTIC)
17249#pragma GCC diagnostic push
17250#pragma GCC diagnostic ignored "-Wcast-align"
17256#if defined(GCC_DIAGNOSTIC)
17257#pragma GCC diagnostic pop
17279#if !defined(NO_SSL) && !defined(USE_MBEDTLS)
17280#if (defined(OPENSSL_API_1_1) || defined(OPENSSL_API_3_0)) \
17281 && !defined(NO_SSL_DL)
17289 "SSL_CTX_new error: %s",
17303 "SSL_CTX_new error: %s",
17313#if defined(USE_IPV6)
17315 :
sizeof(conn->
client.rsa.sin6);
17324 conn->
client.sock = sock;
17329 "%s: getsockname() failed: %s",
17340 "Can not create mutex");
17341#if !defined(NO_SSL) && !defined(USE_MBEDTLS)
17350#if !defined(NO_SSL) && !defined(USE_MBEDTLS)
17368 "Can not use SSL client certificate");
17382 "SSL_CTX_load_verify_locations error: %s ",
17399 "SSL connection error");
17442#if defined(MG_EXPERIMENTAL_INTERFACES)
17445 const char *protocol,
17454 if (error !=
NULL) {
17461 if ((host ==
NULL) || (protocol ==
NULL)) {
17468 "Invalid parameters");
17480#if defined(USE_WEBSOCKET)
17494 "Protocol %s not supported",
17503#if defined(USE_WEBSOCKET)
17511 ((error !=
NULL) ? error->text_buffer_size : 0),
17512 (path ? path :
""),
17516 (void *)init->callbacks);
17528 ((error !=
NULL) ? error->text_buffer_size
17534static const struct {
17539 {
"https://", 8, 443},
17541 {
"wss://", 6, 443},
17557 unsigned long port;
17563 if ((uri[0] ==
'*') && (uri[1] ==
'\0')) {
17574 for (i = 0; uri[i] != 0; i++) {
17583 if (uri[0] ==
'/') {
17627 unsigned long port = 0;
17759 "Invalid message size");
17770 "Message too large");
17782 "Malformed message");
17792 "No data received");
17833 "Bad request: Host mismatch");
17841 "Accept-Encoding"))
17843 &&
strstr(cl,
"gzip")) {
17849 "Transfer-Encoding"))
17921 "Transfer-Encoding"))
17999 "Parameter error");
18026 return (
ret == 0) ? -1 : +1;
18053 if (conn !=
NULL) {
18061 "Error sending request");
18073 if ((
ebuf[0] !=
'\0') && (conn !=
NULL)) {
18091#if defined(USE_WEBSOCKET)
18104#if !defined(_WIN32) && !defined(__ZEPHYR__)
18108 memset(&sa, 0,
sizeof(sa));
18115 if (
cdata->conn->phys_ctx) {
18116 if (
cdata->conn->phys_ctx->callbacks.init_thread) {
18120 cdata->conn->phys_ctx, 3);
18126 DEBUG_TRACE(
"%s",
"Websocket client thread exited\n");
18136 if (
cdata->conn->phys_ctx->callbacks.exit_thread) {
18137 cdata->conn->phys_ctx->callbacks.exit_thread(
cdata->conn->phys_ctx,
18167#if defined(USE_WEBSOCKET)
18169 static const char *
magic =
"x3JJHMbDL1EzLkh9GBhXDw==";
18174#if defined(__clang__)
18175#pragma clang diagnostic push
18176#pragma clang diagnostic ignored "-Wformat-nonliteral"
18194 "Unexpected error");
18202 "GET %s HTTP/1.1\r\n"
18204 "Upgrade: websocket\r\n"
18205 "Connection: Upgrade\r\n"
18206 "Sec-WebSocket-Key: %s\r\n"
18207 "Sec-WebSocket-Version: 13\r\n"
18208 "Sec-WebSocket-Extensions: %s\r\n"
18218 "GET %s HTTP/1.1\r\n"
18220 "Upgrade: websocket\r\n"
18221 "Connection: Upgrade\r\n"
18222 "Sec-WebSocket-Key: %s\r\n"
18223 "Sec-WebSocket-Version: 13\r\n"
18235 "GET %s HTTP/1.1\r\n"
18237 "Upgrade: websocket\r\n"
18238 "Connection: Upgrade\r\n"
18239 "Sec-WebSocket-Key: %s\r\n"
18240 "Sec-WebSocket-Version: 13\r\n"
18241 "Sec-WebSocket-Extensions: %s\r\n"
18249 "GET %s HTTP/1.1\r\n"
18251 "Upgrade: websocket\r\n"
18252 "Connection: Upgrade\r\n"
18253 "Sec-WebSocket-Key: %s\r\n"
18254 "Sec-WebSocket-Version: 13\r\n"
18267 "Error sending request");
18272 conn->data_len = 0;
18277 conn->request_info.local_uri_raw =
conn->request_info.request_uri;
18278 conn->request_info.local_uri =
conn->request_info.local_uri_raw;
18280#if defined(__clang__)
18281#pragma clang diagnostic pop
18284 if (
conn->response_info.status_code != 101) {
18295 "Unexpected server reply");
18316 conn->phys_ctx->worker_threadids =
18318 if (!
conn->phys_ctx->worker_threadids) {
18326 conn->phys_ctx->user_data = user_data;
18328 conn->phys_ctx->cfg_worker_threads = 1;
18335 conn->phys_ctx->worker_threadids)
18337 conn->phys_ctx->cfg_worker_threads = 0;
18342 "Websocket client connect thread could not be started\r\n");
18495#if defined(USE_SERVER_STATS)
18496 conn->conn_state = 2;
18500 if (conn->
phys_ctx->callbacks.init_connection !=
NULL) {
18502 void *conn_data =
NULL;
18503 conn->
phys_ctx->callbacks.init_connection(conn, &conn_data);
18524#if defined(USE_SERVER_STATS)
18530 DEBUG_TRACE(
"Start processing connection from %s",
18536 DEBUG_TRACE(
"calling get_request (%i times for this connection)",
18539#if defined(USE_SERVER_STATS)
18540 conn->conn_state = 3;
18559 "Bad HTTP version: [%s]",
18564 if (
ebuf[0] ==
'\0') {
18602 if (
ebuf[0] !=
'\0') {
18624 if (
ebuf[0] ==
'\0') {
18684 DEBUG_TRACE(
"internal error: data_len = %li, buf_size = %li",
18692 DEBUG_TRACE(
"Done processing connection from %s (%f sec)",
18698#if defined(USE_SERVER_STATS)
18705#if defined(ALTERNATIVE_QUEUE)
18715 if (ctx->client_socks[i].in_use == 2) {
18717 if ((ctx->client_socks[i].in_use == 2) && !ctx->
stop_flag) {
18718 ctx->client_socks[i] = *
sp;
18719 ctx->client_socks[i].in_use = 1;
18751 if (
sp->in_use == 1) {
18759 if (
sp->in_use == 1) {
18821#if defined(USE_SERVER_STATS)
18839#if defined(USE_SERVER_STATS)
18884 "Internal error: Invalid worker index %i",
18896 "Out of memory: Cannot allocate buffer for worker %i",
18916#if defined(USE_SERVER_STATS)
18917 conn->conn_state = 1;
18928#if defined(USE_SERVER_STATS)
18929 conn->conn_close_time = 0;
18948 (conn->
client.is_ssl ?
"SSL " :
""),
18953 if (conn->
client.is_ssl) {
18955#if defined(USE_MBEDTLS)
18959 (
int *)&(conn->
client.sock),
18973#elif !defined(NO_SSL)
18985#if defined(USE_HTTP2)
18987 && (!
memcmp(
tls.alpn_proto,
"\x02h2", 3))) {
19040#if defined(USE_SERVER_STATS)
19041 conn->conn_close_time = time(
NULL);
19068#if defined(USE_SERVER_STATS)
19069 conn->conn_state = 9;
19087#if !defined(__ZEPHYR__)
19091 memset(&sa, 0,
sizeof(sa));
19110#if !defined(__ZEPHYR__)
19113 memset(&so, 0,
sizeof(so));
19120 "%s: %s is not allowed to connect",
19132 "%s: getsockname() failed: %s",
19137#if !defined(__ZEPHYR__)
19155 "%s: setsockopt(SOL_SOCKET SO_KEEPALIVE) failed: %s",
19174 "%s: setsockopt(IPPROTO_TCP TCP_NODELAY) failed: %s",
19208#elif defined(USE_MASTER_THREAD_PRIORITY)
19235#if defined(USE_LUA)
19236 if (ctx->lua_background_state) {
19249 "lua_background_script",
19259 ctx->lua_bg_log_available = 1;
19304#if defined(ALTERNATIVE_QUEUE)
19322#if defined(USE_LUA)
19324 if (ctx->lua_background_state) {
19326 ctx->lua_bg_log_available = 0;
19338 "lua_background_script",
19344 ctx->lua_background_state = 0;
19380#if !defined(__ZEPHYR__)
19384 memset(&sa, 0,
sizeof(sa));
19415#if defined(ALTERNATIVE_QUEUE)
19417 if (ctx->client_wait_events !=
NULL) {
19418 for (i = 0; (unsigned)
i < ctx->cfg_worker_threads; i++) {
19421 mg_free(ctx->client_wait_events);
19432#if defined(USE_LUA)
19438 if (ctx->
dd.config[i] !=
NULL) {
19439#if defined(_MSC_VER)
19440#pragma warning(suppress : 6001)
19447 while (ctx->
dd.handlers) {
19454#if defined(USE_MBEDTLS)
19455 if (ctx->
dd.ssl_ctx !=
NULL) {
19461#elif !defined(NO_SSL)
19463 if (ctx->
dd.ssl_ctx !=
NULL) {
19464 void *ssl_ctx = (
void *)ctx->
dd.ssl_ctx;
19513#if defined(USE_TIMERS)
19526#if defined(USE_LUA)
19546#if defined(_MSC_VER)
19547#pragma warning(push)
19549#pragma warning(disable : 4996)
19552#if defined(_MSC_VER)
19553#pragma warning(pop)
19572#elif defined(__ZEPHYR__)
19615 const char *
name, *
value, *default_value;
19620 const char **options =
19625 if (error !=
NULL) {
19645 "Library uninitialized");
19664 ctx->
dd.auth_nonce_mask =
19665 (uint64_t)
get_random() ^ (uint64_t)(ptrdiff_t)(options);
19671 tls.is_master = -1;
19674 tls.pthread_cond_helper_mutex =
NULL;
19679#if !defined(ALTERNATIVE_QUEUE)
19685#if defined(USE_LUA)
19690 "Cannot initialize thread synchronization objects";
19719 ctx->
dd.handlers =
NULL;
19722#if defined(USE_LUA)
19727 while (options && (
name = *options++) !=
NULL) {
19735 "Invalid configuration option: %s",
19741 }
else if ((
value = *options++) ==
NULL) {
19748 "Invalid configuration option value: %s",
19755 if (ctx->
dd.config[idx] !=
NULL) {
19768 if ((ctx->
dd.config[i] ==
NULL) && (default_value !=
NULL)) {
19784 "Invalid configuration option value: %s",
19794#if !defined(ALTERNATIVE_QUEUE)
19805 "Invalid configuration option value: %s",
19816 "Out of memory: Cannot allocate %s",
19823 "Out of memory: Cannot allocate %s",
19847 "Invalid configuration option value: %s",
19856#if defined(NO_FILES)
19864 "Invalid configuration option value: %s",
19875#if defined(USE_LUA)
19877 ctx->lua_bg_log_available = 0;
19892 "lua_background_script load error: %s",
19899 "Error in script %s: %s",
19936 "lua_background_script start error: %s",
19943 "Error in script %s: %s",
19955 ctx->lua_background_state = (
void *)state;
19959 ctx->lua_background_state = 0;
19964#if !defined(NO_FILESYSTEMS)
19966 const char *
err_msg =
"Invalid global password file";
19984#if defined(USE_MBEDTLS)
19986 const char *
err_msg =
"Error initializing SSL context";
20003#elif !defined(NO_SSL)
20005 const char *
err_msg =
"Error initializing SSL context";
20024 const char *
err_msg =
"Failed to setup server ports";
20042#if !defined(_WIN32) && !defined(__ZEPHYR__)
20044 const char *
err_msg =
"Failed to run as configured user";
20063 const char *
err_msg =
"Failed to setup access control list";
20086 const char *
err_msg =
"Not enough memory for worker thread ID array";
20107 "Not enough memory for worker thread connection array";
20123#if defined(ALTERNATIVE_QUEUE)
20124 ctx->client_wait_events =
20126 sizeof(ctx->client_wait_events[0]),
20128 if (ctx->client_wait_events ==
NULL) {
20129 const char *
err_msg =
"Not enough memory for worker event array";
20146 ctx->client_socks =
20148 sizeof(ctx->client_socks[0]),
20150 if (ctx->client_socks ==
NULL) {
20151 const char *
err_msg =
"Not enough memory for worker socket array";
20153 mg_free(ctx->client_wait_events);
20169 for (i = 0; (unsigned)
i < ctx->cfg_worker_threads; i++) {
20171 if (ctx->client_wait_events[i] == 0) {
20172 const char *
err_msg =
"Error creating worker event %i";
20179 mg_free(ctx->client_wait_events);
20197#if defined(USE_TIMERS)
20199 const char *
err_msg =
"Error creating timers";
20242 "Cannot start worker thread %i: error %ld",
20255 "Cannot create threads: error %ld",
20264 "Cannot create first worker thread: error %ld",
20286 const char **options)
20300 const char **options,
20305 const char *default_value;
20310 if (error !=
NULL) {
20317 if ((ctx ==
NULL) || (options ==
NULL)) {
20324 "Invalid parameters");
20336 "Server already stopped");
20358 while (options && (
name = *options++) !=
NULL) {
20366 "Invalid option: %s",
20371 }
else if ((
value = *options++) ==
NULL) {
20378 "Invalid option value: %s",
20402 "Mandatory option %s missing",
20412 default_value = ctx->
dd.config[i];
20424#if defined(USE_LUA) && defined(USE_WEBSOCKET)
20428#if !defined(NO_SSL) && !defined(USE_MBEDTLS)
20437 "Initializing SSL context failed");
20454 "domain %s already in use",
20461 "Domain %s specified by %s is already in use",
20502#if !defined(NO_FILES)
20505#if !defined(NO_SSL) || defined(USE_MBEDTLS)
20508#if !defined(NO_CGI)
20511#if defined(USE_IPV6)
20514#if defined(USE_WEBSOCKET)
20517#if defined(USE_LUA)
20520#if defined(USE_DUKTAPE)
20523#if !defined(NO_CACHING)
20526#if defined(USE_SERVER_STATS)
20529#if defined(USE_ZLIB)
20532#if defined(USE_HTTP2)
20535#if defined(USE_X_DOM_SOCKET)
20541#if defined(MG_LEGACY_INTERFACE)
20544#if defined(MG_EXPERIMENTAL_INTERFACES)
20547#if !defined(NO_RESPONSE_BUFFERING)
20550#if defined(MEMORY_DEBUGGING)
20564 if ((
size_t)(end - *
dst) >
len) {
20584 static const char eol[] =
"\r\n",
eoobj[] =
"\r\n}\r\n";
20586 static const char eol[] =
"\n",
eoobj[] =
"\n}\n";
20589 if ((buffer ==
NULL) || (buflen < 1)) {
20594 end = buffer + buflen;
20596 if (buflen > (
int)(
sizeof(
eoobj) - 1)) {
20600 end -=
sizeof(
eoobj) - 1;
20613 "%s\"version\" : \"%s\"",
20629#if defined(_MSC_VER)
20630#pragma warning(push)
20632#pragma warning(disable : 4996)
20635#if defined(_MSC_VER)
20636#pragma warning(pop)
20646 ",%s\"os\" : \"Windows %u.%u\"",
20656 ",%s\"cpu\" : \"type %u, cores %u, mask %x\"",
20658 (
unsigned)
si.wProcessorArchitecture,
20659 (
unsigned)
si.dwNumberOfProcessors,
20660 (
unsigned)
si.dwActiveProcessorMask);
20662#elif defined(__ZEPHYR__)
20667 ",%s\"os\" : \"%s %s\"",
20681 ",%s\"os\" : \"%s %s (%s) - %s\"",
20697 ",%s\"features\" : %lu"
20698 ",%s\"feature_list\" : \"Server:%s%s%s%s%s%s%s%s%s\"",
20714#if defined(USE_LUA)
20719 ",%s\"lua_version\" : \"%u (%s)\"",
20725#if defined(USE_DUKTAPE)
20730 ",%s\"javascript\" : \"Duktape %u.%u.%u\"",
20741#if defined(BUILD_DATE)
20744#if defined(GCC_DIAGNOSTIC)
20745#if GCC_VERSION >= 40900
20746#pragma GCC diagnostic push
20750#pragma GCC diagnostic ignored "-Wdate-time"
20754#if defined(GCC_DIAGNOSTIC)
20755#if GCC_VERSION >= 40900
20756#pragma GCC diagnostic pop
20771#if defined(_MSC_VER)
20776 ",%s\"compiler\" : \"MSC: %u (%u)\"",
20781#elif defined(__MINGW64__)
20786 ",%s\"compiler\" : \"MinGW64: %u.%u\"",
20795 ",%s\"compiler\" : \"MinGW32: %u.%u\"",
20800#elif defined(__MINGW32__)
20805 ",%s\"compiler\" : \"MinGW32: %u.%u\"",
20810#elif defined(__clang__)
20815 ",%s\"compiler\" : \"clang: %u.%u.%u (%s)\"",
20822#elif defined(__GNUC__)
20827 ",%s\"compiler\" : \"gcc: %u.%u.%u\"",
20833#elif defined(__INTEL_COMPILER)
20838 ",%s\"compiler\" : \"Intel C/C++: %u\"",
20842#elif defined(__BORLANDC__)
20847 ",%s\"compiler\" : \"Borland C: 0x%x\"",
20851#elif defined(__SUNPRO_C)
20856 ",%s\"compiler\" : \"Solaris: 0x%x\"",
20865 ",%s\"compiler\" : \"other\"",
20878 ",%s\"data_model\" : \"int:%u/%u/%u/%u, float:%u/%u/%u, "
20880 "ptr:%u, size:%u, time:%u\"",
20882 (
unsigned)
sizeof(
short),
20883 (
unsigned)
sizeof(
int),
20884 (
unsigned)
sizeof(
long),
20885 (
unsigned)
sizeof(
long long),
20886 (
unsigned)
sizeof(
float),
20887 (
unsigned)
sizeof(
double),
20888 (
unsigned)
sizeof(
long double),
20889 (
unsigned)
sizeof(
char),
20890 (
unsigned)
sizeof(
wchar_t),
20891 (
unsigned)
sizeof(
void *),
20892 (
unsigned)
sizeof(
size_t),
20893 (
unsigned)
sizeof(time_t));
20912#if defined(USE_SERVER_STATS)
20917 static const char eol[] =
"\r\n",
eoobj[] =
"\r\n}\r\n";
20919 static const char eol[] =
"\n",
eoobj[] =
"\n}\n";
20923 if ((buffer ==
NULL) || (buflen < 1)) {
20928 end = buffer + buflen;
20930 if (buflen > (
int)(
sizeof(
eoobj) - 1)) {
20933 end -=
sizeof(
eoobj) - 1;
20951 "%s\"memory\" : {%s"
20952 "\"blocks\" : %i,%s"
20990 ",%s\"connections\" : {%s"
20991 "\"active\" : %i,%s"
20992 "\"maxActive\" : %i,%s"
21006#if !defined(ALTERNATIVE_QUEUE)
21011 ",%s\"queue\" : {%s"
21012 "\"length\" : %i,%s"
21013 "\"filled\" : %i,%s"
21014 "\"maxFilled\" : %i,%s"
21035 ",%s\"requests\" : {%s"
21036 "\"total\" : %lu%s"
21040 (
unsigned long)ctx->total_requests,
21053 ",%s\"data\" : {%s"
21075 ",%s\"time\" : {%s"
21076 "\"uptime\" : %.0f,%s"
21077 "\"start\" : \"%s\",%s"
21078 "\"now\" : \"%s\"%s"
21100 if ((buffer !=
NULL) && (buflen > 0)) {
21112 if (conn !=
NULL) {
21118#if defined(MG_EXPERIMENTAL_INTERFACES)
21135 static const char eol[] =
"\r\n",
eoobj[] =
"\r\n}\r\n";
21137 static const char eol[] =
"\n",
eoobj[] =
"\n}\n";
21140 if ((buffer ==
NULL) || (buflen < 1)) {
21145 end = buffer + buflen;
21147 if (buflen > (
int)(
sizeof(
eoobj) - 1)) {
21153 if ((ctx ==
NULL) || (idx < 0)) {
21173#if defined(USE_SERVER_STATS)
21174 state = conn->conn_state;
21212 if ((state >= 3) && (state < 9)) {
21217 "%s\"connection\" : {%s"
21219 "\"protocol\" : \"%s\",%s"
21220 "\"addr\" : \"%s\",%s"
21223 "\"handled_requests\" : %u%s"
21241 if ((state >= 4) && (state < 6)) {
21246 "%s%s\"request_info\" : {%s"
21247 "\"method\" : \"%s\",%s"
21248 "\"uri\" : \"%s\",%s"
21249 "\"query\" : %s%s%s%s"
21266 if ((state >= 2) && (state < 9)) {
21276#if defined(USE_SERVER_STATS)
21294 "%s%s\"time\" : {%s"
21295 "\"uptime\" : %.0f,%s"
21296 "\"start\" : \"%s\",%s"
21297 "\"closed\" : \"%s\"%s"
21317 "%s%s\"user\" : {%s"
21318 "\"name\" : \"%s\",%s"
21334 "%s%s\"data\" : {%s"
21341 conn->consumed_content,
21343 conn->num_bytes_sent,
21353 "%s%s\"state\" : \"%s\"",
21437#if defined(USE_LUA)
21444#if (defined(OPENSSL_API_1_0) || defined(OPENSSL_API_1_1) \
21445 || defined(OPENSSL_API_3_0)) \
21446 && !defined(NO_SSL)
21487#if (defined(OPENSSL_API_1_0) || defined(OPENSSL_API_1_1)) && !defined(NO_SSL)
21503#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 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 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 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
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,...)
@ PROTOCOL_TYPE_WEBSOCKET
@ 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 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)
static const struct @141 abs_uri_protocols[]
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)
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 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)
@ CONNECTION_TYPE_RESPONSE
@ CONNECTION_TYPE_INVALID
@ CONNECTION_TYPE_REQUEST
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)
static const struct @140 builtin_mime_types[]
#define PASSWORDS_FILE_NAME
static void close_connection(struct mg_connection *conn)
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)
@ MG_FEATURES_X_DOMAIN_SOCKET
@ MG_FEATURES_COMPRESSION
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_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)
@ 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
#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