| 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 | |
| 25 | /** @file */ |
| 26 | |
| 27 | #ifndef LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C |
| 28 | #define LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C |
| 29 | |
| 30 | #ifdef __cplusplus |
| 31 | #include <cstddef> |
| 32 | #include <cstdarg> |
| 33 | |
| 34 | extern "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 | |
| 69 | typedef struct lws_context * lws_ctx_t; |
| 70 | struct 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 |
| 95 | typedef 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 | |
| 115 | typedef unsigned int uid_t; |
| 116 | typedef unsigned int gid_t; |
| 117 | typedef unsigned short sa_family_t; |
| 118 | #if !defined(LWS_HAVE_SUSECONDS_T) |
| 119 | typedef unsigned int useconds_t; |
| 120 | typedef 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_EXTERN) && defined(LWS_BUILDING_SHARED) |
| 130 | #ifdef LWS_DLL |
| 131 | #ifdef LWS_INTERNAL |
| 132 | #define LWS_EXTERN extern __declspec(dllexport) |
| 133 | #else |
| 134 | #define LWS_EXTERN extern __declspec(dllimport) |
| 135 | #endif |
| 136 | #endif |
| 137 | #endif |
| 138 | |
| 139 | #if !defined(LWS_INTERNAL) && !defined(LWS_EXTERN) |
| 140 | #define LWS_EXTERN |
| 141 | #define LWS_VISIBLE |
| 142 | #endif |
| 143 | |
| 144 | #if !defined(LWS_EXTERN) |
| 145 | #define LWS_EXTERN |
| 146 | #endif |
| 147 | |
| 148 | #define LWS_INVALID_FILE INVALID_HANDLE_VALUE |
| 149 | #define LWS_SOCK_INVALID (INVALID_SOCKET) |
| 150 | #define LWS_O_RDONLY _O_RDONLY |
| 151 | #define LWS_O_WRONLY _O_WRONLY |
| 152 | #define LWS_O_CREAT _O_CREAT |
| 153 | #define LWS_O_TRUNC _O_TRUNC |
| 154 | |
| 155 | #if (__STDC_VERSION__ < 199901L) && !defined(__func__) |
| 156 | #define __func__ __FUNCTION__ |
| 157 | #endif |
| 158 | |
| 159 | #else /* NOT WIN32 */ |
| 160 | #include <unistd.h> |
| 161 | |
| 162 | #if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP) |
| 163 | #include <sys/capability.h> |
| 164 | #endif |
| 165 | |
| 166 | #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__QNX__) || defined(__OpenBSD__) || defined(__NuttX__) |
| 167 | #include <sys/socket.h> |
| 168 | #include <netinet/in.h> |
| 169 | #endif |
| 170 | |
| 171 | #define LWS_INLINE inline |
| 172 | #define LWS_O_RDONLY O_RDONLY |
| 173 | #define LWS_O_WRONLY O_WRONLY |
| 174 | #define LWS_O_CREAT O_CREAT |
| 175 | #define LWS_O_TRUNC O_TRUNC |
| 176 | |
| 177 | #if !defined(LWS_PLAT_OPTEE) && !defined(OPTEE_TA) && !defined(LWS_PLAT_FREERTOS) && !defined(LWS_PLAT_BAREMETAL) |
| 178 | #include <poll.h> |
| 179 | #include <netdb.h> |
| 180 | #define LWS_INVALID_FILE -1 |
| 181 | #define LWS_SOCK_INVALID (-1) |
| 182 | #else |
| 183 | #define getdtablesize() (30) |
| 184 | #if defined(LWS_PLAT_FREERTOS) |
| 185 | #define LWS_INVALID_FILE NULL |
| 186 | #define LWS_SOCK_INVALID (-1) |
| 187 | #else |
| 188 | #define LWS_INVALID_FILE NULL |
| 189 | #define LWS_SOCK_INVALID (-1) |
| 190 | #endif |
| 191 | #endif |
| 192 | |
| 193 | #if defined(__FreeBSD__) |
| 194 | #include <sys/signal.h> |
| 195 | #endif |
| 196 | #if defined(__GNUC__) |
| 197 | |
| 198 | /* warn_unused_result attribute only supported by GCC 3.4 or later */ |
| 199 | #if __GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) |
| 200 | #define LWS_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) |
| 201 | #else |
| 202 | #define LWS_WARN_UNUSED_RESULT |
| 203 | #endif |
| 204 | |
| 205 | #if defined(LWS_BUILDING_SHARED) |
| 206 | /* this is only set when we're building lws itself shared */ |
| 207 | #define LWS_VISIBLE __attribute__((visibility("default"))) |
| 208 | #define LWS_EXTERN extern |
| 209 | |
| 210 | #else /* not shared */ |
| 211 | #if defined(WIN32) || defined(_WIN32) || defined(__MINGW32__) |
| 212 | #define LWS_VISIBLE |
| 213 | #define LWS_EXTERN extern |
| 214 | #else |
| 215 | /* |
| 216 | * If we explicitly say hidden here, symbols exist as T but |
| 217 | * cannot be imported at link-time. |
| 218 | */ |
| 219 | #define LWS_VISIBLE |
| 220 | #define LWS_EXTERN |
| 221 | #endif |
| 222 | |
| 223 | #endif /* not shared */ |
| 224 | |
| 225 | #define LWS_WARN_DEPRECATED __attribute__ ((deprecated)) |
| 226 | #undef printf |
| 227 | #define LWS_FORMAT(string_index) __attribute__ ((format(printf, string_index, string_index+1))) |
| 228 | #else /* not GNUC */ |
| 229 | |
| 230 | #define LWS_VISIBLE |
| 231 | #define LWS_WARN_UNUSED_RESULT |
| 232 | #define LWS_WARN_DEPRECATED |
| 233 | #define LWS_FORMAT(string_index) |
| 234 | #if !defined(LWS_EXTERN) |
| 235 | #define LWS_EXTERN extern |
| 236 | #endif |
| 237 | #endif |
| 238 | |
| 239 | |
| 240 | #if defined(__ANDROID__) |
| 241 | #include <netinet/in.h> |
| 242 | #include <unistd.h> |
| 243 | #endif |
| 244 | #endif |
| 245 | |
| 246 | #ifdef _WIN32 |
| 247 | #define random rand |
| 248 | #else |
| 249 | #if !defined(LWS_PLAT_OPTEE) |
| 250 | #include <sys/time.h> |
| 251 | #include <unistd.h> |
| 252 | #endif |
| 253 | #endif |
| 254 | |
| 255 | #if defined(LWS_WITH_LIBUV_INTERNAL) |
| 256 | #include <uv.h> |
| 257 | |
| 258 | #ifdef LWS_HAVE_UV_VERSION_H |
| 259 | #include <uv-version.h> |
| 260 | #endif |
| 261 | |
| 262 | #ifdef LWS_HAVE_NEW_UV_VERSION_H |
| 263 | #include <uv/version.h> |
| 264 | #endif |
| 265 | #endif |
| 266 | |
| 267 | #if defined(LWS_WITH_TLS) |
| 268 | |
| 269 | #ifdef USE_WOLFSSL |
| 270 | #ifdef USE_OLD_CYASSL |
| 271 | #ifdef _WIN32 |
| 272 | /* |
| 273 | * Include user-controlled settings for windows from |
| 274 | * <wolfssl-root>/IDE/WIN/user_settings.h |
| 275 | */ |
| 276 | #include <IDE/WIN/user_settings.h> |
| 277 | #include <cyassl/ctaocrypt/settings.h> |
| 278 | #else |
| 279 | #include <cyassl/options.h> |
| 280 | #endif |
| 281 | #include <cyassl/openssl/ssl.h> |
| 282 | #include <cyassl/error-ssl.h> |
| 283 | |
| 284 | #else |
| 285 | #ifdef _WIN32 |
| 286 | /* |
| 287 | * Include user-controlled settings for windows from |
| 288 | * <wolfssl-root>/IDE/WIN/user_settings.h |
| 289 | */ |
| 290 | #include <IDE/WIN/user_settings.h> |
| 291 | #include <wolfssl/wolfcrypt/settings.h> |
| 292 | #else |
| 293 | #include <wolfssl/options.h> |
| 294 | #endif |
| 295 | #include <wolfssl/openssl/ssl.h> |
| 296 | #include <wolfssl/error-ssl.h> |
| 297 | #endif /* not USE_OLD_CYASSL */ |
| 298 | #else |
| 299 | #if defined(LWS_WITH_MBEDTLS) |
| 300 | #if defined(LWS_PLAT_FREERTOS) |
| 301 | /* this filepath is passed to us but without quotes or <> */ |
| 302 | #if !defined(LWS_AMAZON_RTOS) |
| 303 | /* AMAZON RTOS has its own setting via MTK_MBEDTLS_CONFIG_FILE */ |
| 304 | #undef MBEDTLS_CONFIG_FILE |
| 305 | #define MBEDTLS_CONFIG_FILE <mbedtls/esp_config.h> |
| 306 | #endif |
| 307 | #endif |
| 308 | |
| 309 | #if defined(LWS_WITH_TLS) |
| 310 | #include <mbedtls/ssl.h> |
| 311 | #include <mbedtls/entropy.h> |
| 312 | #include <mbedtls/ctr_drbg.h> |
| 313 | #include <mbedtls/version.h> |
| 314 | |
| 315 | #if !defined(MBEDTLS_PRIVATE) |
| 316 | #define MBEDTLS_PRIVATE(_q) _q |
| 317 | #endif |
| 318 | |
| 319 | #if (MBEDTLS_VERSION_MAJOR == 3) && (MBEDTLS_VERSION_MINOR == 0) |
| 320 | #define MBEDTLS_PRIVATE_V30_ONLY(_q) MBEDTLS_PRIVATE(_q) |
| 321 | #else |
| 322 | #define MBEDTLS_PRIVATE_V30_ONLY(_q) _q |
| 323 | #endif |
| 324 | |
| 325 | #endif |
| 326 | #else |
| 327 | #include <openssl/ssl.h> |
| 328 | #if !defined(LWS_WITH_MBEDTLS) |
| 329 | #include <openssl/err.h> |
| 330 | #endif |
| 331 | #endif |
| 332 | #endif /* not USE_WOLFSSL */ |
| 333 | #endif |
| 334 | |
| 335 | /* |
| 336 | * Helpers for pthread mutex in user code... if lws is built for |
| 337 | * multiple service threads, these resolve to pthread mutex |
| 338 | * operations. In the case LWS_MAX_SMP is 1 (the default), they |
| 339 | * are all NOPs and no pthread type or api is referenced. |
| 340 | */ |
| 341 | |
| 342 | #if LWS_MAX_SMP > 1 |
| 343 | |
| 344 | #include <pthread.h> |
| 345 | |
| 346 | #define lws_pthread_mutex(name) pthread_mutex_t name; |
| 347 | |
| 348 | static LWS_INLINE void |
| 349 | lws_pthread_mutex_init(pthread_mutex_t *lock) |
| 350 | { |
| 351 | pthread_mutex_init(lock, NULL); |
| 352 | } |
| 353 | |
| 354 | static LWS_INLINE void |
| 355 | lws_pthread_mutex_destroy(pthread_mutex_t *lock) |
| 356 | { |
| 357 | pthread_mutex_destroy(lock); |
| 358 | } |
| 359 | |
| 360 | static LWS_INLINE void |
| 361 | lws_pthread_mutex_lock(pthread_mutex_t *lock) |
| 362 | { |
| 363 | pthread_mutex_lock(lock); |
| 364 | } |
| 365 | |
| 366 | static LWS_INLINE void |
| 367 | lws_pthread_mutex_unlock(pthread_mutex_t *lock) |
| 368 | { |
| 369 | pthread_mutex_unlock(lock); |
| 370 | } |
| 371 | |
| 372 | #else |
| 373 | #define lws_pthread_mutex(name) |
| 374 | #define lws_pthread_mutex_init(_a) |
| 375 | #define lws_pthread_mutex_destroy(_a) |
| 376 | #define lws_pthread_mutex_lock(_a) |
| 377 | #define lws_pthread_mutex_unlock(_a) |
| 378 | #endif |
| 379 | |
| 380 | |
| 381 | #define CONTEXT_PORT_NO_LISTEN -1 |
| 382 | #define CONTEXT_PORT_NO_LISTEN_SERVER -2 |
| 383 | |
| 384 | #include <libwebsockets/lws-logs.h> |
| 385 | |
| 386 | |
| 387 | #include <stddef.h> |
| 388 | |
| 389 | #ifndef lws_container_of |
| 390 | #define lws_container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M))) |
| 391 | #endif |
| 392 | #define LWS_ALIGN_TO(x, bou) x += ((bou) - ((x) % (bou))) % (bou) |
| 393 | |
| 394 | struct lws; |
| 395 | |
| 396 | /* api change list for user code to test against */ |
| 397 | |
| 398 | #define |
| 399 | |
| 400 | /* the struct lws_protocols has the id field present */ |
| 401 | #define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD |
| 402 | |
| 403 | /* you can call lws_get_peer_write_allowance */ |
| 404 | #define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE |
| 405 | |
| 406 | /* extra parameter introduced in 917f43ab821 */ |
| 407 | #define |
| 408 | |
| 409 | /* File operations stuff exists */ |
| 410 | #define LWS_FEATURE_FOPS |
| 411 | |
| 412 | /* Mounts have extra no_cache member */ |
| 413 | #define LWS_FEATURE_MOUNT_NO_CACHE |
| 414 | |
| 415 | |
| 416 | #if defined(_WIN32) |
| 417 | #if !defined(LWS_WIN32_HANDLE_TYPES) |
| 418 | typedef SOCKET lws_sockfd_type; |
| 419 | #if defined(__MINGW32__) |
| 420 | typedef int lws_filefd_type; |
| 421 | #else |
| 422 | typedef HANDLE lws_filefd_type; |
| 423 | #endif |
| 424 | #endif |
| 425 | |
| 426 | |
| 427 | #define lws_pollfd pollfd |
| 428 | #define LWS_POLLHUP (POLLHUP) |
| 429 | #define LWS_POLLIN (POLLRDNORM | POLLRDBAND) |
| 430 | #define LWS_POLLOUT (POLLWRNORM) |
| 431 | |
| 432 | #else |
| 433 | |
| 434 | |
| 435 | #if defined(LWS_PLAT_FREERTOS) |
| 436 | #include <libwebsockets/lws-freertos.h> |
| 437 | #else |
| 438 | typedef int lws_sockfd_type; |
| 439 | typedef int lws_filefd_type; |
| 440 | #endif |
| 441 | |
| 442 | #if defined(LWS_PLAT_OPTEE) |
| 443 | #include <time.h> |
| 444 | struct timeval { |
| 445 | time_t tv_sec; |
| 446 | unsigned int tv_usec; |
| 447 | }; |
| 448 | #if defined(LWS_WITH_NETWORK) |
| 449 | // #include <poll.h> |
| 450 | #define lws_pollfd pollfd |
| 451 | |
| 452 | struct timezone; |
| 453 | |
| 454 | int gettimeofday(struct timeval *tv, struct timezone *tz); |
| 455 | |
| 456 | /* Internet address. */ |
| 457 | struct in_addr { |
| 458 | uint32_t s_addr; /* address in network byte order */ |
| 459 | }; |
| 460 | |
| 461 | typedef unsigned short sa_family_t; |
| 462 | typedef unsigned short in_port_t; |
| 463 | typedef uint32_t socklen_t; |
| 464 | |
| 465 | #include <libwebsockets/lws-optee.h> |
| 466 | |
| 467 | #if !defined(TEE_SE_READER_NAME_MAX) |
| 468 | struct addrinfo { |
| 469 | int ai_flags; |
| 470 | int ai_family; |
| 471 | int ai_socktype; |
| 472 | int ai_protocol; |
| 473 | socklen_t ai_addrlen; |
| 474 | struct sockaddr *ai_addr; |
| 475 | char *ai_canonname; |
| 476 | struct addrinfo *ai_next; |
| 477 | }; |
| 478 | #endif |
| 479 | |
| 480 | ssize_t recv(int sockfd, void *buf, size_t len, int flags); |
| 481 | ssize_t send(int sockfd, const void *buf, size_t len, int flags); |
| 482 | ssize_t read(int fd, void *buf, size_t count); |
| 483 | int getsockopt(int sockfd, int level, int optname, |
| 484 | void *optval, socklen_t *optlen); |
| 485 | int setsockopt(int sockfd, int level, int optname, |
| 486 | const void *optval, socklen_t optlen); |
| 487 | int connect(int sockfd, const struct sockaddr *addr, |
| 488 | socklen_t addrlen); |
| 489 | |
| 490 | extern int errno; |
| 491 | |
| 492 | uint16_t ntohs(uint16_t netshort); |
| 493 | uint16_t htons(uint16_t hostshort); |
| 494 | |
| 495 | int bind(int sockfd, const struct sockaddr *addr, |
| 496 | socklen_t addrlen); |
| 497 | |
| 498 | |
| 499 | #define MSG_NOSIGNAL 0x4000 |
| 500 | #define EAGAIN 11 |
| 501 | #define EINTR 4 |
| 502 | #define EWOULDBLOCK EAGAIN |
| 503 | #define EADDRINUSE 98 |
| 504 | #define INADDR_ANY 0 |
| 505 | #define AF_INET 2 |
| 506 | #define SHUT_WR 1 |
| 507 | #define AF_UNSPEC 0 |
| 508 | #define PF_UNSPEC 0 |
| 509 | #define SOCK_STREAM 1 |
| 510 | #define SOCK_DGRAM 2 |
| 511 | # define AI_PASSIVE 0x0001 |
| 512 | #define IPPROTO_UDP 17 |
| 513 | #define SOL_SOCKET 1 |
| 514 | #define SO_SNDBUF 7 |
| 515 | #define EISCONN 106 |
| 516 | #define EALREADY 114 |
| 517 | #define EINPROGRESS 115 |
| 518 | int shutdown(int sockfd, int how); |
| 519 | int close(int fd); |
| 520 | int atoi(const char *nptr); |
| 521 | long long atoll(const char *nptr); |
| 522 | |
| 523 | int socket(int domain, int type, int protocol); |
| 524 | int getaddrinfo(const char *node, const char *service, |
| 525 | const struct addrinfo *hints, |
| 526 | struct addrinfo **res); |
| 527 | |
| 528 | void freeaddrinfo(struct addrinfo *res); |
| 529 | |
| 530 | #if !defined(TEE_SE_READER_NAME_MAX) |
| 531 | struct lws_pollfd |
| 532 | { |
| 533 | int fd; /* File descriptor to poll. */ |
| 534 | short int events; /* Types of events poller cares about. */ |
| 535 | short int revents; /* Types of events that actually occurred. */ |
| 536 | }; |
| 537 | #endif |
| 538 | |
| 539 | int poll(struct pollfd *fds, int nfds, int timeout); |
| 540 | |
| 541 | #define LWS_POLLHUP (0x18) |
| 542 | #define LWS_POLLIN (1) |
| 543 | #define LWS_POLLOUT (4) |
| 544 | #else |
| 545 | struct lws_pollfd; |
| 546 | struct sockaddr_in; |
| 547 | #endif |
| 548 | #else |
| 549 | #define lws_pollfd pollfd |
| 550 | #define LWS_POLLHUP (POLLHUP | POLLERR) |
| 551 | #define LWS_POLLIN (POLLIN) |
| 552 | #define LWS_POLLOUT (POLLOUT) |
| 553 | #endif |
| 554 | #endif |
| 555 | |
| 556 | |
| 557 | #if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__) |
| 558 | /* ... */ |
| 559 | #define ssize_t SSIZE_T |
| 560 | #endif |
| 561 | |
| 562 | #if defined(WIN32) && defined(LWS_HAVE__STAT32I64) |
| 563 | #include <sys/types.h> |
| 564 | #include <sys/stat.h> |
| 565 | #endif |
| 566 | |
| 567 | #if defined(LWS_HAVE_STDINT_H) |
| 568 | #include <stdint.h> |
| 569 | #else |
| 570 | #if defined(WIN32) || defined(_WIN32) |
| 571 | /* !!! >:-[ */ |
| 572 | typedef __int64 int64_t; |
| 573 | typedef unsigned __int64 uint64_t; |
| 574 | typedef __int32 int32_t; |
| 575 | typedef unsigned __int32 uint32_t; |
| 576 | typedef __int16 int16_t; |
| 577 | typedef unsigned __int16 uint16_t; |
| 578 | typedef unsigned __int8 uint8_t; |
| 579 | #else |
| 580 | typedef unsigned int uint32_t; |
| 581 | typedef unsigned short uint16_t; |
| 582 | typedef unsigned char uint8_t; |
| 583 | #endif |
| 584 | #endif |
| 585 | |
| 586 | typedef int64_t lws_usec_t; |
| 587 | typedef unsigned long long lws_filepos_t; |
| 588 | typedef long long lws_fileofs_t; |
| 589 | typedef uint32_t lws_fop_flags_t; |
| 590 | |
| 591 | #define lws_concat_temp(_t, _l) (_t + sizeof(_t) - _l) |
| 592 | #define lws_concat_used(_t, _l) (sizeof(_t) - _l) |
| 593 | |
| 594 | /** struct lws_pollargs - argument structure for all external poll related calls |
| 595 | * passed in via 'in' */ |
| 596 | struct lws_pollargs { |
| 597 | lws_sockfd_type fd; /**< applicable socket descriptor */ |
| 598 | int events; /**< the new event mask */ |
| 599 | int prev_events; /**< the previous event mask */ |
| 600 | }; |
| 601 | |
| 602 | #if !defined(LWS_SIZEOFPTR) |
| 603 | #define LWS_SIZEOFPTR ((int)sizeof (void *)) |
| 604 | #endif |
| 605 | |
| 606 | #if defined(__x86_64__) |
| 607 | #define _LWS_PAD_SIZE 16 /* Intel recommended for best performance */ |
| 608 | #else |
| 609 | #define _LWS_PAD_SIZE LWS_SIZEOFPTR /* Size of a pointer on the target arch */ |
| 610 | #endif |
| 611 | #define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? \ |
| 612 | ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n)) |
| 613 | /* last 2 is for lws-meta */ |
| 614 | #define LWS_PRE _LWS_PAD(4 + 10 + 2) |
| 615 | /* used prior to 1.7 and retained for backward compatibility */ |
| 616 | #define LWS_SEND_BUFFER_PRE_PADDING LWS_PRE |
| 617 | #define LWS_SEND_BUFFER_POST_PADDING 0 |
| 618 | |
| 619 | |
| 620 | |
| 621 | struct lws_extension; /* needed even with ws exts disabled for create context */ |
| 622 | struct lws_token_limits; |
| 623 | struct lws_protocols; |
| 624 | struct lws_context; |
| 625 | struct lws_tokens; |
| 626 | struct lws_vhost; |
| 627 | struct lws; |
| 628 | |
| 629 | /* Generic stateful operation return codes */ |
| 630 | |
| 631 | typedef enum { |
| 632 | LWS_SRET_OK = 0, |
| 633 | LWS_SRET_WANT_INPUT = (1 << 16), |
| 634 | LWS_SRET_WANT_OUTPUT = (1 << 17), |
| 635 | LWS_SRET_FATAL = (1 << 18), |
| 636 | LWS_SRET_NO_FURTHER_IN = (1 << 19), |
| 637 | LWS_SRET_NO_FURTHER_OUT = (1 << 20), |
| 638 | LWS_SRET_AWAIT_RETRY = (1 << 21), |
| 639 | LWS_SRET_YIELD = (1 << 22), /* return to the event loop and continue */ |
| 640 | } lws_stateful_ret_t; |
| 641 | |
| 642 | typedef struct lws_fixed3232 { |
| 643 | int32_t whole; /* signed 32-bit int */ |
| 644 | int32_t frac; /* signed frac proportion from 0 to (100M - 1) */ |
| 645 | } lws_fx_t; |
| 646 | |
| 647 | #define LWS_FX_FRACTION_MSD 100000000 |
| 648 | #define lws_neg(a) (a->whole < 0 || a->frac < 0) |
| 649 | #define lws_fx_set(a, x, y) { a.whole = x; a.frac = x < 0 ? -y : y; } |
| 650 | #define lws_fix64(a) (((int64_t)a->whole << 32) + \ |
| 651 | (((1ll << 32) * (a->frac < 0 ? -a->frac : a->frac)) / LWS_FX_FRACTION_MSD)) |
| 652 | #define lws_fix64_abs(a) \ |
| 653 | ((((int64_t)(a->whole < 0 ? (-a->whole) : a->whole) << 32) + \ |
| 654 | (((1ll << 32) * (a->frac < 0 ? -a->frac : a->frac)) / LWS_FX_FRACTION_MSD))) |
| 655 | |
| 656 | #define lws_fix3232(a, a64) { a->whole = (int32_t)(a64 >> 32); \ |
| 657 | a->frac = (int32_t)((100000000 * (a64 & 0xffffffff)) >> 32); } |
| 658 | |
| 659 | LWS_VISIBLE LWS_EXTERN const lws_fx_t * |
| 660 | lws_fx_add(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b); |
| 661 | |
| 662 | LWS_VISIBLE LWS_EXTERN const lws_fx_t * |
| 663 | lws_fx_sub(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b); |
| 664 | |
| 665 | LWS_VISIBLE LWS_EXTERN const lws_fx_t * |
| 666 | lws_fx_mul(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b); |
| 667 | |
| 668 | LWS_VISIBLE LWS_EXTERN const lws_fx_t * |
| 669 | lws_fx_div(lws_fx_t *r, const lws_fx_t *a, const lws_fx_t *b); |
| 670 | |
| 671 | LWS_VISIBLE LWS_EXTERN const lws_fx_t * |
| 672 | lws_fx_sqrt(lws_fx_t *r, const lws_fx_t *a); |
| 673 | |
| 674 | LWS_VISIBLE LWS_EXTERN int |
| 675 | lws_fx_comp(const lws_fx_t *a, const lws_fx_t *b); |
| 676 | |
| 677 | LWS_VISIBLE LWS_EXTERN int |
| 678 | lws_fx_roundup(const lws_fx_t *a); |
| 679 | |
| 680 | LWS_VISIBLE LWS_EXTERN int |
| 681 | lws_fx_rounddown(const lws_fx_t *a); |
| 682 | |
| 683 | LWS_VISIBLE LWS_EXTERN const char * |
| 684 | lws_fx_string(const lws_fx_t *a, char *buf, size_t size); |
| 685 | |
| 686 | #include <libwebsockets/lws-dll2.h> |
| 687 | #include <libwebsockets/lws-map.h> |
| 688 | |
| 689 | #include <libwebsockets/lws-fault-injection.h> |
| 690 | #include <libwebsockets/lws-backtrace.h> |
| 691 | #include <libwebsockets/lws-timeout-timer.h> |
| 692 | #include <libwebsockets/lws-cache-ttl.h> |
| 693 | #if defined(LWS_WITH_SYS_SMD) |
| 694 | #include <libwebsockets/lws-smd.h> |
| 695 | #endif |
| 696 | #include <libwebsockets/lws-state.h> |
| 697 | #include <libwebsockets/lws-retry.h> |
| 698 | #if defined(LWS_WITH_NETWORK) |
| 699 | #include <libwebsockets/lws-adopt.h> |
| 700 | #include <libwebsockets/lws-network-helper.h> |
| 701 | #include <libwebsockets/lws-metrics.h> |
| 702 | #endif |
| 703 | |
| 704 | #include <libwebsockets/lws-ota.h> |
| 705 | #include <libwebsockets/lws-system.h> |
| 706 | #include <libwebsockets/lws-callbacks.h> |
| 707 | |
| 708 | #if defined(LWS_WITH_NETWORK) |
| 709 | #include <libwebsockets/lws-ws-close.h> |
| 710 | #include <libwebsockets/lws-ws-state.h> |
| 711 | #include <libwebsockets/lws-ws-ext.h> |
| 712 | #endif |
| 713 | |
| 714 | #include <libwebsockets/lws-protocols-plugins.h> |
| 715 | |
| 716 | #include <libwebsockets/lws-context-vhost.h> |
| 717 | |
| 718 | #if defined(LWS_WITH_NETWORK) |
| 719 | #if defined(LWS_WITH_CONMON) |
| 720 | #include <libwebsockets/lws-conmon.h> |
| 721 | #endif |
| 722 | |
| 723 | #if defined(LWS_ROLE_MQTT) |
| 724 | #include <libwebsockets/lws-mqtt.h> |
| 725 | #endif |
| 726 | #include <libwebsockets/lws-client.h> |
| 727 | #include <libwebsockets/lws-http.h> |
| 728 | #include <libwebsockets/lws-spa.h> |
| 729 | #endif |
| 730 | #include <libwebsockets/lws-purify.h> |
| 731 | #include <libwebsockets/lws-misc.h> |
| 732 | #include <libwebsockets/lws-dsh.h> |
| 733 | #if defined(LWS_WITH_NETWORK) |
| 734 | #include <libwebsockets/lws-service.h> |
| 735 | #include <libwebsockets/lws-write.h> |
| 736 | #include <libwebsockets/lws-writeable.h> |
| 737 | #endif |
| 738 | #include <libwebsockets/lws-ring.h> |
| 739 | #include <libwebsockets/lws-sha1-base64.h> |
| 740 | #include <libwebsockets/lws-x509.h> |
| 741 | #if defined(LWS_WITH_NETWORK) |
| 742 | #include <libwebsockets/lws-cgi.h> |
| 743 | #endif |
| 744 | #if defined(LWS_WITH_FILE_OPS) |
| 745 | #include <libwebsockets/lws-vfs.h> |
| 746 | #endif |
| 747 | #include <libwebsockets/lws-gencrypto.h> |
| 748 | |
| 749 | #include <libwebsockets/lws-lejp.h> |
| 750 | #include <libwebsockets/lws-lecp.h> |
| 751 | #include <libwebsockets/lws-cose.h> |
| 752 | #include <libwebsockets/lws-struct.h> |
| 753 | #include <libwebsockets/lws-threadpool.h> |
| 754 | #include <libwebsockets/lws-tokenize.h> |
| 755 | #include <libwebsockets/lws-lwsac.h> |
| 756 | #include <libwebsockets/lws-fts.h> |
| 757 | #include <libwebsockets/lws-diskcache.h> |
| 758 | #include <libwebsockets/lws-secure-streams.h> |
| 759 | #include <libwebsockets/lws-secure-streams-serialization.h> |
| 760 | #include <libwebsockets/lws-secure-streams-policy.h> |
| 761 | #include <libwebsockets/lws-secure-streams-client.h> |
| 762 | #include <libwebsockets/lws-secure-streams-transport-proxy.h> |
| 763 | #include <libwebsockets/lws-jrpc.h> |
| 764 | |
| 765 | #include <libwebsockets/lws-async-dns.h> |
| 766 | |
| 767 | #if defined(LWS_WITH_TLS) |
| 768 | |
| 769 | #include <libwebsockets/lws-tls-sessions.h> |
| 770 | |
| 771 | #if defined(LWS_WITH_MBEDTLS) |
| 772 | #include <mbedtls/md5.h> |
| 773 | #include <mbedtls/sha1.h> |
| 774 | #include <mbedtls/sha256.h> |
| 775 | #include <mbedtls/sha512.h> |
| 776 | #endif |
| 777 | |
| 778 | #include <libwebsockets/lws-genhash.h> |
| 779 | #include <libwebsockets/lws-genrsa.h> |
| 780 | #include <libwebsockets/lws-genaes.h> |
| 781 | #include <libwebsockets/lws-genec.h> |
| 782 | |
| 783 | #include <libwebsockets/lws-jwk.h> |
| 784 | #include <libwebsockets/lws-jose.h> |
| 785 | #include <libwebsockets/lws-jws.h> |
| 786 | #include <libwebsockets/lws-jwe.h> |
| 787 | |
| 788 | #endif |
| 789 | |
| 790 | #if defined(LWS_WITH_NETWORK) |
| 791 | #include <libwebsockets/lws-eventlib-exports.h> |
| 792 | #endif |
| 793 | #include <libwebsockets/lws-i2c.h> |
| 794 | #include <libwebsockets/lws-spi.h> |
| 795 | #if defined(LWS_ESP_PLATFORM) |
| 796 | #include <libwebsockets/lws-esp32-spi.h> |
| 797 | #endif |
| 798 | #include <libwebsockets/lws-gpio.h> |
| 799 | #include <libwebsockets/lws-bb-i2c.h> |
| 800 | #include <libwebsockets/lws-bb-spi.h> |
| 801 | #include <libwebsockets/lws-button.h> |
| 802 | #include <libwebsockets/lws-led.h> |
| 803 | #include <libwebsockets/lws-pwm.h> |
| 804 | #include <libwebsockets/lws-upng.h> |
| 805 | #include <libwebsockets/lws-jpeg.h> |
| 806 | #include <libwebsockets/lws-display.h> |
| 807 | #include <libwebsockets/lws-dlo.h> |
| 808 | #include <libwebsockets/lws-ssd1306-i2c.h> |
| 809 | #include <libwebsockets/lws-ili9341-spi.h> |
| 810 | #include <libwebsockets/lws-spd1656-spi.h> |
| 811 | #include <libwebsockets/lws-uc8176-spi.h> |
| 812 | #include <libwebsockets/lws-ssd1675b-spi.h> |
| 813 | #include <libwebsockets/lws-settings.h> |
| 814 | #if defined(LWS_WITH_NETWORK) |
| 815 | #include <libwebsockets/lws-netdev.h> |
| 816 | #endif |
| 817 | |
| 818 | #include <libwebsockets/lws-html.h> |
| 819 | |
| 820 | #ifdef __cplusplus |
| 821 | } |
| 822 | #endif |
| 823 | |
| 824 | #endif |
| 825 | |