27 #ifndef LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C
28 #define LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C
39 #include "lws_config.h"
41 #if defined(LWS_HAVE_SYS_TYPES_H) && !defined(LWS_PLAT_BAREMETAL)
42 #include <sys/types.h>
44 #if defined(LWS_HAVE_NET_ETHERNET_H)
45 #include <net/ethernet.h>
47 #if defined(_WIN32) && !defined(ETHER_ADDR_LEN)
48 #define ETHER_ADDR_LEN 6
51 #include <sys/ethernet.h>
52 #if !defined(ETHER_ADDR_LEN) && defined(ETHERADDRL)
53 #define ETHER_ADDR_LEN ETHERADDRL
56 #define LWS_ETHER_ADDR_LEN ETHER_ADDR_LEN
72 #define LWS_US_PER_SEC ((lws_usec_t)1000000)
73 #define LWS_MS_PER_SEC ((lws_usec_t)1000)
74 #define LWS_US_PER_MS ((lws_usec_t)1000)
75 #define LWS_NS_PER_US ((lws_usec_t)1000)
78 #define LWS_MI (LWS_KI * 1024)
79 #define LWS_GI (LWS_MI * 1024)
80 #define LWS_TI ((uint64_t)LWS_GI * 1024)
81 #define LWS_PI ((uint64_t)LWS_TI * 1024)
83 #define LWS_US_TO_MS(x) ((x + (LWS_US_PER_MS / 2)) / LWS_US_PER_MS)
85 #define LWS_FOURCC(a, b, c, d) ((a << 24) | (b << 16) | (c << 8) | d)
87 #if defined(LWS_HAS_INTPTR_T)
89 #define lws_intptr_t intptr_t
94 #if defined(WIN32) || defined(_WIN32)
95 #ifndef WIN32_LEAN_AND_MEAN
96 #define WIN32_LEAN_AND_MEAN
100 #include <ws2tcpip.h>
107 #define _O_RDONLY 0x0000
108 #define O_RDONLY _O_RDONLY
111 typedef unsigned int uid_t;
112 typedef unsigned int gid_t;
113 typedef unsigned short sa_family_t;
114 #if !defined(LWS_HAVE_SUSECONDS_T)
115 typedef unsigned int useconds_t;
116 typedef int suseconds_t;
119 #define LWS_INLINE __inline
121 #define LWS_WARN_UNUSED_RESULT
122 #define LWS_WARN_DEPRECATED
123 #define LWS_FORMAT(string_index)
125 #if !defined(LWS_EXTERN) && defined(LWS_BUILDING_SHARED)
128 #define LWS_EXTERN extern __declspec(dllexport)
130 #define LWS_EXTERN extern __declspec(dllimport)
135 #if !defined(LWS_INTERNAL) && !defined(LWS_EXTERN)
140 #if !defined(LWS_EXTERN)
144 #define LWS_INVALID_FILE INVALID_HANDLE_VALUE
145 #define LWS_SOCK_INVALID (INVALID_SOCKET)
146 #define LWS_O_RDONLY _O_RDONLY
147 #define LWS_O_WRONLY _O_WRONLY
148 #define LWS_O_CREAT _O_CREAT
149 #define LWS_O_TRUNC _O_TRUNC
151 #if (__STDC_VERSION__ < 199901L) && !defined(__func__)
152 #define __func__ __FUNCTION__
158 #if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP)
159 #include <sys/capability.h>
162 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__QNX__) || defined(__OpenBSD__) || defined(__NuttX__)
163 #include <sys/socket.h>
164 #include <netinet/in.h>
167 #define LWS_INLINE inline
168 #define LWS_O_RDONLY O_RDONLY
169 #define LWS_O_WRONLY O_WRONLY
170 #define LWS_O_CREAT O_CREAT
171 #define LWS_O_TRUNC O_TRUNC
173 #if !defined(LWS_PLAT_OPTEE) && !defined(OPTEE_TA) && !defined(LWS_PLAT_FREERTOS) && !defined(LWS_PLAT_BAREMETAL)
176 #define LWS_INVALID_FILE -1
177 #define LWS_SOCK_INVALID (-1)
179 #define getdtablesize() (30)
180 #if defined(LWS_PLAT_FREERTOS)
181 #define LWS_INVALID_FILE NULL
182 #define LWS_SOCK_INVALID (-1)
184 #define LWS_INVALID_FILE NULL
185 #define LWS_SOCK_INVALID (-1)
189 #if defined(__FreeBSD__)
190 #include <sys/signal.h>
192 #if defined(__GNUC__)
195 #if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
196 #define LWS_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
198 #define LWS_WARN_UNUSED_RESULT
201 #if defined(LWS_BUILDING_SHARED)
203 #define LWS_VISIBLE __attribute__((visibility("default")))
204 #define LWS_EXTERN extern
207 #if defined(WIN32) || defined(_WIN32) || defined(__MINGW32__)
209 #define LWS_EXTERN extern
221 #define LWS_WARN_DEPRECATED __attribute__ ((deprecated))
223 #define LWS_FORMAT(string_index) __attribute__ ((format(printf, string_index, string_index+1)))
227 #define LWS_WARN_UNUSED_RESULT
228 #define LWS_WARN_DEPRECATED
229 #define LWS_FORMAT(string_index)
230 #if !defined(LWS_EXTERN)
231 #define LWS_EXTERN extern
236 #if defined(__ANDROID__)
237 #include <netinet/in.h>
245 #if !defined(LWS_PLAT_OPTEE)
246 #include <sys/time.h>
251 #if defined(LWS_WITH_LIBUV_INTERNAL)
254 #ifdef LWS_HAVE_UV_VERSION_H
255 #include <uv-version.h>
258 #ifdef LWS_HAVE_NEW_UV_VERSION_H
259 #include <uv/version.h>
263 #if defined(LWS_WITH_TLS)
266 #ifdef USE_OLD_CYASSL
272 #include <IDE/WIN/user_settings.h>
273 #include <cyassl/ctaocrypt/settings.h>
275 #include <cyassl/options.h>
277 #include <cyassl/openssl/ssl.h>
278 #include <cyassl/error-ssl.h>
286 #include <IDE/WIN/user_settings.h>
287 #include <wolfssl/wolfcrypt/settings.h>
289 #include <wolfssl/options.h>
291 #include <wolfssl/openssl/ssl.h>
292 #include <wolfssl/error-ssl.h>
295 #if defined(LWS_WITH_MBEDTLS)
296 #if defined(LWS_PLAT_FREERTOS)
298 #if !defined(LWS_AMAZON_RTOS)
300 #undef MBEDTLS_CONFIG_FILE
301 #define MBEDTLS_CONFIG_FILE <mbedtls/esp_config.h>
305 #if defined(LWS_WITH_TLS)
306 #include <mbedtls/ssl.h>
307 #include <mbedtls/entropy.h>
308 #include <mbedtls/ctr_drbg.h>
309 #include <mbedtls/version.h>
311 #if !defined(MBEDTLS_PRIVATE)
312 #define MBEDTLS_PRIVATE(_q) _q
315 #if (MBEDTLS_VERSION_MAJOR == 3) && (MBEDTLS_VERSION_MINOR == 0)
316 #define MBEDTLS_PRIVATE_V30_ONLY(_q) MBEDTLS_PRIVATE(_q)
318 #define MBEDTLS_PRIVATE_V30_ONLY(_q) _q
323 #include <openssl/ssl.h>
324 #if !defined(LWS_WITH_MBEDTLS)
325 #include <openssl/err.h>
342 #define lws_pthread_mutex(name) pthread_mutex_t name;
347 pthread_mutex_init(lock, NULL);
353 pthread_mutex_destroy(lock);
359 pthread_mutex_lock(lock);
365 pthread_mutex_unlock(lock);
369 #define lws_pthread_mutex(name)
370 #define lws_pthread_mutex_init(_a)
371 #define lws_pthread_mutex_destroy(_a)
372 #define lws_pthread_mutex_lock(_a)
373 #define lws_pthread_mutex_unlock(_a)
377 #define CONTEXT_PORT_NO_LISTEN -1
378 #define CONTEXT_PORT_NO_LISTEN_SERVER -2
385 #ifndef lws_container_of
386 #define lws_container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M)))
388 #define LWS_ALIGN_TO(x, bou) x += ((bou) - ((x) % (bou))) % (bou)
394 #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG
397 #define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD
400 #define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE
403 #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_LEN
406 #define LWS_FEATURE_FOPS
409 #define LWS_FEATURE_MOUNT_NO_CACHE
413 #if !defined(LWS_WIN32_HANDLE_TYPES)
415 #if defined(__MINGW32__)
423 #define lws_pollfd pollfd
424 #define LWS_POLLHUP (POLLHUP)
425 #define LWS_POLLIN (POLLRDNORM | POLLRDBAND)
426 #define LWS_POLLOUT (POLLWRNORM)
431 #if defined(LWS_PLAT_FREERTOS)
438 #if defined(LWS_PLAT_OPTEE)
442 unsigned int tv_usec;
444 #if defined(LWS_WITH_NETWORK)
446 #define lws_pollfd pollfd
450 int gettimeofday(
struct timeval *tv,
struct timezone *tz);
457 typedef unsigned short sa_family_t;
458 typedef unsigned short in_port_t;
463 #if !defined(TEE_SE_READER_NAME_MAX)
469 socklen_t ai_addrlen;
472 struct addrinfo *ai_next;
476 ssize_t recv(
int sockfd,
void *buf,
size_t len,
int flags);
477 ssize_t send(
int sockfd,
const void *buf,
size_t len,
int flags);
478 ssize_t read(
int fd,
void *buf,
size_t count);
479 int getsockopt(
int sockfd,
int level,
int optname,
480 void *optval, socklen_t *optlen);
481 int setsockopt(
int sockfd,
int level,
int optname,
482 const void *optval, socklen_t optlen);
483 int connect(
int sockfd,
const struct sockaddr *addr,
491 int bind(
int sockfd,
const struct sockaddr *addr,
495 #define MSG_NOSIGNAL 0x4000
498 #define EWOULDBLOCK EAGAIN
499 #define EADDRINUSE 98
505 #define SOCK_STREAM 1
507 # define AI_PASSIVE 0x0001
508 #define IPPROTO_UDP 17
513 #define EINPROGRESS 115
514 int shutdown(
int sockfd,
int how);
516 int atoi(
const char *nptr);
517 long long atoll(
const char *nptr);
519 int socket(
int domain,
int type,
int protocol);
520 int getaddrinfo(
const char *node,
const char *service,
521 const struct addrinfo *hints,
522 struct addrinfo **res);
524 void freeaddrinfo(
struct addrinfo *res);
526 #if !defined(TEE_SE_READER_NAME_MAX)
535 int poll(
struct pollfd *fds,
int nfds,
int timeout);
537 #define LWS_POLLHUP (0x18)
538 #define LWS_POLLIN (1)
539 #define LWS_POLLOUT (4)
545 #define lws_pollfd pollfd
546 #define LWS_POLLHUP (POLLHUP | POLLERR)
547 #define LWS_POLLIN (POLLIN)
548 #define LWS_POLLOUT (POLLOUT)
553 #if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
555 #define ssize_t SSIZE_T
558 #if defined(WIN32) && defined(LWS_HAVE__STAT32I64)
559 #include <sys/types.h>
560 #include <sys/stat.h>
563 #if defined(LWS_HAVE_STDINT_H)
566 #if defined(WIN32) || defined(_WIN32)
568 typedef __int64 int64_t;
569 typedef unsigned __int64 uint64_t;
570 typedef __int32 int32_t;
572 typedef __int16 int16_t;
574 typedef unsigned __int8
uint8_t;
587 #define lws_concat_temp(_t, _l) (_t + sizeof(_t) - _l)
588 #define lws_concat_used(_t, _l) (sizeof(_t) - _l)
598 #if !defined(LWS_SIZEOFPTR)
599 #define LWS_SIZEOFPTR ((int)sizeof (void *))
602 #if defined(__x86_64__)
603 #define _LWS_PAD_SIZE 16
605 #define _LWS_PAD_SIZE LWS_SIZEOFPTR
607 #define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? \
608 ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n))
610 #define LWS_PRE _LWS_PAD(4 + 10 + 2)
612 #define LWS_SEND_BUFFER_PRE_PADDING LWS_PRE
613 #define LWS_SEND_BUFFER_POST_PADDING 0
643 #define LWS_FX_FRACTION_MSD 100000000
644 #define lws_neg(a) (a->whole < 0 || a->frac < 0)
645 #define lws_fx_set(a, x, y) { a.whole = x; a.frac = x < 0 ? -y : y; }
646 #define lws_fix64(a) (((int64_t)a->whole << 32) + \
647 (((1ll << 32) * (a->frac < 0 ? -a->frac : a->frac)) / LWS_FX_FRACTION_MSD))
648 #define lws_fix64_abs(a) \
649 ((((int64_t)(a->whole < 0 ? (-a->whole) : a->whole) << 32) + \
650 (((1ll << 32) * (a->frac < 0 ? -a->frac : a->frac)) / LWS_FX_FRACTION_MSD)))
652 #define lws_fix3232(a, a64) { a->whole = (int32_t)(a64 >> 32); \
653 a->frac = (int32_t)((100000000 * (a64 & 0xffffffff)) >> 32); }
689 #if defined(LWS_WITH_SYS_SMD)
694 #if defined(LWS_WITH_NETWORK)
702 #if defined(LWS_WITH_NETWORK)
711 #if defined(LWS_WITH_NETWORK)
712 #if defined(LWS_WITH_CONMON)
716 #if defined(LWS_ROLE_MQTT)
726 #if defined(LWS_WITH_NETWORK)
734 #if defined(LWS_WITH_NETWORK)
737 #if defined(LWS_WITH_FILE_OPS)
760 #if defined(LWS_WITH_TLS)
764 #if defined(LWS_WITH_MBEDTLS)
765 #include <mbedtls/md5.h>
766 #include <mbedtls/sha1.h>
767 #include <mbedtls/sha256.h>
768 #include <mbedtls/sha512.h>
783 #if defined(LWS_WITH_NETWORK)
788 #if defined(LWS_ESP_PLATFORM)
807 #if defined(LWS_WITH_NETWORK)
LWS_VISIBLE LWS_EXTERN const lws_fx_t * lws_fx_div(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b)
LWS_VISIBLE LWS_EXTERN const lws_fx_t * lws_fx_sub(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b)
#define lws_pthread_mutex_lock(_a)
#define lws_pthread_mutex_init(_a)
#define lws_pthread_mutex_destroy(_a)
LWS_VISIBLE LWS_EXTERN int lws_fx_rounddown(const lws_fx_t *a)
LWS_VISIBLE LWS_EXTERN const lws_fx_t * lws_fx_mul(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b)
struct lws_fixed3232 lws_fx_t
@ LWS_SRET_NO_FURTHER_OUT
struct lws_context * lws_ctx_t
LWS_VISIBLE LWS_EXTERN const lws_fx_t * lws_fx_add(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b)
LWS_VISIBLE LWS_EXTERN const lws_fx_t * lws_fx_sqrt(lws_fx_t *r, const lws_fx_t *a)
LWS_VISIBLE LWS_EXTERN const char * lws_fx_string(const lws_fx_t *a, char *buf, size_t size)
#define lws_pthread_mutex_unlock(_a)
LWS_VISIBLE LWS_EXTERN int lws_fx_roundup(const lws_fx_t *a)
unsigned long long lws_intptr_t
unsigned long long lws_filepos_t
LWS_VISIBLE LWS_EXTERN int lws_fx_comp(const lws_fx_t *a, const lws_fx_t *b)