2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)
56
57
59#define LWS_US_PER_SEC ((lws_usec_t)1000000
)
60#define LWS_MS_PER_SEC ((lws_usec_t)1000
)
61#define LWS_US_PER_MS ((lws_usec_t)1000
)
62#define LWS_NS_PER_US ((lws_usec_t)1000
)
67#define LWS_TI ((uint64_t)LWS_GI * 1024
)
68#define LWS_PI ((uint64_t)LWS_TI * 1024
)
72#define LWS_FOURCC(a, b, c, d) ((a << 24
) | (b << 16
) | (c << 8
) | d)
74#if defined(LWS_HAS_INTPTR_T
)
76#define lws_intptr_t intptr_t
78typedef unsigned long long lws_intptr_t;
81#if defined(WIN32) || defined(_WIN32)
82#ifndef WIN32_LEAN_AND_MEAN
83#define WIN32_LEAN_AND_MEAN
94#define _O_RDONLY 0x0000
95#define O_RDONLY _O_RDONLY
100typedef unsigned short sa_family_t;
101#if !defined(LWS_HAVE_SUSECONDS_T)
102typedef unsigned int useconds_t;
103typedef int suseconds_t;
106#define LWS_INLINE __inline
108#define LWS_WARN_UNUSED_RESULT
109#define LWS_WARN_DEPRECATED
110#define LWS_FORMAT(string_index)
112#if !defined(LWS_EXTERN) && defined(LWS_BUILDING_SHARED)
115#define LWS_EXTERN extern __declspec(dllexport)
117#define LWS_EXTERN extern __declspec(dllimport)
122#if !defined(LWS_INTERNAL) && !defined(LWS_EXTERN)
127#if !defined(LWS_EXTERN)
131#define LWS_INVALID_FILE INVALID_HANDLE_VALUE
132#define LWS_SOCK_INVALID (INVALID_SOCKET)
133#define LWS_O_RDONLY _O_RDONLY
134#define LWS_O_WRONLY _O_WRONLY
135#define LWS_O_CREAT _O_CREAT
136#define LWS_O_TRUNC _O_TRUNC
139#define __func__ __FUNCTION__
145#if defined(LWS_HAVE_SYS_CAPABILITY_H
) && defined(LWS_HAVE_LIBCAP
)
146#include <sys/capability.h>
149#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__QNX__) || defined(__OpenBSD__)
150#include <sys/socket.h>
151#include <netinet/in.h>
154#define LWS_INLINE inline
155#define LWS_O_RDONLY O_RDONLY
156#define LWS_O_WRONLY O_WRONLY
157#define LWS_O_CREAT O_CREAT
158#define LWS_O_TRUNC O_TRUNC
160#if !defined(LWS_PLAT_OPTEE) && !defined(OPTEE_TA) && !defined(LWS_PLAT_FREERTOS) && !defined(LWS_PLAT_BAREMETAL)
163#define LWS_INVALID_FILE -1
164#define LWS_SOCK_INVALID (-1
)
166#define getdtablesize() (30
)
167#if defined(LWS_PLAT_FREERTOS)
168#define LWS_INVALID_FILE NULL
169#define LWS_SOCK_INVALID (-1
)
171#define LWS_INVALID_FILE NULL
172#define LWS_SOCK_INVALID (-1
)
176#if defined(__FreeBSD__)
177#include <sys/signal.h>
182#if __GNUC__
>= 4
|| (__GNUC__
== 3
&& __GNUC_MINOR__
>= 4
)
183#define LWS_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
185#define LWS_WARN_UNUSED_RESULT
188#if defined(LWS_BUILDING_SHARED)
190#define LWS_VISIBLE __attribute__((visibility("default")))
191#define LWS_EXTERN extern
194#if defined(WIN32) || defined(_WIN32) || defined(__MINGW32__)
196#define LWS_EXTERN extern
199
200
201
208#define LWS_WARN_DEPRECATED __attribute__ ((deprecated))
210#define LWS_FORMAT(string_index) __attribute__ ((format(printf, string_index, string_index+1
)))
214#define LWS_WARN_UNUSED_RESULT
215#define LWS_WARN_DEPRECATED
216#define LWS_FORMAT(string_index)
217#if !defined(LWS_EXTERN)
218#define LWS_EXTERN extern
223#if defined(__ANDROID__)
224#include <netinet/in.h>
232#if !defined(LWS_PLAT_OPTEE)
238#if defined(LWS_WITH_LIBUV_INTERNAL)
241#ifdef LWS_HAVE_UV_VERSION_H
242#include <uv-version.h>
245#ifdef LWS_HAVE_NEW_UV_VERSION_H
246#include <uv/version.h>
250#if defined(LWS_WITH_TLS
)
256
257
258
259#include <IDE/WIN/user_settings.h>
260#include <cyassl/ctaocrypt/settings.h>
262#include <cyassl/options.h>
264#include <cyassl/openssl/ssl.h>
265#include <cyassl/error-ssl.h>
270
271
272
273#include <IDE/WIN/user_settings.h>
274#include <wolfssl/wolfcrypt/settings.h>
276#include <wolfssl/options.h>
278#include <wolfssl/openssl/ssl.h>
279#include <wolfssl/error-ssl.h>
282#if defined(LWS_WITH_MBEDTLS)
283#if defined(LWS_PLAT_FREERTOS)
285#if !defined(LWS_AMAZON_RTOS)
287#undef MBEDTLS_CONFIG_FILE
288#define MBEDTLS_CONFIG_FILE <mbedtls/esp_config.h>
291#if defined(LWS_WITH_TLS)
292#include <mbedtls/ssl.h>
293#include <mbedtls/entropy.h>
294#include <mbedtls/ctr_drbg.h>
295#include <mbedtls/version.h>
297#if !defined(MBEDTLS_PRIVATE)
298#define MBEDTLS_PRIVATE(_q) _q
301#if (MBEDTLS_VERSION_MAJOR == 3
) && (MBEDTLS_VERSION_MINOR == 0
)
302#define MBEDTLS_PRIVATE_V30_ONLY(_q) MBEDTLS_PRIVATE(_q)
304#define MBEDTLS_PRIVATE_V30_ONLY(_q) _q
309#include <openssl/ssl.h>
310#if !defined(LWS_WITH_MBEDTLS)
311#include <openssl/err.h>
318
319
320
321
322
328#define lws_pthread_mutex(name) pthread_mutex_t name;
330static LWS_INLINE
void
331lws_pthread_mutex_init(pthread_mutex_t *lock)
333 pthread_mutex_init(lock, NULL);
336static LWS_INLINE
void
337lws_pthread_mutex_destroy(pthread_mutex_t *lock)
339 pthread_mutex_destroy(lock);
342static LWS_INLINE
void
343lws_pthread_mutex_lock(pthread_mutex_t *lock)
345 pthread_mutex_lock(lock);
348static LWS_INLINE
void
349lws_pthread_mutex_unlock(pthread_mutex_t *lock)
351 pthread_mutex_unlock(lock);
355#define lws_pthread_mutex(name)
356#define lws_pthread_mutex_init(_a)
357#define lws_pthread_mutex_destroy(_a)
358#define lws_pthread_mutex_lock(_a)
359#define lws_pthread_mutex_unlock(_a)
363#define CONTEXT_PORT_NO_LISTEN -1
364#define CONTEXT_PORT_NO_LISTEN_SERVER -2
366#include <libwebsockets/lws-logs.h>
371#ifndef lws_container_of
372#define lws_container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M)))
374#define LWS_ALIGN_TO(x, bou) x += ((bou) - ((x) % (bou))) % (bou)
380#define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG
383#define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD
386#define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE
389#define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_LEN
392#define LWS_FEATURE_FOPS
395#define LWS_FEATURE_MOUNT_NO_CACHE
399#if !defined(LWS_WIN32_HANDLE_TYPES)
400typedef SOCKET lws_sockfd_type;
401#if defined(__MINGW32__)
402typedef int lws_filefd_type;
404typedef HANDLE lws_filefd_type;
409#define lws_pollfd pollfd
410#define LWS_POLLHUP (POLLHUP)
411#define LWS_POLLIN (POLLRDNORM | POLLRDBAND)
412#define LWS_POLLOUT (POLLWRNORM)
417#if defined(LWS_PLAT_FREERTOS)
418#include <libwebsockets/lws-freertos.h>
424#if defined(LWS_PLAT_OPTEE)
428 unsigned int tv_usec;
430#if defined(LWS_WITH_NETWORK)
432#define lws_pollfd pollfd
436int gettimeofday(
struct timeval *tv,
struct timezone *tz);
443typedef unsigned short sa_family_t;
444typedef unsigned short in_port_t;
445typedef uint32_t socklen_t;
447#include <libwebsockets/lws-optee.h>
449#if !defined(TEE_SE_READER_NAME_MAX)
455 socklen_t ai_addrlen;
456 struct sockaddr *ai_addr;
458 struct addrinfo *ai_next;
462ssize_t recv(
int sockfd,
void *buf, size_t len,
int flags);
463ssize_t send(
int sockfd,
const void *buf, size_t len,
int flags);
464ssize_t read(
int fd,
void *buf, size_t count);
465int getsockopt(
int sockfd,
int level,
int optname,
466 void *optval, socklen_t *optlen);
467 int setsockopt(
int sockfd,
int level,
int optname,
468 const void *optval, socklen_t optlen);
469int connect(
int sockfd,
const struct sockaddr *addr,
474uint16_t ntohs(uint16_t netshort);
475uint16_t htons(uint16_t hostshort);
477int bind(
int sockfd,
const struct sockaddr *addr,
481#define MSG_NOSIGNAL 0x4000
484#define EWOULDBLOCK EAGAIN
493# define AI_PASSIVE 0x0001
494#define IPPROTO_UDP 17
499#define EINPROGRESS 115
500int shutdown(
int sockfd,
int how);
502int atoi(
const char *nptr);
503long long atoll(
const char *nptr);
505int socket(
int domain,
int type,
int protocol);
506 int getaddrinfo(
const char *node,
const char *service,
507 const struct addrinfo *hints,
508 struct addrinfo **res);
510 void freeaddrinfo(
struct addrinfo *res);
512#if !defined(TEE_SE_READER_NAME_MAX)
521int poll(
struct pollfd *fds,
int nfds,
int timeout);
523#define LWS_POLLHUP (0x18
)
524#define LWS_POLLIN (1
)
525#define LWS_POLLOUT (4
)
531#define lws_pollfd pollfd
532#define LWS_POLLHUP (POLLHUP
| POLLERR
)
533#define LWS_POLLIN (POLLIN
)
534#define LWS_POLLOUT (POLLOUT
)
539#if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
541#define ssize_t SSIZE_T
544#if defined(WIN32) && defined(LWS_HAVE__STAT32I64)
545#include <sys/types.h>
549#if defined(LWS_HAVE_STDINT_H
)
552#if defined(WIN32) || defined(_WIN32)
554typedef __int64 int64_t;
555typedef unsigned __int64 uint64_t;
556typedef __int32 int32_t;
557typedef unsigned __int32 uint32_t;
558typedef __int16 int16_t;
559typedef unsigned __int16 uint16_t;
560typedef unsigned __int8 uint8_t;
562typedef unsigned int uint32_t;
563typedef unsigned short uint16_t;
564typedef unsigned char uint8_t;
573#define lws_concat_temp(_t, _l) (_t + sizeof(_t) - _l)
574#define lws_concat_used(_t, _l) (sizeof(_t) - _l)
577
584#if !defined(LWS_SIZEOFPTR)
585#define LWS_SIZEOFPTR ((int)sizeof (void *))
588#if defined(__x86_64__
)
589#define _LWS_PAD_SIZE 16
591#define _LWS_PAD_SIZE LWS_SIZEOFPTR
599#define LWS_SEND_BUFFER_POST_PADDING 0
629#define LWS_FX_FRACTION_MSD 100000000
630#define lws_neg(a) (a->whole < 0
|| a->frac < 0
)
631#define lws_fx_set(a, x, y) { a.whole = x; a.frac = x < 0
? -y : y; }
632#define lws_fix64(a) (((int64_t)a->whole << 32
) +
634#define lws_fix64_abs(a)
635 ((((int64_t)(a->whole < 0
? (-a->whole) : a->whole) << 32
) +
638#define lws_fix3232(a, a64) { a->whole = (int32_t)(a64 >> 32
);
639 a->frac = (int32_t)((100000000
* (a64 & 0xffffffff
)) >> 32
); }
642lws_fx_add(lws_fx_t *r,
const lws_fx_t *a,
const lws_fx_t *b);
645lws_fx_sub(lws_fx_t *r,
const lws_fx_t *a,
const lws_fx_t *b);
648lws_fx_mul(lws_fx_t *r,
const lws_fx_t *a,
const lws_fx_t *b);
651lws_fx_div(lws_fx_t *r,
const lws_fx_t *a,
const lws_fx_t *b);
668#include <libwebsockets/lws-dll2.h>
669#include <libwebsockets/lws-map.h>
671#include <libwebsockets/lws-fault-injection.h>
672#include <libwebsockets/lws-backtrace.h>
673#include <libwebsockets/lws-timeout-timer.h>
674#include <libwebsockets/lws-cache-ttl.h>
675#if defined(LWS_WITH_SYS_SMD
)
676#include <libwebsockets/lws-smd.h>
678#include <libwebsockets/lws-state.h>
679#include <libwebsockets/lws-retry.h>
680#if defined(LWS_WITH_NETWORK
)
681#include <libwebsockets/lws-adopt.h>
682#include <libwebsockets/lws-network-helper.h>
683#include <libwebsockets/lws-metrics.h>
686#include <libwebsockets/lws-ota.h>
687#include <libwebsockets/lws-system.h>
688#if defined(LWS_WITH_NETWORK
)
689#include <libwebsockets/lws-ws-close.h>
690#include <libwebsockets/lws-callbacks.h>
691#include <libwebsockets/lws-ws-state.h>
692#include <libwebsockets/lws-ws-ext.h>
693#include <libwebsockets/lws-protocols-plugins.h>
695#include <libwebsockets/lws-context-vhost.h>
697#if defined(LWS_WITH_NETWORK
)
698#if defined(LWS_WITH_CONMON
)
699#include <libwebsockets/lws-conmon.h>
702#if defined(LWS_ROLE_MQTT)
703#include <libwebsockets/lws-mqtt.h>
705#include <libwebsockets/lws-client.h>
706#include <libwebsockets/lws-http.h>
707#include <libwebsockets/lws-spa.h>
709#include <libwebsockets/lws-purify.h>
710#include <libwebsockets/lws-misc.h>
711#include <libwebsockets/lws-dsh.h>
712#if defined(LWS_WITH_NETWORK
)
713#include <libwebsockets/lws-service.h>
714#include <libwebsockets/lws-write.h>
715#include <libwebsockets/lws-writeable.h>
717#include <libwebsockets/lws-ring.h>
718#include <libwebsockets/lws-sha1-base64.h>
719#include <libwebsockets/lws-x509.h>
720#if defined(LWS_WITH_NETWORK
)
721#include <libwebsockets/lws-cgi.h>
723#if defined(LWS_WITH_FILE_OPS
)
724#include <libwebsockets/lws-vfs.h>
726#include <libwebsockets/lws-gencrypto.h>
728#include <libwebsockets/lws-lejp.h>
729#include <libwebsockets/lws-lecp.h>
730#include <libwebsockets/lws-cose.h>
731#include <libwebsockets/lws-struct.h>
732#include <libwebsockets/lws-threadpool.h>
733#include <libwebsockets/lws-tokenize.h>
734#include <libwebsockets/lws-lwsac.h>
735#include <libwebsockets/lws-fts.h>
736#include <libwebsockets/lws-diskcache.h>
737#include <libwebsockets/lws-secure-streams.h>
738#include <libwebsockets/lws-secure-streams-serialization.h>
739#include <libwebsockets/lws-secure-streams-policy.h>
740#include <libwebsockets/lws-secure-streams-client.h>
741#include <libwebsockets/lws-secure-streams-transport-proxy.h>
742#include <libwebsockets/lws-jrpc.h>
744#include <libwebsockets/lws-async-dns.h>
746#if defined(LWS_WITH_TLS
)
748#include <libwebsockets/lws-tls-sessions.h>
750#if defined(LWS_WITH_MBEDTLS)
751#include <mbedtls/md5.h>
752#include <mbedtls/sha1.h>
753#include <mbedtls/sha256.h>
754#include <mbedtls/sha512.h>
757#include <libwebsockets/lws-genhash.h>
758#include <libwebsockets/lws-genrsa.h>
759#include <libwebsockets/lws-genaes.h>
760#include <libwebsockets/lws-genec.h>
762#include <libwebsockets/lws-jwk.h>
763#include <libwebsockets/lws-jose.h>
764#include <libwebsockets/lws-jws.h>
765#include <libwebsockets/lws-jwe.h>
769#if defined(LWS_WITH_NETWORK
)
770#include <libwebsockets/lws-eventlib-exports.h>
772#include <libwebsockets/lws-i2c.h>
773#include <libwebsockets/lws-spi.h>
774#if defined(LWS_ESP_PLATFORM)
775#include <libwebsockets/lws-esp32-spi.h>
777#include <libwebsockets/lws-gpio.h>
778#include <libwebsockets/lws-bb-i2c.h>
779#include <libwebsockets/lws-bb-spi.h>
780#include <libwebsockets/lws-button.h>
781#include <libwebsockets/lws-led.h>
782#include <libwebsockets/lws-pwm.h>
783#include <libwebsockets/lws-upng.h>
784#include <libwebsockets/lws-jpeg.h>
785#include <libwebsockets/lws-display.h>
786#include <libwebsockets/lws-dlo.h>
787#include <libwebsockets/lws-ssd1306-i2c.h>
788#include <libwebsockets/lws-ili9341-spi.h>
789#include <libwebsockets/lws-spd1656-spi.h>
790#include <libwebsockets/lws-uc8176-spi.h>
791#include <libwebsockets/lws-ssd1675b-spi.h>
792#include <libwebsockets/lws-settings.h>
793#if defined(LWS_WITH_NETWORK
)
794#include <libwebsockets/lws-netdev.h>
797#include <libwebsockets/lws-html.h>
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)
LWS_VISIBLE LWS_EXTERN int lws_fx_rounddown(const lws_fx_t *a)
LWS_VISIBLE LWS_EXTERN const char * lws_fx_string(const lws_fx_t *a, char *buf, size_t size)
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 lws_fx_t * lws_fx_div(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b)
@ LWS_SRET_NO_FURTHER_OUT
struct lws_context * lws_ctx_t
#define LWS_FX_FRACTION_MSD
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)
LWS_VISIBLE LWS_EXTERN int lws_fx_roundup(const lws_fx_t *a)
unsigned long long lws_filepos_t
LWS_VISIBLE LWS_EXTERN int lws_fx_comp(const lws_fx_t *a, const lws_fx_t *b)