Andy Green | a0da8a8 | 2010-11-08 17:12:19 +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 | 7e37d10 | 2015-01-28 21:03:49 +0800 | [diff] [blame] | 4 | * Copyright (C) 2010-2015 Andy Green <andy@warmcat.com> |
Andy Green | a0da8a8 | 2010-11-08 17:12:19 +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 | */ |
| 21 | |
Markus Elfring | 7521233 | 2013-10-26 20:23:00 +0800 | [diff] [blame] | 22 | #ifndef LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C |
| 23 | #define LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C |
Andy Green | ab990e4 | 2010-10-31 12:42:52 +0000 | [diff] [blame] | 24 | |
Andy Green | 29a44cf | 2015-12-04 07:55:17 +0800 | [diff] [blame] | 25 | /* old (pre 1.6) api name compatibility defines */ |
| 26 | |
| 27 | #define libwebsocket_create_context lws_create_context |
| 28 | #define libwebsocket_set_proxy lws_set_proxy |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 29 | #define lws_context_destroy lws_context_destroy |
Andy Green | 29a44cf | 2015-12-04 07:55:17 +0800 | [diff] [blame] | 30 | #define libwebsocket_service lws_service |
| 31 | #define libwebsocket_cancel_service lws_cancel_service |
| 32 | #define libwebsocket_sigint_cfg lws_sigint_cfg |
| 33 | #define libwebsocket_initloop lws_initloop |
| 34 | #define libwebsocket_sigint_cb lws_sigint_cb |
| 35 | #define libwebsocket_service_fd lws_service_fd |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 36 | #define lws_context_user lws_context_user |
Andy Green | 29a44cf | 2015-12-04 07:55:17 +0800 | [diff] [blame] | 37 | #define libwebsocket_set_timeout lws_set_timeout |
| 38 | #define libwebsocket_write lws_write |
| 39 | #define libwebsockets_serve_http_file_fragment lws_serve_http_file_fragment |
| 40 | #define libwebsockets_serve_http_file lws_serve_http_file |
| 41 | #define libwebsockets_return_http_status lws_return_http_status |
| 42 | #define libwebsockets_get_protocol lws_get_protocol |
| 43 | #define libwebsocket_callback_on_writable_all_protocol lws_callback_on_writable_all_protocol |
| 44 | #define libwebsocket_callback_on_writable lws_callback_on_writable |
| 45 | #define libwebsocket_callback_all_protocol lws_callback_all_protocol |
| 46 | #define libwebsocket_get_socket_fd lws_get_socket_fd |
| 47 | #define libwebsocket_is_final_fragment lws_is_final_fragment |
| 48 | #define libwebsocket_get_reserved_bits lws_get_reserved_bits |
| 49 | #define libwebsocket_rx_flow_control lws_rx_flow_control |
| 50 | #define libwebsocket_rx_flow_allow_all_protocol lws_rx_flow_allow_all_protocol |
| 51 | #define libwebsockets_remaining_packet_payload lws_remaining_packet_payload |
| 52 | #define libwebsocket_client_connect lws_client_connect |
| 53 | #define libwebsocket_canonical_hostname lws_canonical_hostname |
| 54 | #define libwebsockets_get_peer_addresses lws_get_peer_addresses |
| 55 | #define libwebsockets_get_random lws_get_random |
| 56 | #define libwebsockets_SHA1 lws_SHA1 |
| 57 | #define libwebsocket_read lws_read |
| 58 | #define libwebsocket_get_internal_extensions lws_get_internal_extensions |
Andy Green | 6230476 | 2015-12-04 08:43:54 +0800 | [diff] [blame] | 59 | #define libwebsocket_write_protocol lws_write_protocol |
Andy Green | 29a44cf | 2015-12-04 07:55:17 +0800 | [diff] [blame] | 60 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 61 | #define libwebsocket_protocols lws_protocols |
| 62 | #define libwebsocket_extension lws_extension |
| 63 | #define libwebsocket_context lws_context |
| 64 | #define libwebsocket_pollfd lws_pollfd |
| 65 | #define lws_callback_reasons lws_callback_reasons |
| 66 | #define libwebsocket lws |
| 67 | |
Andy Green | a11fe94 | 2011-09-25 10:30:26 +0100 | [diff] [blame] | 68 | #ifdef __cplusplus |
Paulo Roberto Urio | 4144e83 | 2012-06-04 09:04:33 +0800 | [diff] [blame] | 69 | #include <cstddef> |
José Luis Millán | 080e6dd | 2014-12-16 12:54:33 +0100 | [diff] [blame] | 70 | #include <cstdarg> |
Andy Green | 2cd3074 | 2015-11-02 13:10:33 +0800 | [diff] [blame] | 71 | #ifdef MBED_OPERATORS |
| 72 | #include "mbed-drivers/mbed.h" |
| 73 | #include "sal-iface-eth/EthernetInterface.h" |
| 74 | #include "sockets/TCPListener.h" |
| 75 | #include "sal-stack-lwip/lwipv4_init.h" |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 76 | |
| 77 | namespace { |
| 78 | const int SERVER_PORT = 80; |
| 79 | const int BUFFER_SIZE = 4096; |
| 80 | } |
| 81 | using namespace mbed::Sockets::v0; |
| 82 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 83 | struct lws; |
| 84 | struct lws_context; |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 85 | |
| 86 | class lws_conn { |
| 87 | public: |
| 88 | lws_conn(): |
| 89 | ts(NULL), |
Andy Green | 87eeb0a | 2015-11-25 08:22:08 +0800 | [diff] [blame] | 90 | wsi(NULL), |
| 91 | writeable(1), |
| 92 | awaiting_on_writeable(0) |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 93 | { |
| 94 | } |
| 95 | |
| 96 | public: |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 97 | void set_wsi(struct lws *_wsi) { wsi = _wsi; } |
Andy Green | 11f2734 | 2015-11-08 12:10:26 +0800 | [diff] [blame] | 98 | int actual_onRX(Socket *s); |
| 99 | void onRX(Socket *s); |
| 100 | void onError(Socket *s, socket_error_t err); |
| 101 | void onDisconnect(TCPStream *s); |
| 102 | void onSent(Socket *s, uint16_t len); |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 103 | void serialized_writeable(struct lws *wsi); |
Andy Green | 11f2734 | 2015-11-08 12:10:26 +0800 | [diff] [blame] | 104 | |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 105 | public: |
| 106 | TCPStream *ts; |
| 107 | |
| 108 | public: |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 109 | struct lws *wsi; |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 110 | char buffer[BUFFER_SIZE]; |
Andy Green | 87eeb0a | 2015-11-25 08:22:08 +0800 | [diff] [blame] | 111 | char writeable; |
| 112 | char awaiting_on_writeable; |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | class lws_conn_listener : lws_conn { |
| 116 | public: |
| 117 | lws_conn_listener(): |
| 118 | srv(SOCKET_STACK_LWIP_IPV4) |
| 119 | { |
| 120 | srv.setOnError(TCPStream::ErrorHandler_t(this, &lws_conn_listener::onError)); |
| 121 | } |
| 122 | |
| 123 | void start(const uint16_t port); |
| 124 | |
| 125 | protected: |
| 126 | void onRX(Socket *s); |
| 127 | void onError(Socket *s, socket_error_t err); |
| 128 | void onIncoming(TCPListener *s, void *impl); |
| 129 | void onDisconnect(TCPStream *s); |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 130 | |
| 131 | public: |
| 132 | TCPListener srv; |
| 133 | }; |
| 134 | |
Andy Green | 2cd3074 | 2015-11-02 13:10:33 +0800 | [diff] [blame] | 135 | #endif |
| 136 | |
Neil Horman | fc98f9a | 2014-12-13 14:15:48 +0800 | [diff] [blame] | 137 | extern "C" { |
Johan Simonsson | bb87ac8 | 2015-01-04 11:15:23 +0000 | [diff] [blame] | 138 | #else |
| 139 | #include <stdarg.h> |
Andy Green | a11fe94 | 2011-09-25 10:30:26 +0100 | [diff] [blame] | 140 | #endif |
wonder-mice | 41802c7 | 2015-04-22 00:16:57 -0700 | [diff] [blame] | 141 | |
Andy Green | 11f2734 | 2015-11-08 12:10:26 +0800 | [diff] [blame] | 142 | #ifdef MBED_OPERATORS |
| 143 | #define LWS_POSIX 0 |
| 144 | #else |
| 145 | #define LWS_POSIX 1 |
| 146 | #endif |
| 147 | |
Andy Green | 158e804 | 2014-04-02 14:25:10 +0800 | [diff] [blame] | 148 | #include "lws_config.h" |
Andy Green | a11fe94 | 2011-09-25 10:30:26 +0100 | [diff] [blame] | 149 | |
Andreas Pakulat | 68bd4bd | 2013-10-28 15:18:04 +0100 | [diff] [blame] | 150 | #if defined(WIN32) || defined(_WIN32) |
Stephan Eberle | b820e2c | 2015-10-23 08:10:55 +0200 | [diff] [blame] | 151 | #if (WINVER < 0x0501) |
| 152 | #undef WINVER |
| 153 | #undef _WIN32_WINNT |
| 154 | #define WINVER 0x0501 |
| 155 | #define _WIN32_WINNT WINVER |
| 156 | #endif |
Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 157 | #ifndef WIN32_LEAN_AND_MEAN |
| 158 | #define WIN32_LEAN_AND_MEAN |
| 159 | #endif |
| 160 | #include <winsock2.h> |
| 161 | #include <ws2tcpip.h> |
Paulo Roberto Urio | 4144e83 | 2012-06-04 09:04:33 +0800 | [diff] [blame] | 162 | #include <stddef.h> |
Andy Green | a343903 | 2014-11-30 13:17:35 +0800 | [diff] [blame] | 163 | #include <stdint.h> |
pmcdona | 0a0a7eb | 2013-12-18 10:17:25 +0800 | [diff] [blame] | 164 | #include <basetsd.h> |
Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 165 | |
Oleg Golosovskiy | 2ef7505 | 2011-10-04 20:20:14 +0800 | [diff] [blame] | 166 | #define strcasecmp stricmp |
Andy Green | dfb2304 | 2013-01-17 12:26:48 +0800 | [diff] [blame] | 167 | #define getdtablesize() 30000 |
Oleg Golosovskiy | 2ef7505 | 2011-10-04 20:20:14 +0800 | [diff] [blame] | 168 | |
Andy Green | 3661d7b | 2013-04-26 07:37:16 +0800 | [diff] [blame] | 169 | #define LWS_VISIBLE |
| 170 | |
David Galeano | 9454e21 | 2011-09-26 12:17:20 +0100 | [diff] [blame] | 171 | #ifdef LWS_DLL |
| 172 | #ifdef LWS_INTERNAL |
| 173 | #define LWS_EXTERN extern __declspec(dllexport) |
| 174 | #else |
| 175 | #define LWS_EXTERN extern __declspec(dllimport) |
| 176 | #endif |
Andy Green | 3661d7b | 2013-04-26 07:37:16 +0800 | [diff] [blame] | 177 | #else |
| 178 | #define LWS_EXTERN |
David Galeano | 9454e21 | 2011-09-26 12:17:20 +0100 | [diff] [blame] | 179 | #endif |
| 180 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 181 | #else // NOT WIN32 |
Andy Green | dfb2304 | 2013-01-17 12:26:48 +0800 | [diff] [blame] | 182 | #include <unistd.h> |
Andy Green | 5f2a815 | 2015-11-02 08:21:08 +0800 | [diff] [blame] | 183 | |
| 184 | #ifndef MBED_OPERATORS |
| 185 | #include <poll.h> |
Andy Green | 7e37d10 | 2015-01-28 21:03:49 +0800 | [diff] [blame] | 186 | #include <netdb.h> |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 187 | #else |
Andy Green | 87eeb0a | 2015-11-25 08:22:08 +0800 | [diff] [blame] | 188 | #define getdtablesize() (20) |
Andy Green | 5f2a815 | 2015-11-02 08:21:08 +0800 | [diff] [blame] | 189 | #endif |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 190 | |
| 191 | #if defined(__GNUC__) |
| 192 | #define LWS_VISIBLE __attribute__((visibility("default"))) |
| 193 | #else |
| 194 | #define LWS_VISIBLE |
| 195 | #endif |
| 196 | |
Krishnaraj R Bhat | 1662c62 | 2015-10-28 21:02:04 +0530 | [diff] [blame] | 197 | #if defined(__ANDROID__) |
| 198 | #define getdtablesize() 1024 |
| 199 | #endif |
| 200 | |
Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 201 | #endif |
Andy Green | 9f99034 | 2011-02-12 11:57:45 +0000 | [diff] [blame] | 202 | |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 203 | #ifdef LWS_USE_LIBEV |
| 204 | #include <ev.h> |
| 205 | #endif /* LWS_USE_LIBEV */ |
| 206 | |
David Galeano | 9454e21 | 2011-09-26 12:17:20 +0100 | [diff] [blame] | 207 | #ifndef LWS_EXTERN |
| 208 | #define LWS_EXTERN extern |
| 209 | #endif |
Andy Green | 158e804 | 2014-04-02 14:25:10 +0800 | [diff] [blame] | 210 | |
| 211 | #ifdef _WIN32 |
| 212 | #define random rand |
| 213 | #else |
| 214 | #include <sys/time.h> |
| 215 | #include <unistd.h> |
| 216 | #endif |
David Galeano | 9454e21 | 2011-09-26 12:17:20 +0100 | [diff] [blame] | 217 | |
joseph.urciuoli | 4d9c8fc | 2014-10-16 08:53:19 +0800 | [diff] [blame] | 218 | #ifdef LWS_OPENSSL_SUPPORT |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 219 | #ifdef USE_WOLFSSL |
ABruines | 80a7068 | 2015-08-09 22:56:32 +0200 | [diff] [blame] | 220 | #ifdef USE_OLD_CYASSL |
| 221 | #include <cyassl/openssl/ssl.h> |
| 222 | #else |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 223 | #include <wolfssl/openssl/ssl.h> |
ABruines | 80a7068 | 2015-08-09 22:56:32 +0200 | [diff] [blame] | 224 | #endif /* not USE_OLD_CYASSL */ |
joseph.urciuoli | 4d9c8fc | 2014-10-16 08:53:19 +0800 | [diff] [blame] | 225 | #else |
| 226 | #include <openssl/ssl.h> |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 227 | #endif /* not USE_WOLFSSL */ |
joseph.urciuoli | 4d9c8fc | 2014-10-16 08:53:19 +0800 | [diff] [blame] | 228 | #endif |
| 229 | |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 230 | #define CONTEXT_PORT_NO_LISTEN -1 |
Andy Green | a41314f | 2011-05-23 10:00:03 +0100 | [diff] [blame] | 231 | #define MAX_MUX_RECURSION 2 |
Andy Green | bfb051f | 2011-02-09 08:49:14 +0000 | [diff] [blame] | 232 | |
Andy Green | 43db045 | 2013-01-10 19:50:35 +0800 | [diff] [blame] | 233 | enum lws_log_levels { |
| 234 | LLL_ERR = 1 << 0, |
| 235 | LLL_WARN = 1 << 1, |
Andy Green | 7c19c34 | 2013-01-19 12:18:07 +0800 | [diff] [blame] | 236 | LLL_NOTICE = 1 << 2, |
| 237 | LLL_INFO = 1 << 3, |
| 238 | LLL_DEBUG = 1 << 4, |
| 239 | LLL_PARSER = 1 << 5, |
| 240 | LLL_HEADER = 1 << 6, |
| 241 | LLL_EXT = 1 << 7, |
| 242 | LLL_CLIENT = 1 << 8, |
Andy Green | d636e35 | 2013-01-29 12:36:17 +0800 | [diff] [blame] | 243 | LLL_LATENCY = 1 << 9, |
Andy Green | 43db045 | 2013-01-10 19:50:35 +0800 | [diff] [blame] | 244 | |
Andy Green | d636e35 | 2013-01-29 12:36:17 +0800 | [diff] [blame] | 245 | LLL_COUNT = 10 /* set to count of valid flags */ |
Andy Green | 43db045 | 2013-01-10 19:50:35 +0800 | [diff] [blame] | 246 | }; |
| 247 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 248 | LWS_VISIBLE LWS_EXTERN void _lws_log(int filter, const char *format, ...); |
Neal Horman | 98e491f | 2014-12-10 18:50:28 -0600 | [diff] [blame] | 249 | LWS_VISIBLE LWS_EXTERN void _lws_logv(int filter, const char *format, va_list vl); |
Andy Green | 69e4364 | 2013-01-19 11:58:07 +0800 | [diff] [blame] | 250 | |
Andy Green | d636e35 | 2013-01-29 12:36:17 +0800 | [diff] [blame] | 251 | /* notice, warn and log are always compiled in */ |
Andy Green | 69e4364 | 2013-01-19 11:58:07 +0800 | [diff] [blame] | 252 | #define lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__) |
| 253 | #define lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__) |
| 254 | #define lwsl_err(...) _lws_log(LLL_ERR, __VA_ARGS__) |
Andy Green | 69e4364 | 2013-01-19 11:58:07 +0800 | [diff] [blame] | 255 | /* |
Andy Green | d636e35 | 2013-01-29 12:36:17 +0800 | [diff] [blame] | 256 | * weaker logging can be deselected at configure time using --disable-debug |
Andy Green | 69e4364 | 2013-01-19 11:58:07 +0800 | [diff] [blame] | 257 | * that gets rid of the overhead of checking while keeping _warn and _err |
| 258 | * active |
| 259 | */ |
| 260 | #ifdef _DEBUG |
Andy Green | d636e35 | 2013-01-29 12:36:17 +0800 | [diff] [blame] | 261 | |
Andy Green | 69e4364 | 2013-01-19 11:58:07 +0800 | [diff] [blame] | 262 | #define lwsl_info(...) _lws_log(LLL_INFO, __VA_ARGS__) |
| 263 | #define lwsl_debug(...) _lws_log(LLL_DEBUG, __VA_ARGS__) |
| 264 | #define lwsl_parser(...) _lws_log(LLL_PARSER, __VA_ARGS__) |
| 265 | #define lwsl_header(...) _lws_log(LLL_HEADER, __VA_ARGS__) |
Andy Green | d636e35 | 2013-01-29 12:36:17 +0800 | [diff] [blame] | 266 | #define lwsl_ext(...) _lws_log(LLL_EXT, __VA_ARGS__) |
Andy Green | 69e4364 | 2013-01-19 11:58:07 +0800 | [diff] [blame] | 267 | #define lwsl_client(...) _lws_log(LLL_CLIENT, __VA_ARGS__) |
Andy Green | d636e35 | 2013-01-29 12:36:17 +0800 | [diff] [blame] | 268 | #define lwsl_latency(...) _lws_log(LLL_LATENCY, __VA_ARGS__) |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 269 | LWS_VISIBLE LWS_EXTERN void lwsl_hexdump(void *buf, size_t len); |
Andy Green | d636e35 | 2013-01-29 12:36:17 +0800 | [diff] [blame] | 270 | |
Andy Green | 69e4364 | 2013-01-19 11:58:07 +0800 | [diff] [blame] | 271 | #else /* no debug */ |
Andy Green | d636e35 | 2013-01-29 12:36:17 +0800 | [diff] [blame] | 272 | |
Andy Green | 2cd3074 | 2015-11-02 13:10:33 +0800 | [diff] [blame] | 273 | #define lwsl_info(...) {} |
| 274 | #define lwsl_debug(...) {} |
| 275 | #define lwsl_parser(...) {} |
| 276 | #define lwsl_header(...) {} |
| 277 | #define lwsl_ext(...) {} |
| 278 | #define lwsl_client(...) {} |
| 279 | #define lwsl_latency(...) {} |
Andy Green | 69e4364 | 2013-01-19 11:58:07 +0800 | [diff] [blame] | 280 | #define lwsl_hexdump(a, b) |
Andy Green | d636e35 | 2013-01-29 12:36:17 +0800 | [diff] [blame] | 281 | |
Andy Green | 69e4364 | 2013-01-19 11:58:07 +0800 | [diff] [blame] | 282 | #endif |
| 283 | |
Andy Green | 4e7a133 | 2013-11-11 07:30:33 +0800 | [diff] [blame] | 284 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) |
| 285 | |
Andy Green | 6ea337a | 2014-04-21 08:27:19 +0900 | [diff] [blame] | 286 | /* api change list for user code to test against */ |
| 287 | |
| 288 | #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG |
| 289 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 290 | /* the struct lws_protocols has the id field present */ |
Michael Haberler | a2d3bf1 | 2014-08-11 14:36:57 +0200 | [diff] [blame] | 291 | #define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD |
| 292 | |
Andy Green | 97ee57f | 2014-10-29 09:39:08 +0800 | [diff] [blame] | 293 | /* you can call lws_get_peer_write_allowance */ |
| 294 | #define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE |
Andy Green | 6ea337a | 2014-04-21 08:27:19 +0900 | [diff] [blame] | 295 | |
Michael Haberler | 49d0ce1 | 2014-12-01 14:05:51 +0100 | [diff] [blame] | 296 | /* extra parameter introduced in 917f43ab821 */ |
| 297 | #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_LEN |
| 298 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 299 | enum lws_context_options { |
Andy Green | c6bf2c2 | 2011-02-20 11:10:47 +0000 | [diff] [blame] | 300 | LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT = 2, |
Andy Green | 788c4a8 | 2012-10-22 12:29:57 +0100 | [diff] [blame] | 301 | LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME = 4, |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 302 | LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT = 8, |
James Devine | 3f13ea2 | 2014-03-24 16:09:25 +0800 | [diff] [blame] | 303 | LWS_SERVER_OPTION_LIBEV = 16, |
| 304 | LWS_SERVER_OPTION_DISABLE_IPV6 = 32, |
Andy Green | f55b2ef | 2014-07-05 10:59:59 +0800 | [diff] [blame] | 305 | LWS_SERVER_OPTION_DISABLE_OS_CA_CERTS = 64, |
Andy Green | 6d59f59 | 2015-10-15 09:12:58 +0800 | [diff] [blame] | 306 | LWS_SERVER_OPTION_PEER_CERT_NOT_REQUIRED = 128, |
Andy Green | bfb051f | 2011-02-09 08:49:14 +0000 | [diff] [blame] | 307 | }; |
Andy Green | 8014b29 | 2011-01-30 20:57:25 +0000 | [diff] [blame] | 308 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 309 | enum lws_callback_reasons { |
Andy Green | 775c0dd | 2010-10-29 14:15:22 +0100 | [diff] [blame] | 310 | LWS_CALLBACK_ESTABLISHED, |
David Brooks | 80a4497 | 2012-04-20 12:18:47 +0800 | [diff] [blame] | 311 | LWS_CALLBACK_CLIENT_CONNECTION_ERROR, |
Andy Green | 2b57a34 | 2013-02-06 15:15:25 +0900 | [diff] [blame] | 312 | LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH, |
Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 313 | LWS_CALLBACK_CLIENT_ESTABLISHED, |
Andy Green | 775c0dd | 2010-10-29 14:15:22 +0100 | [diff] [blame] | 314 | LWS_CALLBACK_CLOSED, |
Andy Green | 0c9563b | 2013-06-10 22:54:40 +0800 | [diff] [blame] | 315 | LWS_CALLBACK_CLOSED_HTTP, |
Andy Green | 775c0dd | 2010-10-29 14:15:22 +0100 | [diff] [blame] | 316 | LWS_CALLBACK_RECEIVE, |
John Tarlton | 05fc6ba | 2015-10-05 11:35:52 +0100 | [diff] [blame] | 317 | LWS_CALLBACK_RECEIVE_PONG, |
Andy Green | 4739e5c | 2011-01-22 12:51:57 +0000 | [diff] [blame] | 318 | LWS_CALLBACK_CLIENT_RECEIVE, |
Andy Green | a6cbece | 2011-01-27 20:06:03 +0000 | [diff] [blame] | 319 | LWS_CALLBACK_CLIENT_RECEIVE_PONG, |
Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 320 | LWS_CALLBACK_CLIENT_WRITEABLE, |
Andy Green | 9e4c2b6 | 2011-03-07 20:47:39 +0000 | [diff] [blame] | 321 | LWS_CALLBACK_SERVER_WRITEABLE, |
Andy Green | a2b0ab0 | 2010-11-11 12:28:29 +0000 | [diff] [blame] | 322 | LWS_CALLBACK_HTTP, |
kapejod | ce64fb0 | 2013-11-19 13:38:16 +0100 | [diff] [blame] | 323 | LWS_CALLBACK_HTTP_BODY, |
| 324 | LWS_CALLBACK_HTTP_BODY_COMPLETION, |
Andy Green | d280b6e | 2013-01-15 13:40:23 +0800 | [diff] [blame] | 325 | LWS_CALLBACK_HTTP_FILE_COMPLETION, |
Andy Green | 54cb346 | 2013-02-14 22:23:54 +0800 | [diff] [blame] | 326 | LWS_CALLBACK_HTTP_WRITEABLE, |
Andy Green | 0703409 | 2011-02-13 08:37:12 +0000 | [diff] [blame] | 327 | LWS_CALLBACK_FILTER_NETWORK_CONNECTION, |
Andy Green | 19895bc | 2013-11-09 11:59:56 +0800 | [diff] [blame] | 328 | LWS_CALLBACK_FILTER_HTTP_CONNECTION, |
Alexandre Erwin Ittner | d578f57 | 2014-02-06 23:15:51 -0200 | [diff] [blame] | 329 | LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED, |
Andy Green | c85619d | 2011-02-13 08:25:26 +0000 | [diff] [blame] | 330 | LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION, |
Andy Green | 0894bda | 2011-02-19 09:09:11 +0000 | [diff] [blame] | 331 | LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS, |
Andy Green | c6bf2c2 | 2011-02-20 11:10:47 +0000 | [diff] [blame] | 332 | LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS, |
Andy Green | 6901cb3 | 2011-02-21 08:06:47 +0000 | [diff] [blame] | 333 | LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION, |
Andy Green | 385e7ad | 2011-03-01 21:06:02 +0000 | [diff] [blame] | 334 | LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER, |
Andy Green | c511482 | 2011-03-06 10:29:35 +0000 | [diff] [blame] | 335 | LWS_CALLBACK_CONFIRM_EXTENSION_OKAY, |
Andy Green | c6517fa | 2011-03-06 13:15:29 +0000 | [diff] [blame] | 336 | LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED, |
Andy Green | a7109e6 | 2013-02-11 12:05:54 +0800 | [diff] [blame] | 337 | LWS_CALLBACK_PROTOCOL_INIT, |
| 338 | LWS_CALLBACK_PROTOCOL_DESTROY, |
Andy Green | 76b6ea1 | 2014-02-15 19:25:50 +0800 | [diff] [blame] | 339 | LWS_CALLBACK_WSI_CREATE, /* always protocol[0] */ |
| 340 | LWS_CALLBACK_WSI_DESTROY, /* always protocol[0] */ |
Andy Green | 3b3fa9e | 2013-12-25 16:34:37 +0800 | [diff] [blame] | 341 | LWS_CALLBACK_GET_THREAD_ID, |
| 342 | |
Andy Green | 3221f92 | 2011-02-12 13:14:11 +0000 | [diff] [blame] | 343 | /* external poll() management support */ |
| 344 | LWS_CALLBACK_ADD_POLL_FD, |
| 345 | LWS_CALLBACK_DEL_POLL_FD, |
Michael Haberler | b309305 | 2014-02-15 20:18:24 +0800 | [diff] [blame] | 346 | LWS_CALLBACK_CHANGE_MODE_POLL_FD, |
Andy Green | 7a13279 | 2013-12-18 09:48:26 +0800 | [diff] [blame] | 347 | LWS_CALLBACK_LOCK_POLL, |
| 348 | LWS_CALLBACK_UNLOCK_POLL, |
Andy Green | 09f0058 | 2014-02-15 16:49:41 +0800 | [diff] [blame] | 349 | |
Octav Zlatior | cf51896 | 2014-12-15 16:29:15 +0100 | [diff] [blame] | 350 | LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY, |
| 351 | |
Andy Green | 09f0058 | 2014-02-15 16:49:41 +0800 | [diff] [blame] | 352 | LWS_CALLBACK_USER = 1000, /* user code can use any including / above */ |
Andy Green | 5fd8a5e | 2010-10-31 11:57:17 +0000 | [diff] [blame] | 353 | }; |
| 354 | |
Michael Haberler | cb73306 | 2014-02-15 20:15:55 +0800 | [diff] [blame] | 355 | |
Andy Green | 3b19386 | 2015-11-02 13:13:44 +0800 | [diff] [blame] | 356 | #if defined(_WIN32) && (_WIN32_WINNT < 0x0600) |
| 357 | typedef SOCKET lws_sockfd_type; |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 358 | #define lws_sockfd_valid(sfd) (!!sfd) |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 359 | struct lws_pollfd { |
Andy Green | 3b19386 | 2015-11-02 13:13:44 +0800 | [diff] [blame] | 360 | lws_sockfd_type fd; |
Patrick Gansterer | 73882e4 | 2014-03-29 08:25:58 +0100 | [diff] [blame] | 361 | SHORT events; |
| 362 | SHORT revents; |
| 363 | }; |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 364 | WINSOCK_API_LINKAGE int WSAAPI WSAPoll(struct lws_pollfd fdArray[], ULONG fds, INT timeout); |
Patrick Gansterer | 73882e4 | 2014-03-29 08:25:58 +0100 | [diff] [blame] | 365 | #else |
Andy Green | 3b19386 | 2015-11-02 13:13:44 +0800 | [diff] [blame] | 366 | |
| 367 | #if defined(MBED_OPERATORS) |
Andy Green | 11f2734 | 2015-11-08 12:10:26 +0800 | [diff] [blame] | 368 | /* it's a class lws_conn * */ |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 369 | typedef void * lws_sockfd_type; |
| 370 | #define lws_sockfd_valid(sfd) (!!sfd) |
Andy Green | 3b19386 | 2015-11-02 13:13:44 +0800 | [diff] [blame] | 371 | struct pollfd { |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 372 | lws_sockfd_type fd; |
Andy Green | 3b19386 | 2015-11-02 13:13:44 +0800 | [diff] [blame] | 373 | short events; |
| 374 | short revents; |
| 375 | }; |
| 376 | #define POLLIN 0x0001 |
| 377 | #define POLLPRI 0x0002 |
| 378 | #define POLLOUT 0x0004 |
| 379 | #define POLLERR 0x0008 |
| 380 | #define POLLHUP 0x0010 |
| 381 | #define POLLNVAL 0x0020 |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 382 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 383 | struct lws; |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 384 | |
| 385 | void * mbed3_create_tcp_stream_socket(void); |
| 386 | void mbed3_delete_tcp_stream_socket(void *sockfd); |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 387 | void mbed3_tcp_stream_bind(void *sock, int port, struct lws *); |
| 388 | void mbed3_tcp_stream_accept(void *sock, struct lws *); |
Andy Green | 3b19386 | 2015-11-02 13:13:44 +0800 | [diff] [blame] | 389 | #else |
Andy Green | 11f2734 | 2015-11-08 12:10:26 +0800 | [diff] [blame] | 390 | typedef int lws_sockfd_type; |
Andy Green | 8c0d3c0 | 2015-11-02 20:34:12 +0800 | [diff] [blame] | 391 | #define lws_sockfd_valid(sfd) (sfd >= 0) |
Andy Green | 3b19386 | 2015-11-02 13:13:44 +0800 | [diff] [blame] | 392 | #endif |
| 393 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 394 | #define lws_pollfd pollfd |
Patrick Gansterer | 73882e4 | 2014-03-29 08:25:58 +0100 | [diff] [blame] | 395 | #endif |
Michael Haberler | cb73306 | 2014-02-15 20:15:55 +0800 | [diff] [blame] | 396 | |
Andy Green | 3b19386 | 2015-11-02 13:13:44 +0800 | [diff] [blame] | 397 | // argument structure for all external poll related calls |
| 398 | // passed in via 'in' |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 399 | struct lws_pollargs { |
Andy Green | 3b19386 | 2015-11-02 13:13:44 +0800 | [diff] [blame] | 400 | lws_sockfd_type fd; // applicable file descriptor |
| 401 | int events; // the new event mask |
| 402 | int prev_events; // the previous event mask |
| 403 | }; |
| 404 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 405 | enum lws_extension_callback_reasons { |
Andy Green | a41314f | 2011-05-23 10:00:03 +0100 | [diff] [blame] | 406 | LWS_EXT_CALLBACK_SERVER_CONTEXT_CONSTRUCT, |
| 407 | LWS_EXT_CALLBACK_CLIENT_CONTEXT_CONSTRUCT, |
| 408 | LWS_EXT_CALLBACK_SERVER_CONTEXT_DESTRUCT, |
| 409 | LWS_EXT_CALLBACK_CLIENT_CONTEXT_DESTRUCT, |
Andy Green | c511482 | 2011-03-06 10:29:35 +0000 | [diff] [blame] | 410 | LWS_EXT_CALLBACK_CONSTRUCT, |
Andy Green | 2366b1c | 2011-03-06 13:15:31 +0000 | [diff] [blame] | 411 | LWS_EXT_CALLBACK_CLIENT_CONSTRUCT, |
Andy Green | 68b4504 | 2011-05-25 21:41:57 +0100 | [diff] [blame] | 412 | LWS_EXT_CALLBACK_CHECK_OK_TO_REALLY_CLOSE, |
Andy Green | 0922650 | 2011-05-28 10:19:19 +0100 | [diff] [blame] | 413 | LWS_EXT_CALLBACK_CHECK_OK_TO_PROPOSE_EXTENSION, |
Andy Green | c511482 | 2011-03-06 10:29:35 +0000 | [diff] [blame] | 414 | LWS_EXT_CALLBACK_DESTROY, |
Andy Green | a41314f | 2011-05-23 10:00:03 +0100 | [diff] [blame] | 415 | LWS_EXT_CALLBACK_DESTROY_ANY_WSI_CLOSING, |
| 416 | LWS_EXT_CALLBACK_ANY_WSI_ESTABLISHED, |
Andy Green | 98a717c | 2011-03-06 13:14:15 +0000 | [diff] [blame] | 417 | LWS_EXT_CALLBACK_PACKET_RX_PREPARSE, |
Andy Green | 3b84c00 | 2011-03-06 13:14:42 +0000 | [diff] [blame] | 418 | LWS_EXT_CALLBACK_PACKET_TX_PRESEND, |
Andy Green | a41314f | 2011-05-23 10:00:03 +0100 | [diff] [blame] | 419 | LWS_EXT_CALLBACK_PACKET_TX_DO_SEND, |
| 420 | LWS_EXT_CALLBACK_HANDSHAKE_REPLY_TX, |
Andy Green | c44159f | 2011-03-07 07:08:18 +0000 | [diff] [blame] | 421 | LWS_EXT_CALLBACK_FLUSH_PENDING_TX, |
Andy Green | a41314f | 2011-05-23 10:00:03 +0100 | [diff] [blame] | 422 | LWS_EXT_CALLBACK_EXTENDED_PAYLOAD_RX, |
| 423 | LWS_EXT_CALLBACK_CAN_PROXY_CLIENT_CONNECTION, |
| 424 | LWS_EXT_CALLBACK_1HZ, |
| 425 | LWS_EXT_CALLBACK_REQUEST_ON_WRITEABLE, |
| 426 | LWS_EXT_CALLBACK_IS_WRITEABLE, |
David Galeano | e2cf992 | 2013-01-09 18:06:55 +0800 | [diff] [blame] | 427 | LWS_EXT_CALLBACK_PAYLOAD_TX, |
| 428 | LWS_EXT_CALLBACK_PAYLOAD_RX, |
Andy Green | c511482 | 2011-03-06 10:29:35 +0000 | [diff] [blame] | 429 | }; |
| 430 | |
Andy Green | 6230476 | 2015-12-04 08:43:54 +0800 | [diff] [blame] | 431 | enum lws_write_protocol { |
Andy Green | 5fd8a5e | 2010-10-31 11:57:17 +0000 | [diff] [blame] | 432 | LWS_WRITE_TEXT, |
| 433 | LWS_WRITE_BINARY, |
Andy Green | 5d9d94b | 2011-03-07 20:47:41 +0000 | [diff] [blame] | 434 | LWS_WRITE_CONTINUATION, |
Andy Green | 38e57bb | 2011-01-19 12:20:27 +0000 | [diff] [blame] | 435 | LWS_WRITE_HTTP, |
| 436 | |
Andy Green | 5e1fa17 | 2011-02-10 09:07:05 +0000 | [diff] [blame] | 437 | /* special 04+ opcodes */ |
Andy Green | 38e57bb | 2011-01-19 12:20:27 +0000 | [diff] [blame] | 438 | |
| 439 | LWS_WRITE_CLOSE, |
| 440 | LWS_WRITE_PING, |
Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 441 | LWS_WRITE_PONG, |
| 442 | |
Andy Green | 200f385 | 2014-10-18 12:23:05 +0800 | [diff] [blame] | 443 | /* Same as write_http but we know this write ends the transaction */ |
| 444 | LWS_WRITE_HTTP_FINAL, |
| 445 | |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 446 | /* HTTP2 */ |
| 447 | |
| 448 | LWS_WRITE_HTTP_HEADERS, |
| 449 | |
Andy Green | bd96d80 | 2011-01-30 08:24:31 +0000 | [diff] [blame] | 450 | /* flags */ |
| 451 | |
| 452 | LWS_WRITE_NO_FIN = 0x40, |
| 453 | /* |
| 454 | * client packet payload goes out on wire unmunged |
| 455 | * only useful for security tests since normal servers cannot |
| 456 | * decode the content if used |
| 457 | */ |
| 458 | LWS_WRITE_CLIENT_IGNORE_XOR_MASK = 0x80 |
Andy Green | ff95d7a | 2010-10-28 22:36:01 +0100 | [diff] [blame] | 459 | }; |
| 460 | |
Andy Green | c85619d | 2011-02-13 08:25:26 +0000 | [diff] [blame] | 461 | /* |
| 462 | * you need these to look at headers that have been parsed if using the |
| 463 | * LWS_CALLBACK_FILTER_CONNECTION callback. If a header from the enum |
| 464 | * list below is absent, .token = NULL and token_len = 0. Otherwise .token |
| 465 | * points to .token_len chars containing that header content. |
| 466 | */ |
| 467 | |
| 468 | struct lws_tokens { |
| 469 | char *token; |
| 470 | int token_len; |
| 471 | }; |
| 472 | |
Andy Green | 1ee42a5 | 2014-02-23 14:38:59 +0800 | [diff] [blame] | 473 | /* |
| 474 | * don't forget to update test server header dump accordingly |
| 475 | * |
| 476 | * these have to be kept in sync with lextable.h / minilex.c |
| 477 | */ |
Andy Green | 9887bdb | 2014-09-30 08:23:06 +0800 | [diff] [blame] | 478 | |
Andy Green | c85619d | 2011-02-13 08:25:26 +0000 | [diff] [blame] | 479 | enum lws_token_indexes { |
| 480 | WSI_TOKEN_GET_URI, |
kapejod | ce64fb0 | 2013-11-19 13:38:16 +0100 | [diff] [blame] | 481 | WSI_TOKEN_POST_URI, |
Andrew Canaday | da55fb5 | 2014-07-05 10:04:19 +0800 | [diff] [blame] | 482 | WSI_TOKEN_OPTIONS_URI, |
Andy Green | c85619d | 2011-02-13 08:25:26 +0000 | [diff] [blame] | 483 | WSI_TOKEN_HOST, |
| 484 | WSI_TOKEN_CONNECTION, |
Andy Green | c85619d | 2011-02-13 08:25:26 +0000 | [diff] [blame] | 485 | WSI_TOKEN_UPGRADE, |
| 486 | WSI_TOKEN_ORIGIN, |
| 487 | WSI_TOKEN_DRAFT, |
| 488 | WSI_TOKEN_CHALLENGE, |
Andy Green | c85619d | 2011-02-13 08:25:26 +0000 | [diff] [blame] | 489 | WSI_TOKEN_EXTENSIONS, |
Andy Green | 1ee42a5 | 2014-02-23 14:38:59 +0800 | [diff] [blame] | 490 | WSI_TOKEN_KEY1, |
| 491 | WSI_TOKEN_KEY2, |
| 492 | WSI_TOKEN_PROTOCOL, |
Andy Green | c85619d | 2011-02-13 08:25:26 +0000 | [diff] [blame] | 493 | WSI_TOKEN_ACCEPT, |
| 494 | WSI_TOKEN_NONCE, |
| 495 | WSI_TOKEN_HTTP, |
Andy Green | 1ee42a5 | 2014-02-23 14:38:59 +0800 | [diff] [blame] | 496 | WSI_TOKEN_HTTP2_SETTINGS, |
Andy Green | cc13c6f | 2013-11-09 10:09:09 +0800 | [diff] [blame] | 497 | WSI_TOKEN_HTTP_ACCEPT, |
Andrew Canaday | 4220327 | 2014-06-28 20:19:57 -0400 | [diff] [blame] | 498 | WSI_TOKEN_HTTP_AC_REQUEST_HEADERS, |
Andy Green | cc13c6f | 2013-11-09 10:09:09 +0800 | [diff] [blame] | 499 | WSI_TOKEN_HTTP_IF_MODIFIED_SINCE, |
Andrew Canaday | 4220327 | 2014-06-28 20:19:57 -0400 | [diff] [blame] | 500 | WSI_TOKEN_HTTP_IF_NONE_MATCH, |
Andy Green | cc13c6f | 2013-11-09 10:09:09 +0800 | [diff] [blame] | 501 | WSI_TOKEN_HTTP_ACCEPT_ENCODING, |
| 502 | WSI_TOKEN_HTTP_ACCEPT_LANGUAGE, |
| 503 | WSI_TOKEN_HTTP_PRAGMA, |
| 504 | WSI_TOKEN_HTTP_CACHE_CONTROL, |
| 505 | WSI_TOKEN_HTTP_AUTHORIZATION, |
| 506 | WSI_TOKEN_HTTP_COOKIE, |
kapejod | ce64fb0 | 2013-11-19 13:38:16 +0100 | [diff] [blame] | 507 | WSI_TOKEN_HTTP_CONTENT_LENGTH, |
Andy Green | cc13c6f | 2013-11-09 10:09:09 +0800 | [diff] [blame] | 508 | WSI_TOKEN_HTTP_CONTENT_TYPE, |
| 509 | WSI_TOKEN_HTTP_DATE, |
| 510 | WSI_TOKEN_HTTP_RANGE, |
| 511 | WSI_TOKEN_HTTP_REFERER, |
Andy Green | 1ee42a5 | 2014-02-23 14:38:59 +0800 | [diff] [blame] | 512 | WSI_TOKEN_KEY, |
| 513 | WSI_TOKEN_VERSION, |
| 514 | WSI_TOKEN_SWORIGIN, |
Andy Green | cc13c6f | 2013-11-09 10:09:09 +0800 | [diff] [blame] | 515 | |
Andy Green | ecc2e72 | 2014-10-09 16:57:47 +0800 | [diff] [blame] | 516 | WSI_TOKEN_HTTP_COLON_AUTHORITY, |
| 517 | WSI_TOKEN_HTTP_COLON_METHOD, |
| 518 | WSI_TOKEN_HTTP_COLON_PATH, |
| 519 | WSI_TOKEN_HTTP_COLON_SCHEME, |
| 520 | WSI_TOKEN_HTTP_COLON_STATUS, |
| 521 | |
| 522 | WSI_TOKEN_HTTP_ACCEPT_CHARSET, |
| 523 | WSI_TOKEN_HTTP_ACCEPT_RANGES, |
| 524 | WSI_TOKEN_HTTP_ACCESS_CONTROL_ALLOW_ORIGIN, |
| 525 | WSI_TOKEN_HTTP_AGE, |
| 526 | WSI_TOKEN_HTTP_ALLOW, |
| 527 | WSI_TOKEN_HTTP_CONTENT_DISPOSITION, |
| 528 | WSI_TOKEN_HTTP_CONTENT_ENCODING, |
| 529 | WSI_TOKEN_HTTP_CONTENT_LANGUAGE, |
| 530 | WSI_TOKEN_HTTP_CONTENT_LOCATION, |
| 531 | WSI_TOKEN_HTTP_CONTENT_RANGE, |
| 532 | WSI_TOKEN_HTTP_ETAG, |
| 533 | WSI_TOKEN_HTTP_EXPECT, |
| 534 | WSI_TOKEN_HTTP_EXPIRES, |
| 535 | WSI_TOKEN_HTTP_FROM, |
| 536 | WSI_TOKEN_HTTP_IF_MATCH, |
| 537 | WSI_TOKEN_HTTP_IF_RANGE, |
| 538 | WSI_TOKEN_HTTP_IF_UNMODIFIED_SINCE, |
| 539 | WSI_TOKEN_HTTP_LAST_MODIFIED, |
| 540 | WSI_TOKEN_HTTP_LINK, |
| 541 | WSI_TOKEN_HTTP_LOCATION, |
| 542 | WSI_TOKEN_HTTP_MAX_FORWARDS, |
| 543 | WSI_TOKEN_HTTP_PROXY_AUTHENTICATE, |
| 544 | WSI_TOKEN_HTTP_PROXY_AUTHORIZATION, |
| 545 | WSI_TOKEN_HTTP_REFRESH, |
| 546 | WSI_TOKEN_HTTP_RETRY_AFTER, |
| 547 | WSI_TOKEN_HTTP_SERVER, |
| 548 | WSI_TOKEN_HTTP_SET_COOKIE, |
| 549 | WSI_TOKEN_HTTP_STRICT_TRANSPORT_SECURITY, |
| 550 | WSI_TOKEN_HTTP_TRANSFER_ENCODING, |
| 551 | WSI_TOKEN_HTTP_USER_AGENT, |
| 552 | WSI_TOKEN_HTTP_VARY, |
| 553 | WSI_TOKEN_HTTP_VIA, |
| 554 | WSI_TOKEN_HTTP_WWW_AUTHENTICATE, |
=?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= | fdde0f0 | 2014-12-14 12:13:43 +0800 | [diff] [blame] | 555 | WSI_TOKEN_PROXY, |
Andy Green | 917f43a | 2014-10-12 14:31:47 +0800 | [diff] [blame] | 556 | |
Quinlan Pfiffer | 49f72aa | 2015-01-10 19:01:52 -0800 | [diff] [blame] | 557 | WSI_TOKEN_PATCH_URI, |
| 558 | WSI_TOKEN_PUT_URI, |
| 559 | WSI_TOKEN_DELETE_URI, |
| 560 | |
Andy Green | 917f43a | 2014-10-12 14:31:47 +0800 | [diff] [blame] | 561 | WSI_TOKEN_HTTP_URI_ARGS, |
Quinlan Pfiffer | 49f72aa | 2015-01-10 19:01:52 -0800 | [diff] [blame] | 562 | |
Andy Green | 917f43a | 2014-10-12 14:31:47 +0800 | [diff] [blame] | 563 | /* use token storage to stash these */ |
| 564 | |
| 565 | _WSI_TOKEN_CLIENT_SENT_PROTOCOLS, |
| 566 | _WSI_TOKEN_CLIENT_PEER_ADDRESS, |
| 567 | _WSI_TOKEN_CLIENT_URI, |
| 568 | _WSI_TOKEN_CLIENT_HOST, |
| 569 | _WSI_TOKEN_CLIENT_ORIGIN, |
Andy Green | ecc2e72 | 2014-10-09 16:57:47 +0800 | [diff] [blame] | 570 | |
Andy Green | c85619d | 2011-02-13 08:25:26 +0000 | [diff] [blame] | 571 | /* always last real token index*/ |
| 572 | WSI_TOKEN_COUNT, |
| 573 | /* parser state additions */ |
| 574 | WSI_TOKEN_NAME_PART, |
| 575 | WSI_TOKEN_SKIPPING, |
| 576 | WSI_TOKEN_SKIPPING_SAW_CR, |
Andy Green | a41314f | 2011-05-23 10:00:03 +0100 | [diff] [blame] | 577 | WSI_PARSING_COMPLETE, |
| 578 | WSI_INIT_TOKEN_MUXURL, |
Andy Green | c85619d | 2011-02-13 08:25:26 +0000 | [diff] [blame] | 579 | }; |
| 580 | |
Andrew Canaday | 74b4a65 | 2014-06-29 00:25:19 -0400 | [diff] [blame] | 581 | struct lws_token_limits { |
| 582 | unsigned short token_limit[WSI_TOKEN_COUNT]; |
| 583 | }; |
| 584 | |
Andy Green | 687b018 | 2011-02-26 11:04:01 +0000 | [diff] [blame] | 585 | /* |
David Galeano | 2915a80 | 2013-01-09 15:26:08 +0800 | [diff] [blame] | 586 | * From RFC 6455 |
Andy Green | 687b018 | 2011-02-26 11:04:01 +0000 | [diff] [blame] | 587 | 1000 |
| 588 | |
David Galeano | 2915a80 | 2013-01-09 15:26:08 +0800 | [diff] [blame] | 589 | 1000 indicates a normal closure, meaning that the purpose for |
| 590 | which the connection was established has been fulfilled. |
Andy Green | 687b018 | 2011-02-26 11:04:01 +0000 | [diff] [blame] | 591 | |
| 592 | 1001 |
| 593 | |
| 594 | 1001 indicates that an endpoint is "going away", such as a server |
David Galeano | 2915a80 | 2013-01-09 15:26:08 +0800 | [diff] [blame] | 595 | going down or a browser having navigated away from a page. |
Andy Green | 687b018 | 2011-02-26 11:04:01 +0000 | [diff] [blame] | 596 | |
| 597 | 1002 |
| 598 | |
| 599 | 1002 indicates that an endpoint is terminating the connection due |
| 600 | to a protocol error. |
| 601 | |
| 602 | 1003 |
| 603 | |
| 604 | 1003 indicates that an endpoint is terminating the connection |
David Galeano | 2915a80 | 2013-01-09 15:26:08 +0800 | [diff] [blame] | 605 | because it has received a type of data it cannot accept (e.g., an |
| 606 | endpoint that understands only text data MAY send this if it |
| 607 | receives a binary message). |
Andy Green | 687b018 | 2011-02-26 11:04:01 +0000 | [diff] [blame] | 608 | |
| 609 | 1004 |
| 610 | |
David Galeano | 2915a80 | 2013-01-09 15:26:08 +0800 | [diff] [blame] | 611 | Reserved. The specific meaning might be defined in the future. |
| 612 | |
| 613 | 1005 |
| 614 | |
| 615 | 1005 is a reserved value and MUST NOT be set as a status code in a |
| 616 | Close control frame by an endpoint. It is designated for use in |
| 617 | applications expecting a status code to indicate that no status |
| 618 | code was actually present. |
| 619 | |
| 620 | 1006 |
| 621 | |
| 622 | 1006 is a reserved value and MUST NOT be set as a status code in a |
| 623 | Close control frame by an endpoint. It is designated for use in |
| 624 | applications expecting a status code to indicate that the |
| 625 | connection was closed abnormally, e.g., without sending or |
| 626 | receiving a Close control frame. |
| 627 | |
| 628 | 1007 |
| 629 | |
| 630 | 1007 indicates that an endpoint is terminating the connection |
| 631 | because it has received data within a message that was not |
| 632 | consistent with the type of the message (e.g., non-UTF-8 [RFC3629] |
| 633 | data within a text message). |
| 634 | |
| 635 | 1008 |
| 636 | |
| 637 | 1008 indicates that an endpoint is terminating the connection |
| 638 | because it has received a message that violates its policy. This |
| 639 | is a generic status code that can be returned when there is no |
| 640 | other more suitable status code (e.g., 1003 or 1009) or if there |
| 641 | is a need to hide specific details about the policy. |
| 642 | |
| 643 | 1009 |
| 644 | |
| 645 | 1009 indicates that an endpoint is terminating the connection |
| 646 | because it has received a message that is too big for it to |
| 647 | process. |
| 648 | |
| 649 | 1010 |
| 650 | |
| 651 | 1010 indicates that an endpoint (client) is terminating the |
| 652 | connection because it has expected the server to negotiate one or |
| 653 | more extension, but the server didn't return them in the response |
| 654 | message of the WebSocket handshake. The list of extensions that |
| 655 | are needed SHOULD appear in the /reason/ part of the Close frame. |
| 656 | Note that this status code is not used by the server, because it |
| 657 | can fail the WebSocket handshake instead. |
| 658 | |
| 659 | 1011 |
| 660 | |
| 661 | 1011 indicates that a server is terminating the connection because |
| 662 | it encountered an unexpected condition that prevented it from |
| 663 | fulfilling the request. |
| 664 | |
| 665 | 1015 |
| 666 | |
| 667 | 1015 is a reserved value and MUST NOT be set as a status code in a |
| 668 | Close control frame by an endpoint. It is designated for use in |
| 669 | applications expecting a status code to indicate that the |
| 670 | connection was closed due to a failure to perform a TLS handshake |
| 671 | (e.g., the server certificate can't be verified). |
Andy Green | 687b018 | 2011-02-26 11:04:01 +0000 | [diff] [blame] | 672 | */ |
| 673 | |
| 674 | enum lws_close_status { |
| 675 | LWS_CLOSE_STATUS_NOSTATUS = 0, |
| 676 | LWS_CLOSE_STATUS_NORMAL = 1000, |
| 677 | LWS_CLOSE_STATUS_GOINGAWAY = 1001, |
| 678 | LWS_CLOSE_STATUS_PROTOCOL_ERR = 1002, |
| 679 | LWS_CLOSE_STATUS_UNACCEPTABLE_OPCODE = 1003, |
David Galeano | 2915a80 | 2013-01-09 15:26:08 +0800 | [diff] [blame] | 680 | LWS_CLOSE_STATUS_RESERVED = 1004, |
| 681 | LWS_CLOSE_STATUS_NO_STATUS = 1005, |
| 682 | LWS_CLOSE_STATUS_ABNORMAL_CLOSE = 1006, |
| 683 | LWS_CLOSE_STATUS_INVALID_PAYLOAD = 1007, |
| 684 | LWS_CLOSE_STATUS_POLICY_VIOLATION = 1008, |
| 685 | LWS_CLOSE_STATUS_MESSAGE_TOO_LARGE = 1009, |
| 686 | LWS_CLOSE_STATUS_EXTENSION_REQUIRED = 1010, |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 687 | LWS_CLOSE_STATUS_UNEXPECTED_CONDITION = 1011, |
| 688 | LWS_CLOSE_STATUS_TLS_FAILURE = 1015, |
Andy Green | 8ec7802 | 2015-03-25 01:53:58 +0800 | [diff] [blame] | 689 | |
| 690 | LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY = 9999, |
Andy Green | 687b018 | 2011-02-26 11:04:01 +0000 | [diff] [blame] | 691 | }; |
| 692 | |
Andy Green | 4e7a133 | 2013-11-11 07:30:33 +0800 | [diff] [blame] | 693 | enum http_status { |
kapejod | ce64fb0 | 2013-11-19 13:38:16 +0100 | [diff] [blame] | 694 | HTTP_STATUS_OK = 200, |
Andrew Canaday | b57e7a0 | 2014-06-29 19:14:43 -0400 | [diff] [blame] | 695 | HTTP_STATUS_NO_CONTENT = 204, |
kapejod | ce64fb0 | 2013-11-19 13:38:16 +0100 | [diff] [blame] | 696 | |
Andy Green | 4e7a133 | 2013-11-11 07:30:33 +0800 | [diff] [blame] | 697 | HTTP_STATUS_BAD_REQUEST = 400, |
| 698 | HTTP_STATUS_UNAUTHORIZED, |
| 699 | HTTP_STATUS_PAYMENT_REQUIRED, |
| 700 | HTTP_STATUS_FORBIDDEN, |
| 701 | HTTP_STATUS_NOT_FOUND, |
| 702 | HTTP_STATUS_METHOD_NOT_ALLOWED, |
| 703 | HTTP_STATUS_NOT_ACCEPTABLE, |
| 704 | HTTP_STATUS_PROXY_AUTH_REQUIRED, |
| 705 | HTTP_STATUS_REQUEST_TIMEOUT, |
| 706 | HTTP_STATUS_CONFLICT, |
| 707 | HTTP_STATUS_GONE, |
| 708 | HTTP_STATUS_LENGTH_REQUIRED, |
| 709 | HTTP_STATUS_PRECONDITION_FAILED, |
| 710 | HTTP_STATUS_REQ_ENTITY_TOO_LARGE, |
| 711 | HTTP_STATUS_REQ_URI_TOO_LONG, |
| 712 | HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE, |
| 713 | HTTP_STATUS_REQ_RANGE_NOT_SATISFIABLE, |
| 714 | HTTP_STATUS_EXPECTATION_FAILED, |
| 715 | |
| 716 | HTTP_STATUS_INTERNAL_SERVER_ERROR = 500, |
| 717 | HTTP_STATUS_NOT_IMPLEMENTED, |
| 718 | HTTP_STATUS_BAD_GATEWAY, |
| 719 | HTTP_STATUS_SERVICE_UNAVAILABLE, |
| 720 | HTTP_STATUS_GATEWAY_TIMEOUT, |
| 721 | HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED, |
| 722 | }; |
| 723 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 724 | struct lws; |
| 725 | struct lws_context; |
Andy Green | 3182ece | 2013-01-20 17:08:31 +0800 | [diff] [blame] | 726 | /* needed even with extensions disabled for create context */ |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 727 | struct lws_extension; |
Andy Green | ff95d7a | 2010-10-28 22:36:01 +0100 | [diff] [blame] | 728 | |
Andy Green | 8f037e4 | 2010-12-19 22:13:26 +0000 | [diff] [blame] | 729 | /** |
David Brooks | 6c6a3d3 | 2012-04-20 12:13:50 +0800 | [diff] [blame] | 730 | * callback_function() - User server actions |
Andy Green | 32375b7 | 2011-02-19 08:32:53 +0000 | [diff] [blame] | 731 | * @context: Websockets context |
Andy Green | 8f037e4 | 2010-12-19 22:13:26 +0000 | [diff] [blame] | 732 | * @wsi: Opaque websocket instance pointer |
| 733 | * @reason: The reason for the call |
| 734 | * @user: Pointer to per-session user data allocated by library |
| 735 | * @in: Pointer used for some callback reasons |
| 736 | * @len: Length set for some callback reasons |
| 737 | * |
| 738 | * This callback is the way the user controls what is served. All the |
| 739 | * protocol detail is hidden and handled by the library. |
Andy Green | 6964bb5 | 2011-01-23 16:50:33 +0000 | [diff] [blame] | 740 | * |
Andy Green | 8f037e4 | 2010-12-19 22:13:26 +0000 | [diff] [blame] | 741 | * For each connection / session there is user data allocated that is |
| 742 | * pointed to by "user". You set the size of this user data area when |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 743 | * the library is initialized with lws_create_server. |
Andy Green | 6964bb5 | 2011-01-23 16:50:33 +0000 | [diff] [blame] | 744 | * |
Andy Green | 8f037e4 | 2010-12-19 22:13:26 +0000 | [diff] [blame] | 745 | * You get an opportunity to initialize user data when called back with |
| 746 | * LWS_CALLBACK_ESTABLISHED reason. |
| 747 | * |
Andy Green | 2b57a34 | 2013-02-06 15:15:25 +0900 | [diff] [blame] | 748 | * LWS_CALLBACK_ESTABLISHED: after the server completes a handshake with |
Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 749 | * an incoming client |
| 750 | * |
David Brooks | 80a4497 | 2012-04-20 12:18:47 +0800 | [diff] [blame] | 751 | * LWS_CALLBACK_CLIENT_CONNECTION_ERROR: the request client connection has |
MGadkari | 020c53c | 2015-08-21 16:15:36 +0530 | [diff] [blame] | 752 | * been unable to complete a handshake with the remote server. If |
| 753 | * in is non-NULL, you can find an error string of length len where |
| 754 | * it points to. |
David Brooks | 80a4497 | 2012-04-20 12:18:47 +0800 | [diff] [blame] | 755 | * |
Andy Green | 2b57a34 | 2013-02-06 15:15:25 +0900 | [diff] [blame] | 756 | * LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH: this is the last chance for the |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 757 | * client user code to examine the http headers |
| 758 | * and decide to reject the connection. If the |
| 759 | * content in the headers is interesting to the |
| 760 | * client (url, etc) it needs to copy it out at |
| 761 | * this point since it will be destroyed before |
| 762 | * the CLIENT_ESTABLISHED call |
Andy Green | 2b57a34 | 2013-02-06 15:15:25 +0900 | [diff] [blame] | 763 | * |
David Brooks | 80a4497 | 2012-04-20 12:18:47 +0800 | [diff] [blame] | 764 | * LWS_CALLBACK_CLIENT_ESTABLISHED: after your client connection completed |
Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 765 | * a handshake with the remote server |
Andy Green | 8f037e4 | 2010-12-19 22:13:26 +0000 | [diff] [blame] | 766 | * |
| 767 | * LWS_CALLBACK_CLOSED: when the websocket session ends |
| 768 | * |
Andy Green | 0c9563b | 2013-06-10 22:54:40 +0800 | [diff] [blame] | 769 | * LWS_CALLBACK_CLOSED_HTTP: when a HTTP (non-websocket) session ends |
| 770 | * |
Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 771 | * LWS_CALLBACK_RECEIVE: data has appeared for this server endpoint from a |
| 772 | * remote client, it can be found at *in and is |
| 773 | * len bytes long |
| 774 | * |
Andy Green | a6cbece | 2011-01-27 20:06:03 +0000 | [diff] [blame] | 775 | * LWS_CALLBACK_CLIENT_RECEIVE_PONG: if you elected to see PONG packets, |
| 776 | * they appear with this callback reason. PONG |
| 777 | * packets only exist in 04+ protocol |
| 778 | * |
Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 779 | * LWS_CALLBACK_CLIENT_RECEIVE: data has appeared from the server for the |
| 780 | * client connection, it can be found at *in and |
| 781 | * is len bytes long |
Andy Green | 8f037e4 | 2010-12-19 22:13:26 +0000 | [diff] [blame] | 782 | * |
Andy Green | 6964bb5 | 2011-01-23 16:50:33 +0000 | [diff] [blame] | 783 | * LWS_CALLBACK_HTTP: an http request has come from a client that is not |
Andy Green | 8f037e4 | 2010-12-19 22:13:26 +0000 | [diff] [blame] | 784 | * asking to upgrade the connection to a websocket |
| 785 | * one. This is a chance to serve http content, |
| 786 | * for example, to send a script to the client |
| 787 | * which will then open the websockets connection. |
Andy Green | 6964bb5 | 2011-01-23 16:50:33 +0000 | [diff] [blame] | 788 | * @in points to the URI path requested and |
Andy Green | 6230476 | 2015-12-04 08:43:54 +0800 | [diff] [blame] | 789 | * lws_serve_http_file() makes it very |
Andy Green | 8f037e4 | 2010-12-19 22:13:26 +0000 | [diff] [blame] | 790 | * simple to send back a file to the client. |
Andy Green | 24b588b | 2013-01-13 09:53:18 +0800 | [diff] [blame] | 791 | * Normally after sending the file you are done |
| 792 | * with the http connection, since the rest of the |
| 793 | * activity will come by websockets from the script |
| 794 | * that was delivered by http, so you will want to |
| 795 | * return 1; to close and free up the connection. |
| 796 | * That's important because it uses a slot in the |
| 797 | * total number of client connections allowed set |
| 798 | * by MAX_CLIENTS. |
Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 799 | * |
kapejod | ce64fb0 | 2013-11-19 13:38:16 +0100 | [diff] [blame] | 800 | * LWS_CALLBACK_HTTP_BODY: the next @len bytes data from the http |
| 801 | * request body HTTP connection is now available in @in. |
| 802 | * |
| 803 | * LWS_CALLBACK_HTTP_BODY_COMPLETION: the expected amount of http request |
| 804 | * body has been delivered |
| 805 | * |
Andy Green | 54cb346 | 2013-02-14 22:23:54 +0800 | [diff] [blame] | 806 | * LWS_CALLBACK_HTTP_WRITEABLE: you can write more down the http protocol |
| 807 | * link now. |
| 808 | * |
Andy Green | d280b6e | 2013-01-15 13:40:23 +0800 | [diff] [blame] | 809 | * LWS_CALLBACK_HTTP_FILE_COMPLETION: a file requested to be send down |
| 810 | * http link has completed. |
| 811 | * |
Andy Green | 9e4c2b6 | 2011-03-07 20:47:39 +0000 | [diff] [blame] | 812 | * LWS_CALLBACK_CLIENT_WRITEABLE: |
| 813 | * LWS_CALLBACK_SERVER_WRITEABLE: If you call |
Andy Green | 6230476 | 2015-12-04 08:43:54 +0800 | [diff] [blame] | 814 | * lws_callback_on_writable() on a connection, you will |
Andy Green | 9e4c2b6 | 2011-03-07 20:47:39 +0000 | [diff] [blame] | 815 | * get one of these callbacks coming when the connection socket |
| 816 | * is able to accept another write packet without blocking. |
| 817 | * If it already was able to take another packet without blocking, |
| 818 | * you'll get this callback at the next call to the service loop |
| 819 | * function. Notice that CLIENTs get LWS_CALLBACK_CLIENT_WRITEABLE |
| 820 | * and servers get LWS_CALLBACK_SERVER_WRITEABLE. |
Andy Green | e7981dc | 2011-02-12 21:24:03 +0000 | [diff] [blame] | 821 | * |
Andy Green | 0703409 | 2011-02-13 08:37:12 +0000 | [diff] [blame] | 822 | * LWS_CALLBACK_FILTER_NETWORK_CONNECTION: called when a client connects to |
| 823 | * the server at network level; the connection is accepted but then |
| 824 | * passed to this callback to decide whether to hang up immediately |
Edwin van den Oetelaar | 8c8a8e1 | 2013-02-20 20:56:59 +0800 | [diff] [blame] | 825 | * or not, based on the client IP. @in contains the connection |
Alexandre Erwin Ittner | d578f57 | 2014-02-06 23:15:51 -0200 | [diff] [blame] | 826 | * socket's descriptor. Since the client connection information is |
| 827 | * not available yet, @wsi still pointing to the main server socket. |
| 828 | * Return non-zero to terminate the connection before sending or |
| 829 | * receiving anything. Because this happens immediately after the |
| 830 | * network connection from the client, there's no websocket protocol |
| 831 | * selected yet so this callback is issued only to protocol 0. |
Andy Green | 19895bc | 2013-11-09 11:59:56 +0800 | [diff] [blame] | 832 | * |
Alexandre Erwin Ittner | d578f57 | 2014-02-06 23:15:51 -0200 | [diff] [blame] | 833 | * LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED: A new client just had |
| 834 | * been connected, accepted, and instantiated into the pool. This |
| 835 | * callback allows setting any relevant property to it. Because this |
| 836 | * happens immediately after the instantiation of a new client, |
| 837 | * there's no websocket protocol selected yet so this callback is |
| 838 | * issued only to protocol 0. Only @wsi is defined, pointing to the |
| 839 | * new client, and the return value is ignored. |
| 840 | * |
Andy Green | 19895bc | 2013-11-09 11:59:56 +0800 | [diff] [blame] | 841 | * LWS_CALLBACK_FILTER_HTTP_CONNECTION: called when the request has |
| 842 | * been received and parsed from the client, but the response is |
| 843 | * not sent yet. Return non-zero to disallow the connection. |
| 844 | * @user is a pointer to the connection user space allocation, |
| 845 | * @in is the URI, eg, "/" |
| 846 | * In your handler you can use the public APIs |
| 847 | * lws_hdr_total_length() / lws_hdr_copy() to access all of the |
| 848 | * headers using the header enums lws_token_indexes from |
| 849 | * libwebsockets.h to check for and read the supported header |
| 850 | * presence and content before deciding to allow the http |
| 851 | * connection to proceed or to kill the connection. |
Andy Green | 0703409 | 2011-02-13 08:37:12 +0000 | [diff] [blame] | 852 | * |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 853 | * LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION: called when the handshake has |
| 854 | * been received and parsed from the client, but the response is |
| 855 | * not sent yet. Return non-zero to disallow the connection. |
Andy Green | 96d48fd | 2013-09-18 08:32:55 +0800 | [diff] [blame] | 856 | * @user is a pointer to the connection user space allocation, |
| 857 | * @in is the requested protocol name |
| 858 | * In your handler you can use the public APIs |
| 859 | * lws_hdr_total_length() / lws_hdr_copy() to access all of the |
| 860 | * headers using the header enums lws_token_indexes from |
| 861 | * libwebsockets.h to check for and read the supported header |
| 862 | * presence and content before deciding to allow the handshake |
| 863 | * to proceed or to kill the connection. |
Andy Green | c85619d | 2011-02-13 08:25:26 +0000 | [diff] [blame] | 864 | * |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 865 | * LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS: if configured for |
| 866 | * including OpenSSL support, this callback allows your user code |
| 867 | * to perform extra SSL_CTX_load_verify_locations() or similar |
Andy Green | 0894bda | 2011-02-19 09:09:11 +0000 | [diff] [blame] | 868 | * calls to direct OpenSSL where to find certificates the client |
| 869 | * can use to confirm the remote server identity. @user is the |
| 870 | * OpenSSL SSL_CTX* |
Andy Green | c85619d | 2011-02-13 08:25:26 +0000 | [diff] [blame] | 871 | * |
Andy Green | c6bf2c2 | 2011-02-20 11:10:47 +0000 | [diff] [blame] | 872 | * LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS: if configured for |
| 873 | * including OpenSSL support, this callback allows your user code |
| 874 | * to load extra certifcates into the server which allow it to |
| 875 | * verify the validity of certificates returned by clients. @user |
| 876 | * is the server's OpenSSL SSL_CTX* |
| 877 | * |
Octav Zlatior | cf51896 | 2014-12-15 16:29:15 +0100 | [diff] [blame] | 878 | * LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY: if configured for |
| 879 | * including OpenSSL support but no private key file has been specified |
| 880 | * (ssl_private_key_filepath is NULL), this callback is called to |
| 881 | * allow the user to set the private key directly via libopenssl |
| 882 | * and perform further operations if required; this might be useful |
| 883 | * in situations where the private key is not directly accessible by |
| 884 | * the OS, for example if it is stored on a smartcard |
| 885 | * @user is the server's OpenSSL SSL_CTX* |
| 886 | * |
Andy Green | 6901cb3 | 2011-02-21 08:06:47 +0000 | [diff] [blame] | 887 | * LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION: if the |
| 888 | * libwebsockets context was created with the option |
| 889 | * LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT, then this |
| 890 | * callback is generated during OpenSSL verification of the cert |
| 891 | * sent from the client. It is sent to protocol[0] callback as |
| 892 | * no protocol has been negotiated on the connection yet. |
| 893 | * Notice that the libwebsockets context and wsi are both NULL |
| 894 | * during this callback. See |
| 895 | * http://www.openssl.org/docs/ssl/SSL_CTX_set_verify.html |
| 896 | * to understand more detail about the OpenSSL callback that |
| 897 | * generates this libwebsockets callback and the meanings of the |
| 898 | * arguments passed. In this callback, @user is the x509_ctx, |
| 899 | * @in is the ssl pointer and @len is preverify_ok |
| 900 | * Notice that this callback maintains libwebsocket return |
| 901 | * conventions, return 0 to mean the cert is OK or 1 to fail it. |
| 902 | * This also means that if you don't handle this callback then |
| 903 | * the default callback action of returning 0 allows the client |
| 904 | * certificates. |
| 905 | * |
Andy Green | 385e7ad | 2011-03-01 21:06:02 +0000 | [diff] [blame] | 906 | * LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: this callback happens |
| 907 | * when a client handshake is being compiled. @user is NULL, |
| 908 | * @in is a char **, it's pointing to a char * which holds the |
| 909 | * next location in the header buffer where you can add |
| 910 | * headers, and @len is the remaining space in the header buffer, |
| 911 | * which is typically some hundreds of bytes. So, to add a canned |
| 912 | * cookie, your handler code might look similar to: |
| 913 | * |
| 914 | * char **p = (char **)in; |
| 915 | * |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 916 | * if (len < 100) |
| 917 | * return 1; |
Andy Green | 385e7ad | 2011-03-01 21:06:02 +0000 | [diff] [blame] | 918 | * |
| 919 | * *p += sprintf(*p, "Cookie: a=b\x0d\x0a"); |
| 920 | * |
| 921 | * return 0; |
| 922 | * |
| 923 | * Notice if you add anything, you just have to take care about |
| 924 | * the CRLF on the line you added. Obviously this callback is |
| 925 | * optional, if you don't handle it everything is fine. |
| 926 | * |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 927 | * Notice the callback is coming to protocols[0] all the time, |
Andy Green | 385e7ad | 2011-03-01 21:06:02 +0000 | [diff] [blame] | 928 | * because there is no specific protocol handshook yet. |
| 929 | * |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 930 | * LWS_CALLBACK_CONFIRM_EXTENSION_OKAY: When the server handshake code |
Andy Green | c511482 | 2011-03-06 10:29:35 +0000 | [diff] [blame] | 931 | * sees that it does support a requested extension, before |
| 932 | * accepting the extension by additing to the list sent back to |
| 933 | * the client it gives this callback just to check that it's okay |
| 934 | * to use that extension. It calls back to the requested protocol |
| 935 | * and with @in being the extension name, @len is 0 and @user is |
| 936 | * valid. Note though at this time the ESTABLISHED callback hasn't |
| 937 | * happened yet so if you initialize @user content there, @user |
| 938 | * content during this callback might not be useful for anything. |
| 939 | * Notice this callback comes to protocols[0]. |
| 940 | * |
Andy Green | c6517fa | 2011-03-06 13:15:29 +0000 | [diff] [blame] | 941 | * LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED: When a client |
| 942 | * connection is being prepared to start a handshake to a server, |
| 943 | * each supported extension is checked with protocols[0] callback |
| 944 | * with this reason, giving the user code a chance to suppress the |
| 945 | * claim to support that extension by returning non-zero. If |
| 946 | * unhandled, by default 0 will be returned and the extension |
| 947 | * support included in the header to the server. Notice this |
| 948 | * callback comes to protocols[0]. |
| 949 | * |
Andy Green | a7109e6 | 2013-02-11 12:05:54 +0800 | [diff] [blame] | 950 | * LWS_CALLBACK_PROTOCOL_INIT: One-time call per protocol so it can |
| 951 | * do initial setup / allocations etc |
| 952 | * |
| 953 | * LWS_CALLBACK_PROTOCOL_DESTROY: One-time call per protocol indicating |
| 954 | * this protocol won't get used at all after this callback, the |
| 955 | * context is getting destroyed. Take the opportunity to |
| 956 | * deallocate everything that was allocated by the protocol. |
| 957 | * |
Andy Green | 76b6ea1 | 2014-02-15 19:25:50 +0800 | [diff] [blame] | 958 | * LWS_CALLBACK_WSI_CREATE: outermost (earliest) wsi create notification |
| 959 | * |
| 960 | * LWS_CALLBACK_WSI_DESTROY: outermost (latest) wsi destroy notification |
| 961 | * |
Michael Haberler | 8284cf1 | 2014-02-15 20:33:46 +0800 | [diff] [blame] | 962 | * The next five reasons are optional and only need taking care of if you |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 963 | * will be integrating libwebsockets sockets into an external polling |
| 964 | * array. |
| 965 | * |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 966 | * For these calls, @in points to a struct lws_pollargs that |
Michael Haberler | 8284cf1 | 2014-02-15 20:33:46 +0800 | [diff] [blame] | 967 | * contains @fd, @events and @prev_events members |
| 968 | * |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 969 | * LWS_CALLBACK_ADD_POLL_FD: libwebsocket deals with its poll() loop |
| 970 | * internally, but in the case you are integrating with another |
| 971 | * server you will need to have libwebsocket sockets share a |
| 972 | * polling array with the other server. This and the other |
| 973 | * POLL_FD related callbacks let you put your specialized |
| 974 | * poll array interface code in the callback for protocol 0, the |
| 975 | * first protocol you support, usually the HTTP protocol in the |
Michael Haberler | 8284cf1 | 2014-02-15 20:33:46 +0800 | [diff] [blame] | 976 | * serving case. |
| 977 | * This callback happens when a socket needs to be |
| 978 | * added to the polling loop: @in points to a struct |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 979 | * lws_pollargs; the @fd member of the struct is the file |
Michael Haberler | 8284cf1 | 2014-02-15 20:33:46 +0800 | [diff] [blame] | 980 | * descriptor, and @events contains the active events. |
| 981 | * |
| 982 | * If you are using the internal polling loop (the "service" |
| 983 | * callback), you can just ignore these callbacks. |
Andy Green | e7981dc | 2011-02-12 21:24:03 +0000 | [diff] [blame] | 984 | * |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 985 | * LWS_CALLBACK_DEL_POLL_FD: This callback happens when a socket descriptor |
Andy Green | 50097dd | 2013-02-15 22:36:30 +0800 | [diff] [blame] | 986 | * needs to be removed from an external polling array. @in is |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 987 | * again the struct lws_pollargs containing the @fd member |
Michael Haberler | 8284cf1 | 2014-02-15 20:33:46 +0800 | [diff] [blame] | 988 | * to be removed. If you are using the internal polling |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 989 | * loop, you can just ignore it. |
Andy Green | e7981dc | 2011-02-12 21:24:03 +0000 | [diff] [blame] | 990 | * |
Michael Haberler | 8284cf1 | 2014-02-15 20:33:46 +0800 | [diff] [blame] | 991 | * LWS_CALLBACK_CHANGE_MODE_POLL_FD: This callback happens when |
| 992 | * libwebsockets wants to modify the events for a connectiion. |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 993 | * @in is the struct lws_pollargs with the @fd to change. |
Michael Haberler | 8284cf1 | 2014-02-15 20:33:46 +0800 | [diff] [blame] | 994 | * The new event mask is in @events member and the old mask is in |
| 995 | * the @prev_events member. |
| 996 | * If you are using the internal polling loop, you can just ignore |
| 997 | * it. |
Andy Green | e7981dc | 2011-02-12 21:24:03 +0000 | [diff] [blame] | 998 | * |
Michael Haberler | 8284cf1 | 2014-02-15 20:33:46 +0800 | [diff] [blame] | 999 | * LWS_CALLBACK_LOCK_POLL: |
| 1000 | * LWS_CALLBACK_UNLOCK_POLL: These allow the external poll changes driven |
| 1001 | * by libwebsockets to participate in an external thread locking |
| 1002 | * scheme around the changes, so the whole thing is threadsafe. |
Andy Green | 5a3b1d3 | 2015-11-20 09:51:18 +0800 | [diff] [blame] | 1003 | * These are called around three activities in the library, |
| 1004 | * - inserting a new wsi in the wsi / fd table (len=1) |
| 1005 | * - deleting a wsi from the wsi / fd table (len=1) |
| 1006 | * - changing a wsi's POLLIN/OUT state (len=0) |
| 1007 | * Locking and unlocking external synchronization objects when |
| 1008 | * len == 1 allows external threads to be synchronized against |
| 1009 | * wsi lifecycle changes if it acquires the same lock for the |
| 1010 | * duration of wsi dereference from the other thread context. |
Andy Green | 8f037e4 | 2010-12-19 22:13:26 +0000 | [diff] [blame] | 1011 | */ |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1012 | LWS_VISIBLE LWS_EXTERN int callback(struct lws_context *context, |
| 1013 | struct lws *wsi, |
| 1014 | enum lws_callback_reasons reason, void *user, |
Andy Green | 8f037e4 | 2010-12-19 22:13:26 +0000 | [diff] [blame] | 1015 | void *in, size_t len); |
| 1016 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1017 | typedef int (callback_function)(struct lws_context *context, |
| 1018 | struct lws *wsi, |
| 1019 | enum lws_callback_reasons reason, void *user, |
David Brooks | 6c6a3d3 | 2012-04-20 12:13:50 +0800 | [diff] [blame] | 1020 | void *in, size_t len); |
| 1021 | |
Andy Green | 3182ece | 2013-01-20 17:08:31 +0800 | [diff] [blame] | 1022 | #ifndef LWS_NO_EXTENSIONS |
Andy Green | 57b4e9a | 2011-03-06 13:14:46 +0000 | [diff] [blame] | 1023 | /** |
David Brooks | 6c6a3d3 | 2012-04-20 12:13:50 +0800 | [diff] [blame] | 1024 | * extension_callback_function() - Hooks to allow extensions to operate |
Andy Green | 57b4e9a | 2011-03-06 13:14:46 +0000 | [diff] [blame] | 1025 | * @context: Websockets context |
Andy Green | 46c2ea0 | 2011-03-22 09:04:01 +0000 | [diff] [blame] | 1026 | * @ext: This extension |
Andy Green | 57b4e9a | 2011-03-06 13:14:46 +0000 | [diff] [blame] | 1027 | * @wsi: Opaque websocket instance pointer |
| 1028 | * @reason: The reason for the call |
| 1029 | * @user: Pointer to per-session user data allocated by library |
| 1030 | * @in: Pointer used for some callback reasons |
| 1031 | * @len: Length set for some callback reasons |
| 1032 | * |
| 1033 | * Each extension that is active on a particular connection receives |
| 1034 | * callbacks during the connection lifetime to allow the extension to |
| 1035 | * operate on websocket data and manage itself. |
| 1036 | * |
| 1037 | * Libwebsockets takes care of allocating and freeing "user" memory for |
| 1038 | * each active extension on each connection. That is what is pointed to |
| 1039 | * by the @user parameter. |
| 1040 | * |
| 1041 | * LWS_EXT_CALLBACK_CONSTRUCT: called when the server has decided to |
| 1042 | * select this extension from the list provided by the client, |
| 1043 | * just before the server will send back the handshake accepting |
| 1044 | * the connection with this extension active. This gives the |
| 1045 | * extension a chance to initialize its connection context found |
| 1046 | * in @user. |
| 1047 | * |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 1048 | * LWS_EXT_CALLBACK_CLIENT_CONSTRUCT: same as LWS_EXT_CALLBACK_CONSTRUCT |
Andy Green | 2366b1c | 2011-03-06 13:15:31 +0000 | [diff] [blame] | 1049 | * but called when client is instantiating this extension. Some |
| 1050 | * extensions will work the same on client and server side and then |
| 1051 | * you can just merge handlers for both CONSTRUCTS. |
| 1052 | * |
Andy Green | 57b4e9a | 2011-03-06 13:14:46 +0000 | [diff] [blame] | 1053 | * LWS_EXT_CALLBACK_DESTROY: called when the connection the extension was |
| 1054 | * being used on is about to be closed and deallocated. It's the |
| 1055 | * last chance for the extension to deallocate anything it has |
| 1056 | * allocated in the user data (pointed to by @user) before the |
Andy Green | 2366b1c | 2011-03-06 13:15:31 +0000 | [diff] [blame] | 1057 | * user data is deleted. This same callback is used whether you |
| 1058 | * are in client or server instantiation context. |
Andy Green | 57b4e9a | 2011-03-06 13:14:46 +0000 | [diff] [blame] | 1059 | * |
| 1060 | * LWS_EXT_CALLBACK_PACKET_RX_PREPARSE: when this extension was active on |
| 1061 | * a connection, and a packet of data arrived at the connection, |
| 1062 | * it is passed to this callback to give the extension a chance to |
| 1063 | * change the data, eg, decompress it. @user is pointing to the |
| 1064 | * extension's private connection context data, @in is pointing |
| 1065 | * to an lws_tokens struct, it consists of a char * pointer called |
| 1066 | * token, and an int called token_len. At entry, these are |
| 1067 | * set to point to the received buffer and set to the content |
| 1068 | * length. If the extension will grow the content, it should use |
| 1069 | * a new buffer allocated in its private user context data and |
| 1070 | * set the pointed-to lws_tokens members to point to its buffer. |
| 1071 | * |
| 1072 | * LWS_EXT_CALLBACK_PACKET_TX_PRESEND: this works the same way as |
| 1073 | * LWS_EXT_CALLBACK_PACKET_RX_PREPARSE above, except it gives the |
| 1074 | * extension a chance to change websocket data just before it will |
| 1075 | * be sent out. Using the same lws_token pointer scheme in @in, |
| 1076 | * the extension can change the buffer and the length to be |
| 1077 | * transmitted how it likes. Again if it wants to grow the |
| 1078 | * buffer safely, it should copy the data into its own buffer and |
| 1079 | * set the lws_tokens token pointer to it. |
| 1080 | */ |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1081 | LWS_VISIBLE LWS_EXTERN int extension_callback(struct lws_context *context, |
| 1082 | struct lws_extension *ext, |
| 1083 | struct lws *wsi, |
| 1084 | enum lws_extension_callback_reasons reason, |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 1085 | void *user, void *in, size_t len); |
Andy Green | 57b4e9a | 2011-03-06 13:14:46 +0000 | [diff] [blame] | 1086 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1087 | typedef int (extension_callback_function)(struct lws_context *context, |
| 1088 | struct lws_extension *ext, |
| 1089 | struct lws *wsi, |
| 1090 | enum lws_extension_callback_reasons reason, |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 1091 | void *user, void *in, size_t len); |
Andy Green | 3182ece | 2013-01-20 17:08:31 +0800 | [diff] [blame] | 1092 | #endif |
Andy Green | 57b4e9a | 2011-03-06 13:14:46 +0000 | [diff] [blame] | 1093 | |
Andy Green | 4f3943a | 2010-11-12 10:44:16 +0000 | [diff] [blame] | 1094 | /** |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1095 | * struct lws_protocols - List of protocols and handlers server |
Andy Green | 6964bb5 | 2011-01-23 16:50:33 +0000 | [diff] [blame] | 1096 | * supports. |
Andy Green | 4f3943a | 2010-11-12 10:44:16 +0000 | [diff] [blame] | 1097 | * @name: Protocol name that must match the one given in the client |
Andy Green | a40760a | 2014-08-07 16:52:15 +0800 | [diff] [blame] | 1098 | * Javascript new WebSocket(url, 'protocol') name. |
Andy Green | 4f3943a | 2010-11-12 10:44:16 +0000 | [diff] [blame] | 1099 | * @callback: The service callback used for this protocol. It allows the |
Andy Green | 6964bb5 | 2011-01-23 16:50:33 +0000 | [diff] [blame] | 1100 | * service action for an entire protocol to be encapsulated in |
| 1101 | * the protocol-specific callback |
Andy Green | 4f3943a | 2010-11-12 10:44:16 +0000 | [diff] [blame] | 1102 | * @per_session_data_size: Each new connection using this protocol gets |
Andy Green | 6964bb5 | 2011-01-23 16:50:33 +0000 | [diff] [blame] | 1103 | * this much memory allocated on connection establishment and |
| 1104 | * freed on connection takedown. A pointer to this per-connection |
| 1105 | * allocation is passed into the callback in the 'user' parameter |
Andy Green | 5449511 | 2013-02-06 21:10:16 +0900 | [diff] [blame] | 1106 | * @rx_buffer_size: if you want atomic frames delivered to the callback, you |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 1107 | * should set this to the size of the biggest legal frame that |
| 1108 | * you support. If the frame size is exceeded, there is no |
| 1109 | * error, but the buffer will spill to the user callback when |
| 1110 | * full, which you can detect by using |
Andy Green | 6230476 | 2015-12-04 08:43:54 +0800 | [diff] [blame] | 1111 | * lws_remaining_packet_payload(). Notice that you |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 1112 | * just talk about frame size here, the LWS_SEND_BUFFER_PRE_PADDING |
| 1113 | * and post-padding are automatically also allocated on top. |
Andy Green | eabed8d | 2014-08-11 12:11:36 +0800 | [diff] [blame] | 1114 | * @id: ignored by lws, but useful to contain user information bound |
| 1115 | * to the selected protocol. For example if this protocol was |
| 1116 | * called "myprotocol-v2", you might set id to 2, and the user |
| 1117 | * code that acts differently according to the version can do so by |
| 1118 | * switch (wsi->protocol->id), user code might use some bits as |
| 1119 | * capability flags based on selected protocol version, etc. |
Neal Horman | b399237 | 2014-12-10 18:59:04 -0600 | [diff] [blame] | 1120 | * @user: User provided context data at the protocol level. |
Andy Green | 6230476 | 2015-12-04 08:43:54 +0800 | [diff] [blame] | 1121 | * Accessible via lws_get_protocol(wsi)->user |
Neal Horman | b399237 | 2014-12-10 18:59:04 -0600 | [diff] [blame] | 1122 | * This should not be confused with wsi->user, it is not the same. |
| 1123 | * The library completely ignores any value in here. |
Andy Green | b45993c | 2010-12-18 15:13:50 +0000 | [diff] [blame] | 1124 | * @owning_server: the server init call fills in this opaque pointer when |
Andy Green | 6964bb5 | 2011-01-23 16:50:33 +0000 | [diff] [blame] | 1125 | * registering this protocol with the server. |
Andy Green | b45993c | 2010-12-18 15:13:50 +0000 | [diff] [blame] | 1126 | * @protocol_index: which protocol we are starting from zero |
Andy Green | e77ddd8 | 2010-11-13 10:03:47 +0000 | [diff] [blame] | 1127 | * |
Andy Green | 6964bb5 | 2011-01-23 16:50:33 +0000 | [diff] [blame] | 1128 | * This structure represents one protocol supported by the server. An |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1129 | * array of these structures is passed to lws_create_server() |
Andy Green | 6964bb5 | 2011-01-23 16:50:33 +0000 | [diff] [blame] | 1130 | * allows as many protocols as you like to be handled by one server. |
Andy Green | a40760a | 2014-08-07 16:52:15 +0800 | [diff] [blame] | 1131 | * |
| 1132 | * The first protocol given has its callback used for user callbacks when |
| 1133 | * there is no agreed protocol name, that's true during HTTP part of the |
| 1134 | * connection and true if the client did not send a Protocol: header. |
Andy Green | 4f3943a | 2010-11-12 10:44:16 +0000 | [diff] [blame] | 1135 | */ |
| 1136 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1137 | struct lws_protocols { |
Andy Green | 4f3943a | 2010-11-12 10:44:16 +0000 | [diff] [blame] | 1138 | const char *name; |
David Brooks | 6c6a3d3 | 2012-04-20 12:13:50 +0800 | [diff] [blame] | 1139 | callback_function *callback; |
Andy Green | 4f3943a | 2010-11-12 10:44:16 +0000 | [diff] [blame] | 1140 | size_t per_session_data_size; |
Andy Green | 5449511 | 2013-02-06 21:10:16 +0900 | [diff] [blame] | 1141 | size_t rx_buffer_size; |
Andy Green | eabed8d | 2014-08-11 12:11:36 +0800 | [diff] [blame] | 1142 | unsigned int id; |
Neal Horman | b399237 | 2014-12-10 18:59:04 -0600 | [diff] [blame] | 1143 | void *user; |
Andy Green | b45993c | 2010-12-18 15:13:50 +0000 | [diff] [blame] | 1144 | |
| 1145 | /* |
| 1146 | * below are filled in on server init and can be left uninitialized, |
| 1147 | * no need for user to use them directly either |
| 1148 | */ |
Andy Green | 6964bb5 | 2011-01-23 16:50:33 +0000 | [diff] [blame] | 1149 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1150 | struct lws_context *owning_server; |
Andy Green | b45993c | 2010-12-18 15:13:50 +0000 | [diff] [blame] | 1151 | int protocol_index; |
Andy Green | 4f3943a | 2010-11-12 10:44:16 +0000 | [diff] [blame] | 1152 | }; |
| 1153 | |
Andy Green | 3182ece | 2013-01-20 17:08:31 +0800 | [diff] [blame] | 1154 | #ifndef LWS_NO_EXTENSIONS |
Andy Green | d6e0911 | 2011-03-05 16:12:15 +0000 | [diff] [blame] | 1155 | /** |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1156 | * struct lws_extension - An extension we know how to cope with |
Andy Green | d6e0911 | 2011-03-05 16:12:15 +0000 | [diff] [blame] | 1157 | * |
| 1158 | * @name: Formal extension name, eg, "deflate-stream" |
| 1159 | * @callback: Service callback |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 1160 | * @per_session_data_size: Libwebsockets will auto-malloc this much |
| 1161 | * memory for the use of the extension, a pointer |
Andy Green | d6e0911 | 2011-03-05 16:12:15 +0000 | [diff] [blame] | 1162 | * to it comes in the @user callback parameter |
Peter Pentchev | c74964e | 2013-02-07 16:17:13 +0200 | [diff] [blame] | 1163 | * @per_context_private_data: Optional storage for this extension that |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 1164 | * is per-context, so it can track stuff across |
| 1165 | * all sessions, etc, if it wants |
Andy Green | d6e0911 | 2011-03-05 16:12:15 +0000 | [diff] [blame] | 1166 | */ |
| 1167 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1168 | struct lws_extension { |
Andy Green | d6e0911 | 2011-03-05 16:12:15 +0000 | [diff] [blame] | 1169 | const char *name; |
David Brooks | 6c6a3d3 | 2012-04-20 12:13:50 +0800 | [diff] [blame] | 1170 | extension_callback_function *callback; |
Andy Green | d6e0911 | 2011-03-05 16:12:15 +0000 | [diff] [blame] | 1171 | size_t per_session_data_size; |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 1172 | void *per_context_private_data; |
Andy Green | d6e0911 | 2011-03-05 16:12:15 +0000 | [diff] [blame] | 1173 | }; |
Andy Green | 3182ece | 2013-01-20 17:08:31 +0800 | [diff] [blame] | 1174 | #endif |
Andy Green | d6e0911 | 2011-03-05 16:12:15 +0000 | [diff] [blame] | 1175 | |
Andy Green | 1b26527 | 2013-02-09 14:01:09 +0800 | [diff] [blame] | 1176 | /** |
| 1177 | * struct lws_context_creation_info: parameters to create context with |
| 1178 | * |
Andy Green | 67f9459 | 2014-07-31 09:44:00 +0800 | [diff] [blame] | 1179 | * @port: Port to listen on... you can use CONTEXT_PORT_NO_LISTEN to |
| 1180 | * suppress listening on any port, that's what you want if you are |
| 1181 | * not running a websocket server at all but just using it as a |
| 1182 | * client |
Andy Green | 7a506ba | 2013-02-12 10:13:02 +0800 | [diff] [blame] | 1183 | * @iface: NULL to bind the listen socket to all interfaces, or the |
Andy Green | 1b26527 | 2013-02-09 14:01:09 +0800 | [diff] [blame] | 1184 | * interface name, eg, "eth2" |
| 1185 | * @protocols: Array of structures listing supported protocols and a protocol- |
| 1186 | * specific callback for each one. The list is ended with an |
| 1187 | * entry that has a NULL callback pointer. |
| 1188 | * It's not const because we write the owning_server member |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1189 | * @extensions: NULL or array of lws_extension structs listing the |
Andy Green | 1b26527 | 2013-02-09 14:01:09 +0800 | [diff] [blame] | 1190 | * extensions this context supports. If you configured with |
| 1191 | * --without-extensions, you should give NULL here. |
Andrew Canaday | 3d2ebf3 | 2014-06-29 00:30:45 -0400 | [diff] [blame] | 1192 | * @token_limits: NULL or struct lws_token_limits pointer which is initialized |
| 1193 | * with a token length limit for each possible WSI_TOKEN_*** |
Andy Green | 1b26527 | 2013-02-09 14:01:09 +0800 | [diff] [blame] | 1194 | * @ssl_cert_filepath: If libwebsockets was compiled to use ssl, and you want |
| 1195 | * to listen using SSL, set to the filepath to fetch the |
| 1196 | * server cert from, otherwise NULL for unencrypted |
Octav Zlatior | cf51896 | 2014-12-15 16:29:15 +0100 | [diff] [blame] | 1197 | * @ssl_private_key_filepath: filepath to private key if wanting SSL mode; |
| 1198 | * if this is set to NULL but sll_cert_filepath is set, the |
| 1199 | * OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY callback is called to allow |
| 1200 | * setting of the private key directly via openSSL library calls |
Andy Green | 1b26527 | 2013-02-09 14:01:09 +0800 | [diff] [blame] | 1201 | * @ssl_ca_filepath: CA certificate filepath or NULL |
Andy Green | 2672fb2 | 2013-02-22 09:54:35 +0800 | [diff] [blame] | 1202 | * @ssl_cipher_list: List of valid ciphers to use (eg, |
| 1203 | * "RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aNULL" |
| 1204 | * or you can leave it as NULL to get "DEFAULT" |
Andy Green | 6e40556 | 2015-11-08 10:15:01 +0800 | [diff] [blame] | 1205 | * @http_proxy_address: If non-NULL, attempts to proxy via the given address. |
| 1206 | * If proxy auth is required, use format |
| 1207 | * "username:password@server:port" |
Andy Green | ec86b4e | 2015-03-11 08:35:15 +0800 | [diff] [blame] | 1208 | * @http_proxy_port: If http_proxy_address was non-NULL, uses this port at the address |
Andy Green | 1b26527 | 2013-02-09 14:01:09 +0800 | [diff] [blame] | 1209 | * @gid: group id to change to after setting listen socket, or -1. |
| 1210 | * @uid: user id to change to after setting listen socket, or -1. |
| 1211 | * @options: 0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK |
| 1212 | * @user: optional user pointer that can be recovered via the context |
Andy Green | 6230476 | 2015-12-04 08:43:54 +0800 | [diff] [blame] | 1213 | * pointer using lws_context_user |
Andy Green | a690cd0 | 2013-02-09 12:25:31 +0800 | [diff] [blame] | 1214 | * @ka_time: 0 for no keepalive, otherwise apply this keepalive timeout to |
| 1215 | * all libwebsocket sockets, client or server |
| 1216 | * @ka_probes: if ka_time was nonzero, after the timeout expires how many |
| 1217 | * times to try to get a response from the peer before giving up |
| 1218 | * and killing the connection |
| 1219 | * @ka_interval: if ka_time was nonzero, how long to wait before each ka_probes |
| 1220 | * attempt |
joseph.urciuoli | 4d9c8fc | 2014-10-16 08:53:19 +0800 | [diff] [blame] | 1221 | * @provided_client_ssl_ctx: If non-null, swap out libwebsockets ssl |
| 1222 | * implementation for the one provided by provided_ssl_ctx. |
| 1223 | * Libwebsockets no longer is responsible for freeing the context |
| 1224 | * if this option is selected. |
Andy Green | 1b26527 | 2013-02-09 14:01:09 +0800 | [diff] [blame] | 1225 | */ |
| 1226 | |
| 1227 | struct lws_context_creation_info { |
| 1228 | int port; |
Joakim Soderberg | 63ff120 | 2013-02-11 17:52:23 +0100 | [diff] [blame] | 1229 | const char *iface; |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1230 | struct lws_protocols *protocols; |
| 1231 | struct lws_extension *extensions; |
Oleh | faeac3c | 2014-07-29 23:18:41 +0800 | [diff] [blame] | 1232 | struct lws_token_limits *token_limits; |
| 1233 | const char *ssl_private_key_password; |
Andy Green | 1b26527 | 2013-02-09 14:01:09 +0800 | [diff] [blame] | 1234 | const char *ssl_cert_filepath; |
| 1235 | const char *ssl_private_key_filepath; |
| 1236 | const char *ssl_ca_filepath; |
Andy Green | 2672fb2 | 2013-02-22 09:54:35 +0800 | [diff] [blame] | 1237 | const char *ssl_cipher_list; |
Patrick Gansterer | 148b945 | 2014-02-28 02:31:23 +0100 | [diff] [blame] | 1238 | const char *http_proxy_address; |
| 1239 | unsigned int http_proxy_port; |
Andy Green | 1b26527 | 2013-02-09 14:01:09 +0800 | [diff] [blame] | 1240 | int gid; |
| 1241 | int uid; |
| 1242 | unsigned int options; |
| 1243 | void *user; |
Andy Green | a690cd0 | 2013-02-09 12:25:31 +0800 | [diff] [blame] | 1244 | int ka_time; |
| 1245 | int ka_probes; |
| 1246 | int ka_interval; |
joseph.urciuoli | 4d9c8fc | 2014-10-16 08:53:19 +0800 | [diff] [blame] | 1247 | #ifdef LWS_OPENSSL_SUPPORT |
| 1248 | SSL_CTX *provided_client_ssl_ctx; |
| 1249 | #else /* maintain structure layout either way */ |
| 1250 | void *provided_client_ssl_ctx; |
| 1251 | #endif |
Andy Green | 1b26527 | 2013-02-09 14:01:09 +0800 | [diff] [blame] | 1252 | }; |
| 1253 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1254 | LWS_VISIBLE LWS_EXTERN |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 1255 | void lws_set_log_level(int level, |
| 1256 | void (*log_emit_function)(int level, const char *line)); |
Andy Green | d6e0911 | 2011-03-05 16:12:15 +0000 | [diff] [blame] | 1257 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1258 | LWS_VISIBLE LWS_EXTERN void |
Andy Green | c11db20 | 2013-01-19 11:12:16 +0800 | [diff] [blame] | 1259 | lwsl_emit_syslog(int level, const char *line); |
| 1260 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1261 | LWS_VISIBLE LWS_EXTERN struct lws_context * |
Andy Green | 29a44cf | 2015-12-04 07:55:17 +0800 | [diff] [blame] | 1262 | lws_create_context(struct lws_context_creation_info *info); |
shys | b4e800e | 2013-10-24 22:12:03 +0800 | [diff] [blame] | 1263 | |
| 1264 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1265 | lws_set_proxy(struct lws_context *context, const char *proxy); |
Andy Green | ff95d7a | 2010-10-28 22:36:01 +0100 | [diff] [blame] | 1266 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1267 | LWS_VISIBLE LWS_EXTERN void |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1268 | lws_context_destroy(struct lws_context *context); |
Andy Green | 6964bb5 | 2011-01-23 16:50:33 +0000 | [diff] [blame] | 1269 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1270 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1271 | lws_service(struct lws_context *context, int timeout_ms); |
Andy Green | e92cd17 | 2011-01-19 13:11:55 +0000 | [diff] [blame] | 1272 | |
Patrick Gansterer | 1ee57f6 | 2014-03-06 11:57:50 +0100 | [diff] [blame] | 1273 | LWS_VISIBLE LWS_EXTERN void |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1274 | lws_cancel_service(struct lws_context *context); |
Patrick Gansterer | 1ee57f6 | 2014-03-06 11:57:50 +0100 | [diff] [blame] | 1275 | |
Andy Green | 917f43a | 2014-10-12 14:31:47 +0800 | [diff] [blame] | 1276 | LWS_VISIBLE LWS_EXTERN const unsigned char * |
| 1277 | lws_token_to_string(enum lws_token_indexes token); |
| 1278 | |
| 1279 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1280 | lws_add_http_header_by_name(struct lws_context *context, |
| 1281 | struct lws *wsi, |
Andy Green | 917f43a | 2014-10-12 14:31:47 +0800 | [diff] [blame] | 1282 | const unsigned char *name, |
| 1283 | const unsigned char *value, |
| 1284 | int length, |
| 1285 | unsigned char **p, |
| 1286 | unsigned char *end); |
| 1287 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1288 | lws_finalize_http_header(struct lws_context *context, |
| 1289 | struct lws *wsi, |
Andy Green | 917f43a | 2014-10-12 14:31:47 +0800 | [diff] [blame] | 1290 | unsigned char **p, |
| 1291 | unsigned char *end); |
| 1292 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1293 | lws_add_http_header_by_token(struct lws_context *context, |
| 1294 | struct lws *wsi, |
Andy Green | 917f43a | 2014-10-12 14:31:47 +0800 | [diff] [blame] | 1295 | enum lws_token_indexes token, |
| 1296 | const unsigned char *value, |
| 1297 | int length, |
| 1298 | unsigned char **p, |
| 1299 | unsigned char *end); |
Andy Green | 29a44cf | 2015-12-04 07:55:17 +0800 | [diff] [blame] | 1300 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1301 | lws_add_http_header_content_length(struct lws_context *context, |
| 1302 | struct lws *wsi, |
Andy Green | 200f385 | 2014-10-18 12:23:05 +0800 | [diff] [blame] | 1303 | unsigned long content_length, |
| 1304 | unsigned char **p, |
| 1305 | unsigned char *end); |
Andy Green | 917f43a | 2014-10-12 14:31:47 +0800 | [diff] [blame] | 1306 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1307 | lws_add_http_header_status(struct lws_context *context, |
| 1308 | struct lws *wsi, |
Andy Green | 917f43a | 2014-10-12 14:31:47 +0800 | [diff] [blame] | 1309 | unsigned int code, |
| 1310 | unsigned char **p, |
| 1311 | unsigned char *end); |
| 1312 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1313 | LWS_EXTERN int lws_http_transaction_completed(struct lws *wsi); |
Andy Green | 91b0589 | 2014-10-17 08:38:44 +0800 | [diff] [blame] | 1314 | |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 1315 | #ifdef LWS_USE_LIBEV |
Andrew Canaday | a8f47c9 | 2015-04-26 22:50:59 -0400 | [diff] [blame] | 1316 | typedef void (lws_ev_signal_cb)(EV_P_ struct ev_signal *w, int revents); |
| 1317 | |
| 1318 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 29a44cf | 2015-12-04 07:55:17 +0800 | [diff] [blame] | 1319 | lws_sigint_cfg( |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1320 | struct lws_context *context, |
Andrew Canaday | a8f47c9 | 2015-04-26 22:50:59 -0400 | [diff] [blame] | 1321 | int use_ev_sigint, |
| 1322 | lws_ev_signal_cb* cb); |
| 1323 | |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 1324 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 29a44cf | 2015-12-04 07:55:17 +0800 | [diff] [blame] | 1325 | lws_initloop( |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1326 | struct lws_context *context, struct ev_loop *loop); |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 1327 | |
| 1328 | LWS_VISIBLE void |
Andy Green | 29a44cf | 2015-12-04 07:55:17 +0800 | [diff] [blame] | 1329 | lws_sigint_cb( |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 1330 | struct ev_loop *loop, struct ev_signal *watcher, int revents); |
| 1331 | #endif /* LWS_USE_LIBEV */ |
| 1332 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1333 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1334 | lws_service_fd(struct lws_context *context, |
| 1335 | struct lws_pollfd *pollfd); |
Andy Green | 9f99034 | 2011-02-12 11:57:45 +0000 | [diff] [blame] | 1336 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1337 | LWS_VISIBLE LWS_EXTERN void * |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1338 | lws_context_user(struct lws_context *context); |
Alon Levy | 0291eb3 | 2012-10-19 11:21:56 +0200 | [diff] [blame] | 1339 | |
Andy Green | 9beedc1 | 2013-09-18 08:47:15 +0800 | [diff] [blame] | 1340 | enum pending_timeout { |
| 1341 | NO_PENDING_TIMEOUT = 0, |
| 1342 | PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE, |
Andy Green | 5dc62ea | 2013-09-20 20:26:12 +0800 | [diff] [blame] | 1343 | PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE, |
Andy Green | 9beedc1 | 2013-09-18 08:47:15 +0800 | [diff] [blame] | 1344 | PENDING_TIMEOUT_ESTABLISH_WITH_SERVER, |
| 1345 | PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE, |
| 1346 | PENDING_TIMEOUT_AWAITING_PING, |
| 1347 | PENDING_TIMEOUT_CLOSE_ACK, |
| 1348 | PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE, |
| 1349 | PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE, |
| 1350 | PENDING_TIMEOUT_SSL_ACCEPT, |
kapejod | ce64fb0 | 2013-11-19 13:38:16 +0100 | [diff] [blame] | 1351 | PENDING_TIMEOUT_HTTP_CONTENT, |
Andy Green | 0213812 | 2014-04-06 06:26:35 +0100 | [diff] [blame] | 1352 | PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND, |
Andy Green | 9f02c5d | 2015-04-01 05:34:18 +0800 | [diff] [blame] | 1353 | PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE, |
Andy Green | 9beedc1 | 2013-09-18 08:47:15 +0800 | [diff] [blame] | 1354 | }; |
| 1355 | |
Patrick Gansterer | 2ff6955 | 2014-02-26 18:51:05 +0100 | [diff] [blame] | 1356 | LWS_VISIBLE LWS_EXTERN void |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1357 | lws_set_timeout(struct lws *wsi, |
Andy Green | 9beedc1 | 2013-09-18 08:47:15 +0800 | [diff] [blame] | 1358 | enum pending_timeout reason, int secs); |
| 1359 | |
Andy Green | 4ea6006 | 2010-10-30 12:15:07 +0100 | [diff] [blame] | 1360 | /* |
| 1361 | * IMPORTANT NOTICE! |
Andy Green | e77ddd8 | 2010-11-13 10:03:47 +0000 | [diff] [blame] | 1362 | * |
Andy Green | 5fd8a5e | 2010-10-31 11:57:17 +0000 | [diff] [blame] | 1363 | * When sending with websocket protocol (LWS_WRITE_TEXT or LWS_WRITE_BINARY) |
| 1364 | * the send buffer has to have LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE |
Andy Green | 4ea6006 | 2010-10-30 12:15:07 +0100 | [diff] [blame] | 1365 | * buf, and LWS_SEND_BUFFER_POST_PADDING bytes valid AFTER (buf + len). |
Andy Green | e77ddd8 | 2010-11-13 10:03:47 +0000 | [diff] [blame] | 1366 | * |
Andy Green | 4ea6006 | 2010-10-30 12:15:07 +0100 | [diff] [blame] | 1367 | * This allows us to add protocol info before and after the data, and send as |
| 1368 | * one packet on the network without payload copying, for maximum efficiency. |
Andy Green | e77ddd8 | 2010-11-13 10:03:47 +0000 | [diff] [blame] | 1369 | * |
Andy Green | 6230476 | 2015-12-04 08:43:54 +0800 | [diff] [blame] | 1370 | * So for example you need this kind of code to use lws_write with a |
Andy Green | e77ddd8 | 2010-11-13 10:03:47 +0000 | [diff] [blame] | 1371 | * 128-byte payload |
| 1372 | * |
Andy Green | ab990e4 | 2010-10-31 12:42:52 +0000 | [diff] [blame] | 1373 | * char buf[LWS_SEND_BUFFER_PRE_PADDING + 128 + LWS_SEND_BUFFER_POST_PADDING]; |
Andy Green | e77ddd8 | 2010-11-13 10:03:47 +0000 | [diff] [blame] | 1374 | * |
Andy Green | ab990e4 | 2010-10-31 12:42:52 +0000 | [diff] [blame] | 1375 | * // fill your part of the buffer... for example here it's all zeros |
| 1376 | * memset(&buf[LWS_SEND_BUFFER_PRE_PADDING], 0, 128); |
Andy Green | e77ddd8 | 2010-11-13 10:03:47 +0000 | [diff] [blame] | 1377 | * |
Andy Green | 6230476 | 2015-12-04 08:43:54 +0800 | [diff] [blame] | 1378 | * lws_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], 128, |
Alex Rhatushnyak | 9f2246e | 2013-03-09 12:01:47 +0800 | [diff] [blame] | 1379 | * LWS_WRITE_TEXT); |
Andy Green | e77ddd8 | 2010-11-13 10:03:47 +0000 | [diff] [blame] | 1380 | * |
Andy Green | 5fd8a5e | 2010-10-31 11:57:17 +0000 | [diff] [blame] | 1381 | * When sending LWS_WRITE_HTTP, there is no protocol addition and you can just |
| 1382 | * use the whole buffer without taking care of the above. |
Andy Green | 4ea6006 | 2010-10-30 12:15:07 +0100 | [diff] [blame] | 1383 | */ |
| 1384 | |
Andy Green | 687b018 | 2011-02-26 11:04:01 +0000 | [diff] [blame] | 1385 | /* |
| 1386 | * this is the frame nonce plus two header plus 8 length |
Andy Green | a41314f | 2011-05-23 10:00:03 +0100 | [diff] [blame] | 1387 | * there's an additional two for mux extension per mux nesting level |
Andy Green | 687b018 | 2011-02-26 11:04:01 +0000 | [diff] [blame] | 1388 | * 2 byte prepend on close will already fit because control frames cannot use |
| 1389 | * the big length style |
| 1390 | */ |
Andy Green | 4739e5c | 2011-01-22 12:51:57 +0000 | [diff] [blame] | 1391 | |
Bruce Perens | 173e9c4 | 2015-10-13 09:17:39 +0800 | [diff] [blame] | 1392 | // Pad LWS_SEND_BUFFER_PRE_PADDING to the CPU word size, so that word references |
| 1393 | // to the address immediately after the padding won't cause an unaligned access |
| 1394 | // error. Sometimes the recommended padding is even larger than the size of a void *. |
| 1395 | // For example, for the X86-64 architecture, in Intel's document |
| 1396 | // https://software.intel.com/en-us/articles/data-alignment-when-migrating-to-64-bit-intel-architecture |
| 1397 | // they recommend that structures larger than 16 bytes be aligned to 16-byte |
| 1398 | // boundaries. |
| 1399 | // |
Andy Green | 2cd3074 | 2015-11-02 13:10:33 +0800 | [diff] [blame] | 1400 | |
| 1401 | #if !defined(LWS_SIZEOFPTR) |
| 1402 | #define LWS_SIZEOFPTR (sizeof (void *)) |
| 1403 | #endif |
| 1404 | #if !defined(u_int64_t) |
| 1405 | #define u_int64_t unsigned long long |
| 1406 | #endif |
| 1407 | |
Bruce Perens | 173e9c4 | 2015-10-13 09:17:39 +0800 | [diff] [blame] | 1408 | #if __x86_64__ |
| 1409 | #define _LWS_PAD_SIZE 16 // Intel recommended for best performance. |
| 1410 | #else |
Alexander Lukichev | fe6030a | 2015-10-20 13:10:33 +0300 | [diff] [blame] | 1411 | #define _LWS_PAD_SIZE LWS_SIZEOFPTR /* Size of a pointer on the target architecture */ |
Bruce Perens | 173e9c4 | 2015-10-13 09:17:39 +0800 | [diff] [blame] | 1412 | #endif |
Stepan Vondrak | fc6c274 | 2015-10-15 21:05:54 +0800 | [diff] [blame] | 1413 | #define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n)) |
Bruce Perens | 173e9c4 | 2015-10-13 09:17:39 +0800 | [diff] [blame] | 1414 | #define LWS_SEND_BUFFER_PRE_PADDING _LWS_PAD(4 + 10 + (2 * MAX_MUX_RECURSION)) |
David Galeano | e2cf992 | 2013-01-09 18:06:55 +0800 | [diff] [blame] | 1415 | #define LWS_SEND_BUFFER_POST_PADDING 4 |
Andy Green | 4ea6006 | 2010-10-30 12:15:07 +0100 | [diff] [blame] | 1416 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1417 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1418 | lws_write(struct lws *wsi, unsigned char *buf, size_t len, |
Andy Green | 6230476 | 2015-12-04 08:43:54 +0800 | [diff] [blame] | 1419 | enum lws_write_protocol protocol); |
Andy Green | a2b0ab0 | 2010-11-11 12:28:29 +0000 | [diff] [blame] | 1420 | |
Gabriel Gritsch | 890f8e9 | 2014-02-15 16:20:25 +0800 | [diff] [blame] | 1421 | /* helper for case where buffer may be const */ |
Andy Green | 29a44cf | 2015-12-04 07:55:17 +0800 | [diff] [blame] | 1422 | #define lws_write_http(wsi, buf, len) \ |
| 1423 | lws_write(wsi, (unsigned char *)(buf), len, LWS_WRITE_HTTP) |
Gabriel Gritsch | 890f8e9 | 2014-02-15 16:20:25 +0800 | [diff] [blame] | 1424 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1425 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1426 | lws_serve_http_file(struct lws_context *context, |
| 1427 | struct lws *wsi, const char *file, |
Andy Green | 917f43a | 2014-10-12 14:31:47 +0800 | [diff] [blame] | 1428 | const char *content_type, const char *other_headers, |
| 1429 | int other_headers_len); |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1430 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1431 | lws_serve_http_file_fragment(struct lws_context *context, |
| 1432 | struct lws *wsi); |
Andy Green | b45993c | 2010-12-18 15:13:50 +0000 | [diff] [blame] | 1433 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1434 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1435 | lws_return_http_status(struct lws_context *context, |
| 1436 | struct lws *wsi, unsigned int code, |
| 1437 | const char *html_body); |
| 1438 | |
| 1439 | LWS_VISIBLE LWS_EXTERN const struct lws_protocols * |
| 1440 | lws_get_protocol(struct lws *wsi); |
Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 1441 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1442 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1443 | lws_callback_on_writable(struct lws_context *context, struct lws *wsi); |
Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 1444 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1445 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1446 | lws_callback_on_writable_all_protocol(const struct lws_protocols *protocol); |
Andy Green | e39e6ef | 2014-02-15 16:36:38 +0800 | [diff] [blame] | 1447 | |
| 1448 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1449 | lws_callback_all_protocol(const struct lws_protocols *protocol, int reason); |
Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 1450 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1451 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1452 | lws_get_socket_fd(struct lws *wsi); |
| 1453 | |
| 1454 | LWS_VISIBLE LWS_EXTERN int |
| 1455 | lws_is_final_fragment(struct lws *wsi); |
Andy Green | 82c3d54 | 2011-03-07 21:16:31 +0000 | [diff] [blame] | 1456 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1457 | LWS_VISIBLE LWS_EXTERN unsigned char |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1458 | lws_get_reserved_bits(struct lws *wsi); |
David Galeano | e2cf992 | 2013-01-09 18:06:55 +0800 | [diff] [blame] | 1459 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1460 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1461 | lws_rx_flow_control(struct lws *wsi, int enable); |
Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 1462 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1463 | LWS_VISIBLE LWS_EXTERN void |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1464 | lws_rx_flow_allow_all_protocol(const struct lws_protocols *protocol); |
Andy Green | b55451c | 2013-03-16 12:32:27 +0800 | [diff] [blame] | 1465 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1466 | LWS_VISIBLE LWS_EXTERN size_t |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1467 | lws_remaining_packet_payload(struct lws *wsi); |
Andy Green | 38e57bb | 2011-01-19 12:20:27 +0000 | [diff] [blame] | 1468 | |
Andy Green | 97ee57f | 2014-10-29 09:39:08 +0800 | [diff] [blame] | 1469 | /* |
Peter Pentchev | bb085da | 2015-12-03 15:55:11 +0200 | [diff] [blame] | 1470 | * if the protocol does not have any guidance, returns -1. Currently only |
Andy Green | 97ee57f | 2014-10-29 09:39:08 +0800 | [diff] [blame] | 1471 | * http2 connections get send window information from this API. But your code |
| 1472 | * should use it so it can work properly with any protocol. |
| 1473 | * |
| 1474 | * If nonzero return is the amount of payload data the peer or intermediary has |
| 1475 | * reported it has buffer space for. That has NO relationship with the amount |
| 1476 | * of buffer space your OS can accept on this connection for a write action. |
| 1477 | * |
| 1478 | * This number represents the maximum you could send to the peer or intermediary |
| 1479 | * on this connection right now without it complaining. |
| 1480 | * |
| 1481 | * lws manages accounting for send window updates and payload writes |
| 1482 | * automatically, so this number reflects the situation at the peer or |
| 1483 | * intermediary dynamically. |
| 1484 | */ |
| 1485 | LWS_VISIBLE LWS_EXTERN size_t |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1486 | lws_get_peer_write_allowance(struct lws *wsi); |
Andy Green | 97ee57f | 2014-10-29 09:39:08 +0800 | [diff] [blame] | 1487 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1488 | LWS_VISIBLE LWS_EXTERN struct lws * |
| 1489 | lws_client_connect(struct lws_context *clients, |
Andy Green | 4739e5c | 2011-01-22 12:51:57 +0000 | [diff] [blame] | 1490 | const char *address, |
| 1491 | int port, |
Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 1492 | int ssl_connection, |
Andy Green | 4739e5c | 2011-01-22 12:51:57 +0000 | [diff] [blame] | 1493 | const char *path, |
| 1494 | const char *host, |
| 1495 | const char *origin, |
Andy Green | bfb051f | 2011-02-09 08:49:14 +0000 | [diff] [blame] | 1496 | const char *protocol, |
| 1497 | int ietf_version_or_minus_one); |
Andy Green | 4739e5c | 2011-01-22 12:51:57 +0000 | [diff] [blame] | 1498 | |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1499 | LWS_VISIBLE LWS_EXTERN struct lws * |
| 1500 | lws_client_connect_extended(struct lws_context *clients, |
David Brooks | 2c60d95 | 2012-04-20 12:19:01 +0800 | [diff] [blame] | 1501 | const char *address, |
| 1502 | int port, |
| 1503 | int ssl_connection, |
| 1504 | const char *path, |
| 1505 | const char *host, |
| 1506 | const char *origin, |
| 1507 | const char *protocol, |
| 1508 | int ietf_version_or_minus_one, |
| 1509 | void *userdata); |
| 1510 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1511 | LWS_VISIBLE LWS_EXTERN const char * |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1512 | lws_canonical_hostname(struct lws_context *context); |
Andy Green | 2ac5a6f | 2011-01-28 10:00:18 +0000 | [diff] [blame] | 1513 | |
Andy Green | 4739e5c | 2011-01-22 12:51:57 +0000 | [diff] [blame] | 1514 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1515 | LWS_VISIBLE LWS_EXTERN void |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1516 | lws_get_peer_addresses(struct lws_context *context, |
| 1517 | struct lws *wsi, lws_sockfd_type fd, |
Andy Green | 6d41720 | 2015-12-04 10:39:23 +0800 | [diff] [blame] | 1518 | char *name, int name_len, |
| 1519 | char *rip, int rip_len); |
Andy Green | 0703409 | 2011-02-13 08:37:12 +0000 | [diff] [blame] | 1520 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1521 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1522 | lws_get_random(struct lws_context *context, void *buf, int len); |
Andy Green | 8acc194 | 2011-03-07 20:47:40 +0000 | [diff] [blame] | 1523 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1524 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 279a303 | 2013-01-17 10:05:39 +0800 | [diff] [blame] | 1525 | lws_daemonize(const char *_lock_path); |
| 1526 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1527 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1528 | lws_send_pipe_choked(struct lws *wsi); |
Andy Green | 043a0ba | 2011-04-25 23:54:11 +0800 | [diff] [blame] | 1529 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1530 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1531 | lws_partial_buffered(struct lws *wsi); |
Andy Green | 14425ea | 2014-08-18 22:49:39 +0800 | [diff] [blame] | 1532 | |
| 1533 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1534 | lws_frame_is_binary(struct lws *wsi); |
Andy Green | 2fd3f2f | 2013-01-18 09:49:20 +0800 | [diff] [blame] | 1535 | |
Andy Green | b128ccc | 2014-08-16 09:54:27 +0800 | [diff] [blame] | 1536 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1537 | lws_is_ssl(struct lws *wsi); |
Andy Green | 4c79ee7 | 2015-10-15 11:20:40 +0800 | [diff] [blame] | 1538 | #ifdef LWS_SHA1_USE_OPENSSL_NAME |
Andy Green | 29a44cf | 2015-12-04 07:55:17 +0800 | [diff] [blame] | 1539 | #define lws_SHA1 SHA1 |
Andy Green | 4c79ee7 | 2015-10-15 11:20:40 +0800 | [diff] [blame] | 1540 | #else |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1541 | LWS_VISIBLE LWS_EXTERN unsigned char * |
Andy Green | 29a44cf | 2015-12-04 07:55:17 +0800 | [diff] [blame] | 1542 | lws_SHA1(const unsigned char *d, size_t n, unsigned char *md); |
Andy Green | 4c79ee7 | 2015-10-15 11:20:40 +0800 | [diff] [blame] | 1543 | #endif |
Andy Green | 2836c64 | 2011-03-07 20:47:41 +0000 | [diff] [blame] | 1544 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1545 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | f94e058 | 2011-05-14 15:07:56 +0200 | [diff] [blame] | 1546 | lws_b64_encode_string(const char *in, int in_len, char *out, int out_size); |
| 1547 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1548 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | f94e058 | 2011-05-14 15:07:56 +0200 | [diff] [blame] | 1549 | lws_b64_decode_string(const char *in, char *out, int out_size); |
| 1550 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1551 | LWS_VISIBLE LWS_EXTERN const char * |
Andy Green | 7b40545 | 2013-02-01 10:50:15 +0800 | [diff] [blame] | 1552 | lws_get_library_version(void); |
| 1553 | |
Andy Green | 16ab318 | 2013-02-10 18:02:31 +0800 | [diff] [blame] | 1554 | /* access to headers... only valid while headers valid */ |
| 1555 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1556 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1557 | lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h); |
Andy Green | 16ab318 | 2013-02-10 18:02:31 +0800 | [diff] [blame] | 1558 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1559 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1560 | lws_hdr_copy(struct lws *wsi, char *dest, int len, |
Andy Green | b5b2319 | 2013-02-11 17:13:32 +0800 | [diff] [blame] | 1561 | enum lws_token_indexes h); |
Andy Green | 16ab318 | 2013-02-10 18:02:31 +0800 | [diff] [blame] | 1562 | |
Andy Green | ea0642a | 2013-01-29 06:52:00 +0800 | [diff] [blame] | 1563 | /* |
| 1564 | * Note: this is not normally needed as a user api. It's provided in case it is |
| 1565 | * useful when integrating with other app poll loop service code. |
| 1566 | */ |
| 1567 | |
Peter Pentchev | 9a4fef7 | 2013-03-30 09:52:21 +0800 | [diff] [blame] | 1568 | LWS_VISIBLE LWS_EXTERN int |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1569 | lws_read(struct lws_context *context, struct lws *wsi, |
| 1570 | unsigned char *buf, size_t len); |
Andy Green | ea0642a | 2013-01-29 06:52:00 +0800 | [diff] [blame] | 1571 | |
Andy Green | 3182ece | 2013-01-20 17:08:31 +0800 | [diff] [blame] | 1572 | #ifndef LWS_NO_EXTENSIONS |
Andy Green | 4b85c1d | 2015-12-04 11:08:32 +0800 | [diff] [blame^] | 1573 | LWS_VISIBLE LWS_EXTERN struct lws_extension *lws_get_internal_extensions(); |
Andy Green | 3182ece | 2013-01-20 17:08:31 +0800 | [diff] [blame] | 1574 | #endif |
Andy Green | 4cd87a0 | 2011-03-06 13:15:32 +0000 | [diff] [blame] | 1575 | |
Alejandro Mery | cdc9717 | 2014-12-04 23:15:27 +0100 | [diff] [blame] | 1576 | /* |
| 1577 | * custom allocator support |
| 1578 | */ |
| 1579 | LWS_VISIBLE LWS_EXTERN void |
| 1580 | lws_set_allocator(void *(*realloc)(void *ptr, size_t size)); |
| 1581 | |
Peter Hinz | 56885f3 | 2011-03-02 22:03:47 +0000 | [diff] [blame] | 1582 | #ifdef __cplusplus |
| 1583 | } |
| 1584 | #endif |
Andy Green | a11fe94 | 2011-09-25 10:30:26 +0100 | [diff] [blame] | 1585 | |
Andy Green | ab990e4 | 2010-10-31 12:42:52 +0000 | [diff] [blame] | 1586 | #endif |