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
|
|
|
*
|
2016-01-26 20:56:56 +08:00
|
|
|
* Copyright (C) 2010 - 2016 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)
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#endif
|
|
|
|
|
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>
|
2016-07-23 14:18:25 +08:00
|
|
|
#if defined(LWS_WITH_ESP8266)
|
|
|
|
#include <user_interface.h>
|
|
|
|
#define assert(n)
|
|
|
|
|
|
|
|
/* rom-provided stdc functions for free, ensure use these instead of libc ones */
|
|
|
|
|
|
|
|
int ets_vsprintf(char *str, const char *format, va_list argptr);
|
|
|
|
int ets_vsnprintf(char *buffer, size_t sizeOfBuffer, const char *format, va_list argptr);
|
|
|
|
int ets_snprintf(char *str, size_t size, const char *format, ...);
|
|
|
|
int ets_sprintf(char *str, const char *format, ...);
|
|
|
|
int os_printf_plus(const char *format, ...);
|
|
|
|
#undef malloc
|
|
|
|
#undef realloc
|
|
|
|
#undef free
|
|
|
|
void *pvPortMalloc(size_t s, const char *f, int line);
|
|
|
|
#define malloc(s) pvPortMalloc(s, "", 0)
|
|
|
|
void *pvPortRealloc(void *p, size_t s, const char *f, int line);
|
|
|
|
#define realloc(p, s) pvPortRealloc(p, s, "", 0)
|
|
|
|
void vPortFree(void *p, const char *f, int line);
|
|
|
|
#define free(p) vPortFree(p, "", 0)
|
|
|
|
#undef memcpy
|
|
|
|
void *ets_memcpy(void *dest, const void *src, size_t n);
|
|
|
|
#define memcpy ets_memcpy
|
|
|
|
void *ets_memset(void *dest, int v, size_t n);
|
|
|
|
#define memset ets_memset
|
|
|
|
char *ets_strcpy(char *dest, const char *src);
|
|
|
|
#define strcpy ets_strcpy
|
|
|
|
char *ets_strncpy(char *dest, const char *src, size_t n);
|
|
|
|
#define strncpy ets_strncpy
|
|
|
|
char *ets_strstr(const char *haystack, const char *needle);
|
|
|
|
#define strstr ets_strstr
|
|
|
|
int ets_strcmp(const char *s1, const char *s2);
|
|
|
|
int ets_strncmp(const char *s1, const char *s2, size_t n);
|
|
|
|
#define strcmp ets_strcmp
|
|
|
|
#define strncmp ets_strncmp
|
|
|
|
size_t ets_strlen(const char *s);
|
|
|
|
#define strlen ets_strlen
|
|
|
|
void *ets_memmove(void *dest, const void *src, size_t n);
|
|
|
|
#define memmove ets_memmove
|
|
|
|
char *ets_strchr(const char *s, int c);
|
|
|
|
#define strchr_ets_strchr
|
|
|
|
#undef _DEBUG
|
|
|
|
#include <osapi.h>
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define STORE_IN_ROM
|
2015-12-04 07:22:44 +08:00
|
|
|
#include <assert.h>
|
2016-07-23 14:18:25 +08:00
|
|
|
#endif
|
2016-01-26 20:56:56 +08:00
|
|
|
#if LWS_MAX_SMP > 1
|
|
|
|
#include <pthread.h>
|
|
|
|
#endif
|
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)
|
2015-10-23 08:10:55 +02:00
|
|
|
#if (WINVER < 0x0501)
|
|
|
|
#undef WINVER
|
|
|
|
#undef _WIN32_WINNT
|
|
|
|
#define WINVER 0x0501
|
|
|
|
#define _WIN32_WINNT WINVER
|
|
|
|
#endif
|
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-29 08:25:58 +01:00
|
|
|
#define MSG_NOSIGNAL 0
|
|
|
|
#define SHUT_RDWR SD_BOTH
|
|
|
|
#define SOL_TCP IPPROTO_TCP
|
2016-01-26 20:56:56 +08:00
|
|
|
#define SHUT_WR SD_SEND
|
2013-02-06 15:26:58 +09:00
|
|
|
|
2014-04-02 14:25:10 +08:00
|
|
|
#define compatible_close(fd) closesocket(fd)
|
2015-12-26 08:56:58 +08:00
|
|
|
#define lws_set_blocking_send(wsi) wsi->sock_send_blocking = 1
|
2015-11-14 07:35:27 +08:00
|
|
|
#define lws_socket_is_valid(x) (!!x)
|
2015-12-14 08:52:03 +08:00
|
|
|
#define LWS_SOCK_INVALID 0
|
2011-03-02 22:03:47 +00:00
|
|
|
#include <winsock2.h>
|
2015-12-17 15:15:12 +08:00
|
|
|
#include <ws2tcpip.h>
|
2011-03-02 22:03:47 +00:00
|
|
|
#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>
|
2016-05-14 06:49:29 +08:00
|
|
|
#include <io.h>
|
2014-04-07 11:28:08 +02:00
|
|
|
|
|
|
|
#ifndef __func__
|
|
|
|
#define __func__ __FUNCTION__
|
|
|
|
#endif
|
|
|
|
|
2016-05-05 13:56:07 +02:00
|
|
|
#if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(_WIN32_WCE)
|
2014-04-15 18:39:26 +02:00
|
|
|
#define vsnprintf _vsnprintf
|
2016-03-04 10:53:51 +08:00
|
|
|
#else
|
|
|
|
#ifdef LWS_HAVE__VSNPRINTF
|
|
|
|
#define vsnprintf _vsnprintf
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef LWS_HAVE__SNPRINTF
|
2016-09-15 02:22:57 +08:00
|
|
|
#define lws_snprintf _snprintf
|
2014-04-15 18:39:26 +02:00
|
|
|
#endif
|
|
|
|
|
2014-04-02 14:25:10 +08:00
|
|
|
#else /* not windows --> */
|
2015-11-02 20:34:12 +08:00
|
|
|
|
2014-03-30 10:19:23 +02:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include <unistd.h>
|
2011-03-02 22:03:47 +00:00
|
|
|
#include <sys/types.h>
|
2015-11-02 08:21:08 +08:00
|
|
|
#ifndef MBED_OPERATORS
|
2015-11-02 20:34:12 +08:00
|
|
|
#ifndef __cplusplus
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
2015-11-02 08:21:08 +08:00
|
|
|
#include <netdb.h>
|
|
|
|
#include <signal.h>
|
2016-07-23 14:18:25 +08:00
|
|
|
#ifdef LWS_WITH_ESP8266
|
|
|
|
#include <sockets.h>
|
|
|
|
#define vsnprintf ets_vsnprintf
|
|
|
|
#define snprintf ets_snprintf
|
|
|
|
#define sprintf ets_sprintf
|
|
|
|
#else
|
2010-11-08 20:20:42 +00:00
|
|
|
#include <sys/socket.h>
|
2016-07-23 14:18:25 +08:00
|
|
|
#endif
|
2016-03-20 11:59:53 +08:00
|
|
|
#ifdef LWS_WITH_HTTP_PROXY
|
|
|
|
#include <hubbub/hubbub.h>
|
|
|
|
#include <hubbub/parser.h>
|
|
|
|
#endif
|
2016-07-23 14:18:25 +08:00
|
|
|
#if defined(LWS_BUILTIN_GETIFADDRS)
|
2014-04-02 21:02:54 +08:00
|
|
|
#include <getifaddrs.h>
|
|
|
|
#else
|
2016-07-23 14:18:25 +08:00
|
|
|
#if !defined(LWS_WITH_ESP8266)
|
2014-04-02 21:02:54 +08:00
|
|
|
#include <ifaddrs.h>
|
2016-07-23 14:18:25 +08:00
|
|
|
#endif
|
2014-04-02 21:02:54 +08:00
|
|
|
#endif
|
2014-09-26 05:39:05 +08:00
|
|
|
#if defined (__ANDROID__)
|
|
|
|
#include <syslog.h>
|
2016-04-23 11:10:18 +02:00
|
|
|
#include <sys/resource.h>
|
2016-09-09 06:49:44 +08:00
|
|
|
#elif defined (__sun)
|
|
|
|
#include <syslog.h>
|
2014-09-26 05:39:05 +08:00
|
|
|
#else
|
2016-07-23 14:18:25 +08:00
|
|
|
#if !defined(LWS_WITH_ESP8266)
|
2014-04-02 21:02:54 +08:00
|
|
|
#include <sys/syslog.h>
|
2014-09-26 05:39:05 +08:00
|
|
|
#endif
|
2016-07-23 14:18:25 +08:00
|
|
|
#endif
|
2014-04-02 21:02:54 +08:00
|
|
|
#include <netdb.h>
|
2016-07-23 14:18:25 +08:00
|
|
|
#if !defined(LWS_WITH_ESP8266)
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/un.h>
|
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>
|
2016-07-23 14:18:25 +08:00
|
|
|
#endif
|
2014-03-23 13:25:07 +08:00
|
|
|
#ifdef LWS_USE_LIBEV
|
2016-02-14 09:27:41 +08:00
|
|
|
#include <ev.h>
|
|
|
|
#endif
|
|
|
|
#ifdef LWS_USE_LIBUV
|
2016-02-01 08:31:54 +08:00
|
|
|
#include <uv.h>
|
2016-02-14 09:27:41 +08:00
|
|
|
#endif
|
2015-11-02 08:21:08 +08:00
|
|
|
|
|
|
|
#endif /* MBED */
|
|
|
|
|
|
|
|
#ifndef LWS_NO_FORK
|
|
|
|
#ifdef LWS_HAVE_SYS_PRCTL_H
|
|
|
|
#include <sys/prctl.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
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
|
2016-07-11 07:28:23 +08:00
|
|
|
|
2014-04-02 14:25:10 +08:00
|
|
|
#define lws_set_blocking_send(wsi)
|
2015-11-02 13:10:33 +08:00
|
|
|
|
2016-07-23 14:18:25 +08:00
|
|
|
#if defined(MBED_OPERATORS) || defined(LWS_WITH_ESP8266)
|
2015-11-02 13:10:33 +08:00
|
|
|
#define lws_socket_is_valid(x) ((x) != NULL)
|
|
|
|
#define LWS_SOCK_INVALID (NULL)
|
2016-07-23 14:18:25 +08:00
|
|
|
struct lws;
|
|
|
|
const char *
|
|
|
|
lws_plat_get_peer_simple(struct lws *wsi, char *name, int namelen);
|
2015-11-02 13:10:33 +08:00
|
|
|
#else
|
2015-11-14 07:35:27 +08:00
|
|
|
#define lws_socket_is_valid(x) (x >= 0)
|
|
|
|
#define LWS_SOCK_INVALID (-1)
|
2011-03-02 22:03:47 +00:00
|
|
|
#endif
|
2015-11-02 13:10:33 +08:00
|
|
|
#endif
|
2011-03-02 22:03:47 +00:00
|
|
|
|
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
|
2016-03-28 19:58:02 +08:00
|
|
|
|
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>
|
2017-01-07 10:24:50 +08:00
|
|
|
#define OPENSSL_NO_TLSEXT
|
2015-08-09 22:56:32 +02:00
|
|
|
#endif /* not USE_OLD_CYASSL */
|
2013-02-06 15:43:00 +09:00
|
|
|
#else
|
2016-03-28 19:58:02 +08:00
|
|
|
#if defined(LWS_USE_POLARSSL)
|
|
|
|
#include <polarssl/ssl.h>
|
|
|
|
#include <polarssl/error.h>
|
|
|
|
#include <polarssl/md5.h>
|
|
|
|
#include <polarssl/sha1.h>
|
|
|
|
#include <polarssl/ecdh.h>
|
2016-04-17 11:28:43 +08:00
|
|
|
#define SSL_ERROR_WANT_READ POLARSSL_ERR_NET_WANT_READ
|
|
|
|
#define SSL_ERROR_WANT_WRITE POLARSSL_ERR_NET_WANT_WRITE
|
|
|
|
#define OPENSSL_VERSION_NUMBER 0x10002000L
|
2016-03-28 19:58:02 +08:00
|
|
|
#else
|
|
|
|
#if defined(LWS_USE_MBEDTLS)
|
|
|
|
#include <mbedtls/ssl.h>
|
|
|
|
#include <mbedtls/error.h>
|
|
|
|
#include <mbedtls/md5.h>
|
|
|
|
#include <mbedtls/sha1.h>
|
|
|
|
#include <mbedtls/ecdh.h>
|
|
|
|
#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>
|
2016-03-28 19:58:02 +08:00
|
|
|
#ifdef LWS_HAVE_OPENSSL_ECDH_H
|
|
|
|
#include <openssl/ecdh.h>
|
|
|
|
#endif
|
2016-06-28 19:50:40 +08:00
|
|
|
#include <openssl/x509v3.h>
|
2017-01-07 10:24:42 +08:00
|
|
|
|
|
|
|
#if (OPENSSL_VERSION_NUMBER < 0x0009080afL)
|
|
|
|
/* later openssl defines this to negate the presence of tlsext... but it was only
|
|
|
|
* introduced at 0.9.8j. Earlier versions don't know it exists so don't
|
|
|
|
* define it... making it look like the feature exists...
|
|
|
|
*/
|
|
|
|
#define OPENSSL_NO_TLSEXT
|
|
|
|
#endif
|
|
|
|
|
2016-03-28 19:58:02 +08:00
|
|
|
#endif /* not USE_MBEDTLS */
|
|
|
|
#endif /* not USE_POLARSSL */
|
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"
|
2016-07-23 14:18:25 +08:00
|
|
|
#if defined(WIN32) || defined(_WIN32)
|
|
|
|
#else
|
|
|
|
static inline int compatible_close(int fd) { return close(fd); }
|
|
|
|
#endif
|
2010-11-08 20:20:42 +00:00
|
|
|
|
2016-11-09 08:34:27 +08:00
|
|
|
#if defined(WIN32) || defined(_WIN32)
|
|
|
|
#include <gettimeofday.h>
|
|
|
|
#endif
|
|
|
|
|
2015-11-02 20:34:12 +08:00
|
|
|
#if defined(MBED_OPERATORS)
|
|
|
|
#undef compatible_close
|
|
|
|
#define compatible_close(fd) mbed3_delete_tcp_stream_socket(fd)
|
2015-11-08 12:10:26 +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
|
2015-11-02 20:34:12 +08:00
|
|
|
#endif
|
|
|
|
|
2016-07-23 14:18:25 +08:00
|
|
|
#if defined(LWS_WITH_ESP8266)
|
|
|
|
#undef compatible_close
|
|
|
|
#define compatible_close(fd) { fd->state=ESPCONN_CLOSE; espconn_delete(fd); }
|
|
|
|
lws_sockfd_type
|
|
|
|
esp8266_create_tcp_stream_socket(void);
|
|
|
|
void
|
|
|
|
esp8266_tcp_stream_bind(lws_sockfd_type fd, int port, struct lws *wsi);
|
|
|
|
#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
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
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
|
2015-11-08 12:10:26 +08:00
|
|
|
#ifndef u_int64_t
|
2014-04-02 14:25:10 +08:00
|
|
|
typedef unsigned __int64 u_int64_t;
|
2015-11-08 12:10:26 +08:00
|
|
|
#endif
|
2014-04-02 14:25:10 +08:00
|
|
|
|
|
|
|
#undef __P
|
|
|
|
#ifndef __P
|
|
|
|
#if __STDC__
|
|
|
|
#define __P(protos) protos
|
|
|
|
#else
|
|
|
|
#define __P(protos) ()
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#include <sys/stat.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
|
|
|
|
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__)
|
|
|
|
# define BYTE_ORDER __BYTE_ORDER__
|
|
|
|
# define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
|
|
|
|
# define BIG_ENDIAN __ORDER_BIG_ENDIAN__
|
|
|
|
#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
|
|
|
|
|
2016-09-09 06:49:44 +08:00
|
|
|
/*
|
|
|
|
* Solaris 11.X only supports POSIX 2001, MSG_NOSIGNAL appears in
|
|
|
|
* POSIX 2008.
|
|
|
|
*/
|
|
|
|
#ifdef __sun
|
|
|
|
#define MSG_NOSIGNAL 0
|
|
|
|
#endif
|
|
|
|
|
2015-01-30 10:13:01 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
#ifndef FD_HASHTABLE_MODULUS
|
|
|
|
#define FD_HASHTABLE_MODULUS 32
|
|
|
|
#endif
|
|
|
|
#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
|
2016-01-19 04:32:14 +08:00
|
|
|
#define LWS_MAX_EXTENSIONS_ACTIVE 2
|
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
|
|
|
|
|
2011-04-23 10:54:53 +01:00
|
|
|
enum lws_websocket_opcodes_07 {
|
2015-12-17 17:03:59 +08:00
|
|
|
LWSWSOPC_CONTINUATION = 0,
|
|
|
|
LWSWSOPC_TEXT_FRAME = 1,
|
|
|
|
LWSWSOPC_BINARY_FRAME = 2,
|
2011-05-23 10:00:03 +01:00
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
LWSWSOPC_NOSPEC__MUX = 7,
|
2011-05-23 10:00:03 +01:00
|
|
|
|
|
|
|
/* control extensions 8+ */
|
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
LWSWSOPC_CLOSE = 8,
|
|
|
|
LWSWSOPC_PING = 9,
|
|
|
|
LWSWSOPC_PONG = 0xa,
|
2011-04-23 10:54:53 +01:00
|
|
|
};
|
|
|
|
|
2011-05-23 10:00:03 +01:00
|
|
|
|
2010-11-08 20:20:42 +00:00
|
|
|
enum lws_connection_states {
|
2015-12-17 17:03:59 +08:00
|
|
|
LWSS_HTTP,
|
|
|
|
LWSS_HTTP_ISSUING_FILE,
|
|
|
|
LWSS_HTTP_HEADERS,
|
|
|
|
LWSS_HTTP_BODY,
|
|
|
|
LWSS_DEAD_SOCKET,
|
|
|
|
LWSS_ESTABLISHED,
|
2016-02-29 13:18:30 +08:00
|
|
|
LWSS_CLIENT_HTTP_ESTABLISHED,
|
2015-12-17 17:03:59 +08:00
|
|
|
LWSS_CLIENT_UNCONNECTED,
|
|
|
|
LWSS_RETURNED_CLOSE_ALREADY,
|
|
|
|
LWSS_AWAITING_CLOSE_ACK,
|
|
|
|
LWSS_FLUSHING_STORED_SEND_BEFORE_CLOSE,
|
2016-01-26 20:56:56 +08:00
|
|
|
LWSS_SHUTDOWN,
|
2015-12-17 17:03:59 +08:00
|
|
|
|
|
|
|
LWSS_HTTP2_AWAIT_CLIENT_PREFACE,
|
|
|
|
LWSS_HTTP2_ESTABLISHED_PRE_SETTINGS,
|
|
|
|
LWSS_HTTP2_ESTABLISHED,
|
2016-02-21 21:25:48 +08:00
|
|
|
|
2016-02-29 14:19:16 +08:00
|
|
|
LWSS_CGI,
|
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,
|
2016-04-10 09:33:54 +08:00
|
|
|
HTTP_VERSION_2
|
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_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
|
|
|
|
2016-01-11 11:34:01 +08:00
|
|
|
LWS_RXPS_04_mask_1,
|
|
|
|
LWS_RXPS_04_mask_2,
|
|
|
|
LWS_RXPS_04_mask_3,
|
2011-01-18 18:14:26 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2016-08-08 21:54:30 +08:00
|
|
|
#define LWSCM_FLAG_IMPLIES_CALLBACK_CLOSED_CLIENT_HTTP 32
|
2010-11-08 20:20:42 +00:00
|
|
|
|
2011-02-12 11:57:43 +00:00
|
|
|
enum connection_mode {
|
2015-12-17 17:03:59 +08:00
|
|
|
LWSCM_HTTP_SERVING,
|
|
|
|
LWSCM_HTTP_SERVING_ACCEPTED, /* actual HTTP service going on */
|
|
|
|
LWSCM_PRE_WS_SERVING_ACCEPT,
|
2013-01-15 13:40:23 +08:00
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
LWSCM_WS_SERVING,
|
|
|
|
LWSCM_WS_CLIENT,
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2015-12-17 17:03:59 +08:00
|
|
|
LWSCM_HTTP2_SERVING,
|
2011-02-12 11:57:43 +00:00
|
|
|
|
2013-01-28 12:19:10 +08:00
|
|
|
/* transient, ssl delay hiding */
|
2015-12-17 17:03:59 +08:00
|
|
|
LWSCM_SSL_ACK_PENDING,
|
2016-01-26 20:56:56 +08:00
|
|
|
LWSCM_SSL_INIT,
|
2013-01-28 12:19:10 +08:00
|
|
|
|
2016-08-08 21:54:30 +08:00
|
|
|
/* special internal types */
|
|
|
|
LWSCM_SERVER_LISTENER,
|
|
|
|
LWSCM_CGI, /* stdin, stdout, stderr for another cgi master wsi */
|
|
|
|
|
|
|
|
/* HTTP Client related */
|
|
|
|
LWSCM_HTTP_CLIENT = LWSCM_FLAG_IMPLIES_CALLBACK_CLOSED_CLIENT_HTTP,
|
|
|
|
LWSCM_HTTP_CLIENT_ACCEPTED, /* actual HTTP service going on */
|
2015-12-17 17:03:59 +08:00
|
|
|
LWSCM_WSCL_WAITING_CONNECT,
|
|
|
|
LWSCM_WSCL_WAITING_PROXY_REPLY,
|
|
|
|
LWSCM_WSCL_ISSUE_HANDSHAKE,
|
|
|
|
LWSCM_WSCL_ISSUE_HANDSHAKE2,
|
2016-08-08 21:54:30 +08:00
|
|
|
LWSCM_WSCL_ISSUE_HTTP_BODY,
|
2015-12-17 17:03:59 +08:00
|
|
|
LWSCM_WSCL_WAITING_SSL,
|
|
|
|
LWSCM_WSCL_WAITING_SERVER_REPLY,
|
|
|
|
LWSCM_WSCL_WAITING_EXTENSION_CONNECT,
|
|
|
|
LWSCM_WSCL_PENDING_CANDIDATE_CHILD,
|
2011-02-14 20:25:43 +00:00
|
|
|
|
2016-08-08 21:54:30 +08:00
|
|
|
/****** add new things just above ---^ ******/
|
|
|
|
|
|
|
|
|
2011-02-12 11:57:43 +00:00
|
|
|
};
|
|
|
|
|
2013-03-16 11:24:23 +08:00
|
|
|
enum {
|
|
|
|
LWS_RXFLOW_ALLOW = (1 << 0),
|
|
|
|
LWS_RXFLOW_PENDING_CHANGE = (1 << 1),
|
|
|
|
};
|
|
|
|
|
2015-12-26 17:20:34 +08:00
|
|
|
/* this is not usable directly by user code any more, lws_close_reason() */
|
|
|
|
#define LWS_WRITE_CLOSE 4
|
|
|
|
|
2015-12-04 11:08:32 +08:00
|
|
|
struct lws_protocols;
|
|
|
|
struct lws;
|
2011-01-19 13:11:55 +00:00
|
|
|
|
2016-02-14 09:27:41 +08:00
|
|
|
#if defined(LWS_USE_LIBEV) || defined(LWS_USE_LIBUV)
|
|
|
|
|
2014-03-23 13:25:07 +08:00
|
|
|
struct lws_io_watcher {
|
2016-02-14 09:27:41 +08:00
|
|
|
#ifdef LWS_USE_LIBEV
|
|
|
|
ev_io ev_watcher;
|
|
|
|
#endif
|
|
|
|
#ifdef LWS_USE_LIBUV
|
|
|
|
uv_poll_t uv_watcher;
|
|
|
|
#endif
|
|
|
|
struct lws_context *context;
|
2014-03-23 13:25:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct lws_signal_watcher {
|
2016-02-14 09:27:41 +08:00
|
|
|
#ifdef LWS_USE_LIBEV
|
|
|
|
ev_signal ev_watcher;
|
|
|
|
#endif
|
|
|
|
#ifdef LWS_USE_LIBUV
|
|
|
|
uv_signal_t uv_watcher;
|
|
|
|
#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
|
|
|
|
|
2015-12-25 12:44:12 +08: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct lws_fragments {
|
2016-06-02 12:32:38 +08:00
|
|
|
unsigned int offset;
|
2015-12-25 12:44:12 +08:00
|
|
|
unsigned short len;
|
|
|
|
unsigned char nfrag; /* which ah->frag[] continues this content, or 0 */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* these are assigned from a pool held in the context.
|
|
|
|
* Both client and server mode uses them for http header analysis
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct allocated_headers {
|
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
|
|
|
struct lws *wsi; /* owner */
|
2015-12-25 13:48:20 +08:00
|
|
|
char *data; /* prepared by context init to point to dedicated storage */
|
|
|
|
/*
|
|
|
|
* the randomly ordered fragments, indexed by frag_index and
|
|
|
|
* lws_fragments->nfrag for continuation.
|
|
|
|
*/
|
|
|
|
struct lws_fragments frags[WSI_TOKEN_COUNT * 2];
|
2016-01-26 20:56:56 +08:00
|
|
|
time_t assigned;
|
2015-12-25 12:44:12 +08:00
|
|
|
/*
|
|
|
|
* for each recognized token, frag_index says which frag[] his data
|
|
|
|
* starts in (0 means the token did not appear)
|
|
|
|
* the actual header data gets dumped as it comes in, into data[]
|
|
|
|
*/
|
|
|
|
unsigned char frag_index[WSI_TOKEN_COUNT];
|
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
|
|
|
unsigned char rx[2048];
|
|
|
|
unsigned int rxpos;
|
|
|
|
unsigned int rxlen;
|
2016-06-02 12:32:38 +08:00
|
|
|
unsigned int pos;
|
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
|
|
|
|
2015-12-25 12:44:12 +08:00
|
|
|
#ifndef LWS_NO_CLIENT
|
|
|
|
char initial_handshake_hash_base64[30];
|
|
|
|
#endif
|
2015-12-26 08:56:58 +08:00
|
|
|
|
|
|
|
unsigned char in_use;
|
|
|
|
unsigned char nfrag;
|
2015-12-25 12:44:12 +08:00
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
#endif
|
2016-01-19 03:34:24 +08:00
|
|
|
struct lws_pollfd *fds;
|
2016-07-23 14:18:25 +08:00
|
|
|
#if defined(LWS_WITH_ESP8266)
|
|
|
|
struct lws **lws_vs_fds_index;
|
|
|
|
#endif
|
2016-01-19 03:34:24 +08:00
|
|
|
struct lws *rx_draining_ext_list;
|
|
|
|
struct lws *tx_draining_ext_list;
|
2016-01-26 20:56:56 +08:00
|
|
|
struct lws *timeout_list;
|
2016-08-14 14:04:56 +02:00
|
|
|
#ifdef LWS_USE_LIBUV
|
2016-02-27 11:03:27 +08:00
|
|
|
struct lws_context *context;
|
2016-08-14 14:04:56 +02:00
|
|
|
#endif
|
2016-02-21 21:25:48 +08:00
|
|
|
#ifdef LWS_WITH_CGI
|
|
|
|
struct lws_cgi *cgi_list;
|
|
|
|
#endif
|
2016-01-26 20:56:56 +08:00
|
|
|
void *http_header_data;
|
|
|
|
struct allocated_headers *ah_pool;
|
|
|
|
struct lws *ah_wait_list;
|
|
|
|
int ah_wait_list_length;
|
2016-01-19 03:34:24 +08:00
|
|
|
#ifdef LWS_OPENSSL_SUPPORT
|
|
|
|
struct lws *pending_read_list; /* linked list */
|
|
|
|
#endif
|
2016-01-26 20:56:56 +08:00
|
|
|
#ifndef LWS_NO_SERVER
|
|
|
|
struct lws *wsi_listening;
|
2016-02-14 09:27:41 +08:00
|
|
|
#endif
|
|
|
|
#if defined(LWS_USE_LIBEV)
|
|
|
|
struct ev_loop *io_loop_ev;
|
|
|
|
#endif
|
|
|
|
#if defined(LWS_USE_LIBUV)
|
|
|
|
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;
|
2016-04-06 09:23:16 +08:00
|
|
|
uv_idle_t uv_idle;
|
2016-02-14 09:27:41 +08:00
|
|
|
#endif
|
|
|
|
#if defined(LWS_USE_LIBEV)
|
|
|
|
struct lws_io_watcher w_accept;
|
|
|
|
#endif
|
|
|
|
#if defined(LWS_USE_LIBEV) || defined(LWS_USE_LIBUV)
|
|
|
|
struct lws_signal_watcher w_sigint;
|
|
|
|
unsigned char ev_loop_foreign: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;
|
2016-01-19 03:34:24 +08:00
|
|
|
#else
|
2016-07-23 14:18:25 +08:00
|
|
|
lws_sockfd_type dummy_pipe_fds[2];
|
2014-03-28 15:44:56 +01:00
|
|
|
#endif
|
2016-01-26 20:56:56 +08:00
|
|
|
unsigned int fds_count;
|
|
|
|
|
|
|
|
short ah_count_in_use;
|
2016-02-27 11:03:27 +08:00
|
|
|
unsigned char tid;
|
2016-08-07 08:33:08 +08:00
|
|
|
unsigned char lock_depth;
|
2016-01-19 03:34:24 +08:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct lws_vhost {
|
2016-07-23 14:18:25 +08:00
|
|
|
#if !defined(LWS_WITH_ESP8266)
|
2016-03-28 10:10:43 +08:00
|
|
|
char http_proxy_address[128];
|
|
|
|
char proxy_basic_auth_token[128];
|
2016-07-23 14:18:25 +08:00
|
|
|
#endif
|
|
|
|
#if defined(LWS_WITH_ESP8266)
|
|
|
|
/* listen sockets need a place to hang their hat */
|
|
|
|
esp_tcp tcp;
|
|
|
|
#endif
|
2016-03-28 10:10:43 +08:00
|
|
|
struct lws_context *context;
|
|
|
|
struct lws_vhost *vhost_next;
|
2016-05-02 04:59:54 +08:00
|
|
|
const struct lws_http_mount *mount_list;
|
2016-03-28 10:10:43 +08:00
|
|
|
struct lws *lserv_wsi;
|
|
|
|
const char *name;
|
|
|
|
const char *iface;
|
|
|
|
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;
|
2016-03-28 10:10:43 +08:00
|
|
|
#ifdef LWS_OPENSSL_SUPPORT
|
|
|
|
SSL_CTX *ssl_ctx;
|
|
|
|
SSL_CTX *ssl_client_ctx;
|
|
|
|
#endif
|
|
|
|
#ifndef LWS_NO_EXTENSIONS
|
|
|
|
const struct lws_extension *extensions;
|
|
|
|
#endif
|
2016-05-04 15:59:27 +08:00
|
|
|
unsigned long long rx, tx;
|
|
|
|
unsigned long conn, trans, ws_upgrades, http2_upgrades;
|
2016-03-28 10:10:43 +08:00
|
|
|
|
|
|
|
int listen_port;
|
|
|
|
unsigned int http_proxy_port;
|
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;
|
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
|
|
|
|
|
|
|
#ifdef LWS_OPENSSL_SUPPORT
|
|
|
|
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-05-06 14:24:59 +08:00
|
|
|
unsigned char default_protocol_index;
|
2016-03-28 10:10:43 +08:00
|
|
|
};
|
|
|
|
|
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;
|
2016-04-15 14:01:29 +08:00
|
|
|
time_t time_up;
|
2016-01-19 03:34:24 +08:00
|
|
|
struct lws_plat_file_ops fops;
|
|
|
|
struct lws_context_per_thread pt[LWS_MAX_SMP];
|
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];
|
2016-07-23 14:18:25 +08:00
|
|
|
#else
|
|
|
|
#if defined(LWS_WITH_ESP8266)
|
|
|
|
struct espconn **connpool; /* .reverse points to the wsi */
|
|
|
|
void *rxd;
|
|
|
|
int rxd_len;
|
|
|
|
os_timer_t to_timer;
|
2015-01-30 10:13:01 +08:00
|
|
|
#else
|
2015-12-04 11:08:32 +08:00
|
|
|
struct lws **lws_lookup; /* fd to wsi */
|
2016-07-23 14:18:25 +08:00
|
|
|
#endif
|
2015-01-30 10:13:01 +08:00
|
|
|
#endif
|
2016-03-28 10:10:43 +08:00
|
|
|
struct lws_vhost *vhost_list;
|
2016-04-06 16:15:40 +08:00
|
|
|
struct lws_plugin *plugin_list;
|
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-01-19 04:32:14 +08:00
|
|
|
|
2016-02-14 09:27:41 +08:00
|
|
|
#if defined(LWS_USE_LIBEV)
|
|
|
|
lws_ev_signal_cb_t * lws_ev_sigint_cb;
|
|
|
|
#endif
|
|
|
|
#if defined(LWS_USE_LIBUV)
|
2016-03-22 14:04:15 +01:00
|
|
|
uv_signal_cb lws_uv_sigint_cb;
|
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
|
|
|
|
|
|
|
|
int max_fds;
|
2016-02-14 09:27:41 +08:00
|
|
|
#if defined(LWS_USE_LIBEV) || defined(LWS_USE_LIBUV)
|
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;
|
2016-03-28 10:10:43 +08:00
|
|
|
#ifdef LWS_OPENSSL_SUPPORT
|
|
|
|
#define lws_ssl_anybody_has_buffered_read(w) \
|
|
|
|
(w->vhost->use_ssl && \
|
|
|
|
w->context->pt[(int)w->tsi].pending_read_list)
|
|
|
|
#define lws_ssl_anybody_has_buffered_read_tsi(c, t) \
|
|
|
|
(/*c->use_ssl && */ \
|
|
|
|
c->pt[(int)t].pending_read_list)
|
|
|
|
#else
|
|
|
|
#define lws_ssl_anybody_has_buffered_read(ctx) (0)
|
|
|
|
#define lws_ssl_anybody_has_buffered_read_tsi(ctx, t) (0)
|
|
|
|
#endif
|
2016-02-14 09:27:41 +08:00
|
|
|
int count_wsi_allocated;
|
2016-04-20 06:10:56 +08:00
|
|
|
int count_cgi_spawned;
|
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;
|
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;
|
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;
|
2016-01-18 11:49:41 +08:00
|
|
|
|
|
|
|
unsigned int being_destroyed:1;
|
2016-02-14 09:27:41 +08:00
|
|
|
unsigned int requested_kill:1;
|
2016-04-06 16:15:40 +08:00
|
|
|
unsigned int protocol_init_done:1;
|
2010-12-18 15:13:50 +00:00
|
|
|
};
|
|
|
|
|
2016-03-28 10:10:43 +08:00
|
|
|
#define lws_get_context_protocol(ctx, x) ctx->vhost_list->protocols[x]
|
|
|
|
#define lws_get_vh_protocol(vh, x) vh->protocols[x]
|
|
|
|
|
2016-02-14 09:27:41 +08:00
|
|
|
LWS_EXTERN void
|
|
|
|
lws_close_free_wsi_final(struct lws *wsi);
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_libuv_closehandle(struct lws *wsi);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2016-02-14 09:27:41 +08:00
|
|
|
#if defined(LWS_USE_LIBEV)
|
2014-04-11 13:14:37 +08:00
|
|
|
LWS_EXTERN void
|
2015-12-16 18:19:08 +08:00
|
|
|
lws_libev_accept(struct lws *new_wsi, lws_sockfd_type accept_fd);
|
2014-04-11 13:14:37 +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)
|
2016-02-14 09:27:41 +08:00
|
|
|
LWS_EXTERN void lws_feature_status_libev(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)
|
2016-02-14 09:27:41 +08:00
|
|
|
#if LWS_POSIX
|
2014-04-11 13:14:37 +08:00
|
|
|
#define lws_feature_status_libev(_a) \
|
|
|
|
lwsl_notice("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
|
|
|
|
|
2016-02-14 09:27:41 +08:00
|
|
|
#if defined(LWS_USE_LIBUV)
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_libuv_accept(struct lws *new_wsi, lws_sockfd_type accept_fd);
|
|
|
|
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-03-23 09:22:11 +08:00
|
|
|
#define LWS_LIBUV_ENABLED(context) lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV)
|
2016-02-14 09:27:41 +08:00
|
|
|
LWS_EXTERN void lws_feature_status_libuv(struct lws_context_creation_info *info);
|
|
|
|
#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)
|
|
|
|
#if LWS_POSIX
|
|
|
|
#define lws_feature_status_libuv(_a) \
|
|
|
|
lwsl_notice("libuv support not compiled in\n")
|
|
|
|
#else
|
|
|
|
#define lws_feature_status_libuv(_a)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-03-24 16:09:25 +08:00
|
|
|
#ifdef LWS_USE_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
|
|
|
|
2016-03-30 22:47:02 -07:00
|
|
|
#ifdef LWS_USE_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
|
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
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
/* notice that these union members:
|
2015-12-14 08:52:03 +08:00
|
|
|
*
|
2014-10-08 12:00:53 +08:00
|
|
|
* hdr
|
|
|
|
* http
|
|
|
|
* http2
|
2015-12-14 08:52:03 +08:00
|
|
|
*
|
2014-10-08 12:00:53 +08:00
|
|
|
* all have a pointer to allocated_headers struct as their first member.
|
2015-12-14 08:52:03 +08:00
|
|
|
*
|
2014-10-08 12:00:53 +08:00
|
|
|
* It means for allocated_headers access, the three union paths can all be
|
2015-12-03 15:55:11 +02:00
|
|
|
* used interchangeably to access the same data
|
2014-10-08 12:00:53 +08:00
|
|
|
*/
|
|
|
|
|
2016-02-29 13:18:30 +08:00
|
|
|
|
|
|
|
#ifndef LWS_NO_CLIENT
|
|
|
|
struct client_info_stash {
|
|
|
|
char address[256];
|
2016-11-21 09:23:17 -06:00
|
|
|
char path[4096];
|
2016-02-29 13:18:30 +08:00
|
|
|
char host[256];
|
|
|
|
char origin[256];
|
|
|
|
char protocol[256];
|
|
|
|
char method[16];
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2016-02-29 14:19:16 +08:00
|
|
|
struct _lws_header_related {
|
|
|
|
/* MUST be first in struct */
|
|
|
|
struct allocated_headers *ah;
|
|
|
|
struct lws *ah_wait_list;
|
|
|
|
unsigned char *preamble_rx;
|
|
|
|
#ifndef LWS_NO_CLIENT
|
|
|
|
struct client_info_stash *stash;
|
|
|
|
#endif
|
|
|
|
unsigned int preamble_rx_len;
|
|
|
|
enum uri_path_states ups;
|
|
|
|
enum uri_esc_states ues;
|
|
|
|
short lextable_pos;
|
2016-06-02 12:32:38 +08:00
|
|
|
unsigned int current_token_limit;
|
2016-02-29 14:19:16 +08:00
|
|
|
#ifndef LWS_NO_CLIENT
|
|
|
|
unsigned short c_port;
|
|
|
|
#endif
|
|
|
|
char esc_stash;
|
|
|
|
char post_literal_equal;
|
|
|
|
unsigned char parser_state; /* enum lws_token_indexes */
|
|
|
|
char redirects;
|
|
|
|
};
|
|
|
|
|
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 */
|
2016-01-26 20:56:56 +08:00
|
|
|
struct lws *ah_wait_list;
|
2016-02-29 14:19:16 +08:00
|
|
|
unsigned char *preamble_rx;
|
|
|
|
#ifndef LWS_NO_CLIENT
|
|
|
|
struct client_info_stash *stash;
|
|
|
|
#endif
|
|
|
|
unsigned int preamble_rx_len;
|
2016-01-26 20:56:56 +08:00
|
|
|
struct lws *new_wsi_list;
|
2013-11-09 11:40:32 +08:00
|
|
|
unsigned long filepos;
|
|
|
|
unsigned long filelen;
|
2015-12-26 08:56:58 +08:00
|
|
|
lws_filefd_type fd;
|
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;
|
2015-11-02 13:10:33 +08:00
|
|
|
unsigned int content_length;
|
|
|
|
unsigned int content_remain;
|
2013-11-09 11:40:32 +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,
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
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,
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
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 {
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-10-18 12:23:05 +08:00
|
|
|
/* optional before first header block */
|
|
|
|
HPKS_OPT_PADDING,
|
|
|
|
HKPS_OPT_E_DEPENDENCY,
|
|
|
|
HKPS_OPT_WEIGHT,
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-10-18 12:23:05 +08:00
|
|
|
/* header block */
|
2014-10-09 16:57:47 +08:00
|
|
|
HPKS_TYPE,
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-10-12 08:38:16 +08:00
|
|
|
HPKS_IDX_EXT,
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-10-09 16:57:47 +08:00
|
|
|
HPKS_HLEN,
|
|
|
|
HPKS_HLEN_EXT,
|
|
|
|
|
|
|
|
HPKS_DATA,
|
2015-12-14 08:52:03 +08:00
|
|
|
|
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 {
|
2015-12-14 08:52:03 +08:00
|
|
|
/*
|
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;
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2015-12-04 11:08:32 +08:00
|
|
|
struct lws *parent_wsi;
|
|
|
|
struct lws *next_child_wsi;
|
2014-10-08 12:00:53 +08:00
|
|
|
|
2014-10-18 12:23:05 +08:00
|
|
|
struct hpack_dynamic_table *hpack_dyn_table;
|
2015-12-26 08:56:58 +08:00
|
|
|
struct lws *stream_wsi;
|
|
|
|
unsigned char ping_payload[8];
|
|
|
|
unsigned char one_setting[LWS_HTTP2_SETTINGS_LENGTH];
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
unsigned int count;
|
|
|
|
unsigned int length;
|
|
|
|
unsigned int stream_id;
|
2014-10-09 16:57:47 +08:00
|
|
|
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-18 12:23:05 +08:00
|
|
|
unsigned int hpack_e_dep;
|
2014-10-29 09:39:08 +08:00
|
|
|
int tx_credit;
|
2014-10-08 12:00:53 +08:00
|
|
|
unsigned int my_stream_id;
|
|
|
|
unsigned int child_count;
|
|
|
|
int my_priority;
|
2016-01-11 11:34:01 +08:00
|
|
|
|
2015-12-26 08:56:58 +08:00
|
|
|
unsigned int END_STREAM:1;
|
|
|
|
unsigned int END_HEADERS:1;
|
|
|
|
unsigned int send_END_STREAM:1;
|
|
|
|
unsigned int GOING_AWAY;
|
|
|
|
unsigned int requested_POLLOUT:1;
|
|
|
|
unsigned int waiting_tx_credit:1;
|
|
|
|
unsigned int huff:1;
|
|
|
|
unsigned int value:1;
|
|
|
|
|
|
|
|
unsigned short round_robin_POLLOUT;
|
|
|
|
unsigned short count_POLLOUT_children;
|
|
|
|
unsigned short hpack_pos;
|
|
|
|
|
|
|
|
unsigned char type;
|
|
|
|
unsigned char flags;
|
|
|
|
unsigned char frame_state;
|
|
|
|
unsigned char padding;
|
|
|
|
unsigned char hpack_m;
|
2014-10-08 12:00:53 +08:00
|
|
|
unsigned char initialized;
|
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_websocket_related {
|
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
|
|
|
/* cheapest way to deal with ah overlap with ws union transition */
|
2016-02-24 12:40:21 +08:00
|
|
|
struct _lws_header_related hdr;
|
2016-01-11 11:34:01 +08:00
|
|
|
char *rx_ubuf;
|
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
|
|
|
unsigned int rx_ubuf_alloc;
|
2016-01-11 11:34:01 +08:00
|
|
|
struct lws *rx_draining_ext_list;
|
|
|
|
struct lws *tx_draining_ext_list;
|
2016-07-15 13:41:38 +08:00
|
|
|
time_t time_next_ping_check;
|
2015-12-25 13:48:20 +08:00
|
|
|
size_t rx_packet_length;
|
2016-01-11 11:34:01 +08:00
|
|
|
unsigned int rx_ubuf_head;
|
|
|
|
unsigned char mask[4];
|
2015-12-26 17:20:34 +08:00
|
|
|
/* Also used for close content... control opcode == < 128 */
|
2016-01-11 11:34:01 +08:00
|
|
|
unsigned char ping_payload_buf[128 - 3 + LWS_PRE];
|
2015-12-26 17:20:34 +08:00
|
|
|
|
2015-12-26 08:56:58 +08:00
|
|
|
unsigned char ping_payload_len;
|
2016-01-11 11:34:01 +08:00
|
|
|
unsigned char mask_idx;
|
2011-01-19 12:20:27 +00:00
|
|
|
unsigned char opcode;
|
2013-01-09 18:06:55 +08:00
|
|
|
unsigned char rsv;
|
2016-01-11 11:34:01 +08:00
|
|
|
unsigned char rsv_first_msg;
|
2015-12-26 17:20:34 +08:00
|
|
|
/* zero if no info, or length including 2-byte close code */
|
|
|
|
unsigned char close_in_ping_buffer_len;
|
2015-12-29 09:46:03 +08:00
|
|
|
unsigned char utf8;
|
2016-01-11 11:34:01 +08:00
|
|
|
unsigned char stashed_write_type;
|
|
|
|
unsigned char tx_draining_stashed_wp;
|
2015-12-25 13:48:20 +08:00
|
|
|
|
|
|
|
unsigned int final:1;
|
2013-02-10 16:00:47 +08:00
|
|
|
unsigned int frame_is_binary:1;
|
|
|
|
unsigned int all_zero_nonce:1;
|
|
|
|
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 */
|
2015-12-25 13:14:09 +08:00
|
|
|
unsigned int ping_pending_flag:1;
|
2015-12-28 16:51:08 +08:00
|
|
|
unsigned int continuation_possible:1;
|
2015-12-28 17:05:40 +08:00
|
|
|
unsigned int owed_a_fin:1;
|
2015-12-29 12:28:48 +08:00
|
|
|
unsigned int check_utf8:1;
|
|
|
|
unsigned int defeat_check_utf8:1;
|
2016-01-11 11:34:01 +08:00
|
|
|
unsigned int pmce_compressed_message:1;
|
|
|
|
unsigned int stashed_write_pending:1;
|
|
|
|
unsigned int rx_draining_ext:1;
|
|
|
|
unsigned int tx_draining_ext:1;
|
2016-07-15 13:41:38 +08:00
|
|
|
unsigned int send_check_ping:1;
|
2013-01-21 11:04:23 +08:00
|
|
|
};
|
|
|
|
|
2016-02-21 21:25:48 +08:00
|
|
|
#ifdef LWS_WITH_CGI
|
|
|
|
|
|
|
|
/* wsi who is master of the cgi points to an lws_cgi */
|
|
|
|
|
|
|
|
struct lws_cgi {
|
|
|
|
struct lws_cgi *cgi_list;
|
|
|
|
struct lws *stdwsi[3]; /* points to the associated stdin/out/err wsis */
|
|
|
|
struct lws *wsi; /* owner */
|
2016-04-13 11:42:53 +08:00
|
|
|
unsigned long content_length;
|
|
|
|
unsigned long content_length_seen;
|
2016-02-21 21:25:48 +08:00
|
|
|
int pipe_fds[3][2];
|
|
|
|
int pid;
|
|
|
|
|
|
|
|
unsigned int being_closed:1;
|
|
|
|
};
|
2016-03-13 16:44:19 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
signed char char_to_hex(const char c);
|
2016-03-09 07:41:59 +08:00
|
|
|
|
2016-03-13 16:44:19 +08:00
|
|
|
#ifndef LWS_NO_CLIENT
|
|
|
|
enum lws_chunk_parser {
|
|
|
|
ELCP_HEX,
|
|
|
|
ELCP_CR,
|
|
|
|
ELCP_CONTENT,
|
|
|
|
ELCP_POST_CR,
|
|
|
|
ELCP_POST_LF,
|
|
|
|
};
|
2016-02-21 21:25:48 +08:00
|
|
|
#endif
|
|
|
|
|
2016-03-20 11:59:53 +08:00
|
|
|
struct lws_rewrite;
|
|
|
|
|
2016-04-15 12:00:23 +08:00
|
|
|
#ifdef LWS_WITH_ACCESS_LOG
|
|
|
|
struct lws_access_log {
|
|
|
|
char *header_log;
|
|
|
|
char *user_agent;
|
|
|
|
unsigned long sent;
|
|
|
|
int response;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2015-12-04 11:08:32 +08:00
|
|
|
struct lws {
|
2013-01-21 11:04:23 +08:00
|
|
|
|
2015-12-26 08:56:58 +08:00
|
|
|
/* structs */
|
|
|
|
/* members with mutually exclusive lifetimes are unionized */
|
|
|
|
|
|
|
|
union u {
|
|
|
|
struct _lws_http_mode_related http;
|
|
|
|
#ifdef LWS_USE_HTTP2
|
|
|
|
struct _lws_http2_related http2;
|
|
|
|
#endif
|
|
|
|
struct _lws_header_related hdr;
|
|
|
|
struct _lws_websocket_related ws;
|
|
|
|
} u;
|
|
|
|
|
2013-01-21 11:04:23 +08:00
|
|
|
/* lifetime members */
|
|
|
|
|
2016-02-14 09:27:41 +08:00
|
|
|
#if defined(LWS_USE_LIBEV) || defined(LWS_USE_LIBUV)
|
2015-12-14 08:52:03 +08:00
|
|
|
struct lws_io_watcher w_read;
|
2016-02-14 09:27:41 +08:00
|
|
|
#endif
|
|
|
|
#if defined(LWS_USE_LIBEV)
|
2015-12-14 08:52:03 +08:00
|
|
|
struct lws_io_watcher w_write;
|
2016-02-14 09:27:41 +08:00
|
|
|
#endif
|
2015-12-25 13:48:20 +08:00
|
|
|
time_t pending_timeout_limit;
|
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 */
|
2016-02-21 21:25:48 +08:00
|
|
|
#ifdef LWS_WITH_CGI
|
|
|
|
struct lws_cgi *cgi; /* wsi being cgi master have one of these */
|
|
|
|
#endif
|
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;
|
2016-01-19 04:32:14 +08:00
|
|
|
struct lws *timeout_list;
|
|
|
|
struct lws **timeout_list_prev;
|
2016-04-15 12:00:23 +08:00
|
|
|
#ifdef LWS_WITH_ACCESS_LOG
|
|
|
|
struct lws_access_log access_log;
|
|
|
|
#endif
|
2015-12-25 13:48:20 +08:00
|
|
|
void *user_space;
|
|
|
|
/* rxflow handling */
|
|
|
|
unsigned char *rxflow_buffer;
|
|
|
|
/* truncated send handling */
|
|
|
|
unsigned char *trunc_alloc; /* non-NULL means buffering in progress */
|
2016-07-23 14:18:25 +08:00
|
|
|
|
|
|
|
#if defined (LWS_WITH_ESP8266)
|
|
|
|
void *premature_rx;
|
|
|
|
unsigned short prem_rx_size, prem_rx_pos;
|
|
|
|
#endif
|
|
|
|
|
2013-01-21 11:04:23 +08:00
|
|
|
#ifndef LWS_NO_EXTENSIONS
|
2015-12-11 10:45:35 +08:00
|
|
|
const struct lws_extension *active_extensions[LWS_MAX_EXTENSIONS_ACTIVE];
|
2016-01-11 11:34:01 +08:00
|
|
|
void *act_ext_user[LWS_MAX_EXTENSIONS_ACTIVE];
|
2013-01-21 11:04:23 +08:00
|
|
|
#endif
|
2015-12-25 13:48:20 +08:00
|
|
|
#ifdef LWS_OPENSSL_SUPPORT
|
|
|
|
SSL *ssl;
|
2016-03-28 19:58:02 +08:00
|
|
|
#if !defined(LWS_USE_POLARSSL) && !defined(LWS_USE_MBEDTLS)
|
2015-12-25 13:48:20 +08:00
|
|
|
BIO *client_bio;
|
2016-03-28 19:58:02 +08:00
|
|
|
#endif
|
2015-12-25 13:48:20 +08:00
|
|
|
struct lws *pending_read_list_prev, *pending_read_list_next;
|
|
|
|
#endif
|
2016-03-20 11:55:25 +08:00
|
|
|
#ifdef LWS_WITH_HTTP_PROXY
|
2016-03-20 11:59:53 +08:00
|
|
|
struct lws_rewrite *rw;
|
|
|
|
#endif
|
2015-12-26 08:56:58 +08:00
|
|
|
#ifdef LWS_LATENCY
|
|
|
|
unsigned long action_start;
|
|
|
|
unsigned long latency_start;
|
|
|
|
#endif
|
|
|
|
/* pointer / int */
|
2015-12-25 13:48:20 +08:00
|
|
|
lws_sockfd_type sock;
|
2011-04-24 05:46:23 +01:00
|
|
|
|
2015-12-26 08:56:58 +08:00
|
|
|
/* ints */
|
2015-12-25 13:48:20 +08:00
|
|
|
int position_in_fds_table;
|
|
|
|
int rxflow_len;
|
|
|
|
int rxflow_pos;
|
|
|
|
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;
|
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-02-28 10:55:31 +08:00
|
|
|
unsigned int more_rx_waiting:1; /* has to live here since ah may stick to end */
|
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;
|
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;
|
2017-04-05 08:31:33 +08:00
|
|
|
|
2016-07-23 14:18:25 +08:00
|
|
|
#if defined(LWS_WITH_ESP8266)
|
|
|
|
unsigned int pending_send_completion:3;
|
|
|
|
unsigned int close_is_pending_send_completion:1;
|
|
|
|
#endif
|
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;
|
2016-03-20 11:55:25 +08:00
|
|
|
#endif
|
|
|
|
#ifdef LWS_WITH_HTTP_PROXY
|
2016-03-20 11:59:53 +08:00
|
|
|
unsigned int perform_rewrite:1;
|
2016-02-29 13:18:30 +08:00
|
|
|
#endif
|
2015-12-25 13:48:20 +08:00
|
|
|
#ifndef LWS_NO_EXTENSIONS
|
|
|
|
unsigned int extension_data_pending:1;
|
|
|
|
#endif
|
|
|
|
#ifdef LWS_OPENSSL_SUPPORT
|
2016-07-07 08:14:26 +08:00
|
|
|
unsigned int use_ssl:3;
|
2015-12-25 13:48:20 +08:00
|
|
|
unsigned int upgraded:1;
|
|
|
|
#endif
|
2015-12-26 08:56:58 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
unsigned int sock_send_blocking:1;
|
|
|
|
#endif
|
2016-03-17 15:26:49 +08:00
|
|
|
#ifdef LWS_OPENSSL_SUPPORT
|
|
|
|
unsigned int redirect_to_https:1;
|
|
|
|
#endif
|
2013-02-11 21:43:41 +08:00
|
|
|
|
2017-04-05 08:31:33 +08:00
|
|
|
/* volatile to make sure code is aware other thread can change */
|
|
|
|
volatile unsigned int handling_pollout:1;
|
|
|
|
volatile unsigned int leave_pollout_active:1;
|
|
|
|
|
2015-12-26 08:56:58 +08:00
|
|
|
/* chars */
|
2015-12-25 13:48:20 +08:00
|
|
|
#ifndef LWS_NO_EXTENSIONS
|
2016-01-11 11:34:01 +08:00
|
|
|
unsigned char count_act_ext;
|
2015-12-25 13:48:20 +08:00
|
|
|
#endif
|
|
|
|
unsigned char ietf_spec_revision;
|
|
|
|
char mode; /* enum connection_mode */
|
|
|
|
char state; /* enum lws_connection_states */
|
2016-01-26 20:56:56 +08:00
|
|
|
char state_pre_close;
|
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 04:32:14 +08:00
|
|
|
char pps; /* enum lws_pending_protocol_send */
|
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;
|
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 */
|
|
|
|
#endif
|
2010-11-08 20:20:42 +00:00
|
|
|
};
|
|
|
|
|
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 09:00:45 +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);
|
|
|
|
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN void
|
2015-12-15 21:15:58 +08:00
|
|
|
lws_close_free_wsi(struct lws *wsi, enum lws_close_status);
|
2013-02-12 10:19:08 +08:00
|
|
|
|
2014-04-03 07:42:50 +08:00
|
|
|
LWS_EXTERN int
|
2015-12-15 21:15:58 +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
|
|
|
|
|
2015-12-06 09:15:27 +08:00
|
|
|
LWS_EXTERN void
|
2015-12-15 21:15:58 +08:00
|
|
|
lws_set_protocol_write_pending(struct lws *wsi,
|
2015-12-06 09:15:27 +08:00
|
|
|
enum lws_pending_protocol_send pend);
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_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
|
2015-12-15 21:15:58 +08:00
|
|
|
lws_parse(struct lws *wsi, unsigned char c);
|
2010-12-18 15:13:50 +00: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_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);
|
|
|
|
|
2016-07-23 14:18:25 +08:00
|
|
|
#if defined(_WIN32) || defined(MBED_OPERATORS) || defined(LWS_WITH_ESP8266)
|
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
|
2015-12-14 08:52:03 +08:00
|
|
|
#define wsi_from_fd(A,B) A->lws_lookup[B]
|
2016-01-26 20:56:56 +08:00
|
|
|
#define insert_wsi(A,B) assert(A->lws_lookup[B->sock] == 0); A->lws_lookup[B->sock]=B
|
2015-01-30 10:13:01 +08:00
|
|
|
#define delete_from_fd(A,B) A->lws_lookup[B]=0
|
|
|
|
#endif
|
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2015-12-06 09:15:27 +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
|
|
|
|
2011-03-06 10:29:39 +00: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_service_timeout_check(struct lws *wsi, unsigned int sec);
|
2011-05-23 10:00:03 +01:00
|
|
|
|
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
|
|
|
|
lws_client_reset(struct lws *wsi, int ssl, const char *address, int port,
|
|
|
|
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
|
2016-03-28 10:10:43 +08:00
|
|
|
lws_create_new_server_wsi(struct lws_vhost *vhost);
|
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);
|
|
|
|
|
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,
|
2015-12-06 09:15:27 +08:00
|
|
|
struct lws_context *context);
|
2013-02-13 09:29:26 +08:00
|
|
|
LWS_EXTERN int
|
2016-01-20 16:56:06 +08:00
|
|
|
lws_any_extension_handled(struct lws *wsi, enum lws_extension_callback_reasons r,
|
2012-04-09 15:09:01 +08:00
|
|
|
void *v, size_t len);
|
2011-05-23 10:00:03 +01:00
|
|
|
|
2014-04-02 19:45:42 +08:00
|
|
|
LWS_EXTERN int
|
2016-01-20 16:56:06 +08:00
|
|
|
lws_ext_cb_active(struct lws *wsi, int reason, void *buf, int len);
|
2014-04-02 19:45:42 +08:00
|
|
|
LWS_EXTERN int
|
2016-01-20 16:56:06 +08:00
|
|
|
lws_ext_cb_all_exts(struct lws_context *context, struct lws *wsi, int reason,
|
|
|
|
void *arg, int len);
|
2016-01-11 11:34:01 +08:00
|
|
|
|
2014-04-02 19:45:42 +08:00
|
|
|
#else
|
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
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_rx_sm(struct lws *wsi, unsigned char c);
|
2011-05-23 10:00:03 +01:00
|
|
|
|
2016-09-10 04:43:07 +08:00
|
|
|
LWS_EXTERN int
|
2016-03-17 09:34:15 +08:00
|
|
|
lws_payload_until_length_exhausted(struct lws *wsi, unsigned char **buf, size_t *len);
|
|
|
|
|
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
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_union_transition(struct lws *wsi, enum connection_mode mode);
|
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);
|
2014-10-08 12:00:53 +08:00
|
|
|
#ifdef LWS_USE_HTTP2
|
2015-12-04 11:08:32 +08:00
|
|
|
LWS_EXTERN struct lws *lws_http2_get_network_wsi(struct lws *wsi);
|
|
|
|
struct lws * lws_http2_get_nth_child(struct lws *wsi, int n);
|
2014-10-08 12:00:53 +08:00
|
|
|
LWS_EXTERN int
|
2015-12-06 09:15:27 +08:00
|
|
|
lws_http2_interpret_settings_payload(struct http2_settings *settings,
|
|
|
|
unsigned char *buf, int len);
|
2014-10-08 12:00:53 +08:00
|
|
|
LWS_EXTERN void lws_http2_init(struct http2_settings *settings);
|
|
|
|
LWS_EXTERN int
|
2015-12-16 18:19:08 +08:00
|
|
|
lws_http2_parser(struct lws *wsi, unsigned char c);
|
2015-12-06 09:15:27 +08:00
|
|
|
LWS_EXTERN int lws_http2_do_pps_send(struct lws_context *context,
|
|
|
|
struct lws *wsi);
|
|
|
|
LWS_EXTERN int lws_http2_frame_write(struct lws *wsi, int type, int flags,
|
|
|
|
unsigned int sid, unsigned int len,
|
|
|
|
unsigned char *buf);
|
2015-12-04 11:08:32 +08:00
|
|
|
LWS_EXTERN struct lws *
|
|
|
|
lws_http2_wsi_from_id(struct lws *wsi, unsigned int sid);
|
2015-12-16 18:19:08 +08:00
|
|
|
LWS_EXTERN int lws_hpack_interpret(struct lws *wsi,
|
2014-10-12 08:38:16 +08:00
|
|
|
unsigned char c);
|
2014-10-12 14:31:47 +08:00
|
|
|
LWS_EXTERN int
|
2015-12-16 18:19:08 +08:00
|
|
|
lws_add_http2_header_by_name(struct lws *wsi,
|
2015-12-06 09:15:27 +08:00
|
|
|
const unsigned char *name,
|
|
|
|
const unsigned char *value, int length,
|
|
|
|
unsigned char **p, unsigned char *end);
|
2014-10-12 14:31:47 +08:00
|
|
|
LWS_EXTERN int
|
2015-12-16 18:19:08 +08:00
|
|
|
lws_add_http2_header_by_token(struct lws *wsi,
|
2014-10-12 14:31:47 +08:00
|
|
|
enum lws_token_indexes token,
|
2015-12-06 09:15:27 +08:00
|
|
|
const unsigned char *value, int length,
|
|
|
|
unsigned char **p, unsigned char *end);
|
2014-10-12 14:31:47 +08:00
|
|
|
LWS_EXTERN int
|
2015-12-16 18:19:08 +08:00
|
|
|
lws_add_http2_header_status(struct lws *wsi,
|
2015-12-06 09:15:27 +08:00
|
|
|
unsigned int code, unsigned char **p,
|
2014-10-12 14:31:47 +08:00
|
|
|
unsigned char *end);
|
2014-10-22 15:37:28 +08:00
|
|
|
LWS_EXTERN
|
2015-12-04 11:08:32 +08:00
|
|
|
void lws_http2_configure_if_upgraded(struct lws *wsi);
|
2014-10-22 15:37:28 +08:00
|
|
|
#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
|
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);
|
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);
|
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
|
2014-04-03 08:24:29 +08:00
|
|
|
int lws_context_init_server(struct lws_context_creation_info *info,
|
2016-03-28 10:10:43 +08:00
|
|
|
struct lws_vhost *vhost);
|
|
|
|
LWS_EXTERN struct lws_vhost *
|
|
|
|
lws_select_vhost(struct lws_context *context, int port, const char *servername);
|
2014-04-10 14:08:10 +08:00
|
|
|
LWS_EXTERN int
|
2015-12-06 09:15:27 +08:00
|
|
|
handshake_0405(struct lws_context *context, struct lws *wsi);
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2016-01-11 11:34:01 +08:00
|
|
|
lws_interpret_incoming_packet(struct lws *wsi, unsigned char **buf, size_t len);
|
2014-04-12 10:07:02 +08:00
|
|
|
LWS_EXTERN void
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_server_get_canonical_hostname(struct lws_context *context,
|
2015-12-06 09:15:27 +08:00
|
|
|
struct lws_context_creation_info *info);
|
2014-04-03 08:24:29 +08:00
|
|
|
#else
|
|
|
|
#define lws_context_init_server(_a, _b) (0)
|
2015-12-04 09:23:56 +08:00
|
|
|
#define lws_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
|
|
|
|
|
2016-07-23 14:18:25 +08:00
|
|
|
#if !defined(MBED_OPERATORS) && !defined(LWS_WITH_ESP8266)
|
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);
|
2015-11-02 13:10:33 +08:00
|
|
|
#endif
|
2014-04-03 23:34:09 +08:00
|
|
|
LWS_EXTERN void lwsl_emit_stderr(int level, const char *line);
|
|
|
|
|
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
|
2016-01-26 20:56:56 +08:00
|
|
|
#define lws_server_socket_service_ssl(_b, _c) (0)
|
2014-04-12 10:07:02 +08:00
|
|
|
#define lws_ssl_close(_a) (0)
|
|
|
|
#define lws_ssl_context_destroy(_a)
|
2016-03-28 10:10:43 +08:00
|
|
|
#define lws_ssl_SSL_CTX_destroy(_a)
|
2015-12-15 21:15:58 +08:00
|
|
|
#define lws_ssl_remove_wsi_from_buffered_list(_a)
|
2016-03-28 10:10:43 +08:00
|
|
|
#define lws_context_init_ssl_library(_a)
|
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;
|
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(struct lws *wsi, unsigned char *buf, int len);
|
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(struct lws *wsi, unsigned char *buf, int len);
|
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(struct lws *wsi);
|
2016-03-28 10:10:43 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_context_init_ssl_library(struct lws_context_creation_info *info);
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2016-01-26 20:56:56 +08:00
|
|
|
lws_server_socket_service_ssl(struct lws *new_wsi, lws_sockfd_type accept_fd);
|
2014-04-12 10:07:02 +08:00
|
|
|
LWS_EXTERN int
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_ssl_close(struct lws *wsi);
|
2014-04-12 10:07:02 +08:00
|
|
|
LWS_EXTERN void
|
2016-03-28 10:10:43 +08:00
|
|
|
lws_ssl_SSL_CTX_destroy(struct lws_vhost *vhost);
|
|
|
|
LWS_EXTERN void
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_ssl_context_destroy(struct lws_context *context);
|
2015-01-29 08:36:18 +08:00
|
|
|
LWS_VISIBLE void
|
2015-12-15 21:15:58 +08:00
|
|
|
lws_ssl_remove_wsi_from_buffered_list(struct lws *wsi);
|
2016-03-28 12:43:55 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_ssl_client_bio_create(struct lws *wsi);
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_ssl_client_connect1(struct lws *wsi);
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_ssl_client_connect2(struct lws *wsi);
|
2016-05-03 07:26:10 +08:00
|
|
|
LWS_EXTERN void
|
|
|
|
lws_ssl_elaborate_error(void);
|
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,
|
2016-03-28 10:10:43 +08:00
|
|
|
struct lws_vhost *vhost);
|
2014-04-03 10:17:00 +08:00
|
|
|
#else
|
|
|
|
#define lws_context_init_server_ssl(_a, _b) (0)
|
|
|
|
#endif
|
|
|
|
LWS_EXTERN void
|
2016-03-28 10:10:43 +08:00
|
|
|
lws_ssl_destroy(struct lws_vhost *vhost);
|
2014-04-03 14:33:48 +08:00
|
|
|
|
|
|
|
/* HTTP2-related */
|
|
|
|
|
|
|
|
#ifdef LWS_USE_HTTP2
|
|
|
|
LWS_EXTERN void
|
2016-04-10 09:33:54 +08:00
|
|
|
lws_context_init_http2_ssl(struct lws_vhost *vhost);
|
2014-04-03 14:33:48 +08:00
|
|
|
#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
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
#if LWS_MAX_SMP > 1
|
|
|
|
static LWS_INLINE void
|
|
|
|
lws_pt_mutex_init(struct lws_context_per_thread *pt)
|
|
|
|
{
|
|
|
|
pthread_mutex_init(&pt->lock, NULL);
|
|
|
|
}
|
2016-05-12 20:22:35 -05:00
|
|
|
|
|
|
|
static LWS_INLINE void
|
|
|
|
lws_pt_mutex_destroy(struct lws_context_per_thread *pt)
|
|
|
|
{
|
|
|
|
pthread_mutex_destroy(&pt->lock);
|
|
|
|
}
|
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
static LWS_INLINE void
|
|
|
|
lws_pt_lock(struct lws_context_per_thread *pt)
|
|
|
|
{
|
2016-08-07 08:33:08 +08:00
|
|
|
if (!pt->lock_depth++)
|
|
|
|
pthread_mutex_lock(&pt->lock);
|
2016-01-26 20:56:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static LWS_INLINE void
|
|
|
|
lws_pt_unlock(struct lws_context_per_thread *pt)
|
|
|
|
{
|
2016-08-07 08:33:08 +08:00
|
|
|
if (!(--pt->lock_depth))
|
|
|
|
pthread_mutex_unlock(&pt->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)
|
2016-01-26 20:56:56 +08:00
|
|
|
#define lws_pt_lock(_a) (void)(_a)
|
|
|
|
#define lws_pt_unlock(_a) (void)(_a)
|
|
|
|
#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
|
|
|
|
2016-03-20 11:59:53 +08:00
|
|
|
#ifdef LWS_WITH_HTTP_PROXY
|
|
|
|
struct lws_rewrite {
|
|
|
|
hubbub_parser *parser;
|
|
|
|
hubbub_parser_optparams params;
|
|
|
|
const char *from, *to;
|
|
|
|
int from_len, to_len;
|
|
|
|
unsigned char *p, *end;
|
|
|
|
struct lws *wsi;
|
|
|
|
};
|
|
|
|
static LWS_INLINE int hstrcmp(hubbub_string *s, const char *p, int len)
|
|
|
|
{
|
|
|
|
if (s->len != len)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return strncmp((const char *)s->ptr, p, len);
|
|
|
|
}
|
|
|
|
typedef hubbub_error (*hubbub_callback_t)(const hubbub_token *token, void *pw);
|
|
|
|
LWS_EXTERN struct lws_rewrite *
|
|
|
|
lws_rewrite_create(struct lws *wsi, hubbub_callback_t cb, const char *from, const char *to);
|
|
|
|
LWS_EXTERN void
|
|
|
|
lws_rewrite_destroy(struct lws_rewrite *r);
|
|
|
|
LWS_EXTERN int
|
|
|
|
lws_rewrite_parse(struct lws_rewrite *r, const unsigned char *in, int in_len);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef LWS_NO_CLIENT
|
2016-03-20 11:55:25 +08:00
|
|
|
LWS_EXTERN int lws_client_socket_service(struct lws_context *context,
|
|
|
|
struct lws *wsi,
|
|
|
|
struct lws_pollfd *pollfd);
|
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
|
|
|
lws_http_transaction_completed_client(struct lws *wsi);
|
2014-04-03 10:17:00 +08:00
|
|
|
#ifdef LWS_OPENSSL_SUPPORT
|
2015-12-06 09:15:27 +08:00
|
|
|
LWS_EXTERN int
|
|
|
|
lws_context_init_client_ssl(struct lws_context_creation_info *info,
|
2016-03-28 10:10:43 +08:00
|
|
|
struct lws_vhost *vhost);
|
2014-04-03 10:17:00 +08:00
|
|
|
#else
|
|
|
|
#define lws_context_init_client_ssl(_a, _b) (0)
|
|
|
|
#endif
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
|
2015-12-06 09:15:27 +08:00
|
|
|
lws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len);
|
|
|
|
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 09:03:37 +08:00
|
|
|
#define lws_handshake_client(_a, _b, _c) (0)
|
2014-04-03 07:16:40 +08:00
|
|
|
#endif
|
2015-12-28 14:24:49 +08:00
|
|
|
|
|
|
|
LWS_EXTERN int
|
|
|
|
_lws_rx_flow_control(struct lws *wsi);
|
|
|
|
|
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
|
|
|
|
lws_server_socket_service(struct lws_context *context, struct lws *wsi,
|
|
|
|
struct lws_pollfd *pollfd);
|
|
|
|
LWS_EXTERN int
|
2015-12-16 18:19:08 +08:00
|
|
|
lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len);
|
2015-12-25 09:12:08 +08:00
|
|
|
LWS_EXTERN int
|
2016-01-26 20:56:56 +08:00
|
|
|
_lws_server_listen_accept_flow_control(struct lws *twsi, int on);
|
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)
|
2015-12-16 18:19:08 +08:00
|
|
|
#define lws_handshake_server(_a, _b, _c) (0)
|
2015-12-25 09:12:08 +08:00
|
|
|
#define _lws_server_listen_accept_flow_control(a, b) (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);
|
|
|
|
#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);
|
|
|
|
|
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 *
|
2014-12-04 23:15:27 +01:00
|
|
|
lws_realloc(void *ptr, size_t size);
|
|
|
|
|
2016-01-20 16:56:06 +08:00
|
|
|
LWS_EXTERN void * LWS_WARN_UNUSED_RESULT
|
2014-12-04 23:15:27 +01:00
|
|
|
lws_zalloc(size_t size);
|
|
|
|
|
|
|
|
#define lws_malloc(S) lws_realloc(NULL, S)
|
|
|
|
#define lws_free(P) lws_realloc(P, 0)
|
2015-12-17 17:03:59 +08:00
|
|
|
#define lws_free_set_NULL(P) do { lws_realloc(P, 0); (P) = NULL; } while(0)
|
2014-12-04 23:15:27 +01:00
|
|
|
|
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:50:32 +08:00
|
|
|
LWS_EXTERN void
|
2017-03-26 10:11:39 +08:00
|
|
|
lws_add_wsi_to_draining_ext_list(struct lws *wsi);
|
|
|
|
LWS_EXTERN void
|
2017-03-25 08:50:32 +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
|
|
|
|
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,
|
|
|
|
struct lws_context_creation_info *info);
|
2014-04-03 07:16:40 +08:00
|
|
|
LWS_EXTERN void
|
|
|
|
lws_plat_drop_app_privileges(struct lws_context_creation_info *info);
|
|
|
|
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);
|
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);
|
|
|
|
|
2015-11-02 20:34:12 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
};
|
|
|
|
#endif
|