mirror of
https://github.com/webui-dev/webui.git
synced 2024-11-12 21:09:12 +03:00
Fix for 2.0.6
* Fix window can't close after link-click * WebUI-JS-Bridge logs is not enabled when building the lib in debug mode
This commit is contained in:
parent
9bcc02438e
commit
904161c9ec
@ -20,27 +20,25 @@
|
||||
#ifndef MONGOOSE_H
|
||||
#define MONGOOSE_H
|
||||
|
||||
#define MG_VERSION "7.8"
|
||||
#define MG_VERSION "7.9"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define MG_ARCH_CUSTOM 0
|
||||
#define MG_ARCH_UNIX 1
|
||||
#define MG_ARCH_WIN32 2
|
||||
#define MG_ARCH_ESP32 3
|
||||
#define MG_ARCH_ESP8266 4
|
||||
#define MG_ARCH_FREERTOS_TCP 5
|
||||
#define MG_ARCH_FREERTOS_LWIP 6
|
||||
#define MG_ARCH_AZURERTOS 7
|
||||
#define MG_ARCH_RTX_LWIP 8
|
||||
#define MG_ARCH_ZEPHYR 9
|
||||
#define MG_ARCH_NEWLIB 10
|
||||
#define MG_ARCH_RTX 11
|
||||
#define MG_ARCH_TIRTOS 12
|
||||
#define MG_ARCH_RP2040 13
|
||||
#define MG_ARCH_CUSTOM 0 // User creates its own mongoose_custom.h
|
||||
#define MG_ARCH_UNIX 1 // Linux, BSD, Mac, ...
|
||||
#define MG_ARCH_WIN32 2 // Windows
|
||||
#define MG_ARCH_ESP32 3 // ESP32
|
||||
#define MG_ARCH_ESP8266 4 // ESP8266
|
||||
#define MG_ARCH_FREERTOS 5 // FreeRTOS
|
||||
#define MG_ARCH_AZURERTOS 6 // MS Azure RTOS
|
||||
#define MG_ARCH_ZEPHYR 7 // Zephyr RTOS
|
||||
#define MG_ARCH_NEWLIB 8 // Bare metal ARM
|
||||
#define MG_ARCH_RTX 9 // Keil MDK RTX
|
||||
#define MG_ARCH_TIRTOS 10 // Texas Semi TI-RTOS
|
||||
#define MG_ARCH_RP2040 11 // Raspberry Pi RP2040
|
||||
|
||||
#if !defined(MG_ARCH)
|
||||
#if defined(__unix__) || defined(__APPLE__)
|
||||
@ -49,29 +47,32 @@ extern "C" {
|
||||
#define MG_ARCH MG_ARCH_WIN32
|
||||
#elif defined(ICACHE_FLASH) || defined(ICACHE_RAM_ATTR)
|
||||
#define MG_ARCH MG_ARCH_ESP8266
|
||||
#elif defined(__ZEPHYR__)
|
||||
#define MG_ARCH MG_ARCH_ZEPHYR
|
||||
#elif defined(ESP_PLATFORM)
|
||||
#define MG_ARCH MG_ARCH_ESP32
|
||||
#elif defined(FREERTOS_IP_H)
|
||||
#define MG_ARCH MG_ARCH_FREERTOS_TCP
|
||||
#define MG_ARCH MG_ARCH_FREERTOS
|
||||
#define MG_ENABLE_FREERTOS_TCP 1
|
||||
#elif defined(AZURE_RTOS_THREADX)
|
||||
#define MG_ARCH MG_ARCH_AZURERTOS
|
||||
#elif defined(__ZEPHYR__)
|
||||
#define MG_ARCH MG_ARCH_ZEPHYR
|
||||
#elif defined(PICO_TARGET_NAME)
|
||||
#define MG_ARCH MG_ARCH_RP2040
|
||||
#endif
|
||||
#endif // !defined(MG_ARCH)
|
||||
|
||||
#if !defined(MG_ARCH)
|
||||
#if !defined(MG_ARCH) || (MG_ARCH == MG_ARCH_CUSTOM)
|
||||
#include "mongoose_custom.h" // keep this include
|
||||
#endif
|
||||
|
||||
#if !defined(MG_ARCH)
|
||||
#error "MG_ARCH is not specified and we couldn't guess it. Set -D MG_ARCH=..."
|
||||
#endif
|
||||
#endif // !defined(MG_ARCH)
|
||||
|
||||
// http://esr.ibiblio.org/?p=5095
|
||||
#define MG_BIG_ENDIAN (*(uint16_t *)"\0\xff" < 0x100)
|
||||
#define MG_BIG_ENDIAN (*(uint16_t *) "\0\xff" < 0x100)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -162,144 +163,45 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS_LWIP
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS
|
||||
|
||||
#include <ctype.h>
|
||||
// #include <errno.h> // Cannot include errno - might conflict with lwip!
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> // rand(), strtol(), atoi()
|
||||
#include <string.h>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
struct timeval {
|
||||
time_t tv_sec;
|
||||
long tv_usec;
|
||||
};
|
||||
#endif
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
|
||||
#include <lwip/sockets.h>
|
||||
|
||||
#if LWIP_SOCKET != 1
|
||||
// Sockets support disabled in LWIP by default
|
||||
#error Set LWIP_SOCKET variable to 1 (in lwipopts.h)
|
||||
#endif
|
||||
|
||||
// Re-route calloc/free to the FreeRTOS's functions, don't use stdlib
|
||||
static inline void *mg_calloc(int cnt, size_t size) {
|
||||
void *p = pvPortMalloc(cnt * size);
|
||||
if (p != NULL) memset(p, 0, size * cnt);
|
||||
return p;
|
||||
}
|
||||
#define calloc(a, b) mg_calloc((a), (b))
|
||||
#define free(a) vPortFree(a)
|
||||
#define malloc(a) pvPortMalloc(a)
|
||||
#define strdup(s) ((char *) mg_strdup(mg_str(s)).ptr)
|
||||
#define mkdir(a, b) (-1)
|
||||
|
||||
#ifndef MG_IO_SIZE
|
||||
#define MG_IO_SIZE 512
|
||||
#endif
|
||||
|
||||
#endif // MG_ARCH == MG_ARCH_FREERTOS_LWIP
|
||||
|
||||
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <list.h>
|
||||
#include <task.h>
|
||||
|
||||
#include <FreeRTOS_IP.h>
|
||||
#include <FreeRTOS_Sockets.h>
|
||||
|
||||
// Why FreeRTOS-TCP did not implement a clean BSD API, but its own thing
|
||||
// with FreeRTOS_ prefix, is beyond me
|
||||
#define IPPROTO_TCP FREERTOS_IPPROTO_TCP
|
||||
#define IPPROTO_UDP FREERTOS_IPPROTO_UDP
|
||||
#define AF_INET FREERTOS_AF_INET
|
||||
#define SOCK_STREAM FREERTOS_SOCK_STREAM
|
||||
#define SOCK_DGRAM FREERTOS_SOCK_DGRAM
|
||||
#define SO_BROADCAST 0
|
||||
#define SO_ERROR 0
|
||||
#define SOL_SOCKET 0
|
||||
#define SO_REUSEADDR 0
|
||||
#define sockaddr_in freertos_sockaddr
|
||||
#define sockaddr freertos_sockaddr
|
||||
#define accept(a, b, c) FreeRTOS_accept((a), (b), (c))
|
||||
#define connect(a, b, c) FreeRTOS_connect((a), (b), (c))
|
||||
#define bind(a, b, c) FreeRTOS_bind((a), (b), (c))
|
||||
#define listen(a, b) FreeRTOS_listen((a), (b))
|
||||
#define socket(a, b, c) FreeRTOS_socket((a), (b), (c))
|
||||
#define send(a, b, c, d) FreeRTOS_send((a), (b), (c), (d))
|
||||
#define recv(a, b, c, d) FreeRTOS_recv((a), (b), (c), (d))
|
||||
#define setsockopt(a, b, c, d, e) FreeRTOS_setsockopt((a), (b), (c), (d), (e))
|
||||
#define sendto(a, b, c, d, e, f) FreeRTOS_sendto((a), (b), (c), (d), (e), (f))
|
||||
#define recvfrom(a, b, c, d, e, f) \
|
||||
FreeRTOS_recvfrom((a), (b), (c), (d), (e), (f))
|
||||
#define closesocket(x) FreeRTOS_closesocket(x)
|
||||
#define gethostbyname(x) FreeRTOS_gethostbyname(x)
|
||||
#define getsockname(a, b, c) (-1)
|
||||
#define getpeername(a, b, c) 0
|
||||
#define calloc(a, b) mg_calloc(a, b)
|
||||
#define free(a) vPortFree(a)
|
||||
#define malloc(a) pvPortMalloc(a)
|
||||
#define strdup(s) ((char *) mg_strdup(mg_str(s)).ptr)
|
||||
|
||||
// Re-route calloc/free to the FreeRTOS's functions, don't use stdlib
|
||||
static inline void *mg_calloc(int cnt, size_t size) {
|
||||
static inline void *mg_calloc(size_t cnt, size_t size) {
|
||||
void *p = pvPortMalloc(cnt * size);
|
||||
if (p != NULL) memset(p, 0, size * cnt);
|
||||
return p;
|
||||
}
|
||||
#define calloc(a, b) mg_calloc((a), (b))
|
||||
#define free(a) vPortFree(a)
|
||||
#define malloc(a) pvPortMalloc(a)
|
||||
#define mkdir(a, b) (-1)
|
||||
|
||||
#if !defined(__GNUC__)
|
||||
// copied from GCC on ARM; for some reason useconds are signed
|
||||
struct timeval {
|
||||
time_t tv_sec;
|
||||
long tv_usec;
|
||||
};
|
||||
#endif
|
||||
#define mkdir(a, b) mg_mkdir(a, b)
|
||||
static inline int mg_mkdir(const char *path, mode_t mode) {
|
||||
(void) path, (void) mode;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifndef EINPROGRESS
|
||||
#define EINPROGRESS pdFREERTOS_ERRNO_EINPROGRESS
|
||||
#endif
|
||||
#ifndef EWOULDBLOCK
|
||||
#define EWOULDBLOCK pdFREERTOS_ERRNO_EWOULDBLOCK
|
||||
#endif
|
||||
#ifndef EAGAIN
|
||||
#define EAGAIN pdFREERTOS_ERRNO_EAGAIN
|
||||
#endif
|
||||
#ifndef EINTR
|
||||
#define EINTR pdFREERTOS_ERRNO_EINTR
|
||||
#endif
|
||||
|
||||
// FreeRTOS-TCP uses non-standard semantics for listen() backlog size. It is
|
||||
// not a backlog size for pending SYN connections, but a max socket number
|
||||
#ifndef MG_SOCK_LISTEN_BACKLOG_SIZE
|
||||
#define MG_SOCK_LISTEN_BACKLOG_SIZE 128
|
||||
#endif
|
||||
|
||||
#endif // MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
#endif // MG_ARCH == MG_ARCH_FREERTOS
|
||||
|
||||
|
||||
#if MG_ARCH == MG_ARCH_NEWLIB
|
||||
@ -353,60 +255,10 @@ int mkdir(const char *, mode_t);
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <rl_net.h>
|
||||
|
||||
#define MG_ENABLE_CUSTOM_MILLIS 1
|
||||
typedef int socklen_t;
|
||||
#define closesocket(x) closesocket(x)
|
||||
#define mkdir(a, b) (-1)
|
||||
#define EWOULDBLOCK BSD_EWOULDBLOCK
|
||||
#define EAGAIN BSD_EWOULDBLOCK
|
||||
#define EINPROGRESS BSD_EWOULDBLOCK
|
||||
#define EINTR BSD_EWOULDBLOCK
|
||||
#define ECONNRESET BSD_ECONNRESET
|
||||
#define EPIPE BSD_ECONNRESET
|
||||
#define TCP_NODELAY SO_KEEPALIVE
|
||||
|
||||
#if !defined MG_ENABLE_RL && (!defined(MG_ENABLE_LWIP) || !MG_ENABLE_LWIP)
|
||||
#define MG_ENABLE_RL 1
|
||||
#endif
|
||||
|
||||
|
||||
#if MG_ARCH == MG_ARCH_RTX_LWIP
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
struct timeval {
|
||||
time_t tv_sec;
|
||||
long tv_usec;
|
||||
};
|
||||
#endif
|
||||
|
||||
#include <lwip/sockets.h>
|
||||
|
||||
#if LWIP_SOCKET != 1
|
||||
// Sockets support disabled in LWIP by default
|
||||
#error Set LWIP_SOCKET variable to 1 (in lwipopts.h)
|
||||
#endif
|
||||
|
||||
#define mkdir(a, b) (-1)
|
||||
|
||||
#ifndef MG_IO_SIZE
|
||||
#define MG_IO_SIZE 512
|
||||
#endif
|
||||
|
||||
#ifndef MG_PATH_MAX
|
||||
#define MG_PATH_MAX 128
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -420,13 +272,11 @@ struct timeval {
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <serrno.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
extern int SockStatus(SOCKET hSock, int request, int *results );
|
||||
extern int SockSet(SOCKET hSock, int Type, int Prop, void *pbuf, int size);
|
||||
#include <ti/sysbios/knl/Clock.h>
|
||||
|
||||
#endif
|
||||
|
||||
@ -550,6 +400,22 @@ typedef enum { false = 0, true = 1 } bool;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MG_INVALID_SOCKET INVALID_SOCKET
|
||||
#define MG_SOCKET_TYPE SOCKET
|
||||
typedef unsigned long nfds_t;
|
||||
#define MG_SOCKET_ERRNO WSAGetLastError()
|
||||
#if defined(_MSC_VER)
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
#ifndef alloca
|
||||
#define alloca(a) _alloca(a)
|
||||
#endif
|
||||
#endif
|
||||
#define poll(a, b, c) WSAPoll((a), (b), (c))
|
||||
#ifndef SO_EXCLUSIVEADDRUSE
|
||||
#define SO_EXCLUSIVEADDRUSE ((int) (~SO_REUSEADDR))
|
||||
#endif
|
||||
#define closesocket(x) closesocket(x)
|
||||
|
||||
typedef int socklen_t;
|
||||
#define MG_DIRSEP '\\'
|
||||
|
||||
@ -611,12 +477,129 @@ int sscanf(const char *, const char *, ...);
|
||||
#endif
|
||||
|
||||
|
||||
//#ifndef MG_ENABLE_LOG
|
||||
//#define MG_ENABLE_LOG 1
|
||||
//#endif
|
||||
#if defined(MG_ENABLE_FREERTOS_TCP) && MG_ENABLE_FREERTOS_TCP
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <list.h>
|
||||
#include <task.h>
|
||||
|
||||
#include <FreeRTOS_IP.h>
|
||||
#include <FreeRTOS_Sockets.h>
|
||||
|
||||
#define MG_SOCKET_TYPE Socket_t
|
||||
#define MG_INVALID_SOCKET FREERTOS_INVALID_SOCKET
|
||||
|
||||
// Why FreeRTOS-TCP did not implement a clean BSD API, but its own thing
|
||||
// with FreeRTOS_ prefix, is beyond me
|
||||
#define IPPROTO_TCP FREERTOS_IPPROTO_TCP
|
||||
#define IPPROTO_UDP FREERTOS_IPPROTO_UDP
|
||||
#define AF_INET FREERTOS_AF_INET
|
||||
#define SOCK_STREAM FREERTOS_SOCK_STREAM
|
||||
#define SOCK_DGRAM FREERTOS_SOCK_DGRAM
|
||||
#define SO_BROADCAST 0
|
||||
#define SO_ERROR 0
|
||||
#define SOL_SOCKET 0
|
||||
#define SO_REUSEADDR 0
|
||||
#define sockaddr_in freertos_sockaddr
|
||||
#define sockaddr freertos_sockaddr
|
||||
#define accept(a, b, c) FreeRTOS_accept((a), (b), (c))
|
||||
#define connect(a, b, c) FreeRTOS_connect((a), (b), (c))
|
||||
#define bind(a, b, c) FreeRTOS_bind((a), (b), (c))
|
||||
#define listen(a, b) FreeRTOS_listen((a), (b))
|
||||
#define socket(a, b, c) FreeRTOS_socket((a), (b), (c))
|
||||
#define send(a, b, c, d) FreeRTOS_send((a), (b), (c), (d))
|
||||
#define recv(a, b, c, d) FreeRTOS_recv((a), (b), (c), (d))
|
||||
#define setsockopt(a, b, c, d, e) FreeRTOS_setsockopt((a), (b), (c), (d), (e))
|
||||
#define sendto(a, b, c, d, e, f) FreeRTOS_sendto((a), (b), (c), (d), (e), (f))
|
||||
#define recvfrom(a, b, c, d, e, f) \
|
||||
FreeRTOS_recvfrom((a), (b), (c), (d), (e), (f))
|
||||
#define closesocket(x) FreeRTOS_closesocket(x)
|
||||
#define gethostbyname(x) FreeRTOS_gethostbyname(x)
|
||||
#define getsockname(a, b, c) mg_getsockname((a), (b), (c))
|
||||
#define getpeername(a, b, c) mg_getpeername((a), (b), (c))
|
||||
|
||||
static inline int mg_getsockname(MG_SOCKET_TYPE fd, void *buf, socklen_t *len) {
|
||||
(void) fd, (void) buf, (void) len;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline int mg_getpeername(MG_SOCKET_TYPE fd, void *buf, socklen_t *len) {
|
||||
(void) fd, (void) buf, (void) len;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(MG_ENABLE_LWIP) && MG_ENABLE_LWIP
|
||||
#if defined(__GNUC__)
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
struct timeval {
|
||||
time_t tv_sec;
|
||||
long tv_usec;
|
||||
};
|
||||
#endif
|
||||
|
||||
#include <lwip/sockets.h>
|
||||
|
||||
#if LWIP_SOCKET != 1
|
||||
// Sockets support disabled in LWIP by default
|
||||
#error Set LWIP_SOCKET variable to 1 (in lwipopts.h)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(MG_ENABLE_RL) && MG_ENABLE_RL
|
||||
#include <rl_net.h>
|
||||
|
||||
#define MG_ENABLE_CUSTOM_MILLIS 1
|
||||
#define closesocket(x) closesocket(x)
|
||||
#define mkdir(a, b) (-1)
|
||||
#define EWOULDBLOCK BSD_EWOULDBLOCK
|
||||
#define EAGAIN BSD_EWOULDBLOCK
|
||||
#define EINPROGRESS BSD_EWOULDBLOCK
|
||||
#define EINTR BSD_EWOULDBLOCK
|
||||
#define ECONNRESET BSD_ECONNRESET
|
||||
#define EPIPE BSD_ECONNRESET
|
||||
#define TCP_NODELAY SO_KEEPALIVE
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef MG_ENABLE_LOG
|
||||
#define MG_ENABLE_LOG 1
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_MIP
|
||||
#define MG_ENABLE_MIP 0
|
||||
#define MG_ENABLE_MIP 0 // Mongoose built-in network stack
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_LWIP
|
||||
#define MG_ENABLE_LWIP 0 // lWIP network stack
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_FREERTOS_TCP
|
||||
#define MG_ENABLE_FREERTOS_TCP 0 // Amazon FreeRTOS-TCP network stack
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_RL
|
||||
#define MG_ENABLE_RL 0 // ARM MDK network stack
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_SOCKET
|
||||
#define MG_ENABLE_SOCKET !MG_ENABLE_MIP
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_POLL
|
||||
@ -631,10 +614,6 @@ int sscanf(const char *, const char *, ...);
|
||||
#define MG_ENABLE_FATFS 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_SOCKET
|
||||
#define MG_ENABLE_SOCKET 1
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_MBEDTLS
|
||||
#define MG_ENABLE_MBEDTLS 0
|
||||
#endif
|
||||
@ -680,14 +659,16 @@ int sscanf(const char *, const char *, ...);
|
||||
#define MG_ENABLE_PACKED_FS 0
|
||||
#endif
|
||||
|
||||
// Granularity of the send/recv IO buffer growth
|
||||
#ifndef MG_IO_SIZE
|
||||
#define MG_IO_SIZE 2048
|
||||
#define MG_IO_SIZE 2048 // Granularity of the send/recv IO buffer growth
|
||||
#endif
|
||||
|
||||
// Maximum size of the recv IO buffer
|
||||
#ifndef MG_MAX_RECV_SIZE
|
||||
#define MG_MAX_RECV_SIZE (3 * 1024 * 1024)
|
||||
#define MG_MAX_RECV_SIZE (3 * 1024 * 1024) // Maximum recv IO buffer size
|
||||
#endif
|
||||
|
||||
#ifndef MG_DATA_SIZE
|
||||
#define MG_DATA_SIZE 32 // struct mg_connection :: data size
|
||||
#endif
|
||||
|
||||
#ifndef MG_MAX_HTTP_HEADERS
|
||||
@ -722,6 +703,18 @@ int sscanf(const char *, const char *, ...);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef MG_INVALID_SOCKET
|
||||
#define MG_INVALID_SOCKET (-1)
|
||||
#endif
|
||||
|
||||
#ifndef MG_SOCKET_TYPE
|
||||
#define MG_SOCKET_TYPE int
|
||||
#endif
|
||||
|
||||
#ifndef MG_SOCKET_ERRNO
|
||||
#define MG_SOCKET_ERRNO errno
|
||||
#endif
|
||||
|
||||
#if MG_ENABLE_EPOLL
|
||||
#define MG_EPOLL_ADD(c) \
|
||||
do { \
|
||||
@ -903,6 +896,10 @@ uint64_t mg_millis(void);
|
||||
#define mg_htons(x) mg_ntohs(x)
|
||||
#define mg_htonl(x) mg_ntohl(x)
|
||||
|
||||
#define MG_U32(a, b, c, d) \
|
||||
(((uint32_t) ((a) &255) << 24) | ((uint32_t) ((b) &255) << 16) | \
|
||||
((uint32_t) ((c) &255) << 8) | (uint32_t) ((d) &255))
|
||||
|
||||
// Linked list management macros
|
||||
#define LIST_ADD_HEAD(type_, head_, elem_) \
|
||||
do { \
|
||||
@ -1017,6 +1014,7 @@ enum {
|
||||
|
||||
|
||||
|
||||
|
||||
struct mg_dns {
|
||||
const char *url; // DNS server URL
|
||||
struct mg_connection *c; // DNS server connection
|
||||
@ -1044,7 +1042,7 @@ struct mg_mgr {
|
||||
int epoll_fd; // Used when MG_EPOLL_ENABLE=1
|
||||
void *priv; // Used by the MIP stack
|
||||
size_t extraconnsize; // Used by the MIP stack
|
||||
#if MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||
#if MG_ENABLE_FREERTOS_TCP
|
||||
SocketSet_t ss; // NOTE(lsm): referenced from socket struct
|
||||
#endif
|
||||
};
|
||||
@ -1062,7 +1060,7 @@ struct mg_connection {
|
||||
void *fn_data; // User-specified function parameter
|
||||
mg_event_handler_t pfn; // Protocol-specific handler function
|
||||
void *pfn_data; // Protocol-specific function parameter
|
||||
char label[50]; // Arbitrary label
|
||||
char data[MG_DATA_SIZE]; // Arbitrary connection data
|
||||
void *tls; // TLS specific data
|
||||
unsigned is_listening : 1; // Listening connection
|
||||
unsigned is_client : 1; // Outbound (client) connection
|
||||
@ -1097,9 +1095,7 @@ void mg_connect_resolved(struct mg_connection *);
|
||||
bool mg_send(struct mg_connection *, const void *, size_t);
|
||||
size_t mg_printf(struct mg_connection *, const char *fmt, ...);
|
||||
size_t mg_vprintf(struct mg_connection *, const char *fmt, va_list *ap);
|
||||
char *mg_straddr(struct mg_addr *, char *, size_t);
|
||||
bool mg_aton(struct mg_str str, struct mg_addr *addr);
|
||||
char *mg_ntoa(const struct mg_addr *addr, char *buf, size_t len);
|
||||
int mg_mkpipe(struct mg_mgr *, mg_event_handler_t, void *, bool udp);
|
||||
|
||||
// These functions are used to integrate with custom network stacks
|
||||
@ -1180,6 +1176,7 @@ void mg_http_bauth(struct mg_connection *, const char *user, const char *pass);
|
||||
struct mg_str mg_http_get_header_var(struct mg_str s, struct mg_str v);
|
||||
size_t mg_http_next_multipart(struct mg_str, size_t, struct mg_http_part *);
|
||||
int mg_http_status(const struct mg_http_message *hm);
|
||||
void mg_hello(const char *url);
|
||||
|
||||
|
||||
void mg_http_serve_ssi(struct mg_connection *c, const char *root,
|
||||
@ -1429,25 +1426,63 @@ void mg_rpc_list(struct mg_rpc_req *r);
|
||||
|
||||
|
||||
|
||||
struct mip_if; // MIP network interface
|
||||
|
||||
struct mip_driver {
|
||||
bool (*init)(uint8_t *mac, void *data); // Initialise driver
|
||||
size_t (*tx)(const void *, size_t, void *data); // Transmit frame
|
||||
size_t (*rx)(void *buf, size_t len, void *data); // Receive frame (polling)
|
||||
bool (*up)(void *data); // Up/down status
|
||||
// Set receive callback for interrupt-driven drivers
|
||||
void (*setrx)(void (*fn)(void *buf, size_t len, void *rxdata), void *rxdata);
|
||||
bool (*init)(struct mip_if *); // Initialise driver
|
||||
size_t (*tx)(const void *, size_t, struct mip_if *); // Transmit frame
|
||||
size_t (*rx)(void *buf, size_t len, struct mip_if *); // Receive frame (poll)
|
||||
bool (*up)(struct mip_if *); // Up/down status
|
||||
};
|
||||
|
||||
struct mip_cfg {
|
||||
uint8_t mac[6]; // MAC address. Must not be 0
|
||||
uint32_t ip, mask, gw; // IP, netmask, GW. If IP is 0, DHCP is used
|
||||
// Receive queue - single producer, single consumer queue. Interrupt-based
|
||||
// drivers copy received frames to the queue in interrupt context. mip_poll()
|
||||
// function runs in event loop context, reads from the queue
|
||||
struct queue {
|
||||
uint8_t *buf;
|
||||
size_t len;
|
||||
volatile size_t tail, head;
|
||||
};
|
||||
|
||||
void mip_init(struct mg_mgr *, struct mip_cfg *, struct mip_driver *, void *);
|
||||
#define MIP_ARP_ENTRIES 5 // Number of ARP cache entries. Maximum 21
|
||||
#define MIP_ARP_CS (2 + 12 * MIP_ARP_ENTRIES) // ARP cache size
|
||||
|
||||
// Network interface
|
||||
struct mip_if {
|
||||
uint8_t mac[6]; // MAC address. Must be set to a valid MAC
|
||||
uint32_t ip, mask, gw; // IP address, mask, default gateway
|
||||
struct mg_str rx; // Output (TX) buffer
|
||||
struct mg_str tx; // Input (RX) buffer
|
||||
bool enable_dhcp_client; // Enable DCHP client
|
||||
bool enable_dhcp_server; // Enable DCHP server
|
||||
struct mip_driver *driver; // Low level driver
|
||||
void *driver_data; // Driver-specific data
|
||||
struct mg_mgr *mgr; // Mongoose event manager
|
||||
struct queue queue; // Set queue.len for interrupt based drivers
|
||||
|
||||
// Internal state, user can use it but should not change it
|
||||
uint64_t now; // Current time
|
||||
uint64_t timer_1000ms; // 1000 ms timer: for DHCP and link state
|
||||
uint64_t lease_expire; // Lease expiration time
|
||||
uint8_t arp_cache[MIP_ARP_CS]; // Each entry is 12 bytes
|
||||
uint16_t eport; // Next ephemeral port
|
||||
uint16_t dropped; // Number of dropped frames
|
||||
uint8_t state; // Current state
|
||||
#define MIP_STATE_DOWN 0 // Interface is down
|
||||
#define MIP_STATE_UP 1 // Interface is up
|
||||
#define MIP_STATE_READY 2 // Interface is up and has IP
|
||||
};
|
||||
|
||||
void mip_init(struct mg_mgr *, struct mip_if *);
|
||||
void mip_free(struct mip_if *);
|
||||
void mip_qwrite(void *buf, size_t len, struct mip_if *ifp);
|
||||
size_t mip_qread(void *buf, struct mip_if *ifp);
|
||||
// conveniency rx function for IRQ-driven drivers
|
||||
size_t mip_driver_rx(void *buf, size_t len, struct mip_if *ifp);
|
||||
|
||||
extern struct mip_driver mip_driver_stm32;
|
||||
extern struct mip_driver mip_driver_enc28j60;
|
||||
extern struct mip_driver mip_driver_w5500;
|
||||
extern struct mip_driver mip_driver_tm4c;
|
||||
|
||||
// Drivers that require SPI, can use this SPI abstraction
|
||||
struct mip_spi {
|
||||
@ -1475,7 +1510,7 @@ void qp_init(void);
|
||||
#endif
|
||||
|
||||
|
||||
struct mip_driver_stm32 {
|
||||
struct mip_driver_stm32_data {
|
||||
// MDC clock divider. MDC clock is derived from HCLK, must not exceed 2.5MHz
|
||||
// HCLK range DIVIDER mdc_cr VALUE
|
||||
// -------------------------------------
|
||||
@ -1490,6 +1525,20 @@ struct mip_driver_stm32 {
|
||||
int mdc_cr; // Valid values: -1, 0, 1, 2, 3, 4, 5
|
||||
};
|
||||
|
||||
|
||||
struct mip_driver_tm4c_data {
|
||||
// MDC clock divider. MDC clock is derived from SYSCLK, must not exceed 2.5MHz
|
||||
// SYSCLK range DIVIDER mdc_cr VALUE
|
||||
// -------------------------------------
|
||||
// -1 <-- tell driver to guess the value
|
||||
// 60-100 MHz SYSCLK/42 0
|
||||
// 100-150 MHz SYSCLK/62 1 <-- value for EK-TM4C129* on max speed
|
||||
// 20-35 MHz SYSCLK/16 2
|
||||
// 35-60 MHz SYSCLK/26 3
|
||||
// 0x4-0xF Reserved
|
||||
int mdc_cr; // Valid values: -1, 0, 1, 2, 3
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
1139
src/mongoose.c
1139
src/mongoose.c
File diff suppressed because it is too large
Load Diff
32
src/webui.c
32
src/webui.c
@ -20,11 +20,17 @@
|
||||
// -- Heap ----------------------------
|
||||
webui_t webui;
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
#define WEBUI_JS_LOG "true"
|
||||
#else
|
||||
#define WEBUI_JS_LOG "false"
|
||||
#endif
|
||||
|
||||
// -- WebUI JS-Bridge ---------
|
||||
// This is a uncompressed version to make the debugging
|
||||
// more easy in the browser using the builtin dev-tools
|
||||
static const char* webui_javascript_bridge =
|
||||
"var _webui_log = false; \n"
|
||||
"var _webui_log = " WEBUI_JS_LOG "; \n"
|
||||
"var _webui_ws; \n"
|
||||
"var _webui_ws_status = false; \n"
|
||||
"var _webui_ws_status_once = false; \n"
|
||||
@ -189,13 +195,25 @@ static const char* webui_javascript_bridge =
|
||||
" if(!_webui_ws_status_once) { \n"
|
||||
" _webui_freeze_ui(); \n"
|
||||
" alert('WebUI failed to connect to the background application. Please try again.'); \n"
|
||||
" if(!_webui_log) \n"
|
||||
" window.close(); \n"
|
||||
" if(!_webui_log) window.close(); \n"
|
||||
" } \n"
|
||||
"}, 1500); \n"
|
||||
"window.addEventListener('load', _webui_start()); \n"
|
||||
"function UnloadHandler(){window.removeEventListener('unload', UnloadHandler, false);} \n"
|
||||
"window.addEventListener('unload', UnloadHandler, false);";
|
||||
"window.addEventListener('unload', unload_handler, false); \n"
|
||||
"function unload_handler(){ \n"
|
||||
" // Unload for 'back' & 'forward' navigation \n"
|
||||
" window.removeEventListener('unload', unload_handler, false); \n"
|
||||
"} \n"
|
||||
"// Links \n"
|
||||
"document.addEventListener('click', e => { \n"
|
||||
" const attribute = e.target.closest('a'); \n"
|
||||
" if(attribute){ \n"
|
||||
" const link = attribute.href; \n"
|
||||
" e.preventDefault(); \n"
|
||||
" _webui_close(_WEBUI_SWITCH, link); \n"
|
||||
" } \n"
|
||||
"}); \n"
|
||||
"// Load \n"
|
||||
"window.addEventListener('load', _webui_start()); \n";
|
||||
|
||||
// -- Heap ----------------------------
|
||||
static const char* webui_html_served = "<html><head><title>Access Denied</title><style>body{margin:0;background-repeat:no-repeat;background-attachment:fixed;background-color:#FF3CAC;background-image:linear-gradient(225deg,#FF3CAC 0%,#784BA0 45%,#2B86C5 100%);font-family:sans-serif;margin:20px;color:#fff}a{color:#fff}</style></head><body><h2>⚠ Access Denied</h2><p>You can't access this content<br>because it's already processed.<br><br>The current security policy denies<br>multiple requests.</p><br><a href=\"https://www.webui.me\"><small>WebUI v" WEBUI_VERSION "<small></a></body></html>";
|
||||
@ -847,7 +865,7 @@ const char* _webui_generate_js_bridge(webui_window_t* win) {
|
||||
#endif
|
||||
|
||||
// Calculate the cb size
|
||||
size_t cb_mem_size = 256; // To hold `const _webui_bind_list = ["elem1", "elem2",];`
|
||||
size_t cb_mem_size = 256; // To hold 'const _webui_bind_list = ["elem1", "elem2",];'
|
||||
for(unsigned int i = 1; i < WEBUI_MAX_ARRAY; i++)
|
||||
if(!_webui_is_empty(webui.html_elements[i]))
|
||||
cb_mem_size += strlen(webui.html_elements[i]) + 3;
|
||||
|
Loading…
Reference in New Issue
Block a user