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>
50 #if defined(LWS_SUPPRESS_DEPRECATED_API_WARNINGS
)
51 #define OPENSSL_USE_DEPRECATED
63 #define LWS_US_PER_SEC ((lws_usec_t)1000000
)
64 #define LWS_MS_PER_SEC ((lws_usec_t)1000
)
65 #define LWS_US_PER_MS ((lws_usec_t)1000
)
66 #define LWS_NS_PER_US ((lws_usec_t)1000
)
71 #define LWS_TI ((uint64_t)LWS_GI * 1024
)
72 #define LWS_PI ((uint64_t)LWS_TI * 1024
)
76 #define LWS_FOURCC(a, b, c, d) ((a << 24
) | (b << 16
) | (c << 8
) | d)
78 #if defined(LWS_HAS_INTPTR_T
)
80 #define lws_intptr_t intptr_t
82 typedef unsigned long long lws_intptr_t;
85 #if defined(WIN32) || defined(_WIN32)
86 #ifndef WIN32_LEAN_AND_MEAN
87 #define WIN32_LEAN_AND_MEAN
98 #define _O_RDONLY 0x0000
99 #define O_RDONLY _O_RDONLY
104 typedef unsigned short sa_family_t;
105 #if !defined(LWS_HAVE_SUSECONDS_T)
106 typedef unsigned int useconds_t;
107 typedef int suseconds_t;
110 #define LWS_INLINE __inline
112 #define LWS_WARN_UNUSED_RESULT
113 #define LWS_WARN_DEPRECATED
114 #define LWS_FORMAT(string_index)
116 #if !defined(LWS_EXTERN) && defined(LWS_BUILDING_SHARED)
119 #define LWS_EXTERN extern __declspec(dllexport)
121 #define LWS_EXTERN extern __declspec(dllimport)
126 #if !defined(LWS_INTERNAL) && !defined(LWS_EXTERN)
131 #if !defined(LWS_EXTERN)
135 #define LWS_INVALID_FILE INVALID_HANDLE_VALUE
136 #define LWS_SOCK_INVALID (INVALID_SOCKET)
137 #define LWS_O_RDONLY _O_RDONLY
138 #define LWS_O_WRONLY _O_WRONLY
139 #define LWS_O_CREAT _O_CREAT
140 #define LWS_O_TRUNC _O_TRUNC
143 #define __func__ __FUNCTION__
149 #if defined(LWS_HAVE_SYS_CAPABILITY_H
) && defined(LWS_HAVE_LIBCAP
)
150 #include <sys/capability.h>
153 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__QNX__) || defined(__OpenBSD__)
154 #include <sys/socket.h>
155 #include <netinet/in.h>
158 #define LWS_INLINE inline
159 #define LWS_O_RDONLY O_RDONLY
160 #define LWS_O_WRONLY O_WRONLY
161 #define LWS_O_CREAT O_CREAT
162 #define LWS_O_TRUNC O_TRUNC
164 #if !defined(LWS_PLAT_OPTEE) && !defined(OPTEE_TA) && !defined(LWS_PLAT_FREERTOS) && !defined(LWS_PLAT_BAREMETAL)
167 #define LWS_INVALID_FILE -1
168 #define LWS_SOCK_INVALID (-1
)
170 #define getdtablesize() (30
)
171 #if defined(LWS_PLAT_FREERTOS)
172 #define LWS_INVALID_FILE NULL
173 #define LWS_SOCK_INVALID (-1
)
175 #define LWS_INVALID_FILE NULL
176 #define LWS_SOCK_INVALID (-1
)
180 #if defined(__FreeBSD__)
181 #include <sys/signal.h>
183 #if defined(__GNUC__
)
186 #if __GNUC__
>= 4
|| (__GNUC__
== 3
&& __GNUC_MINOR__
>= 4
)
187 #define LWS_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
189 #define LWS_WARN_UNUSED_RESULT
192 #if defined(LWS_BUILDING_SHARED)
194 #define LWS_VISIBLE __attribute__((visibility("default")))
195 #define LWS_EXTERN extern
198 #if defined(WIN32) || defined(_WIN32) || defined(__MINGW32__)
200 #define LWS_EXTERN extern
212 #define LWS_WARN_DEPRECATED __attribute__ ((deprecated))
214 #define LWS_FORMAT(string_index) __attribute__ ((format(printf, string_index, string_index+1
)))
218 #define LWS_WARN_UNUSED_RESULT
219 #define LWS_WARN_DEPRECATED
220 #define LWS_FORMAT(string_index)
221 #if !defined(LWS_EXTERN)
222 #define LWS_EXTERN extern
227 #if defined(__ANDROID__)
228 #include <netinet/in.h>
236 #if !defined(LWS_PLAT_OPTEE)
237 #include <sys/time.h>
242 #if defined(LWS_WITH_LIBUV_INTERNAL)
245 #ifdef LWS_HAVE_UV_VERSION_H
246 #include <uv-version.h>
249 #ifdef LWS_HAVE_NEW_UV_VERSION_H
250 #include <uv/version.h>
254 #if defined(LWS_WITH_TLS
)
257 #ifdef USE_OLD_CYASSL
263 #include <IDE/WIN/user_settings.h>
264 #include <cyassl/ctaocrypt/settings.h>
266 #include <cyassl/options.h>
268 #include <cyassl/openssl/ssl.h>
269 #include <cyassl/error-ssl.h>
277 #include <IDE/WIN/user_settings.h>
278 #include <wolfssl/wolfcrypt/settings.h>
280 #include <wolfssl/options.h>
282 #include <wolfssl/openssl/ssl.h>
283 #include <wolfssl/error-ssl.h>
286 #if defined(LWS_WITH_MBEDTLS)
287 #if defined(LWS_PLAT_FREERTOS)
289 #if !defined(LWS_AMAZON_RTOS)
291 #undef MBEDTLS_CONFIG_FILE
292 #define MBEDTLS_CONFIG_FILE <mbedtls/esp_config.h>
295 #if defined(LWS_WITH_TLS)
296 #include <mbedtls/ssl.h>
297 #include <mbedtls/entropy.h>
298 #include <mbedtls/ctr_drbg.h>
299 #include <mbedtls/version.h>
301 #if !defined(MBEDTLS_PRIVATE)
302 #define MBEDTLS_PRIVATE(_q) _q
305 #if (MBEDTLS_VERSION_MAJOR == 3
) && (MBEDTLS_VERSION_MINOR == 0
)
306 #define MBEDTLS_PRIVATE_V30_ONLY(_q) MBEDTLS_PRIVATE(_q)
308 #define MBEDTLS_PRIVATE_V30_ONLY(_q) _q
313 #include <openssl/ssl.h>
314 #if !defined(LWS_WITH_MBEDTLS)
315 #include <openssl/err.h>
332 #define lws_pthread_mutex(name) pthread_mutex_t name;
334 static LWS_INLINE
void
335 lws_pthread_mutex_init(pthread_mutex_t *lock)
337 pthread_mutex_init(lock, NULL);
340 static LWS_INLINE
void
341 lws_pthread_mutex_destroy(pthread_mutex_t *lock)
343 pthread_mutex_destroy(lock);
346 static LWS_INLINE
void
347 lws_pthread_mutex_lock(pthread_mutex_t *lock)
349 pthread_mutex_lock(lock);
352 static LWS_INLINE
void
353 lws_pthread_mutex_unlock(pthread_mutex_t *lock)
355 pthread_mutex_unlock(lock);
359 #define lws_pthread_mutex(name)
360 #define lws_pthread_mutex_init(_a)
361 #define lws_pthread_mutex_destroy(_a)
362 #define lws_pthread_mutex_lock(_a)
363 #define lws_pthread_mutex_unlock(_a)
367 #define CONTEXT_PORT_NO_LISTEN -1
368 #define CONTEXT_PORT_NO_LISTEN_SERVER -2
370 #include <libwebsockets/lws-logs.h>
375 #ifndef lws_container_of
376 #define lws_container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M)))
378 #define LWS_ALIGN_TO(x, bou) x += ((bou) - ((x) % (bou))) % (bou)
384 #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG
387 #define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD
390 #define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE
393 #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_LEN
396 #define LWS_FEATURE_FOPS
399 #define LWS_FEATURE_MOUNT_NO_CACHE
403 #if !defined(LWS_WIN32_HANDLE_TYPES)
404 typedef SOCKET lws_sockfd_type;
405 #if defined(__MINGW32__)
406 typedef int lws_filefd_type;
408 typedef HANDLE lws_filefd_type;
413 #define lws_pollfd pollfd
414 #define LWS_POLLHUP (POLLHUP)
415 #define LWS_POLLIN (POLLRDNORM | POLLRDBAND)
416 #define LWS_POLLOUT (POLLWRNORM)
421 #if defined(LWS_PLAT_FREERTOS)
422 #include <libwebsockets/lws-freertos.h>
428 #if defined(LWS_PLAT_OPTEE)
432 unsigned int tv_usec;
434 #if defined(LWS_WITH_NETWORK)
436 #define lws_pollfd pollfd
440 int gettimeofday(
struct timeval *tv,
struct timezone *tz);
447 typedef unsigned short sa_family_t;
448 typedef unsigned short in_port_t;
449 typedef uint32_t socklen_t;
451 #include <libwebsockets/lws-optee.h>
453 #if !defined(TEE_SE_READER_NAME_MAX)
459 socklen_t ai_addrlen;
460 struct sockaddr *ai_addr;
462 struct addrinfo *ai_next;
466 ssize_t recv(
int sockfd,
void *buf, size_t len,
int flags);
467 ssize_t send(
int sockfd,
const void *buf, size_t len,
int flags);
468 ssize_t read(
int fd,
void *buf, size_t count);
469 int getsockopt(
int sockfd,
int level,
int optname,
470 void *optval, socklen_t *optlen);
471 int setsockopt(
int sockfd,
int level,
int optname,
472 const void *optval, socklen_t optlen);
473 int connect(
int sockfd,
const struct sockaddr *addr,
478 uint16_t ntohs(uint16_t netshort);
479 uint16_t htons(uint16_t hostshort);
481 int bind(
int sockfd,
const struct sockaddr *addr,
485 #define MSG_NOSIGNAL 0x4000
488 #define EWOULDBLOCK EAGAIN
489 #define EADDRINUSE 98
495 #define SOCK_STREAM 1
497 # define AI_PASSIVE 0x0001
498 #define IPPROTO_UDP 17
503 #define EINPROGRESS 115
504 int shutdown(
int sockfd,
int how);
506 int atoi(
const char *nptr);
507 long long atoll(
const char *nptr);
509 int socket(
int domain,
int type,
int protocol);
510 int getaddrinfo(
const char *node,
const char *service,
511 const struct addrinfo *hints,
512 struct addrinfo **res);
514 void freeaddrinfo(
struct addrinfo *res);
516 #if !defined(TEE_SE_READER_NAME_MAX)
525 int poll(
struct pollfd *fds,
int nfds,
int timeout);
527 #define LWS_POLLHUP (0x18
)
528 #define LWS_POLLIN (1
)
529 #define LWS_POLLOUT (4
)
535 #define lws_pollfd pollfd
536 #define LWS_POLLHUP (POLLHUP
| POLLERR
)
537 #define LWS_POLLIN (POLLIN
)
538 #define LWS_POLLOUT (POLLOUT
)
543 #if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
545 #define ssize_t SSIZE_T
548 #if defined(WIN32) && defined(LWS_HAVE__STAT32I64)
549 #include <sys/types.h>
550 #include <sys/stat.h>
553 #if defined(LWS_HAVE_STDINT_H
)
556 #if defined(WIN32) || defined(_WIN32)
558 typedef __int64 int64_t;
559 typedef unsigned __int64 uint64_t;
560 typedef __int32 int32_t;
561 typedef unsigned __int32 uint32_t;
562 typedef __int16 int16_t;
563 typedef unsigned __int16 uint16_t;
564 typedef unsigned __int8 uint8_t;
566 typedef unsigned int uint32_t;
567 typedef unsigned short uint16_t;
568 typedef unsigned char uint8_t;
577 #define lws_concat_temp(_t, _l) (_t + sizeof(_t) - _l)
578 #define lws_concat_used(_t, _l) (sizeof(_t) - _l)
588 #if !defined(LWS_SIZEOFPTR)
589 #define LWS_SIZEOFPTR ((int)sizeof (void *))
592 #if defined(__x86_64__
)
593 #define _LWS_PAD_SIZE 16
595 #define _LWS_PAD_SIZE LWS_SIZEOFPTR
603 #define LWS_SEND_BUFFER_POST_PADDING 0
626 } lws_stateful_ret_t;
633 #define LWS_FX_FRACTION_MSD 100000000
634 #define lws_neg(a) (a->whole < 0
|| a->frac < 0
)
635 #define lws_fx_set(a, x, y) { a.whole = x; a.frac = x < 0
? -y : y; }
636 #define lws_fix64(a) (((int64_t)a->whole << 32
) +
638 #define lws_fix64_abs(a)
639 ((((int64_t)(a->whole < 0
? (-a->whole) : a->whole) << 32
) +
642 #define lws_fix3232(a, a64) { a->whole = (int32_t)(a64 >> 32
);
643 a->frac = (int32_t)((100000000
* (a64 & 0xffffffff
)) >> 32
); }
646 lws_fx_add(lws_fx_t *r,
const lws_fx_t *a,
const lws_fx_t *b);
649 lws_fx_sub(lws_fx_t *r,
const lws_fx_t *a,
const lws_fx_t *b);
652 lws_fx_mul(lws_fx_t *r,
const lws_fx_t *a,
const lws_fx_t *b);
655 lws_fx_div(lws_fx_t *r,
const lws_fx_t *a,
const lws_fx_t *b);
672 #include <libwebsockets/lws-dll2.h>
673 #include <libwebsockets/lws-map.h>
675 #include <libwebsockets/lws-fault-injection.h>
676 #include <libwebsockets/lws-backtrace.h>
677 #include <libwebsockets/lws-timeout-timer.h>
678 #include <libwebsockets/lws-cache-ttl.h>
679 #if defined(LWS_WITH_SYS_SMD
)
680 #include <libwebsockets/lws-smd.h>
682 #include <libwebsockets/lws-state.h>
683 #include <libwebsockets/lws-retry.h>
684 #if defined(LWS_WITH_NETWORK
)
685 #include <libwebsockets/lws-adopt.h>
686 #include <libwebsockets/lws-network-helper.h>
687 #include <libwebsockets/lws-metrics.h>
690 #include <libwebsockets/lws-ota.h>
691 #include <libwebsockets/lws-system.h>
692 #if defined(LWS_WITH_NETWORK
)
693 #include <libwebsockets/lws-ws-close.h>
694 #include <libwebsockets/lws-callbacks.h>
695 #include <libwebsockets/lws-ws-state.h>
696 #include <libwebsockets/lws-ws-ext.h>
697 #include <libwebsockets/lws-protocols-plugins.h>
699 #include <libwebsockets/lws-context-vhost.h>
701 #if defined(LWS_WITH_NETWORK
)
702 #if defined(LWS_WITH_CONMON
)
703 #include <libwebsockets/lws-conmon.h>
706 #if defined(LWS_ROLE_MQTT
)
707 #include <libwebsockets/lws-mqtt.h>
709 #include <libwebsockets/lws-client.h>
710 #include <libwebsockets/lws-http.h>
711 #include <libwebsockets/lws-spa.h>
713 #include <libwebsockets/lws-purify.h>
714 #include <libwebsockets/lws-misc.h>
715 #include <libwebsockets/lws-dsh.h>
716 #if defined(LWS_WITH_NETWORK
)
717 #include <libwebsockets/lws-service.h>
718 #include <libwebsockets/lws-write.h>
719 #include <libwebsockets/lws-writeable.h>
721 #include <libwebsockets/lws-ring.h>
722 #include <libwebsockets/lws-sha1-base64.h>
723 #include <libwebsockets/lws-x509.h>
724 #if defined(LWS_WITH_NETWORK
)
725 #include <libwebsockets/lws-cgi.h>
727 #if defined(LWS_WITH_FILE_OPS
)
728 #include <libwebsockets/lws-vfs.h>
730 #include <libwebsockets/lws-gencrypto.h>
732 #include <libwebsockets/lws-lejp.h>
733 #include <libwebsockets/lws-lecp.h>
734 #include <libwebsockets/lws-cose.h>
735 #include <libwebsockets/lws-struct.h>
736 #include <libwebsockets/lws-threadpool.h>
737 #include <libwebsockets/lws-tokenize.h>
738 #include <libwebsockets/lws-lwsac.h>
739 #include <libwebsockets/lws-fts.h>
740 #include <libwebsockets/lws-diskcache.h>
741 #include <libwebsockets/lws-secure-streams.h>
742 #include <libwebsockets/lws-secure-streams-serialization.h>
743 #include <libwebsockets/lws-secure-streams-policy.h>
744 #include <libwebsockets/lws-secure-streams-client.h>
745 #include <libwebsockets/lws-secure-streams-transport-proxy.h>
746 #include <libwebsockets/lws-jrpc.h>
748 #include <libwebsockets/lws-async-dns.h>
750 #if defined(LWS_WITH_TLS
)
752 #include <libwebsockets/lws-tls-sessions.h>
754 #if defined(LWS_WITH_MBEDTLS)
755 #include <mbedtls/md5.h>
756 #include <mbedtls/sha1.h>
757 #include <mbedtls/sha256.h>
758 #include <mbedtls/sha512.h>
761 #include <libwebsockets/lws-genhash.h>
762 #include <libwebsockets/lws-genrsa.h>
763 #include <libwebsockets/lws-genaes.h>
764 #include <libwebsockets/lws-genec.h>
766 #include <libwebsockets/lws-jwk.h>
767 #include <libwebsockets/lws-jose.h>
768 #include <libwebsockets/lws-jws.h>
769 #include <libwebsockets/lws-jwe.h>
773 #if defined(LWS_WITH_NETWORK
)
774 #include <libwebsockets/lws-eventlib-exports.h>
776 #include <libwebsockets/lws-i2c.h>
777 #include <libwebsockets/lws-spi.h>
778 #if defined(LWS_ESP_PLATFORM)
779 #include <libwebsockets/lws-esp32-spi.h>
781 #include <libwebsockets/lws-gpio.h>
782 #include <libwebsockets/lws-bb-i2c.h>
783 #include <libwebsockets/lws-bb-spi.h>
784 #include <libwebsockets/lws-button.h>
785 #include <libwebsockets/lws-led.h>
786 #include <libwebsockets/lws-pwm.h>
787 #include <libwebsockets/lws-upng.h>
788 #include <libwebsockets/lws-jpeg.h>
789 #include <libwebsockets/lws-display.h>
790 #include <libwebsockets/lws-dlo.h>
791 #include <libwebsockets/lws-ssd1306-i2c.h>
792 #include <libwebsockets/lws-ili9341-spi.h>
793 #include <libwebsockets/lws-spd1656-spi.h>
794 #include <libwebsockets/lws-uc8176-spi.h>
795 #include <libwebsockets/lws-ssd1675b-spi.h>
796 #include <libwebsockets/lws-settings.h>
797 #if defined(LWS_WITH_NETWORK
)
798 #include <libwebsockets/lws-netdev.h>