20 #ifndef CS_MONGOOSE_SRC_COMMON_H_
21 #define CS_MONGOOSE_SRC_COMMON_H_
23 #define MG_VERSION "6.4"
27 #include <mg_locals.h>
30 #if defined(MG_ENABLE_DEBUG) && !defined(CS_ENABLE_DEBUG)
31 #define CS_ENABLE_DEBUG
33 #if defined(MG_DISABLE_STDIO) && !defined(CS_DISABLE_STDIO)
34 #define CS_DISABLE_STDIO
35 #elif defined(CS_DISABLE_STDIO) && !defined(MG_DISABLE_STDIO)
36 #define MG_DISABLE_STDIO
40 #ifdef MG_DISABLE_FILESYSTEM
41 #ifndef MG_DISABLE_DAV
42 #define MG_DISABLE_DAV
44 #ifndef MG_DISABLE_CGI
45 #define MG_DISABLE_CGI
47 #ifndef MG_DISABLE_DIRECTORY_LISTING
48 #define MG_DISABLE_DIRECTORY_LISTING
50 #ifndef MG_DISABLE_DAV
51 #define MG_DISABLE_DAV
55 #ifdef MG_NO_BSD_SOCKETS
56 #ifndef MG_DISABLE_SYNC_RESOLVER
57 #define MG_DISABLE_SYNC_RESOLVER
59 #ifndef MG_DISABLE_SOCKETPAIR
60 #define MG_DISABLE_SOCKETPAIR
66 #ifndef CS_COMMON_PLATFORM_H_
67 #define CS_COMMON_PLATFORM_H_
75 #define CS_P_WINDOWS 2
76 #define CS_P_ESP_LWIP 3
83 #if defined(TARGET_IS_MSP432P4XX) || defined(__MSP432P401R__)
85 #define CS_PLATFORM CS_P_MSP432
87 #define CS_PLATFORM CS_P_CC3200
88 #elif defined(__unix__) || defined(__APPLE__)
89 #define CS_PLATFORM CS_P_UNIX
91 #define CS_PLATFORM CS_P_WINDOWS
95 #error "CS_PLATFORM is not specified and we couldn't guess it."
104 #define NORETURN __attribute__((noreturn))
105 #define NOINLINE __attribute__((noinline))
106 #define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
110 #define WARN_UNUSED_RESULT
114 #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
118 #ifndef CS_COMMON_PLATFORMS_PLATFORM_WINDOWS_H_
119 #define CS_COMMON_PLATFORMS_PLATFORM_WINDOWS_H_
120 #if CS_PLATFORM == CS_P_WINDOWS
135 #pragma warning(disable : 4127)
136 #pragma warning(disable : 4204)
149 #include <sys/stat.h>
152 #define random() rand()
154 #pragma comment(lib, "ws2_32.lib")
157 #include <winsock2.h>
158 #include <ws2tcpip.h>
163 #define EINPROGRESS WSAEINPROGRESS
166 #define EWOULDBLOCK WSAEWOULDBLOCK
170 #define STR(x) STRX(x)
171 #define __func__ __FILE__ ":" STR(__LINE__)
173 #define snprintf _snprintf
174 #define fileno _fileno
175 #define vsnprintf _vsnprintf
176 #define sleep(x) Sleep((x) *1000)
177 #define to64(x) _atoi64(x)
178 #if !defined(__MINGW32__) && !defined(__MINGW64__)
179 #define popen(x, y) _popen((x), (y))
180 #define pclose(x) _pclose(x)
183 #if defined(_MSC_VER) && _MSC_VER >= 1400
184 #define fseeko(x, y, z) _fseeki64((x), (y), (z))
186 #define fseeko(x, y, z) fseek((x), (y), (z))
188 #define random() rand()
189 typedef int socklen_t;
193 typedef signed char int8_t;
194 typedef unsigned char uint8_t;
196 typedef unsigned int uint32_t;
197 typedef short int16_t;
198 typedef unsigned short uint16_t;
199 typedef __int64 int64_t;
200 typedef unsigned __int64 uint64_t;
202 typedef SOCKET sock_t;
203 typedef uint32_t in_addr_t;
205 #define UINT16_MAX 65535
208 #define UINT32_MAX 4294967295
213 #define INT64_FMT "I64d"
214 #define INT64_X_FMT "I64x"
215 #define SIZE_T_FMT "Iu"
216 #if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
217 typedef struct stat cs_stat_t;
219 typedef struct _stati64 cs_stat_t;
222 #define S_ISDIR(x) (((x) &_S_IFMT) == _S_IFDIR)
225 #define S_ISREG(x) (((x) &_S_IFMT) == _S_IFREG)
231 #define va_copy __va_copy
233 #define va_copy(x, y) (x) = (y)
237 #ifndef MG_MAX_HTTP_REQUEST_SIZE
238 #define MG_MAX_HTTP_REQUEST_SIZE 8192
241 #ifndef MG_MAX_HTTP_SEND_MBUF
242 #define MG_MAX_HTTP_SEND_MBUF 4096
245 #ifndef MG_MAX_HTTP_HEADERS
246 #define MG_MAX_HTTP_HEADERS 40
251 #ifndef CS_COMMON_PLATFORMS_PLATFORM_UNIX_H_
252 #define CS_COMMON_PLATFORMS_PLATFORM_UNIX_H_
253 #if CS_PLATFORM == CS_P_UNIX
255 #ifndef _XOPEN_SOURCE
256 #define _XOPEN_SOURCE 600
260 #ifndef __STDC_FORMAT_MACROS
261 #define __STDC_FORMAT_MACROS
265 #ifndef __STDC_LIMIT_MACROS
266 #define __STDC_LIMIT_MACROS
270 #ifndef _LARGEFILE_SOURCE
271 #define _LARGEFILE_SOURCE
275 #ifndef _FILE_OFFSET_BITS
276 #define _FILE_OFFSET_BITS 64
279 #include <arpa/inet.h>
285 #include <inttypes.h>
289 #include <netinet/in.h>
296 #include <sys/socket.h>
297 #include <sys/select.h>
298 #include <sys/stat.h>
299 #include <sys/time.h>
300 #include <sys/types.h>
308 #if !(defined(__DARWIN_C_LEVEL) && __DARWIN_C_LEVEL >= 200809L)
309 long long strtoll(
const char *,
char **,
int);
313 #define INVALID_SOCKET (-1)
314 #define SIZE_T_FMT "zu"
315 typedef struct stat cs_stat_t;
317 #define to64(x) strtoll(x, NULL, 10)
318 #define INT64_FMT PRId64
319 #define INT64_X_FMT PRIx64
327 #define va_copy __va_copy
329 #define va_copy(x, y) (x) = (y)
333 #define closesocket(x) close(x)
335 #ifndef MG_MAX_HTTP_REQUEST_SIZE
336 #define MG_MAX_HTTP_REQUEST_SIZE 8192
339 #ifndef MG_MAX_HTTP_SEND_MBUF
340 #define MG_MAX_HTTP_SEND_MBUF 4096
343 #ifndef MG_MAX_HTTP_HEADERS
344 #define MG_MAX_HTTP_HEADERS 40
349 #ifndef CS_COMMON_PLATFORMS_PLATFORM_ESP_LWIP_H_
350 #define CS_COMMON_PLATFORMS_PLATFORM_ESP_LWIP_H_
351 #if CS_PLATFORM == CS_P_ESP_LWIP
356 #include <inttypes.h>
358 #include <sys/stat.h>
359 #include <sys/time.h>
361 #include <lwip/err.h>
362 #include <lwip/ip_addr.h>
363 #include <lwip/inet.h>
364 #include <lwip/netdb.h>
365 #include <lwip/dns.h>
367 #ifndef LWIP_PROVIDE_ERRNO
371 #define LWIP_TIMEVAL_PRIVATE 0
374 #include <lwip/sockets.h>
379 #define LWIP_SOCKET 1
380 #include <lwip/sockets.h>
382 #define LWIP_SOCKET 0
386 #define INVALID_SOCKET (-1)
387 #define SIZE_T_FMT "u"
388 typedef struct stat cs_stat_t;
390 #define to64(x) strtoll(x, NULL, 10)
391 #define INT64_FMT PRId64
392 #define INT64_X_FMT PRIx64
395 unsigned long os_random(
void);
396 #define random os_random
405 #ifndef CS_COMMON_PLATFORMS_PLATFORM_CC3200_H_
406 #define CS_COMMON_PLATFORMS_PLATFORM_CC3200_H_
407 #if CS_PLATFORM == CS_P_CC3200
412 #include <inttypes.h>
417 #ifndef __TI_COMPILER_VERSION__
419 #include <sys/time.h>
422 #define MG_SOCKET_SIMPLELINK 1
423 #define MG_DISABLE_SOCKETPAIR 1
424 #define MG_DISABLE_SYNC_RESOLVER 1
425 #define MG_DISABLE_POPEN 1
426 #define MG_DISABLE_CGI 1
428 #ifndef CC3200_FS_SPIFFS
429 #define MG_DISABLE_DAV 1
430 #define MG_DISABLE_DIRECTORY_LISTING 1
435 #define INVALID_SOCKET (-1)
436 #define SIZE_T_FMT "u"
437 typedef struct stat cs_stat_t;
439 #define to64(x) strtoll(x, NULL, 10)
440 #define INT64_FMT PRId64
441 #define INT64_X_FMT PRIx64
452 #ifdef __TI_COMPILER_VERSION__
454 #define timeval SlTimeval_t
455 int gettimeofday(
struct timeval *
t,
void *tz);
457 int asprintf(
char **strp,
const char *fmt, ...);
461 long int random(
void);
464 #ifdef __TI_COMPILER_VERSION__
468 typedef unsigned int mode_t;
469 typedef size_t _off_t;
470 typedef long ssize_t;
480 int _stat(
const char *pathname,
struct stat *st);
481 #define stat(a, b) _stat(a, b)
483 #define __S_IFMT 0170000
485 #define __S_IFDIR 0040000
486 #define __S_IFCHR 0020000
487 #define __S_IFREG 0100000
489 #define __S_ISTYPE(mode, mask) (((mode) &__S_IFMT) == (mask))
491 #define S_IFDIR __S_IFDIR
492 #define S_IFCHR __S_IFCHR
493 #define S_IFREG __S_IFREG
494 #define S_ISDIR(mode) __S_ISTYPE((mode), __S_IFDIR)
495 #define S_ISREG(mode) __S_ISTYPE((mode), __S_IFREG)
498 #define va_copy(apc, ap) ((apc) = (ap))
502 #ifdef CC3200_FS_SPIFFS
503 #include <common/spiffs/spiffs.h>
507 struct spiffs_dirent de;
511 #define dirent spiffs_dirent
513 DIR *opendir(
const char *dir_name);
514 int closedir(DIR *dir);
515 struct dirent *readdir(DIR *dir);
518 #ifdef CC3200_FS_SLFS
533 #ifndef CS_COMMON_PLATFORMS_PLATFORM_MSP432_H_
534 #define CS_COMMON_PLATFORMS_PLATFORM_MSP432_H_
535 #if CS_PLATFORM == CS_P_MSP432
540 #include <inttypes.h>
545 #ifndef __TI_COMPILER_VERSION__
547 #include <sys/time.h>
550 #define MG_SOCKET_SIMPLELINK 1
551 #define MG_DISABLE_SOCKETPAIR 1
552 #define MG_DISABLE_SYNC_RESOLVER 1
553 #define MG_DISABLE_POPEN 1
554 #define MG_DISABLE_CGI 1
555 #define MG_DISABLE_DAV 1
556 #define MG_DISABLE_DIRECTORY_LISTING 1
560 #define INVALID_SOCKET (-1)
561 #define SIZE_T_FMT "u"
562 typedef struct stat cs_stat_t;
564 #define to64(x) strtoll(x, NULL, 10)
565 #define INT64_FMT PRId64
566 #define INT64_X_FMT PRIx64
577 #ifdef __TI_COMPILER_VERSION__
579 #define timeval SlTimeval_t
580 int gettimeofday(
struct timeval *
t,
void *tz);
583 long int random(
void);
586 #ifdef __TI_COMPILER_VERSION__
590 typedef unsigned int mode_t;
591 typedef size_t _off_t;
592 typedef long ssize_t;
602 int _stat(
const char *pathname,
struct stat *st);
603 #define stat(a, b) _stat(a, b)
605 #define __S_IFMT 0170000
607 #define __S_IFDIR 0040000
608 #define __S_IFCHR 0020000
609 #define __S_IFREG 0100000
611 #define __S_ISTYPE(mode, mask) (((mode) &__S_IFMT) == (mask))
613 #define S_IFDIR __S_IFDIR
614 #define S_IFCHR __S_IFCHR
615 #define S_IFREG __S_IFREG
616 #define S_ISDIR(mode) __S_ISTYPE((mode), __S_IFDIR)
617 #define S_ISREG(mode) __S_ISTYPE((mode), __S_IFREG)
620 #define va_copy(apc, ap) ((apc) = (ap))
635 #ifndef CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_
636 #define CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_
639 #if defined(MG_SOCKET_SIMPLELINK) && !defined(__SIMPLELINK_H__)
643 #ifndef __TI_COMPILER_VERSION__
655 #define PROVISIONING_API_H_
656 #include <simplelink/user.h>
657 #undef PROVISIONING_API_H_
658 #undef SL_INC_STD_BSD_API_NAMING
660 #include <simplelink/include/simplelink.h>
664 #define AF_INET SL_AF_INET
666 #define socklen_t SlSocklen_t
667 #define sockaddr SlSockAddr_t
668 #define sockaddr_in SlSockAddrIn_t
669 #define in_addr SlInAddr_t
671 #define SOCK_STREAM SL_SOCK_STREAM
672 #define SOCK_DGRAM SL_SOCK_DGRAM
674 #define FD_SET SL_FD_SET
675 #define FD_CLR SL_FD_CLR
676 #define FD_ISSET SL_FD_ISSET
677 #define FD_ZERO SL_FD_ZERO
678 #define fd_set SlFdSet_t
680 #define htonl sl_Htonl
681 #define ntohl sl_Ntohl
682 #define htons sl_Htons
683 #define ntohs sl_Ntohs
685 #define accept sl_Accept
686 #define closesocket sl_Close
688 #define connect sl_Connect
689 #define listen sl_Listen
691 #define recvfrom sl_RecvFrom
693 #define sendto sl_SendTo
694 #define socket sl_Socket
696 #define select(nfds, rfds, wfds, efds, tout) \
697 sl_Select((nfds), (rfds), (wfds), (efds), (struct SlTimeval_t *)(tout))
700 #define EACCES SL_EACCES
703 #define EAFNOSUPPORT SL_EAFNOSUPPORT
706 #define EAGAIN SL_EAGAIN
709 #define EBADF SL_EBADF
712 #define EINVAL SL_EINVAL
715 #define ENOMEM SL_ENOMEM
718 #define EWOULDBLOCK SL_EWOULDBLOCK
727 const char *inet_ntop(
int af,
const void *src,
char *dst, socklen_t
size);
728 char *inet_ntoa(
struct in_addr
in);
729 int inet_pton(
int af,
const char *src,
void *dst);
733 typedef void (*mg_init_cb)(
struct mg_mgr *mgr);
734 bool mg_start_task(
int priority,
int stack_size, mg_init_cb mg_init);
736 void mg_run_in_task(
void (*
cb)(
struct mg_mgr *mgr,
void *arg),
void *cb_arg);
752 #ifndef CS_COMMON_CS_DBG_H_
753 #define CS_COMMON_CS_DBG_H_
755 #ifndef CS_DISABLE_STDIO
777 #ifndef CS_DISABLE_STDIO
786 if (cs_log_level >= l) { \
787 cs_log_print_prefix(__func__); \
794 if (cs_log_level >= LL_VERBOSE_DEBUG) { \
795 cs_log_print_prefix(__func__); \
822 #ifndef CS_COMMON_CS_TIME_H_
823 #define CS_COMMON_CS_TIME_H_
851 #ifndef CS_COMMON_MBUF_H_
852 #define CS_COMMON_MBUF_H_
854 #if defined(__cplusplus)
860 #ifndef MBUF_SIZE_MULTIPLIER
861 #define MBUF_SIZE_MULTIPLIER 1.5
910 #if defined(__cplusplus)
920 #ifndef CS_COMMON_SHA1_H_
921 #define CS_COMMON_SHA1_H_
939 void cs_hmac_sha1(
const unsigned char *key,
size_t key_len,
940 const unsigned char *
text,
size_t text_len,
941 unsigned char out[20]);
954 #ifndef CS_COMMON_MD5_H_
955 #define CS_COMMON_MD5_H_
965 unsigned char in[64];
980 char *
cs_md5(
char buf[33], ...);
987 void cs_to_hex(
char *to,
const unsigned char *
p,
size_t len);
999 #ifndef CS_COMMON_BASE64_H_
1000 #define CS_COMMON_BASE64_H_
1002 #ifndef DISABLE_BASE64
1041 #ifndef CS_COMMON_STR_UTIL_H_
1042 #define CS_COMMON_STR_UTIL_H_
1051 size_t c_strnlen(
const char *
s,
size_t maxlen);
1053 int c_vsnprintf(
char *buf,
size_t buf_size,
const char *format, va_list ap);
1058 const char *
c_strnstr(
const char *s,
const char *find,
size_t slen);
1084 #ifndef CS_MONGOOSE_DEPS_FROZEN_FROZEN_H_
1085 #define CS_MONGOOSE_DEPS_FROZEN_FROZEN_H_
1112 #define JSON_STRING_INVALID -1
1113 #define JSON_STRING_INCOMPLETE -2
1114 #define JSON_TOKEN_ARRAY_TOO_SMALL -3
1116 int parse_json(
const char *json_string,
int json_string_length,
1117 struct json_token *tokens_array,
int size_of_tokens_array);
1125 int json_emit(
char *buf,
int buf_len,
const char *fmt, ...);
1126 int json_emit_va(
char *buf,
int buf_len,
const char *fmt, va_list);
1160 #ifndef CS_MONGOOSE_SRC_NET_H_
1161 #define CS_MONGOOSE_SRC_NET_H_
1163 #ifdef MG_ENABLE_JAVASCRIPT
1164 #define EXCLUDE_COMMON
1169 #ifdef MG_ENABLE_SSL
1171 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
1173 #include <openssl/ssl.h>
1179 #ifndef MG_VPRINTF_BUFFER_SIZE
1180 #define MG_VPRINTF_BUFFER_SIZE 100
1183 #ifdef MG_USE_READ_WRITE
1184 #define MG_RECV_FUNC(s, b, l, f) read(s, b, l)
1185 #define MG_SEND_FUNC(s, b, l, f) write(s, b, l)
1187 #define MG_RECV_FUNC(s, b, l, f) recv(s, b, l, f)
1188 #define MG_SEND_FUNC(s, b, l, f) send(s, b, l, f)
1198 #ifdef MG_ENABLE_IPV6
1199 struct sockaddr_in6
sin6;
1220 #define MG_EV_POLL 0
1221 #define MG_EV_ACCEPT 1
1222 #define MG_EV_CONNECT 2
1223 #define MG_EV_RECV 3
1224 #define MG_EV_SEND 4
1225 #define MG_EV_CLOSE 5
1226 #define MG_EV_TIMER 6
1234 #ifndef MG_DISABLE_SOCKETPAIR
1239 #ifdef MG_ENABLE_JAVASCRIPT
1279 #define MG_F_LISTENING (1 << 0)
1280 #define MG_F_UDP (1 << 1)
1281 #define MG_F_RESOLVING (1 << 2)
1282 #define MG_F_CONNECTING (1 << 3)
1283 #define MG_F_SSL_HANDSHAKE_DONE (1 << 4)
1284 #define MG_F_WANT_READ (1 << 5)
1285 #define MG_F_WANT_WRITE (1 << 6)
1286 #define MG_F_IS_WEBSOCKET (1 << 7)
1289 #define MG_F_SEND_AND_CLOSE (1 << 10)
1290 #define MG_F_CLOSE_IMMEDIATELY (1 << 11)
1291 #define MG_F_WEBSOCKET_NO_DEFRAG (1 << 12)
1292 #define MG_F_DELETE_CHUNK (1 << 13)
1294 #define MG_F_USER_1 (1 << 20)
1295 #define MG_F_USER_2 (1 << 21)
1296 #define MG_F_USER_3 (1 << 22)
1297 #define MG_F_USER_4 (1 << 23)
1298 #define MG_F_USER_5 (1 << 24)
1299 #define MG_F_USER_6 (1 << 25)
1329 #ifndef MG_DISABLE_SOCKETPAIR
1400 #ifdef MG_ENABLE_SSL
1402 const char *ssl_cert;
1403 const char *ssl_ca_cert;
1440 #ifdef MG_ENABLE_SSL
1442 const char *ssl_cert;
1443 const char *ssl_ca_cert;
1452 const char *ssl_server_name;
1528 const char *ca_cert);
1540 #if defined(__GNUC__)
1572 #ifndef MG_DISABLE_SYNC_RESOLVER
1573 int mg_resolve(
const char *domain_name,
char *ip_addr_buf,
size_t buf_len);
1607 #ifdef MG_ENABLE_JAVASCRIPT
1614 enum v7_err mg_enable_javascript(
struct mg_mgr *
m,
struct v7 *v7,
1615 const char *init_js_file_name);
1659 #ifndef CS_MONGOOSE_SRC_NET_IF_H_
1660 #define CS_MONGOOSE_SRC_NET_IF_H_
1751 #ifndef CS_MONGOOSE_SRC_URI_H_
1752 #define CS_MONGOOSE_SRC_URI_H_
1785 struct mg_str *fragment);
1802 #ifndef CS_MONGOOSE_SRC_UTIL_H_
1803 #define CS_MONGOOSE_SRC_UTIL_H_
1812 #ifndef MAX_PATH_SIZE
1813 #define MAX_PATH_SIZE 500
1825 const char *
mg_skip(
const char *
s,
const char *end_string,
1826 const char *delimiters,
struct mg_str *
v);
1831 int mg_ncasecmp(
const char *s1,
const char *s2,
size_t len);
1836 int mg_casecmp(
const char *s1,
const char *s2);
1868 #ifndef MG_DISABLE_FILESYSTEM
1897 #if defined(_WIN32) && !defined(MG_ENABLE_THREADS)
1898 #define MG_ENABLE_THREADS
1901 #ifdef MG_ENABLE_THREADS
1908 void *mg_start_thread(
void *(*thread_func)(
void *),
void *thread_func_param);
1913 #define MG_SOCK_STRINGIFY_IP 1
1914 #define MG_SOCK_STRINGIFY_PORT 2
1915 #define MG_SOCK_STRINGIFY_REMOTE 4
1931 #ifndef MG_DISABLE_SOCKET_IF
1951 int mg_hexdump(
const void *buf,
int len,
char *dst,
int dst_len);
1961 const void *buf,
int num_bytes,
int ev);
1977 int mg_avprintf(
char **buf,
size_t size,
const char *fmt, va_list ap);
2015 #define MG_MK_STR(str_literal) \
2016 { str_literal, sizeof(str_literal) - 1 }
2031 #ifndef CS_MONGOOSE_SRC_HTTP_H_
2032 #define CS_MONGOOSE_SRC_HTTP_H_
2039 #ifndef MG_MAX_HTTP_HEADERS
2040 #define MG_MAX_HTTP_HEADERS 20
2043 #ifndef MG_MAX_HTTP_REQUEST_SIZE
2044 #define MG_MAX_HTTP_REQUEST_SIZE 1024
2049 #define MG_MAX_PATH PATH_MAX
2051 #define MG_MAX_PATH 256
2055 #ifndef MG_MAX_HTTP_SEND_MBUF
2056 #define MG_MAX_HTTP_SEND_MBUF 1024
2059 #ifndef MG_WEBSOCKET_PING_INTERVAL_SECONDS
2060 #define MG_WEBSOCKET_PING_INTERVAL_SECONDS 5
2063 #ifndef MG_CGI_ENVIRONMENT_SIZE
2064 #define MG_CGI_ENVIRONMENT_SIZE 8192
2067 #ifndef MG_MAX_CGI_ENVIR_VARS
2068 #define MG_MAX_CGI_ENVIR_VARS 64
2071 #ifndef MG_ENV_EXPORT_TO_CGI
2072 #define MG_ENV_EXPORT_TO_CGI "MONGOOSE_CGI"
2123 #define MG_EV_HTTP_REQUEST 100
2124 #define MG_EV_HTTP_REPLY 101
2125 #define MG_EV_HTTP_CHUNK 102
2126 #define MG_EV_SSI_CALL 105
2128 #define MG_EV_WEBSOCKET_HANDSHAKE_REQUEST 111
2129 #define MG_EV_WEBSOCKET_HANDSHAKE_DONE 112
2130 #define MG_EV_WEBSOCKET_FRAME 113
2131 #define MG_EV_WEBSOCKET_CONTROL_FRAME 114
2133 #ifdef MG_ENABLE_HTTP_STREAMING_MULTIPART
2134 #define MG_EV_HTTP_MULTIPART_REQUEST 121
2135 #define MG_EV_HTTP_PART_BEGIN 122
2136 #define MG_EV_HTTP_PART_DATA 123
2137 #define MG_EV_HTTP_PART_END 124
2200 const char *extra_headers);
2213 const char *host,
const char *protocol,
2214 const char *extra_headers);
2238 const char *
url,
const char *protocol,
2239 const char *extra_headers);
2250 const char *
url,
const char *protocol,
2251 const char *extra_headers);
2272 const void *
data,
size_t data_len);
2280 const struct mg_str *strings,
int num_strings);
2289 const char *fmt, ...);
2331 const char *extra_headers);
2347 int64_t content_length,
const char *extra_headers);
2355 #define WEBSOCKET_OP_CONTINUE 0
2356 #define WEBSOCKET_OP_TEXT 1
2357 #define WEBSOCKET_OP_BINARY 2
2358 #define WEBSOCKET_OP_CLOSE 8
2359 #define WEBSOCKET_OP_PING 9
2360 #define WEBSOCKET_OP_PONG 10
2374 #define WEBSOCKET_DONT_FIN 0x100
2449 size_t var_name_len,
char *file_name,
2450 size_t file_name_len,
const char **chunk,
2474 int mg_url_decode(
const char *src,
int src_len,
char *dst,
int dst_len,
2475 int is_form_url_encoded);
2479 const char *method,
const char *uri,
2480 const char *auth_domain,
const char *user,
2481 const char *passwd);
2510 const char *extra_headers,
2511 const char *post_data);
2523 const char *extra_headers,
2524 const char *post_data);
2677 #ifdef MG_ENABLE_HTTP_STREAMING_MULTIPART
2714 void mg_file_upload_handler(
struct mg_connection *nc,
int ev,
void *ev_data,
2715 mg_fu_fname_fn local_name_fn);
2738 #ifndef CS_MONGOOSE_SRC_JSON_RPC_H_
2739 #define CS_MONGOOSE_SRC_JSON_RPC_H_
2797 const char *
id,
const char *params_fmt, ...);
2808 const char *result_fmt, ...);
2819 int code,
const char *
message,
const char *fmt, ...);
2822 #define JSON_RPC_PARSE_ERROR (-32700)
2823 #define JSON_RPC_INVALID_REQUEST_ERROR (-32600)
2824 #define JSON_RPC_METHOD_NOT_FOUND_ERROR (-32601)
2825 #define JSON_RPC_INVALID_PARAMS_ERROR (-32602)
2826 #define JSON_RPC_INTERNAL_ERROR (-32603)
2827 #define JSON_RPC_SERVER_ERROR (-32000)
2888 #ifndef CS_MONGOOSE_SRC_MQTT_H_
2889 #define CS_MONGOOSE_SRC_MQTT_H_
2916 #define MG_MQTT_CMD_CONNECT 1
2917 #define MG_MQTT_CMD_CONNACK 2
2918 #define MG_MQTT_CMD_PUBLISH 3
2919 #define MG_MQTT_CMD_PUBACK 4
2920 #define MG_MQTT_CMD_PUBREC 5
2921 #define MG_MQTT_CMD_PUBREL 6
2922 #define MG_MQTT_CMD_PUBCOMP 7
2923 #define MG_MQTT_CMD_SUBSCRIBE 8
2924 #define MG_MQTT_CMD_SUBACK 9
2925 #define MG_MQTT_CMD_UNSUBSCRIBE 10
2926 #define MG_MQTT_CMD_UNSUBACK 11
2927 #define MG_MQTT_CMD_PINGREQ 12
2928 #define MG_MQTT_CMD_PINGRESP 13
2929 #define MG_MQTT_CMD_DISCONNECT 14
2932 #define MG_MQTT_EVENT_BASE 200
2933 #define MG_EV_MQTT_CONNECT (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_CONNECT)
2934 #define MG_EV_MQTT_CONNACK (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_CONNACK)
2935 #define MG_EV_MQTT_PUBLISH (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PUBLISH)
2936 #define MG_EV_MQTT_PUBACK (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PUBACK)
2937 #define MG_EV_MQTT_PUBREC (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PUBREC)
2938 #define MG_EV_MQTT_PUBREL (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PUBREL)
2939 #define MG_EV_MQTT_PUBCOMP (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PUBCOMP)
2940 #define MG_EV_MQTT_SUBSCRIBE (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_SUBSCRIBE)
2941 #define MG_EV_MQTT_SUBACK (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_SUBACK)
2942 #define MG_EV_MQTT_UNSUBSCRIBE (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_UNSUBSCRIBE)
2943 #define MG_EV_MQTT_UNSUBACK (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_UNSUBACK)
2944 #define MG_EV_MQTT_PINGREQ (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PINGREQ)
2945 #define MG_EV_MQTT_PINGRESP (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PINGRESP)
2946 #define MG_EV_MQTT_DISCONNECT (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_DISCONNECT)
2949 #define MG_MQTT_RETAIN 0x1
2950 #define MG_MQTT_DUP 0x4
2951 #define MG_MQTT_QOS(qos) ((qos) << 1)
2952 #define MG_MQTT_GET_QOS(flags) (((flags) &0x6) >> 1)
2953 #define MG_MQTT_SET_QOS(flags, qos) (flags) = ((flags) & ~0x6) | ((qos) << 1)
2956 #define MG_MQTT_CLEAN_SESSION 0x02
2957 #define MG_MQTT_HAS_WILL 0x04
2958 #define MG_MQTT_WILL_RETAIN 0x20
2959 #define MG_MQTT_HAS_PASSWORD 0x40
2960 #define MG_MQTT_HAS_USER_NAME 0x80
2961 #define MG_MQTT_GET_WILL_QOS(flags) (((flags) &0x18) >> 3)
2962 #define MG_MQTT_SET_WILL_QOS(flags, qos) \
2963 (flags) = ((flags) & ~0x18) | ((qos) << 3)
2966 #define MG_EV_MQTT_CONNACK_ACCEPTED 0
2967 #define MG_EV_MQTT_CONNACK_UNACCEPTABLE_VERSION 1
2968 #define MG_EV_MQTT_CONNACK_IDENTIFIER_REJECTED 2
2969 #define MG_EV_MQTT_CONNACK_SERVER_UNAVAILABLE 3
2970 #define MG_EV_MQTT_CONNACK_BAD_AUTH 4
2971 #define MG_EV_MQTT_CONNACK_NOT_AUTHORIZED 5
3001 uint16_t message_id,
int flags,
const void *
data,
3007 size_t topics_len, uint16_t message_id);
3011 size_t topics_len, uint16_t message_id);
3036 uint16_t message_id);
3055 struct mg_str *topic, uint8_t *qos,
int pos);
3083 #ifndef CS_MONGOOSE_SRC_MQTT_BROKER_H_
3084 #define CS_MONGOOSE_SRC_MQTT_BROKER_H_
3086 #ifdef MG_ENABLE_MQTT_BROKER
3093 #define MG_MQTT_MAX_SESSION_SUBSCRIPTIONS 512;
3095 struct mg_mqtt_broker;
3098 struct mg_mqtt_session {
3099 struct mg_mqtt_broker *brk;
3100 struct mg_mqtt_session *
next, *prev;
3102 size_t num_subscriptions;
3108 struct mg_mqtt_broker {
3109 struct mg_mqtt_session *sessions;
3114 void mg_mqtt_broker_init(
struct mg_mqtt_broker *brk,
void *user_data);
3153 struct mg_mqtt_session *mg_mqtt_next(
struct mg_mqtt_broker *brk,
3154 struct mg_mqtt_session *
s);
3171 #ifndef CS_MONGOOSE_SRC_DNS_H_
3172 #define CS_MONGOOSE_SRC_DNS_H_
3179 #define MG_DNS_A_RECORD 0x01
3180 #define MG_DNS_CNAME_RECORD 0x05
3181 #define MG_DNS_AAAA_RECORD 0x1c
3182 #define MG_DNS_MX_RECORD 0x0f
3184 #define MG_MAX_DNS_QUESTIONS 32
3185 #define MG_MAX_DNS_ANSWERS 32
3187 #define MG_DNS_MESSAGE 100
3275 const char *
name,
size_t nlen,
const void *
rdata,
3295 char *dst,
int dst_len);
3326 #ifndef CS_MONGOOSE_SRC_DNS_SERVER_H_
3327 #define CS_MONGOOSE_SRC_DNS_SERVER_H_
3329 #ifdef MG_ENABLE_DNS_SERVER
3336 #define MG_DNS_SERVER_DEFAULT_TTL 3600
3338 struct mg_dns_reply {
3372 struct mg_dns_reply mg_dns_create_reply(struct mbuf *io,
3383 int mg_dns_reply_record(
struct mg_dns_reply *reply,
3385 const char *
name,
int rtype,
int ttl,
const void *rdata,
3400 void mg_dns_send_reply(
struct mg_connection *nc,
struct mg_dns_reply *
r);
3417 #ifndef CS_MONGOOSE_SRC_RESOLV_H_
3418 #define CS_MONGOOSE_SRC_RESOLV_H_
3516 #ifndef CS_MONGOOSE_SRC_COAP_H_
3517 #define CS_MONGOOSE_SRC_COAP_H_
3519 #ifdef MG_ENABLE_COAP
3521 #define MG_COAP_MSG_TYPE_FIELD 0x2
3522 #define MG_COAP_CODE_CLASS_FIELD 0x4
3523 #define MG_COAP_CODE_DETAIL_FIELD 0x8
3524 #define MG_COAP_MSG_ID_FIELD 0x10
3525 #define MG_COAP_TOKEN_FIELD 0x20
3526 #define MG_COAP_OPTIOMG_FIELD 0x40
3527 #define MG_COAP_PAYLOAD_FIELD 0x80
3529 #define MG_COAP_ERROR 0x10000
3530 #define MG_COAP_FORMAT_ERROR (MG_COAP_ERROR | 0x20000)
3531 #define MG_COAP_IGNORE (MG_COAP_ERROR | 0x40000)
3532 #define MG_COAP_NOT_ENOUGH_DATA (MG_COAP_ERROR | 0x80000)
3533 #define MG_COAP_NETWORK_ERROR (MG_COAP_ERROR | 0x100000)
3535 #define MG_COAP_MSG_CON 0
3536 #define MG_COAP_MSG_NOC 1
3537 #define MG_COAP_MSG_ACK 2
3538 #define MG_COAP_MSG_RST 3
3539 #define MG_COAP_MSG_MAX 3
3541 #define MG_COAP_CODECLASS_REQUEST 0
3542 #define MG_COAP_CODECLASS_RESP_OK 2
3543 #define MG_COAP_CODECLASS_CLIENT_ERR 4
3544 #define MG_COAP_CODECLASS_SRV_ERR 5
3546 #define MG_COAP_EVENT_BASE 300
3547 #define MG_EV_COAP_CON (MG_COAP_EVENT_BASE + MG_COAP_MSG_CON)
3548 #define MG_EV_COAP_NOC (MG_COAP_EVENT_BASE + MG_COAP_MSG_NOC)
3549 #define MG_EV_COAP_ACK (MG_COAP_EVENT_BASE + MG_COAP_MSG_ACK)
3550 #define MG_EV_COAP_RST (MG_COAP_EVENT_BASE + MG_COAP_MSG_RST)
3557 struct mg_coap_option {
3558 struct mg_coap_option *
next;
3564 struct mg_coap_message {
3568 uint8_t code_detail;
3571 struct mg_coap_option *
options;
3573 struct mg_coap_option *optiomg_tail;
3587 struct mg_coap_option *mg_coap_add_option(
struct mg_coap_message *
cm,
3588 uint32_t number,
char *
value,
3595 void mg_coap_free_options(
struct mg_coap_message *
cm);
3609 struct mg_coap_message *
cm);
3616 uint32_t mg_coap_send_ack(
struct mg_connection *nc, uint16_t msg_id);
3633 uint32_t mg_coap_parse(
struct mbuf *io,
struct mg_coap_message *
cm);
3640 uint32_t mg_coap_compose(
struct mg_coap_message *
cm,
struct mbuf *io);