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
|
|
|
*
|
2013-01-28 12:19:10 +08:00
|
|
|
* Copyright (C) 2010 - 2013 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
|
|
|
|
2015-06-24 16:46:02 +02:00
|
|
|
#ifdef LWS_HAVE_SYS_TYPES_H
|
2014-04-02 21:02:54 +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>
|
2010-11-08 20:20:42 +00:00
|
|
|
|
2015-06-24 16:46:02 +02:00
|
|
|
#ifdef LWS_HAVE_SYS_STAT_H
|
2010-12-20 09:35:03 +00: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)
|
2013-02-06 15:26:58 +09:00
|
|
|
#define LWS_NO_DAEMONIZE
|
2014-02-28 12:37:52 +01:00
|
|
|
#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
|
2014-03-30 09:18:05 +02:00
|
|
|
#define LWS_POLLHUP (FD_CLOSE)
|
2014-03-28 15:44:56 +01:00
|
|
|
#define LWS_POLLIN (FD_READ | FD_ACCEPT)
|
|
|
|
#define LWS_POLLOUT (FD_WRITE)
|
2014-03-29 08:25:58 +01:00
|
|
|
#define MSG_NOSIGNAL 0
|
|
|
|
#define SHUT_RDWR SD_BOTH
|
|
|
|
#define SOL_TCP IPPROTO_TCP
|
2013-02-06 15:26:58 +09:00
|
|
|
|
2014-04-02 14:25:10 +08:00
|
|
|
#define compatible_close(fd) closesocket(fd)
|
|
|
|
#define compatible_file_close(fd) CloseHandle(fd)
|
2014-04-03 19:52:37 +08:00
|
|
|
#define compatible_file_seek_cur(fd, offset) SetFilePointer(fd, offset, NULL, FILE_CURRENT)
|
2014-04-02 14:25:10 +08:00
|
|
|
#define compatible_file_read(amount, fd, buf, len) {\
|
|
|
|
DWORD _amount; \
|
2014-04-07 18:43:58 +01:00
|
|
|
if (!ReadFile(fd, buf, len, &_amount, NULL)) \
|
2014-04-02 14:25:10 +08:00
|
|
|
amount = -1; \
|
|
|
|
else \
|
|
|
|
amount = _amount; \
|
|
|
|
}
|
|
|
|
#define lws_set_blocking_send(wsi) wsi->sock_send_blocking = TRUE
|
2011-03-02 22:03:47 +00:00
|
|
|
#include <winsock2.h>
|
|
|
|
#include <windows.h>
|
2014-04-07 11:28:08 +02:00
|
|
|
#include <tchar.h>
|
2015-06-24 16:46:02 +02:00
|
|
|
#ifdef LWS_HAVE_IN6ADDR_H
|
2014-04-12 11:10:35 +08:00
|
|
|
#include <in6addr.h>
|
|
|
|
#endif
|
2014-04-07 11:28:08 +02:00
|
|
|
#include <mstcpip.h>
|
|
|
|
|
|
|
|
#ifndef __func__
|
|
|
|
#define __func__ __FUNCTION__
|
|
|
|
#endif
|
|
|
|
|
2014-04-15 18:39:26 +02:00
|
|
|
#ifdef _WIN32_WCE
|
|
|
|
#define vsnprintf _vsnprintf
|
|
|
|
#endif
|
|
|
|
|
2014-02-27 03:21:50 +01:00
|
|
|
#define LWS_INVALID_FILE INVALID_HANDLE_VALUE
|
2014-04-02 14:25:10 +08:00
|
|
|
#else /* not windows --> */
|
2014-03-30 10:19:23 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include <unistd.h>
|
2011-03-02 22:03:47 +00:00
|
|
|
#include <sys/types.h>
|
2010-11-08 20:20:42 +00:00
|
|
|
#include <sys/socket.h>
|
2014-04-02 21:02:54 +08:00
|
|
|
#ifdef LWS_BUILTIN_GETIFADDRS
|
|
|
|
#include <getifaddrs.h>
|
|
|
|
#else
|
|
|
|
#include <ifaddrs.h>
|
|
|
|
#endif
|
2014-09-26 05:39:05 +08:00
|
|
|
#if defined (__ANDROID__)
|
|
|
|
#include <syslog.h>
|
|
|
|
#else
|
2014-04-02 21:02:54 +08:00
|
|
|
#include <sys/syslog.h>
|
2014-09-26 05:39:05 +08:00
|
|
|
#endif
|
2014-04-02 21:02:54 +08:00
|
|
|
#include <sys/un.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netdb.h>
|
2011-01-20 10:23:50 +00:00
|
|
|
#ifndef LWS_NO_FORK
|
2015-06-24 16:46:02 +02:00
|
|
|
#ifdef LWS_HAVE_SYS_PRCTL_H
|
2010-12-18 15:13:50 +00:00
|
|
|
#include <sys/prctl.h>
|
2011-01-20 10:23:50 +00:00
|
|
|
#endif
|
2011-12-14 22:14:03 +01:00
|
|
|
#endif
|
2010-11-08 20:20:42 +00:00
|
|
|
#include <netinet/in.h>
|
2011-03-08 08:56:57 +00:00
|
|
|
#include <netinet/tcp.h>
|
2010-12-18 15:13:50 +00:00
|
|
|
#include <arpa/inet.h>
|
2010-11-08 20:20:42 +00:00
|
|
|
#include <poll.h>
|
2014-03-23 13:25:07 +08:00
|
|
|
#ifdef LWS_USE_LIBEV
|
|
|
|
#include <ev.h>
|
|
|
|
#endif /* LWS_USE_LIBEV */
|
|
|
|
|
2010-11-08 20:20:42 +00:00
|
|
|
#include <sys/mman.h>
|
2011-02-14 20:58:26 +00:00
|
|
|
#include <sys/time.h>
|
2010-11-08 20:20:42 +00:00
|
|
|
|
2014-02-28 12:37:52 +01: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
|
2014-02-27 03:21:50 +01:00
|
|
|
#define LWS_INVALID_FILE -1
|
2014-03-30 09:18:05 +02:00
|
|
|
#define LWS_POLLHUP (POLLHUP|POLLERR)
|
|
|
|
#define LWS_POLLIN (POLLIN)
|
|
|
|
#define LWS_POLLOUT (POLLOUT)
|
2014-04-02 14:25:10 +08:00
|
|
|
#define compatible_close(fd) close(fd)
|
|
|
|
#define compatible_file_close(fd) close(fd)
|
|
|
|
#define compatible_file_seek_cur(fd, offset) lseek(fd, offset, SEEK_CUR)
|
|
|
|
#define compatible_file_read(amount, fd, buf, len) \
|
|
|
|
amount = read(fd, buf, len);
|
|
|
|
#define lws_set_blocking_send(wsi)
|
2011-03-02 22:03:47 +00:00
|
|
|
#endif
|
|
|
|
|
2015-06-24 16:46:02 +02:00
|
|
|
#ifndef LWS_HAVE_BZERO
|
2014-11-18 18:25:24 +08:00
|
|
|
#ifndef bzero
|
2014-02-28 13:17:49 +01:00
|
|
|
#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
|
2014-02-28 00:59:53 +01:00
|
|
|
#define strerror(x) ""
|
|
|
|
#endif
|
|
|
|
|
2010-11-08 20:20:42 +00:00
|
|
|
#ifdef LWS_OPENSSL_SUPPORT
|
2015-08-08 18:54:49 +02:00
|
|
|
#ifdef USE_WOLFSSL
|
2015-08-09 22:56:32 +02:00
|
|
|
#ifdef USE_OLD_CYASSL
|
|
|
|
#include <cyassl/openssl/ssl.h>
|
|
|
|
#include <cyassl/error-ssl.h>
|
|
|
|
#else
|
2015-08-08 18:54:49 +02:00
|
|
|
#include <wolfssl/openssl/ssl.h>
|
|
|
|
#include <wolfssl/error-ssl.h>
|
2015-08-09 22:56:32 +02:00
|
|
|
#endif /* not USE_OLD_CYASSL */
|
2013-02-06 15:43:00 +09:00
|
|
|
#else
|
2010-11-08 20:20:42 +00:00
|
|
|
#include <openssl/ssl.h>
|
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/err.h>
|
2010-12-20 09:35:03 +00:00
|
|
|
#include <openssl/md5.h>
|
2011-01-18 17:14:03 +00:00
|
|
|
#include <openssl/sha.h>
|
2015-08-08 18:54:49 +02:00
|
|
|
#endif /* not USE_WOLFSSL */
|
2011-02-14 20:56:24 +00:00
|
|
|
#endif
|
|
|
|
|
2010-11-08 20:20:42 +00:00
|
|
|
#include "libwebsockets.h"
|
|
|
|
|
2014-04-02 14:25:10 +08:00
|
|
|
#if defined(WIN32) || defined(_WIN32)
|
|
|
|
|
|
|
|
#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
|
|
|
|
typedef unsigned __int64 u_int64_t;
|
|
|
|
|
|
|
|
#undef __P
|
|
|
|
#ifndef __P
|
|
|
|
#if __STDC__
|
|
|
|
#define __P(protos) protos
|
|
|
|
#else
|
|
|
|
#define __P(protos) ()
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
#include <machine/endian.h>
|
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
#include <sys/endian.h>
|
|
|
|
#elif defined(__linux__)
|
|
|
|
#include <endian.h>
|
|
|
|
#endif
|
2014-12-07 03:36:11 +01:00
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#ifndef container_of
|
|
|
|
#define container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M)))
|
|
|
|
#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
|
|
|
|
|
2014-04-02 14:25:10 +08:00
|
|
|
#if !defined(BYTE_ORDER)
|
|
|
|
# define BYTE_ORDER __BYTE_ORDER
|
|
|
|
#endif
|
|
|
|
#if !defined(LITTLE_ENDIAN)
|
|
|
|
# define LITTLE_ENDIAN __LITTLE_ENDIAN
|
|
|
|
#endif
|
|
|
|
#if !defined(BIG_ENDIAN)
|
|
|
|
# define BIG_ENDIAN __BIG_ENDIAN
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
2015-01-30 10:13:01 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
#ifndef FD_HASHTABLE_MODULUS
|
|
|
|
#define FD_HASHTABLE_MODULUS 32
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2013-01-12 23:42:17 +08:00
|
|
|
#ifndef LWS_MAX_HEADER_LEN
|
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
|
|
|
#define LWS_MAX_HEADER_LEN 1024
|
2013-01-12 23:42:17 +08:00
|
|
|
#endif
|
|
|
|
#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
|
2013-02-10 16:00:47 +08:00
|
|
|
#define LWS_MAX_EXTENSIONS_ACTIVE 3
|
2013-01-12 23:42:17 +08:00
|
|
|
#endif
|
|
|
|
#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
|
2013-01-09 18:01:23 +08:00
|
|
|
#define AWAITING_TIMEOUT 5
|
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-02-06 21:10:16 +09:00
|
|
|
#define LWS_MAX_SOCKET_IO_BUF 4096
|
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
|
|
|
|
#ifndef LWS_MAX_ZLIB_CONN_BUFFER
|
|
|
|
#define LWS_MAX_ZLIB_CONN_BUFFER (64 * 1024)
|
|
|
|
#endif
|
|
|
|
|
listen socket more frequent service
From an idea by Edwin van den Oetelaar <oetelaar.automatisering@gmail.com>
When testing libwebsockets with ab, Edwin found an unexpected bump in
the distribution of latencies, some connections were held back almost
the whole test duration.
http://ml.libwebsockets.org/pipermail/libwebsockets/2013-January/000006.html
Studying the problem revealed that when there are mass pending connections
amongst many active connections, we do not service the listen socket often
enough to clear the backlog, some seem to get stale violating FIFO ordering.
This patch introduces listen socket service "piggybacking", where every n
normal socket service actions we also check the listen socket and deal with
pending connections there.
Normally, it checks the listen socket gratuitously every 10 normal socket
services. However, if it finds something waiting, it forces a check on the
next normal socket service too by keeping stats on how often something was
waiting. If the probability of something waiting each time becomes high,
it will allow up to two waiting connections to be serviced for each normal
socket service.
In that way it has low burden in the normal case, but rapidly adapts by
detecting mass connection loads as found in ab.
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-16 07:59:47 +08:00
|
|
|
/*
|
|
|
|
* if not in a connection storm, check for incoming
|
|
|
|
* connections this many normal connection services
|
|
|
|
*/
|
|
|
|
#define LWS_LISTEN_SERVICE_MODULO 10
|
2011-01-18 17:14:03 +00:00
|
|
|
|
2011-04-23 10:54:53 +01:00
|
|
|
enum lws_websocket_opcodes_07 {
|
|
|
|
LWS_WS_OPCODE_07__CONTINUATION = 0,
|
|
|
|
LWS_WS_OPCODE_07__TEXT_FRAME = 1,
|
|
|
|
LWS_WS_OPCODE_07__BINARY_FRAME = 2,
|
2011-05-23 10:00:03 +01:00
|
|
|
|
|
|
|
LWS_WS_OPCODE_07__NOSPEC__MUX = 7,
|
|
|
|
|
|
|
|
/* control extensions 8+ */
|
|
|
|
|
2011-04-23 10:54:53 +01:00
|
|
|
LWS_WS_OPCODE_07__CLOSE = 8,
|
|
|
|
LWS_WS_OPCODE_07__PING = 9,
|
|
|
|
LWS_WS_OPCODE_07__PONG = 0xa,
|
|
|
|
};
|
|
|
|
|
2011-05-23 10:00:03 +01:00
|
|
|
|
2010-11-08 20:20:42 +00:00
|
|
|
enum lws_connection_states {
|
|
|
|
WSI_STATE_HTTP,
|
2013-01-15 13:40:23 +08:00
|
|
|
WSI_STATE_HTTP_ISSUING_FILE,
|
2010-11-08 20:20:42 +00:00
|
|
|
WSI_STATE_HTTP_HEADERS,
|
2013-11-19 13:38:16 +01:00
|
|
|
WSI_STATE_HTTP_BODY,
|
2010-11-08 20:20:42 +00:00
|
|
|
WSI_STATE_DEAD_SOCKET,
|
2011-01-22 12:51:57 +00:00
|
|
|
WSI_STATE_ESTABLISHED,
|
2011-02-10 09:07:05 +00:00
|
|
|
WSI_STATE_CLIENT_UNCONNECTED,
|
2011-02-14 20:25:43 +00:00
|
|
|
WSI_STATE_RETURNED_CLOSE_ALREADY,
|
2011-05-23 10:00:03 +01:00
|
|
|
WSI_STATE_AWAITING_CLOSE_ACK,
|
2014-04-10 14:25:24 +08:00
|
|
|
WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE,
|
2014-10-08 12:00:53 +08:00
|
|
|
|
|
|
|
WSI_STATE_HTTP2_AWAIT_CLIENT_PREFACE,
|
|
|
|
WSI_STATE_HTTP2_ESTABLISHED_PRE_SETTINGS,
|
|
|
|
WSI_STATE_HTTP2_ESTABLISHED,
|
2010-11-08 20:20:42 +00:00
|
|
|
};
|
|
|
|
|
HTTP Version, Keep-alive support, No-copy POST
This is a squashed commit from https://github.com/andrew-canaday/libwebsockets,
dev/http_keepalive branch (strategies changed a few times, so the commit
history is clutteread). This branch is submitted for clarity, but the other
can be used as a reference or alternative.
* added **enum http_version** to track HTTP/1.0 vs HTTP/1.1 requests
* added **enum http_connection_type** to track keep-alive vs close
* replaced content_length_seen and body_index with **content_remain**
* removed **post_buffer** (see handshake.c modifications)
* removed post_buffer free
* switch state to WSI_TOKEN_SKIPPING after URI is complete to store version
* delete *spill* label (unused)
* add vars to track HTTP version and connection type
* HTTP version defaults to 1.0
* connection type defaults to 'close' for 1.0, keep-alive for 1.1
* additional checks in **cleanup:** label:
* if HTTP version string is present and valid, set enum val appropriately
* override connection default with the "Connection:" header, if present
* set state to WSI_STATE_HTTP_BODY if content_length > 0
* return 0 on HTTP requests, unless LWS_CALLBACK_HTTP indicates otherwise
* add vars to track remaining content_length and body chunk size
* re-arrange switch case order to facilitate creation of jump-table
* added new labels:
* **read_ok**: normal location reach on break from switch; just return 0
* **http_complete**: check for keep-alive + init state, mode, hdr table
* **http_new**: jump location for keep-alive when http_complete sees len>0
* after libwebsocket_parse, jump to one of those labels based on state
* POST body handling:
* don't bother iterating over input byte-by-byte or using memcpy
* just pass the relevant portion of the context->service_buffer to callback
2014-07-13 01:07:36 -04:00
|
|
|
enum http_version {
|
|
|
|
HTTP_VERSION_1_0,
|
|
|
|
HTTP_VERSION_1_1,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum http_connection_type {
|
|
|
|
HTTP_CONNECTION_CLOSE,
|
|
|
|
HTTP_CONNECTION_KEEP_ALIVE
|
|
|
|
};
|
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
enum lws_pending_protocol_send {
|
|
|
|
LWS_PPS_NONE,
|
|
|
|
LWS_PPS_HTTP2_MY_SETTINGS,
|
|
|
|
LWS_PPS_HTTP2_ACK_SETTINGS,
|
2014-10-27 16:46:44 +08:00
|
|
|
LWS_PPS_HTTP2_PONG,
|
2014-10-08 12:00:53 +08:00
|
|
|
};
|
|
|
|
|
2010-11-08 20:20:42 +00:00
|
|
|
enum lws_rx_parse_state {
|
|
|
|
LWS_RXPS_NEW,
|
2010-11-13 10:03:47 +00:00
|
|
|
|
2011-01-18 18:14:26 +00:00
|
|
|
LWS_RXPS_04_MASK_NONCE_1,
|
|
|
|
LWS_RXPS_04_MASK_NONCE_2,
|
|
|
|
LWS_RXPS_04_MASK_NONCE_3,
|
|
|
|
|
|
|
|
LWS_RXPS_04_FRAME_HDR_1,
|
2011-01-19 12:20:27 +00:00
|
|
|
LWS_RXPS_04_FRAME_HDR_LEN,
|
|
|
|
LWS_RXPS_04_FRAME_HDR_LEN16_2,
|
|
|
|
LWS_RXPS_04_FRAME_HDR_LEN16_1,
|
|
|
|
LWS_RXPS_04_FRAME_HDR_LEN64_8,
|
|
|
|
LWS_RXPS_04_FRAME_HDR_LEN64_7,
|
|
|
|
LWS_RXPS_04_FRAME_HDR_LEN64_6,
|
|
|
|
LWS_RXPS_04_FRAME_HDR_LEN64_5,
|
|
|
|
LWS_RXPS_04_FRAME_HDR_LEN64_4,
|
|
|
|
LWS_RXPS_04_FRAME_HDR_LEN64_3,
|
|
|
|
LWS_RXPS_04_FRAME_HDR_LEN64_2,
|
|
|
|
LWS_RXPS_04_FRAME_HDR_LEN64_1,
|
2011-01-18 18:14:26 +00:00
|
|
|
|
2011-04-24 05:46:23 +01:00
|
|
|
LWS_RXPS_07_COLLECT_FRAME_KEY_1,
|
|
|
|
LWS_RXPS_07_COLLECT_FRAME_KEY_2,
|
|
|
|
LWS_RXPS_07_COLLECT_FRAME_KEY_3,
|
|
|
|
LWS_RXPS_07_COLLECT_FRAME_KEY_4,
|
|
|
|
|
2010-11-08 20:20:42 +00:00
|
|
|
LWS_RXPS_PAYLOAD_UNTIL_LENGTH_EXHAUSTED
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-02-12 11:57:43 +00:00
|
|
|
enum connection_mode {
|
2013-01-15 13:40:23 +08:00
|
|
|
LWS_CONNMODE_HTTP_SERVING,
|
2013-05-19 14:04:10 +08:00
|
|
|
LWS_CONNMODE_HTTP_SERVING_ACCEPTED, /* actual HTTP service going on */
|
2013-03-09 11:52:18 +08:00
|
|
|
LWS_CONNMODE_PRE_WS_SERVING_ACCEPT,
|
2013-01-15 13:40:23 +08:00
|
|
|
|
2011-02-12 11:57:43 +00:00
|
|
|
LWS_CONNMODE_WS_SERVING,
|
|
|
|
LWS_CONNMODE_WS_CLIENT,
|
2014-09-30 09:43:14 +08:00
|
|
|
|
|
|
|
LWS_CONNMODE_HTTP2_SERVING,
|
2011-02-12 11:57:43 +00:00
|
|
|
|
2013-01-28 12:19:10 +08:00
|
|
|
/* transient, ssl delay hiding */
|
|
|
|
LWS_CONNMODE_SSL_ACK_PENDING,
|
|
|
|
|
2011-02-14 20:25:43 +00:00
|
|
|
/* transient modes */
|
2013-09-20 20:26:12 +08:00
|
|
|
LWS_CONNMODE_WS_CLIENT_WAITING_CONNECT,
|
2011-02-14 20:25:43 +00:00
|
|
|
LWS_CONNMODE_WS_CLIENT_WAITING_PROXY_REPLY,
|
|
|
|
LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE,
|
2014-04-06 06:26:35 +01:00
|
|
|
LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE2,
|
2013-10-24 22:27:08 +08:00
|
|
|
LWS_CONNMODE_WS_CLIENT_WAITING_SSL,
|
2011-02-14 20:25:43 +00:00
|
|
|
LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY,
|
2011-05-23 10:00:03 +01:00
|
|
|
LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT,
|
|
|
|
LWS_CONNMODE_WS_CLIENT_PENDING_CANDIDATE_CHILD,
|
2011-02-14 20:25:43 +00:00
|
|
|
|
2011-02-12 11:57:43 +00:00
|
|
|
/* special internal types */
|
|
|
|
LWS_CONNMODE_SERVER_LISTENER,
|
|
|
|
};
|
|
|
|
|
2013-03-16 11:24:23 +08:00
|
|
|
enum {
|
|
|
|
LWS_RXFLOW_ALLOW = (1 << 0),
|
|
|
|
LWS_RXFLOW_PENDING_CHANGE = (1 << 1),
|
|
|
|
};
|
|
|
|
|
2011-01-19 13:11:55 +00:00
|
|
|
struct libwebsocket_protocols;
|
2013-01-17 12:26:48 +08:00
|
|
|
struct libwebsocket;
|
2011-01-19 13:11:55 +00:00
|
|
|
|
2014-03-23 13:25:07 +08:00
|
|
|
#ifdef LWS_USE_LIBEV
|
|
|
|
struct lws_io_watcher {
|
|
|
|
struct ev_io watcher;
|
|
|
|
struct libwebsocket_context* context;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct lws_signal_watcher {
|
|
|
|
struct ev_signal watcher;
|
|
|
|
struct libwebsocket_context* context;
|
|
|
|
};
|
|
|
|
#endif /* LWS_USE_LIBEV */
|
|
|
|
|
2015-01-30 10:13:01 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define LWS_FD_HASH(fd) ((fd ^ (fd >> 8) ^ (fd >> 16)) % FD_HASHTABLE_MODULUS)
|
|
|
|
struct libwebsocket_fd_hashtable {
|
|
|
|
struct libwebsocket **wsi;
|
|
|
|
int length;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2010-12-18 15:13:50 +00:00
|
|
|
struct libwebsocket_context {
|
2014-03-28 15:44:56 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
WSAEVENT *events;
|
|
|
|
#endif
|
2014-03-29 08:25:58 +01:00
|
|
|
struct libwebsocket_pollfd *fds;
|
2015-01-30 10:13:01 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
/* different implementation between unix and windows */
|
|
|
|
struct libwebsocket_fd_hashtable fd_hashtable[FD_HASHTABLE_MODULUS];
|
|
|
|
#else
|
|
|
|
struct libwebsocket **lws_lookup; /* fd to wsi */
|
|
|
|
#endif
|
2010-12-18 15:13:50 +00:00
|
|
|
int fds_count;
|
2014-03-23 13:25:07 +08:00
|
|
|
#ifdef LWS_USE_LIBEV
|
|
|
|
struct ev_loop* io_loop;
|
|
|
|
struct lws_io_watcher w_accept;
|
|
|
|
struct lws_signal_watcher w_sigint;
|
2015-04-26 22:50:59 -04:00
|
|
|
lws_ev_signal_cb* lws_ev_sigint_cb;
|
|
|
|
int use_ev_sigint;
|
2014-03-23 13:25:07 +08:00
|
|
|
#endif /* LWS_USE_LIBEV */
|
2013-01-17 12:26:48 +08:00
|
|
|
int max_fds;
|
2011-01-22 12:51:57 +00:00
|
|
|
int listen_port;
|
2014-02-18 10:06:57 +01:00
|
|
|
const char *iface;
|
2013-02-18 12:02:18 +08:00
|
|
|
char http_proxy_address[128];
|
|
|
|
char canonical_hostname[128];
|
2011-01-27 22:01:43 +00:00
|
|
|
unsigned int http_proxy_port;
|
2011-01-30 20:57:25 +00:00
|
|
|
unsigned int options;
|
2014-02-26 21:37:31 +01:00
|
|
|
time_t last_timeout_check_s;
|
2011-02-10 09:32:24 +00:00
|
|
|
|
2013-01-22 07:20:08 +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)
|
|
|
|
*/
|
2013-02-06 21:10:16 +09:00
|
|
|
unsigned char service_buffer[LWS_MAX_SOCKET_IO_BUF];
|
2013-01-22 07:20:08 +08:00
|
|
|
|
2013-01-19 13:56:10 +08:00
|
|
|
int started_with_parent;
|
|
|
|
|
2011-02-10 09:32:24 +00:00
|
|
|
int fd_random;
|
listen socket more frequent service
From an idea by Edwin van den Oetelaar <oetelaar.automatisering@gmail.com>
When testing libwebsockets with ab, Edwin found an unexpected bump in
the distribution of latencies, some connections were held back almost
the whole test duration.
http://ml.libwebsockets.org/pipermail/libwebsockets/2013-January/000006.html
Studying the problem revealed that when there are mass pending connections
amongst many active connections, we do not service the listen socket often
enough to clear the backlog, some seem to get stale violating FIFO ordering.
This patch introduces listen socket service "piggybacking", where every n
normal socket service actions we also check the listen socket and deal with
pending connections there.
Normally, it checks the listen socket gratuitously every 10 normal socket
services. However, if it finds something waiting, it forces a check on the
next normal socket service too by keeping stats on how often something was
waiting. If the probability of something waiting each time becomes high,
it will allow up to two waiting connections to be serviced for each normal
socket service.
In that way it has low burden in the normal case, but rapidly adapts by
detecting mass connection loads as found in ab.
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-01-16 07:59:47 +08:00
|
|
|
int listen_service_modulo;
|
|
|
|
int listen_service_count;
|
|
|
|
int listen_service_fd;
|
|
|
|
int listen_service_extraseen;
|
2012-04-09 15:09:01 +08:00
|
|
|
|
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;
|
|
|
|
#ifndef _WIN32
|
|
|
|
int dummy_pipe_fds[2];
|
|
|
|
#endif
|
|
|
|
|
2013-02-09 12:25:31 +08:00
|
|
|
int ka_time;
|
|
|
|
int ka_probes;
|
|
|
|
int ka_interval;
|
|
|
|
|
2013-01-29 12:36:17 +08:00
|
|
|
#ifdef LWS_LATENCY
|
|
|
|
unsigned long worst_latency;
|
|
|
|
char worst_latency_info[256];
|
|
|
|
#endif
|
|
|
|
|
2010-12-18 15:13:50 +00:00
|
|
|
#ifdef LWS_OPENSSL_SUPPORT
|
|
|
|
int use_ssl;
|
2013-12-14 11:41:29 +08:00
|
|
|
int allow_non_ssl_on_ssl_port;
|
2014-10-16 08:53:19 +08:00
|
|
|
unsigned int user_supplied_ssl_ctx:1;
|
2011-01-27 06:26:52 +00:00
|
|
|
SSL_CTX *ssl_ctx;
|
|
|
|
SSL_CTX *ssl_client_ctx;
|
2015-01-29 08:36:18 +08:00
|
|
|
struct libwebsocket *pending_read_list; /* linked list */
|
|
|
|
#define lws_ssl_anybody_has_buffered_read(ctx) (ctx->use_ssl && ctx->pending_read_list)
|
|
|
|
#else
|
|
|
|
#define lws_ssl_anybody_has_buffered_read(ctx) (0)
|
2010-12-18 15:13:50 +00:00
|
|
|
#endif
|
2011-01-19 13:11:55 +00:00
|
|
|
struct libwebsocket_protocols *protocols;
|
2010-12-18 15:13:50 +00:00
|
|
|
int count_protocols;
|
2013-01-20 17:08:31 +08:00
|
|
|
#ifndef LWS_NO_EXTENSIONS
|
2011-03-05 16:12:15 +00:00
|
|
|
struct libwebsocket_extension *extensions;
|
2013-01-20 17:08:31 +08:00
|
|
|
#endif
|
2014-06-29 00:25:19 -04:00
|
|
|
struct lws_token_limits *token_limits;
|
2013-02-11 17:13:32 +08:00
|
|
|
void *user_space;
|
2016-01-20 08:46:03 +08:00
|
|
|
|
|
|
|
unsigned int being_destroyed:1;
|
2010-12-18 15:13:50 +00: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),
|
|
|
|
};
|
|
|
|
|
2014-03-23 13:25:07 +08:00
|
|
|
#ifdef LWS_USE_LIBEV
|
|
|
|
#define LWS_LIBEV_ENABLED(context) (context->options & LWS_SERVER_OPTION_LIBEV)
|
2014-04-11 13:14:37 +08:00
|
|
|
LWS_EXTERN void lws_feature_status_libev(struct lws_context_creation_info *info);
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_libev_accept(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *new_wsi, int accept_fd);
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_libev_io(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi, int flags);
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_libev_init_fd_table(struct libwebsocket_context *context);
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_libev_run(struct libwebsocket_context *context);
|
2014-03-23 13:25:07 +08:00
|
|
|
#else
|
|
|
|
#define LWS_LIBEV_ENABLED(context) (0)
|
2014-04-11 13:14:37 +08:00
|
|
|
#define lws_feature_status_libev(_a) \
|
|
|
|
lwsl_notice("libev support not compiled in\n")
|
2014-04-27 13:35:28 +02:00
|
|
|
#define lws_libev_accept(_a, _b, _c) ((void) 0)
|
|
|
|
#define lws_libev_io(_a, _b, _c) ((void) 0)
|
2014-04-11 13:14:37 +08:00
|
|
|
#define lws_libev_init_fd_table(_a) (0)
|
2014-04-27 13:35:28 +02:00
|
|
|
#define lws_libev_run(_a) ((void) 0)
|
2014-03-23 13:25:07 +08:00
|
|
|
#endif
|
|
|
|
|
2014-03-24 16:09:25 +08:00
|
|
|
#ifdef LWS_USE_IPV6
|
|
|
|
#define LWS_IPV6_ENABLED(context) (!(context->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
|
|
|
|
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,
|
2013-11-13 07:45:17 +08:00
|
|
|
URIPS_ARGUMENTS,
|
2013-11-10 15:15:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum uri_esc_states {
|
|
|
|
URIES_IDLE,
|
|
|
|
URIES_SEEN_PERCENT,
|
|
|
|
URIES_SEEN_PERCENT_H1,
|
|
|
|
};
|
2011-02-09 07:16:34 +00:00
|
|
|
|
2010-11-08 20:20:42 +00:00
|
|
|
/*
|
|
|
|
* This is totally opaque to code using the library. It's exported as a
|
|
|
|
* forward-reference pointer-only declaration; the user can use the pointer with
|
|
|
|
* other APIs to get information out of it.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
struct lws_fragments {
|
|
|
|
unsigned short offset;
|
|
|
|
unsigned short len;
|
|
|
|
unsigned char next_frag_index;
|
|
|
|
};
|
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
/* notice that these union members:
|
|
|
|
*
|
|
|
|
* hdr
|
|
|
|
* http
|
|
|
|
* http2
|
|
|
|
*
|
|
|
|
* all have a pointer to allocated_headers struct as their first member.
|
|
|
|
*
|
|
|
|
* It means for allocated_headers access, the three union paths can all be
|
|
|
|
* used interchangably to access the same data
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
struct allocated_headers {
|
|
|
|
unsigned short next_frag_index;
|
|
|
|
unsigned short pos;
|
|
|
|
unsigned char frag_index[WSI_TOKEN_COUNT];
|
|
|
|
struct lws_fragments frags[WSI_TOKEN_COUNT * 2];
|
|
|
|
char data[LWS_MAX_HEADER_LEN];
|
2013-02-18 10:38:45 +08:00
|
|
|
#ifndef LWS_NO_CLIENT
|
|
|
|
char initial_handshake_hash_base64[30];
|
|
|
|
unsigned short c_port;
|
|
|
|
#endif
|
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
|
|
|
};
|
|
|
|
|
2013-11-09 11:40:32 +08:00
|
|
|
struct _lws_http_mode_related {
|
2014-10-08 12:00:53 +08:00
|
|
|
/* MUST be first in struct */
|
2013-11-09 11:40:32 +08:00
|
|
|
struct allocated_headers *ah; /* mirroring _lws_header_related */
|
2014-02-27 03:21:50 +01:00
|
|
|
#if defined(WIN32) || defined(_WIN32)
|
|
|
|
HANDLE fd;
|
|
|
|
#else
|
2013-11-09 11:40:32 +08:00
|
|
|
int fd;
|
2014-02-27 03:21:50 +01:00
|
|
|
#endif
|
2013-11-09 11:40:32 +08:00
|
|
|
unsigned long filepos;
|
|
|
|
unsigned long filelen;
|
2013-11-19 13:38:16 +01:00
|
|
|
|
HTTP Version, Keep-alive support, No-copy POST
This is a squashed commit from https://github.com/andrew-canaday/libwebsockets,
dev/http_keepalive branch (strategies changed a few times, so the commit
history is clutteread). This branch is submitted for clarity, but the other
can be used as a reference or alternative.
* added **enum http_version** to track HTTP/1.0 vs HTTP/1.1 requests
* added **enum http_connection_type** to track keep-alive vs close
* replaced content_length_seen and body_index with **content_remain**
* removed **post_buffer** (see handshake.c modifications)
* removed post_buffer free
* switch state to WSI_TOKEN_SKIPPING after URI is complete to store version
* delete *spill* label (unused)
* add vars to track HTTP version and connection type
* HTTP version defaults to 1.0
* connection type defaults to 'close' for 1.0, keep-alive for 1.1
* additional checks in **cleanup:** label:
* if HTTP version string is present and valid, set enum val appropriately
* override connection default with the "Connection:" header, if present
* set state to WSI_STATE_HTTP_BODY if content_length > 0
* return 0 on HTTP requests, unless LWS_CALLBACK_HTTP indicates otherwise
* add vars to track remaining content_length and body chunk size
* re-arrange switch case order to facilitate creation of jump-table
* added new labels:
* **read_ok**: normal location reach on break from switch; just return 0
* **http_complete**: check for keep-alive + init state, mode, hdr table
* **http_new**: jump location for keep-alive when http_complete sees len>0
* after libwebsocket_parse, jump to one of those labels based on state
* POST body handling:
* don't bother iterating over input byte-by-byte or using memcpy
* just pass the relevant portion of the context->service_buffer to callback
2014-07-13 01:07:36 -04:00
|
|
|
enum http_version request_version;
|
|
|
|
enum http_connection_type connection_type;
|
2013-11-19 13:38:16 +01:00
|
|
|
int content_length;
|
HTTP Version, Keep-alive support, No-copy POST
This is a squashed commit from https://github.com/andrew-canaday/libwebsockets,
dev/http_keepalive branch (strategies changed a few times, so the commit
history is clutteread). This branch is submitted for clarity, but the other
can be used as a reference or alternative.
* added **enum http_version** to track HTTP/1.0 vs HTTP/1.1 requests
* added **enum http_connection_type** to track keep-alive vs close
* replaced content_length_seen and body_index with **content_remain**
* removed **post_buffer** (see handshake.c modifications)
* removed post_buffer free
* switch state to WSI_TOKEN_SKIPPING after URI is complete to store version
* delete *spill* label (unused)
* add vars to track HTTP version and connection type
* HTTP version defaults to 1.0
* connection type defaults to 'close' for 1.0, keep-alive for 1.1
* additional checks in **cleanup:** label:
* if HTTP version string is present and valid, set enum val appropriately
* override connection default with the "Connection:" header, if present
* set state to WSI_STATE_HTTP_BODY if content_length > 0
* return 0 on HTTP requests, unless LWS_CALLBACK_HTTP indicates otherwise
* add vars to track remaining content_length and body chunk size
* re-arrange switch case order to facilitate creation of jump-table
* added new labels:
* **read_ok**: normal location reach on break from switch; just return 0
* **http_complete**: check for keep-alive + init state, mode, hdr table
* **http_new**: jump location for keep-alive when http_complete sees len>0
* after libwebsocket_parse, jump to one of those labels based on state
* POST body handling:
* don't bother iterating over input byte-by-byte or using memcpy
* just pass the relevant portion of the context->service_buffer to callback
2014-07-13 01:07:36 -04:00
|
|
|
int content_remain;
|
2013-11-09 11:40:32 +08:00
|
|
|
};
|
|
|
|
|
2014-10-12 08:38:16 +08:00
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
#ifdef LWS_USE_HTTP2
|
|
|
|
|
|
|
|
enum lws_http2_settings {
|
|
|
|
LWS_HTTP2_SETTINGS__HEADER_TABLE_SIZE = 1,
|
|
|
|
LWS_HTTP2_SETTINGS__ENABLE_PUSH,
|
|
|
|
LWS_HTTP2_SETTINGS__MAX_CONCURRENT_STREAMS,
|
|
|
|
LWS_HTTP2_SETTINGS__INITIAL_WINDOW_SIZE,
|
|
|
|
LWS_HTTP2_SETTINGS__MAX_FRAME_SIZE,
|
|
|
|
LWS_HTTP2_SETTINGS__MAX_HEADER_LIST_SIZE,
|
|
|
|
|
|
|
|
LWS_HTTP2_SETTINGS__COUNT /* always last */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum lws_http2_wellknown_frame_types {
|
|
|
|
LWS_HTTP2_FRAME_TYPE_DATA,
|
|
|
|
LWS_HTTP2_FRAME_TYPE_HEADERS,
|
|
|
|
LWS_HTTP2_FRAME_TYPE_PRIORITY,
|
|
|
|
LWS_HTTP2_FRAME_TYPE_RST_STREAM,
|
|
|
|
LWS_HTTP2_FRAME_TYPE_SETTINGS,
|
|
|
|
LWS_HTTP2_FRAME_TYPE_PUSH_PROMISE,
|
|
|
|
LWS_HTTP2_FRAME_TYPE_PING,
|
|
|
|
LWS_HTTP2_FRAME_TYPE_GOAWAY,
|
|
|
|
LWS_HTTP2_FRAME_TYPE_WINDOW_UPDATE,
|
|
|
|
LWS_HTTP2_FRAME_TYPE_CONTINUATION,
|
|
|
|
|
|
|
|
LWS_HTTP2_FRAME_TYPE_COUNT /* always last */
|
|
|
|
};
|
|
|
|
|
2014-10-17 08:38:44 +08:00
|
|
|
enum lws_http2_flags {
|
|
|
|
LWS_HTTP2_FLAG_END_STREAM = 1,
|
|
|
|
LWS_HTTP2_FLAG_END_HEADERS = 4,
|
|
|
|
LWS_HTTP2_FLAG_PADDED = 8,
|
|
|
|
LWS_HTTP2_FLAG_PRIORITY = 0x20,
|
|
|
|
|
|
|
|
LWS_HTTP2_FLAG_SETTINGS_ACK = 1,
|
|
|
|
};
|
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
#define LWS_HTTP2_STREAM_ID_MASTER 0
|
|
|
|
#define LWS_HTTP2_FRAME_HEADER_LENGTH 9
|
|
|
|
#define LWS_HTTP2_SETTINGS_LENGTH 6
|
|
|
|
|
|
|
|
struct http2_settings {
|
|
|
|
unsigned int setting[LWS_HTTP2_SETTINGS__COUNT];
|
|
|
|
};
|
|
|
|
|
2014-10-09 16:57:47 +08:00
|
|
|
enum http2_hpack_state {
|
2014-10-18 12:23:05 +08:00
|
|
|
|
|
|
|
/* optional before first header block */
|
|
|
|
HPKS_OPT_PADDING,
|
|
|
|
HKPS_OPT_E_DEPENDENCY,
|
|
|
|
HKPS_OPT_WEIGHT,
|
|
|
|
|
|
|
|
/* header block */
|
2014-10-09 16:57:47 +08:00
|
|
|
HPKS_TYPE,
|
|
|
|
|
2014-10-12 08:38:16 +08:00
|
|
|
HPKS_IDX_EXT,
|
|
|
|
|
2014-10-09 16:57:47 +08:00
|
|
|
HPKS_HLEN,
|
|
|
|
HPKS_HLEN_EXT,
|
|
|
|
|
|
|
|
HPKS_DATA,
|
2014-10-18 12:23:05 +08:00
|
|
|
|
|
|
|
/* optional after last header block */
|
|
|
|
HKPS_OPT_DISCARD_PADDING,
|
2014-10-09 16:57:47 +08:00
|
|
|
};
|
|
|
|
|
2014-10-12 08:38:16 +08:00
|
|
|
enum http2_hpack_type {
|
|
|
|
HPKT_INDEXED_HDR_7,
|
|
|
|
HPKT_INDEXED_HDR_6_VALUE_INCR,
|
|
|
|
HPKT_LITERAL_HDR_VALUE_INCR,
|
|
|
|
HPKT_INDEXED_HDR_4_VALUE,
|
|
|
|
HPKT_LITERAL_HDR_VALUE,
|
|
|
|
HPKT_SIZE_5
|
|
|
|
};
|
|
|
|
|
2014-10-18 12:23:05 +08:00
|
|
|
struct hpack_dt_entry {
|
|
|
|
int token; /* additions that don't map to a token are ignored */
|
|
|
|
int arg_offset;
|
|
|
|
int arg_len;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct hpack_dynamic_table {
|
|
|
|
struct hpack_dt_entry *entries;
|
|
|
|
char *args;
|
|
|
|
int pos;
|
|
|
|
int next;
|
|
|
|
int num_entries;
|
|
|
|
int args_length;
|
|
|
|
};
|
|
|
|
|
2014-09-30 09:43:14 +08:00
|
|
|
struct _lws_http2_related {
|
2014-10-08 12:00:53 +08:00
|
|
|
/*
|
|
|
|
* having this first lets us also re-use all HTTP union code
|
|
|
|
* and in turn, http_mode_related has allocated headers in right
|
|
|
|
* place so we can use the header apis on the wsi directly still
|
|
|
|
*/
|
|
|
|
struct _lws_http_mode_related http; /* MUST BE FIRST IN STRUCT */
|
|
|
|
|
|
|
|
struct http2_settings my_settings;
|
|
|
|
struct http2_settings peer_settings;
|
|
|
|
|
|
|
|
struct libwebsocket *parent_wsi;
|
|
|
|
struct libwebsocket *next_child_wsi;
|
|
|
|
|
2014-10-18 12:23:05 +08:00
|
|
|
struct hpack_dynamic_table *hpack_dyn_table;
|
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
unsigned int count;
|
|
|
|
|
|
|
|
/* frame */
|
|
|
|
unsigned int length;
|
|
|
|
unsigned int stream_id;
|
|
|
|
struct libwebsocket *stream_wsi;
|
|
|
|
unsigned char type;
|
|
|
|
unsigned char flags;
|
|
|
|
unsigned char frame_state;
|
2014-10-18 12:23:05 +08:00
|
|
|
unsigned char padding;
|
2014-10-27 16:46:44 +08:00
|
|
|
|
|
|
|
unsigned char ping_payload[8];
|
2014-10-17 08:38:44 +08:00
|
|
|
|
2014-10-22 15:37:28 +08:00
|
|
|
unsigned short round_robin_POLLOUT;
|
|
|
|
unsigned short count_POLLOUT_children;
|
|
|
|
|
2014-10-17 08:38:44 +08:00
|
|
|
unsigned int END_STREAM:1;
|
|
|
|
unsigned int END_HEADERS:1;
|
2014-10-19 07:36:20 +08:00
|
|
|
unsigned int send_END_STREAM:1;
|
2014-10-22 15:37:28 +08:00
|
|
|
unsigned int GOING_AWAY;
|
|
|
|
unsigned int requested_POLLOUT:1;
|
2014-10-29 09:39:08 +08:00
|
|
|
unsigned int waiting_tx_credit:1;
|
2014-10-08 12:00:53 +08:00
|
|
|
|
2014-10-09 16:57:47 +08:00
|
|
|
/* hpack */
|
|
|
|
enum http2_hpack_state hpack;
|
2014-10-12 08:38:16 +08:00
|
|
|
enum http2_hpack_type hpack_type;
|
2014-10-09 16:57:47 +08:00
|
|
|
unsigned int header_index;
|
|
|
|
unsigned int hpack_len;
|
2014-10-12 08:38:16 +08:00
|
|
|
unsigned short hpack_pos;
|
2014-10-09 16:57:47 +08:00
|
|
|
unsigned char hpack_m;
|
2014-10-18 12:23:05 +08:00
|
|
|
unsigned int hpack_e_dep;
|
2014-10-09 16:57:47 +08:00
|
|
|
unsigned int huff:1;
|
|
|
|
unsigned int value:1;
|
|
|
|
|
2014-10-29 09:39:08 +08:00
|
|
|
/* negative credit is mandated by the spec */
|
|
|
|
int tx_credit;
|
2014-10-08 12:00:53 +08:00
|
|
|
unsigned int my_stream_id;
|
|
|
|
unsigned int child_count;
|
|
|
|
int my_priority;
|
|
|
|
unsigned char initialized;
|
|
|
|
unsigned char one_setting[LWS_HTTP2_SETTINGS_LENGTH];
|
2014-09-30 09:43:14 +08:00
|
|
|
};
|
|
|
|
|
2014-10-22 15:37:28 +08:00
|
|
|
#define HTTP2_IS_TOPLEVEL_WSI(wsi) (!wsi->u.http2.parent_wsi)
|
2014-10-08 12:00:53 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-01-21 11:04:23 +08:00
|
|
|
struct _lws_header_related {
|
2014-10-08 12:00:53 +08:00
|
|
|
/* MUST be first in struct */
|
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
|
|
|
struct allocated_headers *ah;
|
2013-02-18 10:34:25 +08:00
|
|
|
short lextable_pos;
|
2014-06-29 01:34:24 -04:00
|
|
|
unsigned short current_token_limit;
|
2013-02-10 16:00:47 +08:00
|
|
|
unsigned char parser_state; /* enum lws_token_indexes */
|
2013-11-10 15:15:21 +08:00
|
|
|
enum uri_path_states ups;
|
|
|
|
enum uri_esc_states ues;
|
|
|
|
char esc_stash;
|
2013-01-21 11:04:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _lws_websocket_related {
|
2013-02-06 21:10:16 +09:00
|
|
|
char *rx_user_buffer;
|
2010-11-11 09:22:22 +00:00
|
|
|
int rx_user_buffer_head;
|
2016-01-20 08:40:14 +08:00
|
|
|
unsigned int rx_ubuf_alloc;
|
2011-01-19 12:20:27 +00:00
|
|
|
unsigned char frame_masking_nonce_04[4];
|
|
|
|
unsigned char frame_mask_index;
|
2010-11-08 20:20:42 +00:00
|
|
|
size_t rx_packet_length;
|
2011-01-19 12:20:27 +00:00
|
|
|
unsigned char opcode;
|
2013-02-10 16:00:47 +08:00
|
|
|
unsigned int final:1;
|
2013-01-09 18:06:55 +08:00
|
|
|
unsigned char rsv;
|
2013-02-10 16:00:47 +08:00
|
|
|
unsigned int frame_is_binary:1;
|
|
|
|
unsigned int all_zero_nonce:1;
|
2013-02-18 10:34:25 +08:00
|
|
|
short close_reason; /* enum lws_close_status */
|
2014-10-08 12:00:53 +08:00
|
|
|
|
2013-02-10 16:00:47 +08:00
|
|
|
unsigned int this_frame_masked:1;
|
add explicit error for partial send
This patch adds code to handle the situation that a prepared user buffer could not all be sent on the
socket at once. There are two kinds of situation to handle
1) User code handles it: The connection only has extensions active that do not rewrite the buffer.
In this case, the patch caused libwebsocket_write() to simply return the amount of user buffer that
was consumed (this is specifically the amount of user buffer used in sending what was accepted,
nothing else). So user code can just advance its buffer that much and resume sending when the socket
is writable again. This continues the frame rather than starting a new one or new fragment.
2) The connections has extensions active which actually send something quite different than what the
user buffer contains, for example a compression extension. In this case, libwebsockets will dynamically
malloc a buffer to contain a copy of the remaining unsent data, request notifiction when writeable again,
and automatically spill and free this buffer with the highest priority before passing on the writable
notification to anything else. For this situation, the call to write will return that it used the
whole user buffer, even though part is still rebuffered.
This patch should enable libwebsockets to detect the two cases and take the appropriate action.
There are also two choices for user code to deal with partial sends.
1) Leave the no_buffer_all_partial_tx member in the protocol struct at zero. The library will dyamically
buffer anything you send that did not get completely written to the socket, and automatically spill it next
time the socket is writable. You can use this method if your sent frames are relatvely small and unlikely to get
truncated anyway.
2) Set the no_buffer_all_partial_tx member in the protocol struct. User code now needs to take care of the
return value from libwebsocket_write() and deal with resending the remainder if not all of the requested amount
got sent. You should use this method if you are sending large messages and want to maximize throughput and efficiency.
Since the new member no_buffer_all_partial_tx will be zero by default, this patch will auto-rebuffer any
partial sends by default. That's good for most cases but if you attempt to send large blocks, make sure you
follow option 2) above.
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-10-17 08:09:19 +08:00
|
|
|
unsigned int inside_frame:1; /* next write will be more of frame */
|
|
|
|
unsigned int clean_buffer:1; /* buffer not rewritten by extension */
|
2015-04-17 20:29:58 +08:00
|
|
|
unsigned int payload_is_close:1; /* process as PONG, but it is close */
|
2014-08-24 14:39:19 +08:00
|
|
|
|
|
|
|
unsigned char *ping_payload_buf; /* non-NULL if malloc'd */
|
|
|
|
unsigned int ping_payload_alloc; /* length malloc'd */
|
2015-03-24 21:07:01 +08:00
|
|
|
unsigned int ping_payload_len;
|
|
|
|
unsigned char ping_pending_flag;
|
2013-01-21 11:04:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct libwebsocket {
|
|
|
|
|
|
|
|
/* lifetime members */
|
|
|
|
|
2014-03-23 13:25:07 +08:00
|
|
|
#ifdef LWS_USE_LIBEV
|
|
|
|
struct lws_io_watcher w_read;
|
|
|
|
struct lws_io_watcher w_write;
|
|
|
|
#endif /* LWS_USE_LIBEV */
|
2013-01-21 11:04:23 +08:00
|
|
|
const struct libwebsocket_protocols *protocol;
|
|
|
|
#ifndef LWS_NO_EXTENSIONS
|
|
|
|
struct libwebsocket_extension *
|
|
|
|
active_extensions[LWS_MAX_EXTENSIONS_ACTIVE];
|
|
|
|
void *active_extensions_user[LWS_MAX_EXTENSIONS_ACTIVE];
|
2013-02-10 16:00:47 +08:00
|
|
|
unsigned char count_active_extensions;
|
|
|
|
unsigned int extension_data_pending:1;
|
2013-01-21 11:04:23 +08:00
|
|
|
#endif
|
2013-02-10 16:00:47 +08:00
|
|
|
unsigned char ietf_spec_revision;
|
2014-10-08 12:00:53 +08:00
|
|
|
enum lws_pending_protocol_send pps;
|
2011-04-24 05:46:23 +01:00
|
|
|
|
2013-02-10 16:00:47 +08:00
|
|
|
char mode; /* enum connection_mode */
|
|
|
|
char state; /* enum lws_connection_states */
|
|
|
|
char lws_rx_parse_state; /* enum lws_rx_parse_state */
|
|
|
|
char rx_frame_type; /* enum libwebsocket_write_protocol */
|
2013-01-21 11:04:23 +08:00
|
|
|
|
2013-02-11 21:43:41 +08:00
|
|
|
unsigned int hdr_parsing_completed: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;
|
2013-02-11 21:43:41 +08:00
|
|
|
|
2013-02-10 16:00:47 +08:00
|
|
|
char pending_timeout; /* enum pending_timeout */
|
2014-02-26 21:37:31 +01:00
|
|
|
time_t pending_timeout_limit;
|
2013-01-21 11:04:23 +08:00
|
|
|
int sock;
|
|
|
|
int position_in_fds_table;
|
2013-01-29 12:36:17 +08:00
|
|
|
#ifdef LWS_LATENCY
|
|
|
|
unsigned long action_start;
|
|
|
|
unsigned long latency_start;
|
|
|
|
#endif
|
2014-10-08 12:00:53 +08:00
|
|
|
/* rxflow handling */
|
|
|
|
unsigned char *rxflow_buffer;
|
|
|
|
int rxflow_len;
|
|
|
|
int rxflow_pos;
|
|
|
|
unsigned int rxflow_change_to:2;
|
2013-01-21 11:04:23 +08:00
|
|
|
|
2013-12-09 14:16:17 +08:00
|
|
|
/* truncated send handling */
|
|
|
|
unsigned char *truncated_send_malloc; /* non-NULL means buffering in progress */
|
2014-03-23 11:41:15 +08:00
|
|
|
unsigned int truncated_send_allocation; /* size of malloc */
|
2013-12-09 14:16:17 +08:00
|
|
|
unsigned int truncated_send_offset; /* where we are in terms of spilling */
|
|
|
|
unsigned int truncated_send_len; /* how much is buffered */
|
|
|
|
|
2013-01-21 11:04:23 +08:00
|
|
|
void *user_space;
|
|
|
|
|
|
|
|
/* members with mutually exclusive lifetimes are unionized */
|
|
|
|
|
|
|
|
union u {
|
|
|
|
struct _lws_http_mode_related http;
|
2014-10-08 12:00:53 +08:00
|
|
|
#ifdef LWS_USE_HTTP2
|
2014-09-30 09:43:14 +08:00
|
|
|
struct _lws_http2_related http2;
|
2014-10-08 12:00:53 +08:00
|
|
|
#endif
|
2013-01-21 11:04:23 +08:00
|
|
|
struct _lws_header_related hdr;
|
|
|
|
struct _lws_websocket_related ws;
|
|
|
|
} u;
|
2013-01-18 11:43:21 +08:00
|
|
|
|
2010-11-08 20:20:42 +00:00
|
|
|
#ifdef LWS_OPENSSL_SUPPORT
|
|
|
|
SSL *ssl;
|
2011-01-27 06:26:52 +00:00
|
|
|
BIO *client_bio;
|
2015-01-29 08:36:18 +08:00
|
|
|
struct libwebsocket *pending_read_list_prev, *pending_read_list_next;
|
2013-02-10 16:00:47 +08:00
|
|
|
unsigned int use_ssl:2;
|
2014-10-22 15:37:28 +08:00
|
|
|
unsigned int upgraded:1;
|
2013-02-11 17:13:32 +08:00
|
|
|
#endif
|
2014-03-28 15:44:56 +01:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
BOOL sock_send_blocking;
|
|
|
|
#endif
|
2010-11-08 20:20:42 +00:00
|
|
|
};
|
|
|
|
|
2014-04-03 07:29:50 +08:00
|
|
|
LWS_EXTERN int log_level;
|
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN void
|
2013-02-12 10:19:08 +08:00
|
|
|
libwebsocket_close_and_free_session(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi, enum lws_close_status);
|
|
|
|
|
2014-04-03 07:42:50 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
remove_wsi_socket_from_fds(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi);
|
2014-10-08 12:00:53 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_rxflow_cache(struct libwebsocket *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
|
2013-02-11 17:13:32 +08:00
|
|
|
static inline void lws_latency(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi, const char *action,
|
2014-11-30 12:30:36 +08:00
|
|
|
int ret, int completion) { do { } while (0); }
|
2013-02-11 17:13:32 +08:00
|
|
|
static inline void lws_latency_pre(struct libwebsocket_context *context,
|
2014-11-30 12:30:36 +08:00
|
|
|
struct libwebsocket *wsi) { do { } 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
|
2013-02-11 17:13:32 +08:00
|
|
|
lws_latency(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi, const char *action,
|
|
|
|
int ret, int completion);
|
2013-01-29 12:36:17 +08:00
|
|
|
#endif
|
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
LWS_EXTERN void lws_set_protocol_write_pending(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi,
|
|
|
|
enum lws_pending_protocol_send pend);
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int
|
2011-01-22 12:51:57 +00:00
|
|
|
libwebsocket_client_rx_sm(struct libwebsocket *wsi, unsigned char c);
|
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int
|
2014-06-29 00:25:19 -04:00
|
|
|
libwebsocket_parse(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi, unsigned char c);
|
2010-12-18 15:13:50 +00:00
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_http_action(struct libwebsocket_context *context, struct libwebsocket *wsi);
|
|
|
|
|
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
|
|
|
|
2015-01-30 10:13:01 +08:00
|
|
|
#ifdef _WIN32
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN struct libwebsocket *
|
2011-03-02 22:03:47 +00:00
|
|
|
wsi_from_fd(struct libwebsocket_context *context, int fd);
|
2011-02-12 11:57:43 +00:00
|
|
|
|
2015-01-30 10:13:01 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
insert_wsi(struct libwebsocket_context *context, struct libwebsocket *wsi);
|
|
|
|
|
|
|
|
LWS_EXTERN int
|
|
|
|
delete_from_fd(struct libwebsocket_context *context, int fd);
|
|
|
|
#else
|
|
|
|
#define wsi_from_fd(A,B) A->lws_lookup[B]
|
|
|
|
#define insert_wsi(A,B) A->lws_lookup[B->sock]=B
|
|
|
|
#define delete_from_fd(A,B) A->lws_lookup[B]=0
|
|
|
|
#endif
|
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int
|
2013-02-11 17:13:32 +08:00
|
|
|
insert_wsi_socket_into_fds(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi);
|
2011-02-14 17:52:39 +00:00
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int
|
2011-03-06 10:29:38 +00:00
|
|
|
lws_issue_raw(struct libwebsocket *wsi, unsigned char *buf, size_t len);
|
|
|
|
|
2011-03-06 10:29:39 +00:00
|
|
|
|
2013-02-20 19:11:31 +08:00
|
|
|
LWS_EXTERN int
|
2011-05-23 10:00:03 +01:00
|
|
|
libwebsocket_service_timeout_check(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi, unsigned int sec);
|
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN struct libwebsocket *
|
2013-10-26 20:23:00 +08:00
|
|
|
libwebsocket_client_connect_2(struct libwebsocket_context *context,
|
2011-05-23 10:00:03 +01:00
|
|
|
struct libwebsocket *wsi);
|
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN struct libwebsocket *
|
2011-05-23 10:00:03 +01:00
|
|
|
libwebsocket_create_new_server_wsi(struct libwebsocket_context *context);
|
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN char *
|
2011-05-23 10:00:03 +01:00
|
|
|
libwebsockets_generate_client_handshake(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi, char *pkt);
|
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int
|
2011-05-23 10:00:03 +01:00
|
|
|
lws_handle_POLLOUT_event(struct libwebsocket_context *context,
|
2014-03-29 08:25:58 +01:00
|
|
|
struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd);
|
2014-10-17 08:38:44 +08:00
|
|
|
|
2014-04-12 10:07:02 +08:00
|
|
|
/*
|
|
|
|
* EXTENSIONS
|
|
|
|
*/
|
|
|
|
|
2013-01-20 17:08:31 +08:00
|
|
|
#ifndef LWS_NO_EXTENSIONS
|
2014-04-12 10:07:02 +08:00
|
|
|
LWS_VISIBLE void
|
|
|
|
lws_context_init_extensions(struct lws_context_creation_info *info,
|
|
|
|
struct libwebsocket_context *context);
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int
|
2011-05-23 10:00:03 +01:00
|
|
|
lws_any_extension_handled(struct libwebsocket_context *context,
|
2012-04-09 15:09:01 +08:00
|
|
|
struct libwebsocket *wsi,
|
|
|
|
enum libwebsocket_extension_callback_reasons r,
|
|
|
|
void *v, size_t len);
|
2011-05-23 10:00:03 +01:00
|
|
|
|
2014-04-02 19:45:42 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_ext_callback_for_each_active(struct libwebsocket *wsi, int reason,
|
|
|
|
void *buf, int len);
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_ext_callback_for_each_extension_type(
|
|
|
|
struct libwebsocket_context *context, struct libwebsocket *wsi,
|
|
|
|
int reason, void *arg, int len);
|
|
|
|
#else
|
|
|
|
#define lws_any_extension_handled(_a, _b, _c, _d, _e) (0)
|
|
|
|
#define lws_ext_callback_for_each_active(_a, _b, _c, _d) (0)
|
|
|
|
#define lws_ext_callback_for_each_extension_type(_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
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int
|
2011-05-23 10:00:03 +01:00
|
|
|
lws_client_interpret_server_handshake(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi);
|
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int
|
2011-05-23 10:00:03 +01:00
|
|
|
libwebsocket_rx_sm(struct libwebsocket *wsi, unsigned char c);
|
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int
|
2011-05-28 10:19:19 +01:00
|
|
|
lws_issue_raw_ext_access(struct libwebsocket *wsi,
|
|
|
|
unsigned char *buf, size_t len);
|
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int
|
2013-01-17 16:50:35 +08:00
|
|
|
_libwebsocket_rx_flow_control(struct libwebsocket *wsi);
|
|
|
|
|
2014-11-08 11:18:47 +08:00
|
|
|
LWS_EXTERN void
|
|
|
|
lws_union_transition(struct libwebsocket *wsi, enum connection_mode mode);
|
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int
|
2013-02-11 17:13:32 +08:00
|
|
|
user_callback_handle_rxflow(callback_function,
|
|
|
|
struct libwebsocket_context *context,
|
2013-01-17 16:50:35 +08:00
|
|
|
struct libwebsocket *wsi,
|
|
|
|
enum libwebsocket_callback_reasons reason, void *user,
|
|
|
|
void *in, size_t len);
|
2014-10-08 12:00:53 +08:00
|
|
|
#ifdef LWS_USE_HTTP2
|
2014-10-18 12:23:05 +08:00
|
|
|
LWS_EXTERN struct libwebsocket *lws_http2_get_network_wsi(struct libwebsocket *wsi);
|
2014-10-22 15:37:28 +08:00
|
|
|
struct libwebsocket * lws_http2_get_nth_child(struct libwebsocket *wsi, int n);
|
2014-10-08 12:00:53 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_http2_interpret_settings_payload(struct http2_settings *settings, unsigned char *buf, int len);
|
|
|
|
LWS_EXTERN void lws_http2_init(struct http2_settings *settings);
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_http2_parser(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi, unsigned char c);
|
|
|
|
LWS_EXTERN int lws_http2_do_pps_send(struct libwebsocket_context *context, struct libwebsocket *wsi);
|
|
|
|
LWS_EXTERN int lws_http2_frame_write(struct libwebsocket *wsi, int type, int flags, unsigned int sid, unsigned int len, unsigned char *buf);
|
|
|
|
LWS_EXTERN struct libwebsocket *
|
|
|
|
lws_http2_wsi_from_id(struct libwebsocket *wsi, unsigned int sid);
|
2014-10-12 08:38:16 +08:00
|
|
|
LWS_EXTERN int lws_hpack_interpret(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi,
|
|
|
|
unsigned char c);
|
2014-10-12 14:31:47 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_add_http2_header_by_name(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi,
|
|
|
|
const unsigned char *name,
|
|
|
|
const unsigned char *value,
|
|
|
|
int length,
|
|
|
|
unsigned char **p,
|
|
|
|
unsigned char *end);
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_add_http2_header_by_token(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi,
|
|
|
|
enum lws_token_indexes token,
|
|
|
|
const unsigned char *value,
|
|
|
|
int length,
|
|
|
|
unsigned char **p,
|
|
|
|
unsigned char *end);
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_add_http2_header_status(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi,
|
|
|
|
unsigned int code,
|
|
|
|
unsigned char **p,
|
|
|
|
unsigned char *end);
|
2014-10-22 15:37:28 +08:00
|
|
|
LWS_EXTERN
|
|
|
|
void lws_http2_configure_if_upgraded(struct libwebsocket *wsi);
|
|
|
|
#else
|
|
|
|
#define lws_http2_configure_if_upgraded(x)
|
2014-10-08 12:00:53 +08:00
|
|
|
#endif
|
2013-01-17 16:50:35 +08:00
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int
|
2014-04-02 14:25:10 +08:00
|
|
|
lws_plat_set_socket_options(struct libwebsocket_context *context, int fd);
|
2013-02-09 12:25:31 +08:00
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int
|
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
|
|
|
lws_allocate_header_table(struct libwebsocket *wsi);
|
|
|
|
|
2014-11-07 11:20:59 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_free_header_table(struct libwebsocket *wsi);
|
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN char *
|
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
|
|
|
lws_hdr_simple_ptr(struct libwebsocket *wsi, enum lws_token_indexes h);
|
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int
|
2013-02-11 17:13:32 +08:00
|
|
|
lws_hdr_simple_create(struct libwebsocket *wsi,
|
|
|
|
enum lws_token_indexes h, const char *s);
|
|
|
|
|
2013-02-18 16:30:10 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
libwebsocket_ensure_user_space(struct libwebsocket *wsi);
|
|
|
|
|
2014-04-02 14:25:10 +08:00
|
|
|
LWS_EXTERN int
|
2013-12-21 11:18:34 +08:00
|
|
|
lws_change_pollfd(struct libwebsocket *wsi, int _and, int _or);
|
|
|
|
|
2013-02-11 17:13:32 +08:00
|
|
|
#ifndef LWS_NO_SERVER
|
2014-04-03 08:24:29 +08:00
|
|
|
int lws_context_init_server(struct lws_context_creation_info *info,
|
|
|
|
struct libwebsocket_context *context);
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int handshake_0405(struct libwebsocket_context *context,
|
2013-02-11 17:13:32 +08:00
|
|
|
struct libwebsocket *wsi);
|
2014-04-10 14:08:10 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
libwebsocket_interpret_incoming_packet(struct libwebsocket *wsi,
|
|
|
|
unsigned char *buf, size_t len);
|
2014-04-12 10:07:02 +08:00
|
|
|
LWS_EXTERN void
|
|
|
|
lws_server_get_canonical_hostname(struct libwebsocket_context *context,
|
|
|
|
struct lws_context_creation_info *info);
|
2014-04-03 08:24:29 +08:00
|
|
|
#else
|
|
|
|
#define lws_context_init_server(_a, _b) (0)
|
2014-04-10 14:08:10 +08:00
|
|
|
#define libwebsocket_interpret_incoming_packet(_a, _b, _c) (0)
|
2014-04-12 10:07:02 +08:00
|
|
|
#define lws_server_get_canonical_hostname(_a, _b)
|
2013-02-11 17:13:32 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef LWS_NO_DAEMONIZE
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int get_daemonize_pid();
|
2014-04-12 10:07:02 +08:00
|
|
|
#else
|
|
|
|
#define get_daemonize_pid() (0)
|
2013-02-11 17:13:32 +08:00
|
|
|
#endif
|
|
|
|
|
2014-04-03 07:16:40 +08:00
|
|
|
LWS_EXTERN int interface_to_sa(struct libwebsocket_context *context,
|
2014-03-24 16:09:25 +08:00
|
|
|
const char *ifname, struct sockaddr_in *addr, size_t addrlen);
|
2013-02-11 13:04:45 +08:00
|
|
|
|
2014-04-03 23:34:09 +08:00
|
|
|
LWS_EXTERN void lwsl_emit_stderr(int level, const char *line);
|
|
|
|
|
2014-04-02 14:25:10 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
LWS_EXTERN HANDLE lws_plat_open_file(const char* filename, unsigned long* filelen);
|
|
|
|
#else
|
|
|
|
LWS_EXTERN int lws_plat_open_file(const char* filename, unsigned long* filelen);
|
|
|
|
#endif
|
|
|
|
|
2014-04-08 07:26:30 +01:00
|
|
|
enum lws_ssl_capable_status {
|
|
|
|
LWS_SSL_CAPABLE_ERROR = -1,
|
|
|
|
LWS_SSL_CAPABLE_MORE_SERVICE = -2,
|
|
|
|
};
|
|
|
|
|
2011-02-14 17:52:39 +00:00
|
|
|
#ifndef LWS_OPENSSL_SUPPORT
|
2014-04-12 10:07:02 +08:00
|
|
|
#define LWS_SSL_ENABLED(context) (0)
|
2014-04-03 10:17:00 +08:00
|
|
|
#define lws_context_init_server_ssl(_a, _b) (0)
|
|
|
|
#define lws_ssl_destroy(_a)
|
2014-04-03 14:33:48 +08:00
|
|
|
#define lws_context_init_http2_ssl(_a)
|
2014-04-06 06:26:35 +01:00
|
|
|
#define lws_ssl_capable_read lws_ssl_capable_read_no_ssl
|
|
|
|
#define lws_ssl_capable_write lws_ssl_capable_write_no_ssl
|
2015-08-19 16:23:33 +02:00
|
|
|
#define lws_ssl_pending lws_ssl_pending_no_ssl
|
2014-04-12 10:07:02 +08:00
|
|
|
#define lws_server_socket_service_ssl(_a, _b, _c, _d, _e) (0)
|
|
|
|
#define lws_ssl_close(_a) (0)
|
|
|
|
#define lws_ssl_context_destroy(_a)
|
2015-01-29 08:36:18 +08:00
|
|
|
#define lws_ssl_remove_wsi_from_buffered_list(_a, _b)
|
2013-02-11 17:13:32 +08:00
|
|
|
#else
|
2014-04-12 10:07:02 +08:00
|
|
|
#define LWS_SSL_ENABLED(context) (context->use_ssl)
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int openssl_websocket_private_data_index;
|
2014-04-06 06:26:35 +01:00
|
|
|
LWS_EXTERN int
|
2014-10-09 08:14:30 +08:00
|
|
|
lws_ssl_capable_read(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi, unsigned char *buf, int len);
|
2014-04-06 06:26:35 +01:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_ssl_capable_write(struct libwebsocket *wsi, unsigned char *buf, int len);
|
2014-04-12 10:07:02 +08:00
|
|
|
LWS_EXTERN int
|
2015-08-19 16:23:33 +02:00
|
|
|
lws_ssl_pending(struct libwebsocket *wsi);
|
|
|
|
LWS_EXTERN int
|
2014-04-12 10:07:02 +08:00
|
|
|
lws_server_socket_service_ssl(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket **wsi, struct libwebsocket *new_wsi,
|
|
|
|
int accept_fd, struct libwebsocket_pollfd *pollfd);
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_ssl_close(struct libwebsocket *wsi);
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_ssl_context_destroy(struct libwebsocket_context *context);
|
2015-01-29 08:36:18 +08:00
|
|
|
LWS_VISIBLE void
|
|
|
|
lws_ssl_remove_wsi_from_buffered_list(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi);
|
2014-04-03 10:17:00 +08:00
|
|
|
#ifndef LWS_NO_SERVER
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_context_init_server_ssl(struct lws_context_creation_info *info,
|
|
|
|
struct libwebsocket_context *context);
|
|
|
|
#else
|
|
|
|
#define lws_context_init_server_ssl(_a, _b) (0)
|
|
|
|
#endif
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_ssl_destroy(struct libwebsocket_context *context);
|
2014-04-03 14:33:48 +08:00
|
|
|
|
|
|
|
/* HTTP2-related */
|
|
|
|
|
|
|
|
#ifdef LWS_USE_HTTP2
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_context_init_http2_ssl(struct libwebsocket_context *context);
|
|
|
|
#else
|
|
|
|
#define lws_context_init_http2_ssl(_a)
|
|
|
|
#endif
|
2011-02-14 17:52:39 +00:00
|
|
|
#endif
|
2014-04-03 07:16:40 +08:00
|
|
|
|
2014-04-15 18:40:31 +02:00
|
|
|
LWS_EXTERN int
|
2014-10-09 08:14:30 +08:00
|
|
|
lws_ssl_capable_read_no_ssl(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi, unsigned char *buf, int len);
|
2014-04-15 18:40:31 +02:00
|
|
|
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_ssl_capable_write_no_ssl(struct libwebsocket *wsi, unsigned char *buf, int len);
|
|
|
|
|
2015-08-19 16:23:33 +02:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_ssl_pending_no_ssl(struct libwebsocket *wsi);
|
|
|
|
|
2014-04-03 07:16:40 +08:00
|
|
|
#ifndef LWS_NO_CLIENT
|
|
|
|
LWS_EXTERN int lws_client_socket_service(
|
|
|
|
struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd);
|
2014-04-03 10:17:00 +08:00
|
|
|
#ifdef LWS_OPENSSL_SUPPORT
|
|
|
|
LWS_EXTERN int lws_context_init_client_ssl(struct lws_context_creation_info *info,
|
2014-04-03 08:24:29 +08:00
|
|
|
struct libwebsocket_context *context);
|
2014-04-03 10:17:00 +08:00
|
|
|
#else
|
|
|
|
#define lws_context_init_client_ssl(_a, _b) (0)
|
|
|
|
#endif
|
2014-04-03 09:03:37 +08:00
|
|
|
LWS_EXTERN int lws_handshake_client(struct libwebsocket *wsi, unsigned char **buf, size_t len);
|
2014-04-03 10:17:00 +08:00
|
|
|
LWS_EXTERN void
|
|
|
|
libwebsockets_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 09:03:37 +08:00
|
|
|
#define lws_handshake_client(_a, _b, _c) (0)
|
2014-04-03 07:16:40 +08:00
|
|
|
#endif
|
|
|
|
#ifndef LWS_NO_SERVER
|
|
|
|
LWS_EXTERN int lws_server_socket_service(
|
|
|
|
struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd);
|
2014-04-03 08:40:05 +08:00
|
|
|
LWS_EXTERN int _libwebsocket_rx_flow_control(struct libwebsocket *wsi);
|
2014-04-03 09:03:37 +08:00
|
|
|
LWS_EXTERN int lws_handshake_server(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi, unsigned char **buf, size_t len);
|
2014-04-03 08:40:05 +08:00
|
|
|
#else
|
2014-04-03 10:11:04 +08:00
|
|
|
#define lws_server_socket_service(_a, _b, _c) (0)
|
2014-04-03 08:40:05 +08:00
|
|
|
#define _libwebsocket_rx_flow_control(_a) (0)
|
2014-04-03 09:03:37 +08:00
|
|
|
#define lws_handshake_server(_a, _b, _c, _d) (0)
|
2014-04-03 07:16:40 +08:00
|
|
|
#endif
|
2015-01-28 21:03:49 +08:00
|
|
|
|
|
|
|
LWS_EXTERN int libwebsockets_get_addresses(struct libwebsocket_context *context,
|
|
|
|
void *ads, char *name, int name_len,
|
|
|
|
char *rip, int rip_len);
|
2014-04-03 07:16:40 +08:00
|
|
|
|
2014-12-04 23:15:27 +01:00
|
|
|
/*
|
|
|
|
* custom allocator
|
|
|
|
*/
|
|
|
|
LWS_EXTERN void*
|
|
|
|
lws_realloc(void *ptr, size_t size);
|
|
|
|
|
|
|
|
LWS_EXTERN void*
|
|
|
|
lws_zalloc(size_t size);
|
|
|
|
|
|
|
|
#define lws_malloc(S) lws_realloc(NULL, S)
|
|
|
|
#define lws_free(P) lws_realloc(P, 0)
|
2014-12-05 00:09:20 +01:00
|
|
|
#define lws_free2(P) do { lws_realloc(P, 0); (P) = NULL; } while(0)
|
2014-12-04 23:15:27 +01:00
|
|
|
|
2014-04-03 07:16:40 +08:00
|
|
|
/*
|
|
|
|
* lws_plat_
|
|
|
|
*/
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_plat_delete_socket_from_fds(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi, int m);
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_plat_insert_socket_into_fds(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi);
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_plat_service_periodic(struct libwebsocket_context *context);
|
|
|
|
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_plat_change_pollfd(struct libwebsocket_context *context,
|
|
|
|
struct libwebsocket *wsi, struct libwebsocket_pollfd *pfd);
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_plat_context_early_init(void);
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_plat_context_early_destroy(struct libwebsocket_context *context);
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_plat_context_late_destroy(struct libwebsocket_context *context);
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_poll_listen_fd(struct libwebsocket_pollfd *fd);
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_plat_service(struct libwebsocket_context *context, int timeout_ms);
|
|
|
|
LWS_EXTERN int
|
2015-06-25 17:51:07 +02:00
|
|
|
lws_plat_init_lookup(struct libwebsocket_context *context);
|
|
|
|
LWS_EXTERN int
|
2014-04-03 07:16:40 +08:00
|
|
|
lws_plat_init_fd_tables(struct libwebsocket_context *context);
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_plat_drop_app_privileges(struct lws_context_creation_info *info);
|
|
|
|
LWS_EXTERN unsigned long long
|
|
|
|
time_in_microseconds(void);
|
|
|
|
LWS_EXTERN const char *
|
|
|
|
lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt);
|