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) ((size_t)(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#if !defined(LWS_HAVE_MBEDTLS_V4)
415#include <mbedtls/entropy.h>
416#include <mbedtls/ctr_drbg.h>
417#endif
418#include <mbedtls/version.h>
419
420#if !defined(MBEDTLS_PRIVATE)
421#define MBEDTLS_PRIVATE(_q) _q
422#endif
423
424#if (MBEDTLS_VERSION_MAJOR == 3) && (MBEDTLS_VERSION_MINOR == 0)
425#define MBEDTLS_PRIVATE_V30_ONLY(_q) MBEDTLS_PRIVATE(_q)
426#else
427#define MBEDTLS_PRIVATE_V30_ONLY(_q) _q
428#endif
429
430#endif
431#elif defined(LWS_WITH_GNUTLS)
432#include <gnutls/gnutls.h>
433#include <gnutls/crypto.h>
434#include <gnutls/abstract.h>
435#include <gnutls/x509.h>
436#include <netinet/in.h>
437#include <unistd.h>
438typedef struct gnutls_session_int SSL;
439typedef struct lws_tls_gnutls_ctx SSL_CTX;
440typedef void BIO;
441typedef struct gnutls_x509_crt_int X509;
442#elif defined(LWS_WITH_OPENHITLS)
443#include <hitls_type.h>
444#include <hitls_cert_type.h>
445#include <hitls_pki_cert.h>
446typedef HITLS_Ctx SSL;
447typedef HITLS_Config SSL_CTX;
448typedef void BIO;
449typedef HITLS_X509_Cert X509;
450typedef HITLS_CERT_StoreCtx X509_STORE_CTX;
451#else
452#include <openssl/ssl.h>
453#if !defined(LWS_WITH_MBEDTLS)
454#include <openssl/err.h>
455#endif
456#endif
457#endif /* not USE_WOLFSSL */
458#endif /* not SCHANNEL */
459#endif
460
461/*
462 * Helpers for pthread mutex in user code... if lws is built for
463 * multiple service threads, these resolve to pthread mutex
464 * operations. In the case LWS_MAX_SMP is 1 (the default), they
465 * are all NOPs and no pthread type or api is referenced.
466 */
467
468#if LWS_MAX_SMP > 1
469
470#include <pthread.h>
471
472#define lws_pthread_mutex(name) pthread_mutex_t name;
473
474static LWS_INLINE void
475lws_pthread_mutex_init(pthread_mutex_t *lock)
476{
477 pthread_mutex_init(lock, NULL);
478}
479
480static LWS_INLINE void
481lws_pthread_mutex_destroy(pthread_mutex_t *lock)
482{
483 pthread_mutex_destroy(lock);
484}
485
486static LWS_INLINE void
487lws_pthread_mutex_lock(pthread_mutex_t *lock)
488{
489 pthread_mutex_lock(lock);
490}
491
492static LWS_INLINE void
493lws_pthread_mutex_unlock(pthread_mutex_t *lock)
494{
495 pthread_mutex_unlock(lock);
496}
497
498#else
499#define lws_pthread_mutex(name)
500#define lws_pthread_mutex_init(_a)
501#define lws_pthread_mutex_destroy(_a)
502#define lws_pthread_mutex_lock(_a)
503#define lws_pthread_mutex_unlock(_a)
504#endif
505
506
507#define CONTEXT_PORT_NO_LISTEN -1
508#define CONTEXT_PORT_NO_LISTEN_SERVER -2
509
511
512
513#include <stddef.h>
514
515#ifndef lws_container_of
516#define lws_container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M)))
517#endif
518#define LWS_ALIGN_TO(x, bou) x += ((bou) - ((x) % (bou))) % (bou)
519
520struct lws;
521
522/* api change list for user code to test against */
523
524#define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG
525
526/* the struct lws_protocols has the id field present */
527#define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD
528
529/* you can call lws_get_peer_write_allowance */
530#define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE
531
532/* extra parameter introduced in 917f43ab821 */
533#define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_LEN
534
535/* File operations stuff exists */
536#define LWS_FEATURE_FOPS
537
538/* Mounts have extra no_cache member */
539#define LWS_FEATURE_MOUNT_NO_CACHE
540
541
542#if defined(_WIN32)
543#if !defined(LWS_WIN32_HANDLE_TYPES)
544typedef SOCKET lws_sockfd_type;
545#if defined(__MINGW32__)
546typedef int lws_filefd_type;
547#else
548typedef HANDLE lws_filefd_type;
549#endif
550#endif
551
552
553#define lws_pollfd pollfd
554#define LWS_POLLHUP (POLLHUP)
555#define LWS_POLLIN (POLLRDNORM | POLLRDBAND)
556#define LWS_POLLOUT (POLLWRNORM)
557
558#else
559
560
561#if defined(LWS_PLAT_FREERTOS)
563#else
564typedef int lws_sockfd_type;
565typedef int lws_filefd_type;
566#endif
567
568#if defined(LWS_PLAT_OPTEE)
569#include <time.h>
570struct timeval {
571 time_t tv_sec;
572 unsigned int tv_usec;
573};
574#if defined(LWS_WITH_NETWORK)
575// #include <poll.h>
576#define lws_pollfd pollfd
577
578struct timezone;
579
580int gettimeofday(struct timeval *tv, struct timezone *tz);
581
582 /* Internet address. */
583 struct in_addr {
584 uint32_t s_addr; /* address in network byte order */
585 };
586
587typedef unsigned short sa_family_t;
588typedef unsigned short in_port_t;
589typedef uint32_t socklen_t;
590
592
593#if !defined(TEE_SE_READER_NAME_MAX)
594 struct addrinfo {
595 int ai_flags;
596 int ai_family;
597 int ai_socktype;
598 int ai_protocol;
599 socklen_t ai_addrlen;
600 struct sockaddr *ai_addr;
601 char *ai_canonname;
602 struct addrinfo *ai_next;
603 };
604#endif
605
606ssize_t recv(int sockfd, void *buf, size_t len, int flags);
607ssize_t send(int sockfd, const void *buf, size_t len, int flags);
608ssize_t read(int fd, void *buf, size_t count);
609int getsockopt(int sockfd, int level, int optname,
610 void *optval, socklen_t *optlen);
611 int setsockopt(int sockfd, int level, int optname,
612 const void *optval, socklen_t optlen);
613int connect(int sockfd, const struct sockaddr *addr,
614 socklen_t addrlen);
615
616#if defined(ESP_PLATFORM)
617/* IDF v6 (picolibc) makes errno thread-local; a plain "extern int errno" makes
618 * lws objects reference it non-TLS and fail to link ("TLS definition ...
619 * mismatches non-TLS reference"). Use the platform's real errno. */
620#include <errno.h>
621#else
622extern int errno;
623#endif
624
625uint16_t ntohs(uint16_t netshort);
626uint16_t htons(uint16_t hostshort);
627
628int bind(int sockfd, const struct sockaddr *addr,
629 socklen_t addrlen);
630
631
632#define MSG_NOSIGNAL 0x4000
633#define EAGAIN 11
634#define EINTR 4
635#define EWOULDBLOCK EAGAIN
636#define EADDRINUSE 98
637#define INADDR_ANY 0
638#define AF_INET 2
639#define SHUT_WR 1
640#define AF_UNSPEC 0
641#define PF_UNSPEC 0
642#define SOCK_STREAM 1
643#define SOCK_DGRAM 2
644# define AI_PASSIVE 0x0001
645#define IPPROTO_UDP 17
646#define SOL_SOCKET 1
647#define SO_SNDBUF 7
648#define EISCONN 106
649#define EALREADY 114
650#define EINPROGRESS 115
651int shutdown(int sockfd, int how);
652int close(int fd);
653int atoi(const char *nptr);
654long long atoll(const char *nptr);
655
656int socket(int domain, int type, int protocol);
657 int getaddrinfo(const char *node, const char *service,
658 const struct addrinfo *hints,
659 struct addrinfo **res);
660
661 void freeaddrinfo(struct addrinfo *res);
662
663#if !defined(TEE_SE_READER_NAME_MAX)
664struct lws_pollfd
665{
666 int fd; /* File descriptor to poll. */
667 short int events; /* Types of events poller cares about. */
668 short int revents; /* Types of events that actually occurred. */
669};
670#endif
671
672int poll(struct pollfd *fds, int nfds, int timeout);
673
674#define LWS_POLLHUP (0x18)
675#define LWS_POLLIN (1)
676#define LWS_POLLOUT (4)
677#else
678struct lws_pollfd;
679struct sockaddr_in;
680#endif
681#else
682#define lws_pollfd pollfd
683#define LWS_POLLHUP (POLLHUP | POLLERR)
684#define LWS_POLLIN (POLLIN)
685#define LWS_POLLOUT (POLLOUT)
686#endif
687#endif
688
689
690#if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
691/* ... */
692#define ssize_t SSIZE_T
693#endif
694
695#if defined(WIN32) && defined(LWS_HAVE__STAT32I64)
696#include <sys/types.h>
697#include <sys/stat.h>
698#endif
699
700#if defined(LWS_HAVE_STDINT_H)
701#include <stdint.h>
702#else
703#if defined(WIN32) || defined(_WIN32)
704/* !!! >:-[ */
705typedef __int64 int64_t;
706typedef unsigned __int64 uint64_t;
707typedef __int32 int32_t;
708typedef unsigned __int32 uint32_t;
709typedef __int16 int16_t;
710typedef unsigned __int16 uint16_t;
711typedef unsigned __int8 uint8_t;
712#else
713typedef unsigned int uint32_t;
714typedef unsigned short uint16_t;
715typedef unsigned char uint8_t;
716#endif
717#endif
718
719typedef int64_t lws_usec_t;
720typedef unsigned long long lws_filepos_t;
721typedef long long lws_fileofs_t;
723
724#define lws_concat_temp(_t, _l) (_t + sizeof(_t) - _l)
725#define lws_concat_used(_t, _l) (sizeof(_t) - _l)
726
734
735#if !defined(LWS_SIZEOFPTR)
736#define LWS_SIZEOFPTR ((int)sizeof (void *))
737#endif
738
739#if defined(__x86_64__)
740#define _LWS_PAD_SIZE 16 /* Intel recommended for best performance */
741#else
742#define _LWS_PAD_SIZE LWS_SIZEOFPTR /* Size of a pointer on the target arch */
743#endif
744#define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? \
745 ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n))
746/* last 2 is for lws-meta */
747#define LWS_PRE _LWS_PAD(4 + 10 + 2)
748/* used prior to 1.7 and retained for backward compatibility */
749#define LWS_SEND_BUFFER_PRE_PADDING LWS_PRE
750#define LWS_SEND_BUFFER_POST_PADDING 0
751
752
753
754struct lws_extension; /* needed even with ws exts disabled for create context */
755struct lws_token_limits;
756struct lws_protocols;
757struct lws_context;
758struct lws_tokens;
759struct lws_vhost;
760struct lws;
761
762/* Generic stateful operation return codes */
763
764typedef enum {
768 LWS_SRET_FATAL = (1 << 18),
772 LWS_SRET_YIELD = (1 << 22), /* return to the event loop and continue */
774
775typedef struct lws_fixed3232 {
776 int32_t whole; /* signed 32-bit int */
777 int32_t frac; /* signed frac proportion from 0 to (100M - 1) */
779
780#define LWS_FX_FRACTION_MSD 100000000
781#define lws_neg(a) (a->whole < 0 || a->frac < 0)
782#define lws_fx_set(a, x, y) { a.whole = x; a.frac = x < 0 ? -y : y; }
783#define lws_fix64(a) (((int64_t)a->whole << 32) + \
784 (((1ll << 32) * (a->frac < 0 ? -a->frac : a->frac)) / LWS_FX_FRACTION_MSD))
785#define lws_fix64_abs(a) \
786 ((((int64_t)(a->whole < 0 ? (-a->whole) : a->whole) << 32) + \
787 (((1ll << 32) * (a->frac < 0 ? -a->frac : a->frac)) / LWS_FX_FRACTION_MSD)))
788
789#define lws_fix3232(a, a64) { a->whole = (int32_t)(a64 >> 32); \
790 a->frac = (int32_t)((100000000 * (a64 & 0xffffffff)) >> 32); }
791
793lws_fx_add(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b);
794
796lws_fx_sub(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b);
797
799lws_fx_mul(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b);
800
802lws_fx_div(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b);
803
806
808lws_fx_comp(const lws_fx_t *a, const lws_fx_t *b);
809
812
815
816LWS_VISIBLE LWS_EXTERN const char *
817lws_fx_string(const lws_fx_t *a, char *buf, size_t size);
818
821
826#if defined(LWS_WITH_SYS_SMD)
828#endif
832#if defined(LWS_WITH_TRANSPORT_SEQUENCER)
834#endif
835#if defined(LWS_WITH_NETWORK)
839#endif
840
845
846#if defined(LWS_WITH_NETWORK)
851#endif
852
854#if defined(LWS_WITH_JOSE)
856#endif
857
859
860#if defined(LWS_WITH_NETWORK)
861#if defined(LWS_WITH_CONMON)
863#endif
864
865#if defined(LWS_ROLE_MQTT)
867#endif
870#if defined(LWS_ROLE_H3)
872#endif
875#endif
879#if defined(LWS_WITH_NETWORK)
883#endif
885#if defined(LWS_WITH_MNEMONIC)
887#endif
892#if defined(LWS_WITH_NETWORK)
894#endif
895#if defined(LWS_WITH_FILE_OPS)
897#endif
899
916
918#if defined(LWS_WITH_AUTHORITATIVE_DNS)
920#endif
921
922#if defined(LWS_WITH_TLS)
923
926
927#if defined(LWS_WITH_MBEDTLS)
928#if !defined(LWS_HAVE_MBEDTLS_V4)
929#include <mbedtls/md5.h>
930#include <mbedtls/sha1.h>
931#include <mbedtls/sha256.h>
932#include <mbedtls/sha512.h>
933#else
934#include <psa/crypto.h>
935#endif
936#endif
937#if defined(LWS_WITH_BEARSSL)
938#include <bearssl.h>
939#endif
940
946
952
953#endif
954
955#if defined(LWS_WITH_NETWORK)
957#endif
960#if defined(LWS_ESP_PLATFORM)
962#endif
981#if defined(LWS_WITH_DLTS)
983#endif
984#if defined(LWS_WITH_NETWORK)
989#if defined(LWS_WITH_TRANSCODE)
991#endif
992#if defined(LWS_WITH_V4L2)
994#endif
995#if defined(LWS_WITH_ALSA)
998#endif
999#endif
1000
1001#include <libwebsockets/lws-html.h>
1004
1005#if defined(LWS_WITH_DIR)
1007#endif
1008
1009#ifdef __cplusplus
1010}
1011#endif
1012
1013#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