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