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#endif
141
142#if !defined(LWS_EXTERN) && defined(LWS_BUILDING_SHARED)
143#ifdef LWS_DLL
144#ifdef LWS_INTERNAL
145#define LWS_EXTERN extern __declspec(dllexport)
146#else
147#define LWS_EXTERN extern __declspec(dllimport)
148#endif
149#endif
150#endif
151
152#if !defined(LWS_INTERNAL) && !defined(LWS_EXTERN)
153#define LWS_EXTERN
154#define LWS_VISIBLE
155#endif
156
157#if !defined(LWS_EXTERN)
158#define LWS_EXTERN
159#endif
160
161#define LWS_INVALID_FILE INVALID_HANDLE_VALUE
162#define LWS_SOCK_INVALID (INVALID_SOCKET)
163#define LWS_O_RDONLY _O_RDONLY
164#define LWS_O_WRONLY _O_WRONLY
165#define LWS_O_CREAT _O_CREAT
166#define LWS_O_TRUNC _O_TRUNC
167
168#if (__STDC_VERSION__ < 199901L) && !defined(__func__)
169#define __func__ __FUNCTION__
170#endif
171
172#define LWS_POSIX_LENGTH_CAST(x) (unsigned int)(x)
173
174#else /* NOT WIN32 */
175#include <unistd.h>
176
177#if defined (LWS_PLAT_FREERTOS)
178#if defined(LWS_AMAZON_RTOS)
179#include <FreeRTOS.h>
180#include <semphr.h>
181#include <task.h>
182#else
183#include <freertos/FreeRTOS.h>
184#include <freertos/semphr.h>
185#include <freertos/task.h>
186#endif
187
188typedef SemaphoreHandle_t lws_mutex_t;
189#define lws_mutex_init(x) x = xSemaphoreCreateMutex()
190#define lws_mutex_destroy(x) vSemaphoreDelete(x)
191#define lws_mutex_lock(x) (!xSemaphoreTake(x, portMAX_DELAY)) /*0 = OK */
192#define lws_mutex_unlock(x) xSemaphoreGive(x)
193
194#define lws_tid_t TaskHandle_t
195#define lws_thread_is(x) (x == xTaskGetCurrentTaskHandle())
196#define lws_thread_id() xTaskGetCurrentTaskHandle()
197#else
198
199#if defined(LWS_HAVE_PTHREAD_H)
200#include <pthread.h>
201#include <sys/types.h>
202
203typedef pthread_mutex_t lws_mutex_t;
204#define lws_mutex_init(x) pthread_mutex_init(&(x), NULL)
205#define lws_mutex_destroy(x) pthread_mutex_destroy(&(x))
206#define lws_mutex_lock(x) pthread_mutex_lock(&(x))
207#define lws_mutex_unlock(x) pthread_mutex_unlock(&(x))
208
209#define lws_tid_t pthread_t
210#define lws_thread_is(x) pthread_equal(x, pthread_self())
211#define lws_thread_id() pthread_self()
212#endif
213#endif /* freertos */
214
215#define LWS_POSIX_LENGTH_CAST(x) (x)
216
217#if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP)
218#include <sys/capability.h>
219#endif
220
221#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__QNX__) || defined(__OpenBSD__) || defined(__NuttX__)
222#include <sys/socket.h>
223#include <netinet/in.h>
224#endif
225
226/* Find ETHER_ADDR_LEN on OpenBSD */
227#if defined(__OpenBSD__)
228#include <net/if_arp.h>
229#include <netinet/if_ether.h>
230#endif
231
232#define LWS_INLINE inline
233#define LWS_O_RDONLY O_RDONLY
234#define LWS_O_WRONLY O_WRONLY
235#define LWS_O_CREAT O_CREAT
236#define LWS_O_TRUNC O_TRUNC
237
238#if !defined(LWS_PLAT_OPTEE) && !defined(OPTEE_TA) && !defined(LWS_PLAT_FREERTOS) && !defined(LWS_PLAT_BAREMETAL)
239#include <poll.h>
240#include <netdb.h>
241#define LWS_INVALID_FILE -1
242#define LWS_SOCK_INVALID (-1)
243#else
244#define getdtablesize() (30)
245#if defined(LWS_PLAT_FREERTOS)
246#define LWS_INVALID_FILE NULL
247#define LWS_SOCK_INVALID (-1)
248#else
249#define LWS_INVALID_FILE NULL
250#define LWS_SOCK_INVALID (-1)
251#endif
252#endif
253
254#if defined(__FreeBSD__)
255#include <sys/signal.h>
256#endif
257#if defined(__GNUC__)
258
259/* warn_unused_result attribute only supported by GCC 3.4 or later */
260#if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
261#define LWS_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
262#else
263#define LWS_WARN_UNUSED_RESULT
264#endif
265
266#if defined(LWS_BUILDING_SHARED)
267/* this is only set when we're building lws itself shared */
268#define LWS_VISIBLE __attribute__((visibility("default")))
269#define LWS_EXTERN extern
270
271#else /* not shared */
272#if defined(WIN32) || defined(_WIN32) || defined(__MINGW32__)
273#define LWS_VISIBLE
274#define LWS_EXTERN extern
275#else
276/*
277 * If we explicitly say hidden here, symbols exist as T but
278 * cannot be imported at link-time.
279 */
280#define LWS_VISIBLE
281#define LWS_EXTERN
282#endif
283
284#endif /* not shared */
285
286#define LWS_WARN_DEPRECATED __attribute__ ((deprecated))
287#undef printf
288#define LWS_FORMAT(string_index) __attribute__ ((format(printf, string_index, string_index+1)))
289#else /* not GNUC */
290
291#define LWS_VISIBLE
292#define LWS_WARN_UNUSED_RESULT
293#define LWS_WARN_DEPRECATED
294#define LWS_FORMAT(string_index)
295#if !defined(LWS_EXTERN)
296#define LWS_EXTERN extern
297#endif
298#endif
299
300#if defined(__ANDROID__)
301#include <netinet/in.h>
302#include <unistd.h>
303#endif
304#endif
305
306#if defined(_WIN32)
307#if defined(LWS_DLL)
308#if defined(LWS_INTERNAL)
309#define LWS_EXTERN_FOR_DATA extern __declspec(dllexport)
310#else
311#define LWS_EXTERN_FOR_DATA extern __declspec(dllimport)
312#endif
313#else
314#define LWS_EXTERN_FOR_DATA extern
315#endif
316#else
317#define LWS_EXTERN_FOR_DATA extern
318#endif
319
320#ifdef _WIN32
321#define random rand
322#else
323#if !defined(LWS_PLAT_OPTEE)
324#include <sys/time.h>
325#include <unistd.h>
326#endif
327#endif
328
329#if defined(LWS_WITH_LIBUV_INTERNAL)
330#include <uv.h>
331
332#ifdef LWS_HAVE_UV_VERSION_H
333#include <uv-version.h>
334#endif
335
336#ifdef LWS_HAVE_NEW_UV_VERSION_H
337#include <uv/version.h>
338#endif
339#endif
340
341#if defined(LWS_WITH_TLS)
342
343#if defined(LWS_WITH_SCHANNEL)
344typedef struct lws_tls_schannel_conn SSL;
345typedef struct lws_tls_schannel_ctx SSL_CTX;
346typedef struct lws_tls_schannel_bio BIO;
347typedef struct lws_tls_schannel_x509 X509;
348
349/*
350 * These are needed for lws-gen* and other headers that assume OpenSSL types
351 * when LWS_WITH_TLS is defined. SChannel implementation of these APIs
352 * will need to map these to Windows CryptoAPI/CNG types internally,
353 * or we can just treat them as opaque handles here.
354 */
355typedef void EVP_PKEY_CTX;
356typedef void EVP_MD;
357typedef void EVP_MD_CTX;
358typedef void HMAC_CTX;
359typedef void EVP_CIPHER_CTX;
360typedef void EVP_CIPHER;
361typedef void ENGINE;
362typedef void RSA;
363typedef void BIGNUM;
364typedef void EC_KEY;
365typedef void EC_POINT;
366typedef void EC_GROUP;
367typedef void X509_STORE_CTX;
368typedef void X509_VERIFY_PARAM;
369
370#else
371
372#ifdef USE_WOLFSSL
373#ifdef USE_OLD_CYASSL
374#ifdef _WIN32
375/*
376 * Include user-controlled settings for windows from
377 * <wolfssl-root>/IDE/WIN/user_settings.h
378 */
379#include <IDE/WIN/user_settings.h>
380#include <cyassl/ctaocrypt/settings.h>
381#else
382#include <cyassl/options.h>
383#endif
384#include <cyassl/openssl/ssl.h>
385#include <cyassl/error-ssl.h>
386
387#else
388#ifdef _WIN32
389/*
390 * Include user-controlled settings for windows from
391 * <wolfssl-root>/IDE/WIN/user_settings.h
392 */
393#include <IDE/WIN/user_settings.h>
394#include <wolfssl/wolfcrypt/settings.h>
395#else
396#include <wolfssl/options.h>
397#endif
398#include <wolfssl/openssl/ssl.h>
399#include <wolfssl/error-ssl.h>
400#endif /* not USE_OLD_CYASSL */
401#else
402#if defined(LWS_WITH_MBEDTLS)
403#if defined(LWS_PLAT_FREERTOS)
404/* this filepath is passed to us but without quotes or <> */
405#if !defined(LWS_AMAZON_RTOS)
406/* AMAZON RTOS has its own setting via MTK_MBEDTLS_CONFIG_FILE */
407#undef MBEDTLS_CONFIG_FILE
408#define MBEDTLS_CONFIG_FILE <mbedtls/esp_config.h>
409#endif
410#endif
411
412#if defined(LWS_WITH_TLS)
413#include <mbedtls/ssl.h>
414#include <mbedtls/entropy.h>
415#include <mbedtls/ctr_drbg.h>
416#include <mbedtls/version.h>
417
418#if !defined(MBEDTLS_PRIVATE)
419#define MBEDTLS_PRIVATE(_q) _q
420#endif
421
422#if (MBEDTLS_VERSION_MAJOR == 3) && (MBEDTLS_VERSION_MINOR == 0)
423#define MBEDTLS_PRIVATE_V30_ONLY(_q) MBEDTLS_PRIVATE(_q)
424#else
425#define MBEDTLS_PRIVATE_V30_ONLY(_q) _q
426#endif
427
428#endif
429#elif defined(LWS_WITH_GNUTLS)
430#include <gnutls/gnutls.h>
431#include <gnutls/crypto.h>
432#include <gnutls/abstract.h>
433#include <gnutls/x509.h>
434#include <netinet/in.h>
435#include <unistd.h>
436typedef struct gnutls_session_int SSL;
437typedef struct lws_tls_gnutls_ctx SSL_CTX;
438typedef void BIO;
439typedef struct gnutls_x509_crt_int X509;
440#else
441#include <openssl/ssl.h>
442#if !defined(LWS_WITH_MBEDTLS)
443#include <openssl/err.h>
444#endif
445#endif
446#endif /* not USE_WOLFSSL */
447#endif /* not SCHANNEL */
448#endif
449
450/*
451 * Helpers for pthread mutex in user code... if lws is built for
452 * multiple service threads, these resolve to pthread mutex
453 * operations. In the case LWS_MAX_SMP is 1 (the default), they
454 * are all NOPs and no pthread type or api is referenced.
455 */
456
457#if LWS_MAX_SMP > 1
458
459#include <pthread.h>
460
461#define lws_pthread_mutex(name) pthread_mutex_t name;
462
463static LWS_INLINE void
464lws_pthread_mutex_init(pthread_mutex_t *lock)
465{
466 pthread_mutex_init(lock, NULL);
467}
468
469static LWS_INLINE void
470lws_pthread_mutex_destroy(pthread_mutex_t *lock)
471{
472 pthread_mutex_destroy(lock);
473}
474
475static LWS_INLINE void
476lws_pthread_mutex_lock(pthread_mutex_t *lock)
477{
478 pthread_mutex_lock(lock);
479}
480
481static LWS_INLINE void
482lws_pthread_mutex_unlock(pthread_mutex_t *lock)
483{
484 pthread_mutex_unlock(lock);
485}
486
487#else
488#define lws_pthread_mutex(name)
489#define lws_pthread_mutex_init(_a)
490#define lws_pthread_mutex_destroy(_a)
491#define lws_pthread_mutex_lock(_a)
492#define lws_pthread_mutex_unlock(_a)
493#endif
494
495
496#define CONTEXT_PORT_NO_LISTEN -1
497#define CONTEXT_PORT_NO_LISTEN_SERVER -2
498
500
501
502#include <stddef.h>
503
504#ifndef lws_container_of
505#define lws_container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M)))
506#endif
507#define LWS_ALIGN_TO(x, bou) x += ((bou) - ((x) % (bou))) % (bou)
508
509struct lws;
510
511/* api change list for user code to test against */
512
513#define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG
514
515/* the struct lws_protocols has the id field present */
516#define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD
517
518/* you can call lws_get_peer_write_allowance */
519#define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE
520
521/* extra parameter introduced in 917f43ab821 */
522#define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_LEN
523
524/* File operations stuff exists */
525#define LWS_FEATURE_FOPS
526
527/* Mounts have extra no_cache member */
528#define LWS_FEATURE_MOUNT_NO_CACHE
529
530
531#if defined(_WIN32)
532#if !defined(LWS_WIN32_HANDLE_TYPES)
533typedef SOCKET lws_sockfd_type;
534#if defined(__MINGW32__)
535typedef int lws_filefd_type;
536#else
537typedef HANDLE lws_filefd_type;
538#endif
539#endif
540
541
542#define lws_pollfd pollfd
543#define LWS_POLLHUP (POLLHUP)
544#define LWS_POLLIN (POLLRDNORM | POLLRDBAND)
545#define LWS_POLLOUT (POLLWRNORM)
546
547#else
548
549
550#if defined(LWS_PLAT_FREERTOS)
552#else
553typedef int lws_sockfd_type;
554typedef int lws_filefd_type;
555#endif
556
557#if defined(LWS_PLAT_OPTEE)
558#include <time.h>
559struct timeval {
560 time_t tv_sec;
561 unsigned int tv_usec;
562};
563#if defined(LWS_WITH_NETWORK)
564// #include <poll.h>
565#define lws_pollfd pollfd
566
567struct timezone;
568
569int gettimeofday(struct timeval *tv, struct timezone *tz);
570
571 /* Internet address. */
572 struct in_addr {
573 uint32_t s_addr; /* address in network byte order */
574 };
575
576typedef unsigned short sa_family_t;
577typedef unsigned short in_port_t;
578typedef uint32_t socklen_t;
579
581
582#if !defined(TEE_SE_READER_NAME_MAX)
583 struct addrinfo {
584 int ai_flags;
585 int ai_family;
586 int ai_socktype;
587 int ai_protocol;
588 socklen_t ai_addrlen;
589 struct sockaddr *ai_addr;
590 char *ai_canonname;
591 struct addrinfo *ai_next;
592 };
593#endif
594
595ssize_t recv(int sockfd, void *buf, size_t len, int flags);
596ssize_t send(int sockfd, const void *buf, size_t len, int flags);
597ssize_t read(int fd, void *buf, size_t count);
598int getsockopt(int sockfd, int level, int optname,
599 void *optval, socklen_t *optlen);
600 int setsockopt(int sockfd, int level, int optname,
601 const void *optval, socklen_t optlen);
602int connect(int sockfd, const struct sockaddr *addr,
603 socklen_t addrlen);
604
605extern int errno;
606
607uint16_t ntohs(uint16_t netshort);
608uint16_t htons(uint16_t hostshort);
609
610int bind(int sockfd, const struct sockaddr *addr,
611 socklen_t addrlen);
612
613
614#define MSG_NOSIGNAL 0x4000
615#define EAGAIN 11
616#define EINTR 4
617#define EWOULDBLOCK EAGAIN
618#define EADDRINUSE 98
619#define INADDR_ANY 0
620#define AF_INET 2
621#define SHUT_WR 1
622#define AF_UNSPEC 0
623#define PF_UNSPEC 0
624#define SOCK_STREAM 1
625#define SOCK_DGRAM 2
626# define AI_PASSIVE 0x0001
627#define IPPROTO_UDP 17
628#define SOL_SOCKET 1
629#define SO_SNDBUF 7
630#define EISCONN 106
631#define EALREADY 114
632#define EINPROGRESS 115
633int shutdown(int sockfd, int how);
634int close(int fd);
635int atoi(const char *nptr);
636long long atoll(const char *nptr);
637
638int socket(int domain, int type, int protocol);
639 int getaddrinfo(const char *node, const char *service,
640 const struct addrinfo *hints,
641 struct addrinfo **res);
642
643 void freeaddrinfo(struct addrinfo *res);
644
645#if !defined(TEE_SE_READER_NAME_MAX)
646struct lws_pollfd
647{
648 int fd; /* File descriptor to poll. */
649 short int events; /* Types of events poller cares about. */
650 short int revents; /* Types of events that actually occurred. */
651};
652#endif
653
654int poll(struct pollfd *fds, int nfds, int timeout);
655
656#define LWS_POLLHUP (0x18)
657#define LWS_POLLIN (1)
658#define LWS_POLLOUT (4)
659#else
660struct lws_pollfd;
661struct sockaddr_in;
662#endif
663#else
664#define lws_pollfd pollfd
665#define LWS_POLLHUP (POLLHUP | POLLERR)
666#define LWS_POLLIN (POLLIN)
667#define LWS_POLLOUT (POLLOUT)
668#endif
669#endif
670
671
672#if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
673/* ... */
674#define ssize_t SSIZE_T
675#endif
676
677#if defined(WIN32) && defined(LWS_HAVE__STAT32I64)
678#include <sys/types.h>
679#include <sys/stat.h>
680#endif
681
682#if defined(LWS_HAVE_STDINT_H)
683#include <stdint.h>
684#else
685#if defined(WIN32) || defined(_WIN32)
686/* !!! >:-[ */
687typedef __int64 int64_t;
688typedef unsigned __int64 uint64_t;
689typedef __int32 int32_t;
690typedef unsigned __int32 uint32_t;
691typedef __int16 int16_t;
692typedef unsigned __int16 uint16_t;
693typedef unsigned __int8 uint8_t;
694#else
695typedef unsigned int uint32_t;
696typedef unsigned short uint16_t;
697typedef unsigned char uint8_t;
698#endif
699#endif
700
701typedef int64_t lws_usec_t;
702typedef unsigned long long lws_filepos_t;
703typedef long long lws_fileofs_t;
705
706#define lws_concat_temp(_t, _l) (_t + sizeof(_t) - _l)
707#define lws_concat_used(_t, _l) (sizeof(_t) - _l)
708
716
717#if !defined(LWS_SIZEOFPTR)
718#define LWS_SIZEOFPTR ((int)sizeof (void *))
719#endif
720
721#if defined(__x86_64__)
722#define _LWS_PAD_SIZE 16 /* Intel recommended for best performance */
723#else
724#define _LWS_PAD_SIZE LWS_SIZEOFPTR /* Size of a pointer on the target arch */
725#endif
726#define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? \
727 ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n))
728/* last 2 is for lws-meta */
729#define LWS_PRE _LWS_PAD(4 + 10 + 2)
730/* used prior to 1.7 and retained for backward compatibility */
731#define LWS_SEND_BUFFER_PRE_PADDING LWS_PRE
732#define LWS_SEND_BUFFER_POST_PADDING 0
733
734
735
736struct lws_extension; /* needed even with ws exts disabled for create context */
737struct lws_token_limits;
738struct lws_protocols;
739struct lws_context;
740struct lws_tokens;
741struct lws_vhost;
742struct lws;
743
744/* Generic stateful operation return codes */
745
746typedef enum {
750 LWS_SRET_FATAL = (1 << 18),
754 LWS_SRET_YIELD = (1 << 22), /* return to the event loop and continue */
756
757typedef struct lws_fixed3232 {
758 int32_t whole; /* signed 32-bit int */
759 int32_t frac; /* signed frac proportion from 0 to (100M - 1) */
761
762#define LWS_FX_FRACTION_MSD 100000000
763#define lws_neg(a) (a->whole < 0 || a->frac < 0)
764#define lws_fx_set(a, x, y) { a.whole = x; a.frac = x < 0 ? -y : y; }
765#define lws_fix64(a) (((int64_t)a->whole << 32) + \
766 (((1ll << 32) * (a->frac < 0 ? -a->frac : a->frac)) / LWS_FX_FRACTION_MSD))
767#define lws_fix64_abs(a) \
768 ((((int64_t)(a->whole < 0 ? (-a->whole) : a->whole) << 32) + \
769 (((1ll << 32) * (a->frac < 0 ? -a->frac : a->frac)) / LWS_FX_FRACTION_MSD)))
770
771#define lws_fix3232(a, a64) { a->whole = (int32_t)(a64 >> 32); \
772 a->frac = (int32_t)((100000000 * (a64 & 0xffffffff)) >> 32); }
773
775lws_fx_add(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b);
776
778lws_fx_sub(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b);
779
781lws_fx_mul(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b);
782
784lws_fx_div(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b);
785
788
790lws_fx_comp(const lws_fx_t *a, const lws_fx_t *b);
791
794
797
798LWS_VISIBLE LWS_EXTERN const char *
799lws_fx_string(const lws_fx_t *a, char *buf, size_t size);
800
803
808#if defined(LWS_WITH_SYS_SMD)
810#endif
814#if defined(LWS_WITH_TRANSPORT_SEQUENCER)
816#endif
817#if defined(LWS_WITH_NETWORK)
821#endif
822
827
828#if defined(LWS_WITH_NETWORK)
833#endif
834
836#if defined(LWS_WITH_JOSE)
838#endif
839
841
842#if defined(LWS_WITH_NETWORK)
843#if defined(LWS_WITH_CONMON)
845#endif
846
847#if defined(LWS_ROLE_MQTT)
849#endif
852#if defined(LWS_ROLE_H3)
854#endif
857#endif
861#if defined(LWS_WITH_NETWORK)
865#endif
867#if defined(LWS_WITH_MNEMONIC)
869#endif
874#if defined(LWS_WITH_NETWORK)
876#endif
877#if defined(LWS_WITH_FILE_OPS)
879#endif
881
898
900#if defined(LWS_WITH_AUTHORITATIVE_DNS)
902#endif
903
904#if defined(LWS_WITH_TLS)
905
908
909#if defined(LWS_WITH_MBEDTLS)
910#include <mbedtls/md5.h>
911#include <mbedtls/sha1.h>
912#include <mbedtls/sha256.h>
913#include <mbedtls/sha512.h>
914#endif
915#if defined(LWS_WITH_BEARSSL)
916#include <bearssl.h>
917#endif
918
924
930
931#endif
932
933#if defined(LWS_WITH_NETWORK)
935#endif
938#if defined(LWS_ESP_PLATFORM)
940#endif
959#if defined(LWS_WITH_DLTS)
961#endif
962#if defined(LWS_WITH_NETWORK)
967#if defined(LWS_WITH_TRANSCODE)
969#endif
970#if defined(LWS_WITH_V4L2)
972#endif
973#if defined(LWS_WITH_ALSA)
976#endif
977#endif
978
982
983#if defined(LWS_WITH_DIR)
985#endif
986
987#ifdef __cplusplus
988}
989#endif
990
991#endif
#define lws_pthread_mutex_lock(_a)
uint32_t lws_fop_flags_t
unsigned short uint16_t
#define lws_pollfd
unsigned int uint32_t
#define lws_pthread_mutex_init(_a)
long long lws_fileofs_t
#define LWS_INLINE
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)
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
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