blob: ac261b5bf813b390909735d4728cdde19135b0d9 [file] [log] [blame]
Andy Greena0da8a82010-11-08 17:12:19 +00001/*
2 * libwebsockets - small server side websockets and web server implementation
Andy Greene77ddd82010-11-13 10:03:47 +00003 *
Andy Greena0da8a82010-11-08 17:12:19 +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 Greenab990e42010-10-31 12:42:52 +000022#ifndef __LIBWEBSOCKET_H__
23#define __LIBWEBSOCKET_H__
24
Andy Greena11fe942011-09-25 10:30:26 +010025#ifdef __cplusplus
26extern "C" {
Paulo Roberto Urio4144e832012-06-04 09:04:33 +080027#include <cstddef>
Andy Greena11fe942011-09-25 10:30:26 +010028#endif
29
Peter Hinz56885f32011-03-02 22:03:47 +000030#ifdef WIN32
31
32#ifndef WIN32_LEAN_AND_MEAN
33#define WIN32_LEAN_AND_MEAN
34#endif
35#include <winsock2.h>
36#include <ws2tcpip.h>
Paulo Roberto Urio4144e832012-06-04 09:04:33 +080037#include <stddef.h>
Andy Green2a480ea2012-04-12 10:54:22 +080038#include "../win32port/win32helpers/websock-w32.h"
Peter Hinz56885f32011-03-02 22:03:47 +000039
Andy Greena3147882012-04-12 11:02:06 +080040#include "../win32port/win32helpers/gettimeofday.h"
Michel Archambault03bec392011-05-24 17:15:25 +010041
Oleg Golosovskiy2ef75052011-10-04 20:20:14 +080042#define strcasecmp stricmp
43
David Brooks06fbcee2012-05-02 06:02:45 +080044typedef int ssize_t;
45
David Galeano9454e212011-09-26 12:17:20 +010046#ifdef LWS_DLL
47#ifdef LWS_INTERNAL
48#define LWS_EXTERN extern __declspec(dllexport)
49#else
50#define LWS_EXTERN extern __declspec(dllimport)
51#endif
52#endif
53
Peter Hinz56885f32011-03-02 22:03:47 +000054#else
Andy Green9f990342011-02-12 11:57:45 +000055#include <poll.h>
Peter Hinz56885f32011-03-02 22:03:47 +000056#endif
Andy Green9f990342011-02-12 11:57:45 +000057
David Galeano9454e212011-09-26 12:17:20 +010058#ifndef LWS_EXTERN
59#define LWS_EXTERN extern
60#endif
61
Andy Green4739e5c2011-01-22 12:51:57 +000062#define CONTEXT_PORT_NO_LISTEN 0
Andy Greena41314f2011-05-23 10:00:03 +010063#define MAX_MUX_RECURSION 2
Andy Greenbfb051f2011-02-09 08:49:14 +000064
Andy Green43db0452013-01-10 19:50:35 +080065enum lws_log_levels {
66 LLL_ERR = 1 << 0,
67 LLL_WARN = 1 << 1,
68 LLL_INFO = 1 << 2,
69 LLL_DEBUG = 1 << 3,
70 LLL_PARSER = 1 << 4,
71 LLL_HEADER = 1 << 5,
72 LLL_EXT = 1 << 6,
73 LLL_CLIENT = 1 << 7,
74
75 LLL_COUNT = 8 /* set to count of valid flags */
76};
77
Andy Greenbfb051f2011-02-09 08:49:14 +000078enum libwebsocket_context_options {
79 LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK = 1,
Andy Greenc6bf2c22011-02-20 11:10:47 +000080 LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT = 2,
Andy Green788c4a82012-10-22 12:29:57 +010081 LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME = 4,
Andy Greenbfb051f2011-02-09 08:49:14 +000082};
Andy Green8014b292011-01-30 20:57:25 +000083
Andy Green775c0dd2010-10-29 14:15:22 +010084enum libwebsocket_callback_reasons {
85 LWS_CALLBACK_ESTABLISHED,
David Brooks80a44972012-04-20 12:18:47 +080086 LWS_CALLBACK_CLIENT_CONNECTION_ERROR,
Andy Green90c7cbc2011-01-27 06:26:52 +000087 LWS_CALLBACK_CLIENT_ESTABLISHED,
Andy Green775c0dd2010-10-29 14:15:22 +010088 LWS_CALLBACK_CLOSED,
Andy Green775c0dd2010-10-29 14:15:22 +010089 LWS_CALLBACK_RECEIVE,
Andy Green4739e5c2011-01-22 12:51:57 +000090 LWS_CALLBACK_CLIENT_RECEIVE,
Andy Greena6cbece2011-01-27 20:06:03 +000091 LWS_CALLBACK_CLIENT_RECEIVE_PONG,
Andy Green90c7cbc2011-01-27 06:26:52 +000092 LWS_CALLBACK_CLIENT_WRITEABLE,
Andy Green9e4c2b62011-03-07 20:47:39 +000093 LWS_CALLBACK_SERVER_WRITEABLE,
Andy Greena2b0ab02010-11-11 12:28:29 +000094 LWS_CALLBACK_HTTP,
Andy Greend280b6e2013-01-15 13:40:23 +080095 LWS_CALLBACK_HTTP_FILE_COMPLETION,
Andy Green3221f922011-02-12 13:14:11 +000096 LWS_CALLBACK_BROADCAST,
Andy Green07034092011-02-13 08:37:12 +000097 LWS_CALLBACK_FILTER_NETWORK_CONNECTION,
Andy Greenc85619d2011-02-13 08:25:26 +000098 LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION,
Andy Green0894bda2011-02-19 09:09:11 +000099 LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS,
Andy Greenc6bf2c22011-02-20 11:10:47 +0000100 LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS,
Andy Green6901cb32011-02-21 08:06:47 +0000101 LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION,
Andy Green385e7ad2011-03-01 21:06:02 +0000102 LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER,
Andy Greenc5114822011-03-06 10:29:35 +0000103 LWS_CALLBACK_CONFIRM_EXTENSION_OKAY,
Andy Greenc6517fa2011-03-06 13:15:29 +0000104 LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED,
Andy Green3221f922011-02-12 13:14:11 +0000105 /* external poll() management support */
106 LWS_CALLBACK_ADD_POLL_FD,
107 LWS_CALLBACK_DEL_POLL_FD,
108 LWS_CALLBACK_SET_MODE_POLL_FD,
109 LWS_CALLBACK_CLEAR_MODE_POLL_FD,
Andy Green5fd8a5e2010-10-31 11:57:17 +0000110};
111
Andy Greenc5114822011-03-06 10:29:35 +0000112enum libwebsocket_extension_callback_reasons {
Andy Greena41314f2011-05-23 10:00:03 +0100113 LWS_EXT_CALLBACK_SERVER_CONTEXT_CONSTRUCT,
114 LWS_EXT_CALLBACK_CLIENT_CONTEXT_CONSTRUCT,
115 LWS_EXT_CALLBACK_SERVER_CONTEXT_DESTRUCT,
116 LWS_EXT_CALLBACK_CLIENT_CONTEXT_DESTRUCT,
Andy Greenc5114822011-03-06 10:29:35 +0000117 LWS_EXT_CALLBACK_CONSTRUCT,
Andy Green2366b1c2011-03-06 13:15:31 +0000118 LWS_EXT_CALLBACK_CLIENT_CONSTRUCT,
Andy Green68b45042011-05-25 21:41:57 +0100119 LWS_EXT_CALLBACK_CHECK_OK_TO_REALLY_CLOSE,
Andy Green09226502011-05-28 10:19:19 +0100120 LWS_EXT_CALLBACK_CHECK_OK_TO_PROPOSE_EXTENSION,
Andy Greenc5114822011-03-06 10:29:35 +0000121 LWS_EXT_CALLBACK_DESTROY,
Andy Greena41314f2011-05-23 10:00:03 +0100122 LWS_EXT_CALLBACK_DESTROY_ANY_WSI_CLOSING,
123 LWS_EXT_CALLBACK_ANY_WSI_ESTABLISHED,
Andy Green98a717c2011-03-06 13:14:15 +0000124 LWS_EXT_CALLBACK_PACKET_RX_PREPARSE,
Andy Green3b84c002011-03-06 13:14:42 +0000125 LWS_EXT_CALLBACK_PACKET_TX_PRESEND,
Andy Greena41314f2011-05-23 10:00:03 +0100126 LWS_EXT_CALLBACK_PACKET_TX_DO_SEND,
127 LWS_EXT_CALLBACK_HANDSHAKE_REPLY_TX,
Andy Greenc44159f2011-03-07 07:08:18 +0000128 LWS_EXT_CALLBACK_FLUSH_PENDING_TX,
Andy Greena41314f2011-05-23 10:00:03 +0100129 LWS_EXT_CALLBACK_EXTENDED_PAYLOAD_RX,
130 LWS_EXT_CALLBACK_CAN_PROXY_CLIENT_CONNECTION,
131 LWS_EXT_CALLBACK_1HZ,
132 LWS_EXT_CALLBACK_REQUEST_ON_WRITEABLE,
133 LWS_EXT_CALLBACK_IS_WRITEABLE,
David Galeanoe2cf9922013-01-09 18:06:55 +0800134 LWS_EXT_CALLBACK_PAYLOAD_TX,
135 LWS_EXT_CALLBACK_PAYLOAD_RX,
Andy Greenc5114822011-03-06 10:29:35 +0000136};
137
Andy Green5fd8a5e2010-10-31 11:57:17 +0000138enum libwebsocket_write_protocol {
139 LWS_WRITE_TEXT,
140 LWS_WRITE_BINARY,
Andy Green5d9d94b2011-03-07 20:47:41 +0000141 LWS_WRITE_CONTINUATION,
Andy Green38e57bb2011-01-19 12:20:27 +0000142 LWS_WRITE_HTTP,
143
Andy Green5e1fa172011-02-10 09:07:05 +0000144 /* special 04+ opcodes */
Andy Green38e57bb2011-01-19 12:20:27 +0000145
146 LWS_WRITE_CLOSE,
147 LWS_WRITE_PING,
Andy Green90c7cbc2011-01-27 06:26:52 +0000148 LWS_WRITE_PONG,
149
Andy Greenbd96d802011-01-30 08:24:31 +0000150 /* flags */
151
152 LWS_WRITE_NO_FIN = 0x40,
153 /*
154 * client packet payload goes out on wire unmunged
155 * only useful for security tests since normal servers cannot
156 * decode the content if used
157 */
158 LWS_WRITE_CLIENT_IGNORE_XOR_MASK = 0x80
Andy Greenff95d7a2010-10-28 22:36:01 +0100159};
160
Andy Greenc85619d2011-02-13 08:25:26 +0000161/*
162 * you need these to look at headers that have been parsed if using the
163 * LWS_CALLBACK_FILTER_CONNECTION callback. If a header from the enum
164 * list below is absent, .token = NULL and token_len = 0. Otherwise .token
165 * points to .token_len chars containing that header content.
166 */
167
168struct lws_tokens {
169 char *token;
170 int token_len;
171};
172
173enum lws_token_indexes {
174 WSI_TOKEN_GET_URI,
175 WSI_TOKEN_HOST,
176 WSI_TOKEN_CONNECTION,
177 WSI_TOKEN_KEY1,
178 WSI_TOKEN_KEY2,
179 WSI_TOKEN_PROTOCOL,
180 WSI_TOKEN_UPGRADE,
181 WSI_TOKEN_ORIGIN,
182 WSI_TOKEN_DRAFT,
183 WSI_TOKEN_CHALLENGE,
184
185 /* new for 04 */
186 WSI_TOKEN_KEY,
187 WSI_TOKEN_VERSION,
188 WSI_TOKEN_SWORIGIN,
189
190 /* new for 05 */
191 WSI_TOKEN_EXTENSIONS,
192
193 /* client receives these */
194 WSI_TOKEN_ACCEPT,
195 WSI_TOKEN_NONCE,
196 WSI_TOKEN_HTTP,
Andy Greena41314f2011-05-23 10:00:03 +0100197 WSI_TOKEN_MUXURL,
Andy Greenc85619d2011-02-13 08:25:26 +0000198
199 /* always last real token index*/
200 WSI_TOKEN_COUNT,
201 /* parser state additions */
202 WSI_TOKEN_NAME_PART,
203 WSI_TOKEN_SKIPPING,
204 WSI_TOKEN_SKIPPING_SAW_CR,
Andy Greena41314f2011-05-23 10:00:03 +0100205 WSI_PARSING_COMPLETE,
206 WSI_INIT_TOKEN_MUXURL,
Andy Greenc85619d2011-02-13 08:25:26 +0000207};
208
Andy Green687b0182011-02-26 11:04:01 +0000209/*
David Galeano2915a802013-01-09 15:26:08 +0800210 * From RFC 6455
Andy Green687b0182011-02-26 11:04:01 +0000211 1000
212
David Galeano2915a802013-01-09 15:26:08 +0800213 1000 indicates a normal closure, meaning that the purpose for
214 which the connection was established has been fulfilled.
Andy Green687b0182011-02-26 11:04:01 +0000215
216 1001
217
218 1001 indicates that an endpoint is "going away", such as a server
David Galeano2915a802013-01-09 15:26:08 +0800219 going down or a browser having navigated away from a page.
Andy Green687b0182011-02-26 11:04:01 +0000220
221 1002
222
223 1002 indicates that an endpoint is terminating the connection due
224 to a protocol error.
225
226 1003
227
228 1003 indicates that an endpoint is terminating the connection
David Galeano2915a802013-01-09 15:26:08 +0800229 because it has received a type of data it cannot accept (e.g., an
230 endpoint that understands only text data MAY send this if it
231 receives a binary message).
Andy Green687b0182011-02-26 11:04:01 +0000232
233 1004
234
David Galeano2915a802013-01-09 15:26:08 +0800235 Reserved. The specific meaning might be defined in the future.
236
237 1005
238
239 1005 is a reserved value and MUST NOT be set as a status code in a
240 Close control frame by an endpoint. It is designated for use in
241 applications expecting a status code to indicate that no status
242 code was actually present.
243
244 1006
245
246 1006 is a reserved value and MUST NOT be set as a status code in a
247 Close control frame by an endpoint. It is designated for use in
248 applications expecting a status code to indicate that the
249 connection was closed abnormally, e.g., without sending or
250 receiving a Close control frame.
251
252 1007
253
254 1007 indicates that an endpoint is terminating the connection
255 because it has received data within a message that was not
256 consistent with the type of the message (e.g., non-UTF-8 [RFC3629]
257 data within a text message).
258
259 1008
260
261 1008 indicates that an endpoint is terminating the connection
262 because it has received a message that violates its policy. This
263 is a generic status code that can be returned when there is no
264 other more suitable status code (e.g., 1003 or 1009) or if there
265 is a need to hide specific details about the policy.
266
267 1009
268
269 1009 indicates that an endpoint is terminating the connection
270 because it has received a message that is too big for it to
271 process.
272
273 1010
274
275 1010 indicates that an endpoint (client) is terminating the
276 connection because it has expected the server to negotiate one or
277 more extension, but the server didn't return them in the response
278 message of the WebSocket handshake. The list of extensions that
279 are needed SHOULD appear in the /reason/ part of the Close frame.
280 Note that this status code is not used by the server, because it
281 can fail the WebSocket handshake instead.
282
283 1011
284
285 1011 indicates that a server is terminating the connection because
286 it encountered an unexpected condition that prevented it from
287 fulfilling the request.
288
289 1015
290
291 1015 is a reserved value and MUST NOT be set as a status code in a
292 Close control frame by an endpoint. It is designated for use in
293 applications expecting a status code to indicate that the
294 connection was closed due to a failure to perform a TLS handshake
295 (e.g., the server certificate can't be verified).
Andy Green687b0182011-02-26 11:04:01 +0000296*/
297
298enum lws_close_status {
299 LWS_CLOSE_STATUS_NOSTATUS = 0,
300 LWS_CLOSE_STATUS_NORMAL = 1000,
301 LWS_CLOSE_STATUS_GOINGAWAY = 1001,
302 LWS_CLOSE_STATUS_PROTOCOL_ERR = 1002,
303 LWS_CLOSE_STATUS_UNACCEPTABLE_OPCODE = 1003,
David Galeano2915a802013-01-09 15:26:08 +0800304 LWS_CLOSE_STATUS_RESERVED = 1004,
305 LWS_CLOSE_STATUS_NO_STATUS = 1005,
306 LWS_CLOSE_STATUS_ABNORMAL_CLOSE = 1006,
307 LWS_CLOSE_STATUS_INVALID_PAYLOAD = 1007,
308 LWS_CLOSE_STATUS_POLICY_VIOLATION = 1008,
309 LWS_CLOSE_STATUS_MESSAGE_TOO_LARGE = 1009,
310 LWS_CLOSE_STATUS_EXTENSION_REQUIRED = 1010,
311 LWS_CLOSE_STATUS_UNEXPECTED_CONDITION = 1011,
312 LWS_CLOSE_STATUS_TLS_FAILURE = 1015,
Andy Green687b0182011-02-26 11:04:01 +0000313};
314
Andy Green775c0dd2010-10-29 14:15:22 +0100315struct libwebsocket;
Andy Greenb45993c2010-12-18 15:13:50 +0000316struct libwebsocket_context;
Andy Green46c2ea02011-03-22 09:04:01 +0000317struct libwebsocket_extension;
Andy Greenff95d7a2010-10-28 22:36:01 +0100318
Andy Green8f037e42010-12-19 22:13:26 +0000319/**
David Brooks6c6a3d32012-04-20 12:13:50 +0800320 * callback_function() - User server actions
Andy Green32375b72011-02-19 08:32:53 +0000321 * @context: Websockets context
Andy Green8f037e42010-12-19 22:13:26 +0000322 * @wsi: Opaque websocket instance pointer
323 * @reason: The reason for the call
324 * @user: Pointer to per-session user data allocated by library
325 * @in: Pointer used for some callback reasons
326 * @len: Length set for some callback reasons
327 *
328 * This callback is the way the user controls what is served. All the
329 * protocol detail is hidden and handled by the library.
Andy Green6964bb52011-01-23 16:50:33 +0000330 *
Andy Green8f037e42010-12-19 22:13:26 +0000331 * For each connection / session there is user data allocated that is
332 * pointed to by "user". You set the size of this user data area when
333 * the library is initialized with libwebsocket_create_server.
Andy Green6964bb52011-01-23 16:50:33 +0000334 *
Andy Green8f037e42010-12-19 22:13:26 +0000335 * You get an opportunity to initialize user data when called back with
336 * LWS_CALLBACK_ESTABLISHED reason.
337 *
Andy Green90c7cbc2011-01-27 06:26:52 +0000338 * LWS_CALLBACK_ESTABLISHED: after the server completes a handshake with
339 * an incoming client
340 *
David Brooks80a44972012-04-20 12:18:47 +0800341 * LWS_CALLBACK_CLIENT_CONNECTION_ERROR: the request client connection has
342 * been unable to complete a handshake with the remote server
343 *
344 * LWS_CALLBACK_CLIENT_ESTABLISHED: after your client connection completed
Andy Green90c7cbc2011-01-27 06:26:52 +0000345 * a handshake with the remote server
Andy Green8f037e42010-12-19 22:13:26 +0000346 *
347 * LWS_CALLBACK_CLOSED: when the websocket session ends
348 *
349 * LWS_CALLBACK_BROADCAST: signal to send to client (you would use
350 * libwebsocket_write() taking care about the
351 * special buffer requirements
Andy Green90c7cbc2011-01-27 06:26:52 +0000352 *
353 * LWS_CALLBACK_RECEIVE: data has appeared for this server endpoint from a
354 * remote client, it can be found at *in and is
355 * len bytes long
356 *
Andy Greena6cbece2011-01-27 20:06:03 +0000357 * LWS_CALLBACK_CLIENT_RECEIVE_PONG: if you elected to see PONG packets,
358 * they appear with this callback reason. PONG
359 * packets only exist in 04+ protocol
360 *
Andy Green90c7cbc2011-01-27 06:26:52 +0000361 * LWS_CALLBACK_CLIENT_RECEIVE: data has appeared from the server for the
362 * client connection, it can be found at *in and
363 * is len bytes long
Andy Green8f037e42010-12-19 22:13:26 +0000364 *
Andy Green6964bb52011-01-23 16:50:33 +0000365 * LWS_CALLBACK_HTTP: an http request has come from a client that is not
Andy Green8f037e42010-12-19 22:13:26 +0000366 * asking to upgrade the connection to a websocket
367 * one. This is a chance to serve http content,
368 * for example, to send a script to the client
369 * which will then open the websockets connection.
Andy Green6964bb52011-01-23 16:50:33 +0000370 * @in points to the URI path requested and
Andy Green8f037e42010-12-19 22:13:26 +0000371 * libwebsockets_serve_http_file() makes it very
372 * simple to send back a file to the client.
Andy Green24b588b2013-01-13 09:53:18 +0800373 * Normally after sending the file you are done
374 * with the http connection, since the rest of the
375 * activity will come by websockets from the script
376 * that was delivered by http, so you will want to
377 * return 1; to close and free up the connection.
378 * That's important because it uses a slot in the
379 * total number of client connections allowed set
380 * by MAX_CLIENTS.
Andy Green90c7cbc2011-01-27 06:26:52 +0000381 *
Andy Greend280b6e2013-01-15 13:40:23 +0800382 * LWS_CALLBACK_HTTP_FILE_COMPLETION: a file requested to be send down
383 * http link has completed.
384 *
Andy Green9e4c2b62011-03-07 20:47:39 +0000385 * LWS_CALLBACK_CLIENT_WRITEABLE:
386 * LWS_CALLBACK_SERVER_WRITEABLE: If you call
Andy Green90c7cbc2011-01-27 06:26:52 +0000387 * libwebsocket_callback_on_writable() on a connection, you will
Andy Green9e4c2b62011-03-07 20:47:39 +0000388 * get one of these callbacks coming when the connection socket
389 * is able to accept another write packet without blocking.
390 * If it already was able to take another packet without blocking,
391 * you'll get this callback at the next call to the service loop
392 * function. Notice that CLIENTs get LWS_CALLBACK_CLIENT_WRITEABLE
393 * and servers get LWS_CALLBACK_SERVER_WRITEABLE.
Andy Greene7981dc2011-02-12 21:24:03 +0000394 *
Andy Green07034092011-02-13 08:37:12 +0000395 * LWS_CALLBACK_FILTER_NETWORK_CONNECTION: called when a client connects to
396 * the server at network level; the connection is accepted but then
397 * passed to this callback to decide whether to hang up immediately
398 * or not, based on the client IP. @user contains the connection
399 * socket's descriptor. Return non-zero to terminate
400 * the connection before sending or receiving anything.
401 * Because this happens immediately after the network connection
402 * from the client, there's no websocket protocol selected yet so
403 * this callback is issued only to protocol 0.
404 *
Andy Greenc85619d2011-02-13 08:25:26 +0000405 * LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION: called when the handshake has
406 * been received and parsed from the client, but the response is
407 * not sent yet. Return non-zero to disallow the connection.
408 * @user is a pointer to an array of struct lws_tokens, you can
409 * use the header enums lws_token_indexes from libwebsockets.h
410 * to check for and read the supported header presence and
411 * content before deciding to allow the handshake to proceed or
412 * to kill the connection.
413 *
Andy Greenc6bf2c22011-02-20 11:10:47 +0000414 * LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS: if configured for
Andy Green0894bda2011-02-19 09:09:11 +0000415 * including OpenSSL support, this callback allows your user code
416 * to perform extra SSL_CTX_load_verify_locations() or similar
417 * calls to direct OpenSSL where to find certificates the client
418 * can use to confirm the remote server identity. @user is the
419 * OpenSSL SSL_CTX*
Andy Greenc85619d2011-02-13 08:25:26 +0000420 *
Andy Greenc6bf2c22011-02-20 11:10:47 +0000421 * LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS: if configured for
422 * including OpenSSL support, this callback allows your user code
423 * to load extra certifcates into the server which allow it to
424 * verify the validity of certificates returned by clients. @user
425 * is the server's OpenSSL SSL_CTX*
426 *
Andy Green6901cb32011-02-21 08:06:47 +0000427 * LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION: if the
428 * libwebsockets context was created with the option
429 * LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT, then this
430 * callback is generated during OpenSSL verification of the cert
431 * sent from the client. It is sent to protocol[0] callback as
432 * no protocol has been negotiated on the connection yet.
433 * Notice that the libwebsockets context and wsi are both NULL
434 * during this callback. See
435 * http://www.openssl.org/docs/ssl/SSL_CTX_set_verify.html
436 * to understand more detail about the OpenSSL callback that
437 * generates this libwebsockets callback and the meanings of the
438 * arguments passed. In this callback, @user is the x509_ctx,
439 * @in is the ssl pointer and @len is preverify_ok
440 * Notice that this callback maintains libwebsocket return
441 * conventions, return 0 to mean the cert is OK or 1 to fail it.
442 * This also means that if you don't handle this callback then
443 * the default callback action of returning 0 allows the client
444 * certificates.
445 *
Andy Green385e7ad2011-03-01 21:06:02 +0000446 * LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: this callback happens
447 * when a client handshake is being compiled. @user is NULL,
448 * @in is a char **, it's pointing to a char * which holds the
449 * next location in the header buffer where you can add
450 * headers, and @len is the remaining space in the header buffer,
451 * which is typically some hundreds of bytes. So, to add a canned
452 * cookie, your handler code might look similar to:
453 *
454 * char **p = (char **)in;
455 *
456 * if (len < 100)
457 * return 1;
458 *
459 * *p += sprintf(*p, "Cookie: a=b\x0d\x0a");
460 *
461 * return 0;
462 *
463 * Notice if you add anything, you just have to take care about
464 * the CRLF on the line you added. Obviously this callback is
465 * optional, if you don't handle it everything is fine.
466 *
467 * Notice the callback is coming to protocols[0] all the time,
468 * because there is no specific protocol handshook yet.
469 *
Andy Greenc5114822011-03-06 10:29:35 +0000470 * LWS_CALLBACK_CONFIRM_EXTENSION_OKAY: When the server handshake code
471 * sees that it does support a requested extension, before
472 * accepting the extension by additing to the list sent back to
473 * the client it gives this callback just to check that it's okay
474 * to use that extension. It calls back to the requested protocol
475 * and with @in being the extension name, @len is 0 and @user is
476 * valid. Note though at this time the ESTABLISHED callback hasn't
477 * happened yet so if you initialize @user content there, @user
478 * content during this callback might not be useful for anything.
479 * Notice this callback comes to protocols[0].
480 *
Andy Greenc6517fa2011-03-06 13:15:29 +0000481 * LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED: When a client
482 * connection is being prepared to start a handshake to a server,
483 * each supported extension is checked with protocols[0] callback
484 * with this reason, giving the user code a chance to suppress the
485 * claim to support that extension by returning non-zero. If
486 * unhandled, by default 0 will be returned and the extension
487 * support included in the header to the server. Notice this
488 * callback comes to protocols[0].
489 *
Andy Greene7981dc2011-02-12 21:24:03 +0000490 * The next four reasons are optional and only need taking care of if you
491 * will be integrating libwebsockets sockets into an external polling
492 * array.
493 *
494 * LWS_CALLBACK_ADD_POLL_FD: libwebsocket deals with its poll() loop
495 * internally, but in the case you are integrating with another
496 * server you will need to have libwebsocket sockets share a
497 * polling array with the other server. This and the other
498 * POLL_FD related callbacks let you put your specialized
499 * poll array interface code in the callback for protocol 0, the
500 * first protocol you support, usually the HTTP protocol in the
501 * serving case. This callback happens when a socket needs to be
502 * added to the polling loop: @user contains the fd, and
503 * @len is the events bitmap (like, POLLIN). If you are using the
504 * internal polling loop (the "service" callback), you can just
505 * ignore these callbacks.
506 *
507 * LWS_CALLBACK_DEL_POLL_FD: This callback happens when a socket descriptor
508 * needs to be removed from an external polling array. @user is
509 * the socket desricptor. If you are using the internal polling
510 * loop, you can just ignore it.
511 *
512 * LWS_CALLBACK_SET_MODE_POLL_FD: This callback happens when libwebsockets
513 * wants to modify the events for the socket descriptor in @user.
514 * The handler should OR @len on to the events member of the pollfd
515 * struct for this socket descriptor. If you are using the
516 * internal polling loop, you can just ignore it.
517 *
518 * LWS_CALLBACK_CLEAR_MODE_POLL_FD: This callback occurs when libwebsockets
519 * wants to modify the events for the socket descriptor in @user.
520 * The handler should AND ~@len on to the events member of the
521 * pollfd struct for this socket descriptor. If you are using the
522 * internal polling loop, you can just ignore it.
Andy Green8f037e42010-12-19 22:13:26 +0000523 */
David Galeano9454e212011-09-26 12:17:20 +0100524LWS_EXTERN int callback(struct libwebsocket_context * context,
Andy Green62c54d22011-02-14 09:14:25 +0000525 struct libwebsocket *wsi,
Andy Green6964bb52011-01-23 16:50:33 +0000526 enum libwebsocket_callback_reasons reason, void *user,
Andy Green8f037e42010-12-19 22:13:26 +0000527 void *in, size_t len);
528
David Brooks6c6a3d32012-04-20 12:13:50 +0800529typedef int (callback_function)(struct libwebsocket_context * context,
530 struct libwebsocket *wsi,
531 enum libwebsocket_callback_reasons reason, void *user,
532 void *in, size_t len);
533
534
Andy Green57b4e9a2011-03-06 13:14:46 +0000535/**
David Brooks6c6a3d32012-04-20 12:13:50 +0800536 * extension_callback_function() - Hooks to allow extensions to operate
Andy Green57b4e9a2011-03-06 13:14:46 +0000537 * @context: Websockets context
Andy Green46c2ea02011-03-22 09:04:01 +0000538 * @ext: This extension
Andy Green57b4e9a2011-03-06 13:14:46 +0000539 * @wsi: Opaque websocket instance pointer
540 * @reason: The reason for the call
541 * @user: Pointer to per-session user data allocated by library
542 * @in: Pointer used for some callback reasons
543 * @len: Length set for some callback reasons
544 *
545 * Each extension that is active on a particular connection receives
546 * callbacks during the connection lifetime to allow the extension to
547 * operate on websocket data and manage itself.
548 *
549 * Libwebsockets takes care of allocating and freeing "user" memory for
550 * each active extension on each connection. That is what is pointed to
551 * by the @user parameter.
552 *
553 * LWS_EXT_CALLBACK_CONSTRUCT: called when the server has decided to
554 * select this extension from the list provided by the client,
555 * just before the server will send back the handshake accepting
556 * the connection with this extension active. This gives the
557 * extension a chance to initialize its connection context found
558 * in @user.
559 *
Andy Green2366b1c2011-03-06 13:15:31 +0000560 * LWS_EXT_CALLBACK_CLIENT_CONSTRUCT: same as LWS_EXT_CALLBACK_CONSTRUCT
561 * but called when client is instantiating this extension. Some
562 * extensions will work the same on client and server side and then
563 * you can just merge handlers for both CONSTRUCTS.
564 *
Andy Green57b4e9a2011-03-06 13:14:46 +0000565 * LWS_EXT_CALLBACK_DESTROY: called when the connection the extension was
566 * being used on is about to be closed and deallocated. It's the
567 * last chance for the extension to deallocate anything it has
568 * allocated in the user data (pointed to by @user) before the
Andy Green2366b1c2011-03-06 13:15:31 +0000569 * user data is deleted. This same callback is used whether you
570 * are in client or server instantiation context.
Andy Green57b4e9a2011-03-06 13:14:46 +0000571 *
572 * LWS_EXT_CALLBACK_PACKET_RX_PREPARSE: when this extension was active on
573 * a connection, and a packet of data arrived at the connection,
574 * it is passed to this callback to give the extension a chance to
575 * change the data, eg, decompress it. @user is pointing to the
576 * extension's private connection context data, @in is pointing
577 * to an lws_tokens struct, it consists of a char * pointer called
578 * token, and an int called token_len. At entry, these are
579 * set to point to the received buffer and set to the content
580 * length. If the extension will grow the content, it should use
581 * a new buffer allocated in its private user context data and
582 * set the pointed-to lws_tokens members to point to its buffer.
583 *
584 * LWS_EXT_CALLBACK_PACKET_TX_PRESEND: this works the same way as
585 * LWS_EXT_CALLBACK_PACKET_RX_PREPARSE above, except it gives the
586 * extension a chance to change websocket data just before it will
587 * be sent out. Using the same lws_token pointer scheme in @in,
588 * the extension can change the buffer and the length to be
589 * transmitted how it likes. Again if it wants to grow the
590 * buffer safely, it should copy the data into its own buffer and
591 * set the lws_tokens token pointer to it.
592 */
David Galeano9454e212011-09-26 12:17:20 +0100593LWS_EXTERN int extension_callback(struct libwebsocket_context * context,
Andy Green46c2ea02011-03-22 09:04:01 +0000594 struct libwebsocket_extension *ext,
Andy Green57b4e9a2011-03-06 13:14:46 +0000595 struct libwebsocket *wsi,
David Brooks6c6a3d32012-04-20 12:13:50 +0800596 enum libwebsocket_extension_callback_reasons reason, void *user,
Andy Green57b4e9a2011-03-06 13:14:46 +0000597 void *in, size_t len);
598
David Brooks6c6a3d32012-04-20 12:13:50 +0800599typedef int (extension_callback_function)(struct libwebsocket_context * context,
600 struct libwebsocket_extension *ext,
601 struct libwebsocket *wsi,
602 enum libwebsocket_extension_callback_reasons reason, void *user,
603 void *in, size_t len);
Andy Green57b4e9a2011-03-06 13:14:46 +0000604
Andy Green4f3943a2010-11-12 10:44:16 +0000605/**
Andy Green6964bb52011-01-23 16:50:33 +0000606 * struct libwebsocket_protocols - List of protocols and handlers server
607 * supports.
Andy Green4f3943a2010-11-12 10:44:16 +0000608 * @name: Protocol name that must match the one given in the client
Andy Green6964bb52011-01-23 16:50:33 +0000609 * Javascript new WebSocket(url, 'protocol') name
Andy Green4f3943a2010-11-12 10:44:16 +0000610 * @callback: The service callback used for this protocol. It allows the
Andy Green6964bb52011-01-23 16:50:33 +0000611 * service action for an entire protocol to be encapsulated in
612 * the protocol-specific callback
Andy Green4f3943a2010-11-12 10:44:16 +0000613 * @per_session_data_size: Each new connection using this protocol gets
Andy Green6964bb52011-01-23 16:50:33 +0000614 * this much memory allocated on connection establishment and
615 * freed on connection takedown. A pointer to this per-connection
616 * allocation is passed into the callback in the 'user' parameter
Andy Greenb45993c2010-12-18 15:13:50 +0000617 * @owning_server: the server init call fills in this opaque pointer when
Andy Green6964bb52011-01-23 16:50:33 +0000618 * registering this protocol with the server.
Andy Greenb45993c2010-12-18 15:13:50 +0000619 * @broadcast_socket_port: the server init call fills this in with the
Andy Green6964bb52011-01-23 16:50:33 +0000620 * localhost port number used to forward broadcasts for this
621 * protocol
Andy Greenb45993c2010-12-18 15:13:50 +0000622 * @broadcast_socket_user_fd: the server init call fills this in ... the main()
Andy Green6964bb52011-01-23 16:50:33 +0000623 * process context can write to this socket to perform broadcasts
624 * (use the libwebsockets_broadcast() api to do this instead,
625 * it works from any process context)
Andy Greenb45993c2010-12-18 15:13:50 +0000626 * @protocol_index: which protocol we are starting from zero
Andy Greene77ddd82010-11-13 10:03:47 +0000627 *
Andy Green6964bb52011-01-23 16:50:33 +0000628 * This structure represents one protocol supported by the server. An
629 * array of these structures is passed to libwebsocket_create_server()
630 * allows as many protocols as you like to be handled by one server.
Andy Green4f3943a2010-11-12 10:44:16 +0000631 */
632
633struct libwebsocket_protocols {
634 const char *name;
David Brooks6c6a3d32012-04-20 12:13:50 +0800635 callback_function *callback;
Andy Green4f3943a2010-11-12 10:44:16 +0000636 size_t per_session_data_size;
Andy Greenb45993c2010-12-18 15:13:50 +0000637
638 /*
639 * below are filled in on server init and can be left uninitialized,
640 * no need for user to use them directly either
641 */
Andy Green6964bb52011-01-23 16:50:33 +0000642
Andy Greenb45993c2010-12-18 15:13:50 +0000643 struct libwebsocket_context *owning_server;
644 int broadcast_socket_port;
645 int broadcast_socket_user_fd;
646 int protocol_index;
Andy Green4f3943a2010-11-12 10:44:16 +0000647};
648
Andy Greend6e09112011-03-05 16:12:15 +0000649/**
650 * struct libwebsocket_extension - An extension we know how to cope with
651 *
652 * @name: Formal extension name, eg, "deflate-stream"
653 * @callback: Service callback
654 * @per_session_data_size: Libwebsockets will auto-malloc this much
655 * memory for the use of the extension, a pointer
656 * to it comes in the @user callback parameter
Andy Greendc361922012-04-12 11:15:23 +0800657 * @per_context_private_data: Optional storage for this externsion that
658 * is per-context, so it can track stuff across
659 * all sessions, etc, if it wants
Andy Greend6e09112011-03-05 16:12:15 +0000660 */
661
662struct libwebsocket_extension {
663 const char *name;
David Brooks6c6a3d32012-04-20 12:13:50 +0800664 extension_callback_function *callback;
Andy Greend6e09112011-03-05 16:12:15 +0000665 size_t per_session_data_size;
Andy Greena41314f2011-05-23 10:00:03 +0100666 void * per_context_private_data;
Andy Greend6e09112011-03-05 16:12:15 +0000667};
668
Andy Green43db0452013-01-10 19:50:35 +0800669LWS_EXTERN
Andy Greende8f27a2013-01-12 09:17:42 +0800670void lws_set_log_level(int level, void (*log_emit_function)(const char *line));
Andy Greend6e09112011-03-05 16:12:15 +0000671
David Galeano9454e212011-09-26 12:17:20 +0100672LWS_EXTERN struct libwebsocket_context *
Peter Hinz56885f32011-03-02 22:03:47 +0000673libwebsocket_create_context(int port, const char * interf,
Andy Greenb45993c2010-12-18 15:13:50 +0000674 struct libwebsocket_protocols *protocols,
Andy Greend6e09112011-03-05 16:12:15 +0000675 struct libwebsocket_extension *extensions,
Andy Greene77ddd82010-11-13 10:03:47 +0000676 const char *ssl_cert_filepath,
David Galeano2f82be82013-01-09 16:25:54 +0800677 const char *ssl_private_key_filepath,
678 const char *ssl_ca_filepath,
679 int gid, int uid,
Alon Levy0291eb32012-10-19 11:21:56 +0200680 unsigned int options, void *user);
Andy Greenff95d7a2010-10-28 22:36:01 +0100681
David Galeano9454e212011-09-26 12:17:20 +0100682LWS_EXTERN void
Darin Willitsc19456f2011-02-14 17:52:39 +0000683libwebsocket_context_destroy(struct libwebsocket_context *context);
Andy Green6964bb52011-01-23 16:50:33 +0000684
David Galeano9454e212011-09-26 12:17:20 +0100685LWS_EXTERN int
Darin Willitsc19456f2011-02-14 17:52:39 +0000686libwebsockets_fork_service_loop(struct libwebsocket_context *context);
Andy Greene92cd172011-01-19 13:11:55 +0000687
David Galeano9454e212011-09-26 12:17:20 +0100688LWS_EXTERN int
Darin Willitsc19456f2011-02-14 17:52:39 +0000689libwebsocket_service(struct libwebsocket_context *context, int timeout_ms);
Andy Greene92cd172011-01-19 13:11:55 +0000690
David Galeano9454e212011-09-26 12:17:20 +0100691LWS_EXTERN int
Darin Willitsc19456f2011-02-14 17:52:39 +0000692libwebsocket_service_fd(struct libwebsocket_context *context,
Andy Green9f990342011-02-12 11:57:45 +0000693 struct pollfd *pollfd);
694
Alon Levy0291eb32012-10-19 11:21:56 +0200695LWS_EXTERN void *
696libwebsocket_context_user(struct libwebsocket_context *context);
697
Andy Green4ea60062010-10-30 12:15:07 +0100698/*
699 * IMPORTANT NOTICE!
Andy Greene77ddd82010-11-13 10:03:47 +0000700 *
Andy Green5fd8a5e2010-10-31 11:57:17 +0000701 * When sending with websocket protocol (LWS_WRITE_TEXT or LWS_WRITE_BINARY)
702 * the send buffer has to have LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE
Andy Green4ea60062010-10-30 12:15:07 +0100703 * buf, and LWS_SEND_BUFFER_POST_PADDING bytes valid AFTER (buf + len).
Andy Greene77ddd82010-11-13 10:03:47 +0000704 *
Andy Green4ea60062010-10-30 12:15:07 +0100705 * This allows us to add protocol info before and after the data, and send as
706 * one packet on the network without payload copying, for maximum efficiency.
Andy Greene77ddd82010-11-13 10:03:47 +0000707 *
Andy Green4ea60062010-10-30 12:15:07 +0100708 * So for example you need this kind of code to use libwebsocket_write with a
Andy Greene77ddd82010-11-13 10:03:47 +0000709 * 128-byte payload
710 *
Andy Greenab990e42010-10-31 12:42:52 +0000711 * char buf[LWS_SEND_BUFFER_PRE_PADDING + 128 + LWS_SEND_BUFFER_POST_PADDING];
Andy Greene77ddd82010-11-13 10:03:47 +0000712 *
Andy Greenab990e42010-10-31 12:42:52 +0000713 * // fill your part of the buffer... for example here it's all zeros
714 * memset(&buf[LWS_SEND_BUFFER_PRE_PADDING], 0, 128);
Andy Greene77ddd82010-11-13 10:03:47 +0000715 *
Andy Greenab990e42010-10-31 12:42:52 +0000716 * libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], 128);
Andy Greene77ddd82010-11-13 10:03:47 +0000717 *
Andy Green5fd8a5e2010-10-31 11:57:17 +0000718 * When sending LWS_WRITE_HTTP, there is no protocol addition and you can just
719 * use the whole buffer without taking care of the above.
Andy Green4ea60062010-10-30 12:15:07 +0100720 */
721
Andy Green687b0182011-02-26 11:04:01 +0000722/*
723 * this is the frame nonce plus two header plus 8 length
Andy Greena41314f2011-05-23 10:00:03 +0100724 * there's an additional two for mux extension per mux nesting level
Andy Green687b0182011-02-26 11:04:01 +0000725 * 2 byte prepend on close will already fit because control frames cannot use
726 * the big length style
727 */
Andy Green4739e5c2011-01-22 12:51:57 +0000728
Andy Greena41314f2011-05-23 10:00:03 +0100729#define LWS_SEND_BUFFER_PRE_PADDING (4 + 10 + (2 * MAX_MUX_RECURSION))
David Galeanoe2cf9922013-01-09 18:06:55 +0800730#define LWS_SEND_BUFFER_POST_PADDING 4
Andy Green4ea60062010-10-30 12:15:07 +0100731
David Galeano9454e212011-09-26 12:17:20 +0100732LWS_EXTERN int
Andy Greene77ddd82010-11-13 10:03:47 +0000733libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf, size_t len,
Andy Green5fd8a5e2010-10-31 11:57:17 +0000734 enum libwebsocket_write_protocol protocol);
Andy Greena2b0ab02010-11-11 12:28:29 +0000735
David Galeano9454e212011-09-26 12:17:20 +0100736LWS_EXTERN int
Andy Greend280b6e2013-01-15 13:40:23 +0800737libwebsockets_serve_http_file(struct libwebsocket_context *context,
738 struct libwebsocket *wsi, const char *file,
Andy Greene77ddd82010-11-13 10:03:47 +0000739 const char *content_type);
Andy Greend280b6e2013-01-15 13:40:23 +0800740LWS_EXTERN int
741libwebsockets_serve_http_file_fragment(struct libwebsocket_context *context,
742 struct libwebsocket *wsi);
Andy Greenab990e42010-10-31 12:42:52 +0000743
Andy Greenb45993c2010-12-18 15:13:50 +0000744/* notice - you need the pre- and post- padding allocation for buf below */
745
David Galeano9454e212011-09-26 12:17:20 +0100746LWS_EXTERN int
Andy Green6964bb52011-01-23 16:50:33 +0000747libwebsockets_broadcast(const struct libwebsocket_protocols *protocol,
Andy Greenb45993c2010-12-18 15:13:50 +0000748 unsigned char *buf, size_t len);
749
David Galeano9454e212011-09-26 12:17:20 +0100750LWS_EXTERN const struct libwebsocket_protocols *
Andy Greenb45993c2010-12-18 15:13:50 +0000751libwebsockets_get_protocol(struct libwebsocket *wsi);
752
David Galeano9454e212011-09-26 12:17:20 +0100753LWS_EXTERN int
Darin Willitsc19456f2011-02-14 17:52:39 +0000754libwebsocket_callback_on_writable(struct libwebsocket_context *context,
Andy Green62c54d22011-02-14 09:14:25 +0000755 struct libwebsocket *wsi);
Andy Green90c7cbc2011-01-27 06:26:52 +0000756
David Galeano9454e212011-09-26 12:17:20 +0100757LWS_EXTERN int
Andy Green90c7cbc2011-01-27 06:26:52 +0000758libwebsocket_callback_on_writable_all_protocol(
759 const struct libwebsocket_protocols *protocol);
760
David Galeano9454e212011-09-26 12:17:20 +0100761LWS_EXTERN int
Andy Greena6cbece2011-01-27 20:06:03 +0000762libwebsocket_get_socket_fd(struct libwebsocket *wsi);
Andy Green90c7cbc2011-01-27 06:26:52 +0000763
David Galeano9454e212011-09-26 12:17:20 +0100764LWS_EXTERN int
Andy Green82c3d542011-03-07 21:16:31 +0000765libwebsocket_is_final_fragment(struct libwebsocket *wsi);
766
David Galeanoe2cf9922013-01-09 18:06:55 +0800767LWS_EXTERN unsigned char
768libwebsocket_get_reserved_bits(struct libwebsocket *wsi);
769
Alex Bligh49146db2011-11-07 17:19:25 +0800770LWS_EXTERN void *
771libwebsocket_ensure_user_space(struct libwebsocket *wsi);
772
David Galeano9454e212011-09-26 12:17:20 +0100773LWS_EXTERN int
Andy Green90c7cbc2011-01-27 06:26:52 +0000774libwebsocket_rx_flow_control(struct libwebsocket *wsi, int enable);
775
David Galeano9454e212011-09-26 12:17:20 +0100776LWS_EXTERN size_t
Andy Green38e57bb2011-01-19 12:20:27 +0000777libwebsockets_remaining_packet_payload(struct libwebsocket *wsi);
778
David Galeano9454e212011-09-26 12:17:20 +0100779LWS_EXTERN struct libwebsocket *
Andy Green4739e5c2011-01-22 12:51:57 +0000780libwebsocket_client_connect(struct libwebsocket_context *clients,
781 const char *address,
782 int port,
Andy Green90c7cbc2011-01-27 06:26:52 +0000783 int ssl_connection,
Andy Green4739e5c2011-01-22 12:51:57 +0000784 const char *path,
785 const char *host,
786 const char *origin,
Andy Greenbfb051f2011-02-09 08:49:14 +0000787 const char *protocol,
788 int ietf_version_or_minus_one);
Andy Green4739e5c2011-01-22 12:51:57 +0000789
David Brooks2c60d952012-04-20 12:19:01 +0800790LWS_EXTERN struct libwebsocket *
791libwebsocket_client_connect_extended(struct libwebsocket_context *clients,
792 const char *address,
793 int port,
794 int ssl_connection,
795 const char *path,
796 const char *host,
797 const char *origin,
798 const char *protocol,
799 int ietf_version_or_minus_one,
800 void *userdata);
801
David Galeano9454e212011-09-26 12:17:20 +0100802LWS_EXTERN const char *
Darin Willitsc19456f2011-02-14 17:52:39 +0000803libwebsocket_canonical_hostname(struct libwebsocket_context *context);
Andy Green2ac5a6f2011-01-28 10:00:18 +0000804
Andy Green4739e5c2011-01-22 12:51:57 +0000805
David Galeano9454e212011-09-26 12:17:20 +0100806LWS_EXTERN void
Andy Green07034092011-02-13 08:37:12 +0000807libwebsockets_get_peer_addresses(int fd, char *name, int name_len,
808 char *rip, int rip_len);
809
David Galeano9454e212011-09-26 12:17:20 +0100810LWS_EXTERN void
Darin Willitsc19456f2011-02-14 17:52:39 +0000811libwebsockets_hangup_on_client(struct libwebsocket_context *context, int fd);
Andy Greenf7ee5492011-02-13 09:04:21 +0000812
David Galeano9454e212011-09-26 12:17:20 +0100813LWS_EXTERN void
Darin Willitsc19456f2011-02-14 17:52:39 +0000814libwebsocket_close_and_free_session(struct libwebsocket_context *context,
Andy Green687b0182011-02-26 11:04:01 +0000815 struct libwebsocket *wsi, enum lws_close_status);
Andy Green4b6fbe12011-02-14 08:03:48 +0000816
David Galeano9454e212011-09-26 12:17:20 +0100817LWS_EXTERN int
Andy Green8acc1942011-03-07 20:47:40 +0000818libwebsockets_get_random(struct libwebsocket_context *context,
819 void *buf, int len);
820
David Galeano9454e212011-09-26 12:17:20 +0100821LWS_EXTERN int
Andy Green279a3032013-01-17 10:05:39 +0800822lws_daemonize(const char *_lock_path);
823
824LWS_EXTERN int
Andy Green043a0ba2011-04-25 23:54:11 +0800825lws_send_pipe_choked(struct libwebsocket *wsi);
826
David Galeano9454e212011-09-26 12:17:20 +0100827LWS_EXTERN unsigned char *
Andy Green2836c642011-03-07 20:47:41 +0000828libwebsockets_SHA1(const unsigned char *d, size_t n, unsigned char *md);
829
David Galeano9454e212011-09-26 12:17:20 +0100830LWS_EXTERN int
Andy Greenf94e0582011-05-14 15:07:56 +0200831lws_b64_encode_string(const char *in, int in_len, char *out, int out_size);
832
David Galeano9454e212011-09-26 12:17:20 +0100833LWS_EXTERN int
Andy Greenf94e0582011-05-14 15:07:56 +0200834lws_b64_decode_string(const char *in, char *out, int out_size);
835
David Galeano9454e212011-09-26 12:17:20 +0100836LWS_EXTERN struct libwebsocket_extension libwebsocket_internal_extensions[];
Andy Green4cd87a02011-03-06 13:15:32 +0000837
Peter Hinz56885f32011-03-02 22:03:47 +0000838#ifdef __cplusplus
839}
840#endif
Andy Greena11fe942011-09-25 10:30:26 +0100841
Andy Greenab990e42010-10-31 12:42:52 +0000842#endif