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)
344#include <wincrypt.h>
345typedef struct lws_tls_schannel_conn SSL;
346typedef struct lws_tls_schannel_ctx SSL_CTX;
347typedef struct lws_tls_schannel_bio BIO;
348typedef struct lws_tls_schannel_x509 X509;
349
350/*
351 * These are needed for lws-gen* and other headers that assume OpenSSL types
352 * when LWS_WITH_TLS is defined. SChannel implementation of these APIs
353 * will need to map these to Windows CryptoAPI/CNG types internally,
354 * or we can just treat them as opaque handles here.
355 */
356typedef void EVP_PKEY_CTX;
357typedef void EVP_MD;
358typedef void EVP_MD_CTX;
359typedef void HMAC_CTX;
360typedef void EVP_CIPHER_CTX;
361typedef void EVP_CIPHER;
362typedef void ENGINE;
363typedef void RSA;
364typedef void BIGNUM;
365typedef void EC_KEY;
366typedef void EC_POINT;
367typedef void EC_GROUP;
368typedef void X509_STORE_CTX;
369typedef void X509_VERIFY_PARAM;
370
371#else
372
373#ifdef USE_WOLFSSL
374#ifdef USE_OLD_CYASSL
375#ifdef _WIN32
376/*
377 * Include user-controlled settings for windows from
378 * <wolfssl-root>/IDE/WIN/user_settings.h
379 */
380#include <IDE/WIN/user_settings.h>
381#include <cyassl/ctaocrypt/settings.h>
382#else
383#include <cyassl/options.h>
384#endif
385#include <cyassl/openssl/ssl.h>
386#include <cyassl/error-ssl.h>
387
388#else
389#ifdef _WIN32
390/*
391 * Include user-controlled settings for windows from
392 * <wolfssl-root>/IDE/WIN/user_settings.h
393 */
394#include <IDE/WIN/user_settings.h>
395#include <wolfssl/wolfcrypt/settings.h>
396#else
397#include <wolfssl/options.h>
398#endif
399#include <wolfssl/openssl/ssl.h>
400#include <wolfssl/error-ssl.h>
401#endif /* not USE_OLD_CYASSL */
402#else
403#if defined(LWS_WITH_MBEDTLS)
404#if defined(LWS_PLAT_FREERTOS)
405/* this filepath is passed to us but without quotes or <> */
406#if !defined(LWS_AMAZON_RTOS)
407/* AMAZON RTOS has its own setting via MTK_MBEDTLS_CONFIG_FILE */
408#undef MBEDTLS_CONFIG_FILE
409#define MBEDTLS_CONFIG_FILE <mbedtls/esp_config.h>
410#endif
411#endif
412
413#if defined(LWS_WITH_TLS)
414#include <mbedtls/ssl.h>
415#include <mbedtls/entropy.h>
416#include <mbedtls/ctr_drbg.h>
417#include <mbedtls/version.h>
418
419#if !defined(MBEDTLS_PRIVATE)
420#define MBEDTLS_PRIVATE(_q) _q
421#endif
422
423#if (MBEDTLS_VERSION_MAJOR == 3) && (MBEDTLS_VERSION_MINOR == 0)
424#define MBEDTLS_PRIVATE_V30_ONLY(_q) MBEDTLS_PRIVATE(_q)
425#else
426#define MBEDTLS_PRIVATE_V30_ONLY(_q) _q
427#endif
428
429#endif
430#elif defined(LWS_WITH_GNUTLS)
431#include <gnutls/gnutls.h>
432#include <gnutls/crypto.h>
433#include <gnutls/abstract.h>
434#include <gnutls/x509.h>
435#include <netinet/in.h>
436#include <unistd.h>
437typedef struct gnutls_session_int SSL;
438typedef struct lws_tls_gnutls_ctx SSL_CTX;
439typedef void BIO;
440typedef struct gnutls_x509_crt_int X509;
441#else
442#include <openssl/ssl.h>
443#if !defined(LWS_WITH_MBEDTLS)
444#include <openssl/err.h>
445#endif
446#endif
447#endif /* not USE_WOLFSSL */
448#endif /* not SCHANNEL */
449#endif
450
451/*
452 * Helpers for pthread mutex in user code... if lws is built for
453 * multiple service threads, these resolve to pthread mutex
454 * operations. In the case LWS_MAX_SMP is 1 (the default), they
455 * are all NOPs and no pthread type or api is referenced.
456 */
457
458#if LWS_MAX_SMP > 1
459
460#include <pthread.h>
461
462#define lws_pthread_mutex(name) pthread_mutex_t name;
463
464static LWS_INLINE void
465lws_pthread_mutex_init(pthread_mutex_t *lock)
466{
467 pthread_mutex_init(lock, NULL);
468}
469
470static LWS_INLINE void
471lws_pthread_mutex_destroy(pthread_mutex_t *lock)
472{
473 pthread_mutex_destroy(lock);
474}
475
476static LWS_INLINE void
477lws_pthread_mutex_lock(pthread_mutex_t *lock)
478{
479 pthread_mutex_lock(lock);
480}
481
482static LWS_INLINE void
483lws_pthread_mutex_unlock(pthread_mutex_t *lock)
484{
485 pthread_mutex_unlock(lock);
486}
487
488#else
489#define lws_pthread_mutex(name)
490#define lws_pthread_mutex_init(_a)
491#define lws_pthread_mutex_destroy(_a)
492#define lws_pthread_mutex_lock(_a)
493#define lws_pthread_mutex_unlock(_a)
494#endif
495
496
497#define CONTEXT_PORT_NO_LISTEN -1
498#define CONTEXT_PORT_NO_LISTEN_SERVER -2
499
501
502
503#include <stddef.h>
504
505#ifndef lws_container_of
506#define lws_container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M)))
507#endif
508#define LWS_ALIGN_TO(x, bou) x += ((bou) - ((x) % (bou))) % (bou)
509
510struct lws;
511
512/* api change list for user code to test against */
513
514#define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG
515
516/* the struct lws_protocols has the id field present */
517#define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD
518
519/* you can call lws_get_peer_write_allowance */
520#define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE
521
522/* extra parameter introduced in 917f43ab821 */
523#define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_LEN
524
525/* File operations stuff exists */
526#define LWS_FEATURE_FOPS
527
528/* Mounts have extra no_cache member */
529#define LWS_FEATURE_MOUNT_NO_CACHE
530
531
532#if defined(_WIN32)
533#if !defined(LWS_WIN32_HANDLE_TYPES)
534typedef SOCKET lws_sockfd_type;
535#if defined(__MINGW32__)
536typedef int lws_filefd_type;
537#else
538typedef HANDLE lws_filefd_type;
539#endif
540#endif
541
542
543#define lws_pollfd pollfd
544#define LWS_POLLHUP (POLLHUP)
545#define LWS_POLLIN (POLLRDNORM | POLLRDBAND)
546#define LWS_POLLOUT (POLLWRNORM)
547
548#else
549
550
551#if defined(LWS_PLAT_FREERTOS)
553#else
554typedef int lws_sockfd_type;
555typedef int lws_filefd_type;
556#endif
557
558#if defined(LWS_PLAT_OPTEE)
559#include <time.h>
560struct timeval {
561 time_t tv_sec;
562 unsigned int tv_usec;
563};
564#if defined(LWS_WITH_NETWORK)
565// #include <poll.h>
566#define lws_pollfd pollfd
567
568struct timezone;
569
570int gettimeofday(struct timeval *tv, struct timezone *tz);
571
572 /* Internet address. */
573 struct in_addr {
574 uint32_t s_addr; /* address in network byte order */
575 };
576
577typedef unsigned short sa_family_t;
578typedef unsigned short in_port_t;
579typedef uint32_t socklen_t;
580
582
583#if !defined(TEE_SE_READER_NAME_MAX)
584 struct addrinfo {
585 int ai_flags;
586 int ai_family;
587 int ai_socktype;
588 int ai_protocol;
589 socklen_t ai_addrlen;
590 struct sockaddr *ai_addr;
591 char *ai_canonname;
592 struct addrinfo *ai_next;
593 };
594#endif
595
596ssize_t recv(int sockfd, void *buf, size_t len, int flags);
597ssize_t send(int sockfd, const void *buf, size_t len, int flags);
598ssize_t read(int fd, void *buf, size_t count);
599int getsockopt(int sockfd, int level, int optname,
600 void *optval, socklen_t *optlen);
601 int setsockopt(int sockfd, int level, int optname,
602 const void *optval, socklen_t optlen);
603int connect(int sockfd, const struct sockaddr *addr,
604 socklen_t addrlen);
605
606extern int errno;
607
608uint16_t ntohs(uint16_t netshort);
609uint16_t htons(uint16_t hostshort);
610
611int bind(int sockfd, const struct sockaddr *addr,
612 socklen_t addrlen);
613
614
615#define MSG_NOSIGNAL 0x4000
616#define EAGAIN 11
617#define EINTR 4
618#define EWOULDBLOCK EAGAIN
619#define EADDRINUSE 98
620#define INADDR_ANY 0
621#define AF_INET 2
622#define SHUT_WR 1
623#define AF_UNSPEC 0
624#define PF_UNSPEC 0
625#define SOCK_STREAM 1
626#define SOCK_DGRAM 2
627# define AI_PASSIVE 0x0001
628#define IPPROTO_UDP 17
629#define SOL_SOCKET 1
630#define SO_SNDBUF 7
631#define EISCONN 106
632#define EALREADY 114
633#define EINPROGRESS 115
634int shutdown(int sockfd, int how);
635int close(int fd);
636int atoi(const char *nptr);
637long long atoll(const char *nptr);
638
639int socket(int domain, int type, int protocol);
640 int getaddrinfo(const char *node, const char *service,
641 const struct addrinfo *hints,
642 struct addrinfo **res);
643
644 void freeaddrinfo(struct addrinfo *res);
645
646#if !defined(TEE_SE_READER_NAME_MAX)
647struct lws_pollfd
648{
649 int fd; /* File descriptor to poll. */
650 short int events; /* Types of events poller cares about. */
651 short int revents; /* Types of events that actually occurred. */
652};
653#endif
654
655int poll(struct pollfd *fds, int nfds, int timeout);
656
657#define LWS_POLLHUP (0x18)
658#define LWS_POLLIN (1)
659#define LWS_POLLOUT (4)
660#else
661struct lws_pollfd;
662struct sockaddr_in;
663#endif
664#else
665#define lws_pollfd pollfd
666#define LWS_POLLHUP (POLLHUP | POLLERR)
667#define LWS_POLLIN (POLLIN)
668#define LWS_POLLOUT (POLLOUT)
669#endif
670#endif
671
672
673#if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
674/* ... */
675#define ssize_t SSIZE_T
676#endif
677
678#if defined(WIN32) && defined(LWS_HAVE__STAT32I64)
679#include <sys/types.h>
680#include <sys/stat.h>
681#endif
682
683#if defined(LWS_HAVE_STDINT_H)
684#include <stdint.h>
685#else
686#if defined(WIN32) || defined(_WIN32)
687/* !!! >:-[ */
688typedef __int64 int64_t;
689typedef unsigned __int64 uint64_t;
690typedef __int32 int32_t;
691typedef unsigned __int32 uint32_t;
692typedef __int16 int16_t;
693typedef unsigned __int16 uint16_t;
694typedef unsigned __int8 uint8_t;
695#else
696typedef unsigned int uint32_t;
697typedef unsigned short uint16_t;
698typedef unsigned char uint8_t;
699#endif
700#endif
701
702typedef int64_t lws_usec_t;
703typedef unsigned long long lws_filepos_t;
704typedef long long lws_fileofs_t;
706
707#define lws_concat_temp(_t, _l) (_t + sizeof(_t) - _l)
708#define lws_concat_used(_t, _l) (sizeof(_t) - _l)
709
717
718#if !defined(LWS_SIZEOFPTR)
719#define LWS_SIZEOFPTR ((int)sizeof (void *))
720#endif
721
722#if defined(__x86_64__)
723#define _LWS_PAD_SIZE 16 /* Intel recommended for best performance */
724#else
725#define _LWS_PAD_SIZE LWS_SIZEOFPTR /* Size of a pointer on the target arch */
726#endif
727#define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? \
728 ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n))
729/* last 2 is for lws-meta */
730#define LWS_PRE _LWS_PAD(4 + 10 + 2)
731/* used prior to 1.7 and retained for backward compatibility */
732#define LWS_SEND_BUFFER_PRE_PADDING LWS_PRE
733#define LWS_SEND_BUFFER_POST_PADDING 0
734
735
736
737struct lws_extension; /* needed even with ws exts disabled for create context */
738struct lws_token_limits;
739struct lws_protocols;
740struct lws_context;
741struct lws_tokens;
742struct lws_vhost;
743struct lws;
744
745/* Generic stateful operation return codes */
746
747typedef enum {
751 LWS_SRET_FATAL = (1 << 18),
755 LWS_SRET_YIELD = (1 << 22), /* return to the event loop and continue */
757
758typedef struct lws_fixed3232 {
759 int32_t whole; /* signed 32-bit int */
760 int32_t frac; /* signed frac proportion from 0 to (100M - 1) */
762
763#define LWS_FX_FRACTION_MSD 100000000
764#define lws_neg(a) (a->whole < 0 || a->frac < 0)
765#define lws_fx_set(a, x, y) { a.whole = x; a.frac = x < 0 ? -y : y; }
766#define lws_fix64(a) (((int64_t)a->whole << 32) + \
767 (((1ll << 32) * (a->frac < 0 ? -a->frac : a->frac)) / LWS_FX_FRACTION_MSD))
768#define lws_fix64_abs(a) \
769 ((((int64_t)(a->whole < 0 ? (-a->whole) : a->whole) << 32) + \
770 (((1ll << 32) * (a->frac < 0 ? -a->frac : a->frac)) / LWS_FX_FRACTION_MSD)))
771
772#define lws_fix3232(a, a64) { a->whole = (int32_t)(a64 >> 32); \
773 a->frac = (int32_t)((100000000 * (a64 & 0xffffffff)) >> 32); }
774
776lws_fx_add(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b);
777
779lws_fx_sub(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b);
780
782lws_fx_mul(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b);
783
785lws_fx_div(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b);
786
789
791lws_fx_comp(const lws_fx_t *a, const lws_fx_t *b);
792
795
798
799LWS_VISIBLE LWS_EXTERN const char *
800lws_fx_string(const lws_fx_t *a, char *buf, size_t size);
801
804
809#if defined(LWS_WITH_SYS_SMD)
811#endif
815#if defined(LWS_WITH_TRANSPORT_SEQUENCER)
817#endif
818#if defined(LWS_WITH_NETWORK)
822#endif
823
828
829#if defined(LWS_WITH_NETWORK)
834#endif
835
837#if defined(LWS_WITH_JOSE)
839#endif
840
842
843#if defined(LWS_WITH_NETWORK)
844#if defined(LWS_WITH_CONMON)
846#endif
847
848#if defined(LWS_ROLE_MQTT)
850#endif
854#endif
858#if defined(LWS_WITH_NETWORK)
862#endif
864#if defined(LWS_WITH_MNEMONIC)
866#endif
871#if defined(LWS_WITH_NETWORK)
873#endif
874#if defined(LWS_WITH_FILE_OPS)
876#endif
878
894
896#if defined(LWS_WITH_AUTHORITATIVE_DNS)
898#endif
899
900#if defined(LWS_WITH_TLS)
901
903
904#if defined(LWS_WITH_MBEDTLS)
905#include <mbedtls/md5.h>
906#include <mbedtls/sha1.h>
907#include <mbedtls/sha256.h>
908#include <mbedtls/sha512.h>
909#endif
910
915
921
922#endif
923
924#if defined(LWS_WITH_NETWORK)
926#endif
929#if defined(LWS_ESP_PLATFORM)
931#endif
948#if defined(LWS_WITH_DLTS)
950#endif
951#if defined(LWS_WITH_NETWORK)
956#if defined(LWS_WITH_TRANSCODE)
958#endif
959#if defined(LWS_WITH_V4L2)
961#endif
962#if defined(LWS_WITH_ALSA)
965#endif
966#endif
967
971
972#if defined(LWS_WITH_DIR)
974#endif
975
976#ifdef __cplusplus
977}
978#endif
979
980#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