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