blob: bc55125ab64db4a510a6acef2f0e872a01b0ed36 [file] [log] [blame]
Andy Green7c212cc2010-11-08 20:20:42 +00001/*
2 * libwebsockets - small server side websockets and web server implementation
Andy Greene77ddd82010-11-13 10:03:47 +00003 *
Andy Green7c212cc2010-11-08 20:20:42 +00004 * Copyright (C) 2010 Andy Green <andy@warmcat.com>
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
Andy Green70dfebd2010-12-20 09:35:03 +000022#include <unistd.h>
Andy Green7c212cc2010-11-08 20:20:42 +000023#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
Andy Green70dfebd2010-12-20 09:35:03 +000026#include <strings.h>
Andy Green7c212cc2010-11-08 20:20:42 +000027#include <ctype.h>
Andy Green7c212cc2010-11-08 20:20:42 +000028#include <errno.h>
Andy Green7c212cc2010-11-08 20:20:42 +000029#include <fcntl.h>
30#include <signal.h>
Andy Green2a480ea2012-04-12 10:54:22 +080031#ifdef __MINGW64__
32#else
33#ifdef __MINGW32__
34#else
Andy Green2ac5a6f2011-01-28 10:00:18 +000035#include <netdb.h>
Andy Green2a480ea2012-04-12 10:54:22 +080036#endif
37#endif
Peter Hinz56885f32011-03-02 22:03:47 +000038#include <stdarg.h>
39
40#include <sys/stat.h>
41
42#ifdef WIN32
Andy Green2a480ea2012-04-12 10:54:22 +080043#ifdef __MINGW64__
44#else
45#ifdef __MINGW32__
46#else
Peter Hinz56885f32011-03-02 22:03:47 +000047#include <time.h >
Andy Green2a480ea2012-04-12 10:54:22 +080048#endif
49#endif
Peter Hinz56885f32011-03-02 22:03:47 +000050#include <winsock2.h>
51#include <ws2ipdef.h>
52#include <windows.h>
53
54#else
Andy Green7c212cc2010-11-08 20:20:42 +000055
Andy Greene77ddd82010-11-13 10:03:47 +000056#include <sys/types.h>
Andy Green7c212cc2010-11-08 20:20:42 +000057#include <sys/socket.h>
Andy Greened11a022011-01-20 10:23:50 +000058#ifndef LWS_NO_FORK
Artem Baguinski91531662011-12-14 22:14:03 +010059#ifdef HAVE_SYS_PRCTL_H
Andy Greenb45993c2010-12-18 15:13:50 +000060#include <sys/prctl.h>
Andy Greened11a022011-01-20 10:23:50 +000061#endif
Artem Baguinski91531662011-12-14 22:14:03 +010062#endif
Andy Green7c212cc2010-11-08 20:20:42 +000063#include <netinet/in.h>
Andy Green6c939552011-03-08 08:56:57 +000064#include <netinet/tcp.h>
Andy Greenb45993c2010-12-18 15:13:50 +000065#include <arpa/inet.h>
Andy Green7c212cc2010-11-08 20:20:42 +000066
67#include <poll.h>
68#include <sys/mman.h>
Andy Green038d5822011-02-14 20:58:26 +000069#include <sys/time.h>
Andy Green7c212cc2010-11-08 20:20:42 +000070
Peter Hinz56885f32011-03-02 22:03:47 +000071#endif
72
Andy Green7c212cc2010-11-08 20:20:42 +000073#ifdef LWS_OPENSSL_SUPPORT
74#include <openssl/ssl.h>
75#include <openssl/evp.h>
76#include <openssl/err.h>
Andy Green70dfebd2010-12-20 09:35:03 +000077#include <openssl/md5.h>
Andy Greene2522172011-01-18 17:14:03 +000078#include <openssl/sha.h>
Darin Willitsdb9ba422011-02-14 20:56:24 +000079#endif
80
81
Andy Green7c212cc2010-11-08 20:20:42 +000082#include "libwebsockets.h"
83
Andy Green6964bb52011-01-23 16:50:33 +000084#if 0
85#define DEBUG
86#endif
Andy Green7c212cc2010-11-08 20:20:42 +000087
88#ifdef DEBUG
Peter Hinz56885f32011-03-02 22:03:47 +000089#ifdef WIN32
90static
91#else
92static inline
93#endif
94void debug(const char *format, ...)
Andy Green6964bb52011-01-23 16:50:33 +000095{
Andy Green4739e5c2011-01-22 12:51:57 +000096 va_list ap;
97 va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap);
98}
Andy Green7c212cc2010-11-08 20:20:42 +000099#else
Andy Greenb1dab512011-05-14 13:12:01 +0200100#ifdef WIN32
101static
102#else
103static inline
104#endif
105void debug(const char *format, ...)
Andy Green6964bb52011-01-23 16:50:33 +0000106{
107}
Andy Green7c212cc2010-11-08 20:20:42 +0000108#endif
109
Darin Willitsc19456f2011-02-14 17:52:39 +0000110
111/*
112 * Mac OSX as well as iOS do not define the MSG_NOSIGNAL flag,
113 * but happily have something equivalent in the SO_NOSIGPIPE flag.
114 */
115#ifdef __APPLE__
Andy Green6ee372f2012-04-09 15:09:01 +0800116#define MSG_NOSIGNAL SO_NOSIGPIPE
Darin Willitsc19456f2011-02-14 17:52:39 +0000117#endif
118
119
Andy Green0d338332011-02-12 11:57:43 +0000120#define FD_HASHTABLE_MODULUS 32
Andy Green7c212cc2010-11-08 20:20:42 +0000121#define MAX_CLIENTS 100
122#define LWS_MAX_HEADER_NAME_LENGTH 64
123#define LWS_MAX_HEADER_LEN 4096
124#define LWS_INITIAL_HDR_ALLOC 256
125#define LWS_ADDITIONAL_HDR_ALLOC 64
Andy Greena6cbece2011-01-27 20:06:03 +0000126#define MAX_USER_RX_BUFFER 4096
Andy Green90c7cbc2011-01-27 06:26:52 +0000127#define MAX_BROADCAST_PAYLOAD 2048
Andy Greenb45993c2010-12-18 15:13:50 +0000128#define LWS_MAX_PROTOCOLS 10
Andy Greend6e09112011-03-05 16:12:15 +0000129#define LWS_MAX_EXTENSIONS_ACTIVE 10
Andy Greend85cb202011-09-25 09:32:54 +0100130#define SPEC_LATEST_SUPPORTED 13
David Galeanoc9f1ff82013-01-09 18:01:23 +0800131#define AWAITING_TIMEOUT 5
Andy Green7c212cc2010-11-08 20:20:42 +0000132
Andy Greene2522172011-01-18 17:14:03 +0000133#define MAX_WEBSOCKET_04_KEY_LEN 128
Andy Green4739e5c2011-01-22 12:51:57 +0000134#define SYSTEM_RANDOM_FILEPATH "/dev/urandom"
Andy Greene2522172011-01-18 17:14:03 +0000135
Andy Green38e57bb2011-01-19 12:20:27 +0000136enum lws_websocket_opcodes_04 {
137 LWS_WS_OPCODE_04__CONTINUATION = 0,
138 LWS_WS_OPCODE_04__CLOSE = 1,
139 LWS_WS_OPCODE_04__PING = 2,
140 LWS_WS_OPCODE_04__PONG = 3,
141 LWS_WS_OPCODE_04__TEXT_FRAME = 4,
142 LWS_WS_OPCODE_04__BINARY_FRAME = 5,
Andy Greena41314f2011-05-23 10:00:03 +0100143
144 LWS_WS_OPCODE_04__RESERVED_6 = 6,
145 LWS_WS_OPCODE_04__RESERVED_7 = 7,
146 LWS_WS_OPCODE_04__RESERVED_8 = 8,
147 LWS_WS_OPCODE_04__RESERVED_9 = 9,
148 LWS_WS_OPCODE_04__RESERVED_A = 0xa,
149 LWS_WS_OPCODE_04__RESERVED_B = 0xb,
150 LWS_WS_OPCODE_04__RESERVED_C = 0xc,
151 LWS_WS_OPCODE_04__RESERVED_D = 0xd,
152 LWS_WS_OPCODE_04__RESERVED_E = 0xe,
153 LWS_WS_OPCODE_04__RESERVED_F = 0xf,
Andy Green38e57bb2011-01-19 12:20:27 +0000154};
155
Andy Green5fd55cd2011-04-23 10:54:53 +0100156enum lws_websocket_opcodes_07 {
157 LWS_WS_OPCODE_07__CONTINUATION = 0,
158 LWS_WS_OPCODE_07__TEXT_FRAME = 1,
159 LWS_WS_OPCODE_07__BINARY_FRAME = 2,
Andy Greena41314f2011-05-23 10:00:03 +0100160
161 LWS_WS_OPCODE_07__NOSPEC__MUX = 7,
162
163 /* control extensions 8+ */
164
Andy Green5fd55cd2011-04-23 10:54:53 +0100165 LWS_WS_OPCODE_07__CLOSE = 8,
166 LWS_WS_OPCODE_07__PING = 9,
167 LWS_WS_OPCODE_07__PONG = 0xa,
168};
169
Andy Greena41314f2011-05-23 10:00:03 +0100170
Andy Green7c212cc2010-11-08 20:20:42 +0000171enum lws_connection_states {
172 WSI_STATE_HTTP,
173 WSI_STATE_HTTP_HEADERS,
174 WSI_STATE_DEAD_SOCKET,
Andy Green4739e5c2011-01-22 12:51:57 +0000175 WSI_STATE_ESTABLISHED,
Andy Green5e1fa172011-02-10 09:07:05 +0000176 WSI_STATE_CLIENT_UNCONNECTED,
Andy Greenbe93fef2011-02-14 20:25:43 +0000177 WSI_STATE_RETURNED_CLOSE_ALREADY,
Andy Greena41314f2011-05-23 10:00:03 +0100178 WSI_STATE_AWAITING_CLOSE_ACK,
Andy Green7c212cc2010-11-08 20:20:42 +0000179};
180
Andy Green7c212cc2010-11-08 20:20:42 +0000181enum lws_rx_parse_state {
182 LWS_RXPS_NEW,
Andy Greene77ddd82010-11-13 10:03:47 +0000183
Andy Green7c212cc2010-11-08 20:20:42 +0000184 LWS_RXPS_SEEN_76_FF,
185 LWS_RXPS_PULLING_76_LENGTH,
Andy Green6452f1e2010-11-11 09:22:22 +0000186 LWS_RXPS_EAT_UNTIL_76_FF,
Andy Greene77ddd82010-11-13 10:03:47 +0000187
Andy Green3e5eb782011-01-18 18:14:26 +0000188 LWS_RXPS_04_MASK_NONCE_1,
189 LWS_RXPS_04_MASK_NONCE_2,
190 LWS_RXPS_04_MASK_NONCE_3,
191
192 LWS_RXPS_04_FRAME_HDR_1,
Andy Green38e57bb2011-01-19 12:20:27 +0000193 LWS_RXPS_04_FRAME_HDR_LEN,
194 LWS_RXPS_04_FRAME_HDR_LEN16_2,
195 LWS_RXPS_04_FRAME_HDR_LEN16_1,
196 LWS_RXPS_04_FRAME_HDR_LEN64_8,
197 LWS_RXPS_04_FRAME_HDR_LEN64_7,
198 LWS_RXPS_04_FRAME_HDR_LEN64_6,
199 LWS_RXPS_04_FRAME_HDR_LEN64_5,
200 LWS_RXPS_04_FRAME_HDR_LEN64_4,
201 LWS_RXPS_04_FRAME_HDR_LEN64_3,
202 LWS_RXPS_04_FRAME_HDR_LEN64_2,
203 LWS_RXPS_04_FRAME_HDR_LEN64_1,
Andy Green3e5eb782011-01-18 18:14:26 +0000204
Andy Green283d0a22011-04-24 05:46:23 +0100205 LWS_RXPS_07_COLLECT_FRAME_KEY_1,
206 LWS_RXPS_07_COLLECT_FRAME_KEY_2,
207 LWS_RXPS_07_COLLECT_FRAME_KEY_3,
208 LWS_RXPS_07_COLLECT_FRAME_KEY_4,
209
Andy Green7c212cc2010-11-08 20:20:42 +0000210 LWS_RXPS_PAYLOAD_UNTIL_LENGTH_EXHAUSTED
211};
212
213
Andy Green0d338332011-02-12 11:57:43 +0000214enum connection_mode {
215 LWS_CONNMODE_WS_SERVING,
216 LWS_CONNMODE_WS_CLIENT,
217
Andy Greenbe93fef2011-02-14 20:25:43 +0000218 /* transient modes */
219 LWS_CONNMODE_WS_CLIENT_WAITING_PROXY_REPLY,
220 LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE,
221 LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY,
Andy Greena41314f2011-05-23 10:00:03 +0100222 LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT,
223 LWS_CONNMODE_WS_CLIENT_PENDING_CANDIDATE_CHILD,
Andy Greenbe93fef2011-02-14 20:25:43 +0000224
Andy Green0d338332011-02-12 11:57:43 +0000225 /* special internal types */
226 LWS_CONNMODE_SERVER_LISTENER,
227 LWS_CONNMODE_BROADCAST_PROXY_LISTENER,
228 LWS_CONNMODE_BROADCAST_PROXY
229};
230
231
232#define LWS_FD_HASH(fd) ((fd ^ (fd >> 8) ^ (fd >> 16)) % FD_HASHTABLE_MODULUS)
233
234struct libwebsocket_fd_hashtable {
235 struct libwebsocket *wsi[MAX_CLIENTS + 1];
236 int length;
237};
238
Andy Greene92cd172011-01-19 13:11:55 +0000239struct libwebsocket_protocols;
240
Andy Greenb45993c2010-12-18 15:13:50 +0000241struct libwebsocket_context {
Andy Green0d338332011-02-12 11:57:43 +0000242 struct libwebsocket_fd_hashtable fd_hashtable[FD_HASHTABLE_MODULUS];
243 struct pollfd fds[MAX_CLIENTS * FD_HASHTABLE_MODULUS + 1];
Andy Greenb45993c2010-12-18 15:13:50 +0000244 int fds_count;
Andy Green4739e5c2011-01-22 12:51:57 +0000245 int listen_port;
Andy Green9659f372011-01-27 22:01:43 +0000246 char http_proxy_address[256];
Andy Green2ac5a6f2011-01-28 10:00:18 +0000247 char canonical_hostname[1024];
Andy Green9659f372011-01-27 22:01:43 +0000248 unsigned int http_proxy_port;
Andy Green8014b292011-01-30 20:57:25 +0000249 unsigned int options;
Andy Greena71eafc2011-02-14 17:59:43 +0000250 unsigned long last_timeout_check_s;
Andy Green44eee682011-02-10 09:32:24 +0000251
252 int fd_random;
Andy Green6ee372f2012-04-09 15:09:01 +0800253
Andy Greenb45993c2010-12-18 15:13:50 +0000254#ifdef LWS_OPENSSL_SUPPORT
255 int use_ssl;
Andy Green90c7cbc2011-01-27 06:26:52 +0000256 SSL_CTX *ssl_ctx;
257 SSL_CTX *ssl_client_ctx;
Andy Greenb45993c2010-12-18 15:13:50 +0000258#endif
Andy Greene92cd172011-01-19 13:11:55 +0000259 struct libwebsocket_protocols *protocols;
Andy Greenb45993c2010-12-18 15:13:50 +0000260 int count_protocols;
Andy Greend6e09112011-03-05 16:12:15 +0000261 struct libwebsocket_extension *extensions;
Alon Levy0291eb32012-10-19 11:21:56 +0200262
263 void *user_space;
Andy Greenb45993c2010-12-18 15:13:50 +0000264};
265
Andy Greenf3d3b402011-02-09 07:16:34 +0000266
Andy Greena71eafc2011-02-14 17:59:43 +0000267enum pending_timeout {
268 NO_PENDING_TIMEOUT = 0,
Andy Greenbe93fef2011-02-14 20:25:43 +0000269 PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE,
Andy Greena71eafc2011-02-14 17:59:43 +0000270 PENDING_TIMEOUT_ESTABLISH_WITH_SERVER,
Andy Greenbe93fef2011-02-14 20:25:43 +0000271 PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE,
Andy Greena71eafc2011-02-14 17:59:43 +0000272 PENDING_TIMEOUT_AWAITING_PING,
Andy Greenda527df2011-03-07 07:08:12 +0000273 PENDING_TIMEOUT_CLOSE_ACK,
Andy Greena41314f2011-05-23 10:00:03 +0100274 PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE,
Andy Greena71eafc2011-02-14 17:59:43 +0000275};
276
Andy Green7c212cc2010-11-08 20:20:42 +0000277
278/*
279 * This is totally opaque to code using the library. It's exported as a
280 * forward-reference pointer-only declaration; the user can use the pointer with
281 * other APIs to get information out of it.
282 */
283
284struct libwebsocket {
Andy Green4f3943a2010-11-12 10:44:16 +0000285 const struct libwebsocket_protocols *protocol;
Andy Green46c2ea02011-03-22 09:04:01 +0000286 struct libwebsocket_extension *
Andy Greend6e09112011-03-05 16:12:15 +0000287 active_extensions[LWS_MAX_EXTENSIONS_ACTIVE];
Andy Green6ee372f2012-04-09 15:09:01 +0800288 void *active_extensions_user[LWS_MAX_EXTENSIONS_ACTIVE];
Andy Greend6e09112011-03-05 16:12:15 +0000289 int count_active_extensions;
Andy Green7c212cc2010-11-08 20:20:42 +0000290
291 enum lws_connection_states state;
292
293 char name_buffer[LWS_MAX_HEADER_NAME_LENGTH];
294 int name_buffer_pos;
295 int current_alloc_len;
296 enum lws_token_indexes parser_state;
297 struct lws_tokens utf8_token[WSI_TOKEN_COUNT];
298 int ietf_spec_revision;
Andy Green6452f1e2010-11-11 09:22:22 +0000299 char rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING + MAX_USER_RX_BUFFER +
300 LWS_SEND_BUFFER_POST_PADDING];
301 int rx_user_buffer_head;
Andy Green66a36ff2011-04-29 17:43:06 +0800302 enum libwebsocket_write_protocol rx_frame_type;
Andy Green0d338332011-02-12 11:57:43 +0000303 int protocol_index_for_broadcast_proxy;
Andy Greena71eafc2011-02-14 17:59:43 +0000304 enum pending_timeout pending_timeout;
305 unsigned long pending_timeout_limit;
Andy Green6452f1e2010-11-11 09:22:22 +0000306
Andy Green7c212cc2010-11-08 20:20:42 +0000307 int sock;
308
309 enum lws_rx_parse_state lws_rx_parse_state;
Andy Green3b84c002011-03-06 13:14:42 +0000310 char extension_data_pending;
Andy Greena41314f2011-05-23 10:00:03 +0100311 struct libwebsocket *candidate_children_list;
312 struct libwebsocket *extension_handles;
Andy Green38e57bb2011-01-19 12:20:27 +0000313
314 /* 04 protocol specific */
315
Andy Greenbe93fef2011-02-14 20:25:43 +0000316 char key_b64[150];
Andy Green38e57bb2011-01-19 12:20:27 +0000317 unsigned char masking_key_04[20];
318 unsigned char frame_masking_nonce_04[4];
319 unsigned char frame_mask_04[20];
320 unsigned char frame_mask_index;
Andy Green7c212cc2010-11-08 20:20:42 +0000321 size_t rx_packet_length;
Andy Green38e57bb2011-01-19 12:20:27 +0000322 unsigned char opcode;
323 unsigned char final;
David Galeanoe2cf9922013-01-09 18:06:55 +0800324 unsigned char rsv;
Andy Green38e57bb2011-01-19 12:20:27 +0000325
326 int pings_vs_pongs;
Andy Greenbfb051f2011-02-09 08:49:14 +0000327 unsigned char (*xor_mask)(struct libwebsocket *, unsigned char);
Andy Green92970ba2011-02-10 09:22:35 +0000328 char all_zero_nonce;
Andy Greene77ddd82010-11-13 10:03:47 +0000329
Andy Green687b0182011-02-26 11:04:01 +0000330 enum lws_close_status close_reason;
331
Andy Green283d0a22011-04-24 05:46:23 +0100332 /* 07 specific */
333 char this_frame_masked;
334
Andy Green4739e5c2011-01-22 12:51:57 +0000335 /* client support */
336 char initial_handshake_hash_base64[30];
Andy Greenf3d3b402011-02-09 07:16:34 +0000337 enum connection_mode mode;
Andy Greenbe93fef2011-02-14 20:25:43 +0000338 char *c_path;
339 char *c_host;
340 char *c_origin;
341 char *c_protocol;
David Brooks6c6a3d32012-04-20 12:13:50 +0800342 callback_function *c_callback;
Andy Green4739e5c2011-01-22 12:51:57 +0000343
Andy Greena41314f2011-05-23 10:00:03 +0100344 char *c_address;
345 int c_port;
346
347
Andy Green7c212cc2010-11-08 20:20:42 +0000348#ifdef LWS_OPENSSL_SUPPORT
349 SSL *ssl;
Andy Green90c7cbc2011-01-27 06:26:52 +0000350 BIO *client_bio;
Andy Greenbe93fef2011-02-14 20:25:43 +0000351 int use_ssl;
Andy Green7c212cc2010-11-08 20:20:42 +0000352#endif
353
Andy Green4f3943a2010-11-12 10:44:16 +0000354 void *user_space;
Andy Green7c212cc2010-11-08 20:20:42 +0000355};
356
Andy Green4739e5c2011-01-22 12:51:57 +0000357extern int
358libwebsocket_client_rx_sm(struct libwebsocket *wsi, unsigned char c);
359
Andy Greenb45993c2010-12-18 15:13:50 +0000360extern int
361libwebsocket_parse(struct libwebsocket *wsi, unsigned char c);
362
363extern int
364libwebsocket_interpret_incoming_packet(struct libwebsocket *wsi,
365 unsigned char *buf, size_t len);
Andy Green8f037e42010-12-19 22:13:26 +0000366
367extern int
Andy Green6ee372f2012-04-09 15:09:01 +0800368libwebsocket_read(struct libwebsocket_context *context,
369 struct libwebsocket *wsi,
370 unsigned char *buf, size_t len);
Andy Greendf736162011-01-18 15:39:02 +0000371
372extern int
Andy Greendf736162011-01-18 15:39:02 +0000373lws_b64_selftest(void);
Andy Greenbfb051f2011-02-09 08:49:14 +0000374
375extern unsigned char
376xor_no_mask(struct libwebsocket *wsi, unsigned char c);
377
378extern unsigned char
379xor_mask_04(struct libwebsocket *wsi, unsigned char c);
380
381extern unsigned char
382xor_mask_05(struct libwebsocket *wsi, unsigned char c);
Andy Green0d338332011-02-12 11:57:43 +0000383
384extern struct libwebsocket *
Peter Hinz56885f32011-03-02 22:03:47 +0000385wsi_from_fd(struct libwebsocket_context *context, int fd);
Andy Green0d338332011-02-12 11:57:43 +0000386
387extern int
Peter Hinz56885f32011-03-02 22:03:47 +0000388insert_wsi(struct libwebsocket_context *context, struct libwebsocket *wsi);
Andy Green0d338332011-02-12 11:57:43 +0000389
390extern int
Peter Hinz56885f32011-03-02 22:03:47 +0000391delete_from_fd(struct libwebsocket_context *context, int fd);
Darin Willitsc19456f2011-02-14 17:52:39 +0000392
Andy Greenbe93fef2011-02-14 20:25:43 +0000393extern void
394libwebsocket_set_timeout(struct libwebsocket *wsi,
395 enum pending_timeout reason, int secs);
396
Peter Hinz56885f32011-03-02 22:03:47 +0000397extern int
Andy Greend44bf7f2011-03-06 10:29:38 +0000398lws_issue_raw(struct libwebsocket *wsi, unsigned char *buf, size_t len);
399
Andy Green95a7b5d2011-03-06 10:29:39 +0000400
Andy Greena41314f2011-05-23 10:00:03 +0100401extern void
402libwebsocket_service_timeout_check(struct libwebsocket_context *context,
403 struct libwebsocket *wsi, unsigned int sec);
404
Andy Green6ee372f2012-04-09 15:09:01 +0800405extern struct libwebsocket *
406__libwebsocket_client_connect_2(struct libwebsocket_context *context,
Andy Greena41314f2011-05-23 10:00:03 +0100407 struct libwebsocket *wsi);
408
409extern struct libwebsocket *
410libwebsocket_create_new_server_wsi(struct libwebsocket_context *context);
411
412extern char *
413libwebsockets_generate_client_handshake(struct libwebsocket_context *context,
414 struct libwebsocket *wsi, char *pkt);
415
416extern int
417lws_handle_POLLOUT_event(struct libwebsocket_context *context,
418 struct libwebsocket *wsi, struct pollfd *pollfd);
419
420extern int
421lws_any_extension_handled(struct libwebsocket_context *context,
Andy Green6ee372f2012-04-09 15:09:01 +0800422 struct libwebsocket *wsi,
423 enum libwebsocket_extension_callback_reasons r,
424 void *v, size_t len);
Andy Greena41314f2011-05-23 10:00:03 +0100425
426extern void *
427lws_get_extension_user_matching_ext(struct libwebsocket *wsi,
Andy Green6ee372f2012-04-09 15:09:01 +0800428 struct libwebsocket_extension *ext);
Andy Greena41314f2011-05-23 10:00:03 +0100429
430extern int
431lws_client_interpret_server_handshake(struct libwebsocket_context *context,
432 struct libwebsocket *wsi);
433
434extern int
435libwebsocket_rx_sm(struct libwebsocket *wsi, unsigned char c);
436
Andy Green09226502011-05-28 10:19:19 +0100437extern int
438lws_issue_raw_ext_access(struct libwebsocket *wsi,
439 unsigned char *buf, size_t len);
440
Darin Willitsc19456f2011-02-14 17:52:39 +0000441#ifndef LWS_OPENSSL_SUPPORT
442
443unsigned char *
444SHA1(const unsigned char *d, size_t n, unsigned char *md);
445
446void
447MD5(const unsigned char *input, int ilen, unsigned char *output);
448
449#endif