Andy Green | 7c212cc | 2010-11-08 20:20:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libwebsockets - small server side websockets and web server implementation |
Andy Green | e77ddd8 | 2010-11-13 10:03:47 +0000 | [diff] [blame] | 3 | * |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 4 | * Copyright (C) 2010 - 2015 Andy Green <andy@warmcat.com> |
Andy Green | 7c212cc | 2010-11-08 20:20:42 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation: |
| 9 | * version 2.1 of the License. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 19 | * MA 02110-1301 USA |
| 20 | */ |
Joakim Soderberg | 91de933 | 2013-02-06 15:30:33 +0900 | [diff] [blame] | 21 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 22 | #include "lws_config.h" |
Roger A. Light | 7a474b4 | 2015-06-26 11:40:54 +0200 | [diff] [blame] | 23 | #include "lws_config_private.h" |
Andy Green | e40aa9b | 2014-04-02 21:02:54 +0800 | [diff] [blame] | 24 | |
=?UTF-8?q?Joakim=20S=C3=B6derberg?= | cefab31 | 2015-06-24 16:46:02 +0200 | [diff] [blame] | 25 | #ifdef LWS_HAVE_SYS_TYPES_H |
Andy Green | e40aa9b | 2014-04-02 21:02:54 +0800 | [diff] [blame] | 26 | #include <sys/types.h> |
Joakim Soderberg | 91de933 | 2013-02-06 15:30:33 +0900 | [diff] [blame] | 27 | #endif |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 28 | |
Andy Green | 7c212cc | 2010-11-08 20:20:42 +0000 | [diff] [blame] | 29 | #include <stdio.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <string.h> |
Patrick Gansterer | b13eed4 | 2014-03-30 10:19:23 +0200 | [diff] [blame] | 32 | #include <time.h> |
Andy Green | 7c212cc | 2010-11-08 20:20:42 +0000 | [diff] [blame] | 33 | #include <ctype.h> |
Peter Young | 26757a7 | 2013-01-17 10:08:16 +0800 | [diff] [blame] | 34 | #include <limits.h> |
Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 35 | #include <stdarg.h> |
Andy Green | 112f980 | 2015-12-04 07:22:44 +0800 | [diff] [blame] | 36 | #include <assert.h> |
Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 37 | |
=?UTF-8?q?Joakim=20S=C3=B6derberg?= | cefab31 | 2015-06-24 16:46:02 +0200 | [diff] [blame] | 38 | #ifdef LWS_HAVE_SYS_STAT_H |
Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 39 | #include <sys/stat.h> |
Patrick Gansterer | e5720a3 | 2014-02-28 00:57:19 +0100 | [diff] [blame] | 40 | #endif |
Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 41 | |
Andreas Pakulat | 68bd4bd | 2013-10-28 15:18:04 +0100 | [diff] [blame] | 42 | #if defined(WIN32) || defined(_WIN32) |
Stephan Eberle | b820e2c | 2015-10-23 08:10:55 +0200 | [diff] [blame] | 43 | #if (WINVER < 0x0501) |
| 44 | #undef WINVER |
| 45 | #undef _WIN32_WINNT |
| 46 | #define WINVER 0x0501 |
| 47 | #define _WIN32_WINNT WINVER |
| 48 | #endif |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 49 | #define LWS_NO_DAEMONIZE |
Patrick Gansterer | 2dbd837 | 2014-02-28 12:37:52 +0100 | [diff] [blame] | 50 | #define LWS_ERRNO WSAGetLastError() |
| 51 | #define LWS_EAGAIN WSAEWOULDBLOCK |
| 52 | #define LWS_EALREADY WSAEALREADY |
| 53 | #define LWS_EINPROGRESS WSAEINPROGRESS |
| 54 | #define LWS_EINTR WSAEINTR |
| 55 | #define LWS_EISCONN WSAEISCONN |
| 56 | #define LWS_EWOULDBLOCK WSAEWOULDBLOCK |
Patrick Gansterer | b47f87b | 2014-03-30 09:18:05 +0200 | [diff] [blame] | 57 | #define LWS_POLLHUP (FD_CLOSE) |
Patrick Gansterer | 0fc37b6 | 2014-03-28 15:44:56 +0100 | [diff] [blame] | 58 | #define LWS_POLLIN (FD_READ | FD_ACCEPT) |
| 59 | #define LWS_POLLOUT (FD_WRITE) |
Patrick Gansterer | 73882e4 | 2014-03-29 08:25:58 +0100 | [diff] [blame] | 60 | #define MSG_NOSIGNAL 0 |
| 61 | #define SHUT_RDWR SD_BOTH |
| 62 | #define SOL_TCP IPPROTO_TCP |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 63 | |
Andy Green | 158e804 | 2014-04-02 14:25:10 +0800 | [diff] [blame] | 64 | #define compatible_close(fd) closesocket(fd) |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 65 | #define lws_set_blocking_send(wsi) wsi->sock_send_blocking = 1 |
Andy Green | c53f7ca | 2015-11-14 07:35:27 +0800 | [diff] [blame] | 66 | #define lws_socket_is_valid(x) (!!x) |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 67 | #define LWS_SOCK_INVALID 0 |
Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 68 | #include <winsock2.h> |
Andy Green | eee0d8a | 2015-12-17 15:15:12 +0800 | [diff] [blame] | 69 | #include <ws2tcpip.h> |
Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 70 | #include <windows.h> |
Joakim Soderberg | d2f5b19 | 2014-04-07 11:28:08 +0200 | [diff] [blame] | 71 | #include <tchar.h> |
=?UTF-8?q?Joakim=20S=C3=B6derberg?= | cefab31 | 2015-06-24 16:46:02 +0200 | [diff] [blame] | 72 | #ifdef LWS_HAVE_IN6ADDR_H |
Andy Green | 0f58db3 | 2014-04-12 11:10:35 +0800 | [diff] [blame] | 73 | #include <in6addr.h> |
| 74 | #endif |
Joakim Soderberg | d2f5b19 | 2014-04-07 11:28:08 +0200 | [diff] [blame] | 75 | #include <mstcpip.h> |
| 76 | |
| 77 | #ifndef __func__ |
| 78 | #define __func__ __FUNCTION__ |
| 79 | #endif |
| 80 | |
Patrick Gansterer | 6bb4b62 | 2014-04-15 18:39:26 +0200 | [diff] [blame] | 81 | #ifdef _WIN32_WCE |
| 82 | #define vsnprintf _vsnprintf |
| 83 | #endif |
| 84 | |
Andy Green | 158e804 | 2014-04-02 14:25:10 +0800 | [diff] [blame] | 85 | #else /* not windows --> */ |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 86 | |
Patrick Gansterer | b13eed4 | 2014-03-30 10:19:23 +0200 | [diff] [blame] | 87 | #include <fcntl.h> |
Patrick Gansterer | b13eed4 | 2014-03-30 10:19:23 +0200 | [diff] [blame] | 88 | #include <strings.h> |
| 89 | #include <unistd.h> |
Andy Green | e77ddd8 | 2010-11-13 10:03:47 +0000 | [diff] [blame] | 90 | #include <sys/types.h> |
Andy Green | 5f2a815 | 2015-11-02 08:21:08 +0800 | [diff] [blame] | 91 | #ifndef MBED_OPERATORS |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 92 | #ifndef __cplusplus |
| 93 | #include <errno.h> |
| 94 | #endif |
Andy Green | 5f2a815 | 2015-11-02 08:21:08 +0800 | [diff] [blame] | 95 | #include <netdb.h> |
| 96 | #include <signal.h> |
Andy Green | 7c212cc | 2010-11-08 20:20:42 +0000 | [diff] [blame] | 97 | #include <sys/socket.h> |
Andy Green | e40aa9b | 2014-04-02 21:02:54 +0800 | [diff] [blame] | 98 | #ifdef LWS_BUILTIN_GETIFADDRS |
| 99 | #include <getifaddrs.h> |
| 100 | #else |
| 101 | #include <ifaddrs.h> |
| 102 | #endif |
Dnyanesh Gate | 759e50c | 2014-09-26 05:39:05 +0800 | [diff] [blame] | 103 | #if defined (__ANDROID__) |
| 104 | #include <syslog.h> |
| 105 | #else |
Andy Green | e40aa9b | 2014-04-02 21:02:54 +0800 | [diff] [blame] | 106 | #include <sys/syslog.h> |
Dnyanesh Gate | 759e50c | 2014-09-26 05:39:05 +0800 | [diff] [blame] | 107 | #endif |
Andy Green | e40aa9b | 2014-04-02 21:02:54 +0800 | [diff] [blame] | 108 | #include <sys/un.h> |
| 109 | #include <sys/socket.h> |
| 110 | #include <netdb.h> |
Andy Green | 7c212cc | 2010-11-08 20:20:42 +0000 | [diff] [blame] | 111 | #include <netinet/in.h> |
Andy Green | 6c93955 | 2011-03-08 08:56:57 +0000 | [diff] [blame] | 112 | #include <netinet/tcp.h> |
Andy Green | b45993c | 2010-12-18 15:13:50 +0000 | [diff] [blame] | 113 | #include <arpa/inet.h> |
Andy Green | 7c212cc | 2010-11-08 20:20:42 +0000 | [diff] [blame] | 114 | #include <poll.h> |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 115 | #ifdef LWS_USE_LIBEV |
| 116 | #include <ev.h> |
| 117 | #endif /* LWS_USE_LIBEV */ |
Andy Green | 7c212cc | 2010-11-08 20:20:42 +0000 | [diff] [blame] | 118 | #include <sys/mman.h> |
Andy Green | 5f2a815 | 2015-11-02 08:21:08 +0800 | [diff] [blame] | 119 | |
| 120 | #endif /* MBED */ |
| 121 | |
| 122 | #ifndef LWS_NO_FORK |
| 123 | #ifdef LWS_HAVE_SYS_PRCTL_H |
| 124 | #include <sys/prctl.h> |
| 125 | #endif |
| 126 | #endif |
| 127 | |
Andy Green | 038d582 | 2011-02-14 20:58:26 +0000 | [diff] [blame] | 128 | #include <sys/time.h> |
Andy Green | 7c212cc | 2010-11-08 20:20:42 +0000 | [diff] [blame] | 129 | |
Patrick Gansterer | 2dbd837 | 2014-02-28 12:37:52 +0100 | [diff] [blame] | 130 | #define LWS_ERRNO errno |
| 131 | #define LWS_EAGAIN EAGAIN |
| 132 | #define LWS_EALREADY EALREADY |
| 133 | #define LWS_EINPROGRESS EINPROGRESS |
| 134 | #define LWS_EINTR EINTR |
| 135 | #define LWS_EISCONN EISCONN |
| 136 | #define LWS_EWOULDBLOCK EWOULDBLOCK |
Patrick Gansterer | b47f87b | 2014-03-30 09:18:05 +0200 | [diff] [blame] | 137 | #define LWS_POLLHUP (POLLHUP|POLLERR) |
| 138 | #define LWS_POLLIN (POLLIN) |
| 139 | #define LWS_POLLOUT (POLLOUT) |
Andy Green | 158e804 | 2014-04-02 14:25:10 +0800 | [diff] [blame] | 140 | #define compatible_close(fd) close(fd) |
Andy Green | 158e804 | 2014-04-02 14:25:10 +0800 | [diff] [blame] | 141 | #define lws_set_blocking_send(wsi) |
Andy Green | 2cd3074 | 2015-11-02 13:10:33 +0800 | [diff] [blame] | 142 | |
| 143 | #ifdef MBED_OPERATORS |
| 144 | #define lws_socket_is_valid(x) ((x) != NULL) |
| 145 | #define LWS_SOCK_INVALID (NULL) |
| 146 | #else |
Andy Green | c53f7ca | 2015-11-14 07:35:27 +0800 | [diff] [blame] | 147 | #define lws_socket_is_valid(x) (x >= 0) |
| 148 | #define LWS_SOCK_INVALID (-1) |
Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 149 | #endif |
Andy Green | 2cd3074 | 2015-11-02 13:10:33 +0800 | [diff] [blame] | 150 | #endif |
Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 151 | |
=?UTF-8?q?Joakim=20S=C3=B6derberg?= | cefab31 | 2015-06-24 16:46:02 +0200 | [diff] [blame] | 152 | #ifndef LWS_HAVE_BZERO |
Andy Green | e5ea1f9 | 2014-11-18 18:25:24 +0800 | [diff] [blame] | 153 | #ifndef bzero |
Patrick Gansterer | 4a83727 | 2014-02-28 13:17:49 +0100 | [diff] [blame] | 154 | #define bzero(b, len) (memset((b), '\0', (len)), (void) 0) |
| 155 | #endif |
Andy Green | e5ea1f9 | 2014-11-18 18:25:24 +0800 | [diff] [blame] | 156 | #endif |
Patrick Gansterer | 4a83727 | 2014-02-28 13:17:49 +0100 | [diff] [blame] | 157 | |
=?UTF-8?q?Joakim=20S=C3=B6derberg?= | cefab31 | 2015-06-24 16:46:02 +0200 | [diff] [blame] | 158 | #ifndef LWS_HAVE_STRERROR |
Patrick Gansterer | 9d61491 | 2014-02-28 00:59:53 +0100 | [diff] [blame] | 159 | #define strerror(x) "" |
| 160 | #endif |
| 161 | |
Andy Green | 7c212cc | 2010-11-08 20:20:42 +0000 | [diff] [blame] | 162 | #ifdef LWS_OPENSSL_SUPPORT |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 163 | #ifdef USE_WOLFSSL |
ABruines | 80a7068 | 2015-08-09 22:56:32 +0200 | [diff] [blame] | 164 | #ifdef USE_OLD_CYASSL |
| 165 | #include <cyassl/openssl/ssl.h> |
| 166 | #include <cyassl/error-ssl.h> |
| 167 | #else |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 168 | #include <wolfssl/openssl/ssl.h> |
| 169 | #include <wolfssl/error-ssl.h> |
ABruines | 80a7068 | 2015-08-09 22:56:32 +0200 | [diff] [blame] | 170 | #endif /* not USE_OLD_CYASSL */ |
Andy Green | 23c5f2e | 2013-02-06 15:43:00 +0900 | [diff] [blame] | 171 | #else |
Andy Green | 7c212cc | 2010-11-08 20:20:42 +0000 | [diff] [blame] | 172 | #include <openssl/ssl.h> |
| 173 | #include <openssl/evp.h> |
| 174 | #include <openssl/err.h> |
Andy Green | 70dfebd | 2010-12-20 09:35:03 +0000 | [diff] [blame] | 175 | #include <openssl/md5.h> |
Andy Green | e252217 | 2011-01-18 17:14:03 +0000 | [diff] [blame] | 176 | #include <openssl/sha.h> |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 177 | #endif /* not USE_WOLFSSL */ |
Darin Willits | db9ba42 | 2011-02-14 20:56:24 +0000 | [diff] [blame] | 178 | #endif |
| 179 | |
Andy Green | 7c212cc | 2010-11-08 20:20:42 +0000 | [diff] [blame] | 180 | #include "libwebsockets.h" |
| 181 | |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 182 | #if defined(MBED_OPERATORS) |
| 183 | #undef compatible_close |
| 184 | #define compatible_close(fd) mbed3_delete_tcp_stream_socket(fd) |
Andy Green | 11f2734 | 2015-11-08 12:10:26 +0800 | [diff] [blame] | 185 | #ifndef BIG_ENDIAN |
| 186 | #define BIG_ENDIAN 4321 /* to show byte order (taken from gcc) */ |
| 187 | #endif |
| 188 | #ifndef LITTLE_ENDIAN |
| 189 | #define LITTLE_ENDIAN 1234 |
| 190 | #endif |
| 191 | #ifndef BYTE_ORDER |
| 192 | #define BYTE_ORDER LITTLE_ENDIAN |
| 193 | #endif |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 194 | #endif |
| 195 | |
Andy Green | 158e804 | 2014-04-02 14:25:10 +0800 | [diff] [blame] | 196 | #if defined(WIN32) || defined(_WIN32) |
| 197 | |
| 198 | #ifndef BIG_ENDIAN |
| 199 | #define BIG_ENDIAN 4321 /* to show byte order (taken from gcc) */ |
| 200 | #endif |
| 201 | #ifndef LITTLE_ENDIAN |
| 202 | #define LITTLE_ENDIAN 1234 |
| 203 | #endif |
| 204 | #ifndef BYTE_ORDER |
| 205 | #define BYTE_ORDER LITTLE_ENDIAN |
| 206 | #endif |
Andy Green | 11f2734 | 2015-11-08 12:10:26 +0800 | [diff] [blame] | 207 | #ifndef u_int64_t |
Andy Green | 158e804 | 2014-04-02 14:25:10 +0800 | [diff] [blame] | 208 | typedef unsigned __int64 u_int64_t; |
Andy Green | 11f2734 | 2015-11-08 12:10:26 +0800 | [diff] [blame] | 209 | #endif |
Andy Green | 158e804 | 2014-04-02 14:25:10 +0800 | [diff] [blame] | 210 | |
| 211 | #undef __P |
| 212 | #ifndef __P |
| 213 | #if __STDC__ |
| 214 | #define __P(protos) protos |
| 215 | #else |
| 216 | #define __P(protos) () |
| 217 | #endif |
| 218 | #endif |
| 219 | |
| 220 | #else |
| 221 | |
| 222 | #include <sys/stat.h> |
| 223 | #include <sys/cdefs.h> |
| 224 | #include <sys/time.h> |
| 225 | |
| 226 | #if defined(__APPLE__) |
| 227 | #include <machine/endian.h> |
| 228 | #elif defined(__FreeBSD__) |
| 229 | #include <sys/endian.h> |
| 230 | #elif defined(__linux__) |
| 231 | #include <endian.h> |
| 232 | #endif |
| 233 | |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 234 | #ifdef __cplusplus |
| 235 | extern "C" { |
| 236 | #endif |
Alejandro Mery | ead8afe | 2014-12-07 03:36:11 +0100 | [diff] [blame] | 237 | #include <stddef.h> |
| 238 | |
| 239 | #ifndef container_of |
| 240 | #define container_of(P,T,M) ((T *)((char *)(P) - offsetof(T, M))) |
| 241 | #endif |
| 242 | |
emironov | a49d084 | 2014-09-16 14:05:13 +0400 | [diff] [blame] | 243 | #if defined(__QNX__) |
| 244 | #include <gulliver.h> |
| 245 | #if defined(__LITTLEENDIAN__) |
| 246 | #define BYTE_ORDER __LITTLEENDIAN__ |
| 247 | #define LITTLE_ENDIAN __LITTLEENDIAN__ |
| 248 | #define BIG_ENDIAN 4321 /* to show byte order (taken from gcc); for suppres warning that BIG_ENDIAN is not defined. */ |
| 249 | #endif |
| 250 | #if defined(__BIGENDIAN__) |
| 251 | #define BYTE_ORDER __BIGENDIAN__ |
| 252 | #define LITTLE_ENDIAN 1234 /* to show byte order (taken from gcc); for suppres warning that LITTLE_ENDIAN is not defined. */ |
| 253 | #define BIG_ENDIAN __BIGENDIAN__ |
| 254 | #endif |
| 255 | #endif |
| 256 | |
Andy Green | 158e804 | 2014-04-02 14:25:10 +0800 | [diff] [blame] | 257 | #if !defined(BYTE_ORDER) |
| 258 | # define BYTE_ORDER __BYTE_ORDER |
| 259 | #endif |
| 260 | #if !defined(LITTLE_ENDIAN) |
| 261 | # define LITTLE_ENDIAN __LITTLE_ENDIAN |
| 262 | #endif |
| 263 | #if !defined(BIG_ENDIAN) |
| 264 | # define BIG_ENDIAN __BIG_ENDIAN |
| 265 | #endif |
| 266 | |
| 267 | #endif |
| 268 | |
Darin Willits | c19456f | 2011-02-14 17:52:39 +0000 | [diff] [blame] | 269 | /* |
| 270 | * Mac OSX as well as iOS do not define the MSG_NOSIGNAL flag, |
| 271 | * but happily have something equivalent in the SO_NOSIGPIPE flag. |
| 272 | */ |
| 273 | #ifdef __APPLE__ |
Andy Green | 6ee372f | 2012-04-09 15:09:01 +0800 | [diff] [blame] | 274 | #define MSG_NOSIGNAL SO_NOSIGPIPE |
Darin Willits | c19456f | 2011-02-14 17:52:39 +0000 | [diff] [blame] | 275 | #endif |
| 276 | |
Bud Davis | 229bfec | 2015-01-30 10:13:01 +0800 | [diff] [blame] | 277 | #ifdef _WIN32 |
| 278 | #ifndef FD_HASHTABLE_MODULUS |
| 279 | #define FD_HASHTABLE_MODULUS 32 |
| 280 | #endif |
| 281 | #endif |
| 282 | |
Andy Green | c0d6b63 | 2013-01-12 23:42:17 +0800 | [diff] [blame] | 283 | #ifndef LWS_MAX_HEADER_LEN |
Andy Green | 16ab318 | 2013-02-10 18:02:31 +0800 | [diff] [blame] | 284 | #define LWS_MAX_HEADER_LEN 1024 |
Andy Green | c0d6b63 | 2013-01-12 23:42:17 +0800 | [diff] [blame] | 285 | #endif |
Andy Green | 3df5800 | 2015-12-25 12:44:12 +0800 | [diff] [blame] | 286 | #ifndef LWS_MAX_HEADER_POOL |
| 287 | #define LWS_MAX_HEADER_POOL 16 |
| 288 | #endif |
Andy Green | c0d6b63 | 2013-01-12 23:42:17 +0800 | [diff] [blame] | 289 | #ifndef LWS_MAX_PROTOCOLS |
Andy Green | d91d5e8 | 2013-02-10 16:00:47 +0800 | [diff] [blame] | 290 | #define LWS_MAX_PROTOCOLS 5 |
Andy Green | c0d6b63 | 2013-01-12 23:42:17 +0800 | [diff] [blame] | 291 | #endif |
| 292 | #ifndef LWS_MAX_EXTENSIONS_ACTIVE |
Andy Green | d91d5e8 | 2013-02-10 16:00:47 +0800 | [diff] [blame] | 293 | #define LWS_MAX_EXTENSIONS_ACTIVE 3 |
Andy Green | c0d6b63 | 2013-01-12 23:42:17 +0800 | [diff] [blame] | 294 | #endif |
| 295 | #ifndef SPEC_LATEST_SUPPORTED |
Andy Green | d85cb20 | 2011-09-25 09:32:54 +0100 | [diff] [blame] | 296 | #define SPEC_LATEST_SUPPORTED 13 |
Andy Green | c0d6b63 | 2013-01-12 23:42:17 +0800 | [diff] [blame] | 297 | #endif |
| 298 | #ifndef AWAITING_TIMEOUT |
Andy Green | c0b0c3d | 2015-11-20 18:52:48 +0800 | [diff] [blame] | 299 | #define AWAITING_TIMEOUT 5 |
Andy Green | c0d6b63 | 2013-01-12 23:42:17 +0800 | [diff] [blame] | 300 | #endif |
| 301 | #ifndef CIPHERS_LIST_STRING |
David Galeano | f177f2a | 2013-01-10 10:15:19 +0800 | [diff] [blame] | 302 | #define CIPHERS_LIST_STRING "DEFAULT" |
Andy Green | c0d6b63 | 2013-01-12 23:42:17 +0800 | [diff] [blame] | 303 | #endif |
Andy Green | a824d18 | 2013-01-15 20:52:29 +0800 | [diff] [blame] | 304 | #ifndef LWS_SOMAXCONN |
| 305 | #define LWS_SOMAXCONN SOMAXCONN |
| 306 | #endif |
Andy Green | 7c212cc | 2010-11-08 20:20:42 +0000 | [diff] [blame] | 307 | |
Andy Green | e252217 | 2011-01-18 17:14:03 +0000 | [diff] [blame] | 308 | #define MAX_WEBSOCKET_04_KEY_LEN 128 |
Andy Green | 5449511 | 2013-02-06 21:10:16 +0900 | [diff] [blame] | 309 | #define LWS_MAX_SOCKET_IO_BUF 4096 |
Andy Green | c0d6b63 | 2013-01-12 23:42:17 +0800 | [diff] [blame] | 310 | |
| 311 | #ifndef SYSTEM_RANDOM_FILEPATH |
Andy Green | 4739e5c | 2011-01-22 12:51:57 +0000 | [diff] [blame] | 312 | #define SYSTEM_RANDOM_FILEPATH "/dev/urandom" |
Andy Green | c0d6b63 | 2013-01-12 23:42:17 +0800 | [diff] [blame] | 313 | #endif |
| 314 | #ifndef LWS_MAX_ZLIB_CONN_BUFFER |
| 315 | #define LWS_MAX_ZLIB_CONN_BUFFER (64 * 1024) |
| 316 | #endif |
| 317 | |
Andy Green | 65b0e91 | 2013-01-16 07:59:47 +0800 | [diff] [blame] | 318 | /* |
| 319 | * if not in a connection storm, check for incoming |
| 320 | * connections this many normal connection services |
| 321 | */ |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 322 | #define LWS_lserv_mod 10 |
Andy Green | e252217 | 2011-01-18 17:14:03 +0000 | [diff] [blame] | 323 | |
Andy Green | 5fd55cd | 2011-04-23 10:54:53 +0100 | [diff] [blame] | 324 | enum lws_websocket_opcodes_07 { |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 325 | LWSWSOPC_CONTINUATION = 0, |
| 326 | LWSWSOPC_TEXT_FRAME = 1, |
| 327 | LWSWSOPC_BINARY_FRAME = 2, |
Andy Green | a41314f | 2011-05-23 10:00:03 +0100 | [diff] [blame] | 328 | |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 329 | LWSWSOPC_NOSPEC__MUX = 7, |
Andy Green | a41314f | 2011-05-23 10:00:03 +0100 | [diff] [blame] | 330 | |
| 331 | /* control extensions 8+ */ |
| 332 | |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 333 | LWSWSOPC_CLOSE = 8, |
| 334 | LWSWSOPC_PING = 9, |
| 335 | LWSWSOPC_PONG = 0xa, |
Andy Green | 5fd55cd | 2011-04-23 10:54:53 +0100 | [diff] [blame] | 336 | }; |
| 337 | |
Andy Green | a41314f | 2011-05-23 10:00:03 +0100 | [diff] [blame] | 338 | |
Andy Green | 7c212cc | 2010-11-08 20:20:42 +0000 | [diff] [blame] | 339 | enum lws_connection_states { |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 340 | LWSS_HTTP, |
| 341 | LWSS_HTTP_ISSUING_FILE, |
| 342 | LWSS_HTTP_HEADERS, |
| 343 | LWSS_HTTP_BODY, |
| 344 | LWSS_DEAD_SOCKET, |
| 345 | LWSS_ESTABLISHED, |
| 346 | LWSS_CLIENT_UNCONNECTED, |
| 347 | LWSS_RETURNED_CLOSE_ALREADY, |
| 348 | LWSS_AWAITING_CLOSE_ACK, |
| 349 | LWSS_FLUSHING_STORED_SEND_BEFORE_CLOSE, |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 350 | |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 351 | LWSS_HTTP2_AWAIT_CLIENT_PREFACE, |
| 352 | LWSS_HTTP2_ESTABLISHED_PRE_SETTINGS, |
| 353 | LWSS_HTTP2_ESTABLISHED, |
Andy Green | 7c212cc | 2010-11-08 20:20:42 +0000 | [diff] [blame] | 354 | }; |
| 355 | |
Andrew Canaday | afe26cf | 2014-07-13 01:07:36 -0400 | [diff] [blame] | 356 | enum http_version { |
| 357 | HTTP_VERSION_1_0, |
| 358 | HTTP_VERSION_1_1, |
| 359 | }; |
| 360 | |
| 361 | enum http_connection_type { |
| 362 | HTTP_CONNECTION_CLOSE, |
| 363 | HTTP_CONNECTION_KEEP_ALIVE |
| 364 | }; |
| 365 | |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 366 | enum lws_pending_protocol_send { |
| 367 | LWS_PPS_NONE, |
| 368 | LWS_PPS_HTTP2_MY_SETTINGS, |
| 369 | LWS_PPS_HTTP2_ACK_SETTINGS, |
Andy Green | bbbf07a | 2014-10-27 16:46:44 +0800 | [diff] [blame] | 370 | LWS_PPS_HTTP2_PONG, |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 371 | }; |
| 372 | |
Andy Green | 7c212cc | 2010-11-08 20:20:42 +0000 | [diff] [blame] | 373 | enum lws_rx_parse_state { |
| 374 | LWS_RXPS_NEW, |
Andy Green | e77ddd8 | 2010-11-13 10:03:47 +0000 | [diff] [blame] | 375 | |
Andy Green | 3e5eb78 | 2011-01-18 18:14:26 +0000 | [diff] [blame] | 376 | LWS_RXPS_04_MASK_NONCE_1, |
| 377 | LWS_RXPS_04_MASK_NONCE_2, |
| 378 | LWS_RXPS_04_MASK_NONCE_3, |
| 379 | |
| 380 | LWS_RXPS_04_FRAME_HDR_1, |
Andy Green | 38e57bb | 2011-01-19 12:20:27 +0000 | [diff] [blame] | 381 | LWS_RXPS_04_FRAME_HDR_LEN, |
| 382 | LWS_RXPS_04_FRAME_HDR_LEN16_2, |
| 383 | LWS_RXPS_04_FRAME_HDR_LEN16_1, |
| 384 | LWS_RXPS_04_FRAME_HDR_LEN64_8, |
| 385 | LWS_RXPS_04_FRAME_HDR_LEN64_7, |
| 386 | LWS_RXPS_04_FRAME_HDR_LEN64_6, |
| 387 | LWS_RXPS_04_FRAME_HDR_LEN64_5, |
| 388 | LWS_RXPS_04_FRAME_HDR_LEN64_4, |
| 389 | LWS_RXPS_04_FRAME_HDR_LEN64_3, |
| 390 | LWS_RXPS_04_FRAME_HDR_LEN64_2, |
| 391 | LWS_RXPS_04_FRAME_HDR_LEN64_1, |
Andy Green | 3e5eb78 | 2011-01-18 18:14:26 +0000 | [diff] [blame] | 392 | |
Andy Green | 283d0a2 | 2011-04-24 05:46:23 +0100 | [diff] [blame] | 393 | LWS_RXPS_07_COLLECT_FRAME_KEY_1, |
| 394 | LWS_RXPS_07_COLLECT_FRAME_KEY_2, |
| 395 | LWS_RXPS_07_COLLECT_FRAME_KEY_3, |
| 396 | LWS_RXPS_07_COLLECT_FRAME_KEY_4, |
| 397 | |
Andy Green | 7c212cc | 2010-11-08 20:20:42 +0000 | [diff] [blame] | 398 | LWS_RXPS_PAYLOAD_UNTIL_LENGTH_EXHAUSTED |
| 399 | }; |
| 400 | |
| 401 | |
Andy Green | 0d33833 | 2011-02-12 11:57:43 +0000 | [diff] [blame] | 402 | enum connection_mode { |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 403 | LWSCM_HTTP_SERVING, |
| 404 | LWSCM_HTTP_SERVING_ACCEPTED, /* actual HTTP service going on */ |
| 405 | LWSCM_PRE_WS_SERVING_ACCEPT, |
Andy Green | d280b6e | 2013-01-15 13:40:23 +0800 | [diff] [blame] | 406 | |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 407 | LWSCM_WS_SERVING, |
| 408 | LWSCM_WS_CLIENT, |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 409 | |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 410 | LWSCM_HTTP2_SERVING, |
Andy Green | 0d33833 | 2011-02-12 11:57:43 +0000 | [diff] [blame] | 411 | |
Andy Green | e216071 | 2013-01-28 12:19:10 +0800 | [diff] [blame] | 412 | /* transient, ssl delay hiding */ |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 413 | LWSCM_SSL_ACK_PENDING, |
Andy Green | e216071 | 2013-01-28 12:19:10 +0800 | [diff] [blame] | 414 | |
Andy Green | be93fef | 2011-02-14 20:25:43 +0000 | [diff] [blame] | 415 | /* transient modes */ |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 416 | LWSCM_WSCL_WAITING_CONNECT, |
| 417 | LWSCM_WSCL_WAITING_PROXY_REPLY, |
| 418 | LWSCM_WSCL_ISSUE_HANDSHAKE, |
| 419 | LWSCM_WSCL_ISSUE_HANDSHAKE2, |
| 420 | LWSCM_WSCL_WAITING_SSL, |
| 421 | LWSCM_WSCL_WAITING_SERVER_REPLY, |
| 422 | LWSCM_WSCL_WAITING_EXTENSION_CONNECT, |
| 423 | LWSCM_WSCL_PENDING_CANDIDATE_CHILD, |
Andy Green | be93fef | 2011-02-14 20:25:43 +0000 | [diff] [blame] | 424 | |
Andy Green | 0d33833 | 2011-02-12 11:57:43 +0000 | [diff] [blame] | 425 | /* special internal types */ |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 426 | LWSCM_SERVER_LISTENER, |
Andy Green | 0d33833 | 2011-02-12 11:57:43 +0000 | [diff] [blame] | 427 | }; |
| 428 | |
Andy Green | ca0a129 | 2013-03-16 11:24:23 +0800 | [diff] [blame] | 429 | enum { |
| 430 | LWS_RXFLOW_ALLOW = (1 << 0), |
| 431 | LWS_RXFLOW_PENDING_CHANGE = (1 << 1), |
| 432 | }; |
| 433 | |
Andy Green | 1fb95e8 | 2015-12-26 17:20:34 +0800 | [diff] [blame] | 434 | /* this is not usable directly by user code any more, lws_close_reason() */ |
| 435 | #define LWS_WRITE_CLOSE 4 |
| 436 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 437 | struct lws_protocols; |
| 438 | struct lws; |
Andy Green | e92cd17 | 2011-01-19 13:11:55 +0000 | [diff] [blame] | 439 | |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 440 | #ifdef LWS_USE_LIBEV |
| 441 | struct lws_io_watcher { |
| 442 | struct ev_io watcher; |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 443 | struct lws_context* context; |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 444 | }; |
| 445 | |
| 446 | struct lws_signal_watcher { |
| 447 | struct ev_signal watcher; |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 448 | struct lws_context* context; |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 449 | }; |
| 450 | #endif /* LWS_USE_LIBEV */ |
| 451 | |
Bud Davis | 229bfec | 2015-01-30 10:13:01 +0800 | [diff] [blame] | 452 | #ifdef _WIN32 |
| 453 | #define LWS_FD_HASH(fd) ((fd ^ (fd >> 8) ^ (fd >> 16)) % FD_HASHTABLE_MODULUS) |
Andy Green | 3ef579b | 2015-12-04 09:23:56 +0800 | [diff] [blame] | 454 | struct lws_fd_hashtable { |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 455 | struct lws **wsi; |
Bud Davis | 229bfec | 2015-01-30 10:13:01 +0800 | [diff] [blame] | 456 | int length; |
| 457 | }; |
| 458 | #endif |
| 459 | |
Andy Green | 3df5800 | 2015-12-25 12:44:12 +0800 | [diff] [blame] | 460 | /* |
| 461 | * This is totally opaque to code using the library. It's exported as a |
| 462 | * forward-reference pointer-only declaration; the user can use the pointer with |
| 463 | * other APIs to get information out of it. |
| 464 | */ |
| 465 | |
| 466 | struct lws_fragments { |
| 467 | unsigned short offset; |
| 468 | unsigned short len; |
| 469 | unsigned char nfrag; /* which ah->frag[] continues this content, or 0 */ |
| 470 | }; |
| 471 | |
| 472 | /* |
| 473 | * these are assigned from a pool held in the context. |
| 474 | * Both client and server mode uses them for http header analysis |
| 475 | */ |
| 476 | |
| 477 | struct allocated_headers { |
Andy Green | de132b9 | 2015-12-25 13:48:20 +0800 | [diff] [blame] | 478 | char *data; /* prepared by context init to point to dedicated storage */ |
| 479 | /* |
| 480 | * the randomly ordered fragments, indexed by frag_index and |
| 481 | * lws_fragments->nfrag for continuation. |
| 482 | */ |
| 483 | struct lws_fragments frags[WSI_TOKEN_COUNT * 2]; |
Andy Green | 3df5800 | 2015-12-25 12:44:12 +0800 | [diff] [blame] | 484 | /* |
| 485 | * for each recognized token, frag_index says which frag[] his data |
| 486 | * starts in (0 means the token did not appear) |
| 487 | * the actual header data gets dumped as it comes in, into data[] |
| 488 | */ |
| 489 | unsigned char frag_index[WSI_TOKEN_COUNT]; |
Andy Green | 3df5800 | 2015-12-25 12:44:12 +0800 | [diff] [blame] | 490 | #ifndef LWS_NO_CLIENT |
| 491 | char initial_handshake_hash_base64[30]; |
| 492 | unsigned short c_port; |
| 493 | #endif |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 494 | |
| 495 | unsigned short pos; |
| 496 | unsigned char in_use; |
| 497 | unsigned char nfrag; |
Andy Green | 3df5800 | 2015-12-25 12:44:12 +0800 | [diff] [blame] | 498 | }; |
| 499 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 500 | struct lws_context { |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 501 | time_t last_timeout_check_s; |
| 502 | struct lws_plat_file_ops fops; |
Patrick Gansterer | 0fc37b6 | 2014-03-28 15:44:56 +0100 | [diff] [blame] | 503 | #ifdef _WIN32 |
| 504 | WSAEVENT *events; |
| 505 | #endif |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 506 | struct lws_pollfd *fds; |
Bud Davis | 229bfec | 2015-01-30 10:13:01 +0800 | [diff] [blame] | 507 | #ifdef _WIN32 |
| 508 | /* different implementation between unix and windows */ |
Andy Green | 3ef579b | 2015-12-04 09:23:56 +0800 | [diff] [blame] | 509 | struct lws_fd_hashtable fd_hashtable[FD_HASHTABLE_MODULUS]; |
Bud Davis | 229bfec | 2015-01-30 10:13:01 +0800 | [diff] [blame] | 510 | #else |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 511 | struct lws **lws_lookup; /* fd to wsi */ |
Bud Davis | 229bfec | 2015-01-30 10:13:01 +0800 | [diff] [blame] | 512 | #endif |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 513 | #ifdef LWS_USE_LIBEV |
| 514 | struct ev_loop* io_loop; |
| 515 | struct lws_io_watcher w_accept; |
| 516 | struct lws_signal_watcher w_sigint; |
Andrew Canaday | a8f47c9 | 2015-04-26 22:50:59 -0400 | [diff] [blame] | 517 | lws_ev_signal_cb* lws_ev_sigint_cb; |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 518 | #endif /* LWS_USE_LIBEV */ |
Mattias Lundberg | 03bb8f9 | 2014-02-18 10:06:57 +0100 | [diff] [blame] | 519 | const char *iface; |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 520 | const struct lws_token_limits *token_limits; |
| 521 | void *user_space; |
| 522 | #ifndef LWS_NO_SERVER |
| 523 | struct lws *wsi_listening; |
| 524 | #endif |
| 525 | const struct lws_protocols *protocols; |
| 526 | void *http_header_data; |
| 527 | struct allocated_headers *ah_pool; |
| 528 | #ifdef LWS_OPENSSL_SUPPORT |
| 529 | SSL_CTX *ssl_ctx; |
| 530 | SSL_CTX *ssl_client_ctx; |
| 531 | struct lws *pending_read_list; /* linked list */ |
| 532 | #endif |
| 533 | #ifndef LWS_NO_EXTENSIONS |
| 534 | const struct lws_extension *extensions; |
| 535 | #endif |
Andy Green | 44eee68 | 2011-02-10 09:32:24 +0000 | [diff] [blame] | 536 | |
Andy Green | b8b247d | 2013-01-22 07:20:08 +0800 | [diff] [blame] | 537 | /* |
| 538 | * usable by anything in the service code, but only if the scope |
| 539 | * does not last longer than the service action (since next service |
| 540 | * of any socket can likewise use it and overwrite) |
| 541 | */ |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 542 | unsigned char serv_buf[LWS_MAX_SOCKET_IO_BUF]; |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 543 | char http_proxy_address[128]; |
| 544 | char proxy_basic_auth_token[128]; |
| 545 | char canonical_hostname[128]; |
| 546 | #ifdef LWS_LATENCY |
| 547 | unsigned long worst_latency; |
| 548 | char worst_latency_info[256]; |
| 549 | #endif |
Andy Green | b8b247d | 2013-01-22 07:20:08 +0800 | [diff] [blame] | 550 | |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 551 | lws_sockfd_type lserv_fd; |
| 552 | |
| 553 | int fds_count; |
| 554 | int max_fds; |
| 555 | int listen_port; |
| 556 | #ifdef LWS_USE_LIBEV |
| 557 | int use_ev_sigint; |
| 558 | #endif |
Andy Green | 24cba92 | 2013-01-19 13:56:10 +0800 | [diff] [blame] | 559 | int started_with_parent; |
| 560 | |
Andy Green | 44eee68 | 2011-02-10 09:32:24 +0000 | [diff] [blame] | 561 | int fd_random; |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 562 | int lserv_mod; |
| 563 | int lserv_count; |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 564 | int lserv_seen; |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 565 | unsigned int http_proxy_port; |
| 566 | unsigned int options; |
Andy Green | 6ee372f | 2012-04-09 15:09:01 +0800 | [diff] [blame] | 567 | |
Patrick Gansterer | 1ee57f6 | 2014-03-06 11:57:50 +0100 | [diff] [blame] | 568 | /* |
| 569 | * set to the Thread ID that's doing the service loop just before entry |
| 570 | * to poll indicates service thread likely idling in poll() |
| 571 | * volatile because other threads may check it as part of processing |
| 572 | * for pollfd event change. |
| 573 | */ |
| 574 | volatile int service_tid; |
Andy Green | c35b36b | 2015-12-24 13:00:54 +0800 | [diff] [blame] | 575 | int service_tid_detected; |
Patrick Gansterer | 1ee57f6 | 2014-03-06 11:57:50 +0100 | [diff] [blame] | 576 | #ifndef _WIN32 |
| 577 | int dummy_pipe_fds[2]; |
| 578 | #endif |
| 579 | |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 580 | int count_protocols; |
Andy Green | a690cd0 | 2013-02-09 12:25:31 +0800 | [diff] [blame] | 581 | int ka_time; |
| 582 | int ka_probes; |
| 583 | int ka_interval; |
| 584 | |
Andy Green | b45993c | 2010-12-18 15:13:50 +0000 | [diff] [blame] | 585 | #ifdef LWS_OPENSSL_SUPPORT |
| 586 | int use_ssl; |
James Devine | 5b34c97 | 2013-12-14 11:41:29 +0800 | [diff] [blame] | 587 | int allow_non_ssl_on_ssl_port; |
joseph.urciuoli | 4d9c8fc | 2014-10-16 08:53:19 +0800 | [diff] [blame] | 588 | unsigned int user_supplied_ssl_ctx:1; |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 589 | #define lws_ssl_anybody_has_buffered_read(ctx) \ |
| 590 | (ctx->use_ssl && ctx->pending_read_list) |
Andy Green | 5281560 | 2015-01-29 08:36:18 +0800 | [diff] [blame] | 591 | #else |
| 592 | #define lws_ssl_anybody_has_buffered_read(ctx) (0) |
Andy Green | b45993c | 2010-12-18 15:13:50 +0000 | [diff] [blame] | 593 | #endif |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 594 | |
Andy Green | 3df5800 | 2015-12-25 12:44:12 +0800 | [diff] [blame] | 595 | short max_http_header_data; |
| 596 | short max_http_header_pool; |
| 597 | short ah_count_in_use; |
Andy Green | b45993c | 2010-12-18 15:13:50 +0000 | [diff] [blame] | 598 | }; |
| 599 | |
Andy Green | a717df2 | 2014-04-11 13:14:37 +0800 | [diff] [blame] | 600 | enum { |
| 601 | LWS_EV_READ = (1 << 0), |
| 602 | LWS_EV_WRITE = (1 << 1), |
| 603 | LWS_EV_START = (1 << 2), |
| 604 | LWS_EV_STOP = (1 << 3), |
| 605 | }; |
| 606 | |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 607 | #ifdef LWS_USE_LIBEV |
| 608 | #define LWS_LIBEV_ENABLED(context) (context->options & LWS_SERVER_OPTION_LIBEV) |
Andy Green | a717df2 | 2014-04-11 13:14:37 +0800 | [diff] [blame] | 609 | LWS_EXTERN void lws_feature_status_libev(struct lws_context_creation_info *info); |
| 610 | LWS_EXTERN void |
Andy Green | 11c05bf | 2015-12-16 18:19:08 +0800 | [diff] [blame] | 611 | lws_libev_accept(struct lws *new_wsi, lws_sockfd_type accept_fd); |
Andy Green | a717df2 | 2014-04-11 13:14:37 +0800 | [diff] [blame] | 612 | LWS_EXTERN void |
Andy Green | 11c05bf | 2015-12-16 18:19:08 +0800 | [diff] [blame] | 613 | lws_libev_io(struct lws *wsi, int flags); |
Andy Green | a717df2 | 2014-04-11 13:14:37 +0800 | [diff] [blame] | 614 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 615 | lws_libev_init_fd_table(struct lws_context *context); |
Andy Green | a717df2 | 2014-04-11 13:14:37 +0800 | [diff] [blame] | 616 | LWS_EXTERN void |
Andy Green | a01fb52 | 2015-12-14 07:51:15 +0800 | [diff] [blame] | 617 | lws_libev_run(const struct lws_context *context); |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 618 | #else |
| 619 | #define LWS_LIBEV_ENABLED(context) (0) |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 620 | #ifdef LWS_POSIX |
Andy Green | a717df2 | 2014-04-11 13:14:37 +0800 | [diff] [blame] | 621 | #define lws_feature_status_libev(_a) \ |
| 622 | lwsl_notice("libev support not compiled in\n") |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 623 | #else |
| 624 | #define lws_feature_status_libev(_a) |
| 625 | #endif |
Andy Green | 11c05bf | 2015-12-16 18:19:08 +0800 | [diff] [blame] | 626 | #define lws_libev_accept(_a, _b) ((void) 0) |
| 627 | #define lws_libev_io(_a, _b) ((void) 0) |
Andy Green | a717df2 | 2014-04-11 13:14:37 +0800 | [diff] [blame] | 628 | #define lws_libev_init_fd_table(_a) (0) |
vpeter4 | 7c00fc3 | 2014-04-27 13:35:28 +0200 | [diff] [blame] | 629 | #define lws_libev_run(_a) ((void) 0) |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 630 | #endif |
| 631 | |
Andy Green | 055f297 | 2014-03-24 16:09:25 +0800 | [diff] [blame] | 632 | #ifdef LWS_USE_IPV6 |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 633 | #define LWS_IPV6_ENABLED(context) \ |
| 634 | (!(context->options & LWS_SERVER_OPTION_DISABLE_IPV6)) |
James Devine | 3f13ea2 | 2014-03-24 16:09:25 +0800 | [diff] [blame] | 635 | #else |
| 636 | #define LWS_IPV6_ENABLED(context) (0) |
| 637 | #endif |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 638 | |
Andy Green | b1a9e50 | 2013-11-10 15:15:21 +0800 | [diff] [blame] | 639 | enum uri_path_states { |
| 640 | URIPS_IDLE, |
| 641 | URIPS_SEEN_SLASH, |
| 642 | URIPS_SEEN_SLASH_DOT, |
| 643 | URIPS_SEEN_SLASH_DOT_DOT, |
| 644 | }; |
| 645 | |
| 646 | enum uri_esc_states { |
| 647 | URIES_IDLE, |
| 648 | URIES_SEEN_PERCENT, |
| 649 | URIES_SEEN_PERCENT_H1, |
| 650 | }; |
Andy Green | f3d3b40 | 2011-02-09 07:16:34 +0000 | [diff] [blame] | 651 | |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 652 | /* notice that these union members: |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 653 | * |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 654 | * hdr |
| 655 | * http |
| 656 | * http2 |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 657 | * |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 658 | * all have a pointer to allocated_headers struct as their first member. |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 659 | * |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 660 | * It means for allocated_headers access, the three union paths can all be |
Peter Pentchev | bb085da | 2015-12-03 15:55:11 +0200 | [diff] [blame] | 661 | * used interchangeably to access the same data |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 662 | */ |
| 663 | |
Andy Green | 84fd949 | 2013-11-09 11:40:32 +0800 | [diff] [blame] | 664 | struct _lws_http_mode_related { |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 665 | /* MUST be first in struct */ |
Andy Green | 84fd949 | 2013-11-09 11:40:32 +0800 | [diff] [blame] | 666 | struct allocated_headers *ah; /* mirroring _lws_header_related */ |
Andy Green | 84fd949 | 2013-11-09 11:40:32 +0800 | [diff] [blame] | 667 | unsigned long filepos; |
| 668 | unsigned long filelen; |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 669 | lws_filefd_type fd; |
kapejod | ce64fb0 | 2013-11-19 13:38:16 +0100 | [diff] [blame] | 670 | |
Andrew Canaday | afe26cf | 2014-07-13 01:07:36 -0400 | [diff] [blame] | 671 | enum http_version request_version; |
| 672 | enum http_connection_type connection_type; |
Andy Green | 2cd3074 | 2015-11-02 13:10:33 +0800 | [diff] [blame] | 673 | unsigned int content_length; |
| 674 | unsigned int content_remain; |
Andy Green | 84fd949 | 2013-11-09 11:40:32 +0800 | [diff] [blame] | 675 | }; |
| 676 | |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 677 | #ifdef LWS_USE_HTTP2 |
| 678 | |
| 679 | enum lws_http2_settings { |
| 680 | LWS_HTTP2_SETTINGS__HEADER_TABLE_SIZE = 1, |
| 681 | LWS_HTTP2_SETTINGS__ENABLE_PUSH, |
| 682 | LWS_HTTP2_SETTINGS__MAX_CONCURRENT_STREAMS, |
| 683 | LWS_HTTP2_SETTINGS__INITIAL_WINDOW_SIZE, |
| 684 | LWS_HTTP2_SETTINGS__MAX_FRAME_SIZE, |
| 685 | LWS_HTTP2_SETTINGS__MAX_HEADER_LIST_SIZE, |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 686 | |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 687 | LWS_HTTP2_SETTINGS__COUNT /* always last */ |
Andy Green | a54f232 | 2014-09-30 09:43:14 +0800 | [diff] [blame] | 688 | }; |
| 689 | |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 690 | enum lws_http2_wellknown_frame_types { |
| 691 | LWS_HTTP2_FRAME_TYPE_DATA, |
| 692 | LWS_HTTP2_FRAME_TYPE_HEADERS, |
| 693 | LWS_HTTP2_FRAME_TYPE_PRIORITY, |
| 694 | LWS_HTTP2_FRAME_TYPE_RST_STREAM, |
| 695 | LWS_HTTP2_FRAME_TYPE_SETTINGS, |
| 696 | LWS_HTTP2_FRAME_TYPE_PUSH_PROMISE, |
| 697 | LWS_HTTP2_FRAME_TYPE_PING, |
| 698 | LWS_HTTP2_FRAME_TYPE_GOAWAY, |
| 699 | LWS_HTTP2_FRAME_TYPE_WINDOW_UPDATE, |
| 700 | LWS_HTTP2_FRAME_TYPE_CONTINUATION, |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 701 | |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 702 | LWS_HTTP2_FRAME_TYPE_COUNT /* always last */ |
| 703 | }; |
| 704 | |
Andy Green | 91b0589 | 2014-10-17 08:38:44 +0800 | [diff] [blame] | 705 | enum lws_http2_flags { |
| 706 | LWS_HTTP2_FLAG_END_STREAM = 1, |
| 707 | LWS_HTTP2_FLAG_END_HEADERS = 4, |
| 708 | LWS_HTTP2_FLAG_PADDED = 8, |
| 709 | LWS_HTTP2_FLAG_PRIORITY = 0x20, |
| 710 | |
| 711 | LWS_HTTP2_FLAG_SETTINGS_ACK = 1, |
| 712 | }; |
| 713 | |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 714 | #define LWS_HTTP2_STREAM_ID_MASTER 0 |
| 715 | #define LWS_HTTP2_FRAME_HEADER_LENGTH 9 |
| 716 | #define LWS_HTTP2_SETTINGS_LENGTH 6 |
| 717 | |
| 718 | struct http2_settings { |
| 719 | unsigned int setting[LWS_HTTP2_SETTINGS__COUNT]; |
| 720 | }; |
| 721 | |
Andy Green | ecc2e72 | 2014-10-09 16:57:47 +0800 | [diff] [blame] | 722 | enum http2_hpack_state { |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 723 | |
Andy Green | 200f385 | 2014-10-18 12:23:05 +0800 | [diff] [blame] | 724 | /* optional before first header block */ |
| 725 | HPKS_OPT_PADDING, |
| 726 | HKPS_OPT_E_DEPENDENCY, |
| 727 | HKPS_OPT_WEIGHT, |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 728 | |
Andy Green | 200f385 | 2014-10-18 12:23:05 +0800 | [diff] [blame] | 729 | /* header block */ |
Andy Green | ecc2e72 | 2014-10-09 16:57:47 +0800 | [diff] [blame] | 730 | HPKS_TYPE, |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 731 | |
Andy Green | 2add634 | 2014-10-12 08:38:16 +0800 | [diff] [blame] | 732 | HPKS_IDX_EXT, |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 733 | |
Andy Green | ecc2e72 | 2014-10-09 16:57:47 +0800 | [diff] [blame] | 734 | HPKS_HLEN, |
| 735 | HPKS_HLEN_EXT, |
| 736 | |
| 737 | HPKS_DATA, |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 738 | |
Andy Green | 200f385 | 2014-10-18 12:23:05 +0800 | [diff] [blame] | 739 | /* optional after last header block */ |
| 740 | HKPS_OPT_DISCARD_PADDING, |
Andy Green | ecc2e72 | 2014-10-09 16:57:47 +0800 | [diff] [blame] | 741 | }; |
| 742 | |
Andy Green | 2add634 | 2014-10-12 08:38:16 +0800 | [diff] [blame] | 743 | enum http2_hpack_type { |
| 744 | HPKT_INDEXED_HDR_7, |
| 745 | HPKT_INDEXED_HDR_6_VALUE_INCR, |
| 746 | HPKT_LITERAL_HDR_VALUE_INCR, |
| 747 | HPKT_INDEXED_HDR_4_VALUE, |
| 748 | HPKT_LITERAL_HDR_VALUE, |
| 749 | HPKT_SIZE_5 |
| 750 | }; |
| 751 | |
Andy Green | 200f385 | 2014-10-18 12:23:05 +0800 | [diff] [blame] | 752 | struct hpack_dt_entry { |
| 753 | int token; /* additions that don't map to a token are ignored */ |
| 754 | int arg_offset; |
| 755 | int arg_len; |
| 756 | }; |
| 757 | |
| 758 | struct hpack_dynamic_table { |
| 759 | struct hpack_dt_entry *entries; |
| 760 | char *args; |
| 761 | int pos; |
| 762 | int next; |
| 763 | int num_entries; |
| 764 | int args_length; |
| 765 | }; |
| 766 | |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 767 | struct _lws_http2_related { |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 768 | /* |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 769 | * having this first lets us also re-use all HTTP union code |
| 770 | * and in turn, http_mode_related has allocated headers in right |
| 771 | * place so we can use the header apis on the wsi directly still |
| 772 | */ |
| 773 | struct _lws_http_mode_related http; /* MUST BE FIRST IN STRUCT */ |
| 774 | |
| 775 | struct http2_settings my_settings; |
| 776 | struct http2_settings peer_settings; |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 777 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 778 | struct lws *parent_wsi; |
| 779 | struct lws *next_child_wsi; |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 780 | |
Andy Green | 200f385 | 2014-10-18 12:23:05 +0800 | [diff] [blame] | 781 | struct hpack_dynamic_table *hpack_dyn_table; |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 782 | struct lws *stream_wsi; |
| 783 | unsigned char ping_payload[8]; |
| 784 | unsigned char one_setting[LWS_HTTP2_SETTINGS_LENGTH]; |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 785 | |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 786 | unsigned int count; |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 787 | unsigned int length; |
| 788 | unsigned int stream_id; |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 789 | enum http2_hpack_state hpack; |
| 790 | enum http2_hpack_type hpack_type; |
| 791 | unsigned int header_index; |
| 792 | unsigned int hpack_len; |
| 793 | unsigned int hpack_e_dep; |
| 794 | int tx_credit; |
| 795 | unsigned int my_stream_id; |
| 796 | unsigned int child_count; |
| 797 | int my_priority; |
| 798 | |
Andy Green | 91b0589 | 2014-10-17 08:38:44 +0800 | [diff] [blame] | 799 | unsigned int END_STREAM:1; |
| 800 | unsigned int END_HEADERS:1; |
Andy Green | 1cea581 | 2014-10-19 07:36:20 +0800 | [diff] [blame] | 801 | unsigned int send_END_STREAM:1; |
Andy Green | 7df53c5 | 2014-10-22 15:37:28 +0800 | [diff] [blame] | 802 | unsigned int GOING_AWAY; |
| 803 | unsigned int requested_POLLOUT:1; |
Andy Green | 97ee57f | 2014-10-29 09:39:08 +0800 | [diff] [blame] | 804 | unsigned int waiting_tx_credit:1; |
Andy Green | ecc2e72 | 2014-10-09 16:57:47 +0800 | [diff] [blame] | 805 | unsigned int huff:1; |
| 806 | unsigned int value:1; |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 807 | |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 808 | unsigned short round_robin_POLLOUT; |
| 809 | unsigned short count_POLLOUT_children; |
| 810 | unsigned short hpack_pos; |
| 811 | |
| 812 | unsigned char type; |
| 813 | unsigned char flags; |
| 814 | unsigned char frame_state; |
| 815 | unsigned char padding; |
| 816 | unsigned char hpack_m; |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 817 | unsigned char initialized; |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 818 | }; |
| 819 | |
Andy Green | 7df53c5 | 2014-10-22 15:37:28 +0800 | [diff] [blame] | 820 | #define HTTP2_IS_TOPLEVEL_WSI(wsi) (!wsi->u.http2.parent_wsi) |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 821 | |
| 822 | #endif |
| 823 | |
Andy Green | 623a98d | 2013-01-21 11:04:23 +0800 | [diff] [blame] | 824 | struct _lws_header_related { |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 825 | /* MUST be first in struct */ |
Andy Green | 16ab318 | 2013-02-10 18:02:31 +0800 | [diff] [blame] | 826 | struct allocated_headers *ah; |
Andy Green | b1a9e50 | 2013-11-10 15:15:21 +0800 | [diff] [blame] | 827 | enum uri_path_states ups; |
| 828 | enum uri_esc_states ues; |
Andy Green | de132b9 | 2015-12-25 13:48:20 +0800 | [diff] [blame] | 829 | short lextable_pos; |
| 830 | unsigned short current_token_limit; |
Andy Green | b1a9e50 | 2013-11-10 15:15:21 +0800 | [diff] [blame] | 831 | char esc_stash; |
Andy Green | 3ba035d | 2015-12-18 15:40:03 +0800 | [diff] [blame] | 832 | char post_literal_equal; |
Andy Green | de132b9 | 2015-12-25 13:48:20 +0800 | [diff] [blame] | 833 | unsigned char parser_state; /* enum lws_token_indexes */ |
Andy Green | 623a98d | 2013-01-21 11:04:23 +0800 | [diff] [blame] | 834 | }; |
| 835 | |
| 836 | struct _lws_websocket_related { |
Andy Green | 5449511 | 2013-02-06 21:10:16 +0900 | [diff] [blame] | 837 | char *rx_user_buffer; |
Andy Green | de132b9 | 2015-12-25 13:48:20 +0800 | [diff] [blame] | 838 | size_t rx_packet_length; |
Andy Green | 2cd3074 | 2015-11-02 13:10:33 +0800 | [diff] [blame] | 839 | unsigned int rx_user_buffer_head; |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 840 | unsigned char mask_nonce[4]; |
Andy Green | 1fb95e8 | 2015-12-26 17:20:34 +0800 | [diff] [blame] | 841 | /* Also used for close content... control opcode == < 128 */ |
Andy Green | 7dbf21e | 2015-12-28 13:40:54 +0800 | [diff] [blame^] | 842 | unsigned char ping_payload_buf[128 - 3 + LWS_SEND_BUFFER_PRE_PADDING]; |
Andy Green | 1fb95e8 | 2015-12-26 17:20:34 +0800 | [diff] [blame] | 843 | |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 844 | unsigned char ping_payload_len; |
Andy Green | 623a98d | 2013-01-21 11:04:23 +0800 | [diff] [blame] | 845 | unsigned char frame_mask_index; |
Andy Green | 623a98d | 2013-01-21 11:04:23 +0800 | [diff] [blame] | 846 | unsigned char opcode; |
Andy Green | 623a98d | 2013-01-21 11:04:23 +0800 | [diff] [blame] | 847 | unsigned char rsv; |
Andy Green | 1fb95e8 | 2015-12-26 17:20:34 +0800 | [diff] [blame] | 848 | /* zero if no info, or length including 2-byte close code */ |
| 849 | unsigned char close_in_ping_buffer_len; |
Andy Green | de132b9 | 2015-12-25 13:48:20 +0800 | [diff] [blame] | 850 | |
| 851 | unsigned int final:1; |
Andy Green | d91d5e8 | 2013-02-10 16:00:47 +0800 | [diff] [blame] | 852 | unsigned int frame_is_binary:1; |
Andy Green | d91d5e8 | 2013-02-10 16:00:47 +0800 | [diff] [blame] | 853 | unsigned int all_zero_nonce:1; |
Andy Green | d91d5e8 | 2013-02-10 16:00:47 +0800 | [diff] [blame] | 854 | unsigned int this_frame_masked:1; |
Andy Green | 1f4267b | 2013-10-17 08:09:19 +0800 | [diff] [blame] | 855 | unsigned int inside_frame:1; /* next write will be more of frame */ |
| 856 | unsigned int clean_buffer:1; /* buffer not rewritten by extension */ |
Andy Green | 40d5abc | 2015-04-17 20:29:58 +0800 | [diff] [blame] | 857 | unsigned int payload_is_close:1; /* process as PONG, but it is close */ |
Andy Green | ba38a7e | 2015-12-25 13:14:09 +0800 | [diff] [blame] | 858 | unsigned int ping_pending_flag:1; |
Andy Green | 623a98d | 2013-01-21 11:04:23 +0800 | [diff] [blame] | 859 | }; |
| 860 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 861 | struct lws { |
Andy Green | 623a98d | 2013-01-21 11:04:23 +0800 | [diff] [blame] | 862 | |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 863 | /* structs */ |
| 864 | /* members with mutually exclusive lifetimes are unionized */ |
| 865 | |
| 866 | union u { |
| 867 | struct _lws_http_mode_related http; |
| 868 | #ifdef LWS_USE_HTTP2 |
| 869 | struct _lws_http2_related http2; |
| 870 | #endif |
| 871 | struct _lws_header_related hdr; |
| 872 | struct _lws_websocket_related ws; |
| 873 | } u; |
| 874 | |
Andy Green | 623a98d | 2013-01-21 11:04:23 +0800 | [diff] [blame] | 875 | /* lifetime members */ |
| 876 | |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 877 | #ifdef LWS_USE_LIBEV |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 878 | struct lws_io_watcher w_read; |
| 879 | struct lws_io_watcher w_write; |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 880 | #endif /* LWS_USE_LIBEV */ |
Andy Green | de132b9 | 2015-12-25 13:48:20 +0800 | [diff] [blame] | 881 | time_t pending_timeout_limit; |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 882 | |
| 883 | /* pointers */ |
| 884 | |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 885 | struct lws_context *context; |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 886 | const struct lws_protocols *protocol; |
Andy Green | de132b9 | 2015-12-25 13:48:20 +0800 | [diff] [blame] | 887 | void *user_space; |
| 888 | /* rxflow handling */ |
| 889 | unsigned char *rxflow_buffer; |
| 890 | /* truncated send handling */ |
| 891 | unsigned char *trunc_alloc; /* non-NULL means buffering in progress */ |
Andy Green | 3182ece | 2013-01-20 17:08:31 +0800 | [diff] [blame] | 892 | #ifndef LWS_NO_EXTENSIONS |
Andy Green | d2ac22c | 2015-12-11 10:45:35 +0800 | [diff] [blame] | 893 | const struct lws_extension *active_extensions[LWS_MAX_EXTENSIONS_ACTIVE]; |
Andy Green | 6ee372f | 2012-04-09 15:09:01 +0800 | [diff] [blame] | 894 | void *active_extensions_user[LWS_MAX_EXTENSIONS_ACTIVE]; |
Andy Green | 3182ece | 2013-01-20 17:08:31 +0800 | [diff] [blame] | 895 | #endif |
Andy Green | de132b9 | 2015-12-25 13:48:20 +0800 | [diff] [blame] | 896 | #ifdef LWS_OPENSSL_SUPPORT |
| 897 | SSL *ssl; |
| 898 | BIO *client_bio; |
| 899 | struct lws *pending_read_list_prev, *pending_read_list_next; |
| 900 | #endif |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 901 | #ifdef LWS_LATENCY |
| 902 | unsigned long action_start; |
| 903 | unsigned long latency_start; |
| 904 | #endif |
| 905 | /* pointer / int */ |
Andy Green | 3b19386 | 2015-11-02 13:13:44 +0800 | [diff] [blame] | 906 | lws_sockfd_type sock; |
Andy Green | de132b9 | 2015-12-25 13:48:20 +0800 | [diff] [blame] | 907 | |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 908 | /* ints */ |
Andy Green | de132b9 | 2015-12-25 13:48:20 +0800 | [diff] [blame] | 909 | enum lws_pending_protocol_send pps; |
Andy Green | dfb2304 | 2013-01-17 12:26:48 +0800 | [diff] [blame] | 910 | int position_in_fds_table; |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 911 | int rxflow_len; |
| 912 | int rxflow_pos; |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 913 | unsigned int trunc_alloc_len; /* size of malloc */ |
| 914 | unsigned int trunc_offset; /* where we are in terms of spilling */ |
| 915 | unsigned int trunc_len; /* how much is buffered */ |
Andy Green | 2764eba | 2013-12-09 14:16:17 +0800 | [diff] [blame] | 916 | |
Andy Green | de132b9 | 2015-12-25 13:48:20 +0800 | [diff] [blame] | 917 | unsigned int hdr_parsing_completed:1; |
| 918 | unsigned int user_space_externally_allocated:1; |
| 919 | unsigned int socket_is_permanently_unusable:1; |
| 920 | unsigned int rxflow_change_to:2; |
| 921 | #ifndef LWS_NO_EXTENSIONS |
| 922 | unsigned int extension_data_pending:1; |
| 923 | #endif |
| 924 | #ifdef LWS_OPENSSL_SUPPORT |
| 925 | unsigned int use_ssl:2; |
| 926 | unsigned int upgraded:1; |
| 927 | #endif |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 928 | #ifdef _WIN32 |
| 929 | unsigned int sock_send_blocking:1; |
| 930 | #endif |
Andy Green | de132b9 | 2015-12-25 13:48:20 +0800 | [diff] [blame] | 931 | |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 932 | /* chars */ |
Andy Green | de132b9 | 2015-12-25 13:48:20 +0800 | [diff] [blame] | 933 | #ifndef LWS_NO_EXTENSIONS |
| 934 | unsigned char count_active_extensions; |
| 935 | #endif |
| 936 | unsigned char ietf_spec_revision; |
| 937 | char mode; /* enum connection_mode */ |
| 938 | char state; /* enum lws_connection_states */ |
| 939 | char lws_rx_parse_state; /* enum lws_rx_parse_state */ |
| 940 | char rx_frame_type; /* enum lws_write_protocol */ |
| 941 | char pending_timeout; /* enum pending_timeout */ |
Andy Green | 7c212cc | 2010-11-08 20:20:42 +0000 | [diff] [blame] | 942 | }; |
| 943 | |
Andy Green | 3d67f51 | 2014-04-03 07:29:50 +0800 | [diff] [blame] | 944 | LWS_EXTERN int log_level; |
| 945 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 946 | LWS_EXTERN void |
Andy Green | 6b5de70 | 2015-12-15 21:15:58 +0800 | [diff] [blame] | 947 | lws_close_free_wsi(struct lws *wsi, enum lws_close_status); |
Andy Green | 508946c | 2013-02-12 10:19:08 +0800 | [diff] [blame] | 948 | |
Andy Green | 34f3dd2 | 2014-04-03 07:42:50 +0800 | [diff] [blame] | 949 | LWS_EXTERN int |
Andy Green | 6b5de70 | 2015-12-15 21:15:58 +0800 | [diff] [blame] | 950 | remove_wsi_socket_from_fds(struct lws *wsi); |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 951 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 952 | lws_rxflow_cache(struct lws *wsi, unsigned char *buf, int n, int len); |
Andy Green | 34f3dd2 | 2014-04-03 07:42:50 +0800 | [diff] [blame] | 953 | |
Andy Green | d636e35 | 2013-01-29 12:36:17 +0800 | [diff] [blame] | 954 | #ifndef LWS_LATENCY |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 955 | static inline void |
| 956 | lws_latency(struct lws_context *context, struct lws *wsi, const char *action, |
| 957 | int ret, int completion) { |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 958 | do { |
| 959 | (void)context; (void)wsi; (void)action; (void)ret; |
| 960 | (void)completion; |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 961 | } while (0); |
| 962 | } |
| 963 | static inline void |
| 964 | lws_latency_pre(struct lws_context *context, struct lws *wsi) { |
| 965 | do { (void)context; (void)wsi; } while (0); |
| 966 | } |
Andy Green | d636e35 | 2013-01-29 12:36:17 +0800 | [diff] [blame] | 967 | #else |
| 968 | #define lws_latency_pre(_context, _wsi) lws_latency(_context, _wsi, NULL, 0, 0) |
| 969 | extern void |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 970 | lws_latency(struct lws_context *context, struct lws *wsi, const char *action, |
| 971 | int ret, int completion); |
Andy Green | d636e35 | 2013-01-29 12:36:17 +0800 | [diff] [blame] | 972 | #endif |
| 973 | |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 974 | LWS_EXTERN void |
Andy Green | 6b5de70 | 2015-12-15 21:15:58 +0800 | [diff] [blame] | 975 | lws_set_protocol_write_pending(struct lws *wsi, |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 976 | enum lws_pending_protocol_send pend); |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 977 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 978 | lws_client_rx_sm(struct lws *wsi, unsigned char c); |
Andy Green | 4739e5c | 2011-01-22 12:51:57 +0000 | [diff] [blame] | 979 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 980 | LWS_EXTERN int |
Andy Green | 6b5de70 | 2015-12-15 21:15:58 +0800 | [diff] [blame] | 981 | lws_parse(struct lws *wsi, unsigned char c); |
Andy Green | b45993c | 2010-12-18 15:13:50 +0000 | [diff] [blame] | 982 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 983 | LWS_EXTERN int |
Andy Green | 6b5de70 | 2015-12-15 21:15:58 +0800 | [diff] [blame] | 984 | lws_http_action(struct lws *wsi); |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 985 | |
| 986 | LWS_EXTERN int |
Andy Green | df73616 | 2011-01-18 15:39:02 +0000 | [diff] [blame] | 987 | lws_b64_selftest(void); |
Andy Green | bfb051f | 2011-02-09 08:49:14 +0000 | [diff] [blame] | 988 | |
Andy Green | 2cd3074 | 2015-11-02 13:10:33 +0800 | [diff] [blame] | 989 | #if defined(_WIN32) || defined(MBED_OPERATORS) |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 990 | LWS_EXTERN struct lws * |
Andy Green | 1fa7685 | 2015-12-14 11:17:16 +0800 | [diff] [blame] | 991 | wsi_from_fd(const struct lws_context *context, lws_sockfd_type fd); |
Andy Green | 0d33833 | 2011-02-12 11:57:43 +0000 | [diff] [blame] | 992 | |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 993 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 994 | insert_wsi(struct lws_context *context, struct lws *wsi); |
Bud Davis | 229bfec | 2015-01-30 10:13:01 +0800 | [diff] [blame] | 995 | |
| 996 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 997 | delete_from_fd(struct lws_context *context, lws_sockfd_type fd); |
Bud Davis | 229bfec | 2015-01-30 10:13:01 +0800 | [diff] [blame] | 998 | #else |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 999 | #define wsi_from_fd(A,B) A->lws_lookup[B] |
Bud Davis | 229bfec | 2015-01-30 10:13:01 +0800 | [diff] [blame] | 1000 | #define insert_wsi(A,B) A->lws_lookup[B->sock]=B |
| 1001 | #define delete_from_fd(A,B) A->lws_lookup[B]=0 |
| 1002 | #endif |
| 1003 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 1004 | LWS_EXTERN int |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1005 | insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi); |
Darin Willits | c19456f | 2011-02-14 17:52:39 +0000 | [diff] [blame] | 1006 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 1007 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1008 | lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len); |
Andy Green | d44bf7f | 2011-03-06 10:29:38 +0000 | [diff] [blame] | 1009 | |
Andy Green | 95a7b5d | 2011-03-06 10:29:39 +0000 | [diff] [blame] | 1010 | |
Andy Green | 1c6e142 | 2013-02-20 19:11:31 +0800 | [diff] [blame] | 1011 | LWS_EXTERN int |
Andy Green | 6b5de70 | 2015-12-15 21:15:58 +0800 | [diff] [blame] | 1012 | lws_service_timeout_check(struct lws *wsi, unsigned int sec); |
Andy Green | a41314f | 2011-05-23 10:00:03 +0100 | [diff] [blame] | 1013 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1014 | LWS_EXTERN struct lws * |
Andy Green | 6b5de70 | 2015-12-15 21:15:58 +0800 | [diff] [blame] | 1015 | lws_client_connect_2(struct lws *wsi); |
Andy Green | a41314f | 2011-05-23 10:00:03 +0100 | [diff] [blame] | 1016 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1017 | LWS_EXTERN struct lws * |
| 1018 | lws_create_new_server_wsi(struct lws_context *context); |
Andy Green | a41314f | 2011-05-23 10:00:03 +0100 | [diff] [blame] | 1019 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 1020 | LWS_EXTERN char * |
Andy Green | 6b5de70 | 2015-12-15 21:15:58 +0800 | [diff] [blame] | 1021 | lws_generate_client_handshake(struct lws *wsi, char *pkt); |
Andy Green | a41314f | 2011-05-23 10:00:03 +0100 | [diff] [blame] | 1022 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 1023 | LWS_EXTERN int |
Andy Green | 6b5de70 | 2015-12-15 21:15:58 +0800 | [diff] [blame] | 1024 | lws_handle_POLLOUT_event(struct lws *wsi, struct lws_pollfd *pollfd); |
Andy Green | 91b0589 | 2014-10-17 08:38:44 +0800 | [diff] [blame] | 1025 | |
Andy Green | cdb9bf9 | 2014-04-12 10:07:02 +0800 | [diff] [blame] | 1026 | /* |
| 1027 | * EXTENSIONS |
| 1028 | */ |
| 1029 | |
Andy Green | 3182ece | 2013-01-20 17:08:31 +0800 | [diff] [blame] | 1030 | #ifndef LWS_NO_EXTENSIONS |
Andy Green | cdb9bf9 | 2014-04-12 10:07:02 +0800 | [diff] [blame] | 1031 | LWS_VISIBLE void |
| 1032 | lws_context_init_extensions(struct lws_context_creation_info *info, |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1033 | struct lws_context *context); |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 1034 | LWS_EXTERN int |
Andy Green | 6b5de70 | 2015-12-15 21:15:58 +0800 | [diff] [blame] | 1035 | lws_any_extension_handled(struct lws *wsi, |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1036 | enum lws_extension_callback_reasons r, |
Andy Green | 6ee372f | 2012-04-09 15:09:01 +0800 | [diff] [blame] | 1037 | void *v, size_t len); |
Andy Green | a41314f | 2011-05-23 10:00:03 +0100 | [diff] [blame] | 1038 | |
Andy Green | 2c24ec0 | 2014-04-02 19:45:42 +0800 | [diff] [blame] | 1039 | LWS_EXTERN int |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 1040 | lws_ext_cb_wsi_active_exts(struct lws *wsi, int reason, |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1041 | void *buf, int len); |
Andy Green | 2c24ec0 | 2014-04-02 19:45:42 +0800 | [diff] [blame] | 1042 | LWS_EXTERN int |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 1043 | lws_ext_cb_all_exts(struct lws_context *context, |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1044 | struct lws *wsi, int reason, |
| 1045 | void *arg, int len); |
Andy Green | 2c24ec0 | 2014-04-02 19:45:42 +0800 | [diff] [blame] | 1046 | #else |
Andy Green | 6b5de70 | 2015-12-15 21:15:58 +0800 | [diff] [blame] | 1047 | #define lws_any_extension_handled(_a, _b, _c, _d) (0) |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 1048 | #define lws_ext_cb_wsi_active_exts(_a, _b, _c, _d) (0) |
| 1049 | #define lws_ext_cb_all_exts(_a, _b, _c, _d, _e) (0) |
Andy Green | b49a995 | 2014-04-03 10:11:04 +0800 | [diff] [blame] | 1050 | #define lws_issue_raw_ext_access lws_issue_raw |
Andy Green | cdb9bf9 | 2014-04-12 10:07:02 +0800 | [diff] [blame] | 1051 | #define lws_context_init_extensions(_a, _b) |
Andy Green | 3182ece | 2013-01-20 17:08:31 +0800 | [diff] [blame] | 1052 | #endif |
Andy Green | a41314f | 2011-05-23 10:00:03 +0100 | [diff] [blame] | 1053 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 1054 | LWS_EXTERN int |
Andy Green | 6b5de70 | 2015-12-15 21:15:58 +0800 | [diff] [blame] | 1055 | lws_client_interpret_server_handshake(struct lws *wsi); |
Andy Green | a41314f | 2011-05-23 10:00:03 +0100 | [diff] [blame] | 1056 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 1057 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1058 | lws_rx_sm(struct lws *wsi, unsigned char c); |
Andy Green | a41314f | 2011-05-23 10:00:03 +0100 | [diff] [blame] | 1059 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 1060 | LWS_EXTERN int |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1061 | lws_issue_raw_ext_access(struct lws *wsi, unsigned char *buf, size_t len); |
Andy Green | 0922650 | 2011-05-28 10:19:19 +0100 | [diff] [blame] | 1062 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 1063 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1064 | _lws_rx_flow_control(struct lws *wsi); |
Andy Green | 706961d | 2013-01-17 16:50:35 +0800 | [diff] [blame] | 1065 | |
Andy Green | 44c1161 | 2014-11-08 11:18:47 +0800 | [diff] [blame] | 1066 | LWS_EXTERN void |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1067 | lws_union_transition(struct lws *wsi, enum connection_mode mode); |
Andy Green | 44c1161 | 2014-11-08 11:18:47 +0800 | [diff] [blame] | 1068 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 1069 | LWS_EXTERN int |
Andy Green | 00c6d15 | 2015-12-17 07:54:44 +0800 | [diff] [blame] | 1070 | user_callback_handle_rxflow(callback_function, struct lws *wsi, |
| 1071 | enum lws_callback_reasons reason, void *user, |
| 1072 | void *in, size_t len); |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 1073 | #ifdef LWS_USE_HTTP2 |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1074 | LWS_EXTERN struct lws *lws_http2_get_network_wsi(struct lws *wsi); |
| 1075 | struct lws * lws_http2_get_nth_child(struct lws *wsi, int n); |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 1076 | LWS_EXTERN int |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1077 | lws_http2_interpret_settings_payload(struct http2_settings *settings, |
| 1078 | unsigned char *buf, int len); |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 1079 | LWS_EXTERN void lws_http2_init(struct http2_settings *settings); |
| 1080 | LWS_EXTERN int |
Andy Green | 11c05bf | 2015-12-16 18:19:08 +0800 | [diff] [blame] | 1081 | lws_http2_parser(struct lws *wsi, unsigned char c); |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1082 | LWS_EXTERN int lws_http2_do_pps_send(struct lws_context *context, |
| 1083 | struct lws *wsi); |
| 1084 | LWS_EXTERN int lws_http2_frame_write(struct lws *wsi, int type, int flags, |
| 1085 | unsigned int sid, unsigned int len, |
| 1086 | unsigned char *buf); |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1087 | LWS_EXTERN struct lws * |
| 1088 | lws_http2_wsi_from_id(struct lws *wsi, unsigned int sid); |
Andy Green | 11c05bf | 2015-12-16 18:19:08 +0800 | [diff] [blame] | 1089 | LWS_EXTERN int lws_hpack_interpret(struct lws *wsi, |
Andy Green | 2add634 | 2014-10-12 08:38:16 +0800 | [diff] [blame] | 1090 | unsigned char c); |
Andy Green | 917f43a | 2014-10-12 14:31:47 +0800 | [diff] [blame] | 1091 | LWS_EXTERN int |
Andy Green | 11c05bf | 2015-12-16 18:19:08 +0800 | [diff] [blame] | 1092 | lws_add_http2_header_by_name(struct lws *wsi, |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1093 | const unsigned char *name, |
| 1094 | const unsigned char *value, int length, |
| 1095 | unsigned char **p, unsigned char *end); |
Andy Green | 917f43a | 2014-10-12 14:31:47 +0800 | [diff] [blame] | 1096 | LWS_EXTERN int |
Andy Green | 11c05bf | 2015-12-16 18:19:08 +0800 | [diff] [blame] | 1097 | lws_add_http2_header_by_token(struct lws *wsi, |
Andy Green | 917f43a | 2014-10-12 14:31:47 +0800 | [diff] [blame] | 1098 | enum lws_token_indexes token, |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1099 | const unsigned char *value, int length, |
| 1100 | unsigned char **p, unsigned char *end); |
Andy Green | 917f43a | 2014-10-12 14:31:47 +0800 | [diff] [blame] | 1101 | LWS_EXTERN int |
Andy Green | 11c05bf | 2015-12-16 18:19:08 +0800 | [diff] [blame] | 1102 | lws_add_http2_header_status(struct lws *wsi, |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1103 | unsigned int code, unsigned char **p, |
Andy Green | 917f43a | 2014-10-12 14:31:47 +0800 | [diff] [blame] | 1104 | unsigned char *end); |
Andy Green | 7df53c5 | 2014-10-22 15:37:28 +0800 | [diff] [blame] | 1105 | LWS_EXTERN |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1106 | void lws_http2_configure_if_upgraded(struct lws *wsi); |
Andy Green | 7df53c5 | 2014-10-22 15:37:28 +0800 | [diff] [blame] | 1107 | #else |
| 1108 | #define lws_http2_configure_if_upgraded(x) |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 1109 | #endif |
Andy Green | 706961d | 2013-01-17 16:50:35 +0800 | [diff] [blame] | 1110 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 1111 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1112 | lws_plat_set_socket_options(struct lws_context *context, lws_sockfd_type fd); |
Andy Green | a690cd0 | 2013-02-09 12:25:31 +0800 | [diff] [blame] | 1113 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 1114 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1115 | lws_allocate_header_table(struct lws *wsi); |
Andy Green | 16ab318 | 2013-02-10 18:02:31 +0800 | [diff] [blame] | 1116 | |
Andrew Canaday | 3771881 | 2014-11-07 11:20:59 +0800 | [diff] [blame] | 1117 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1118 | lws_free_header_table(struct lws *wsi); |
Andrew Canaday | 3771881 | 2014-11-07 11:20:59 +0800 | [diff] [blame] | 1119 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 1120 | LWS_EXTERN char * |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1121 | lws_hdr_simple_ptr(struct lws *wsi, enum lws_token_indexes h); |
Andy Green | 16ab318 | 2013-02-10 18:02:31 +0800 | [diff] [blame] | 1122 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 1123 | LWS_EXTERN int |
Andy Green | 11c05bf | 2015-12-16 18:19:08 +0800 | [diff] [blame] | 1124 | lws_hdr_simple_create(struct lws *wsi, enum lws_token_indexes h, const char *s); |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 1125 | |
Andy Green | 2af4d5b | 2013-02-18 16:30:10 +0800 | [diff] [blame] | 1126 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1127 | lws_ensure_user_space(struct lws *wsi); |
Andy Green | 2af4d5b | 2013-02-18 16:30:10 +0800 | [diff] [blame] | 1128 | |
Andy Green | 158e804 | 2014-04-02 14:25:10 +0800 | [diff] [blame] | 1129 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1130 | lws_change_pollfd(struct lws *wsi, int _and, int _or); |
Andy Green | 91f19d8 | 2013-12-21 11:18:34 +0800 | [diff] [blame] | 1131 | |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 1132 | #ifndef LWS_NO_SERVER |
Andy Green | e38031a | 2014-04-03 08:24:29 +0800 | [diff] [blame] | 1133 | int lws_context_init_server(struct lws_context_creation_info *info, |
Andy Green | aa775fd | 2015-12-26 08:56:58 +0800 | [diff] [blame] | 1134 | struct lws_context *context); |
Andy Green | d7340c1 | 2014-04-10 14:08:10 +0800 | [diff] [blame] | 1135 | LWS_EXTERN int |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1136 | handshake_0405(struct lws_context *context, struct lws *wsi); |
| 1137 | LWS_EXTERN int |
| 1138 | lws_interpret_incoming_packet(struct lws *wsi, unsigned char *buf, size_t len); |
Andy Green | cdb9bf9 | 2014-04-12 10:07:02 +0800 | [diff] [blame] | 1139 | LWS_EXTERN void |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1140 | lws_server_get_canonical_hostname(struct lws_context *context, |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1141 | struct lws_context_creation_info *info); |
Andy Green | e38031a | 2014-04-03 08:24:29 +0800 | [diff] [blame] | 1142 | #else |
| 1143 | #define lws_context_init_server(_a, _b) (0) |
Andy Green | 3ef579b | 2015-12-04 09:23:56 +0800 | [diff] [blame] | 1144 | #define lws_interpret_incoming_packet(_a, _b, _c) (0) |
Andy Green | cdb9bf9 | 2014-04-12 10:07:02 +0800 | [diff] [blame] | 1145 | #define lws_server_get_canonical_hostname(_a, _b) |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 1146 | #endif |
| 1147 | |
| 1148 | #ifndef LWS_NO_DAEMONIZE |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 1149 | LWS_EXTERN int get_daemonize_pid(); |
Andy Green | cdb9bf9 | 2014-04-12 10:07:02 +0800 | [diff] [blame] | 1150 | #else |
| 1151 | #define get_daemonize_pid() (0) |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 1152 | #endif |
| 1153 | |
Andy Green | 2cd3074 | 2015-11-02 13:10:33 +0800 | [diff] [blame] | 1154 | #if !defined(MBED_OPERATORS) |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1155 | LWS_EXTERN int |
| 1156 | interface_to_sa(struct lws_context *context, const char *ifname, |
| 1157 | struct sockaddr_in *addr, size_t addrlen); |
Andy Green | 2cd3074 | 2015-11-02 13:10:33 +0800 | [diff] [blame] | 1158 | #endif |
Andy Green | b25b85f | 2014-04-03 23:34:09 +0800 | [diff] [blame] | 1159 | LWS_EXTERN void lwsl_emit_stderr(int level, const char *line); |
| 1160 | |
Andy Green | 1a308e4 | 2014-04-08 07:26:30 +0100 | [diff] [blame] | 1161 | enum lws_ssl_capable_status { |
| 1162 | LWS_SSL_CAPABLE_ERROR = -1, |
| 1163 | LWS_SSL_CAPABLE_MORE_SERVICE = -2, |
| 1164 | }; |
| 1165 | |
Darin Willits | c19456f | 2011-02-14 17:52:39 +0000 | [diff] [blame] | 1166 | #ifndef LWS_OPENSSL_SUPPORT |
Andy Green | cdb9bf9 | 2014-04-12 10:07:02 +0800 | [diff] [blame] | 1167 | #define LWS_SSL_ENABLED(context) (0) |
Andy Green | c57037a | 2014-04-03 10:17:00 +0800 | [diff] [blame] | 1168 | #define lws_context_init_server_ssl(_a, _b) (0) |
| 1169 | #define lws_ssl_destroy(_a) |
Andy Green | 2eedea9 | 2014-04-03 14:33:48 +0800 | [diff] [blame] | 1170 | #define lws_context_init_http2_ssl(_a) |
Andy Green | 0213812 | 2014-04-06 06:26:35 +0100 | [diff] [blame] | 1171 | #define lws_ssl_capable_read lws_ssl_capable_read_no_ssl |
| 1172 | #define lws_ssl_capable_write lws_ssl_capable_write_no_ssl |
=?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= | 4c0ba02 | 2015-08-19 16:23:33 +0200 | [diff] [blame] | 1173 | #define lws_ssl_pending lws_ssl_pending_no_ssl |
Andy Green | 6b5de70 | 2015-12-15 21:15:58 +0800 | [diff] [blame] | 1174 | #define lws_server_socket_service_ssl(_a, _b, _c, _d) (0) |
Andy Green | cdb9bf9 | 2014-04-12 10:07:02 +0800 | [diff] [blame] | 1175 | #define lws_ssl_close(_a) (0) |
| 1176 | #define lws_ssl_context_destroy(_a) |
Andy Green | 6b5de70 | 2015-12-15 21:15:58 +0800 | [diff] [blame] | 1177 | #define lws_ssl_remove_wsi_from_buffered_list(_a) |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 1178 | #else |
Andy Green | cdb9bf9 | 2014-04-12 10:07:02 +0800 | [diff] [blame] | 1179 | #define LWS_SSL_ENABLED(context) (context->use_ssl) |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 1180 | LWS_EXTERN int openssl_websocket_private_data_index; |
Andy Green | 0213812 | 2014-04-06 06:26:35 +0100 | [diff] [blame] | 1181 | LWS_EXTERN int |
Andy Green | 6b5de70 | 2015-12-15 21:15:58 +0800 | [diff] [blame] | 1182 | lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len); |
Andy Green | 0213812 | 2014-04-06 06:26:35 +0100 | [diff] [blame] | 1183 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1184 | lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len); |
Andy Green | cdb9bf9 | 2014-04-12 10:07:02 +0800 | [diff] [blame] | 1185 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1186 | lws_ssl_pending(struct lws *wsi); |
=?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= | 4c0ba02 | 2015-08-19 16:23:33 +0200 | [diff] [blame] | 1187 | LWS_EXTERN int |
Andy Green | 6b5de70 | 2015-12-15 21:15:58 +0800 | [diff] [blame] | 1188 | lws_server_socket_service_ssl(struct lws **wsi, struct lws *new_wsi, |
| 1189 | lws_sockfd_type accept_fd, |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1190 | struct lws_pollfd *pollfd); |
Andy Green | cdb9bf9 | 2014-04-12 10:07:02 +0800 | [diff] [blame] | 1191 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1192 | lws_ssl_close(struct lws *wsi); |
Andy Green | cdb9bf9 | 2014-04-12 10:07:02 +0800 | [diff] [blame] | 1193 | LWS_EXTERN void |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1194 | lws_ssl_context_destroy(struct lws_context *context); |
Andy Green | 5281560 | 2015-01-29 08:36:18 +0800 | [diff] [blame] | 1195 | LWS_VISIBLE void |
Andy Green | 6b5de70 | 2015-12-15 21:15:58 +0800 | [diff] [blame] | 1196 | lws_ssl_remove_wsi_from_buffered_list(struct lws *wsi); |
Andy Green | c57037a | 2014-04-03 10:17:00 +0800 | [diff] [blame] | 1197 | #ifndef LWS_NO_SERVER |
| 1198 | LWS_EXTERN int |
| 1199 | lws_context_init_server_ssl(struct lws_context_creation_info *info, |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1200 | struct lws_context *context); |
Andy Green | c57037a | 2014-04-03 10:17:00 +0800 | [diff] [blame] | 1201 | #else |
| 1202 | #define lws_context_init_server_ssl(_a, _b) (0) |
| 1203 | #endif |
| 1204 | LWS_EXTERN void |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1205 | lws_ssl_destroy(struct lws_context *context); |
Andy Green | 2eedea9 | 2014-04-03 14:33:48 +0800 | [diff] [blame] | 1206 | |
| 1207 | /* HTTP2-related */ |
| 1208 | |
| 1209 | #ifdef LWS_USE_HTTP2 |
| 1210 | LWS_EXTERN void |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1211 | lws_context_init_http2_ssl(struct lws_context *context); |
Andy Green | 2eedea9 | 2014-04-03 14:33:48 +0800 | [diff] [blame] | 1212 | #else |
| 1213 | #define lws_context_init_http2_ssl(_a) |
| 1214 | #endif |
Darin Willits | c19456f | 2011-02-14 17:52:39 +0000 | [diff] [blame] | 1215 | #endif |
Andy Green | a654fc0 | 2014-04-03 07:16:40 +0800 | [diff] [blame] | 1216 | |
Patrick Gansterer | a6b019a | 2014-04-15 18:40:31 +0200 | [diff] [blame] | 1217 | LWS_EXTERN int |
Andy Green | 6b5de70 | 2015-12-15 21:15:58 +0800 | [diff] [blame] | 1218 | lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, int len); |
Patrick Gansterer | a6b019a | 2014-04-15 18:40:31 +0200 | [diff] [blame] | 1219 | |
| 1220 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1221 | lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, int len); |
Patrick Gansterer | a6b019a | 2014-04-15 18:40:31 +0200 | [diff] [blame] | 1222 | |
=?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= | 4c0ba02 | 2015-08-19 16:23:33 +0200 | [diff] [blame] | 1223 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1224 | lws_ssl_pending_no_ssl(struct lws *wsi); |
=?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= | 4c0ba02 | 2015-08-19 16:23:33 +0200 | [diff] [blame] | 1225 | |
Andy Green | a654fc0 | 2014-04-03 07:16:40 +0800 | [diff] [blame] | 1226 | #ifndef LWS_NO_CLIENT |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1227 | LWS_EXTERN int lws_client_socket_service(struct lws_context *context, |
| 1228 | struct lws *wsi, |
| 1229 | struct lws_pollfd *pollfd); |
Andy Green | c57037a | 2014-04-03 10:17:00 +0800 | [diff] [blame] | 1230 | #ifdef LWS_OPENSSL_SUPPORT |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1231 | LWS_EXTERN int |
| 1232 | lws_context_init_client_ssl(struct lws_context_creation_info *info, |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1233 | struct lws_context *context); |
Andy Green | e38031a | 2014-04-03 08:24:29 +0800 | [diff] [blame] | 1234 | #else |
Andy Green | c57037a | 2014-04-03 10:17:00 +0800 | [diff] [blame] | 1235 | #define lws_context_init_client_ssl(_a, _b) (0) |
| 1236 | #endif |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1237 | LWS_EXTERN int |
| 1238 | lws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len); |
| 1239 | LWS_EXTERN void |
| 1240 | lws_decode_ssl_error(void); |
Andy Green | c57037a | 2014-04-03 10:17:00 +0800 | [diff] [blame] | 1241 | #else |
| 1242 | #define lws_context_init_client_ssl(_a, _b) (0) |
Andy Green | aad2eac | 2014-04-03 09:03:37 +0800 | [diff] [blame] | 1243 | #define lws_handshake_client(_a, _b, _c) (0) |
Andy Green | a654fc0 | 2014-04-03 07:16:40 +0800 | [diff] [blame] | 1244 | #endif |
| 1245 | #ifndef LWS_NO_SERVER |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1246 | LWS_EXTERN int |
| 1247 | lws_server_socket_service(struct lws_context *context, struct lws *wsi, |
| 1248 | struct lws_pollfd *pollfd); |
| 1249 | LWS_EXTERN int |
| 1250 | _lws_rx_flow_control(struct lws *wsi); |
| 1251 | LWS_EXTERN int |
Andy Green | 11c05bf | 2015-12-16 18:19:08 +0800 | [diff] [blame] | 1252 | lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len); |
Andy Green | b3d21f1 | 2015-12-25 09:12:08 +0800 | [diff] [blame] | 1253 | LWS_EXTERN int |
| 1254 | _lws_server_listen_accept_flow_control(struct lws_context *context, int on); |
Andy Green | d99476b | 2014-04-03 08:40:05 +0800 | [diff] [blame] | 1255 | #else |
Andy Green | b49a995 | 2014-04-03 10:11:04 +0800 | [diff] [blame] | 1256 | #define lws_server_socket_service(_a, _b, _c) (0) |
Andy Green | 6230476 | 2015-12-04 08:43:54 +0800 | [diff] [blame] | 1257 | #define _lws_rx_flow_control(_a) (0) |
Andy Green | 11c05bf | 2015-12-16 18:19:08 +0800 | [diff] [blame] | 1258 | #define lws_handshake_server(_a, _b, _c) (0) |
Andy Green | b3d21f1 | 2015-12-25 09:12:08 +0800 | [diff] [blame] | 1259 | #define _lws_server_listen_accept_flow_control(a, b) (0) |
Andy Green | a654fc0 | 2014-04-03 07:16:40 +0800 | [diff] [blame] | 1260 | #endif |
Andy Green | 40110e8 | 2015-12-14 08:52:03 +0800 | [diff] [blame] | 1261 | |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1262 | LWS_EXTERN int |
| 1263 | lws_get_addresses(struct lws_context *context, void *ads, char *name, |
| 1264 | int name_len, char *rip, int rip_len); |
Andy Green | a654fc0 | 2014-04-03 07:16:40 +0800 | [diff] [blame] | 1265 | |
| 1266 | /* |
Alejandro Mery | cdc9717 | 2014-12-04 23:15:27 +0100 | [diff] [blame] | 1267 | * custom allocator |
| 1268 | */ |
| 1269 | LWS_EXTERN void* |
| 1270 | lws_realloc(void *ptr, size_t size); |
| 1271 | |
| 1272 | LWS_EXTERN void* |
| 1273 | lws_zalloc(size_t size); |
| 1274 | |
| 1275 | #define lws_malloc(S) lws_realloc(NULL, S) |
| 1276 | #define lws_free(P) lws_realloc(P, 0) |
Andy Green | 54806b1 | 2015-12-17 17:03:59 +0800 | [diff] [blame] | 1277 | #define lws_free_set_NULL(P) do { lws_realloc(P, 0); (P) = NULL; } while(0) |
Alejandro Mery | cdc9717 | 2014-12-04 23:15:27 +0100 | [diff] [blame] | 1278 | |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1279 | /* lws_plat_ */ |
Andy Green | a654fc0 | 2014-04-03 07:16:40 +0800 | [diff] [blame] | 1280 | LWS_EXTERN void |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1281 | lws_plat_delete_socket_from_fds(struct lws_context *context, |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1282 | struct lws *wsi, int m); |
Andy Green | a654fc0 | 2014-04-03 07:16:40 +0800 | [diff] [blame] | 1283 | LWS_EXTERN void |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1284 | lws_plat_insert_socket_into_fds(struct lws_context *context, |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1285 | struct lws *wsi); |
Andy Green | a654fc0 | 2014-04-03 07:16:40 +0800 | [diff] [blame] | 1286 | LWS_EXTERN void |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1287 | lws_plat_service_periodic(struct lws_context *context); |
Andy Green | a654fc0 | 2014-04-03 07:16:40 +0800 | [diff] [blame] | 1288 | |
| 1289 | LWS_EXTERN int |
Andy Green | dc8a3a8 | 2015-12-06 09:15:27 +0800 | [diff] [blame] | 1290 | lws_plat_change_pollfd(struct lws_context *context, struct lws *wsi, |
| 1291 | struct lws_pollfd *pfd); |
Andy Green | a654fc0 | 2014-04-03 07:16:40 +0800 | [diff] [blame] | 1292 | LWS_EXTERN int |
| 1293 | lws_plat_context_early_init(void); |
| 1294 | LWS_EXTERN void |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1295 | lws_plat_context_early_destroy(struct lws_context *context); |
Andy Green | a654fc0 | 2014-04-03 07:16:40 +0800 | [diff] [blame] | 1296 | LWS_EXTERN void |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1297 | lws_plat_context_late_destroy(struct lws_context *context); |
Andy Green | a654fc0 | 2014-04-03 07:16:40 +0800 | [diff] [blame] | 1298 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1299 | lws_poll_listen_fd(struct lws_pollfd *fd); |
Andy Green | a654fc0 | 2014-04-03 07:16:40 +0800 | [diff] [blame] | 1300 | LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame] | 1301 | lws_plat_service(struct lws_context *context, int timeout_ms); |
Andy Green | a654fc0 | 2014-04-03 07:16:40 +0800 | [diff] [blame] | 1302 | LWS_EXTERN int |
Andy Green | 4386e36 | 2015-12-10 07:14:16 +0800 | [diff] [blame] | 1303 | lws_plat_init(struct lws_context *context, |
| 1304 | struct lws_context_creation_info *info); |
Andy Green | a654fc0 | 2014-04-03 07:16:40 +0800 | [diff] [blame] | 1305 | LWS_EXTERN void |
| 1306 | lws_plat_drop_app_privileges(struct lws_context_creation_info *info); |
| 1307 | LWS_EXTERN unsigned long long |
| 1308 | time_in_microseconds(void); |
| 1309 | LWS_EXTERN const char * |
| 1310 | lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt); |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 1311 | |
| 1312 | #ifdef __cplusplus |
| 1313 | }; |
| 1314 | #endif |