libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
libwebsockets.h
Go to the documentation of this file.
1/*
2 * libwebsockets - small server side websockets and web server implementation
3 *
4 * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
26
27#ifndef LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C
28#define LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C
29
30#ifdef __cplusplus
31#include <cstddef>
32#include <cstdarg>
33
34extern "C" {
35#else
36#include <stdarg.h>
37#endif
38
39#include "lws_config.h"
40
41#if defined(LWS_HAVE_SYS_TYPES_H) && !defined(LWS_PLAT_BAREMETAL)
42#include <sys/types.h>
43#endif
44#if defined(LWS_HAVE_NET_ETHERNET_H)
45#include <net/ethernet.h>
46#endif
47/* NetBSD */
48#if defined(LWS_HAVE_NET_IF_ETHER_H)
49#include <net/if_ether.h>
50#endif
51#if defined(_WIN32) && !defined(ETHER_ADDR_LEN)
52#define ETHER_ADDR_LEN 6
53#endif
54#if defined (__sun)
55 #include <sys/ethernet.h>
56 #if !defined(ETHER_ADDR_LEN) && defined(ETHERADDRL)
57 #define ETHER_ADDR_LEN ETHERADDRL
58 #endif
59#endif
60#define LWS_ETHER_ADDR_LEN ETHER_ADDR_LEN
61
62#include <stddef.h>
63#include <string.h>
64#include <stdlib.h>
65
66
67/* place for one-shot opaque forward references */
68
69typedef struct lws_context * lws_ctx_t;
70struct lws_dsh;
71
72/*
73 * CARE: everything using cmake defines needs to be below here
74 */
75
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)
80
81#define LWS_KI (1024)
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)
86
87#define LWS_US_TO_MS(x) ((x + (LWS_US_PER_MS / 2)) / LWS_US_PER_MS)
88
89#define LWS_FOURCC(a, b, c, d) ((a << 24) | (b << 16) | (c << 8) | d)
90
91#if defined(LWS_HAS_INTPTR_T)
92#include <stdint.h>
93#define lws_intptr_t intptr_t
94#else
95typedef unsigned long long lws_intptr_t;
96#endif
97
98#if defined(WIN32) || defined(_WIN32)
99#ifndef WIN32_LEAN_AND_MEAN
100#define WIN32_LEAN_AND_MEAN
101#endif
102
103#include <winsock2.h>
104#include <ws2tcpip.h>
105#include <stddef.h>
106#include <basetsd.h>
107#include <io.h>
108#ifndef _WIN32_WCE
109#include <fcntl.h>
110#else
111#define _O_RDONLY 0x0000
112#define O_RDONLY _O_RDONLY
113#endif
114
115typedef unsigned int uid_t;
116typedef unsigned int gid_t;
117typedef unsigned short sa_family_t;
118#if !defined(LWS_HAVE_SUSECONDS_T)
119typedef unsigned int useconds_t;
120typedef int suseconds_t;
121#endif
122
123#define LWS_INLINE __inline
124#define LWS_VISIBLE
125#define LWS_WARN_UNUSED_RESULT
126#define LWS_WARN_DEPRECATED
127#define LWS_FORMAT(string_index)
128
129#if defined(LWS_HAVE_PTHREAD_H)
130#define lws_mutex_t pthread_mutex_t
131#define lws_mutex_init(x) pthread_mutex_init(&(x), NULL)
132#define lws_mutex_destroy(x) pthread_mutex_destroy(&(x))
133#define lws_mutex_lock(x) pthread_mutex_lock(&(x))
134#define lws_mutex_unlock(x) pthread_mutex_unlock(&(x))
135
136#define lws_tid_t pthread_t
137#define lws_thread_is(x) pthread_equal(x, pthread_self())
138#define lws_thread_id() pthread_self()
139
140#else
141/*
142 * Native win32 without an external pthreads: use the win32 slim
143 * reader/writer lock, which is header-only, needs no destroy, and lets
144 * SMD and async-dns build without pthreads. Lock must evaluate to 0 on
145 * success like the pthreads and freertos flavours.
146 */
147#define lws_mutex_t SRWLOCK
148#define lws_mutex_init(x) InitializeSRWLock(&(x))
149#define lws_mutex_destroy(x) ((void)(x))
150#define lws_mutex_lock(x) (AcquireSRWLockExclusive(&(x)), 0)
151#define lws_mutex_unlock(x) ReleaseSRWLockExclusive(&(x))
152
153#define lws_tid_t DWORD
154#define lws_thread_is(x) ((x) == GetCurrentThreadId())
155#define lws_thread_id() GetCurrentThreadId()
156#endif
157
158#if !defined(LWS_EXTERN) && defined(LWS_BUILDING_SHARED)
159#ifdef LWS_DLL
160#ifdef LWS_INTERNAL
161#define LWS_EXTERN extern __declspec(dllexport)
162#else
163#define LWS_EXTERN extern __declspec(dllimport)
164#endif
165#endif
166#endif
167
168#if !defined(LWS_INTERNAL) && !defined(LWS_EXTERN)
169#define LWS_EXTERN
170#define LWS_VISIBLE
171#endif
172
173#if !defined(LWS_EXTERN)
174#define LWS_EXTERN
175#endif
176
177#define LWS_INVALID_FILE INVALID_HANDLE_VALUE
178#define LWS_SOCK_INVALID (INVALID_SOCKET)
179#define LWS_O_RDONLY _O_RDONLY
180#define LWS_O_WRONLY _O_WRONLY
181#define LWS_O_CREAT _O_CREAT
182#define LWS_O_TRUNC _O_TRUNC
183
184#if (__STDC_VERSION__ < 199901L) && !defined(__func__)
185#define __func__ __FUNCTION__
186#endif
187
188#define LWS_POSIX_LENGTH_CAST(x) (unsigned int)(x)
189
190#else /* NOT WIN32 */
191#include <unistd.h>
192
193#if defined (LWS_PLAT_FREERTOS)
194#if defined(LWS_AMAZON_RTOS)
195#include <FreeRTOS.h>
196#include <semphr.h>
197#include <task.h>
198#else
199#include <freertos/FreeRTOS.h>
200#include <freertos/semphr.h>
201#include <freertos/task.h>
202#endif
203
204typedef SemaphoreHandle_t lws_mutex_t;
205#define lws_mutex_init(x) x = xSemaphoreCreateMutex()
206#define lws_mutex_destroy(x) vSemaphoreDelete(x)
207#define lws_mutex_lock(x) (!xSemaphoreTake(x, portMAX_DELAY)) /*0 = OK */
208#define lws_mutex_unlock(x) xSemaphoreGive(x)
209
210#define lws_tid_t TaskHandle_t
211#define lws_thread_is(x) (x == xTaskGetCurrentTaskHandle())
212#define lws_thread_id() xTaskGetCurrentTaskHandle()
213#else
214
215#if defined(LWS_HAVE_PTHREAD_H)
216#include <pthread.h>
217#include <sys/types.h>
218
219typedef pthread_mutex_t lws_mutex_t;
220#define lws_mutex_init(x) pthread_mutex_init(&(x), NULL)
221#define lws_mutex_destroy(x) pthread_mutex_destroy(&(x))
222#define lws_mutex_lock(x) pthread_mutex_lock(&(x))
223#define lws_mutex_unlock(x) pthread_mutex_unlock(&(x))
224
225#define lws_tid_t pthread_t
226#define lws_thread_is(x) pthread_equal(x, pthread_self())
227#define lws_thread_id() pthread_self()
228#else
229/*
230 * No threading support on this platform: the lws_mutex_t apis become
231 * no-ops so single-threaded builds of SMD and async-dns still work.
232 * Lock must evaluate to 0 on success like the other flavours.
233 */
234typedef char lws_mutex_t;
235#define lws_mutex_init(x) ((void)(x))
236#define lws_mutex_destroy(x) ((void)(x))
237#define lws_mutex_lock(x) ((void)(x), 0)
238#define lws_mutex_unlock(x) ((void)(x))
239
240#define lws_tid_t int
241#define lws_thread_is(x) ((void)(x), 1)
242#define lws_thread_id() 0
243#endif
244#endif /* freertos */
245
246#define LWS_POSIX_LENGTH_CAST(x) ((size_t)(x))
247
248#if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP)
249#include <sys/capability.h>
250#endif
251
252#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__QNX__) || defined(__OpenBSD__) || defined(__NuttX__)
253#include <sys/socket.h>
254#include <netinet/in.h>
255#endif
256
257/* Find ETHER_ADDR_LEN on OpenBSD */
258#if defined(__OpenBSD__)
259#include <net/if_arp.h>
260#include <netinet/if_ether.h>
261#endif
262
263#define LWS_INLINE inline
264#define LWS_O_RDONLY O_RDONLY
265#define LWS_O_WRONLY O_WRONLY
266#define LWS_O_CREAT O_CREAT
267#define LWS_O_TRUNC O_TRUNC
268
269#if !defined(LWS_PLAT_OPTEE) && !defined(OPTEE_TA) && !defined(LWS_PLAT_FREERTOS) && !defined(LWS_PLAT_BAREMETAL)
270#include <poll.h>
271#include <netdb.h>
272#define LWS_INVALID_FILE -1
273#define LWS_SOCK_INVALID (-1)
274#else
275#define getdtablesize() (30)
276#if defined(LWS_PLAT_FREERTOS)
277#define LWS_INVALID_FILE NULL
278#define LWS_SOCK_INVALID (-1)
279#else
280#define LWS_INVALID_FILE NULL
281#define LWS_SOCK_INVALID (-1)
282#endif
283#endif
284
285#if defined(__FreeBSD__)
286#include <sys/signal.h>
287#endif
288#if defined(__GNUC__)
289
290/* warn_unused_result attribute only supported by GCC 3.4 or later */
291#if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
292#define LWS_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
293#else
294#define LWS_WARN_UNUSED_RESULT
295#endif
296
297#if defined(LWS_BUILDING_SHARED)
298/* this is only set when we're building lws itself shared */
299#define LWS_VISIBLE __attribute__((visibility("default")))
300#define LWS_EXTERN extern
301
302#else /* not shared */
303#if defined(WIN32) || defined(_WIN32) || defined(__MINGW32__)
304#define LWS_VISIBLE
305#define LWS_EXTERN extern
306#else
307/*
308 * If we explicitly say hidden here, symbols exist as T but
309 * cannot be imported at link-time.
310 */
311#define LWS_VISIBLE
312#define LWS_EXTERN
313#endif
314
315#endif /* not shared */
316
317#define LWS_WARN_DEPRECATED __attribute__ ((deprecated))
318#undef printf
319#define LWS_FORMAT(string_index) __attribute__ ((format(printf, string_index, string_index+1)))
320#else /* not GNUC */
321
322#define LWS_VISIBLE
323#define LWS_WARN_UNUSED_RESULT
324#define LWS_WARN_DEPRECATED
325#define LWS_FORMAT(string_index)
326#if !defined(LWS_EXTERN)
327#define LWS_EXTERN extern
328#endif
329#endif
330
331#if defined(__ANDROID__)
332#include <netinet/in.h>
333#include <unistd.h>
334#endif
335#endif
336
337#if defined(_WIN32)
338#if defined(LWS_DLL)
339#if defined(LWS_INTERNAL)
340#define LWS_EXTERN_FOR_DATA extern __declspec(dllexport)
341#else
342#define LWS_EXTERN_FOR_DATA extern __declspec(dllimport)
343#endif
344#else
345#define LWS_EXTERN_FOR_DATA extern
346#endif
347#else
348#define LWS_EXTERN_FOR_DATA extern
349#endif
350
351#ifdef _WIN32
352#define random rand
353#else
354#if !defined(LWS_PLAT_OPTEE)
355#include <sys/time.h>
356#include <unistd.h>
357#endif
358#endif
359
360#if defined(LWS_WITH_LIBUV_INTERNAL)
361#include <uv.h>
362
363#ifdef LWS_HAVE_UV_VERSION_H
364#include <uv-version.h>
365#endif
366
367#ifdef LWS_HAVE_NEW_UV_VERSION_H
368#include <uv/version.h>
369#endif
370#endif
371
372#if defined(LWS_WITH_TLS)
373
374#if defined(LWS_WITH_SCHANNEL)
375typedef struct lws_tls_schannel_conn SSL;
376typedef struct lws_tls_schannel_ctx SSL_CTX;
377typedef struct lws_tls_schannel_bio BIO;
378typedef struct lws_tls_schannel_x509 X509;
379
380/*
381 * These are needed for lws-gen* and other headers that assume OpenSSL types
382 * when LWS_WITH_TLS is defined. SChannel implementation of these APIs
383 * will need to map these to Windows CryptoAPI/CNG types internally,
384 * or we can just treat them as opaque handles here.
385 */
386typedef void EVP_PKEY_CTX;
387typedef void EVP_MD;
388typedef void EVP_MD_CTX;
389typedef void HMAC_CTX;
390typedef void EVP_CIPHER_CTX;
391typedef void EVP_CIPHER;
392typedef void ENGINE;
393typedef void RSA;
394typedef void BIGNUM;
395typedef void EC_KEY;
396typedef void EC_POINT;
397typedef void EC_GROUP;
398typedef void X509_STORE_CTX;
399typedef void X509_VERIFY_PARAM;
400
401#else
402
403#ifdef USE_WOLFSSL
404#ifdef USE_OLD_CYASSL
405#ifdef _WIN32
406/*
407 * Include user-controlled settings for windows from
408 * <wolfssl-root>/IDE/WIN/user_settings.h
409 */
410#include <IDE/WIN/user_settings.h>
411#include <cyassl/ctaocrypt/settings.h>
412#else
413#include <cyassl/options.h>
414#endif
415#include <cyassl/openssl/ssl.h>
416#include <cyassl/error-ssl.h>
417
418#else
419#ifdef _WIN32
420/*
421 * Include user-controlled settings for windows from
422 * <wolfssl-root>/IDE/WIN/user_settings.h
423 */
424#include <IDE/WIN/user_settings.h>
425#include <wolfssl/wolfcrypt/settings.h>
426#else
427#include <wolfssl/options.h>
428#endif
429#include <wolfssl/openssl/ssl.h>
430#include <wolfssl/error-ssl.h>
431#endif /* not USE_OLD_CYASSL */
432#else
433#if defined(LWS_WITH_MBEDTLS)
434#if defined(LWS_PLAT_FREERTOS)
435/* this filepath is passed to us but without quotes or <> */
436#if !defined(LWS_AMAZON_RTOS)
437/* AMAZON RTOS has its own setting via MTK_MBEDTLS_CONFIG_FILE */
438#undef MBEDTLS_CONFIG_FILE
439#define MBEDTLS_CONFIG_FILE <mbedtls/esp_config.h>
440#endif
441#endif
442
443#if defined(LWS_WITH_TLS)
444#include <mbedtls/ssl.h>
445#if !defined(LWS_HAVE_MBEDTLS_V4)
446#include <mbedtls/entropy.h>
447#include <mbedtls/ctr_drbg.h>
448#endif
449#include <mbedtls/version.h>
450
451#if !defined(MBEDTLS_PRIVATE)
452#define MBEDTLS_PRIVATE(_q) _q
453#endif
454
455#if (MBEDTLS_VERSION_MAJOR == 3) && (MBEDTLS_VERSION_MINOR == 0)
456#define MBEDTLS_PRIVATE_V30_ONLY(_q) MBEDTLS_PRIVATE(_q)
457#else
458#define MBEDTLS_PRIVATE_V30_ONLY(_q) _q
459#endif
460
461#endif
462#elif defined(LWS_WITH_GNUTLS)
463#include <gnutls/gnutls.h>
464#include <gnutls/crypto.h>
465#include <gnutls/abstract.h>
466#include <gnutls/x509.h>
467#include <netinet/in.h>
468#include <unistd.h>
469typedef struct gnutls_session_int SSL;
470typedef struct lws_tls_gnutls_ctx SSL_CTX;
471typedef void BIO;
472typedef struct gnutls_x509_crt_int X509;
473#elif defined(LWS_WITH_OPENHITLS)
474#include <hitls_type.h>
475#include <hitls_cert_type.h>
476#include <hitls_pki_cert.h>
477typedef HITLS_Ctx SSL;
478typedef HITLS_Config SSL_CTX;
479typedef void BIO;
480typedef HITLS_X509_Cert X509;
481typedef HITLS_CERT_StoreCtx X509_STORE_CTX;
482#else
483#include <openssl/ssl.h>
484#if !defined(LWS_WITH_MBEDTLS)
485#include <openssl/err.h>
486#endif
487#endif
488#endif /* not USE_WOLFSSL */
489#endif /* not SCHANNEL */
490#endif
491
492/*
493 * Helpers for pthread mutex in user code... if lws is built for
494 * multiple service threads, these resolve to pthread mutex
495 * operations. In the case LWS_MAX_SMP is 1 (the default), they
496 * are all NOPs and no pthread type or api is referenced.
497 */
498
499#if LWS_MAX_SMP > 1
500
501#include <pthread.h>
502
503#define lws_pthread_mutex(name) pthread_mutex_t name;
504
505static LWS_INLINE void
506lws_pthread_mutex_init(pthread_mutex_t *lock)
507{
508 pthread_mutex_init(lock, NULL);
509}
510
511static LWS_INLINE void
512lws_pthread_mutex_destroy(pthread_mutex_t *lock)
513{
514 pthread_mutex_destroy(lock);
515}
516
517static LWS_INLINE void
518lws_pthread_mutex_lock(pthread_mutex_t *lock)
519{
520 pthread_mutex_lock(lock);
521}
522
523static LWS_INLINE void
524lws_pthread_mutex_unlock(pthread_mutex_t *lock)
525{
526 pthread_mutex_unlock(lock);
527}
528
529#else
530#define lws_pthread_mutex(name)
531#define lws_pthread_mutex_init(_a)
532#define lws_pthread_mutex_destroy(_a)
533#define lws_pthread_mutex_lock(_a)
534#define lws_pthread_mutex_unlock(_a)
535#endif
536
537
538#define CONTEXT_PORT_NO_LISTEN -1
539#define CONTEXT_PORT_NO_LISTEN_SERVER -2
540
542
543
544#include <stddef.h>
545
546#ifndef lws_container_of
547#define lws_container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M)))
548#endif
549#define LWS_ALIGN_TO(x, bou) x += ((bou) - ((x) % (bou))) % (bou)
550
551struct lws;
552
553/* api change list for user code to test against */
554
555#define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG
556
557/* the struct lws_protocols has the id field present */
558#define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD
559
560/* you can call lws_get_peer_write_allowance */
561#define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE
562
563/* extra parameter introduced in 917f43ab821 */
564#define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_LEN
565
566/* File operations stuff exists */
567#define LWS_FEATURE_FOPS
568
569/* Mounts have extra no_cache member */
570#define LWS_FEATURE_MOUNT_NO_CACHE
571
572
573#if defined(_WIN32)
574#if !defined(LWS_WIN32_HANDLE_TYPES)
575typedef SOCKET lws_sockfd_type;
576#if defined(__MINGW32__)
577typedef int lws_filefd_type;
578#else
579typedef HANDLE lws_filefd_type;
580#endif
581#endif
582
583
584#define lws_pollfd pollfd
585#define LWS_POLLHUP (POLLHUP)
586#define LWS_POLLIN (POLLRDNORM | POLLRDBAND)
587#define LWS_POLLOUT (POLLWRNORM)
588
589#else
590
591
592#if defined(LWS_PLAT_FREERTOS)
594#else
595typedef int lws_sockfd_type;
596typedef int lws_filefd_type;
597#endif
598
599#if defined(LWS_PLAT_OPTEE)
600#include <time.h>
601struct timeval {
602 time_t tv_sec;
603 unsigned int tv_usec;
604};
605#if defined(LWS_WITH_NETWORK)
606// #include <poll.h>
607#define lws_pollfd pollfd
608
609struct timezone;
610
611int gettimeofday(struct timeval *tv, struct timezone *tz);
612
613 /* Internet address. */
614 struct in_addr {
615 uint32_t s_addr; /* address in network byte order */
616 };
617
618typedef unsigned short sa_family_t;
619typedef unsigned short in_port_t;
620typedef uint32_t socklen_t;
621
623
624#if !defined(TEE_SE_READER_NAME_MAX)
625 struct addrinfo {
626 int ai_flags;
627 int ai_family;
628 int ai_socktype;
629 int ai_protocol;
630 socklen_t ai_addrlen;
631 struct sockaddr *ai_addr;
632 char *ai_canonname;
633 struct addrinfo *ai_next;
634 };
635#endif
636
637ssize_t recv(int sockfd, void *buf, size_t len, int flags);
638ssize_t send(int sockfd, const void *buf, size_t len, int flags);
639ssize_t read(int fd, void *buf, size_t count);
640int getsockopt(int sockfd, int level, int optname,
641 void *optval, socklen_t *optlen);
642 int setsockopt(int sockfd, int level, int optname,
643 const void *optval, socklen_t optlen);
644int connect(int sockfd, const struct sockaddr *addr,
645 socklen_t addrlen);
646
647#if defined(ESP_PLATFORM)
648/* IDF v6 (picolibc) makes errno thread-local; a plain "extern int errno" makes
649 * lws objects reference it non-TLS and fail to link ("TLS definition ...
650 * mismatches non-TLS reference"). Use the platform's real errno. */
651#include <errno.h>
652#else
653extern int errno;
654#endif
655
656uint16_t ntohs(uint16_t netshort);
657uint16_t htons(uint16_t hostshort);
658
659int bind(int sockfd, const struct sockaddr *addr,
660 socklen_t addrlen);
661
662
663#define MSG_NOSIGNAL 0x4000
664#define EAGAIN 11
665#define EINTR 4
666#define EWOULDBLOCK EAGAIN
667#define EADDRINUSE 98
668#define INADDR_ANY 0
669#define AF_INET 2
670#define SHUT_WR 1
671#define AF_UNSPEC 0
672#define PF_UNSPEC 0
673#define SOCK_STREAM 1
674#define SOCK_DGRAM 2
675# define AI_PASSIVE 0x0001
676#define IPPROTO_UDP 17
677#define SOL_SOCKET 1
678#define SO_SNDBUF 7
679#define EISCONN 106
680#define EALREADY 114
681#define EINPROGRESS 115
682int shutdown(int sockfd, int how);
683int close(int fd);
684int atoi(const char *nptr);
685long long atoll(const char *nptr);
686
687int socket(int domain, int type, int protocol);
688 int getaddrinfo(const char *node, const char *service,
689 const struct addrinfo *hints,
690 struct addrinfo **res);
691
692 void freeaddrinfo(struct addrinfo *res);
693
694#if !defined(TEE_SE_READER_NAME_MAX)
695struct lws_pollfd
696{
697 int fd; /* File descriptor to poll. */
698 short int events; /* Types of events poller cares about. */
699 short int revents; /* Types of events that actually occurred. */
700};
701#endif
702
703int poll(struct pollfd *fds, int nfds, int timeout);
704
705#define LWS_POLLHUP (0x18)
706#define LWS_POLLIN (1)
707#define LWS_POLLOUT (4)
708#else
709struct lws_pollfd;
710struct sockaddr_in;
711#endif
712#else
713#define lws_pollfd pollfd
714#define LWS_POLLHUP (POLLHUP | POLLERR)
715#define LWS_POLLIN (POLLIN)
716#define LWS_POLLOUT (POLLOUT)
717#endif
718#endif
719
720
721#if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
722/* ... */
723#define ssize_t SSIZE_T
724#endif
725
726#if defined(WIN32) && defined(LWS_HAVE__STAT32I64)
727#include <sys/types.h>
728#include <sys/stat.h>
729#endif
730
731#if defined(LWS_HAVE_STDINT_H)
732#include <stdint.h>
733#else
734#if defined(WIN32) || defined(_WIN32)
735/* !!! >:-[ */
736typedef __int64 int64_t;
737typedef unsigned __int64 uint64_t;
738typedef __int32 int32_t;
739typedef unsigned __int32 uint32_t;
740typedef __int16 int16_t;
741typedef unsigned __int16 uint16_t;
742typedef unsigned __int8 uint8_t;
743#else
744typedef unsigned int uint32_t;
745typedef unsigned short uint16_t;
746typedef unsigned char uint8_t;
747#endif
748#endif
749
750typedef int64_t lws_usec_t;
751typedef unsigned long long lws_filepos_t;
752typedef long long lws_fileofs_t;
754
755#define lws_concat_temp(_t, _l) (_t + sizeof(_t) - _l)
756#define lws_concat_used(_t, _l) (sizeof(_t) - _l)
757
765
766#if !defined(LWS_SIZEOFPTR)
767#define LWS_SIZEOFPTR ((int)sizeof (void *))
768#endif
769
770#if defined(__x86_64__)
771#define _LWS_PAD_SIZE 16 /* Intel recommended for best performance */
772#else
773#define _LWS_PAD_SIZE LWS_SIZEOFPTR /* Size of a pointer on the target arch */
774#endif
775#define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? \
776 ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n))
777/*
778 * Headroom lws needs before a buffer passed to lws_write(): the largest ws
779 * frame header (10) plus its client-side mask (4), plus 2 for lws-meta, plus
780 * the 9-byte h2 DATA frame header that is prepended in place when a ws
781 * stream is carried over h2 (RFC 8441). Without the last term a ws-over-h2
782 * frame of 126+ bytes (client) or 64KB+ (server) wrote up to 7 bytes before
783 * the caller's buffer. Pads to 32 on 64-bit.
784 */
785#define LWS_PRE _LWS_PAD(4 + 10 + 2 + 9)
786/* used prior to 1.7 and retained for backward compatibility */
787#define LWS_SEND_BUFFER_PRE_PADDING LWS_PRE
788#define LWS_SEND_BUFFER_POST_PADDING 0
789
790
791
792struct lws_extension; /* needed even with ws exts disabled for create context */
793struct lws_token_limits;
794struct lws_protocols;
795struct lws_context;
796struct lws_tokens;
797struct lws_vhost;
798struct lws;
799
800/* Generic stateful operation return codes */
801
802typedef enum {
806 LWS_SRET_FATAL = (1 << 18),
810 LWS_SRET_YIELD = (1 << 22), /* return to the event loop and continue */
812
813typedef struct lws_fixed3232 {
814 int32_t whole; /* signed 32-bit int */
815 int32_t frac; /* signed frac proportion from 0 to (100M - 1) */
817
818#define LWS_FX_FRACTION_MSD 100000000
819#define lws_neg(a) (a->whole < 0 || a->frac < 0)
820#define lws_fx_set(a, x, y) { a.whole = x; a.frac = x < 0 ? -y : y; }
821#define lws_fix64(a) (((int64_t)a->whole << 32) + \
822 (((1ll << 32) * (a->frac < 0 ? -a->frac : a->frac)) / LWS_FX_FRACTION_MSD))
823#define lws_fix64_abs(a) \
824 ((((int64_t)(a->whole < 0 ? (-a->whole) : a->whole) << 32) + \
825 (((1ll << 32) * (a->frac < 0 ? -a->frac : a->frac)) / LWS_FX_FRACTION_MSD)))
826
827#define lws_fix3232(a, a64) { a->whole = (int32_t)(a64 >> 32); \
828 a->frac = (int32_t)((100000000 * (a64 & 0xffffffff)) >> 32); }
829
831lws_fx_add(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b);
832
834lws_fx_sub(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b);
835
837lws_fx_mul(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b);
838
840lws_fx_div(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b);
841
844
858
869
881
894lws_fx_atan2(lws_fx_t *r, const lws_fx_t *y, const lws_fx_t *x);
895
897lws_fx_comp(const lws_fx_t *a, const lws_fx_t *b);
898
901
904
905LWS_VISIBLE LWS_EXTERN const char *
906lws_fx_string(const lws_fx_t *a, char *buf, size_t size);
907
910
915#if defined(LWS_WITH_SYS_SMD)
917#endif
921#if defined(LWS_WITH_TRANSPORT_SEQUENCER)
923#endif
924#if defined(LWS_WITH_NETWORK)
928#endif
929
934
935#if defined(LWS_WITH_NETWORK)
940#endif
941
943#if defined(LWS_WITH_JOSE)
945#endif
946
948
949#if defined(LWS_WITH_NETWORK)
950#if defined(LWS_WITH_CONMON)
952#endif
953
954#if defined(LWS_ROLE_MQTT)
956#endif
959#if defined(LWS_ROLE_H3)
962#endif
965#endif
969#if defined(LWS_WITH_NETWORK)
973#endif
975#if defined(LWS_WITH_MNEMONIC)
977#endif
982#if defined(LWS_WITH_NETWORK)
984#endif
985#if defined(LWS_WITH_FILE_OPS)
987#endif
989
1004#include <libwebsockets/lws-jrpc.h>
1005#include <libwebsockets/lws-stub.h>
1006
1008#if defined(LWS_WITH_AUTHORITATIVE_DNS)
1010#endif
1011
1012#if defined(LWS_WITH_TLS)
1013
1015#include <libwebsockets/lws-quic.h>
1016
1017#if defined(LWS_WITH_MBEDTLS)
1018#if !defined(LWS_HAVE_MBEDTLS_V4)
1019#include <mbedtls/md5.h>
1020#include <mbedtls/sha1.h>
1021#include <mbedtls/sha256.h>
1022#include <mbedtls/sha512.h>
1023#else
1024#include <psa/crypto.h>
1025#endif
1026#endif
1027#if defined(LWS_WITH_BEARSSL)
1028#include <bearssl.h>
1029#endif
1030
1036
1037#include <libwebsockets/lws-jwk.h>
1038#include <libwebsockets/lws-jose.h>
1039#include <libwebsockets/lws-jws.h>
1040#include <libwebsockets/lws-jwe.h>
1042
1043#endif
1044
1045#if defined(LWS_WITH_NETWORK)
1047#endif
1048#include <libwebsockets/lws-i2c.h>
1049#include <libwebsockets/lws-spi.h>
1050#if defined(LWS_ESP_PLATFORM)
1052#endif
1053#include <libwebsockets/lws-gpio.h>
1057#include <libwebsockets/lws-led.h>
1058#include <libwebsockets/lws-pwm.h>
1059#include <libwebsockets/lws-upng.h>
1060#include <libwebsockets/lws-jpeg.h>
1061#include <libwebsockets/lws-svg.h>
1062#include <libwebsockets/lws-gif.h>
1064#include <libwebsockets/lws-dlo.h>
1073#if defined(LWS_WITH_DLTS)
1075#endif
1076#if defined(LWS_WITH_NETWORK)
1079#include "libwebsockets/lws-dht.h"
1081#if defined(LWS_WITH_TRANSCODE)
1083#endif
1084#if defined(LWS_WITH_V4L2)
1085#include <libwebsockets/lws-v4l2.h>
1086#endif
1087#if defined(LWS_WITH_ALSA)
1088#include <libwebsockets/lws-alsa.h>
1090#endif
1091#endif
1092
1093#include <libwebsockets/lws-html.h>
1094#if defined(LWS_WITH_HL)
1095#include <libwebsockets/lws-hl.h>
1096#endif
1097#if defined(LWS_WITH_MD)
1098#include <libwebsockets/lws-md.h>
1099#endif
1102
1103#if defined(LWS_WITH_DIR)
1105#endif
1106
1107#ifdef __cplusplus
1108}
1109#endif
1110
1111#endif
#define lws_pthread_mutex_lock(_a)
uint32_t lws_fop_flags_t
LWS_VISIBLE LWS_EXTERN const lws_fx_t * lws_fx_cos(lws_fx_t *r, const lws_fx_t *a)
unsigned short uint16_t
#define lws_pollfd
unsigned int uint32_t
#define lws_pthread_mutex_init(_a)
LWS_VISIBLE LWS_EXTERN const lws_fx_t * lws_fx_atan2(lws_fx_t *r, const lws_fx_t *y, const lws_fx_t *x)
long long lws_fileofs_t
#define LWS_INLINE
LWS_VISIBLE LWS_EXTERN const lws_fx_t * lws_fx_sin(lws_fx_t *r, const lws_fx_t *a)
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_destroy(_a)
LWS_VISIBLE LWS_EXTERN int lws_fx_rounddown(const lws_fx_t *a)
#define LWS_EXTERN
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)
char lws_mutex_t
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)
int64_t lws_usec_t
unsigned char uint8_t
struct lws_fixed3232 lws_fx_t
lws_stateful_ret_t
@ LWS_SRET_WANT_OUTPUT
@ LWS_SRET_NO_FURTHER_OUT
@ LWS_SRET_FATAL
@ LWS_SRET_OK
@ LWS_SRET_NO_FURTHER_IN
@ LWS_SRET_YIELD
@ LWS_SRET_WANT_INPUT
@ LWS_SRET_AWAIT_RETRY
struct lws_context * lws_ctx_t
LWS_VISIBLE LWS_EXTERN const lws_fx_t * lws_fx_tan(lws_fx_t *r, const lws_fx_t *a)
int lws_sockfd_type
#define lws_pthread_mutex_unlock(_a)
#define LWS_VISIBLE
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_intptr_t
unsigned long long lws_filepos_t
lws_sockfd_type fd
LWS_VISIBLE LWS_EXTERN int lws_fx_comp(const lws_fx_t *a, const lws_fx_t *b)
int lws_filefd_type