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
50 #define LWS_ETHER_ADDR_LEN ETHER_ADDR_LEN
66 #define LWS_US_PER_SEC ((lws_usec_t)1000000)
67 #define LWS_MS_PER_SEC ((lws_usec_t)1000)
68 #define LWS_US_PER_MS ((lws_usec_t)1000)
69 #define LWS_NS_PER_US ((lws_usec_t)1000)
72 #define LWS_MI (LWS_KI * 1024)
73 #define LWS_GI (LWS_MI * 1024)
74 #define LWS_TI ((uint64_t)LWS_GI * 1024)
75 #define LWS_PI ((uint64_t)LWS_TI * 1024)
77 #define LWS_US_TO_MS(x) ((x + (LWS_US_PER_MS / 2)) / LWS_US_PER_MS)
79 #define LWS_FOURCC(a, b, c, d) ((a << 24) | (b << 16) | (c << 8) | d)
81 #if defined(LWS_HAS_INTPTR_T)
83 #define lws_intptr_t intptr_t
88 #if defined(WIN32) || defined(_WIN32)
89 #ifndef WIN32_LEAN_AND_MEAN
90 #define WIN32_LEAN_AND_MEAN
101 #define _O_RDONLY 0x0000
102 #define O_RDONLY _O_RDONLY
105 typedef unsigned int uid_t;
106 typedef unsigned int gid_t;
107 typedef unsigned short sa_family_t;
108 #if !defined(LWS_HAVE_SUSECONDS_T)
109 typedef unsigned int useconds_t;
110 typedef int suseconds_t;
113 #define LWS_INLINE __inline
115 #define LWS_WARN_UNUSED_RESULT
116 #define LWS_WARN_DEPRECATED
117 #define LWS_FORMAT(string_index)
119 #if !defined(LWS_EXTERN) && defined(LWS_BUILDING_SHARED)
122 #define LWS_EXTERN extern __declspec(dllexport)
124 #define LWS_EXTERN extern __declspec(dllimport)
129 #if !defined(LWS_INTERNAL) && !defined(LWS_EXTERN)
134 #if !defined(LWS_EXTERN)
138 #define LWS_INVALID_FILE INVALID_HANDLE_VALUE
139 #define LWS_SOCK_INVALID (INVALID_SOCKET)
140 #define LWS_O_RDONLY _O_RDONLY
141 #define LWS_O_WRONLY _O_WRONLY
142 #define LWS_O_CREAT _O_CREAT
143 #define LWS_O_TRUNC _O_TRUNC
145 #if (__STDC_VERSION__ < 199901L) && !defined(__func__)
146 #define __func__ __FUNCTION__
152 #if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP)
153 #include <sys/capability.h>
156 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__QNX__) || defined(__OpenBSD__) || defined(__NuttX__)
157 #include <sys/socket.h>
158 #include <netinet/in.h>
161 #define LWS_INLINE inline
162 #define LWS_O_RDONLY O_RDONLY
163 #define LWS_O_WRONLY O_WRONLY
164 #define LWS_O_CREAT O_CREAT
165 #define LWS_O_TRUNC O_TRUNC
167 #if !defined(LWS_PLAT_OPTEE) && !defined(OPTEE_TA) && !defined(LWS_PLAT_FREERTOS) && !defined(LWS_PLAT_BAREMETAL)
170 #define LWS_INVALID_FILE -1
171 #define LWS_SOCK_INVALID (-1)
173 #define getdtablesize() (30)
174 #if defined(LWS_PLAT_FREERTOS)
175 #define LWS_INVALID_FILE NULL
176 #define LWS_SOCK_INVALID (-1)
178 #define LWS_INVALID_FILE NULL
179 #define LWS_SOCK_INVALID (-1)
183 #if defined(__FreeBSD__)
184 #include <sys/signal.h>
186 #if defined(__GNUC__)
189 #if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
190 #define LWS_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
192 #define LWS_WARN_UNUSED_RESULT
195 #if defined(LWS_BUILDING_SHARED)
197 #define LWS_VISIBLE __attribute__((visibility("default")))
198 #define LWS_EXTERN extern
201 #if defined(WIN32) || defined(_WIN32) || defined(__MINGW32__)
203 #define LWS_EXTERN extern
215 #define LWS_WARN_DEPRECATED __attribute__ ((deprecated))
217 #define LWS_FORMAT(string_index) __attribute__ ((format(printf, string_index, string_index+1)))
221 #define LWS_WARN_UNUSED_RESULT
222 #define LWS_WARN_DEPRECATED
223 #define LWS_FORMAT(string_index)
224 #if !defined(LWS_EXTERN)
225 #define LWS_EXTERN extern
230 #if defined(__ANDROID__)
231 #include <netinet/in.h>
239 #if !defined(LWS_PLAT_OPTEE)
240 #include <sys/time.h>
245 #if defined(LWS_WITH_LIBUV_INTERNAL)
248 #ifdef LWS_HAVE_UV_VERSION_H
249 #include <uv-version.h>
252 #ifdef LWS_HAVE_NEW_UV_VERSION_H
253 #include <uv/version.h>
257 #if defined(LWS_WITH_TLS)
260 #ifdef USE_OLD_CYASSL
266 #include <IDE/WIN/user_settings.h>
267 #include <cyassl/ctaocrypt/settings.h>
269 #include <cyassl/options.h>
271 #include <cyassl/openssl/ssl.h>
272 #include <cyassl/error-ssl.h>
280 #include <IDE/WIN/user_settings.h>
281 #include <wolfssl/wolfcrypt/settings.h>
283 #include <wolfssl/options.h>
285 #include <wolfssl/openssl/ssl.h>
286 #include <wolfssl/error-ssl.h>
289 #if defined(LWS_WITH_MBEDTLS)
290 #if defined(LWS_PLAT_FREERTOS)
292 #if !defined(LWS_AMAZON_RTOS)
294 #undef MBEDTLS_CONFIG_FILE
295 #define MBEDTLS_CONFIG_FILE <mbedtls/esp_config.h>
299 #if defined(LWS_WITH_TLS)
300 #include <mbedtls/ssl.h>
301 #include <mbedtls/entropy.h>
302 #include <mbedtls/ctr_drbg.h>
303 #include <mbedtls/version.h>
305 #if !defined(MBEDTLS_PRIVATE)
306 #define MBEDTLS_PRIVATE(_q) _q
309 #if (MBEDTLS_VERSION_MAJOR == 3) && (MBEDTLS_VERSION_MINOR == 0)
310 #define MBEDTLS_PRIVATE_V30_ONLY(_q) MBEDTLS_PRIVATE(_q)
312 #define MBEDTLS_PRIVATE_V30_ONLY(_q) _q
317 #include <openssl/ssl.h>
318 #if !defined(LWS_WITH_MBEDTLS)
319 #include <openssl/err.h>
336 #define lws_pthread_mutex(name) pthread_mutex_t name;
341 pthread_mutex_init(lock, NULL);
347 pthread_mutex_destroy(lock);
353 pthread_mutex_lock(lock);
359 pthread_mutex_unlock(lock);
363 #define lws_pthread_mutex(name)
364 #define lws_pthread_mutex_init(_a)
365 #define lws_pthread_mutex_destroy(_a)
366 #define lws_pthread_mutex_lock(_a)
367 #define lws_pthread_mutex_unlock(_a)
371 #define CONTEXT_PORT_NO_LISTEN -1
372 #define CONTEXT_PORT_NO_LISTEN_SERVER -2
379 #ifndef lws_container_of
380 #define lws_container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M)))
382 #define LWS_ALIGN_TO(x, bou) x += ((bou) - ((x) % (bou))) % (bou)
388 #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG
391 #define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD
394 #define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE
397 #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_LEN
400 #define LWS_FEATURE_FOPS
403 #define LWS_FEATURE_MOUNT_NO_CACHE
407 #if !defined(LWS_WIN32_HANDLE_TYPES)
409 #if defined(__MINGW32__)
417 #define lws_pollfd pollfd
418 #define LWS_POLLHUP (POLLHUP)
419 #define LWS_POLLIN (POLLRDNORM | POLLRDBAND)
420 #define LWS_POLLOUT (POLLWRNORM)
425 #if defined(LWS_PLAT_FREERTOS)
432 #if defined(LWS_PLAT_OPTEE)
436 unsigned int tv_usec;
438 #if defined(LWS_WITH_NETWORK)
440 #define lws_pollfd pollfd
444 int gettimeofday(
struct timeval *tv,
struct timezone *tz);
451 typedef unsigned short sa_family_t;
452 typedef unsigned short in_port_t;
457 #if !defined(TEE_SE_READER_NAME_MAX)
463 socklen_t ai_addrlen;
466 struct addrinfo *ai_next;
470 ssize_t recv(
int sockfd,
void *buf,
size_t len,
int flags);
471 ssize_t send(
int sockfd,
const void *buf,
size_t len,
int flags);
472 ssize_t read(
int fd,
void *buf,
size_t count);
473 int getsockopt(
int sockfd,
int level,
int optname,
474 void *optval, socklen_t *optlen);
475 int setsockopt(
int sockfd,
int level,
int optname,
476 const void *optval, socklen_t optlen);
477 int connect(
int sockfd,
const struct sockaddr *addr,
485 int bind(
int sockfd,
const struct sockaddr *addr,
489 #define MSG_NOSIGNAL 0x4000
492 #define EWOULDBLOCK EAGAIN
493 #define EADDRINUSE 98
499 #define SOCK_STREAM 1
501 # define AI_PASSIVE 0x0001
502 #define IPPROTO_UDP 17
507 #define EINPROGRESS 115
508 int shutdown(
int sockfd,
int how);
510 int atoi(
const char *nptr);
511 long long atoll(
const char *nptr);
513 int socket(
int domain,
int type,
int protocol);
514 int getaddrinfo(
const char *node,
const char *service,
515 const struct addrinfo *hints,
516 struct addrinfo **res);
518 void freeaddrinfo(
struct addrinfo *res);
520 #if !defined(TEE_SE_READER_NAME_MAX)
529 int poll(
struct pollfd *fds,
int nfds,
int timeout);
531 #define LWS_POLLHUP (0x18)
532 #define LWS_POLLIN (1)
533 #define LWS_POLLOUT (4)
539 #define lws_pollfd pollfd
540 #define LWS_POLLHUP (POLLHUP | POLLERR)
541 #define LWS_POLLIN (POLLIN)
542 #define LWS_POLLOUT (POLLOUT)
547 #if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
549 #define ssize_t SSIZE_T
552 #if defined(WIN32) && defined(LWS_HAVE__STAT32I64)
553 #include <sys/types.h>
554 #include <sys/stat.h>
557 #if defined(LWS_HAVE_STDINT_H)
560 #if defined(WIN32) || defined(_WIN32)
562 typedef __int64 int64_t;
563 typedef unsigned __int64 uint64_t;
564 typedef __int32 int32_t;
566 typedef __int16 int16_t;
568 typedef unsigned __int8
uint8_t;
581 #define lws_concat_temp(_t, _l) (_t + sizeof(_t) - _l)
582 #define lws_concat_used(_t, _l) (sizeof(_t) - _l)
592 #if !defined(LWS_SIZEOFPTR)
593 #define LWS_SIZEOFPTR ((int)sizeof (void *))
596 #if defined(__x86_64__)
597 #define _LWS_PAD_SIZE 16
599 #define _LWS_PAD_SIZE LWS_SIZEOFPTR
601 #define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? \
602 ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n))
604 #define LWS_PRE _LWS_PAD(4 + 10 + 2)
606 #define LWS_SEND_BUFFER_PRE_PADDING LWS_PRE
607 #define LWS_SEND_BUFFER_POST_PADDING 0
637 #define LWS_FX_FRACTION_MSD 100000000
638 #define lws_neg(a) (a->whole < 0 || a->frac < 0)
639 #define lws_fx_set(a, x, y) { a.whole = x; a.frac = x < 0 ? -y : y; }
640 #define lws_fix64(a) (((int64_t)a->whole << 32) + \
641 (((1ll << 32) * (a->frac < 0 ? -a->frac : a->frac)) / LWS_FX_FRACTION_MSD))
642 #define lws_fix64_abs(a) \
643 ((((int64_t)(a->whole < 0 ? (-a->whole) : a->whole) << 32) + \
644 (((1ll << 32) * (a->frac < 0 ? -a->frac : a->frac)) / LWS_FX_FRACTION_MSD)))
646 #define lws_fix3232(a, a64) { a->whole = (int32_t)(a64 >> 32); \
647 a->frac = (int32_t)((100000000 * (a64 & 0xffffffff)) >> 32); }
683 #if defined(LWS_WITH_SYS_SMD)
688 #if defined(LWS_WITH_NETWORK)
696 #if defined(LWS_WITH_NETWORK)
705 #if defined(LWS_WITH_NETWORK)
706 #if defined(LWS_WITH_CONMON)
710 #if defined(LWS_ROLE_MQTT)
720 #if defined(LWS_WITH_NETWORK)
728 #if defined(LWS_WITH_NETWORK)
731 #if defined(LWS_WITH_FILE_OPS)
754 #if defined(LWS_WITH_TLS)
758 #if defined(LWS_WITH_MBEDTLS)
759 #include <mbedtls/md5.h>
760 #include <mbedtls/sha1.h>
761 #include <mbedtls/sha256.h>
762 #include <mbedtls/sha512.h>
777 #if defined(LWS_WITH_NETWORK)
782 #if defined(LWS_ESP_PLATFORM)
801 #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)