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>
48 #if defined(LWS_HAVE_NET_IF_ETHER_H)
49 #include <net/if_ether.h>
51 #if defined(_WIN32) && !defined(ETHER_ADDR_LEN)
52 #define ETHER_ADDR_LEN 6
55 #include <sys/ethernet.h>
56 #if !defined(ETHER_ADDR_LEN) && defined(ETHERADDRL)
57 #define ETHER_ADDR_LEN ETHERADDRL
60 #define LWS_ETHER_ADDR_LEN ETHER_ADDR_LEN
76 #define LWS_US_PER_SEC ((lws_usec_t)1000000)
77 #define LWS_MS_PER_SEC ((lws_usec_t)1000)
78 #define LWS_US_PER_MS ((lws_usec_t)1000)
79 #define LWS_NS_PER_US ((lws_usec_t)1000)
82 #define LWS_MI (LWS_KI * 1024)
83 #define LWS_GI (LWS_MI * 1024)
84 #define LWS_TI ((uint64_t)LWS_GI * 1024)
85 #define LWS_PI ((uint64_t)LWS_TI * 1024)
87 #define LWS_US_TO_MS(x) ((x + (LWS_US_PER_MS / 2)) / LWS_US_PER_MS)
89 #define LWS_FOURCC(a, b, c, d) ((a << 24) | (b << 16) | (c << 8) | d)
91 #if defined(LWS_HAS_INTPTR_T)
93 #define lws_intptr_t intptr_t
98 #if defined(WIN32) || defined(_WIN32)
99 #ifndef WIN32_LEAN_AND_MEAN
100 #define WIN32_LEAN_AND_MEAN
103 #include <winsock2.h>
104 #include <ws2tcpip.h>
111 #define _O_RDONLY 0x0000
112 #define O_RDONLY _O_RDONLY
115 typedef unsigned int uid_t;
116 typedef unsigned int gid_t;
117 typedef unsigned short sa_family_t;
118 #if !defined(LWS_HAVE_SUSECONDS_T)
119 typedef unsigned int useconds_t;
120 typedef int suseconds_t;
123 #define LWS_INLINE __inline
125 #define LWS_WARN_UNUSED_RESULT
126 #define LWS_WARN_DEPRECATED
127 #define LWS_FORMAT(string_index)
129 #if !defined(LWS_EXTERN) && defined(LWS_BUILDING_SHARED)
132 #define LWS_EXTERN extern __declspec(dllexport)
134 #define LWS_EXTERN extern __declspec(dllimport)
139 #if !defined(LWS_INTERNAL) && !defined(LWS_EXTERN)
144 #if !defined(LWS_EXTERN)
148 #define LWS_INVALID_FILE INVALID_HANDLE_VALUE
149 #define LWS_SOCK_INVALID (INVALID_SOCKET)
150 #define LWS_O_RDONLY _O_RDONLY
151 #define LWS_O_WRONLY _O_WRONLY
152 #define LWS_O_CREAT _O_CREAT
153 #define LWS_O_TRUNC _O_TRUNC
155 #if (__STDC_VERSION__ < 199901L) && !defined(__func__)
156 #define __func__ __FUNCTION__
162 #if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP)
163 #include <sys/capability.h>
166 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__QNX__) || defined(__OpenBSD__) || defined(__NuttX__)
167 #include <sys/socket.h>
168 #include <netinet/in.h>
171 #define LWS_INLINE inline
172 #define LWS_O_RDONLY O_RDONLY
173 #define LWS_O_WRONLY O_WRONLY
174 #define LWS_O_CREAT O_CREAT
175 #define LWS_O_TRUNC O_TRUNC
177 #if !defined(LWS_PLAT_OPTEE) && !defined(OPTEE_TA) && !defined(LWS_PLAT_FREERTOS) && !defined(LWS_PLAT_BAREMETAL)
180 #define LWS_INVALID_FILE -1
181 #define LWS_SOCK_INVALID (-1)
183 #define getdtablesize() (30)
184 #if defined(LWS_PLAT_FREERTOS)
185 #define LWS_INVALID_FILE NULL
186 #define LWS_SOCK_INVALID (-1)
188 #define LWS_INVALID_FILE NULL
189 #define LWS_SOCK_INVALID (-1)
193 #if defined(__FreeBSD__)
194 #include <sys/signal.h>
196 #if defined(__GNUC__)
199 #if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
200 #define LWS_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
202 #define LWS_WARN_UNUSED_RESULT
205 #if defined(LWS_BUILDING_SHARED)
207 #define LWS_VISIBLE __attribute__((visibility("default")))
208 #define LWS_EXTERN extern
211 #if defined(WIN32) || defined(_WIN32) || defined(__MINGW32__)
213 #define LWS_EXTERN extern
225 #define LWS_WARN_DEPRECATED __attribute__ ((deprecated))
227 #define LWS_FORMAT(string_index) __attribute__ ((format(printf, string_index, string_index+1)))
231 #define LWS_WARN_UNUSED_RESULT
232 #define LWS_WARN_DEPRECATED
233 #define LWS_FORMAT(string_index)
234 #if !defined(LWS_EXTERN)
235 #define LWS_EXTERN extern
240 #if defined(__ANDROID__)
241 #include <netinet/in.h>
249 #if !defined(LWS_PLAT_OPTEE)
250 #include <sys/time.h>
255 #if defined(LWS_WITH_LIBUV_INTERNAL)
258 #ifdef LWS_HAVE_UV_VERSION_H
259 #include <uv-version.h>
262 #ifdef LWS_HAVE_NEW_UV_VERSION_H
263 #include <uv/version.h>
267 #if defined(LWS_WITH_TLS)
270 #ifdef USE_OLD_CYASSL
276 #include <IDE/WIN/user_settings.h>
277 #include <cyassl/ctaocrypt/settings.h>
279 #include <cyassl/options.h>
281 #include <cyassl/openssl/ssl.h>
282 #include <cyassl/error-ssl.h>
290 #include <IDE/WIN/user_settings.h>
291 #include <wolfssl/wolfcrypt/settings.h>
293 #include <wolfssl/options.h>
295 #include <wolfssl/openssl/ssl.h>
296 #include <wolfssl/error-ssl.h>
299 #if defined(LWS_WITH_MBEDTLS)
300 #if defined(LWS_PLAT_FREERTOS)
302 #if !defined(LWS_AMAZON_RTOS)
304 #undef MBEDTLS_CONFIG_FILE
305 #define MBEDTLS_CONFIG_FILE <mbedtls/esp_config.h>
309 #if defined(LWS_WITH_TLS)
310 #include <mbedtls/ssl.h>
311 #include <mbedtls/entropy.h>
312 #include <mbedtls/ctr_drbg.h>
313 #include <mbedtls/version.h>
315 #if !defined(MBEDTLS_PRIVATE)
316 #define MBEDTLS_PRIVATE(_q) _q
319 #if (MBEDTLS_VERSION_MAJOR == 3) && (MBEDTLS_VERSION_MINOR == 0)
320 #define MBEDTLS_PRIVATE_V30_ONLY(_q) MBEDTLS_PRIVATE(_q)
322 #define MBEDTLS_PRIVATE_V30_ONLY(_q) _q
327 #include <openssl/ssl.h>
328 #if !defined(LWS_WITH_MBEDTLS)
329 #include <openssl/err.h>
346 #define lws_pthread_mutex(name) pthread_mutex_t name;
351 pthread_mutex_init(lock, NULL);
357 pthread_mutex_destroy(lock);
363 pthread_mutex_lock(lock);
369 pthread_mutex_unlock(lock);
373 #define lws_pthread_mutex(name)
374 #define lws_pthread_mutex_init(_a)
375 #define lws_pthread_mutex_destroy(_a)
376 #define lws_pthread_mutex_lock(_a)
377 #define lws_pthread_mutex_unlock(_a)
381 #define CONTEXT_PORT_NO_LISTEN -1
382 #define CONTEXT_PORT_NO_LISTEN_SERVER -2
389 #ifndef lws_container_of
390 #define lws_container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M)))
392 #define LWS_ALIGN_TO(x, bou) x += ((bou) - ((x) % (bou))) % (bou)
398 #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG
401 #define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD
404 #define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE
407 #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_LEN
410 #define LWS_FEATURE_FOPS
413 #define LWS_FEATURE_MOUNT_NO_CACHE
417 #if !defined(LWS_WIN32_HANDLE_TYPES)
419 #if defined(__MINGW32__)
427 #define lws_pollfd pollfd
428 #define LWS_POLLHUP (POLLHUP)
429 #define LWS_POLLIN (POLLRDNORM | POLLRDBAND)
430 #define LWS_POLLOUT (POLLWRNORM)
435 #if defined(LWS_PLAT_FREERTOS)
442 #if defined(LWS_PLAT_OPTEE)
446 unsigned int tv_usec;
448 #if defined(LWS_WITH_NETWORK)
450 #define lws_pollfd pollfd
454 int gettimeofday(
struct timeval *tv,
struct timezone *tz);
461 typedef unsigned short sa_family_t;
462 typedef unsigned short in_port_t;
467 #if !defined(TEE_SE_READER_NAME_MAX)
473 socklen_t ai_addrlen;
476 struct addrinfo *ai_next;
480 ssize_t recv(
int sockfd,
void *buf,
size_t len,
int flags);
481 ssize_t send(
int sockfd,
const void *buf,
size_t len,
int flags);
482 ssize_t read(
int fd,
void *buf,
size_t count);
483 int getsockopt(
int sockfd,
int level,
int optname,
484 void *optval, socklen_t *optlen);
485 int setsockopt(
int sockfd,
int level,
int optname,
486 const void *optval, socklen_t optlen);
487 int connect(
int sockfd,
const struct sockaddr *addr,
495 int bind(
int sockfd,
const struct sockaddr *addr,
499 #define MSG_NOSIGNAL 0x4000
502 #define EWOULDBLOCK EAGAIN
503 #define EADDRINUSE 98
509 #define SOCK_STREAM 1
511 # define AI_PASSIVE 0x0001
512 #define IPPROTO_UDP 17
517 #define EINPROGRESS 115
518 int shutdown(
int sockfd,
int how);
520 int atoi(
const char *nptr);
521 long long atoll(
const char *nptr);
523 int socket(
int domain,
int type,
int protocol);
524 int getaddrinfo(
const char *node,
const char *service,
525 const struct addrinfo *hints,
526 struct addrinfo **res);
528 void freeaddrinfo(
struct addrinfo *res);
530 #if !defined(TEE_SE_READER_NAME_MAX)
539 int poll(
struct pollfd *fds,
int nfds,
int timeout);
541 #define LWS_POLLHUP (0x18)
542 #define LWS_POLLIN (1)
543 #define LWS_POLLOUT (4)
549 #define lws_pollfd pollfd
550 #define LWS_POLLHUP (POLLHUP | POLLERR)
551 #define LWS_POLLIN (POLLIN)
552 #define LWS_POLLOUT (POLLOUT)
557 #if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
559 #define ssize_t SSIZE_T
562 #if defined(WIN32) && defined(LWS_HAVE__STAT32I64)
563 #include <sys/types.h>
564 #include <sys/stat.h>
567 #if defined(LWS_HAVE_STDINT_H)
570 #if defined(WIN32) || defined(_WIN32)
572 typedef __int64 int64_t;
573 typedef unsigned __int64 uint64_t;
574 typedef __int32 int32_t;
576 typedef __int16 int16_t;
578 typedef unsigned __int8
uint8_t;
591 #define lws_concat_temp(_t, _l) (_t + sizeof(_t) - _l)
592 #define lws_concat_used(_t, _l) (sizeof(_t) - _l)
602 #if !defined(LWS_SIZEOFPTR)
603 #define LWS_SIZEOFPTR ((int)sizeof (void *))
606 #if defined(__x86_64__)
607 #define _LWS_PAD_SIZE 16
609 #define _LWS_PAD_SIZE LWS_SIZEOFPTR
611 #define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? \
612 ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n))
614 #define LWS_PRE _LWS_PAD(4 + 10 + 2)
616 #define LWS_SEND_BUFFER_PRE_PADDING LWS_PRE
617 #define LWS_SEND_BUFFER_POST_PADDING 0
647 #define LWS_FX_FRACTION_MSD 100000000
648 #define lws_neg(a) (a->whole < 0 || a->frac < 0)
649 #define lws_fx_set(a, x, y) { a.whole = x; a.frac = x < 0 ? -y : y; }
650 #define lws_fix64(a) (((int64_t)a->whole << 32) + \
651 (((1ll << 32) * (a->frac < 0 ? -a->frac : a->frac)) / LWS_FX_FRACTION_MSD))
652 #define lws_fix64_abs(a) \
653 ((((int64_t)(a->whole < 0 ? (-a->whole) : a->whole) << 32) + \
654 (((1ll << 32) * (a->frac < 0 ? -a->frac : a->frac)) / LWS_FX_FRACTION_MSD)))
656 #define lws_fix3232(a, a64) { a->whole = (int32_t)(a64 >> 32); \
657 a->frac = (int32_t)((100000000 * (a64 & 0xffffffff)) >> 32); }
693 #if defined(LWS_WITH_SYS_SMD)
698 #if defined(LWS_WITH_NETWORK)
708 #if defined(LWS_WITH_NETWORK)
718 #if defined(LWS_WITH_NETWORK)
719 #if defined(LWS_WITH_CONMON)
723 #if defined(LWS_ROLE_MQTT)
733 #if defined(LWS_WITH_NETWORK)
741 #if defined(LWS_WITH_NETWORK)
744 #if defined(LWS_WITH_FILE_OPS)
767 #if defined(LWS_WITH_TLS)
771 #if defined(LWS_WITH_MBEDTLS)
772 #include <mbedtls/md5.h>
773 #include <mbedtls/sha1.h>
774 #include <mbedtls/sha256.h>
775 #include <mbedtls/sha512.h>
790 #if defined(LWS_WITH_NETWORK)
795 #if defined(LWS_ESP_PLATFORM)
814 #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)