2010-11-08 20:20:42 +00:00
|
|
|
/*
|
|
|
|
* libwebsockets - small server side websockets and web server implementation
|
2010-11-13 10:03:47 +00:00
|
|
|
*
|
2019-01-13 06:58:21 +08:00
|
|
|
* Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
|
2010-11-08 20:20:42 +00:00
|
|
|
*
|
2019-08-14 10:44:14 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
* deal in the Software without restriction, including without limitation the
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2010-11-08 20:20:42 +00:00
|
|
|
*
|
2019-08-14 10:44:14 +01:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2010-11-08 20:20:42 +00:00
|
|
|
*
|
2019-08-14 10:44:14 +01:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
2010-11-08 20:20:42 +00:00
|
|
|
*/
|
2013-02-06 15:30:33 +09:00
|
|
|
|
2019-09-19 10:15:56 +01:00
|
|
|
#if !defined(__LWS_PRIVATE_LIB_CORE_H__)
|
|
|
|
#define __LWS_PRIVATE_LIB_CORE_H__
|
|
|
|
|
2013-02-06 15:26:58 +09:00
|
|
|
#include "lws_config.h"
|
2015-06-26 11:40:54 +02:00
|
|
|
#include "lws_config_private.h"
|
2014-04-02 21:02:54 +08:00
|
|
|
|
2019-06-07 11:11:46 +01:00
|
|
|
#if defined(LWS_WITH_CGI) && defined(LWS_HAVE_VFORK) && \
|
2019-12-22 03:38:05 +00:00
|
|
|
!defined(NO_GNU_SOURCE_THIS_TIME) && !defined(_GNU_SOURCE)
|
2018-04-19 12:53:53 +08:00
|
|
|
#define _GNU_SOURCE
|
2016-02-21 21:25:48 +08:00
|
|
|
#endif
|
|
|
|
|
2019-06-07 11:11:46 +01:00
|
|
|
/*
|
|
|
|
#if !defined(_POSIX_C_SOURCE)
|
|
|
|
#define _POSIX_C_SOURCE 200112L
|
|
|
|
#endif
|
|
|
|
*/
|
|
|
|
|
2010-11-08 20:20:42 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2014-03-30 10:19:23 +02:00
|
|
|
#include <time.h>
|
2010-11-08 20:20:42 +00:00
|
|
|
#include <ctype.h>
|
2013-01-17 10:08:16 +08:00
|
|
|
#include <limits.h>
|
2011-03-02 22:03:47 +00:00
|
|
|
#include <stdarg.h>
|
2019-07-31 16:31:22 +08:00
|
|
|
|
|
|
|
#ifdef LWS_HAVE_INTTYPES_H
|
2017-09-08 13:54:36 +02:00
|
|
|
#include <inttypes.h>
|
2019-07-31 16:31:22 +08:00
|
|
|
#endif
|
|
|
|
|
2015-12-04 07:22:44 +08:00
|
|
|
#include <assert.h>
|
2014-04-07 11:28:08 +02:00
|
|
|
|
2018-06-16 09:37:07 +08:00
|
|
|
#ifdef LWS_HAVE_SYS_TYPES_H
|
2018-04-19 12:53:53 +08:00
|
|
|
#include <sys/types.h>
|
2011-02-14 20:56:24 +00:00
|
|
|
#endif
|
2019-01-15 06:59:48 +08:00
|
|
|
#if defined(LWS_HAVE_SYS_STAT_H) && !defined(LWS_PLAT_OPTEE)
|
2018-04-19 12:53:53 +08:00
|
|
|
#include <sys/stat.h>
|
2014-09-16 14:05:13 +04:00
|
|
|
#endif
|
|
|
|
|
2018-06-16 09:37:07 +08:00
|
|
|
#if LWS_MAX_SMP > 1
|
|
|
|
#include <pthread.h>
|
2015-01-30 10:13:01 +08:00
|
|
|
#endif
|
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
#ifndef LWS_DEF_HEADER_LEN
|
2016-07-11 07:48:53 +08:00
|
|
|
#define LWS_DEF_HEADER_LEN 4096
|
2013-01-12 23:42:17 +08:00
|
|
|
#endif
|
2016-01-26 20:56:56 +08:00
|
|
|
#ifndef LWS_DEF_HEADER_POOL
|
2016-07-11 07:48:53 +08:00
|
|
|
#define LWS_DEF_HEADER_POOL 4
|
2015-12-25 12:44:12 +08:00
|
|
|
#endif
|
2013-01-12 23:42:17 +08:00
|
|
|
#ifndef LWS_MAX_PROTOCOLS
|
2013-02-10 16:00:47 +08:00
|
|
|
#define LWS_MAX_PROTOCOLS 5
|
2013-01-12 23:42:17 +08:00
|
|
|
#endif
|
|
|
|
#ifndef LWS_MAX_EXTENSIONS_ACTIVE
|
2018-04-20 10:33:23 +08:00
|
|
|
#define LWS_MAX_EXTENSIONS_ACTIVE 1
|
2013-01-12 23:42:17 +08:00
|
|
|
#endif
|
2016-01-11 11:34:01 +08:00
|
|
|
#ifndef LWS_MAX_EXT_OFFERS
|
|
|
|
#define LWS_MAX_EXT_OFFERS 8
|
|
|
|
#endif
|
2013-01-12 23:42:17 +08:00
|
|
|
#ifndef SPEC_LATEST_SUPPORTED
|
2011-09-25 09:32:54 +01:00
|
|
|
#define SPEC_LATEST_SUPPORTED 13
|
2013-01-12 23:42:17 +08:00
|
|
|
#endif
|
|
|
|
#ifndef AWAITING_TIMEOUT
|
2016-01-26 20:56:56 +08:00
|
|
|
#define AWAITING_TIMEOUT 20
|
2013-01-12 23:42:17 +08:00
|
|
|
#endif
|
|
|
|
#ifndef CIPHERS_LIST_STRING
|
2013-01-10 10:15:19 +08:00
|
|
|
#define CIPHERS_LIST_STRING "DEFAULT"
|
2013-01-12 23:42:17 +08:00
|
|
|
#endif
|
2013-01-15 20:52:29 +08:00
|
|
|
#ifndef LWS_SOMAXCONN
|
|
|
|
#define LWS_SOMAXCONN SOMAXCONN
|
|
|
|
#endif
|
2010-11-08 20:20:42 +00:00
|
|
|
|
2011-01-18 17:14:03 +00:00
|
|
|
#define MAX_WEBSOCKET_04_KEY_LEN 128
|
2013-01-12 23:42:17 +08:00
|
|
|
|
|
|
|
#ifndef SYSTEM_RANDOM_FILEPATH
|
2011-01-22 12:51:57 +00:00
|
|
|
#define SYSTEM_RANDOM_FILEPATH "/dev/urandom"
|
2013-01-12 23:42:17 +08:00
|
|
|
#endif
|
|
|
|
|
2018-03-31 11:30:12 +08:00
|
|
|
#define LWS_H2_RX_SCRATCH_SIZE 512
|
|
|
|
|
2018-06-16 08:53:48 -07:00
|
|
|
#define lws_socket_is_valid(x) (x != LWS_SOCK_INVALID)
|
2017-10-18 09:41:44 +08:00
|
|
|
|
2018-06-16 09:37:07 +08:00
|
|
|
#ifndef LWS_HAVE_STRERROR
|
|
|
|
#define strerror(x) ""
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* ------ private platform defines ------
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-08-18 10:35:43 +01:00
|
|
|
#if defined(LWS_PLAT_FREERTOS)
|
|
|
|
#include "private-lib-plat-freertos.h"
|
2018-06-16 09:37:07 +08:00
|
|
|
#else
|
|
|
|
#if defined(WIN32) || defined(_WIN32)
|
2019-08-15 10:49:52 +01:00
|
|
|
#include "private-lib-plat-windows.h"
|
2018-06-16 09:37:07 +08:00
|
|
|
#else
|
|
|
|
#if defined(LWS_PLAT_OPTEE)
|
2019-08-15 10:49:52 +01:00
|
|
|
#include "private-lib-plat.h"
|
2018-06-16 09:37:07 +08:00
|
|
|
#else
|
2019-08-15 10:49:52 +01:00
|
|
|
#include "private-lib-plat-unix.h"
|
2018-06-16 09:37:07 +08:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* ------ public api ------
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libwebsockets.h"
|
|
|
|
|
2020-01-15 12:07:20 +00:00
|
|
|
/*
|
|
|
|
* Generic bidi tx credit management
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct lws_tx_credit {
|
|
|
|
int32_t tx_cr; /* our credit to write peer */
|
|
|
|
int32_t peer_tx_cr_est; /* peer's credit to write us */
|
|
|
|
|
|
|
|
int32_t manual_initial_tx_credit;
|
|
|
|
|
|
|
|
uint8_t skint; /* unable to write anything */
|
|
|
|
uint8_t manual;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-08-15 10:49:52 +01:00
|
|
|
#include "private-lib-tls.h"
|
2018-06-16 09:37:07 +08:00
|
|
|
|
2018-08-16 19:10:32 +08:00
|
|
|
#if defined(WIN32) || defined(_WIN32)
|
|
|
|
// Visual studio older than 2015 and WIN_CE has only _stricmp
|
|
|
|
#if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(_WIN32_WCE)
|
|
|
|
#define strcasecmp _stricmp
|
2019-05-04 08:23:03 +01:00
|
|
|
#define strncasecmp _strnicmp
|
2018-08-16 19:10:32 +08:00
|
|
|
#elif !defined(__MINGW32__)
|
|
|
|
#define strcasecmp stricmp
|
2019-05-04 08:23:03 +01:00
|
|
|
#define strncasecmp strnicmp
|
2018-08-16 19:10:32 +08:00
|
|
|
#endif
|
|
|
|
#define getdtablesize() 30000
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef LWS_ARRAY_SIZE
|
|
|
|
#define LWS_ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
|
|
|
|
#endif
|
|
|
|
|
2018-06-16 09:37:07 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2017-10-18 09:41:44 +08:00
|
|
|
|
2019-01-13 06:58:21 +08:00
|
|
|
|
2017-10-18 09:41:44 +08:00
|
|
|
|
2017-11-12 09:16:46 +08:00
|
|
|
#if defined(__clang__)
|
|
|
|
#define lws_memory_barrier() __sync_synchronize()
|
|
|
|
#elif defined(__GNUC__)
|
|
|
|
#define lws_memory_barrier() __sync_synchronize()
|
|
|
|
#else
|
|
|
|
#define lws_memory_barrier()
|
|
|
|
#endif
|
|
|
|
|
2018-11-29 08:47:49 +08:00
|
|
|
|
2017-09-20 10:37:59 +08:00
|
|
|
struct lws_ring {
|
|
|
|
void *buf;
|
|
|
|
void (*destroy_element)(void *element);
|
2017-10-25 08:00:23 +08:00
|
|
|
uint32_t buflen;
|
|
|
|
uint32_t element_len;
|
2017-09-20 10:37:59 +08:00
|
|
|
uint32_t head;
|
|
|
|
uint32_t oldest_tail;
|
|
|
|
};
|
|
|
|
|
2015-12-04 11:08:32 +08:00
|
|
|
struct lws_protocols;
|
|
|
|
struct lws;
|
2011-01-19 13:11:55 +00:00
|
|
|
|
2019-01-13 06:58:21 +08:00
|
|
|
#if defined(LWS_WITH_NETWORK)
|
2019-08-15 10:49:52 +01:00
|
|
|
#include "private-lib-event-libs.h"
|
2019-01-13 06:58:21 +08:00
|
|
|
|
2020-02-29 12:37:24 +00:00
|
|
|
#if defined(LWS_WITH_SECURE_STREAMS)
|
|
|
|
#include "private-lib-secure-streams.h"
|
|
|
|
#endif
|
2019-01-13 06:58:21 +08:00
|
|
|
|
2014-03-23 13:25:07 +08:00
|
|
|
struct lws_io_watcher {
|
2017-09-28 11:29:03 +08:00
|
|
|
#ifdef LWS_WITH_LIBEV
|
2018-04-29 08:34:19 +08:00
|
|
|
struct lws_io_watcher_libev ev;
|
2016-02-14 09:27:41 +08:00
|
|
|
#endif
|
2017-09-28 11:29:03 +08:00
|
|
|
#ifdef LWS_WITH_LIBUV
|
2018-04-29 08:34:19 +08:00
|
|
|
struct lws_io_watcher_libuv uv;
|
2017-03-15 19:41:11 +05:30
|
|
|
#endif
|
2017-09-28 11:29:03 +08:00
|
|
|
#ifdef LWS_WITH_LIBEVENT
|
2018-04-29 08:34:19 +08:00
|
|
|
struct lws_io_watcher_libevent event;
|
2020-02-07 11:39:32 +00:00
|
|
|
#endif
|
|
|
|
#ifdef LWS_WITH_GLIB
|
|
|
|
struct lws_io_watcher_glib glib;
|
2016-02-14 09:27:41 +08:00
|
|
|
#endif
|
|
|
|
struct lws_context *context;
|
2017-09-25 11:54:00 +08:00
|
|
|
|
|
|
|
uint8_t actual_events;
|
2014-03-23 13:25:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct lws_signal_watcher {
|
2017-09-28 11:29:03 +08:00
|
|
|
#ifdef LWS_WITH_LIBEV
|
2018-04-29 08:34:19 +08:00
|
|
|
struct lws_signal_watcher_libev ev;
|
2016-02-14 09:27:41 +08:00
|
|
|
#endif
|
2017-09-28 11:29:03 +08:00
|
|
|
#ifdef LWS_WITH_LIBUV
|
2018-04-29 08:34:19 +08:00
|
|
|
struct lws_signal_watcher_libuv uv;
|
2017-03-15 19:41:11 +05:30
|
|
|
#endif
|
2017-09-28 11:29:03 +08:00
|
|
|
#ifdef LWS_WITH_LIBEVENT
|
2018-04-29 08:34:19 +08:00
|
|
|
struct lws_signal_watcher_libevent event;
|
2016-02-14 09:27:41 +08:00
|
|
|
#endif
|
|
|
|
struct lws_context *context;
|
2014-03-23 13:25:07 +08:00
|
|
|
};
|
|
|
|
|
2017-11-12 09:16:46 +08:00
|
|
|
struct lws_foreign_thread_pollfd {
|
|
|
|
struct lws_foreign_thread_pollfd *next;
|
|
|
|
int fd_index;
|
|
|
|
int _and;
|
|
|
|
int _or;
|
|
|
|
};
|
2019-08-09 10:12:09 +01:00
|
|
|
#endif
|
2017-11-12 09:16:46 +08:00
|
|
|
|
2018-06-27 07:15:39 +08:00
|
|
|
#if LWS_MAX_SMP > 1
|
|
|
|
|
|
|
|
struct lws_mutex_refcount {
|
|
|
|
pthread_mutex_t lock;
|
|
|
|
pthread_t lock_owner;
|
|
|
|
const char *last_lock_reason;
|
|
|
|
char lock_depth;
|
|
|
|
char metadata;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
lws_mutex_refcount_init(struct lws_mutex_refcount *mr);
|
|
|
|
|
|
|
|
void
|
|
|
|
lws_mutex_refcount_destroy(struct lws_mutex_refcount *mr);
|
|
|
|
|
|
|
|
void
|
|
|
|
lws_mutex_refcount_lock(struct lws_mutex_refcount *mr, const char *reason);
|
|
|
|
|
|
|
|
void
|
|
|
|
lws_mutex_refcount_unlock(struct lws_mutex_refcount *mr);
|
|
|
|
#endif
|
2015-12-25 12:44:12 +08:00
|
|
|
|
2019-01-13 06:58:21 +08:00
|
|
|
#if defined(LWS_WITH_NETWORK)
|
2019-08-15 10:49:52 +01:00
|
|
|
#include "private-lib-core-net.h"
|
2018-03-02 15:31:35 +08:00
|
|
|
#endif
|
2018-04-25 06:53:30 +08:00
|
|
|
|
2017-07-15 14:37:04 +08:00
|
|
|
struct lws_deferred_free
|
|
|
|
{
|
|
|
|
struct lws_deferred_free *next;
|
|
|
|
time_t deadline;
|
|
|
|
void *payload;
|
|
|
|
};
|
|
|
|
|
2020-02-10 09:06:28 +00:00
|
|
|
struct lws_system_blob {
|
2019-12-07 19:41:58 +00:00
|
|
|
union {
|
|
|
|
struct lws_buflist *bl;
|
|
|
|
struct {
|
|
|
|
const uint8_t *ptr;
|
|
|
|
size_t len;
|
|
|
|
} direct;
|
|
|
|
} u;
|
|
|
|
char is_direct;
|
2020-02-10 09:06:28 +00:00
|
|
|
};
|
2019-12-07 19:41:58 +00:00
|
|
|
|
2019-12-31 15:24:58 +00:00
|
|
|
|
|
|
|
typedef struct lws_attach_item {
|
|
|
|
lws_dll2_t list;
|
|
|
|
lws_attach_cb_t cb;
|
|
|
|
void *opaque;
|
|
|
|
lws_system_states_t state;
|
|
|
|
} lws_attach_item_t;
|
|
|
|
|
2016-01-19 03:34:24 +08:00
|
|
|
/*
|
|
|
|
* the rest is managed per-context, that includes
|
|
|
|
*
|
|
|
|
* - processwide single fd -> wsi lookup
|
|
|
|
* - contextwide headers pool
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct lws_context {
|
2019-09-19 06:54:53 +01:00
|
|
|
#if defined(LWS_WITH_SERVER)
|
|
|
|
char canonical_hostname[96];
|
|
|
|
#endif
|
|
|
|
|
2019-08-18 06:29:34 +01:00
|
|
|
#if defined(LWS_WITH_FILE_OPS)
|
2017-03-03 12:38:10 +08:00
|
|
|
struct lws_plat_file_ops fops_platform;
|
2019-08-18 06:29:34 +01:00
|
|
|
#endif
|
2018-05-01 12:41:42 +08:00
|
|
|
|
2019-09-19 06:54:53 +01:00
|
|
|
#if defined(LWS_WITH_ZIP_FOPS)
|
|
|
|
struct lws_plat_file_ops fops_zip;
|
2019-08-18 06:29:34 +01:00
|
|
|
#endif
|
2018-05-01 12:41:42 +08:00
|
|
|
|
2019-12-07 19:41:58 +00:00
|
|
|
lws_system_blob_t system_blobs[LWS_SYSBLOB_TYPE_COUNT];
|
|
|
|
|
2019-09-19 06:54:53 +01:00
|
|
|
#if defined(LWS_WITH_NETWORK)
|
|
|
|
struct lws_context_per_thread pt[LWS_MAX_SMP];
|
2019-09-18 13:09:32 +01:00
|
|
|
lws_retry_bo_t default_retry;
|
2019-09-19 09:48:17 +01:00
|
|
|
lws_sorted_usec_list_t sul_system_state;
|
2019-03-24 17:54:48 +08:00
|
|
|
|
2020-01-15 08:31:28 +00:00
|
|
|
#if defined(LWS_PLAT_FREERTOS)
|
|
|
|
struct sockaddr_in frt_pipe_si;
|
|
|
|
#endif
|
|
|
|
|
2017-10-13 10:33:02 +08:00
|
|
|
#if defined(LWS_WITH_HTTP2)
|
|
|
|
struct http2_settings set;
|
|
|
|
#endif
|
2019-09-19 06:54:53 +01:00
|
|
|
|
2019-08-18 06:29:34 +01:00
|
|
|
#if defined(LWS_WITH_SERVER_STATUS)
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
struct lws_conn_stats conn_stats;
|
2019-08-18 06:29:34 +01:00
|
|
|
#endif
|
2019-09-19 06:54:53 +01:00
|
|
|
#if LWS_MAX_SMP > 1
|
|
|
|
struct lws_mutex_refcount mr;
|
|
|
|
#endif
|
|
|
|
|
2019-08-23 16:10:36 +01:00
|
|
|
#if defined(LWS_WITH_NETWORK)
|
2019-09-19 06:54:53 +01:00
|
|
|
#if defined(LWS_WITH_LIBEV)
|
|
|
|
struct lws_context_eventlibs_libev ev;
|
|
|
|
#endif
|
|
|
|
#if defined(LWS_WITH_LIBUV)
|
|
|
|
struct lws_context_eventlibs_libuv uv;
|
|
|
|
#endif
|
|
|
|
#if defined(LWS_WITH_LIBEVENT)
|
|
|
|
struct lws_context_eventlibs_libevent event;
|
|
|
|
#endif
|
2020-02-07 11:39:32 +00:00
|
|
|
#if defined(LWS_WITH_GLIB)
|
|
|
|
struct lws_context_eventlibs_glib glib;
|
|
|
|
#endif
|
2019-09-19 06:54:53 +01:00
|
|
|
|
|
|
|
#if defined(LWS_WITH_TLS)
|
|
|
|
struct lws_context_tls tls;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(LWS_WITH_SYS_ASYNC_DNS)
|
|
|
|
lws_async_dns_t async_dns;
|
|
|
|
#endif
|
|
|
|
|
2020-02-29 12:37:24 +00:00
|
|
|
#if defined(LWS_WITH_SECURE_STREAMS_SYS_AUTH_API_AMAZON_COM)
|
|
|
|
void *pol_args;
|
|
|
|
struct lws_ss_handle *hss_auth;
|
|
|
|
struct lws_ss_handle *hss_fetch_policy;
|
|
|
|
lws_sorted_usec_list_t sul_api_amazon_com;
|
|
|
|
lws_sorted_usec_list_t sul_api_amazon_com_kick;
|
|
|
|
#endif
|
|
|
|
|
2019-09-19 09:48:17 +01:00
|
|
|
lws_state_manager_t mgr_system;
|
|
|
|
lws_state_notify_link_t protocols_notify;
|
2019-09-27 14:32:59 -07:00
|
|
|
#if defined (LWS_WITH_SYS_DHCP_CLIENT)
|
|
|
|
lws_dll2_owner_t dhcpc_owner;
|
|
|
|
/**< list of ifaces with dhcpc */
|
2019-09-19 09:48:17 +01:00
|
|
|
#endif
|
|
|
|
|
2019-09-19 06:54:53 +01:00
|
|
|
/* pointers */
|
|
|
|
|
2019-01-13 06:58:21 +08:00
|
|
|
struct lws_vhost *vhost_list;
|
|
|
|
struct lws_vhost *no_listener_vhost_list;
|
|
|
|
struct lws_vhost *vhost_pending_destruction_list;
|
2019-09-19 09:48:17 +01:00
|
|
|
struct lws_vhost *vhost_system;
|
2019-09-19 06:54:53 +01:00
|
|
|
|
|
|
|
#if defined(LWS_WITH_SERVER)
|
|
|
|
const char *server_string;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct lws_event_loop_ops *event_loop_ops;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(LWS_WITH_TLS)
|
|
|
|
const struct lws_tls_ops *tls_ops;
|
|
|
|
#endif
|
2019-08-23 16:10:36 +01:00
|
|
|
|
|
|
|
#if defined(LWS_WITH_DETAILED_LATENCY)
|
|
|
|
det_lat_buf_cb_t detailed_latency_cb;
|
|
|
|
#endif
|
2019-08-18 06:29:34 +01:00
|
|
|
#if defined(LWS_WITH_PLUGINS)
|
2019-01-13 06:58:21 +08:00
|
|
|
struct lws_plugin *plugin_list;
|
2019-08-18 06:29:34 +01:00
|
|
|
#endif
|
2015-01-30 10:13:01 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
/* different implementation between unix and windows */
|
2015-12-04 09:23:56 +08:00
|
|
|
struct lws_fd_hashtable fd_hashtable[FD_HASHTABLE_MODULUS];
|
2015-01-30 10:13:01 +08:00
|
|
|
#else
|
unix plat: add minimal wsi fd map option
An lws context usually contains a processwide fd -> wsi lookup table.
This allows any possible fd returned by a *nix type OS to be immediately
converted to a wsi just by indexing an array of struct lws * the size of
the highest possible fd, as found by ulimit -n or similar.
This works modestly for Linux type systems where the default ulimit -n for
a process is 1024, it means a 4KB or 8KB lookup table for 32-bit or
64-bit systems.
However in the case your lws usage is much simpler, like one outgoing
client connection and no serving, this represents increasing waste. It's
made much worse if the system has a much larger default ulimit -n, eg 1M,
the table is occupying 4MB or 8MB, of which you will only use one.
Even so, because lws can't be sure the OS won't return a socket fd at any
number up to (ulimit -n - 1), it has to allocate the whole lookup table
at the moment.
This patch looks to see if the context creation info is setting
info->fd_limit_per_thread... if it leaves it at the default 0, then
everything is as it was before this patch. However if finds that
(info->fd_limit_per_thread * actual_number_of_service_threads) where
the default number of service threads is 1, is less than the fd limit
set by ulimit -n, lws switches to a slower lookup table scheme, which
only allocates the requested number of slots. Lookups happen then by
iterating the table and comparing rather than indexing the array
directly, which is obviously somewhat of a performance hit.
However in the case where you know lws will only have a very few wsi
maximum, this method can very usefully trade off speed to be able to
avoid the allocation sized by ulimit -n.
minimal examples for client that can make use of this are also modified
by this patch to use the smaller context allocations.
2019-05-17 01:20:07 +01:00
|
|
|
struct lws **lws_lookup;
|
|
|
|
|
2015-01-30 10:13:01 +08:00
|
|
|
#endif
|
2019-09-19 06:54:53 +01:00
|
|
|
#endif /* NETWORK */
|
2019-01-13 06:58:21 +08:00
|
|
|
|
2020-02-29 12:37:24 +00:00
|
|
|
#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API)
|
|
|
|
const char *ss_proxy_bind;
|
|
|
|
const char *ss_proxy_address;
|
|
|
|
#endif
|
|
|
|
|
2019-08-23 16:10:36 +01:00
|
|
|
#if defined(LWS_WITH_FILE_OPS)
|
|
|
|
const struct lws_plat_file_ops *fops;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct lws_context **pcontext_finalize;
|
|
|
|
const char *username, *groupname;
|
|
|
|
#if defined(LWS_WITH_DETAILED_LATENCY)
|
|
|
|
const char *detailed_latency_filepath;
|
|
|
|
#endif
|
|
|
|
|
2019-08-07 18:58:05 +01:00
|
|
|
#if defined(LWS_AMAZON_RTOS)
|
|
|
|
mbedtls_entropy_context mec;
|
|
|
|
mbedtls_ctr_drbg_context mcdc;
|
|
|
|
#endif
|
|
|
|
|
2017-07-15 14:37:04 +08:00
|
|
|
struct lws_deferred_free *deferred_free_list;
|
2018-09-02 14:35:37 +08:00
|
|
|
|
|
|
|
#if defined(LWS_WITH_THREADPOOL)
|
|
|
|
struct lws_threadpool *tp_list_head;
|
|
|
|
#endif
|
|
|
|
|
2017-09-14 13:14:11 +08:00
|
|
|
#if defined(LWS_WITH_PEER_LIMITS)
|
|
|
|
struct lws_peer **pl_hash_table;
|
|
|
|
struct lws_peer *peer_wait_list;
|
|
|
|
time_t next_cull;
|
|
|
|
#endif
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
|
2019-08-14 08:59:12 +01:00
|
|
|
const lws_system_ops_t *system_ops;
|
2020-02-29 12:37:24 +00:00
|
|
|
|
|
|
|
#if defined(LWS_WITH_SECURE_STREAMS)
|
|
|
|
const char *pss_policies_json;
|
|
|
|
const lws_ss_policy_t *pss_policies;
|
|
|
|
const lws_ss_plugin_t **pss_plugins;
|
|
|
|
struct lwsac *ac_policy;
|
|
|
|
#endif
|
|
|
|
|
2016-12-04 07:34:05 +08:00
|
|
|
void *external_baggage_free_on_destroy;
|
2015-12-26 08:56:58 +08:00
|
|
|
const struct lws_token_limits *token_limits;
|
|
|
|
void *user_space;
|
2019-08-18 06:29:34 +01:00
|
|
|
#if defined(LWS_WITH_SERVER)
|
2016-10-13 06:32:57 +08:00
|
|
|
const struct lws_protocol_vhost_options *reject_service_keywords;
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
lws_reload_func deprecation_cb;
|
2019-08-18 06:29:34 +01:00
|
|
|
#endif
|
2018-04-29 10:44:36 +08:00
|
|
|
void (*eventlib_signal_cb)(void *event_lib_handle, int signum);
|
2016-01-19 04:32:14 +08:00
|
|
|
|
2017-06-07 06:10:02 +08:00
|
|
|
#if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP)
|
|
|
|
cap_value_t caps[4];
|
|
|
|
char count_caps;
|
|
|
|
#endif
|
|
|
|
|
2019-08-23 16:10:36 +01:00
|
|
|
lws_usec_t time_up; /* monotonic */
|
|
|
|
|
2019-09-13 13:12:55 +01:00
|
|
|
uint64_t options;
|
|
|
|
|
2019-08-23 16:10:36 +01:00
|
|
|
time_t last_ws_ping_pong_check_s;
|
|
|
|
|
2019-08-18 10:35:43 +01:00
|
|
|
#if defined(LWS_PLAT_FREERTOS)
|
2017-09-11 10:23:30 +08:00
|
|
|
unsigned long time_last_state_dump;
|
|
|
|
uint32_t last_free_heap;
|
|
|
|
#endif
|
2017-05-07 10:02:03 +08:00
|
|
|
|
2015-12-26 08:56:58 +08:00
|
|
|
int max_fds;
|
2018-04-29 08:34:19 +08:00
|
|
|
int count_event_loop_static_asset_handles;
|
2019-01-23 18:06:32 +08:00
|
|
|
#if !defined(LWS_NO_DAEMONIZE)
|
|
|
|
pid_t started_with_parent;
|
|
|
|
#endif
|
2016-03-28 10:10:43 +08:00
|
|
|
int uid, gid;
|
2013-01-19 13:56:10 +08:00
|
|
|
|
2011-02-10 09:32:24 +00:00
|
|
|
int fd_random;
|
2019-08-23 16:10:36 +01:00
|
|
|
#if defined(LWS_WITH_DETAILED_LATENCY)
|
|
|
|
int latencies_fd;
|
|
|
|
#endif
|
2016-02-14 09:27:41 +08:00
|
|
|
int count_wsi_allocated;
|
2016-04-20 06:10:56 +08:00
|
|
|
int count_cgi_spawned;
|
2016-01-19 03:34:24 +08:00
|
|
|
unsigned int fd_limit_per_thread;
|
2016-02-15 20:36:02 +08:00
|
|
|
unsigned int timeout_secs;
|
2016-05-19 12:34:35 +08:00
|
|
|
unsigned int pt_serv_buf_size;
|
2016-06-02 12:32:38 +08:00
|
|
|
int max_http_header_data;
|
2018-06-19 13:27:54 +08:00
|
|
|
int max_http_header_pool;
|
2017-03-16 10:46:31 +08:00
|
|
|
int simultaneous_ssl_restriction;
|
|
|
|
int simultaneous_ssl;
|
2017-09-14 13:14:11 +08:00
|
|
|
#if defined(LWS_WITH_PEER_LIMITS)
|
|
|
|
uint32_t pl_hash_elements; /* protected by context->lock */
|
|
|
|
uint32_t count_peers; /* protected by context->lock */
|
|
|
|
unsigned short ip_limit_ah;
|
|
|
|
unsigned short ip_limit_wsi;
|
|
|
|
#endif
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
unsigned int deprecated:1;
|
2020-01-23 11:12:28 +00:00
|
|
|
unsigned int inside_context_destroy:1;
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
unsigned int being_destroyed:1;
|
|
|
|
unsigned int being_destroyed1:1;
|
2018-04-30 09:16:04 +08:00
|
|
|
unsigned int being_destroyed2:1;
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
unsigned int requested_kill:1;
|
|
|
|
unsigned int protocol_init_done:1;
|
2018-04-29 10:44:36 +08:00
|
|
|
unsigned int doing_protocol_init:1;
|
|
|
|
unsigned int done_protocol_destroy_cb:1;
|
|
|
|
unsigned int finalize_destroy_after_internal_loops_stopped:1;
|
unix plat: add minimal wsi fd map option
An lws context usually contains a processwide fd -> wsi lookup table.
This allows any possible fd returned by a *nix type OS to be immediately
converted to a wsi just by indexing an array of struct lws * the size of
the highest possible fd, as found by ulimit -n or similar.
This works modestly for Linux type systems where the default ulimit -n for
a process is 1024, it means a 4KB or 8KB lookup table for 32-bit or
64-bit systems.
However in the case your lws usage is much simpler, like one outgoing
client connection and no serving, this represents increasing waste. It's
made much worse if the system has a much larger default ulimit -n, eg 1M,
the table is occupying 4MB or 8MB, of which you will only use one.
Even so, because lws can't be sure the OS won't return a socket fd at any
number up to (ulimit -n - 1), it has to allocate the whole lookup table
at the moment.
This patch looks to see if the context creation info is setting
info->fd_limit_per_thread... if it leaves it at the default 0, then
everything is as it was before this patch. However if finds that
(info->fd_limit_per_thread * actual_number_of_service_threads) where
the default number of service threads is 1, is less than the fd limit
set by ulimit -n, lws switches to a slower lookup table scheme, which
only allocates the requested number of slots. Lookups happen then by
iterating the table and comparing rather than indexing the array
directly, which is obviously somewhat of a performance hit.
However in the case where you know lws will only have a very few wsi
maximum, this method can very usefully trade off speed to be able to
avoid the allocation sized by ulimit -n.
minimal examples for client that can make use of this are also modified
by this patch to use the smaller context allocations.
2019-05-17 01:20:07 +01:00
|
|
|
unsigned int max_fds_unrelated_to_ulimit:1;
|
2020-02-29 12:37:24 +00:00
|
|
|
unsigned int policy_updated:1;
|
2014-03-06 11:57:50 +01:00
|
|
|
|
2016-01-19 03:34:24 +08:00
|
|
|
short count_threads;
|
2016-04-06 16:15:40 +08:00
|
|
|
short plugin_protocol_count;
|
|
|
|
short plugin_extension_count;
|
2016-04-15 13:33:52 +08:00
|
|
|
short server_string_len;
|
2016-07-15 13:41:38 +08:00
|
|
|
unsigned short ws_ping_pong_interval;
|
context deprecation
1) This makes lwsws run a parent process with the original permissions.
But this process is only able to respond to SIGHUP, it doesn't do anything
else.
2) You can send this parent process a SIGHUP now to cause it to
- close listening sockets in existing lwsws processes
- mark those processes as to exit when the number of active connections
on the falls to zero
- spawn a fresh child process from scratch, using latest configuration
file content, latest plugins, etc. It can now reopen listening sockets
if it chooses to, or open different listen ports or whatever.
Notes:
1) lws_context_destroy() has been split into two pieces... the reason for
the split is the first part closes the per-vhost protocols, but since
they may have created libuv objects in the per-vhost protocol storage,
these cannot be freed until after the loop has been run.
That's the purpose of the second part of the context destruction,
lws_context_destroy2().
For compatibility, if you are not using libuv, the first part calls the
second part. However if you are using libuv, you must now call the
second part from your own main.c after the first part.
2016-12-16 07:37:43 +08:00
|
|
|
unsigned short deprecation_pending_listen_close_count;
|
2020-02-29 12:37:24 +00:00
|
|
|
#if defined(LWS_WITH_SECURE_STREAMS_PROXY_API)
|
|
|
|
uint16_t ss_proxy_port;
|
|
|
|
#endif
|
2017-09-14 13:14:11 +08:00
|
|
|
|
2017-03-03 12:38:10 +08:00
|
|
|
uint8_t max_fi;
|
2019-09-08 08:08:55 +01:00
|
|
|
uint8_t udp_loss_sim_tx_pc;
|
|
|
|
uint8_t udp_loss_sim_rx_pc;
|
2019-08-10 07:32:32 +01:00
|
|
|
|
|
|
|
#if defined(LWS_WITH_STATS)
|
|
|
|
uint8_t updated;
|
|
|
|
#endif
|
2010-12-18 15:13:50 +00:00
|
|
|
};
|
|
|
|
|
2017-07-15 14:37:04 +08:00
|
|
|
int
|
vhost_destroy: use vhost wsi reference counting to trigger destroy
This changes the vhost destroy flow to only hand off the listen
socket if another vhost sharing it, and mark the vhost as
being_destroyed.
Each tsi calls lws_check_deferred_free() once a second, if it sees
any vhost being_destroyed there, it closes all wsi on its tsi on
the same vhost, one time.
As the wsi on the vhost complete close (ie, after libuv async close
if on libuv event loop), they decrement a reference count for all
wsi open on the vhost. The tsi who closes the last one then
completes the destroy flow for the vhost itself... it's random
which tsi completes the vhost destroy but since there are no
wsi left on the vhost, and it holds the context lock, nothing
can conflict.
The advantage of this is that owning tsi do the close for wsi
that are bound to the vhost under destruction, at a time when
they are guaranteed to be idle for service, and they do it with
both vhost and context locks owned, so no other service thread
can conflict for stuff protected by those either.
For the situation the user code may have allocations attached to
the vhost, this adds args to lws_vhost_destroy() to allow destroying
the user allocations just before the vhost is freed.
2018-06-16 09:31:07 +08:00
|
|
|
lws_check_deferred_free(struct lws_context *context, int tsi, int force);
|
2017-07-15 14:37:04 +08:00
|
|
|
|
2016-03-28 10:10:43 +08:00
|
|
|
#define lws_get_context_protocol(ctx, x) ctx->vhost_list->protocols[x]
|
|
|
|
#define lws_get_vh_protocol(vh, x) vh->protocols[x]
|
|
|
|
|
2017-10-18 19:27:38 +08:00
|
|
|
int
|
|
|
|
lws_jws_base64_enc(const char *in, size_t in_len, char *out, size_t out_max);
|
|
|
|
|
2018-03-30 20:22:46 +08:00
|
|
|
void
|
|
|
|
lws_vhost_destroy1(struct lws_vhost *vh);
|
2016-07-23 14:18:25 +08:00
|
|
|
|
2016-02-14 09:27:41 +08:00
|
|
|
|
2019-08-18 10:35:43 +01:00
|
|
|
#if defined(LWS_PLAT_FREERTOS)
|
2018-02-24 08:14:17 +08:00
|
|
|
LWS_EXTERN int
|
2018-11-23 08:47:56 +08:00
|
|
|
lws_find_string_in_file(const char *filename, const char *str, int stringlen);
|
2018-02-24 08:14:17 +08:00
|
|
|
#endif
|
|
|
|
|
2016-03-13 16:44:19 +08:00
|
|
|
signed char char_to_hex(const char c);
|
2016-03-09 07:41:59 +08:00
|
|
|
|
2019-12-31 15:24:58 +00:00
|
|
|
#if defined(LWS_WITH_NETWORK)
|
|
|
|
int
|
|
|
|
lws_system_do_attach(struct lws_context_per_thread *pt);
|
|
|
|
#endif
|
2016-04-15 12:00:23 +08:00
|
|
|
|
2018-04-13 16:01:38 +08:00
|
|
|
struct lws_buflist {
|
|
|
|
struct lws_buflist *next;
|
|
|
|
size_t len;
|
|
|
|
size_t pos;
|
|
|
|
};
|
|
|
|
|
2018-05-10 16:13:26 +08:00
|
|
|
LWS_EXTERN char *
|
|
|
|
lws_strdup(const char *s);
|
|
|
|
|
2014-04-03 07:29:50 +08:00
|
|
|
LWS_EXTERN int log_level;
|
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int
|
2011-01-18 15:39:02 +00:00
|
|
|
lws_b64_selftest(void);
|
2011-02-09 08:49:14 +00:00
|
|
|
|
2011-05-23 10:00:03 +01:00
|
|
|
|
2013-02-11 17:13:32 +08:00
|
|
|
#ifndef LWS_NO_DAEMONIZE
|
2019-10-07 10:12:03 +01:00
|
|
|
LWS_EXTERN pid_t get_daemonize_pid();
|
2014-04-12 10:07:02 +08:00
|
|
|
#else
|
2018-04-19 12:53:53 +08:00
|
|
|
#define get_daemonize_pid() (0)
|
2013-02-11 17:13:32 +08:00
|
|
|
#endif
|
|
|
|
|
2014-04-03 23:34:09 +08:00
|
|
|
LWS_EXTERN void lwsl_emit_stderr(int level, const char *line);
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
#if !defined(LWS_WITH_TLS)
|
2018-04-19 12:53:53 +08:00
|
|
|
#define LWS_SSL_ENABLED(context) (0)
|
|
|
|
#define lws_context_init_server_ssl(_a, _b) (0)
|
|
|
|
#define lws_ssl_destroy(_a)
|
|
|
|
#define lws_context_init_alpn(_a)
|
|
|
|
#define lws_ssl_capable_read lws_ssl_capable_read_no_ssl
|
|
|
|
#define lws_ssl_capable_write lws_ssl_capable_write_no_ssl
|
|
|
|
#define lws_ssl_pending lws_ssl_pending_no_ssl
|
|
|
|
#define lws_server_socket_service_ssl(_b, _c) (0)
|
|
|
|
#define lws_ssl_close(_a) (0)
|
|
|
|
#define lws_ssl_context_destroy(_a)
|
|
|
|
#define lws_ssl_SSL_CTX_destroy(_a)
|
|
|
|
#define lws_ssl_remove_wsi_from_buffered_list(_a)
|
|
|
|
#define __lws_ssl_remove_wsi_from_buffered_list(_a)
|
|
|
|
#define lws_context_init_ssl_library(_a)
|
2019-08-02 09:47:23 +01:00
|
|
|
#define lws_context_deinit_ssl_library(_a)
|
2018-04-19 12:53:53 +08:00
|
|
|
#define lws_tls_check_all_cert_lifetimes(_a)
|
|
|
|
#define lws_tls_acme_sni_cert_destroy(_a)
|
2014-04-03 10:17:00 +08:00
|
|
|
#endif
|
2017-10-18 09:41:44 +08:00
|
|
|
|
2014-04-03 07:16:40 +08:00
|
|
|
|
2018-03-02 14:22:49 +08:00
|
|
|
|
2019-01-13 06:58:21 +08:00
|
|
|
#if LWS_MAX_SMP > 1
|
2018-06-27 07:15:39 +08:00
|
|
|
#define lws_context_lock(c, reason) lws_mutex_refcount_lock(&c->mr, reason)
|
|
|
|
#define lws_context_unlock(c) lws_mutex_refcount_unlock(&c->mr)
|
2017-09-14 13:14:11 +08:00
|
|
|
|
2018-03-02 15:31:35 +08:00
|
|
|
static LWS_INLINE void
|
|
|
|
lws_vhost_lock(struct lws_vhost *vhost)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&vhost->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static LWS_INLINE void
|
|
|
|
lws_vhost_unlock(struct lws_vhost *vhost)
|
|
|
|
{
|
|
|
|
pthread_mutex_unlock(&vhost->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
#else
|
|
|
|
#define lws_pt_mutex_init(_a) (void)(_a)
|
2016-05-12 20:22:35 -05:00
|
|
|
#define lws_pt_mutex_destroy(_a) (void)(_a)
|
2018-03-02 14:22:49 +08:00
|
|
|
#define lws_pt_lock(_a, b) (void)(_a)
|
2016-01-26 20:56:56 +08:00
|
|
|
#define lws_pt_unlock(_a) (void)(_a)
|
2018-06-27 07:15:39 +08:00
|
|
|
#define lws_context_lock(_a, _b) (void)(_a)
|
2017-09-14 13:14:11 +08:00
|
|
|
#define lws_context_unlock(_a) (void)(_a)
|
2018-03-02 15:31:35 +08:00
|
|
|
#define lws_vhost_lock(_a) (void)(_a)
|
|
|
|
#define lws_vhost_unlock(_a) (void)(_a)
|
2018-03-02 14:22:49 +08:00
|
|
|
#define lws_pt_stats_lock(_a) (void)(_a)
|
|
|
|
#define lws_pt_stats_unlock(_a) (void)(_a)
|
2016-01-26 20:56:56 +08:00
|
|
|
#endif
|
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2015-12-15 21:15:58 +08:00
|
|
|
lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, int len);
|
2014-04-15 18:40:31 +02:00
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, int len);
|
2014-04-15 18:40:31 +02:00
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_ssl_pending_no_ssl(struct lws *wsi);
|
2015-08-19 16:23:33 +02:00
|
|
|
|
2017-10-26 18:53:34 +08:00
|
|
|
int
|
|
|
|
lws_tls_check_cert_lifetime(struct lws_vhost *vhost);
|
|
|
|
|
2017-10-18 19:27:38 +08:00
|
|
|
int lws_jws_selftest(void);
|
2018-11-27 08:36:08 +08:00
|
|
|
int lws_jwe_selftest(void);
|
2016-03-20 11:59:53 +08:00
|
|
|
|
2016-04-06 16:15:40 +08:00
|
|
|
int
|
|
|
|
lws_protocol_init(struct lws_context *context);
|
|
|
|
|
2016-06-18 09:00:04 +08:00
|
|
|
int
|
2018-09-02 14:35:37 +08:00
|
|
|
lws_bind_protocol(struct lws *wsi, const struct lws_protocols *p,
|
|
|
|
const char *reason);
|
2016-06-18 09:00:04 +08:00
|
|
|
|
2018-11-28 12:16:01 +08:00
|
|
|
const struct lws_protocol_vhost_options *
|
|
|
|
lws_vhost_protocol_options(struct lws_vhost *vh, const char *name);
|
|
|
|
|
2016-06-26 06:29:20 +08:00
|
|
|
const struct lws_http_mount *
|
|
|
|
lws_find_mount(struct lws *wsi, const char *uri_ptr, int uri_len);
|
|
|
|
|
2014-12-04 23:15:27 +01:00
|
|
|
/*
|
|
|
|
* custom allocator
|
|
|
|
*/
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN void *
|
2017-10-04 07:10:39 +08:00
|
|
|
lws_realloc(void *ptr, size_t size, const char *reason);
|
2014-12-04 23:15:27 +01:00
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN void * LWS_WARN_UNUSED_RESULT
|
2017-10-04 07:10:39 +08:00
|
|
|
lws_zalloc(size_t size, const char *reason);
|
2014-12-04 23:15:27 +01:00
|
|
|
|
2017-01-30 15:02:54 +08:00
|
|
|
#ifdef LWS_PLAT_OPTEE
|
2017-10-04 07:10:39 +08:00
|
|
|
void *lws_malloc(size_t size, const char *reason);
|
2017-01-30 15:02:54 +08:00
|
|
|
void lws_free(void *p);
|
|
|
|
#define lws_free_set_NULL(P) do { lws_free(P); (P) = NULL; } while(0)
|
|
|
|
#else
|
2017-10-04 07:10:39 +08:00
|
|
|
#define lws_malloc(S, R) lws_realloc(NULL, S, R)
|
|
|
|
#define lws_free(P) lws_realloc(P, 0, "lws_free")
|
|
|
|
#define lws_free_set_NULL(P) do { lws_realloc(P, 0, "free"); (P) = NULL; } while(0)
|
2017-01-30 15:02:54 +08:00
|
|
|
#endif
|
2014-12-04 23:15:27 +01:00
|
|
|
|
2017-10-24 11:59:44 +08:00
|
|
|
int
|
|
|
|
lws_create_event_pipes(struct lws_context *context);
|
|
|
|
|
2018-08-01 06:52:03 +08:00
|
|
|
int
|
2018-06-23 12:56:21 +08:00
|
|
|
lws_plat_apply_FD_CLOEXEC(int n);
|
|
|
|
|
2017-03-03 12:38:10 +08:00
|
|
|
const struct lws_plat_file_ops *
|
|
|
|
lws_vfs_select_fops(const struct lws_plat_file_ops *fops, const char *vfs_path,
|
|
|
|
const char **vpath);
|
|
|
|
|
2015-12-06 09:15:27 +08:00
|
|
|
/* lws_plat_ */
|
2014-04-03 07:16:40 +08:00
|
|
|
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_plat_context_early_init(void);
|
|
|
|
LWS_EXTERN void
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_plat_context_early_destroy(struct lws_context *context);
|
2014-04-03 07:16:40 +08:00
|
|
|
LWS_EXTERN void
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_plat_context_late_destroy(struct lws_context *context);
|
2018-11-15 16:33:54 +08:00
|
|
|
|
2014-04-03 07:16:40 +08:00
|
|
|
LWS_EXTERN int
|
2015-12-10 07:14:16 +08:00
|
|
|
lws_plat_init(struct lws_context *context,
|
2018-04-27 08:27:16 +08:00
|
|
|
const struct lws_context_creation_info *info);
|
2019-03-24 17:54:48 +08:00
|
|
|
LWS_EXTERN int
|
2019-04-21 19:51:03 +01:00
|
|
|
lws_plat_drop_app_privileges(struct lws_context *context, int actually_drop);
|
2015-11-02 20:34:12 +08:00
|
|
|
|
2019-03-25 08:07:28 +08:00
|
|
|
#if defined(LWS_WITH_UNIX_SOCK)
|
|
|
|
int
|
|
|
|
lws_plat_user_colon_group_to_ids(const char *u_colon_g, uid_t *puid, gid_t *pgid);
|
|
|
|
#endif
|
|
|
|
|
2019-09-27 14:32:59 -07:00
|
|
|
int
|
|
|
|
lws_plat_ifname_to_hwaddr(int fd, const char *ifname, uint8_t *hwaddr, int len);
|
|
|
|
|
2018-10-09 10:29:42 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_check_byte_utf8(unsigned char state, unsigned char c);
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2015-12-30 11:43:36 +08:00
|
|
|
lws_check_utf8(unsigned char *state, unsigned char *buf, size_t len);
|
2018-11-23 08:47:56 +08:00
|
|
|
LWS_EXTERN int alloc_file(struct lws_context *context, const char *filename,
|
|
|
|
uint8_t **buf, lws_filepos_t *amount);
|
2017-10-18 09:41:44 +08:00
|
|
|
|
2018-04-29 10:44:36 +08:00
|
|
|
void
|
|
|
|
lws_context_destroy2(struct lws_context *context);
|
2019-01-13 06:58:21 +08:00
|
|
|
|
2019-08-17 20:46:53 +01:00
|
|
|
#if !defined(PRIu64)
|
|
|
|
#define PRIu64 "llu"
|
|
|
|
#endif
|
2018-04-20 10:33:23 +08:00
|
|
|
|
2019-07-05 09:38:32 +01:00
|
|
|
#if defined(LWS_WITH_ABSTRACT)
|
|
|
|
#include "private-lib-abstract.h"
|
|
|
|
#endif
|
|
|
|
|
2015-11-02 20:34:12 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
};
|
|
|
|
#endif
|
2019-09-19 10:15:56 +01:00
|
|
|
|
|
|
|
#endif
|