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
|
|
|
*
|
2018-04-19 12:53:53 +08:00
|
|
|
* Copyright (C) 2010 - 2018 Andy Green <andy@warmcat.com>
|
2010-11-08 20:20:42 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation:
|
|
|
|
* version 2.1 of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301 USA
|
|
|
|
*/
|
2013-02-06 15:30:33 +09:00
|
|
|
|
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
|
|
|
|
2016-02-21 21:25:48 +08:00
|
|
|
#if defined(LWS_WITH_CGI) && defined(LWS_HAVE_VFORK)
|
2018-04-19 12:53:53 +08:00
|
|
|
#define _GNU_SOURCE
|
2016-02-21 21:25:48 +08:00
|
|
|
#endif
|
|
|
|
|
2017-11-05 09:02:16 +08:00
|
|
|
#if defined(__COVERITY__)
|
2018-04-19 12:53:53 +08:00
|
|
|
typedef struct { long double x, y; } _Float128;
|
2017-11-05 09:02:16 +08:00
|
|
|
#endif
|
|
|
|
|
2015-06-24 16:46:02 +02:00
|
|
|
#ifdef LWS_HAVE_SYS_TYPES_H
|
2018-04-19 12:53:53 +08:00
|
|
|
#include <sys/types.h>
|
2013-02-06 15:30:33 +09:00
|
|
|
#endif
|
2013-02-06 15:26:58 +09:00
|
|
|
|
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>
|
2017-09-08 13:54:36 +02:00
|
|
|
#include <inttypes.h>
|
2017-02-18 17:26:40 +08:00
|
|
|
|
|
|
|
#if defined(LWS_WITH_ESP32)
|
2018-04-19 12:53:53 +08:00
|
|
|
#define MSG_NOSIGNAL 0
|
|
|
|
#define SOMAXCONN 3
|
2017-02-18 17:26:40 +08:00
|
|
|
#endif
|
|
|
|
|
2016-07-23 14:18:25 +08:00
|
|
|
#define STORE_IN_ROM
|
2015-12-04 07:22:44 +08:00
|
|
|
#include <assert.h>
|
2016-01-26 20:56:56 +08:00
|
|
|
#if LWS_MAX_SMP > 1
|
2018-04-19 12:53:53 +08:00
|
|
|
#include <pthread.h>
|
2016-01-26 20:56:56 +08:00
|
|
|
#endif
|
2010-11-08 20:20:42 +00:00
|
|
|
|
2015-06-24 16:46:02 +02:00
|
|
|
#ifdef LWS_HAVE_SYS_STAT_H
|
2018-04-19 12:53:53 +08:00
|
|
|
#include <sys/stat.h>
|
2014-02-28 00:57:19 +01:00
|
|
|
#endif
|
2011-03-02 22:03:47 +00:00
|
|
|
|
2013-10-28 15:18:04 +01:00
|
|
|
#if defined(WIN32) || defined(_WIN32)
|
2017-10-31 06:40:04 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
2017-06-09 20:20:42 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#if (WINVER < 0x0501)
|
|
|
|
#undef WINVER
|
|
|
|
#undef _WIN32_WINNT
|
|
|
|
#define WINVER 0x0501
|
|
|
|
#define _WIN32_WINNT WINVER
|
|
|
|
#endif
|
2014-04-07 11:28:08 +02:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#define LWS_NO_DAEMONIZE
|
|
|
|
#define LWS_ERRNO WSAGetLastError()
|
|
|
|
#define LWS_EAGAIN WSAEWOULDBLOCK
|
|
|
|
#define LWS_EALREADY WSAEALREADY
|
|
|
|
#define LWS_EINPROGRESS WSAEINPROGRESS
|
|
|
|
#define LWS_EINTR WSAEINTR
|
|
|
|
#define LWS_EISCONN WSAEISCONN
|
|
|
|
#define LWS_EWOULDBLOCK WSAEWOULDBLOCK
|
|
|
|
#define MSG_NOSIGNAL 0
|
|
|
|
#define SHUT_RDWR SD_BOTH
|
|
|
|
#define SOL_TCP IPPROTO_TCP
|
|
|
|
#define SHUT_WR SD_SEND
|
|
|
|
|
|
|
|
#define compatible_close(fd) closesocket(fd)
|
|
|
|
#define lws_set_blocking_send(wsi) wsi->sock_send_blocking = 1
|
|
|
|
#define lws_socket_is_valid(x) (!!x)
|
|
|
|
#define LWS_SOCK_INVALID 0
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <ws2tcpip.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <tchar.h>
|
|
|
|
#ifdef LWS_HAVE_IN6ADDR_H
|
|
|
|
#include <in6addr.h>
|
|
|
|
#endif
|
|
|
|
#include <mstcpip.h>
|
|
|
|
#include <io.h>
|
|
|
|
|
|
|
|
#if !defined(LWS_HAVE_ATOLL)
|
|
|
|
#if defined(LWS_HAVE__ATOI64)
|
|
|
|
#define atoll _atoi64
|
|
|
|
#else
|
|
|
|
#warning No atoll or _atoi64 available, using atoi
|
|
|
|
#define atoll atoi
|
|
|
|
#endif
|
|
|
|
#endif
|
2014-04-15 18:39:26 +02:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#ifndef __func__
|
|
|
|
#define __func__ __FUNCTION__
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef LWS_HAVE__VSNPRINTF
|
|
|
|
#define vsnprintf _vsnprintf
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* we don't have an implementation for this on windows... */
|
|
|
|
int kill(int pid, int sig);
|
|
|
|
int fork(void);
|
|
|
|
#ifndef SIGINT
|
|
|
|
#define SIGINT 2
|
|
|
|
#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
|
|
|
|
2014-04-02 14:25:10 +08:00
|
|
|
#else /* not windows --> */
|
2015-11-02 20:34:12 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
2017-02-22 09:50:11 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#ifndef __cplusplus
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/socket.h>
|
2018-04-27 14:36:10 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#if defined(LWS_BUILTIN_GETIFADDRS)
|
|
|
|
#include "./misc/getifaddrs.h"
|
|
|
|
#else
|
|
|
|
#if !defined(LWS_WITH_ESP32)
|
|
|
|
#if defined(__HAIKU__)
|
|
|
|
#define _BSD_SOURCE
|
|
|
|
#endif
|
|
|
|
#include <ifaddrs.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if defined (__ANDROID__)
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#elif defined (__sun) || defined(__HAIKU__) || defined(__QNX__)
|
|
|
|
#include <syslog.h>
|
|
|
|
#else
|
|
|
|
#if !defined(LWS_WITH_ESP32)
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#include <netdb.h>
|
2017-11-30 12:40:46 +08:00
|
|
|
#if !defined(LWS_WITH_ESP32)
|
2018-04-19 12:53:53 +08:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/tcp.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <poll.h>
|
2017-09-24 15:30:42 +00:00
|
|
|
#endif
|
2018-04-19 12:53:53 +08:00
|
|
|
#if defined(LWS_WITH_LIBEV)
|
|
|
|
#include <ev.h>
|
|
|
|
#endif
|
|
|
|
#ifdef LWS_WITH_LIBUV
|
|
|
|
#include <uv.h>
|
|
|
|
#endif
|
|
|
|
#if defined(LWS_WITH_LIBEVENT) && !defined(LWS_HIDE_LIBEVENT)
|
|
|
|
#include <event2/event.h>
|
2016-07-23 14:18:25 +08:00
|
|
|
#endif
|
2015-11-02 08:21:08 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#ifndef LWS_NO_FORK
|
|
|
|
#ifdef LWS_HAVE_SYS_PRCTL_H
|
|
|
|
#include <sys/prctl.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
2015-11-02 08:21:08 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#include <sys/time.h>
|
2010-11-08 20:20:42 +00:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#define LWS_ERRNO errno
|
|
|
|
#define LWS_EAGAIN EAGAIN
|
|
|
|
#define LWS_EALREADY EALREADY
|
|
|
|
#define LWS_EINPROGRESS EINPROGRESS
|
|
|
|
#define LWS_EINTR EINTR
|
|
|
|
#define LWS_EISCONN EISCONN
|
|
|
|
#define LWS_EWOULDBLOCK EWOULDBLOCK
|
2016-07-11 07:28:23 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#define lws_set_blocking_send(wsi)
|
2015-11-02 13:10:33 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#define lws_socket_is_valid(x) (x >= 0)
|
|
|
|
#define LWS_SOCK_INVALID (-1)
|
|
|
|
#endif /* not windows */
|
2011-03-02 22:03:47 +00:00
|
|
|
|
2015-06-24 16:46:02 +02:00
|
|
|
#ifndef LWS_HAVE_BZERO
|
2018-04-19 12:53:53 +08:00
|
|
|
#ifndef bzero
|
|
|
|
#define bzero(b, len) (memset((b), '\0', (len)), (void) 0)
|
|
|
|
#endif
|
2014-11-18 18:25:24 +08:00
|
|
|
#endif
|
2014-02-28 13:17:49 +01:00
|
|
|
|
2015-06-24 16:46:02 +02:00
|
|
|
#ifndef LWS_HAVE_STRERROR
|
2018-04-19 12:53:53 +08:00
|
|
|
#define strerror(x) ""
|
2011-02-14 20:56:24 +00:00
|
|
|
#endif
|
|
|
|
|
2010-11-08 20:20:42 +00:00
|
|
|
#include "libwebsockets.h"
|
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#if defined(LWS_WITH_TLS)
|
|
|
|
#include "tls/private.h"
|
2016-11-07 21:36:05 +01:00
|
|
|
#endif
|
|
|
|
|
2014-04-02 14:25:10 +08:00
|
|
|
#if defined(WIN32) || defined(_WIN32)
|
2018-04-19 12:53:53 +08:00
|
|
|
#include <gettimeofday.h>
|
2014-04-02 14:25:10 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#ifndef BIG_ENDIAN
|
|
|
|
#define BIG_ENDIAN 4321 /* to show byte order (taken from gcc) */
|
|
|
|
#endif
|
|
|
|
#ifndef LITTLE_ENDIAN
|
|
|
|
#define LITTLE_ENDIAN 1234
|
|
|
|
#endif
|
|
|
|
#ifndef BYTE_ORDER
|
|
|
|
#define BYTE_ORDER LITTLE_ENDIAN
|
|
|
|
#endif
|
2014-04-02 14:25:10 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#undef __P
|
|
|
|
#ifndef __P
|
|
|
|
#if __STDC__
|
|
|
|
#define __P(protos) protos
|
|
|
|
#else
|
|
|
|
#define __P(protos) ()
|
|
|
|
#endif
|
|
|
|
#endif
|
2014-04-02 14:25:10 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#else /* not windows */
|
|
|
|
static inline int compatible_close(int fd) { return close(fd); }
|
2014-04-02 14:25:10 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/time.h>
|
2014-04-02 14:25:10 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
#include <machine/endian.h>
|
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
#include <sys/endian.h>
|
|
|
|
#elif defined(__linux__)
|
|
|
|
#include <endian.h>
|
|
|
|
#endif
|
2014-04-02 14:25:10 +08:00
|
|
|
#endif
|
2014-12-07 03:36:11 +01:00
|
|
|
|
2015-11-02 20:34:12 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2014-04-02 14:25:10 +08:00
|
|
|
|
2014-09-16 14:05:13 +04:00
|
|
|
#if defined(__QNX__)
|
|
|
|
#include <gulliver.h>
|
|
|
|
#if defined(__LITTLEENDIAN__)
|
|
|
|
#define BYTE_ORDER __LITTLEENDIAN__
|
|
|
|
#define LITTLE_ENDIAN __LITTLEENDIAN__
|
|
|
|
#define BIG_ENDIAN 4321 /* to show byte order (taken from gcc); for suppres warning that BIG_ENDIAN is not defined. */
|
|
|
|
#endif
|
|
|
|
#if defined(__BIGENDIAN__)
|
|
|
|
#define BYTE_ORDER __BIGENDIAN__
|
|
|
|
#define LITTLE_ENDIAN 1234 /* to show byte order (taken from gcc); for suppres warning that LITTLE_ENDIAN is not defined. */
|
|
|
|
#define BIG_ENDIAN __BIGENDIAN__
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-09-09 06:49:44 +08:00
|
|
|
#if defined(__sun) && defined(__GNUC__)
|
2017-03-23 23:56:25 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#include <arpa/nameser_compat.h>
|
2017-03-23 23:56:25 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#if !defined (BYTE_ORDER)
|
|
|
|
#define BYTE_ORDER __BYTE_ORDER__
|
|
|
|
#endif
|
2017-03-23 23:56:25 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#if !defined(LITTLE_ENDIAN)
|
|
|
|
#define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
|
|
|
|
#endif
|
2017-03-23 23:56:25 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#if !defined(BIG_ENDIAN)
|
|
|
|
#define BIG_ENDIAN __ORDER_BIG_ENDIAN__
|
|
|
|
#endif
|
2016-09-09 06:49:44 +08:00
|
|
|
|
2017-03-23 23:56:25 +08:00
|
|
|
#endif /* sun + GNUC */
|
|
|
|
|
2014-04-02 14:25:10 +08:00
|
|
|
#if !defined(BYTE_ORDER)
|
2018-04-19 12:53:53 +08:00
|
|
|
#define BYTE_ORDER __BYTE_ORDER
|
2014-04-02 14:25:10 +08:00
|
|
|
#endif
|
|
|
|
#if !defined(LITTLE_ENDIAN)
|
2018-04-19 12:53:53 +08:00
|
|
|
#define LITTLE_ENDIAN __LITTLE_ENDIAN
|
2014-04-02 14:25:10 +08:00
|
|
|
#endif
|
|
|
|
#if !defined(BIG_ENDIAN)
|
2018-04-19 12:53:53 +08:00
|
|
|
#define BIG_ENDIAN __BIG_ENDIAN
|
2014-04-02 14:25:10 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2011-02-14 17:52:39 +00:00
|
|
|
/*
|
|
|
|
* Mac OSX as well as iOS do not define the MSG_NOSIGNAL flag,
|
|
|
|
* but happily have something equivalent in the SO_NOSIGPIPE flag.
|
|
|
|
*/
|
|
|
|
#ifdef __APPLE__
|
2012-04-09 15:09:01 +08:00
|
|
|
#define MSG_NOSIGNAL SO_NOSIGPIPE
|
2011-02-14 17:52:39 +00:00
|
|
|
#endif
|
|
|
|
|
2016-09-09 06:49:44 +08:00
|
|
|
/*
|
|
|
|
* Solaris 11.X only supports POSIX 2001, MSG_NOSIGNAL appears in
|
|
|
|
* POSIX 2008.
|
|
|
|
*/
|
|
|
|
#ifdef __sun
|
2018-04-19 12:53:53 +08:00
|
|
|
#define MSG_NOSIGNAL 0
|
2016-09-09 06:49:44 +08:00
|
|
|
#endif
|
|
|
|
|
2015-01-30 10:13:01 +08:00
|
|
|
#ifdef _WIN32
|
2018-04-19 12:53:53 +08:00
|
|
|
#ifndef FD_HASHTABLE_MODULUS
|
|
|
|
#define FD_HASHTABLE_MODULUS 32
|
|
|
|
#endif
|
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
|
|
|
|
|
2017-10-18 09:41:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All lws_tls...() functions must return this type, converting the
|
|
|
|
* native backend result and doing the extra work to determine which one
|
|
|
|
* as needed.
|
|
|
|
*
|
|
|
|
* Native TLS backend return codes are NOT ALLOWED outside the backend.
|
|
|
|
*
|
|
|
|
* Non-SSL mode also uses these types.
|
|
|
|
*/
|
|
|
|
enum lws_ssl_capable_status {
|
|
|
|
LWS_SSL_CAPABLE_ERROR = -1, /* it failed */
|
|
|
|
LWS_SSL_CAPABLE_DONE = 0, /* it succeeded */
|
|
|
|
LWS_SSL_CAPABLE_MORE_SERVICE_READ = -2, /* retry WANT_READ */
|
|
|
|
LWS_SSL_CAPABLE_MORE_SERVICE_WRITE = -3, /* retry WANT_WRITE */
|
|
|
|
LWS_SSL_CAPABLE_MORE_SERVICE = -4, /* general retry */
|
|
|
|
};
|
|
|
|
|
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-04-02 11:55:17 +08:00
|
|
|
typedef uint32_t lws_wsi_state_t;
|
|
|
|
|
|
|
|
/*
|
2018-04-11 13:39:42 +08:00
|
|
|
* The wsi->role_ops pointer decides almost everything about what role the wsi
|
|
|
|
* will play, h2, raw, ws, etc.
|
2018-04-02 11:55:17 +08:00
|
|
|
*
|
2018-04-11 13:39:42 +08:00
|
|
|
* However there are a few additional flags needed that vary, such as if the
|
|
|
|
* role is a client or server side, if it has that concept. And the connection
|
|
|
|
* fulfilling the role, has a separate dynamic state.
|
|
|
|
*
|
|
|
|
* 31 16 15 0
|
|
|
|
* [ role flags ] [ state ]
|
|
|
|
*
|
|
|
|
* The role flags part is generally invariant for the lifetime of the wsi,
|
|
|
|
* although it can change if the connection role itself does, eg, if the
|
|
|
|
* connection upgrades from H1 -> WS1 the role flags may be changed at that
|
|
|
|
* point.
|
2018-04-02 11:55:17 +08:00
|
|
|
*
|
|
|
|
* The state part reflects the dynamic connection state, and the states are
|
|
|
|
* reused between roles.
|
|
|
|
*
|
|
|
|
* None of the internal role or state representations are made available outside
|
2018-04-11 13:39:42 +08:00
|
|
|
* of lws internals. Even for lws internals, if you add stuff here, please keep
|
|
|
|
* the constants inside this header only by adding necessary helpers here and
|
|
|
|
* use the helpers in the actual code. This is to ease any future refactors.
|
|
|
|
*
|
|
|
|
* Notice LWSIFR_ENCAP means we have a parent wsi that actually carries our
|
|
|
|
* data as a stream inside a different protocol.
|
2018-04-02 11:55:17 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define _RS 16
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
#define LWSIFR_CLIENT (0x1000 << _RS) /* client side */
|
|
|
|
#define LWSIFR_SERVER (0x2000 << _RS) /* server side */
|
2018-04-02 11:55:17 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
#define LWSIFR_P_ENCAP_H2 (0x0100 << _RS) /* we are encapsulated by h2 */
|
2018-04-02 11:55:17 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
enum lwsi_role {
|
|
|
|
LWSI_ROLE_MASK = (0xffff << _RS),
|
|
|
|
LWSI_ROLE_ENCAP_MASK = (0x0f00 << _RS),
|
2018-04-02 11:55:17 +08:00
|
|
|
};
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
#define lwsi_role(wsi) (wsi->wsistate & LWSI_ROLE_MASK)
|
2018-04-02 11:55:17 +08:00
|
|
|
#if !defined (_DEBUG)
|
|
|
|
#define lwsi_set_role(wsi, role) wsi->wsistate = \
|
2018-04-13 16:01:38 +08:00
|
|
|
(wsi->wsistate & (~LWSI_ROLE_MASK)) | role
|
2018-04-02 11:55:17 +08:00
|
|
|
#else
|
|
|
|
void lwsi_set_role(struct lws *wsi, lws_wsi_state_t role);
|
|
|
|
#endif
|
2018-04-11 13:39:42 +08:00
|
|
|
|
2018-04-02 11:55:17 +08:00
|
|
|
#define lwsi_role_client(wsi) (!!(wsi->wsistate & LWSIFR_CLIENT))
|
2018-04-11 13:39:42 +08:00
|
|
|
#define lwsi_role_server(wsi) (!!(wsi->wsistate & LWSIFR_SERVER))
|
|
|
|
#define lwsi_role_h2_ENCAPSULATION(wsi) \
|
|
|
|
((wsi->wsistate & LWSI_ROLE_ENCAP_MASK) == LWSIFR_P_ENCAP_H2)
|
2018-04-02 11:55:17 +08:00
|
|
|
|
|
|
|
/* Pollout wants a callback in this state */
|
|
|
|
#define LWSIFS_POCB (0x100)
|
|
|
|
/* Before any protocol connection was established */
|
2018-04-11 13:39:42 +08:00
|
|
|
#define LWSIFS_NOT_EST (0x200)
|
2018-04-02 11:55:17 +08:00
|
|
|
|
|
|
|
enum lwsi_state {
|
|
|
|
|
|
|
|
/* Phase 1: pre-transport */
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
LRS_UNCONNECTED = LWSIFS_NOT_EST | 0,
|
|
|
|
LRS_WAITING_CONNECT = LWSIFS_NOT_EST | 1,
|
2018-04-02 11:55:17 +08:00
|
|
|
|
|
|
|
/* Phase 2: establishing intermediaries on top of transport */
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
LRS_WAITING_PROXY_REPLY = LWSIFS_NOT_EST | 2,
|
|
|
|
LRS_WAITING_SSL = LWSIFS_NOT_EST | 3,
|
|
|
|
LRS_WAITING_SOCKS_GREETING_REPLY = LWSIFS_NOT_EST | 4,
|
|
|
|
LRS_WAITING_SOCKS_CONNECT_REPLY = LWSIFS_NOT_EST | 5,
|
|
|
|
LRS_WAITING_SOCKS_AUTH_REPLY = LWSIFS_NOT_EST | 6,
|
2018-04-02 11:55:17 +08:00
|
|
|
|
|
|
|
/* Phase 3: establishing tls tunnel */
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
LRS_SSL_INIT = LWSIFS_NOT_EST | 7,
|
|
|
|
LRS_SSL_ACK_PENDING = LWSIFS_NOT_EST | 8,
|
|
|
|
LRS_PRE_WS_SERVING_ACCEPT = LWSIFS_NOT_EST | 9,
|
2018-04-02 11:55:17 +08:00
|
|
|
|
|
|
|
/* Phase 4: connected */
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
LRS_WAITING_SERVER_REPLY = LWSIFS_NOT_EST | 10,
|
|
|
|
LRS_H2_AWAIT_PREFACE = LWSIFS_NOT_EST | 11,
|
|
|
|
LRS_H2_AWAIT_SETTINGS = LWSIFS_NOT_EST |
|
2018-04-02 11:55:17 +08:00
|
|
|
LWSIFS_POCB | 12,
|
|
|
|
|
|
|
|
/* Phase 5: protocol logically established */
|
|
|
|
|
|
|
|
LRS_H2_CLIENT_SEND_SETTINGS = LWSIFS_POCB | 13,
|
|
|
|
LRS_H2_WAITING_TO_SEND_HEADERS = LWSIFS_POCB | 14,
|
|
|
|
LRS_DEFERRING_ACTION = LWSIFS_POCB | 15,
|
2018-04-11 13:39:42 +08:00
|
|
|
LRS_IDLING = 16,
|
|
|
|
LRS_H1C_ISSUE_HANDSHAKE = 17,
|
|
|
|
LRS_H1C_ISSUE_HANDSHAKE2 = 18,
|
|
|
|
LRS_ISSUE_HTTP_BODY = 19,
|
|
|
|
LRS_ISSUING_FILE = 20,
|
|
|
|
LRS_HEADERS = 21,
|
|
|
|
LRS_BODY = 22,
|
|
|
|
LRS_ESTABLISHED = LWSIFS_POCB | 23,
|
2018-04-02 11:55:17 +08:00
|
|
|
|
|
|
|
/* Phase 6: finishing */
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
LRS_WAITING_TO_SEND_CLOSE = LWSIFS_POCB | 24,
|
|
|
|
LRS_RETURNED_CLOSE = LWSIFS_POCB | 25,
|
2018-04-20 10:33:23 +08:00
|
|
|
LRS_AWAITING_CLOSE_ACK = LWSIFS_POCB | 26,
|
2018-04-11 13:39:42 +08:00
|
|
|
LRS_FLUSHING_BEFORE_CLOSE = LWSIFS_POCB | 27,
|
|
|
|
LRS_SHUTDOWN = 28,
|
2018-04-02 11:55:17 +08:00
|
|
|
|
|
|
|
/* Phase 7: dead */
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
LRS_DEAD_SOCKET = 29,
|
2018-04-02 11:55:17 +08:00
|
|
|
|
|
|
|
LRS_MASK = 0xffff
|
2010-11-08 20:20:42 +00:00
|
|
|
};
|
|
|
|
|
2018-04-02 11:55:17 +08:00
|
|
|
#define lwsi_state(wsi) ((enum lwsi_state)(wsi->wsistate & LRS_MASK))
|
2018-04-11 13:39:42 +08:00
|
|
|
#define lwsi_state_PRE_CLOSE(wsi) ((enum lwsi_state)(wsi->wsistate_pre_close & LRS_MASK))
|
|
|
|
#define lwsi_state_est(wsi) (!(wsi->wsistate & LWSIFS_NOT_EST))
|
|
|
|
#define lwsi_state_est_PRE_CLOSE(wsi) (!(wsi->wsistate_pre_close & LWSIFS_NOT_EST))
|
|
|
|
#define lwsi_state_can_handle_POLLOUT(wsi) (wsi->wsistate & LWSIFS_POCB)
|
2018-04-02 11:55:17 +08:00
|
|
|
#if !defined (_DEBUG)
|
|
|
|
#define lwsi_set_state(wsi, lrs) wsi->wsistate = \
|
|
|
|
(wsi->wsistate & (~LRS_MASK)) | lrs
|
|
|
|
#else
|
|
|
|
void lwsi_set_state(struct lws *wsi, lws_wsi_state_t lrs);
|
|
|
|
#endif
|
2017-11-14 07:35:05 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
/*
|
|
|
|
* internal role-specific ops
|
|
|
|
*/
|
|
|
|
struct lws_context_per_thread;
|
|
|
|
struct lws_role_ops {
|
|
|
|
const char *name;
|
2018-04-12 15:56:38 +08:00
|
|
|
const char *alpn;
|
2018-04-11 13:39:42 +08:00
|
|
|
/*
|
|
|
|
* After http headers have parsed, this is the last chance for a role
|
|
|
|
* to upgrade the connection to something else using the headers.
|
|
|
|
* ws-over-h2 is upgraded from h2 like this.
|
|
|
|
*/
|
|
|
|
int (*check_upgrades)(struct lws *wsi);
|
2018-04-25 08:42:18 +08:00
|
|
|
/* role-specific context init during context creation */
|
2018-04-11 13:39:42 +08:00
|
|
|
int (*init_context)(struct lws_context *context,
|
2018-04-27 08:27:16 +08:00
|
|
|
const struct lws_context_creation_info *info);
|
2018-04-11 13:39:42 +08:00
|
|
|
/* role-specific per-vhost init during vhost creation */
|
|
|
|
int (*init_vhost)(struct lws_vhost *vh,
|
2018-04-27 08:27:16 +08:00
|
|
|
const struct lws_context_creation_info *info);
|
2018-04-25 08:42:18 +08:00
|
|
|
/* role-specific per-vhost destructor during vhost destroy */
|
|
|
|
int (*destroy_vhost)(struct lws_vhost *vh);
|
2018-04-11 13:39:42 +08:00
|
|
|
/* generic 1Hz callback for the role itself */
|
|
|
|
int (*periodic_checks)(struct lws_context *context, int tsi,
|
|
|
|
time_t now);
|
|
|
|
/* chance for the role to force POLLIN without network activity */
|
|
|
|
int (*service_flag_pending)(struct lws_context *context, int tsi);
|
|
|
|
/* an fd using this role has POLLIN signalled */
|
|
|
|
int (*handle_POLLIN)(struct lws_context_per_thread *pt, struct lws *wsi,
|
|
|
|
struct lws_pollfd *pollfd);
|
|
|
|
/* an fd using the role wanted a POLLOUT callback and now has it */
|
|
|
|
int (*handle_POLLOUT)(struct lws *wsi);
|
|
|
|
/* perform user pollout */
|
|
|
|
int (*perform_user_POLLOUT)(struct lws *wsi);
|
|
|
|
/* do effective callback on writeable */
|
|
|
|
int (*callback_on_writable)(struct lws *wsi);
|
|
|
|
/* connection-specific tx credit in bytes */
|
2018-04-26 08:30:12 +08:00
|
|
|
lws_fileofs_t (*tx_credit)(struct lws *wsi);
|
2018-04-11 13:39:42 +08:00
|
|
|
/* role-specific write formatting */
|
|
|
|
int (*write_role_protocol)(struct lws *wsi, unsigned char *buf,
|
|
|
|
size_t len, enum lws_write_protocol *wp);
|
|
|
|
|
|
|
|
/* get encapsulation parent */
|
|
|
|
struct lws * (*encapsulation_parent)(struct lws *wsi);
|
|
|
|
|
2018-04-12 15:56:38 +08:00
|
|
|
/* role-specific destructor */
|
|
|
|
int (*alpn_negotiated)(struct lws *wsi, const char *alpn);
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
/* chance for the role to handle close in the protocol */
|
|
|
|
int (*close_via_role_protocol)(struct lws *wsi,
|
|
|
|
enum lws_close_status reason);
|
|
|
|
/* role-specific close processing */
|
|
|
|
int (*close_role)(struct lws_context_per_thread *pt, struct lws *wsi);
|
|
|
|
/* role-specific connection close processing */
|
|
|
|
int (*close_kill_connection)(struct lws *wsi,
|
|
|
|
enum lws_close_status reason);
|
|
|
|
/* role-specific destructor */
|
|
|
|
int (*destroy_role)(struct lws *wsi);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* the callback reasons for WRITEABLE for client, server
|
|
|
|
* (just client applies if no concept of client or server)
|
|
|
|
*/
|
|
|
|
uint16_t writeable_cb[2];
|
|
|
|
/*
|
|
|
|
* the callback reasons for CLOSE for client, server
|
|
|
|
* (just client applies if no concept of client or server)
|
|
|
|
*/
|
|
|
|
uint16_t close_cb[2];
|
|
|
|
};
|
|
|
|
|
2018-04-25 08:42:18 +08:00
|
|
|
/* null-terminated array of pointers to roles lws built with */
|
|
|
|
extern const struct lws_role_ops *available_roles[];
|
|
|
|
|
|
|
|
#define LWS_FOR_EVERY_AVAILABLE_ROLE_START(xx) { \
|
|
|
|
const struct lws_role_ops **ppxx = available_roles; \
|
|
|
|
while (*ppxx) { \
|
|
|
|
const struct lws_role_ops *xx = *ppxx++;
|
|
|
|
|
|
|
|
#define LWS_FOR_EVERY_AVAILABLE_ROLE_END }}
|
|
|
|
|
|
|
|
/* core roles */
|
2018-04-19 12:53:53 +08:00
|
|
|
extern struct lws_role_ops role_ops_raw_skt, role_ops_raw_file, role_ops_listen,
|
|
|
|
role_ops_pipe;
|
2018-04-11 13:39:42 +08:00
|
|
|
|
2018-04-25 08:42:18 +08:00
|
|
|
/* bring in role private declarations */
|
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
|
|
|
#include "roles/http/private.h"
|
2018-04-17 15:35:15 +08:00
|
|
|
#else
|
2018-04-19 12:53:53 +08:00
|
|
|
#define lwsi_role_http(wsi) (0)
|
2018-04-17 15:35:15 +08:00
|
|
|
#endif
|
2018-04-19 12:53:53 +08:00
|
|
|
|
|
|
|
#if defined(LWS_ROLE_H1)
|
|
|
|
#include "roles/h1/private.h"
|
|
|
|
#else
|
|
|
|
#define lwsi_role_h1(wsi) (0)
|
|
|
|
#endif
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
#if defined(LWS_ROLE_H2)
|
2018-04-19 12:53:53 +08:00
|
|
|
#include "roles/h2/private.h"
|
2018-04-11 13:39:42 +08:00
|
|
|
#else
|
2018-04-19 12:53:53 +08:00
|
|
|
#define lwsi_role_h2(wsi) (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(LWS_ROLE_WS)
|
|
|
|
#include "roles/ws/private.h"
|
|
|
|
#else
|
|
|
|
#define lwsi_role_ws(wsi) (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(LWS_ROLE_CGI)
|
|
|
|
#include "roles/cgi/private.h"
|
|
|
|
#else
|
|
|
|
#define lwsi_role_cgi(wsi) (0)
|
2018-04-11 13:39:42 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
enum {
|
|
|
|
LWS_HP_RET_BAIL_OK,
|
|
|
|
LWS_HP_RET_BAIL_DIE,
|
|
|
|
LWS_HP_RET_USER_SERVICE,
|
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
LWS_HPI_RET_WSI_ALREADY_DIED, /* we closed it */
|
2018-04-12 15:56:38 +08:00
|
|
|
LWS_HPI_RET_HANDLED, /* no probs */
|
2018-04-17 15:35:15 +08:00
|
|
|
LWS_HPI_RET_PLEASE_CLOSE_ME, /* close it for us */
|
2018-04-11 13:39:42 +08:00
|
|
|
|
|
|
|
LWS_UPG_RET_DONE,
|
|
|
|
LWS_UPG_RET_CONTINUE,
|
|
|
|
LWS_UPG_RET_BAIL
|
|
|
|
};
|
|
|
|
|
2017-05-05 11:38:34 -04:00
|
|
|
/* enums of socks version */
|
|
|
|
enum socks_version {
|
|
|
|
SOCKS_VERSION_4 = 4,
|
|
|
|
SOCKS_VERSION_5 = 5
|
|
|
|
};
|
|
|
|
|
|
|
|
/* enums of subnegotiation version */
|
|
|
|
enum socks_subnegotiation_version {
|
|
|
|
SOCKS_SUBNEGOTIATION_VERSION_1 = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* enums of socks commands */
|
|
|
|
enum socks_command {
|
|
|
|
SOCKS_COMMAND_CONNECT = 1,
|
|
|
|
SOCKS_COMMAND_BIND = 2,
|
|
|
|
SOCKS_COMMAND_UDP_ASSOCIATE = 3
|
|
|
|
};
|
|
|
|
|
|
|
|
/* enums of socks address type */
|
|
|
|
enum socks_atyp {
|
|
|
|
SOCKS_ATYP_IPV4 = 1,
|
|
|
|
SOCKS_ATYP_DOMAINNAME = 3,
|
|
|
|
SOCKS_ATYP_IPV6 = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
/* enums of socks authentication methods */
|
|
|
|
enum socks_auth_method {
|
|
|
|
SOCKS_AUTH_NO_AUTH = 0,
|
|
|
|
SOCKS_AUTH_GSSAPI = 1,
|
|
|
|
SOCKS_AUTH_USERNAME_PASSWORD = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
/* enums of subnegotiation status */
|
|
|
|
enum socks_subnegotiation_status {
|
|
|
|
SOCKS_SUBNEGOTIATION_STATUS_SUCCESS = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* enums of socks request reply */
|
|
|
|
enum socks_request_reply {
|
|
|
|
SOCKS_REQUEST_REPLY_SUCCESS = 0,
|
|
|
|
SOCKS_REQUEST_REPLY_FAILURE_GENERAL = 1,
|
|
|
|
SOCKS_REQUEST_REPLY_CONNECTION_NOT_ALLOWED = 2,
|
|
|
|
SOCKS_REQUEST_REPLY_NETWORK_UNREACHABLE = 3,
|
|
|
|
SOCKS_REQUEST_REPLY_HOST_UNREACHABLE = 4,
|
|
|
|
SOCKS_REQUEST_REPLY_CONNECTION_REFUSED = 5,
|
|
|
|
SOCKS_REQUEST_REPLY_TTL_EXPIRED = 6,
|
|
|
|
SOCKS_REQUEST_REPLY_COMMAND_NOT_SUPPORTED = 7,
|
|
|
|
SOCKS_REQUEST_REPLY_ATYP_NOT_SUPPORTED = 8
|
|
|
|
};
|
|
|
|
|
|
|
|
/* enums used to generate socks messages */
|
|
|
|
enum socks_msg_type {
|
|
|
|
/* greeting */
|
|
|
|
SOCKS_MSG_GREETING,
|
|
|
|
/* credential, user name and password */
|
|
|
|
SOCKS_MSG_USERNAME_PASSWORD,
|
|
|
|
/* connect command */
|
|
|
|
SOCKS_MSG_CONNECT
|
|
|
|
};
|
|
|
|
|
2013-03-16 11:24:23 +08:00
|
|
|
enum {
|
|
|
|
LWS_RXFLOW_ALLOW = (1 << 0),
|
|
|
|
LWS_RXFLOW_PENDING_CHANGE = (1 << 1),
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2017-09-28 11:29:03 +08:00
|
|
|
#if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBUV) || defined(LWS_WITH_LIBEVENT)
|
2016-02-14 09:27:41 +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
|
2016-02-14 09:27:41 +08:00
|
|
|
ev_io ev_watcher;
|
|
|
|
#endif
|
2017-09-28 11:29:03 +08:00
|
|
|
#ifdef LWS_WITH_LIBUV
|
2016-02-14 09:27:41 +08:00
|
|
|
uv_poll_t uv_watcher;
|
2017-03-15 19:41:11 +05:30
|
|
|
#endif
|
2017-09-28 11:29:03 +08:00
|
|
|
#ifdef LWS_WITH_LIBEVENT
|
2017-03-15 19:41:11 +05:30
|
|
|
struct event *event_watcher;
|
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
|
2016-02-14 09:27:41 +08:00
|
|
|
ev_signal ev_watcher;
|
|
|
|
#endif
|
2017-09-28 11:29:03 +08:00
|
|
|
#ifdef LWS_WITH_LIBUV
|
2016-02-14 09:27:41 +08:00
|
|
|
uv_signal_t uv_watcher;
|
2017-03-15 19:41:11 +05:30
|
|
|
#endif
|
2017-09-28 11:29:03 +08:00
|
|
|
#ifdef LWS_WITH_LIBEVENT
|
2017-03-15 19:41:11 +05:30
|
|
|
struct event *event_watcher;
|
2016-02-14 09:27:41 +08:00
|
|
|
#endif
|
|
|
|
struct lws_context *context;
|
2014-03-23 13:25:07 +08:00
|
|
|
};
|
2016-02-14 09:27:41 +08:00
|
|
|
#endif
|
2014-03-23 13:25:07 +08:00
|
|
|
|
2015-01-30 10:13:01 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define LWS_FD_HASH(fd) ((fd ^ (fd >> 8) ^ (fd >> 16)) % FD_HASHTABLE_MODULUS)
|
2015-12-04 09:23:56 +08:00
|
|
|
struct lws_fd_hashtable {
|
2015-12-04 11:08:32 +08:00
|
|
|
struct lws **wsi;
|
2015-01-30 10:13:01 +08:00
|
|
|
int length;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2015-12-25 12:44:12 +08:00
|
|
|
|
2018-03-19 16:37:37 +08:00
|
|
|
#define LWS_HRTIMER_NOWAIT (0x7fffffffffffffffll)
|
|
|
|
|
2016-01-19 03:34:24 +08:00
|
|
|
/*
|
|
|
|
* so we can have n connections being serviced simultaneously,
|
|
|
|
* these things need to be isolated per-thread.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct lws_context_per_thread {
|
2016-01-26 20:56:56 +08:00
|
|
|
#if LWS_MAX_SMP > 1
|
|
|
|
pthread_mutex_t lock;
|
2018-03-02 14:22:49 +08:00
|
|
|
pthread_mutex_t lock_stats;
|
2016-01-26 20:56:56 +08:00
|
|
|
#endif
|
2016-01-19 03:34:24 +08:00
|
|
|
struct lws_pollfd *fds;
|
2017-11-12 09:16:46 +08:00
|
|
|
volatile struct lws_foreign_thread_pollfd * volatile foreign_pfd_list;
|
2018-04-27 15:20:56 +08:00
|
|
|
|
2018-04-25 08:42:18 +08:00
|
|
|
#if defined(LWS_ROLE_WS) && !defined(LWS_WITHOUT_EXTENSIONS)
|
|
|
|
struct lws_pt_role_ws ws;
|
2018-04-19 12:53:53 +08:00
|
|
|
#endif
|
2018-04-27 15:20:56 +08:00
|
|
|
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
|
|
|
struct lws_pt_role_http http;
|
|
|
|
#endif
|
|
|
|
|
2018-03-19 16:37:37 +08:00
|
|
|
struct lws_dll_lws dll_head_timeout;
|
|
|
|
struct lws_dll_lws dll_head_hrtimer;
|
2018-04-17 15:35:15 +08:00
|
|
|
struct lws_dll_lws dll_head_buflist; /* guys with pending rxflow */
|
2017-09-28 11:29:03 +08:00
|
|
|
#if defined(LWS_WITH_LIBUV) || defined(LWS_WITH_LIBEVENT)
|
2016-02-27 11:03:27 +08:00
|
|
|
struct lws_context *context;
|
2016-08-14 14:04:56 +02:00
|
|
|
#endif
|
2018-04-27 15:20:56 +08:00
|
|
|
|
|
|
|
|
2018-03-02 14:22:49 +08:00
|
|
|
#if defined(LWS_HAVE_PTHREAD_H)
|
|
|
|
const char *last_lock_reason;
|
|
|
|
#endif
|
2018-04-27 15:20:56 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
#if defined(LWS_WITH_TLS)
|
2016-01-19 03:34:24 +08:00
|
|
|
struct lws *pending_read_list; /* linked list */
|
|
|
|
#endif
|
2017-09-28 11:29:03 +08:00
|
|
|
#if defined(LWS_WITH_LIBEV)
|
2016-02-14 09:27:41 +08:00
|
|
|
struct ev_loop *io_loop_ev;
|
|
|
|
#endif
|
2017-09-28 11:29:03 +08:00
|
|
|
#if defined(LWS_WITH_LIBUV)
|
2016-02-14 09:27:41 +08:00
|
|
|
uv_loop_t *io_loop_uv;
|
|
|
|
uv_signal_t signals[8];
|
2016-02-27 11:03:27 +08:00
|
|
|
uv_timer_t uv_timeout_watcher;
|
2018-03-19 16:37:37 +08:00
|
|
|
uv_timer_t uv_hrtimer;
|
2016-04-06 09:23:16 +08:00
|
|
|
uv_idle_t uv_idle;
|
2016-02-14 09:27:41 +08:00
|
|
|
#endif
|
2017-09-28 11:29:03 +08:00
|
|
|
#if defined(LWS_WITH_LIBEVENT)
|
2017-03-15 19:41:11 +05:30
|
|
|
struct event_base *io_loop_event_base;
|
|
|
|
#endif
|
2017-09-28 11:29:03 +08:00
|
|
|
#if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBUV) || defined(LWS_WITH_LIBEVENT)
|
2016-02-14 09:27:41 +08:00
|
|
|
struct lws_signal_watcher w_sigint;
|
|
|
|
unsigned char ev_loop_foreign:1;
|
2018-03-30 20:22:46 +08:00
|
|
|
unsigned char event_loop_destroy_processing_done:1;
|
2016-01-26 20:56:56 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
unsigned long count_conns;
|
2016-01-19 03:34:24 +08:00
|
|
|
/*
|
|
|
|
* usable by anything in the service code, but only if the scope
|
|
|
|
* does not last longer than the service action (since next service
|
|
|
|
* of any socket can likewise use it and overwrite)
|
|
|
|
*/
|
|
|
|
unsigned char *serv_buf;
|
2014-03-28 15:44:56 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
WSAEVENT *events;
|
|
|
|
#endif
|
2017-10-24 11:59:44 +08:00
|
|
|
lws_sockfd_type dummy_pipe_fds[2];
|
|
|
|
struct lws *pipe_wsi;
|
|
|
|
|
2017-11-12 09:16:46 +08:00
|
|
|
volatile unsigned char inside_poll;
|
|
|
|
volatile unsigned char foreign_spinlock;
|
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
unsigned int fds_count;
|
|
|
|
|
2016-02-27 11:03:27 +08:00
|
|
|
unsigned char tid;
|
2018-03-11 11:26:06 +08:00
|
|
|
unsigned char lock_depth;
|
2018-03-02 14:22:49 +08:00
|
|
|
#if LWS_MAX_SMP > 1
|
|
|
|
pthread_t lock_owner;
|
|
|
|
#endif
|
2016-01-19 03:34:24 +08:00
|
|
|
};
|
|
|
|
|
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 {
|
|
|
|
unsigned long long rx, tx;
|
2017-10-13 10:33:02 +08:00
|
|
|
unsigned long h1_conn, h1_trans, h2_trans, ws_upg, h2_alpn, h2_subs,
|
|
|
|
h2_upg, rejected;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
lws_sum_stats(const struct lws_context *ctx, struct lws_conn_stats *cs);
|
|
|
|
|
2017-12-07 10:16:17 +08:00
|
|
|
struct lws_timed_vh_protocol {
|
|
|
|
struct lws_timed_vh_protocol *next;
|
|
|
|
const struct lws_protocols *protocol;
|
|
|
|
time_t time;
|
|
|
|
int reason;
|
|
|
|
};
|
|
|
|
|
2016-03-28 10:10:43 +08:00
|
|
|
/*
|
|
|
|
* virtual host -related context information
|
|
|
|
* vhostwide SSL context
|
|
|
|
* vhostwide proxy
|
|
|
|
*
|
2016-10-02 02:21:03 +03:00
|
|
|
* hierarchy:
|
2016-03-28 10:10:43 +08:00
|
|
|
*
|
|
|
|
* context -> vhost -> wsi
|
|
|
|
*
|
|
|
|
* incoming connection non-SSL vhost binding:
|
|
|
|
*
|
|
|
|
* listen socket -> wsi -> select vhost after first headers
|
|
|
|
*
|
|
|
|
* incoming connection SSL vhost binding:
|
|
|
|
*
|
|
|
|
* SSL SNI -> wsi -> bind after SSL negotiation
|
|
|
|
*/
|
|
|
|
|
2017-10-28 11:33:34 +08:00
|
|
|
struct lws_tls_ss_pieces;
|
|
|
|
|
2018-04-12 15:56:38 +08:00
|
|
|
struct alpn_ctx {
|
|
|
|
uint8_t data[23];
|
|
|
|
uint8_t len;
|
|
|
|
};
|
|
|
|
|
2016-03-28 10:10:43 +08:00
|
|
|
struct lws_vhost {
|
|
|
|
char proxy_basic_auth_token[128];
|
2018-03-02 15:31:35 +08:00
|
|
|
#if LWS_MAX_SMP > 1
|
|
|
|
pthread_mutex_t lock;
|
|
|
|
#endif
|
2018-04-25 06:53:30 +08:00
|
|
|
|
|
|
|
#if defined(LWS_ROLE_H2)
|
|
|
|
struct lws_vhost_role_h2 h2;
|
2017-10-13 10:33:02 +08:00
|
|
|
#endif
|
2018-04-27 15:20:56 +08:00
|
|
|
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
|
|
|
struct lws_vhost_role_http http;
|
|
|
|
#endif
|
2018-04-25 08:42:18 +08:00
|
|
|
#if defined(LWS_ROLE_WS) && !defined(LWS_WITHOUT_EXTENSIONS)
|
2018-04-25 06:53:30 +08:00
|
|
|
struct lws_vhost_role_ws ws;
|
|
|
|
#endif
|
|
|
|
|
2017-05-05 11:38:34 -04:00
|
|
|
#if defined(LWS_WITH_SOCKS5)
|
|
|
|
char socks_proxy_address[128];
|
|
|
|
char socks_user[96];
|
|
|
|
char socks_password[96];
|
2018-02-19 10:19:40 +08:00
|
|
|
#endif
|
|
|
|
#if defined(LWS_WITH_LIBEV)
|
|
|
|
struct lws_io_watcher w_accept;
|
2016-07-23 14:18:25 +08:00
|
|
|
#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
|
|
|
struct lws_conn_stats conn_stats;
|
2016-03-28 10:10:43 +08:00
|
|
|
struct lws_context *context;
|
|
|
|
struct lws_vhost *vhost_next;
|
2018-04-27 15:20:56 +08:00
|
|
|
|
2016-03-28 10:10:43 +08:00
|
|
|
struct lws *lserv_wsi;
|
|
|
|
const char *name;
|
|
|
|
const char *iface;
|
2017-11-02 09:20:17 +08:00
|
|
|
char *alloc_cert_path;
|
|
|
|
char *key_path;
|
2017-11-30 12:40:46 +08:00
|
|
|
#if !defined(LWS_WITH_ESP32) && !defined(OPTEE_TA) && !defined(WIN32)
|
2017-06-02 14:07:35 -03:00
|
|
|
int bind_iface;
|
|
|
|
#endif
|
2016-03-28 10:10:43 +08:00
|
|
|
const struct lws_protocols *protocols;
|
2016-04-06 16:15:40 +08:00
|
|
|
void **protocol_vh_privs;
|
2016-05-02 06:01:59 +08:00
|
|
|
const struct lws_protocol_vhost_options *pvo;
|
2016-08-27 17:07:06 +08:00
|
|
|
const struct lws_protocol_vhost_options *headers;
|
2016-04-16 08:40:35 +08:00
|
|
|
struct lws **same_vh_protocol_list;
|
2018-03-29 13:32:33 +08:00
|
|
|
struct lws_vhost *no_listener_vhost_list;
|
2018-03-26 12:05:04 +08:00
|
|
|
#if !defined(LWS_NO_CLIENT)
|
|
|
|
struct lws_dll_lws dll_active_client_conns;
|
|
|
|
#endif
|
2018-04-27 15:20:56 +08:00
|
|
|
|
2018-04-12 15:56:38 +08:00
|
|
|
const char *alpn;
|
2018-04-11 13:39:42 +08:00
|
|
|
#if defined(LWS_WITH_TLS)
|
2017-10-18 09:41:44 +08:00
|
|
|
lws_tls_ctx *ssl_ctx;
|
|
|
|
lws_tls_ctx *ssl_client_ctx;
|
2017-10-28 11:33:34 +08:00
|
|
|
struct lws_tls_ss_pieces *ss; /* for acme tls certs */
|
2017-11-02 09:20:17 +08:00
|
|
|
char ecdh_curve[16];
|
2018-04-12 15:56:38 +08:00
|
|
|
struct alpn_ctx alpn_ctx;
|
2016-03-28 10:10:43 +08:00
|
|
|
#endif
|
2017-09-28 11:29:03 +08:00
|
|
|
#if defined(LWS_WITH_MBEDTLS)
|
2017-10-18 09:41:44 +08:00
|
|
|
lws_tls_x509 *x509_client_CA;
|
2017-09-02 10:50:54 +08:00
|
|
|
#endif
|
2018-04-25 06:53:30 +08:00
|
|
|
|
2017-12-07 10:16:17 +08:00
|
|
|
struct lws_timed_vh_protocol *timed_vh_protocol_list;
|
2017-08-29 15:37:16 +08:00
|
|
|
void *user;
|
2016-03-28 10:10:43 +08:00
|
|
|
|
|
|
|
int listen_port;
|
2018-04-27 15:20:56 +08:00
|
|
|
|
2017-05-05 11:38:34 -04:00
|
|
|
#if defined(LWS_WITH_SOCKS5)
|
|
|
|
unsigned int socks_proxy_port;
|
|
|
|
#endif
|
2016-04-14 15:09:01 +08:00
|
|
|
unsigned int options;
|
2016-03-28 10:10:43 +08:00
|
|
|
int count_protocols;
|
|
|
|
int ka_time;
|
|
|
|
int ka_probes;
|
|
|
|
int ka_interval;
|
2016-04-12 16:26:03 +08:00
|
|
|
int keepalive_timeout;
|
2017-07-26 11:49:41 +08:00
|
|
|
int timeout_secs_ah_idle;
|
2017-06-20 11:46:49 +08:00
|
|
|
int ssl_info_event_mask;
|
2016-04-15 12:00:23 +08:00
|
|
|
#ifdef LWS_WITH_ACCESS_LOG
|
|
|
|
int log_fd;
|
|
|
|
#endif
|
2016-03-28 10:10:43 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
#if defined(LWS_WITH_TLS)
|
2016-03-28 10:10:43 +08:00
|
|
|
int use_ssl;
|
|
|
|
int allow_non_ssl_on_ssl_port;
|
|
|
|
unsigned int user_supplied_ssl_ctx:1;
|
|
|
|
#endif
|
2016-07-15 13:41:38 +08:00
|
|
|
|
2016-11-30 07:05:13 +08:00
|
|
|
unsigned int created_vhost_protocols:1;
|
2017-07-15 14:37:04 +08:00
|
|
|
unsigned int being_destroyed:1;
|
2017-11-02 06:22:44 +08:00
|
|
|
unsigned int skipped_certs:1;
|
2017-11-26 09:22:42 +08:00
|
|
|
unsigned int acme_challenge:1;
|
2016-11-30 07:05:13 +08:00
|
|
|
|
2016-05-06 14:24:59 +08:00
|
|
|
unsigned char default_protocol_index;
|
2017-03-07 16:06:05 +08:00
|
|
|
unsigned char raw_protocol_index;
|
2016-03-28 10:10:43 +08:00
|
|
|
};
|
|
|
|
|
2017-07-15 14:37:04 +08:00
|
|
|
struct lws_deferred_free
|
|
|
|
{
|
|
|
|
struct lws_deferred_free *next;
|
|
|
|
time_t deadline;
|
|
|
|
void *payload;
|
|
|
|
};
|
|
|
|
|
2017-09-14 13:14:11 +08:00
|
|
|
typedef union {
|
2017-09-28 11:29:03 +08:00
|
|
|
#ifdef LWS_WITH_IPV6
|
2017-09-14 13:14:11 +08:00
|
|
|
struct sockaddr_in6 sa6;
|
|
|
|
#endif
|
|
|
|
struct sockaddr_in sa4;
|
|
|
|
} sockaddr46;
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(LWS_WITH_PEER_LIMITS)
|
|
|
|
struct lws_peer {
|
|
|
|
struct lws_peer *next;
|
|
|
|
struct lws_peer *peer_wait_list;
|
|
|
|
|
|
|
|
time_t time_created;
|
|
|
|
time_t time_closed_all;
|
|
|
|
|
|
|
|
uint8_t addr[32];
|
|
|
|
uint32_t hash;
|
|
|
|
uint32_t count_wsi;
|
|
|
|
uint32_t total_wsi;
|
2018-04-27 15:20:56 +08:00
|
|
|
|
|
|
|
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
|
|
|
struct lws_peer_role_http http;
|
|
|
|
#endif
|
2017-09-14 13:14:11 +08:00
|
|
|
|
|
|
|
uint8_t af;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-03-30 20:22:46 +08:00
|
|
|
#if defined(LWS_WITH_LIBUV)
|
|
|
|
/*
|
|
|
|
* All "static" (per-pt or per-context) uv handles must
|
|
|
|
*
|
|
|
|
* - have their .data set to point to the context
|
|
|
|
*
|
|
|
|
* - contribute to context->uv_count_static_asset_handles
|
|
|
|
* counting
|
|
|
|
*/
|
|
|
|
#define LWS_UV_REFCOUNT_STATIC_HANDLE_NEW(_x, _ctx) \
|
|
|
|
{ uv_handle_t *_uht = (uv_handle_t *)(_x); _uht->data = _ctx; \
|
|
|
|
_ctx->uv_count_static_asset_handles++; }
|
|
|
|
#define LWS_UV_REFCOUNT_STATIC_HANDLE_TO_CONTEXT(_x) \
|
|
|
|
((struct lws_context *)((uv_handle_t *)((_x)->data)))
|
|
|
|
#define LWS_UV_REFCOUNT_STATIC_HANDLE_DESTROYED(_x) \
|
|
|
|
(--(LWS_UV_REFCOUNT_STATIC_HANDLE_TO_CONTEXT(_x)-> \
|
|
|
|
uv_count_static_asset_handles))
|
|
|
|
#endif
|
|
|
|
|
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 {
|
|
|
|
time_t last_timeout_check_s;
|
2016-07-15 13:41:38 +08:00
|
|
|
time_t last_ws_ping_pong_check_s;
|
2017-10-26 18:53:34 +08:00
|
|
|
time_t last_cert_check_s;
|
2016-04-15 14:01:29 +08:00
|
|
|
time_t time_up;
|
2017-11-24 11:00:59 +08:00
|
|
|
time_t time_discontiguity;
|
|
|
|
time_t time_fixup;
|
2017-03-01 14:28:56 +08:00
|
|
|
const struct lws_plat_file_ops *fops;
|
2017-03-03 12:38:10 +08:00
|
|
|
struct lws_plat_file_ops fops_platform;
|
2017-10-13 10:33:02 +08:00
|
|
|
#if defined(LWS_WITH_HTTP2)
|
|
|
|
struct http2_settings set;
|
|
|
|
#endif
|
2017-03-03 12:38:10 +08:00
|
|
|
#if defined(LWS_WITH_ZIP_FOPS)
|
|
|
|
struct lws_plat_file_ops fops_zip;
|
|
|
|
#endif
|
2016-01-19 03:34:24 +08:00
|
|
|
struct lws_context_per_thread pt[LWS_MAX_SMP];
|
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;
|
2017-09-14 13:14:11 +08:00
|
|
|
#if LWS_MAX_SMP > 1
|
|
|
|
pthread_mutex_t lock;
|
|
|
|
int lock_depth;
|
|
|
|
#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
|
2015-12-04 11:08:32 +08:00
|
|
|
struct lws **lws_lookup; /* fd to wsi */
|
2015-01-30 10:13:01 +08:00
|
|
|
#endif
|
2016-03-28 10:10:43 +08:00
|
|
|
struct lws_vhost *vhost_list;
|
2018-03-29 13:32:33 +08:00
|
|
|
struct lws_vhost *no_listener_vhost_list;
|
2017-07-15 14:37:04 +08:00
|
|
|
struct lws_vhost *vhost_pending_destruction_list;
|
2016-04-06 16:15:40 +08:00
|
|
|
struct lws_plugin *plugin_list;
|
2017-07-15 14:37:04 +08:00
|
|
|
struct lws_deferred_free *deferred_free_list;
|
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
|
|
|
|
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;
|
2016-04-15 13:33:52 +08:00
|
|
|
const char *server_string;
|
2016-10-13 06:32:57 +08:00
|
|
|
const struct lws_protocol_vhost_options *reject_service_keywords;
|
2018-04-12 15:56:38 +08:00
|
|
|
const char *alpn_default;
|
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;
|
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
|
|
|
|
|
2017-09-28 11:29:03 +08:00
|
|
|
#if defined(LWS_WITH_LIBEV)
|
2016-02-14 09:27:41 +08:00
|
|
|
lws_ev_signal_cb_t * lws_ev_sigint_cb;
|
|
|
|
#endif
|
2017-09-28 11:29:03 +08:00
|
|
|
#if defined(LWS_WITH_LIBUV)
|
2016-03-22 14:04:15 +01:00
|
|
|
uv_signal_cb lws_uv_sigint_cb;
|
2017-07-15 17:57:14 +08:00
|
|
|
uv_loop_t pu_loop;
|
2018-03-30 20:22:46 +08:00
|
|
|
int uv_count_static_asset_handles;
|
2017-03-15 19:41:11 +05:30
|
|
|
#endif
|
2017-09-28 11:29:03 +08:00
|
|
|
#if defined(LWS_WITH_LIBEVENT)
|
2018-02-19 10:39:01 +08:00
|
|
|
#if defined(LWS_HIDE_LIBEVENT)
|
|
|
|
void * lws_event_sigint_cb;
|
|
|
|
#else
|
2017-03-15 19:41:11 +05:30
|
|
|
lws_event_signal_cb_t * lws_event_sigint_cb;
|
2018-02-19 10:39:01 +08:00
|
|
|
#endif
|
2016-02-14 09:27:41 +08:00
|
|
|
#endif
|
2015-12-26 08:56:58 +08:00
|
|
|
char canonical_hostname[128];
|
|
|
|
#ifdef LWS_LATENCY
|
|
|
|
unsigned long worst_latency;
|
|
|
|
char worst_latency_info[256];
|
|
|
|
#endif
|
|
|
|
|
2017-05-07 10:02:03 +08:00
|
|
|
#if defined(LWS_WITH_STATS)
|
|
|
|
uint64_t lws_stats[LWSSTATS_SIZE];
|
|
|
|
uint64_t last_dump;
|
|
|
|
int updated;
|
|
|
|
#endif
|
2017-09-11 10:23:30 +08:00
|
|
|
#if defined(LWS_WITH_ESP32)
|
|
|
|
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;
|
2017-09-28 11:29:03 +08:00
|
|
|
#if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBUV) || defined(LWS_WITH_LIBEVENT)
|
2015-12-26 08:56:58 +08:00
|
|
|
int use_ev_sigint;
|
|
|
|
#endif
|
2013-01-19 13:56:10 +08:00
|
|
|
int started_with_parent;
|
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;
|
2017-10-16 12:52:32 +08:00
|
|
|
|
2016-02-14 09:27:41 +08:00
|
|
|
int count_wsi_allocated;
|
2016-04-20 06:10:56 +08:00
|
|
|
int count_cgi_spawned;
|
2015-12-26 08:56:58 +08:00
|
|
|
unsigned int options;
|
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;
|
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;
|
|
|
|
unsigned int being_destroyed:1;
|
|
|
|
unsigned int being_destroyed1:1;
|
|
|
|
unsigned int requested_kill:1;
|
|
|
|
unsigned int protocol_init_done:1;
|
2017-05-15 07:30:06 +08:00
|
|
|
unsigned int ssl_gate_accepts:1;
|
2017-10-21 09:06:13 +08:00
|
|
|
unsigned int doing_protocol_init;
|
2018-03-27 09:17:19 +08:00
|
|
|
unsigned int done_protocol_destroy_cb;
|
2014-03-06 11:57:50 +01:00
|
|
|
/*
|
|
|
|
* set to the Thread ID that's doing the service loop just before entry
|
|
|
|
* to poll indicates service thread likely idling in poll()
|
|
|
|
* volatile because other threads may check it as part of processing
|
|
|
|
* for pollfd event change.
|
|
|
|
*/
|
|
|
|
volatile int service_tid;
|
2015-12-24 13:00:54 +08:00
|
|
|
int service_tid_detected;
|
2014-03-06 11:57:50 +01:00
|
|
|
|
2015-12-25 12:44:12 +08:00
|
|
|
short max_http_header_pool;
|
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;
|
2017-09-14 13:14:11 +08:00
|
|
|
|
2017-03-03 12:38:10 +08:00
|
|
|
uint8_t max_fi;
|
2010-12-18 15:13:50 +00:00
|
|
|
};
|
|
|
|
|
2017-07-15 14:37:04 +08:00
|
|
|
int
|
|
|
|
lws_check_deferred_free(struct lws_context *context, int force);
|
|
|
|
|
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]
|
|
|
|
|
2016-02-14 09:27:41 +08:00
|
|
|
LWS_EXTERN void
|
2018-03-05 16:49:28 +08:00
|
|
|
__lws_close_free_wsi_final(struct lws *wsi);
|
2016-02-14 09:27:41 +08:00
|
|
|
LWS_EXTERN void
|
|
|
|
lws_libuv_closehandle(struct lws *wsi);
|
2017-06-23 10:27:52 +08:00
|
|
|
LWS_EXTERN void
|
|
|
|
lws_libuv_closehandle_manually(struct lws *wsi);
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_libuv_check_watcher_active(struct lws *wsi);
|
2016-02-14 09:27:41 +08:00
|
|
|
|
2016-04-09 07:22:40 +08:00
|
|
|
LWS_VISIBLE LWS_EXTERN int
|
2016-05-02 10:03:25 +08:00
|
|
|
lws_plat_plugins_init(struct lws_context * context, const char * const *d);
|
2016-04-09 07:22:40 +08:00
|
|
|
|
|
|
|
LWS_VISIBLE LWS_EXTERN int
|
|
|
|
lws_plat_plugins_destroy(struct lws_context * context);
|
|
|
|
|
2016-07-15 13:41:38 +08:00
|
|
|
LWS_EXTERN void
|
|
|
|
lws_restart_ws_ping_pong_timer(struct lws *wsi);
|
|
|
|
|
2016-07-23 14:18:25 +08:00
|
|
|
struct lws *
|
|
|
|
lws_adopt_socket_vhost(struct lws_vhost *vh, lws_sockfd_type accept_fd);
|
|
|
|
|
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
|
|
|
|
2014-04-11 13:14:37 +08:00
|
|
|
enum {
|
|
|
|
LWS_EV_READ = (1 << 0),
|
|
|
|
LWS_EV_WRITE = (1 << 1),
|
|
|
|
LWS_EV_START = (1 << 2),
|
|
|
|
LWS_EV_STOP = (1 << 3),
|
2016-02-14 09:27:41 +08:00
|
|
|
|
|
|
|
LWS_EV_PREPARE_DELETION = (1 << 31),
|
2014-04-11 13:14:37 +08:00
|
|
|
};
|
|
|
|
|
2017-09-28 11:29:03 +08:00
|
|
|
#if defined(LWS_WITH_LIBEV)
|
2014-04-11 13:14:37 +08:00
|
|
|
LWS_EXTERN void
|
2017-02-27 12:55:56 +08:00
|
|
|
lws_libev_accept(struct lws *new_wsi, lws_sock_file_fd_type desc);
|
2017-03-03 08:18:16 +08:00
|
|
|
LWS_EXTERN void
|
2015-12-16 18:19:08 +08:00
|
|
|
lws_libev_io(struct lws *wsi, int flags);
|
2014-04-11 13:14:37 +08:00
|
|
|
LWS_EXTERN int
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_libev_init_fd_table(struct lws_context *context);
|
2014-04-11 13:14:37 +08:00
|
|
|
LWS_EXTERN void
|
2016-02-14 09:27:41 +08:00
|
|
|
lws_libev_destroyloop(struct lws_context *context, int tsi);
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_libev_run(const struct lws_context *context, int tsi);
|
2016-03-23 09:22:11 +08:00
|
|
|
#define LWS_LIBEV_ENABLED(context) lws_check_opt(context->options, LWS_SERVER_OPTION_LIBEV)
|
2018-04-27 08:27:16 +08:00
|
|
|
LWS_EXTERN void lws_feature_status_libev(const struct lws_context_creation_info *info);
|
2014-03-23 13:25:07 +08:00
|
|
|
#else
|
2016-02-14 09:27:41 +08:00
|
|
|
#define lws_libev_accept(_a, _b) ((void) 0)
|
|
|
|
#define lws_libev_io(_a, _b) ((void) 0)
|
|
|
|
#define lws_libev_init_fd_table(_a) (0)
|
|
|
|
#define lws_libev_run(_a, _b) ((void) 0)
|
|
|
|
#define lws_libev_destroyloop(_a, _b) ((void) 0)
|
2014-03-23 13:25:07 +08:00
|
|
|
#define LWS_LIBEV_ENABLED(context) (0)
|
2018-04-11 13:39:42 +08:00
|
|
|
#if !defined(LWS_WITH_ESP32)
|
2014-04-11 13:14:37 +08:00
|
|
|
#define lws_feature_status_libev(_a) \
|
2017-09-19 17:30:06 +08:00
|
|
|
lwsl_info("libev support not compiled in\n")
|
2015-11-02 20:34:12 +08:00
|
|
|
#else
|
|
|
|
#define lws_feature_status_libev(_a)
|
|
|
|
#endif
|
2014-03-23 13:25:07 +08:00
|
|
|
#endif
|
|
|
|
|
2017-09-28 11:29:03 +08:00
|
|
|
#if defined(LWS_WITH_LIBUV)
|
2016-02-14 09:27:41 +08:00
|
|
|
LWS_EXTERN void
|
2017-02-27 12:55:56 +08:00
|
|
|
lws_libuv_accept(struct lws *new_wsi, lws_sock_file_fd_type desc);
|
2016-02-14 09:27:41 +08:00
|
|
|
LWS_EXTERN void
|
|
|
|
lws_libuv_io(struct lws *wsi, int flags);
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_libuv_init_fd_table(struct lws_context *context);
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_libuv_run(const struct lws_context *context, int tsi);
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_libuv_destroyloop(struct lws_context *context, int tsi);
|
2016-11-30 07:05:13 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_uv_initvhost(struct lws_vhost* vh, struct lws*);
|
2016-03-23 09:22:11 +08:00
|
|
|
#define LWS_LIBUV_ENABLED(context) lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV)
|
2018-04-27 08:27:16 +08:00
|
|
|
LWS_EXTERN void lws_feature_status_libuv(const struct lws_context_creation_info *info);
|
2016-02-14 09:27:41 +08:00
|
|
|
#else
|
|
|
|
#define lws_libuv_accept(_a, _b) ((void) 0)
|
|
|
|
#define lws_libuv_io(_a, _b) ((void) 0)
|
|
|
|
#define lws_libuv_init_fd_table(_a) (0)
|
|
|
|
#define lws_libuv_run(_a, _b) ((void) 0)
|
|
|
|
#define lws_libuv_destroyloop(_a, _b) ((void) 0)
|
|
|
|
#define LWS_LIBUV_ENABLED(context) (0)
|
2018-04-11 13:39:42 +08:00
|
|
|
#if !defined(LWS_WITH_ESP32)
|
2016-02-14 09:27:41 +08:00
|
|
|
#define lws_feature_status_libuv(_a) \
|
2018-03-04 09:39:45 +08:00
|
|
|
lwsl_info("libuv support not compiled in\n")
|
2016-02-14 09:27:41 +08:00
|
|
|
#else
|
|
|
|
#define lws_feature_status_libuv(_a)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2017-09-28 11:29:03 +08:00
|
|
|
#if defined(LWS_WITH_LIBEVENT)
|
2017-03-15 19:41:11 +05:30
|
|
|
LWS_EXTERN void
|
|
|
|
lws_libevent_accept(struct lws *new_wsi, lws_sock_file_fd_type desc);
|
2018-01-17 02:05:45 +01:00
|
|
|
LWS_VISIBLE void
|
|
|
|
lws_libevent_destroy(struct lws *wsi);
|
2017-03-15 19:41:11 +05:30
|
|
|
LWS_EXTERN void
|
|
|
|
lws_libevent_io(struct lws *wsi, int flags);
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_libevent_init_fd_table(struct lws_context *context);
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_libevent_destroyloop(struct lws_context *context, int tsi);
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_libevent_run(const struct lws_context *context, int tsi);
|
|
|
|
#define LWS_LIBEVENT_ENABLED(context) lws_check_opt(context->options, LWS_SERVER_OPTION_LIBEVENT)
|
|
|
|
LWS_EXTERN void lws_feature_status_libevent(struct lws_context_creation_info *info);
|
|
|
|
#else
|
|
|
|
#define lws_libevent_accept(_a, _b) ((void) 0)
|
2018-01-17 02:05:45 +01:00
|
|
|
#define lws_libevent_destroy(_a) ((void) 0)
|
2017-03-15 19:41:11 +05:30
|
|
|
#define lws_libevent_io(_a, _b) ((void) 0)
|
|
|
|
#define lws_libevent_init_fd_table(_a) (0)
|
|
|
|
#define lws_libevent_run(_a, _b) ((void) 0)
|
|
|
|
#define lws_libevent_destroyloop(_a, _b) ((void) 0)
|
|
|
|
#define LWS_LIBEVENT_ENABLED(context) (0)
|
2018-04-11 13:39:42 +08:00
|
|
|
#if !defined(LWS_WITH_ESP32)
|
2017-03-15 19:41:11 +05:30
|
|
|
#define lws_feature_status_libevent(_a) \
|
2018-03-04 09:39:45 +08:00
|
|
|
lwsl_info("libevent support not compiled in\n")
|
2017-03-15 19:41:11 +05:30
|
|
|
#else
|
|
|
|
#define lws_feature_status_libevent(_a)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-02-14 09:27:41 +08:00
|
|
|
|
2018-02-24 08:14:17 +08:00
|
|
|
#if defined(LWS_WITH_ESP32)
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_find_string_in_file(const char *filename, const char *string, int stringlen);
|
|
|
|
#endif
|
|
|
|
|
2017-09-28 11:29:03 +08:00
|
|
|
#ifdef LWS_WITH_IPV6
|
2016-06-03 21:19:40 +08:00
|
|
|
#define LWS_IPV6_ENABLED(vh) \
|
2016-06-03 17:40:12 +02:00
|
|
|
(!lws_check_opt(vh->context->options, LWS_SERVER_OPTION_DISABLE_IPV6) && \
|
2016-06-03 21:19:40 +08:00
|
|
|
!lws_check_opt(vh->options, LWS_SERVER_OPTION_DISABLE_IPV6))
|
2014-03-24 16:09:25 +08:00
|
|
|
#else
|
|
|
|
#define LWS_IPV6_ENABLED(context) (0)
|
|
|
|
#endif
|
2014-03-23 13:25:07 +08:00
|
|
|
|
2017-09-28 11:29:03 +08:00
|
|
|
#ifdef LWS_WITH_UNIX_SOCK
|
2016-04-14 12:11:51 +08:00
|
|
|
#define LWS_UNIX_SOCK_ENABLED(vhost) \
|
|
|
|
(vhost->options & LWS_SERVER_OPTION_UNIX_SOCK)
|
2016-03-30 22:47:02 -07:00
|
|
|
#else
|
2016-04-14 12:11:51 +08:00
|
|
|
#define LWS_UNIX_SOCK_ENABLED(vhost) (0)
|
2016-03-30 22:47:02 -07:00
|
|
|
#endif
|
2017-06-20 11:46:49 +08:00
|
|
|
|
2013-11-10 15:15:21 +08:00
|
|
|
enum uri_path_states {
|
|
|
|
URIPS_IDLE,
|
|
|
|
URIPS_SEEN_SLASH,
|
|
|
|
URIPS_SEEN_SLASH_DOT,
|
|
|
|
URIPS_SEEN_SLASH_DOT_DOT,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum uri_esc_states {
|
|
|
|
URIES_IDLE,
|
|
|
|
URIES_SEEN_PERCENT,
|
|
|
|
URIES_SEEN_PERCENT_H1,
|
|
|
|
};
|
2011-02-09 07:16:34 +00:00
|
|
|
|
2016-02-29 13:18:30 +08:00
|
|
|
|
|
|
|
#ifndef LWS_NO_CLIENT
|
|
|
|
struct client_info_stash {
|
2017-12-07 10:09:56 +08:00
|
|
|
char *address;
|
|
|
|
char *path;
|
|
|
|
char *host;
|
|
|
|
char *origin;
|
|
|
|
char *protocol;
|
|
|
|
char *method;
|
|
|
|
char *iface;
|
2018-04-12 15:56:38 +08:00
|
|
|
char *alpn;
|
2016-02-29 13:18:30 +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
|
|
|
|
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;
|
|
|
|
|
|
|
|
uint8_t buf[1]; /* true length of this is set by the oversize malloc */
|
|
|
|
};
|
|
|
|
|
2018-03-24 08:07:00 +08:00
|
|
|
#define lws_wsi_is_udp(___wsi) (!!___wsi->udp)
|
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#define LWS_H2_FRAME_HEADER_LENGTH 9
|
|
|
|
|
2015-12-04 11:08:32 +08:00
|
|
|
struct lws {
|
2015-12-26 08:56:58 +08:00
|
|
|
/* structs */
|
2017-11-16 11:26:00 +08:00
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
2017-12-01 11:09:32 +08:00
|
|
|
struct _lws_http_mode_related http;
|
2018-04-19 12:53:53 +08:00
|
|
|
#endif
|
|
|
|
#if defined(LWS_ROLE_H2)
|
2017-12-01 11:09:32 +08:00
|
|
|
struct _lws_h2_related h2;
|
2015-12-26 08:56:58 +08:00
|
|
|
#endif
|
2018-04-25 08:42:18 +08:00
|
|
|
#if defined(LWS_ROLE_WS)
|
|
|
|
struct _lws_websocket_related *ws; /* allocated if we upgrade to ws */
|
|
|
|
#endif
|
2015-12-26 08:56:58 +08:00
|
|
|
|
2018-04-27 14:36:10 +08:00
|
|
|
struct lws_role_ops *role_ops;
|
|
|
|
lws_wsi_state_t wsistate;
|
|
|
|
lws_wsi_state_t wsistate_pre_close;
|
|
|
|
|
2013-01-21 11:04:23 +08:00
|
|
|
/* lifetime members */
|
|
|
|
|
2017-09-28 11:29:03 +08:00
|
|
|
#if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBUV) || defined(LWS_WITH_LIBEVENT)
|
2015-12-14 08:52:03 +08:00
|
|
|
struct lws_io_watcher w_read;
|
2016-02-14 09:27:41 +08:00
|
|
|
#endif
|
2017-09-28 11:29:03 +08:00
|
|
|
#if defined(LWS_WITH_LIBEV) || defined(LWS_WITH_LIBEVENT)
|
2015-12-14 08:52:03 +08:00
|
|
|
struct lws_io_watcher w_write;
|
2017-09-14 13:14:11 +08:00
|
|
|
#endif
|
2015-12-26 08:56:58 +08:00
|
|
|
|
|
|
|
/* pointers */
|
|
|
|
|
2015-12-14 08:52:03 +08:00
|
|
|
struct lws_context *context;
|
2016-03-28 10:10:43 +08:00
|
|
|
struct lws_vhost *vhost;
|
2016-03-02 09:17:22 +08:00
|
|
|
struct lws *parent; /* points to parent, if any */
|
|
|
|
struct lws *child_list; /* points to first child */
|
|
|
|
struct lws *sibling_list; /* subsequent children at same level */
|
2018-04-25 08:42:18 +08:00
|
|
|
|
2015-12-04 11:08:32 +08:00
|
|
|
const struct lws_protocols *protocol;
|
2016-04-16 08:40:35 +08:00
|
|
|
struct lws **same_vh_protocol_prev, *same_vh_protocol_next;
|
2018-03-26 12:05:04 +08:00
|
|
|
|
2018-03-19 16:37:37 +08:00
|
|
|
struct lws_dll_lws dll_timeout;
|
|
|
|
struct lws_dll_lws dll_hrtimer;
|
2018-04-17 15:35:15 +08:00
|
|
|
struct lws_dll_lws dll_buflist; /* guys with pending rxflow */
|
2018-04-17 11:43:20 +08:00
|
|
|
|
2017-09-14 13:14:11 +08:00
|
|
|
#if defined(LWS_WITH_PEER_LIMITS)
|
|
|
|
struct lws_peer *peer;
|
2016-04-15 12:00:23 +08:00
|
|
|
#endif
|
2018-04-27 15:20:56 +08:00
|
|
|
|
2018-03-24 08:07:00 +08:00
|
|
|
struct lws_udp *udp;
|
2017-11-16 11:26:00 +08:00
|
|
|
#ifndef LWS_NO_CLIENT
|
|
|
|
struct client_info_stash *stash;
|
2018-03-27 09:17:19 +08:00
|
|
|
char *client_hostname_copy;
|
2018-03-26 12:05:04 +08:00
|
|
|
struct lws_dll_lws dll_active_client_conns;
|
|
|
|
struct lws_dll_lws dll_client_transaction_queue_head;
|
|
|
|
struct lws_dll_lws dll_client_transaction_queue;
|
2017-11-16 11:26:00 +08:00
|
|
|
#endif
|
2015-12-25 13:48:20 +08:00
|
|
|
void *user_space;
|
2017-07-19 04:39:14 +08:00
|
|
|
void *opaque_parent_data;
|
2018-04-13 16:01:38 +08:00
|
|
|
|
2018-04-17 15:35:15 +08:00
|
|
|
struct lws_buflist *buflist;
|
2018-04-13 16:01:38 +08:00
|
|
|
|
2015-12-25 13:48:20 +08:00
|
|
|
/* truncated send handling */
|
|
|
|
unsigned char *trunc_alloc; /* non-NULL means buffering in progress */
|
2016-07-23 14:18:25 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
#if defined(LWS_WITH_TLS)
|
2017-10-18 09:41:44 +08:00
|
|
|
lws_tls_conn *ssl;
|
|
|
|
lws_tls_bio *client_bio;
|
2015-12-25 13:48:20 +08:00
|
|
|
struct lws *pending_read_list_prev, *pending_read_list_next;
|
|
|
|
#endif
|
2018-04-27 14:36:10 +08:00
|
|
|
|
2015-12-26 08:56:58 +08:00
|
|
|
#ifdef LWS_LATENCY
|
|
|
|
unsigned long action_start;
|
|
|
|
unsigned long latency_start;
|
|
|
|
#endif
|
2018-04-27 14:36:10 +08:00
|
|
|
|
2017-02-27 12:55:56 +08:00
|
|
|
lws_sock_file_fd_type desc; /* .filefd / .sockfd */
|
2017-05-07 10:02:03 +08:00
|
|
|
#if defined(LWS_WITH_STATS)
|
|
|
|
uint64_t active_writable_req_us;
|
2018-04-11 13:39:42 +08:00
|
|
|
#if defined(LWS_WITH_TLS)
|
2017-12-01 11:09:32 +08:00
|
|
|
uint64_t accept_start_us;
|
|
|
|
#endif
|
2017-05-07 10:02:03 +08:00
|
|
|
#endif
|
2018-04-11 13:39:42 +08:00
|
|
|
|
2018-03-19 16:37:37 +08:00
|
|
|
lws_usec_t pending_timer;
|
2017-11-24 11:00:59 +08:00
|
|
|
time_t pending_timeout_set;
|
2017-12-01 11:09:32 +08:00
|
|
|
|
2018-04-27 14:36:10 +08:00
|
|
|
|
2018-04-02 11:55:17 +08:00
|
|
|
|
2015-12-26 08:56:58 +08:00
|
|
|
/* ints */
|
2015-12-25 13:48:20 +08:00
|
|
|
int position_in_fds_table;
|
|
|
|
unsigned int trunc_alloc_len; /* size of malloc */
|
|
|
|
unsigned int trunc_offset; /* where we are in terms of spilling */
|
|
|
|
unsigned int trunc_len; /* how much is buffered */
|
2016-03-13 16:44:19 +08:00
|
|
|
#ifndef LWS_NO_CLIENT
|
|
|
|
int chunk_remaining;
|
|
|
|
#endif
|
2016-04-22 08:53:49 +08:00
|
|
|
unsigned int cache_secs;
|
2013-01-21 11:04:23 +08:00
|
|
|
|
2013-02-11 21:43:41 +08:00
|
|
|
unsigned int hdr_parsing_completed:1;
|
2016-04-10 09:33:54 +08:00
|
|
|
unsigned int http2_substream:1;
|
2017-10-13 10:33:02 +08:00
|
|
|
unsigned int upgraded_to_http2:1;
|
2017-11-14 07:35:05 +08:00
|
|
|
unsigned int h2_stream_carries_ws:1;
|
2017-11-10 08:56:44 +08:00
|
|
|
unsigned int seen_nonpseudoheader:1;
|
2016-03-28 10:10:43 +08:00
|
|
|
unsigned int listener:1;
|
2014-07-05 10:31:12 +08:00
|
|
|
unsigned int user_space_externally_allocated:1;
|
2014-10-16 08:23:46 +08:00
|
|
|
unsigned int socket_is_permanently_unusable:1;
|
2015-12-25 13:48:20 +08:00
|
|
|
unsigned int rxflow_change_to:2;
|
2016-04-15 14:01:29 +08:00
|
|
|
unsigned int conn_stat_done:1;
|
2016-04-22 08:53:49 +08:00
|
|
|
unsigned int cache_reuse:1;
|
|
|
|
unsigned int cache_revalidate:1;
|
|
|
|
unsigned int cache_intermediaries:1;
|
2016-04-23 09:26:11 +08:00
|
|
|
unsigned int favoured_pollin:1;
|
2016-05-19 15:28:31 +08:00
|
|
|
unsigned int sending_chunked:1;
|
2018-01-14 20:09:41 +08:00
|
|
|
unsigned int interpreting:1;
|
2016-07-01 08:54:39 +08:00
|
|
|
unsigned int already_did_cce:1;
|
2016-09-06 15:36:51 +08:00
|
|
|
unsigned int told_user_closed:1;
|
2018-04-11 13:39:42 +08:00
|
|
|
unsigned int told_event_loop_closed:1;
|
2017-07-17 10:11:17 +08:00
|
|
|
unsigned int waiting_to_send_close_frame:1;
|
2018-04-20 10:33:23 +08:00
|
|
|
unsigned int close_needs_ack:1;
|
2017-06-20 15:56:48 +08:00
|
|
|
unsigned int ipv6:1;
|
2017-07-19 04:39:14 +08:00
|
|
|
unsigned int parent_carries_io:1;
|
|
|
|
unsigned int parent_pending_cb_on_writable:1;
|
2017-09-07 12:55:12 +08:00
|
|
|
unsigned int cgi_stdout_zero_length:1;
|
2017-10-13 10:33:02 +08:00
|
|
|
unsigned int seen_zero_length_recv:1;
|
|
|
|
unsigned int rxflow_will_be_applied:1;
|
2017-10-24 11:59:44 +08:00
|
|
|
unsigned int event_pipe:1;
|
2018-03-07 18:15:17 +08:00
|
|
|
unsigned int on_same_vh_list:1;
|
2018-03-26 12:05:04 +08:00
|
|
|
unsigned int handling_404:1;
|
2018-04-03 10:37:14 +08:00
|
|
|
unsigned int protocol_bind_balance:1;
|
2017-04-05 08:30:55 +08:00
|
|
|
|
2017-12-07 07:20:47 +08:00
|
|
|
unsigned int could_have_pending:1; /* detect back-to-back writes */
|
2017-12-07 13:03:06 +08:00
|
|
|
unsigned int outer_will_close:1;
|
2017-12-05 20:02:29 +08:00
|
|
|
|
2016-04-15 12:00:23 +08:00
|
|
|
#ifdef LWS_WITH_ACCESS_LOG
|
|
|
|
unsigned int access_log_pending:1;
|
|
|
|
#endif
|
2016-02-29 13:18:30 +08:00
|
|
|
#ifndef LWS_NO_CLIENT
|
|
|
|
unsigned int do_ws:1; /* whether we are doing http or ws flow */
|
2016-03-13 16:44:19 +08:00
|
|
|
unsigned int chunked:1; /* if the clientside connection is chunked */
|
2016-03-20 11:59:53 +08:00
|
|
|
unsigned int client_rx_avail:1;
|
2016-08-08 21:54:30 +08:00
|
|
|
unsigned int client_http_body_pending:1;
|
2018-03-26 12:05:04 +08:00
|
|
|
unsigned int transaction_from_pipeline_queue:1;
|
|
|
|
unsigned int keepalive_active:1;
|
|
|
|
unsigned int keepalive_rejected:1;
|
|
|
|
unsigned int client_pipeline:1;
|
2018-03-27 09:17:19 +08:00
|
|
|
unsigned int client_h2_alpn:1;
|
|
|
|
unsigned int client_h2_substream:1;
|
2016-03-20 11:55:25 +08:00
|
|
|
#endif
|
2018-04-25 06:53:30 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
#if defined(LWS_WITH_TLS)
|
2018-03-27 09:17:19 +08:00
|
|
|
unsigned int use_ssl;
|
2018-04-27 14:36:10 +08:00
|
|
|
unsigned int redirect_to_https:1;
|
2015-12-25 13:48:20 +08:00
|
|
|
#endif
|
2015-12-26 08:56:58 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
unsigned int sock_send_blocking:1;
|
|
|
|
#endif
|
2013-02-11 21:43:41 +08:00
|
|
|
|
2017-02-22 06:55:12 +08:00
|
|
|
#ifndef LWS_NO_CLIENT
|
|
|
|
unsigned short c_port;
|
|
|
|
#endif
|
2017-11-24 11:00:59 +08:00
|
|
|
unsigned short pending_timeout_limit;
|
|
|
|
|
2015-12-26 08:56:58 +08:00
|
|
|
/* chars */
|
2018-04-02 11:55:17 +08:00
|
|
|
|
2015-12-25 13:48:20 +08:00
|
|
|
char lws_rx_parse_state; /* enum lws_rx_parse_state */
|
|
|
|
char rx_frame_type; /* enum lws_write_protocol */
|
2013-02-10 16:00:47 +08:00
|
|
|
char pending_timeout; /* enum pending_timeout */
|
2016-01-19 03:34:24 +08:00
|
|
|
char tsi; /* thread service index we belong to */
|
2016-05-19 15:28:31 +08:00
|
|
|
char protocol_interpret_idx;
|
2017-02-22 06:55:12 +08:00
|
|
|
char redirects;
|
2017-10-13 10:33:02 +08:00
|
|
|
uint8_t rxflow_bitmap;
|
2016-02-21 21:25:48 +08:00
|
|
|
#ifdef LWS_WITH_CGI
|
|
|
|
char cgi_channel; /* which of stdin/out/err */
|
2016-03-09 07:41:59 +08:00
|
|
|
char hdr_state;
|
2016-02-21 21:25:48 +08:00
|
|
|
#endif
|
2016-03-13 16:44:19 +08:00
|
|
|
#ifndef LWS_NO_CLIENT
|
|
|
|
char chunk_parser; /* enum lws_chunk_parser */
|
|
|
|
#endif
|
2016-05-10 10:16:52 +08:00
|
|
|
#if defined(LWS_WITH_CGI) || !defined(LWS_NO_CLIENT)
|
|
|
|
char reason_bf; /* internal writeable callback reason bitfield */
|
2017-12-01 11:09:32 +08:00
|
|
|
#endif
|
2018-04-11 13:39:42 +08:00
|
|
|
#if defined(LWS_WITH_STATS) && defined(LWS_WITH_TLS)
|
2017-12-01 11:09:32 +08:00
|
|
|
char seen_rx;
|
2016-05-10 10:16:52 +08:00
|
|
|
#endif
|
2018-03-11 11:26:06 +08:00
|
|
|
uint8_t ws_over_h2_count;
|
2017-11-12 09:16:46 +08:00
|
|
|
/* volatile to make sure code is aware other thread can change */
|
|
|
|
volatile char handling_pollout;
|
|
|
|
volatile char leave_pollout_active;
|
2010-11-08 20:20:42 +00:00
|
|
|
};
|
|
|
|
|
2017-10-13 10:33:02 +08:00
|
|
|
#define lws_is_flowcontrolled(w) (!!(wsi->rxflow_bitmap))
|
|
|
|
|
2018-04-17 11:43:20 +08:00
|
|
|
void
|
|
|
|
lws_service_do_ripe_rxflow(struct lws_context_per_thread *pt);
|
|
|
|
|
2014-04-03 07:29:50 +08:00
|
|
|
LWS_EXTERN int log_level;
|
|
|
|
|
2016-03-12 08:18:58 +08:00
|
|
|
LWS_EXTERN int
|
2016-11-16 08:59:47 +08:00
|
|
|
lws_socket_bind(struct lws_vhost *vhost, lws_sockfd_type sockfd, int port,
|
2016-03-12 08:18:58 +08:00
|
|
|
const char *iface);
|
|
|
|
|
2017-09-28 11:29:03 +08:00
|
|
|
#if defined(LWS_WITH_IPV6)
|
2017-06-05 13:59:22 -03:00
|
|
|
LWS_EXTERN unsigned long
|
|
|
|
lws_get_addr_scope(const char *ipaddr);
|
|
|
|
#endif
|
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN void
|
2018-02-03 13:48:18 +08:00
|
|
|
lws_close_free_wsi(struct lws *wsi, enum lws_close_status, const char *caller);
|
2018-03-05 16:49:28 +08:00
|
|
|
LWS_EXTERN void
|
|
|
|
__lws_close_free_wsi(struct lws *wsi, enum lws_close_status, const char *caller);
|
2013-02-12 10:19:08 +08:00
|
|
|
|
2017-10-16 12:52:32 +08:00
|
|
|
LWS_EXTERN void
|
2018-03-05 16:49:28 +08:00
|
|
|
__lws_free_wsi(struct lws *wsi);
|
2017-10-16 12:52:32 +08:00
|
|
|
|
2014-04-03 07:42:50 +08:00
|
|
|
LWS_EXTERN int
|
2018-03-05 16:49:28 +08:00
|
|
|
__remove_wsi_socket_from_fds(struct lws *wsi);
|
2014-10-08 12:00:53 +08:00
|
|
|
LWS_EXTERN int
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_rxflow_cache(struct lws *wsi, unsigned char *buf, int n, int len);
|
2014-04-03 07:42:50 +08:00
|
|
|
|
2013-01-29 12:36:17 +08:00
|
|
|
#ifndef LWS_LATENCY
|
2015-12-06 09:15:27 +08:00
|
|
|
static inline void
|
|
|
|
lws_latency(struct lws_context *context, struct lws *wsi, const char *action,
|
|
|
|
int ret, int completion) {
|
2015-12-14 08:52:03 +08:00
|
|
|
do {
|
|
|
|
(void)context; (void)wsi; (void)action; (void)ret;
|
|
|
|
(void)completion;
|
2015-12-06 09:15:27 +08:00
|
|
|
} while (0);
|
|
|
|
}
|
|
|
|
static inline void
|
|
|
|
lws_latency_pre(struct lws_context *context, struct lws *wsi) {
|
|
|
|
do { (void)context; (void)wsi; } while (0);
|
|
|
|
}
|
2013-01-29 12:36:17 +08:00
|
|
|
#else
|
|
|
|
#define lws_latency_pre(_context, _wsi) lws_latency(_context, _wsi, NULL, 0, 0)
|
|
|
|
extern void
|
2015-12-06 09:15:27 +08:00
|
|
|
lws_latency(struct lws_context *context, struct lws *wsi, const char *action,
|
|
|
|
int ret, int completion);
|
2013-01-29 12:36:17 +08:00
|
|
|
#endif
|
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2018-04-20 10:33:23 +08:00
|
|
|
lws_ws_client_rx_sm(struct lws *wsi, unsigned char c);
|
2011-01-22 12:51:57 +00:00
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2018-03-07 18:15:17 +08:00
|
|
|
lws_parse(struct lws *wsi, unsigned char *buf, int *len);
|
2010-12-18 15:13:50 +00:00
|
|
|
|
2017-10-13 10:33:02 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
|
|
|
lws_parse_urldecode(struct lws *wsi, uint8_t *_c);
|
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2015-12-15 21:15:58 +08:00
|
|
|
lws_http_action(struct lws *wsi);
|
2014-10-08 12:00:53 +08:00
|
|
|
|
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
|
|
|
|
ah owns rxbuf
This is intended to solve a longstanding problem with the
relationship between http/1.1 keep-alive and the service
loop.
Ah now contain an rx buffer which is used during header
processing, and the ah may not be detached from the wsi
until the rx buffer is exhausted.
Having the rx buffer in the ah means we can delay using the
rx until a later service loop.
Ah which have pending rx force POLLIN service on the wsi
they are attached to automatically, so we can interleave
general service / connections with draining each ah rx
buffer.
The possible http/1.1 situations and their dispositions are:
1) exactly one set of http headers come. After processing,
the ah is detached since no pending rx left. If more
headers come later, a fresh ah is aqcuired when available
and the rx flow control blocks the read until then.
2) more that one whole set of headers come and we remain in
http mode (no upgrade). The ah is left attached and
returns to the service loop after the first set of headers.
We will get forced service due to the ah having pending
content (respecting flowcontrol) and process the pending
rx in the ah. If we use it all up, we will detach the
ah.
3) one set of http headers come with ws traffic appended.
We service the headers, do the upgrade, and keep the ah
until the remaining ws content is used. When we
exhausted the ws traffix in the ah rx buffer, we
detach the ah.
Since there can be any amount of http/1.1 pipelining on a
connection, and each may be expensive to service, it's now
enforced there is a return to the service loop after each
header set is serviced on a connection.
When I added the forced service for ah with pending buffering,
I added support for it to the windows plat code. However this
is untested.
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-15 12:37:04 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_service_flag_pending(struct lws_context *context, int tsi);
|
|
|
|
|
2017-12-07 10:16:17 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_timed_callback_remove(struct lws_vhost *vh, struct lws_timed_vh_protocol *p);
|
|
|
|
|
2017-11-30 12:40:46 +08:00
|
|
|
#if defined(_WIN32)
|
2015-12-04 11:08:32 +08:00
|
|
|
LWS_EXTERN struct lws *
|
2015-12-14 11:17:16 +08:00
|
|
|
wsi_from_fd(const struct lws_context *context, lws_sockfd_type fd);
|
2011-02-12 11:57:43 +00:00
|
|
|
|
2015-12-14 08:52:03 +08:00
|
|
|
LWS_EXTERN int
|
2015-12-04 11:08:32 +08:00
|
|
|
insert_wsi(struct lws_context *context, struct lws *wsi);
|
2015-01-30 10:13:01 +08:00
|
|
|
|
|
|
|
LWS_EXTERN int
|
2015-12-04 11:08:32 +08:00
|
|
|
delete_from_fd(struct lws_context *context, lws_sockfd_type fd);
|
2015-01-30 10:13:01 +08:00
|
|
|
#else
|
2017-11-05 14:28:57 +08:00
|
|
|
#define wsi_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()]
|
|
|
|
#define insert_wsi(A,B) assert(A->lws_lookup[B->desc.sockfd - lws_plat_socket_offset()] == 0); A->lws_lookup[B->desc.sockfd - lws_plat_socket_offset()]=B
|
|
|
|
#define delete_from_fd(A,B) A->lws_lookup[B - lws_plat_socket_offset()]=0
|
2015-01-30 10:13:01 +08:00
|
|
|
#endif
|
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2018-03-05 16:49:28 +08:00
|
|
|
__insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi);
|
2011-02-14 17:52:39 +00: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_issue_raw(struct lws *wsi, unsigned char *buf, size_t len);
|
2011-03-06 10:29:38 +00:00
|
|
|
|
2017-02-21 23:38:40 +08:00
|
|
|
LWS_EXTERN void
|
|
|
|
lws_remove_from_timeout_list(struct lws *wsi);
|
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
|
2015-12-15 21:15:58 +08:00
|
|
|
lws_client_connect_2(struct lws *wsi);
|
2011-05-23 10:00:03 +01:00
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_VISIBLE struct lws * LWS_WARN_UNUSED_RESULT
|
2017-02-21 22:59:00 +08:00
|
|
|
lws_client_reset(struct lws **wsi, int ssl, const char *address, int port,
|
2016-01-20 16:56:06 +08:00
|
|
|
const char *path, const char *host);
|
2016-01-14 11:37:56 +08:00
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
|
2018-04-27 12:49:42 +08:00
|
|
|
lws_create_new_server_wsi(struct lws_vhost *vhost, int fixed_tsi);
|
2011-05-23 10:00:03 +01:00
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN char * LWS_WARN_UNUSED_RESULT
|
2015-12-15 21:15:58 +08:00
|
|
|
lws_generate_client_handshake(struct lws *wsi, char *pkt);
|
2011-05-23 10:00:03 +01:00
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int
|
2015-12-15 21:15:58 +08:00
|
|
|
lws_handle_POLLOUT_event(struct lws *wsi, struct lws_pollfd *pollfd);
|
2014-10-17 08:38:44 +08:00
|
|
|
|
2016-02-29 14:19:16 +08:00
|
|
|
LWS_EXTERN struct lws *
|
|
|
|
lws_client_connect_via_info2(struct lws *wsi);
|
|
|
|
|
2018-04-27 19:16:50 +08:00
|
|
|
|
2017-10-06 16:07:57 +08:00
|
|
|
|
2017-12-07 10:09:56 +08:00
|
|
|
LWS_EXTERN void
|
|
|
|
lws_client_stash_destroy(struct lws *wsi);
|
|
|
|
|
2014-04-12 10:07:02 +08:00
|
|
|
/*
|
|
|
|
* EXTENSIONS
|
|
|
|
*/
|
|
|
|
|
2018-04-19 12:53:53 +08:00
|
|
|
#if defined(LWS_WITHOUT_EXTENSIONS)
|
2015-12-15 21:15:58 +08:00
|
|
|
#define lws_any_extension_handled(_a, _b, _c, _d) (0)
|
2016-01-11 11:34:01 +08:00
|
|
|
#define lws_ext_cb_active(_a, _b, _c, _d) (0)
|
2015-12-17 17:03:59 +08:00
|
|
|
#define lws_ext_cb_all_exts(_a, _b, _c, _d, _e) (0)
|
2014-04-03 10:11:04 +08:00
|
|
|
#define lws_issue_raw_ext_access lws_issue_raw
|
2014-04-12 10:07:02 +08:00
|
|
|
#define lws_context_init_extensions(_a, _b)
|
2013-01-20 17:08:31 +08:00
|
|
|
#endif
|
2011-05-23 10:00:03 +01:00
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2015-12-15 21:15:58 +08:00
|
|
|
lws_client_interpret_server_handshake(struct lws *wsi);
|
2011-05-23 10:00:03 +01:00
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2018-04-20 10:33:23 +08:00
|
|
|
lws_ws_rx_sm(struct lws *wsi, char already_processed, unsigned char c);
|
2016-03-17 09:34:15 +08:00
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2015-12-06 09:15:27 +08:00
|
|
|
lws_issue_raw_ext_access(struct lws *wsi, unsigned char *buf, size_t len);
|
2011-05-28 10:19:19 +01:00
|
|
|
|
2014-11-08 11:18:47 +08:00
|
|
|
LWS_EXTERN void
|
2018-04-11 13:39:42 +08:00
|
|
|
lws_role_transition(struct lws *wsi, enum lwsi_role role, enum lwsi_state state,
|
|
|
|
struct lws_role_ops *ops);
|
2014-11-08 11:18:47 +08:00
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2015-12-21 18:06:38 +01:00
|
|
|
user_callback_handle_rxflow(lws_callback_function, struct lws *wsi,
|
2015-12-17 07:54:44 +08:00
|
|
|
enum lws_callback_reasons reason, void *user,
|
|
|
|
void *in, size_t len);
|
2013-01-17 16:50:35 +08:00
|
|
|
|
2017-11-05 14:28:57 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_plat_socket_offset(void);
|
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int
|
2016-03-28 10:10:43 +08:00
|
|
|
lws_plat_set_socket_options(struct lws_vhost *vhost, lws_sockfd_type fd);
|
2013-02-09 12:25:31 +08:00
|
|
|
|
2016-06-28 19:01:20 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_plat_check_connection_error(struct lws *wsi);
|
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2016-02-27 11:42:22 +08:00
|
|
|
lws_header_table_attach(struct lws *wsi, int autoservice);
|
replace per header mallocs with single malloc 3 level struct
This big patch replaces the malloc / realloc per header
approach used until now with a single three-level struct
that gets malloc'd during the header union phase and freed
in one go when we transition to a different union phase.
It's more expensive in that we malloc a bit more than 4Kbytes,
but it's a lot cheaper in terms of malloc, frees, heap fragmentation,
no reallocs, nothing to configure. It also moves from arrays of
pointers (8 bytes on x86_64) to unsigned short offsets into the
data array, (2 bytes on all platforms).
The 3-level thing is all in one struct
- array indexed by the header enum, pointing to first "fragment" index
(ie, header type to fragment lookup, or 0 for none)
- array of fragments indexes, enough for 2 x the number of known headers
(fragment array... note that fragments can point to a "next"
fragment if the same header is spread across multiple entries)
- linear char array where the known header payload gets written
(fragments point into null-terminated strings stored in here,
only the known header content is stored)
http headers can legally be split over multiple headers of the same
name which should be concatenated. This scheme does not linearly
conatenate them but uses a linked list in the fragment structs to
link them. There are apis to get the total length and copy out a
linear, concatenated version to a buffer.
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-10 18:02:31 +08:00
|
|
|
|
2014-11-07 11:20:59 +08:00
|
|
|
LWS_EXTERN int
|
2016-02-27 11:42:22 +08:00
|
|
|
lws_header_table_detach(struct lws *wsi, int autoservice);
|
2018-03-05 16:49:28 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
__lws_header_table_detach(struct lws *wsi, int autoservice);
|
2014-11-07 11:20:59 +08:00
|
|
|
|
ah http1.1 deal with pipelined headers properly
Connections must hold an ah for the whole time they are
processing one header set, even if eg, the headers are
fragmented and it involves network roundtrip times.
However on http1.1 / keepalive, it must drop the ah when
there are no more header sets to deal with, and reacquire
the ah later when more data appears. It's because the
time between header sets / http1.1 requests is unbounded
and the ah would be tied up forever.
But in the case that we got pipelined http1.1 requests,
even partial already buffered, we must keep the ah,
resetting it instead of dropping it. Because we store
the rx data conveniently in a per-tsi buffer since it only
does one thing at a time per thread, we cannot go back to
the event loop to await a new ah inside one service action.
But no problem since we definitely already have an ah,
let's just reuse it at http completion time if more rx is
already buffered.
NB: attack.sh makes request with echo | nc, this
accidentally sends a trailing '\n' from the echo showing
this problem. With this patch attack.sh can complete well.
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-30 11:43:10 +08:00
|
|
|
LWS_EXTERN void
|
2016-02-27 11:42:22 +08:00
|
|
|
lws_header_table_reset(struct lws *wsi, int autoservice);
|
2018-04-27 19:16:50 +08:00
|
|
|
|
2018-03-02 14:22:49 +08:00
|
|
|
void
|
|
|
|
__lws_header_table_reset(struct lws *wsi, int autoservice);
|
ah http1.1 deal with pipelined headers properly
Connections must hold an ah for the whole time they are
processing one header set, even if eg, the headers are
fragmented and it involves network roundtrip times.
However on http1.1 / keepalive, it must drop the ah when
there are no more header sets to deal with, and reacquire
the ah later when more data appears. It's because the
time between header sets / http1.1 requests is unbounded
and the ah would be tied up forever.
But in the case that we got pipelined http1.1 requests,
even partial already buffered, we must keep the ah,
resetting it instead of dropping it. Because we store
the rx data conveniently in a per-tsi buffer since it only
does one thing at a time per thread, we cannot go back to
the event loop to await a new ah inside one service action.
But no problem since we definitely already have an ah,
let's just reuse it at http completion time if more rx is
already buffered.
NB: attack.sh makes request with echo | nc, this
accidentally sends a trailing '\n' from the echo showing
this problem. With this patch attack.sh can complete well.
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-30 11:43:10 +08:00
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN char * LWS_WARN_UNUSED_RESULT
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_hdr_simple_ptr(struct lws *wsi, enum lws_token_indexes h);
|
replace per header mallocs with single malloc 3 level struct
This big patch replaces the malloc / realloc per header
approach used until now with a single three-level struct
that gets malloc'd during the header union phase and freed
in one go when we transition to a different union phase.
It's more expensive in that we malloc a bit more than 4Kbytes,
but it's a lot cheaper in terms of malloc, frees, heap fragmentation,
no reallocs, nothing to configure. It also moves from arrays of
pointers (8 bytes on x86_64) to unsigned short offsets into the
data array, (2 bytes on all platforms).
The 3-level thing is all in one struct
- array indexed by the header enum, pointing to first "fragment" index
(ie, header type to fragment lookup, or 0 for none)
- array of fragments indexes, enough for 2 x the number of known headers
(fragment array... note that fragments can point to a "next"
fragment if the same header is spread across multiple entries)
- linear char array where the known header payload gets written
(fragments point into null-terminated strings stored in here,
only the known header content is stored)
http headers can legally be split over multiple headers of the same
name which should be concatenated. This scheme does not linearly
conatenate them but uses a linked list in the fragment structs to
link them. There are apis to get the total length and copy out a
linear, concatenated version to a buffer.
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-02-10 18:02:31 +08:00
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2015-12-16 18:19:08 +08:00
|
|
|
lws_hdr_simple_create(struct lws *wsi, enum lws_token_indexes h, const char *s);
|
2013-02-11 17:13:32 +08:00
|
|
|
|
2016-04-23 07:53:46 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_ensure_user_space(struct lws *wsi);
|
2013-02-18 16:30:10 +08:00
|
|
|
|
2014-04-02 14:25:10 +08:00
|
|
|
LWS_EXTERN int
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_change_pollfd(struct lws *wsi, int _and, int _or);
|
2013-12-21 11:18:34 +08:00
|
|
|
|
2013-02-11 17:13:32 +08:00
|
|
|
#ifndef LWS_NO_SERVER
|
2018-04-27 08:27:16 +08:00
|
|
|
int _lws_context_init_server(const struct lws_context_creation_info *info,
|
|
|
|
struct lws_vhost *vhost);
|
2018-04-19 12:53:53 +08:00
|
|
|
LWS_EXTERN struct lws_vhost *
|
|
|
|
lws_select_vhost(struct lws_context *context, int port, const char *servername);
|
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2018-04-20 10:33:23 +08:00
|
|
|
lws_parse_ws(struct lws *wsi, unsigned char **buf, size_t len);
|
2018-04-19 12:53:53 +08:00
|
|
|
LWS_EXTERN void
|
|
|
|
lws_server_get_canonical_hostname(struct lws_context *context,
|
2018-04-27 08:27:16 +08:00
|
|
|
const struct lws_context_creation_info *info);
|
2014-04-03 08:24:29 +08:00
|
|
|
#else
|
2018-04-26 15:27:02 +08:00
|
|
|
#define _lws_context_init_server(_a, _b) (0)
|
2018-04-20 10:33:23 +08:00
|
|
|
#define lws_parse_ws(_a, _b, _c) (0)
|
2018-04-19 12:53:53 +08:00
|
|
|
#define lws_server_get_canonical_hostname(_a, _b)
|
2013-02-11 17:13:32 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef LWS_NO_DAEMONIZE
|
2018-04-19 12:53:53 +08:00
|
|
|
LWS_EXTERN int 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
|
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2016-06-03 21:19:40 +08:00
|
|
|
interface_to_sa(struct lws_vhost *vh, const char *ifname,
|
2015-12-06 09:15:27 +08:00
|
|
|
struct sockaddr_in *addr, size_t addrlen);
|
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)
|
|
|
|
#define lws_ssl_anybody_has_buffered_read_tsi(_a, _b) (0)
|
|
|
|
#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
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
#if LWS_MAX_SMP > 1
|
2018-03-02 14:22:49 +08:00
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
static LWS_INLINE void
|
|
|
|
lws_pt_mutex_init(struct lws_context_per_thread *pt)
|
|
|
|
{
|
|
|
|
pthread_mutex_init(&pt->lock, NULL);
|
2018-03-02 14:22:49 +08:00
|
|
|
pthread_mutex_init(&pt->lock_stats, NULL);
|
2016-01-26 20:56:56 +08:00
|
|
|
}
|
2016-05-12 20:22:35 -05:00
|
|
|
|
|
|
|
static LWS_INLINE void
|
|
|
|
lws_pt_mutex_destroy(struct lws_context_per_thread *pt)
|
|
|
|
{
|
2018-03-02 14:22:49 +08:00
|
|
|
pthread_mutex_destroy(&pt->lock_stats);
|
2016-05-12 20:22:35 -05:00
|
|
|
pthread_mutex_destroy(&pt->lock);
|
|
|
|
}
|
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
static LWS_INLINE void
|
2018-03-02 14:22:49 +08:00
|
|
|
lws_pt_lock(struct lws_context_per_thread *pt, const char *reason)
|
2016-01-26 20:56:56 +08:00
|
|
|
{
|
2018-03-02 14:22:49 +08:00
|
|
|
if (pt->lock_owner == pthread_self()) {
|
2018-03-11 11:26:06 +08:00
|
|
|
pt->lock_depth++;
|
|
|
|
return;
|
2018-03-02 14:22:49 +08:00
|
|
|
}
|
|
|
|
pthread_mutex_lock(&pt->lock);
|
|
|
|
pt->last_lock_reason = reason;
|
|
|
|
pt->lock_owner = pthread_self();
|
|
|
|
//lwsl_notice("tid %d: lock %s\n", pt->tid, reason);
|
2016-01-26 20:56:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static LWS_INLINE void
|
|
|
|
lws_pt_unlock(struct lws_context_per_thread *pt)
|
|
|
|
{
|
2018-03-11 11:26:06 +08:00
|
|
|
if (pt->lock_depth) {
|
|
|
|
pt->lock_depth--;
|
|
|
|
return;
|
|
|
|
}
|
2018-03-02 14:22:49 +08:00
|
|
|
pt->last_lock_reason ="free";
|
|
|
|
pt->lock_owner = 0;
|
|
|
|
//lwsl_notice("tid %d: unlock %s\n", pt->tid, pt->last_lock_reason);
|
|
|
|
pthread_mutex_unlock(&pt->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static LWS_INLINE void
|
|
|
|
lws_pt_stats_lock(struct lws_context_per_thread *pt)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&pt->lock_stats);
|
|
|
|
}
|
|
|
|
|
|
|
|
static LWS_INLINE void
|
|
|
|
lws_pt_stats_unlock(struct lws_context_per_thread *pt)
|
|
|
|
{
|
|
|
|
pthread_mutex_unlock(&pt->lock_stats);
|
2016-01-26 20:56:56 +08:00
|
|
|
}
|
2018-03-02 14:22:49 +08:00
|
|
|
|
2017-09-14 13:14:11 +08:00
|
|
|
static LWS_INLINE void
|
|
|
|
lws_context_lock(struct lws_context *context)
|
|
|
|
{
|
2018-03-02 14:22:49 +08:00
|
|
|
pthread_mutex_lock(&context->lock);
|
2017-09-14 13:14:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static LWS_INLINE void
|
|
|
|
lws_context_unlock(struct lws_context *context)
|
|
|
|
{
|
2018-03-02 14:22:49 +08:00
|
|
|
pthread_mutex_unlock(&context->lock);
|
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)
|
2017-09-14 13:14:11 +08:00
|
|
|
#define lws_context_lock(_a) (void)(_a)
|
|
|
|
#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);
|
|
|
|
|
2016-03-20 11:59:53 +08:00
|
|
|
|
|
|
|
#ifndef LWS_NO_CLIENT
|
2018-03-26 12:05:04 +08:00
|
|
|
LWS_EXTERN int lws_client_socket_service(struct lws *wsi,
|
|
|
|
struct lws_pollfd *pollfd,
|
|
|
|
struct lws *wsi_conn);
|
|
|
|
LWS_EXTERN struct lws *
|
|
|
|
lws_client_wsi_effective(struct lws *wsi);
|
2016-03-20 11:55:25 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
|
|
|
lws_http_transaction_completed_client(struct lws *wsi);
|
2018-04-19 12:53:53 +08:00
|
|
|
#if !defined(LWS_WITH_TLS)
|
2014-04-03 10:17:00 +08:00
|
|
|
#define lws_context_init_client_ssl(_a, _b) (0)
|
|
|
|
#endif
|
2015-12-06 09:15:27 +08:00
|
|
|
LWS_EXTERN void
|
|
|
|
lws_decode_ssl_error(void);
|
2014-04-03 08:24:29 +08:00
|
|
|
#else
|
2014-04-03 10:17:00 +08:00
|
|
|
#define lws_context_init_client_ssl(_a, _b) (0)
|
2014-04-03 07:16:40 +08:00
|
|
|
#endif
|
2015-12-28 14:24:49 +08:00
|
|
|
|
|
|
|
LWS_EXTERN int
|
2018-03-02 14:22:49 +08:00
|
|
|
__lws_rx_flow_control(struct lws *wsi);
|
2015-12-28 14:24:49 +08:00
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
_lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa);
|
|
|
|
|
2014-04-03 07:16:40 +08:00
|
|
|
#ifndef LWS_NO_SERVER
|
2015-12-06 09:15:27 +08:00
|
|
|
LWS_EXTERN int
|
2015-12-16 18:19:08 +08:00
|
|
|
lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len);
|
2014-04-03 08:40:05 +08:00
|
|
|
#else
|
2018-04-11 13:39:42 +08:00
|
|
|
#define lws_server_socket_service(_b, _c) (0)
|
2015-12-16 18:19:08 +08:00
|
|
|
#define lws_handshake_server(_a, _b, _c) (0)
|
2014-04-03 07:16:40 +08:00
|
|
|
#endif
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2016-04-15 12:00:23 +08:00
|
|
|
#ifdef LWS_WITH_ACCESS_LOG
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_access_log(struct lws *wsi);
|
2017-10-16 12:52:32 +08:00
|
|
|
LWS_EXTERN void
|
|
|
|
lws_prepare_access_log_info(struct lws *wsi, char *uri_ptr, int meth);
|
2016-04-15 12:00:23 +08:00
|
|
|
#else
|
|
|
|
#define lws_access_log(_a)
|
|
|
|
#endif
|
|
|
|
|
2016-02-21 21:25:48 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_cgi_kill_terminated(struct lws_context_per_thread *pt);
|
|
|
|
|
2017-10-16 12:52:32 +08:00
|
|
|
LWS_EXTERN void
|
|
|
|
lws_cgi_remove_and_kill(struct lws *wsi);
|
|
|
|
|
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
|
|
|
|
lws_bind_protocol(struct lws *wsi, const struct lws_protocols *p);
|
|
|
|
|
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_plat_pipe_create(struct lws *wsi);
|
|
|
|
int
|
|
|
|
lws_plat_pipe_signal(struct lws *wsi);
|
|
|
|
void
|
|
|
|
lws_plat_pipe_close(struct lws *wsi);
|
|
|
|
int
|
|
|
|
lws_create_event_pipes(struct lws_context *context);
|
|
|
|
|
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 void
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_plat_delete_socket_from_fds(struct lws_context *context,
|
2015-12-06 09:15:27 +08:00
|
|
|
struct lws *wsi, int m);
|
2014-04-03 07:16:40 +08:00
|
|
|
LWS_EXTERN void
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_plat_insert_socket_into_fds(struct lws_context *context,
|
2015-12-06 09:15:27 +08:00
|
|
|
struct lws *wsi);
|
2014-04-03 07:16:40 +08:00
|
|
|
LWS_EXTERN void
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_plat_service_periodic(struct lws_context *context);
|
2014-04-03 07:16:40 +08:00
|
|
|
|
|
|
|
LWS_EXTERN int
|
2015-12-06 09:15:27 +08:00
|
|
|
lws_plat_change_pollfd(struct lws_context *context, struct lws *wsi,
|
|
|
|
struct lws_pollfd *pfd);
|
2017-03-25 08:42:35 +08:00
|
|
|
LWS_EXTERN void
|
2017-03-26 10:08:35 +08:00
|
|
|
lws_add_wsi_to_draining_ext_list(struct lws *wsi);
|
|
|
|
LWS_EXTERN void
|
2017-03-25 08:42:35 +08:00
|
|
|
lws_remove_wsi_from_draining_ext_list(struct lws *wsi);
|
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);
|
2014-04-03 07:16:40 +08:00
|
|
|
LWS_EXTERN int
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_poll_listen_fd(struct lws_pollfd *fd);
|
2014-04-03 07:16:40 +08:00
|
|
|
LWS_EXTERN int
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_plat_service(struct lws_context *context, int timeout_ms);
|
2016-01-19 03:34:24 +08:00
|
|
|
LWS_EXTERN LWS_VISIBLE int
|
2016-10-20 09:09:56 +08:00
|
|
|
_lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi);
|
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);
|
2014-04-03 07:16:40 +08:00
|
|
|
LWS_EXTERN void
|
2018-04-27 08:27:16 +08:00
|
|
|
lws_plat_drop_app_privileges(const struct lws_context_creation_info *info);
|
2014-04-03 07:16:40 +08:00
|
|
|
LWS_EXTERN unsigned long long
|
|
|
|
time_in_microseconds(void);
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
|
2014-04-03 07:16:40 +08:00
|
|
|
lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt);
|
2017-06-05 13:59:22 -03:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
|
|
|
lws_plat_inet_pton(int af, const char *src, void *dst);
|
2015-11-02 20:34:12 +08:00
|
|
|
|
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);
|
2017-03-08 11:11:41 +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
|
|
|
|
2017-05-11 15:02:01 +08:00
|
|
|
|
2017-04-06 13:49:17 +08:00
|
|
|
LWS_EXTERN void
|
|
|
|
lws_same_vh_protocol_remove(struct lws *wsi);
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_same_vh_protocol_insert(struct lws *wsi, int n);
|
2015-12-30 11:43:36 +08:00
|
|
|
|
2017-10-26 18:53:34 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_broadcast(struct lws_context *context, int reason, void *in, size_t len);
|
|
|
|
|
2017-05-07 10:02:03 +08:00
|
|
|
#if defined(LWS_WITH_STATS)
|
2018-04-19 12:53:53 +08:00
|
|
|
void
|
|
|
|
lws_stats_atomic_bump(struct lws_context * context,
|
2017-05-07 10:02:03 +08:00
|
|
|
struct lws_context_per_thread *pt, int index, uint64_t bump);
|
2018-04-19 12:53:53 +08:00
|
|
|
void
|
|
|
|
lws_stats_atomic_max(struct lws_context * context,
|
2017-05-07 10:02:03 +08:00
|
|
|
struct lws_context_per_thread *pt, int index, uint64_t val);
|
|
|
|
#else
|
2018-04-19 12:53:53 +08:00
|
|
|
static inline uint64_t lws_stats_atomic_bump(struct lws_context * context,
|
2017-05-07 10:02:03 +08:00
|
|
|
struct lws_context_per_thread *pt, int index, uint64_t bump) {
|
|
|
|
(void)context; (void)pt; (void)index; (void)bump; return 0; }
|
2018-04-19 12:53:53 +08:00
|
|
|
static inline uint64_t lws_stats_atomic_max(struct lws_context * context,
|
2017-05-07 10:02:03 +08:00
|
|
|
struct lws_context_per_thread *pt, int index, uint64_t val) {
|
|
|
|
(void)context; (void)pt; (void)index; (void)val; return 0; }
|
|
|
|
#endif
|
|
|
|
|
2017-05-05 11:38:34 -04:00
|
|
|
/* socks */
|
|
|
|
void socks_generate_msg(struct lws *wsi, enum socks_msg_type type,
|
2017-09-01 15:37:53 +08:00
|
|
|
ssize_t *msg_len);
|
2017-05-05 11:38:34 -04:00
|
|
|
|
2017-09-14 13:14:11 +08:00
|
|
|
#if defined(LWS_WITH_PEER_LIMITS)
|
|
|
|
void
|
|
|
|
lws_peer_track_wsi_close(struct lws_context *context, struct lws_peer *peer);
|
|
|
|
int
|
|
|
|
lws_peer_confirm_ah_attach_ok(struct lws_context *context, struct lws_peer *peer);
|
|
|
|
void
|
|
|
|
lws_peer_track_ah_detach(struct lws_context *context, struct lws_peer *peer);
|
|
|
|
void
|
|
|
|
lws_peer_cull_peer_wait_list(struct lws_context *context);
|
2017-10-16 12:52:32 +08:00
|
|
|
struct lws_peer *
|
|
|
|
lws_get_or_create_peer(struct lws_vhost *vhost, lws_sockfd_type sockfd);
|
|
|
|
void
|
|
|
|
lws_peer_add_wsi(struct lws_context *context, struct lws_peer *peer,
|
|
|
|
struct lws *wsi);
|
2017-09-14 13:14:11 +08:00
|
|
|
#endif
|
|
|
|
|
2018-03-02 14:22:49 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
__lws_remove_from_timeout_list(struct lws *wsi);
|
2018-03-19 16:37:37 +08:00
|
|
|
|
|
|
|
lws_usec_t
|
|
|
|
__lws_hrtimer_service(struct lws_context_per_thread *pt);
|
|
|
|
|
2018-03-02 14:22:49 +08:00
|
|
|
void
|
|
|
|
__lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs);
|
|
|
|
int
|
|
|
|
__lws_change_pollfd(struct lws *wsi, int _and, int _or);
|
|
|
|
|
2018-04-27 19:16:50 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
int
|
|
|
|
lws_callback_as_writeable(struct lws *wsi);
|
|
|
|
int
|
2018-04-17 15:35:15 +08:00
|
|
|
lws_buflist_aware_read(struct lws_context_per_thread *pt, struct lws *wsi,
|
|
|
|
struct lws_tokens *ebuf);
|
|
|
|
int
|
|
|
|
lws_buflist_aware_consume(struct lws *wsi, struct lws_tokens *ebuf, int used,
|
|
|
|
int buffered);
|
2018-04-27 19:16:50 +08:00
|
|
|
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
char *
|
|
|
|
lws_generate_client_ws_handshake(struct lws *wsi, char *p);
|
|
|
|
int
|
|
|
|
lws_client_ws_upgrade(struct lws *wsi, const char **cce);
|
|
|
|
int
|
|
|
|
lws_create_client_ws_object(struct lws_client_connect_info *i, struct lws *wsi);
|
2018-04-12 15:56:38 +08:00
|
|
|
int
|
|
|
|
lws_alpn_comma_to_openssl(const char *comma, uint8_t *os, int len);
|
|
|
|
int
|
|
|
|
lws_role_call_alpn_negotiated(struct lws *wsi, const char *alpn);
|
|
|
|
int
|
|
|
|
lws_tls_server_conn_alpn(struct lws *wsi);
|
|
|
|
|
2018-04-20 10:33:23 +08:00
|
|
|
int
|
|
|
|
lws_ws_client_rx_sm_block(struct lws *wsi, unsigned char **buf, size_t len);
|
|
|
|
|
2015-11-02 20:34:12 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
};
|
|
|
|
#endif
|