blob: e4ad60bbfb4176087da89c6abf8ab3571b43a4ed [file] [log] [blame]
Andy Greend88146d2013-01-22 12:40:35 +08001<h2>libwebsocket_client_connect - Connect to another websocket server</h2>
2<i>struct libwebsocket *</i>
3<b>libwebsocket_client_connect</b>
4(<i>struct libwebsocket_context *</i> <b>context</b>,
5<i>const char *</i> <b>address</b>,
6<i>int</i> <b>port</b>,
7<i>int</i> <b>ssl_connection</b>,
8<i>const char *</i> <b>path</b>,
9<i>const char *</i> <b>host</b>,
10<i>const char *</i> <b>origin</b>,
11<i>const char *</i> <b>protocol</b>,
12<i>int</i> <b>ietf_version_or_minus_one</b>)
13<h3>Arguments</h3>
14<dl>
15<dt><b>context</b>
16<dd>Websocket context
17<dt><b>address</b>
18<dd>Remote server address, eg, "myserver.com"
19<dt><b>port</b>
20<dd>Port to connect to on the remote server, eg, 80
21<dt><b>ssl_connection</b>
22<dd>0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self
23signed certs
24<dt><b>path</b>
25<dd>Websocket path on server
26<dt><b>host</b>
27<dd>Hostname on server
28<dt><b>origin</b>
29<dd>Socket origin name
30<dt><b>protocol</b>
31<dd>Comma-separated list of protocols being asked for from
32the server, or just one. The server will pick the one it
33likes best.
34<dt><b>ietf_version_or_minus_one</b>
35<dd>-1 to ask to connect using the default, latest
36protocol supported, or the specific protocol ordinal
37</dl>
38<h3>Description</h3>
39<blockquote>
40This function creates a connection to a remote server
41</blockquote>
42<hr>
43<h2>libwebsocket_client_connect_extended - Connect to another websocket server</h2>
44<i>struct libwebsocket *</i>
45<b>libwebsocket_client_connect_extended</b>
46(<i>struct libwebsocket_context *</i> <b>context</b>,
47<i>const char *</i> <b>address</b>,
48<i>int</i> <b>port</b>,
49<i>int</i> <b>ssl_connection</b>,
50<i>const char *</i> <b>path</b>,
51<i>const char *</i> <b>host</b>,
52<i>const char *</i> <b>origin</b>,
53<i>const char *</i> <b>protocol</b>,
54<i>int</i> <b>ietf_version_or_minus_one</b>,
55<i>void *</i> <b>userdata</b>)
56<h3>Arguments</h3>
57<dl>
58<dt><b>context</b>
59<dd>Websocket context
60<dt><b>address</b>
61<dd>Remote server address, eg, "myserver.com"
62<dt><b>port</b>
63<dd>Port to connect to on the remote server, eg, 80
64<dt><b>ssl_connection</b>
65<dd>0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self
66signed certs
67<dt><b>path</b>
68<dd>Websocket path on server
69<dt><b>host</b>
70<dd>Hostname on server
71<dt><b>origin</b>
72<dd>Socket origin name
73<dt><b>protocol</b>
74<dd>Comma-separated list of protocols being asked for from
75the server, or just one. The server will pick the one it
76likes best.
77<dt><b>ietf_version_or_minus_one</b>
78<dd>-1 to ask to connect using the default, latest
79protocol supported, or the specific protocol ordinal
80<dt><b>userdata</b>
81<dd>Pre-allocated user data
82</dl>
83<h3>Description</h3>
84<blockquote>
85This function creates a connection to a remote server
86</blockquote>
87<hr>
Andy Green7b405452013-02-01 10:50:15 +080088<h2>lws_get_library_version - </h2>
89<i>const char *</i>
90<b>lws_get_library_version</b>
91(<i></i> <b>void</b>)
92<h3>Arguments</h3>
93<dl>
94<dt><b>void</b>
95<dd>no arguments
96</dl>
97<h3>Description</h3>
98<blockquote>
99<p>
100returns a const char * to a string like "1.1 178d78c"
101representing the library version followed by the git head hash it
102was built from
103</blockquote>
104<hr>
Andy Green07034092011-02-13 08:37:12 +0000105<h2>libwebsockets_get_peer_addresses - Get client address information</h2>
106<i>void</i>
107<b>libwebsockets_get_peer_addresses</b>
Andy Greenaaf0b9f2013-01-30 08:12:20 +0800108(<i>struct libwebsocket_context *</i> <b>context</b>,
109<i>struct libwebsocket *</i> <b>wsi</b>,
110<i>int</i> <b>fd</b>,
Andy Green07034092011-02-13 08:37:12 +0000111<i>char *</i> <b>name</b>,
112<i>int</i> <b>name_len</b>,
113<i>char *</i> <b>rip</b>,
114<i>int</i> <b>rip_len</b>)
115<h3>Arguments</h3>
116<dl>
Andy Greenaaf0b9f2013-01-30 08:12:20 +0800117<dt><b>context</b>
118<dd>Libwebsockets context
119<dt><b>wsi</b>
120<dd>Local struct libwebsocket associated with
Andy Green07034092011-02-13 08:37:12 +0000121<dt><b>fd</b>
122<dd>Connection socket descriptor
123<dt><b>name</b>
124<dd>Buffer to take client address name
125<dt><b>name_len</b>
126<dd>Length of client address name buffer
127<dt><b>rip</b>
128<dd>Buffer to take client address IP qotted quad
129<dt><b>rip_len</b>
130<dd>Length of client address IP buffer
131</dl>
132<h3>Description</h3>
133<blockquote>
134This function fills in <tt><b>name</b></tt> and <tt><b>rip</b></tt> with the name and IP of
135the client connected with socket descriptor <tt><b>fd</b></tt>. Names may be
136truncated if there is not enough room. If either cannot be
137determined, they will be returned as valid zero-length strings.
138</blockquote>
139<hr>
Andy Green9f990342011-02-12 11:57:45 +0000140<h2>libwebsocket_service_fd - Service polled socket with something waiting</h2>
141<i>int</i>
142<b>libwebsocket_service_fd</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000143(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green9f990342011-02-12 11:57:45 +0000144<i>struct pollfd *</i> <b>pollfd</b>)
145<h3>Arguments</h3>
146<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000147<dt><b>context</b>
Andy Green9f990342011-02-12 11:57:45 +0000148<dd>Websocket context
149<dt><b>pollfd</b>
150<dd>The pollfd entry describing the socket fd and which events
151happened.
152</dl>
153<h3>Description</h3>
154<blockquote>
Andy Green75006172013-01-22 12:32:11 +0800155This function takes a pollfd that has POLLIN or POLLOUT activity and
Andy Greenb5b23192013-02-11 17:13:32 +0800156services it according to the state of the associated
157struct libwebsocket.
Andy Green75006172013-01-22 12:32:11 +0800158<p>
159The one call deals with all "service" that might happen on a socket
160including listen accepts, http files as well as websocket protocol.
Andy Green9f990342011-02-12 11:57:45 +0000161</blockquote>
162<hr>
Andy Green6964bb52011-01-23 16:50:33 +0000163<h2>libwebsocket_context_destroy - Destroy the websocket context</h2>
164<i>void</i>
165<b>libwebsocket_context_destroy</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000166(<i>struct libwebsocket_context *</i> <b>context</b>)
Andy Green6964bb52011-01-23 16:50:33 +0000167<h3>Arguments</h3>
168<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000169<dt><b>context</b>
Andy Green6964bb52011-01-23 16:50:33 +0000170<dd>Websocket context
171</dl>
172<h3>Description</h3>
173<blockquote>
174This function closes any active connections and then frees the
175context. After calling this, any further use of the context is
176undefined.
177</blockquote>
178<hr>
Andy Greenb5b23192013-02-11 17:13:32 +0800179<h2>libwebsocket_context_user - get the user data associated with the context</h2>
Andy Greend88146d2013-01-22 12:40:35 +0800180<i>LWS_EXTERN void *</i>
181<b>libwebsocket_context_user</b>
182(<i>struct libwebsocket_context *</i> <b>context</b>)
183<h3>Arguments</h3>
184<dl>
185<dt><b>context</b>
186<dd>Websocket context
187</dl>
188<h3>Description</h3>
189<blockquote>
190This returns the optional user allocation that can be attached to
191the context the sockets live in at context_create time. It's a way
192to let all sockets serviced in the same context share data without
193using globals statics in the user code.
194</blockquote>
195<hr>
Andy Green6964bb52011-01-23 16:50:33 +0000196<h2>libwebsocket_service - Service any pending websocket activity</h2>
197<i>int</i>
198<b>libwebsocket_service</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000199(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green6964bb52011-01-23 16:50:33 +0000200<i>int</i> <b>timeout_ms</b>)
201<h3>Arguments</h3>
202<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000203<dt><b>context</b>
Andy Green6964bb52011-01-23 16:50:33 +0000204<dd>Websocket context
205<dt><b>timeout_ms</b>
206<dd>Timeout for poll; 0 means return immediately if nothing needed
207service otherwise block and service immediately, returning
208after the timeout if nothing needed service.
209</dl>
210<h3>Description</h3>
211<blockquote>
212This function deals with any pending websocket traffic, for three
213kinds of event. It handles these events on both server and client
214types of connection the same.
215<p>
2161) Accept new connections to our context's server
217<p>
Andy Green6f520a52013-01-29 17:57:39 +08002182) Call the receive callback for incoming frame data received by
Andy Green6964bb52011-01-23 16:50:33 +0000219server or client connections.
220<p>
221You need to call this service function periodically to all the above
222functions to happen; if your application is single-threaded you can
223just call it in your main event loop.
224<p>
225Alternatively you can fork a new process that asynchronously handles
226calling this service in a loop. In that case you are happy if this
227call blocks your thread until it needs to take care of something and
228would call it with a large nonzero timeout. Your loop then takes no
229CPU while there is nothing happening.
230<p>
231If you are calling it in a single-threaded app, you don't want it to
232wait around blocking other things in your loop from happening, so you
233would call it with a timeout_ms of 0, so it returns immediately if
234nothing is pending, or as soon as it services whatever was pending.
235</blockquote>
236<hr>
Andy Green32375b72011-02-19 08:32:53 +0000237<h2>libwebsocket_callback_on_writable - Request a callback when this socket becomes able to be written to without blocking</h2>
Andy Green90c7cbc2011-01-27 06:26:52 +0000238<i>int</i>
239<b>libwebsocket_callback_on_writable</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000240(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green62c54d22011-02-14 09:14:25 +0000241<i>struct libwebsocket *</i> <b>wsi</b>)
Andy Green90c7cbc2011-01-27 06:26:52 +0000242<h3>Arguments</h3>
243<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000244<dt><b>context</b>
Andy Green32375b72011-02-19 08:32:53 +0000245<dd>libwebsockets context
Andy Green90c7cbc2011-01-27 06:26:52 +0000246<dt><b>wsi</b>
247<dd>Websocket connection instance to get callback for
248</dl>
249<hr>
250<h2>libwebsocket_callback_on_writable_all_protocol - Request a callback for all connections using the given protocol when it becomes possible to write to each socket without blocking in turn.</h2>
251<i>int</i>
252<b>libwebsocket_callback_on_writable_all_protocol</b>
253(<i>const struct libwebsocket_protocols *</i> <b>protocol</b>)
254<h3>Arguments</h3>
255<dl>
256<dt><b>protocol</b>
257<dd>Protocol whose connections will get callbacks
258</dl>
259<hr>
Andy Greenbe93fef2011-02-14 20:25:43 +0000260<h2>libwebsocket_set_timeout - marks the wsi as subject to a timeout</h2>
261<i>void</i>
262<b>libwebsocket_set_timeout</b>
263(<i>struct libwebsocket *</i> <b>wsi</b>,
264<i>enum pending_timeout</i> <b>reason</b>,
265<i>int</i> <b>secs</b>)
266<h3>Arguments</h3>
267<dl>
268<dt><b>wsi</b>
269<dd>Websocket connection instance
270<dt><b>reason</b>
271<dd>timeout reason
272<dt><b>secs</b>
273<dd>how many seconds
274</dl>
275<h3>Description</h3>
276<blockquote>
277<p>
278You will not need this unless you are doing something special
279</blockquote>
280<hr>
Andy Greena6cbece2011-01-27 20:06:03 +0000281<h2>libwebsocket_get_socket_fd - returns the socket file descriptor</h2>
282<i>int</i>
283<b>libwebsocket_get_socket_fd</b>
284(<i>struct libwebsocket *</i> <b>wsi</b>)
285<h3>Arguments</h3>
286<dl>
287<dt><b>wsi</b>
288<dd>Websocket connection instance
289</dl>
290<h3>Description</h3>
291<blockquote>
292<p>
293You will not need this unless you are doing something special
294</blockquote>
295<hr>
Andy Green90c7cbc2011-01-27 06:26:52 +0000296<h2>libwebsocket_rx_flow_control - Enable and disable socket servicing for receieved packets.</h2>
297<i>int</i>
298<b>libwebsocket_rx_flow_control</b>
299(<i>struct libwebsocket *</i> <b>wsi</b>,
300<i>int</i> <b>enable</b>)
301<h3>Arguments</h3>
302<dl>
303<dt><b>wsi</b>
304<dd>Websocket connection instance to get callback for
305<dt><b>enable</b>
306<dd>0 = disable read servicing for this connection, 1 = enable
307</dl>
308<h3>Description</h3>
309<blockquote>
310<p>
311If the output side of a server process becomes choked, this allows flow
312control for the input side.
313</blockquote>
314<hr>
Andy Green2ac5a6f2011-01-28 10:00:18 +0000315<h2>libwebsocket_canonical_hostname - returns this host's hostname</h2>
316<i>const char *</i>
317<b>libwebsocket_canonical_hostname</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000318(<i>struct libwebsocket_context *</i> <b>context</b>)
Andy Green2ac5a6f2011-01-28 10:00:18 +0000319<h3>Arguments</h3>
320<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000321<dt><b>context</b>
Andy Green2ac5a6f2011-01-28 10:00:18 +0000322<dd>Websocket context
323</dl>
324<h3>Description</h3>
325<blockquote>
326<p>
327This is typically used by client code to fill in the host parameter
328when making a client connection. You can only call it after the context
329has been created.
330</blockquote>
331<hr>
Andy Green4739e5c2011-01-22 12:51:57 +0000332<h2>libwebsocket_create_context - Create the websocket handler</h2>
Andy Greene92cd172011-01-19 13:11:55 +0000333<i>struct libwebsocket_context *</i>
Andy Green4739e5c2011-01-22 12:51:57 +0000334<b>libwebsocket_create_context</b>
Andy Green1b265272013-02-09 14:01:09 +0800335(<i>struct lws_context_creation_info *</i> <b>info</b>)
Andy Green62a12932010-11-03 11:19:23 +0000336<h3>Arguments</h3>
337<dl>
Andy Green1b265272013-02-09 14:01:09 +0800338<dt><b>info</b>
339<dd>pointer to struct with parameters
Andy Green62a12932010-11-03 11:19:23 +0000340</dl>
341<h3>Description</h3>
342<blockquote>
Andy Green1b265272013-02-09 14:01:09 +0800343This function creates the listening socket (if serving) and takes care
Andy Green62a12932010-11-03 11:19:23 +0000344of all initialization in one step.
345<p>
Andy Greene92cd172011-01-19 13:11:55 +0000346After initialization, it returns a struct libwebsocket_context * that
347represents this server. After calling, user code needs to take care
348of calling <b>libwebsocket_service</b> with the context pointer to get the
349server's sockets serviced. This can be done in the same process context
350or a forked process, or another thread,
Andy Green47943ae2010-11-12 11:15:49 +0000351<p>
352The protocol callback functions are called for a handful of events
353including http requests coming in, websocket connections becoming
Andy Green62a12932010-11-03 11:19:23 +0000354established, and data arriving; it's also called periodically to allow
355async transmission.
356<p>
Andy Green47943ae2010-11-12 11:15:49 +0000357HTTP requests are sent always to the FIRST protocol in <tt><b>protocol</b></tt>, since
358at that time websocket protocol has not been negotiated. Other
359protocols after the first one never see any HTTP callack activity.
360<p>
Andy Green62a12932010-11-03 11:19:23 +0000361The server created is a simple http server by default; part of the
362websocket standard is upgrading this http connection to a websocket one.
363<p>
364This allows the same server to provide files like scripts and favicon /
365images or whatever over http and dynamic data over websockets all in
366one place; they're all handled in the user callback.
367</blockquote>
368<hr>
Andy Greenb45993c2010-12-18 15:13:50 +0000369<h2>libwebsockets_get_protocol - Returns a protocol pointer from a websocket connection.</h2>
370<i>const struct libwebsocket_protocols *</i>
371<b>libwebsockets_get_protocol</b>
372(<i>struct libwebsocket *</i> <b>wsi</b>)
373<h3>Arguments</h3>
374<dl>
375<dt><b>wsi</b>
376<dd>pointer to struct websocket you want to know the protocol of
377</dl>
378<h3>Description</h3>
379<blockquote>
380<p>
Andy Green6f520a52013-01-29 17:57:39 +0800381Some apis can act on all live connections of a given protocol,
382this is how you can get a pointer to the active protocol if needed.
Andy Greenacbaee62013-01-18 22:00:22 +0800383</blockquote>
384<hr>
Andy Green43db0452013-01-10 19:50:35 +0800385<h2>lws_set_log_level - Set the logging bitfield</h2>
386<i>void</i>
387<b>lws_set_log_level</b>
Andy Greende8f27a2013-01-12 09:17:42 +0800388(<i>int</i> <b>level</b>,
Andy Greenb5b23192013-02-11 17:13:32 +0800389<i>void (*</i><b>log_emit_function</b>) <i>(int level, const char *line)</i>)
Andy Green43db0452013-01-10 19:50:35 +0800390<h3>Arguments</h3>
391<dl>
392<dt><b>level</b>
393<dd>OR together the LLL_ debug contexts you want output from
Andy Greende8f27a2013-01-12 09:17:42 +0800394<dt><b>log_emit_function</b>
395<dd>NULL to leave it as it is, or a user-supplied
396function to perform log string emission instead of
397the default stderr one.
Andy Green43db0452013-01-10 19:50:35 +0800398</dl>
399<h3>Description</h3>
400<blockquote>
Andy Greenc6511a02013-02-19 10:01:48 +0800401log level defaults to "err", "warn" and "notice" contexts enabled and
Andy Greende8f27a2013-01-12 09:17:42 +0800402emission on stderr.
Andy Green43db0452013-01-10 19:50:35 +0800403</blockquote>
404<hr>
Andy Greend88146d2013-01-22 12:40:35 +0800405<h2>libwebsocket_write - Apply protocol then write data to client</h2>
406<i>int</i>
407<b>libwebsocket_write</b>
408(<i>struct libwebsocket *</i> <b>wsi</b>,
409<i>unsigned char *</i> <b>buf</b>,
410<i>size_t</i> <b>len</b>,
411<i>enum libwebsocket_write_protocol</i> <b>protocol</b>)
412<h3>Arguments</h3>
413<dl>
414<dt><b>wsi</b>
415<dd>Websocket instance (available from user callback)
416<dt><b>buf</b>
417<dd>The data to send. For data being sent on a websocket
418connection (ie, not default http), this buffer MUST have
419LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE the pointer
420and an additional LWS_SEND_BUFFER_POST_PADDING bytes valid
421in the buffer after (buf + len). This is so the protocol
422header and trailer data can be added in-situ.
423<dt><b>len</b>
424<dd>Count of the data bytes in the payload starting from buf
425<dt><b>protocol</b>
426<dd>Use LWS_WRITE_HTTP to reply to an http connection, and one
427of LWS_WRITE_BINARY or LWS_WRITE_TEXT to send appropriate
428data on a websockets connection. Remember to allow the extra
429bytes before and after buf if LWS_WRITE_BINARY or LWS_WRITE_TEXT
430are used.
431</dl>
432<h3>Description</h3>
433<blockquote>
434This function provides the way to issue data back to the client
435for both http and websocket protocols.
436<p>
437In the case of sending using websocket protocol, be sure to allocate
438valid storage before and after buf as explained above. This scheme
439allows maximum efficiency of sending data and protocol in a single
440packet while not burdening the user code with any protocol knowledge.
Andy Greenfc7c5e42013-02-23 10:50:10 +0800441<p>
442Return may be -1 for a fatal error needing connection close, or a
443positive number reflecting the amount of bytes actually sent. This
444can be less than the requested number of bytes due to OS memory
445pressure at any given time.
Andy Greend88146d2013-01-22 12:40:35 +0800446</blockquote>
447<hr>
448<h2>libwebsockets_serve_http_file - Send a file back to the client using http</h2>
449<i>int</i>
450<b>libwebsockets_serve_http_file</b>
451(<i>struct libwebsocket_context *</i> <b>context</b>,
452<i>struct libwebsocket *</i> <b>wsi</b>,
453<i>const char *</i> <b>file</b>,
454<i>const char *</i> <b>content_type</b>)
455<h3>Arguments</h3>
456<dl>
457<dt><b>context</b>
458<dd>libwebsockets context
459<dt><b>wsi</b>
460<dd>Websocket instance (available from user callback)
461<dt><b>file</b>
462<dd>The file to issue over http
463<dt><b>content_type</b>
464<dd>The http content type, eg, text/html
465</dl>
466<h3>Description</h3>
467<blockquote>
468This function is intended to be called from the callback in response
469to http requests from the client. It allows the callback to issue
470local files down the http link in a single step.
Andy Greenb8b247d2013-01-22 07:20:08 +0800471<p>
472Returning &lt;0 indicates error and the wsi should be closed. Returning
473&gt;0 indicates the file was completely sent and the wsi should be closed.
474==0 indicates the file transfer is started and needs more service later,
475the wsi should be left alone.
Andy Greend88146d2013-01-22 12:40:35 +0800476</blockquote>
477<hr>
Andy Green2fd3f2f2013-01-18 09:49:20 +0800478<h2>lws_frame_is_binary - </h2>
479<i>int</i>
480<b>lws_frame_is_binary</b>
481(<i>struct libwebsocket *</i> <b>wsi</b>)
482<h3>Arguments</h3>
483<dl>
484<dt><b>wsi</b>
485<dd>the connection we are inquiring about
486</dl>
487<h3>Description</h3>
488<blockquote>
489This is intended to be called from the LWS_CALLBACK_RECEIVE callback if
490it's interested to see if the frame it's dealing with was sent in binary
491mode.
492</blockquote>
493<hr>
Andy Green38e57bb2011-01-19 12:20:27 +0000494<h2>libwebsockets_remaining_packet_payload - Bytes to come before "overall" rx packet is complete</h2>
495<i>size_t</i>
496<b>libwebsockets_remaining_packet_payload</b>
497(<i>struct libwebsocket *</i> <b>wsi</b>)
498<h3>Arguments</h3>
499<dl>
500<dt><b>wsi</b>
501<dd>Websocket instance (available from user callback)
502</dl>
503<h3>Description</h3>
504<blockquote>
505This function is intended to be called from the callback if the
506user code is interested in "complete packets" from the client.
507libwebsockets just passes through payload as it comes and issues a buffer
508additionally when it hits a built-in limit. The LWS_CALLBACK_RECEIVE
509callback handler can use this API to find out if the buffer it has just
510been given is the last piece of a "complete packet" from the client --
511when that is the case <b>libwebsockets_remaining_packet_payload</b> will return
5120.
513<p>
514Many protocols won't care becuse their packets are always small.
515</blockquote>
516<hr>
Andy Green8f037e42010-12-19 22:13:26 +0000517<h2>callback - User server actions</h2>
Andy Green07b56e62011-10-03 19:30:22 +0800518<i>LWS_EXTERN int</i>
Andy Green8f037e42010-12-19 22:13:26 +0000519<b>callback</b>
Darin Willitsc19456f2011-02-14 17:52:39 +0000520(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green62c54d22011-02-14 09:14:25 +0000521<i>struct libwebsocket *</i> <b>wsi</b>,
Andy Green8f037e42010-12-19 22:13:26 +0000522<i>enum libwebsocket_callback_reasons</i> <b>reason</b>,
523<i>void *</i> <b>user</b>,
524<i>void *</i> <b>in</b>,
525<i>size_t</i> <b>len</b>)
526<h3>Arguments</h3>
527<dl>
Andy Green32375b72011-02-19 08:32:53 +0000528<dt><b>context</b>
529<dd>Websockets context
Andy Green8f037e42010-12-19 22:13:26 +0000530<dt><b>wsi</b>
531<dd>Opaque websocket instance pointer
532<dt><b>reason</b>
533<dd>The reason for the call
534<dt><b>user</b>
535<dd>Pointer to per-session user data allocated by library
536<dt><b>in</b>
537<dd>Pointer used for some callback reasons
538<dt><b>len</b>
539<dd>Length set for some callback reasons
540</dl>
541<h3>Description</h3>
542<blockquote>
543This callback is the way the user controls what is served. All the
544protocol detail is hidden and handled by the library.
545<p>
546For each connection / session there is user data allocated that is
547pointed to by "user". You set the size of this user data area when
548the library is initialized with libwebsocket_create_server.
549<p>
550You get an opportunity to initialize user data when called back with
551LWS_CALLBACK_ESTABLISHED reason.
552</blockquote>
553<h3>LWS_CALLBACK_ESTABLISHED</h3>
554<blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000555after the server completes a handshake with
556an incoming client
557</blockquote>
David Brooks2c60d952012-04-20 12:19:01 +0800558<h3>LWS_CALLBACK_CLIENT_CONNECTION_ERROR</h3>
559<blockquote>
560the request client connection has
561been unable to complete a handshake with the remote server
562</blockquote>
Andy Green2b57a342013-02-06 15:15:25 +0900563<h3>LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH</h3>
564<blockquote>
565this is the last chance for the
566client user code to examine the http headers
567and decide to reject the connection. If the
568content in the headers is interesting to the
569client (url, etc) it needs to copy it out at
570this point since it will be destroyed before
571the CLIENT_ESTABLISHED call
572</blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000573<h3>LWS_CALLBACK_CLIENT_ESTABLISHED</h3>
574<blockquote>
575after your client connection completed
576a handshake with the remote server
Andy Green8f037e42010-12-19 22:13:26 +0000577</blockquote>
578<h3>LWS_CALLBACK_CLOSED</h3>
579<blockquote>
580when the websocket session ends
581</blockquote>
Andy Green8f037e42010-12-19 22:13:26 +0000582<h3>LWS_CALLBACK_RECEIVE</h3>
583<blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000584data has appeared for this server endpoint from a
585remote client, it can be found at *in and is
586len bytes long
587</blockquote>
Andy Greena6cbece2011-01-27 20:06:03 +0000588<h3>LWS_CALLBACK_CLIENT_RECEIVE_PONG</h3>
589<blockquote>
590if you elected to see PONG packets,
591they appear with this callback reason. PONG
592packets only exist in 04+ protocol
593</blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000594<h3>LWS_CALLBACK_CLIENT_RECEIVE</h3>
595<blockquote>
596data has appeared from the server for the
597client connection, it can be found at *in and
598is len bytes long
Andy Green8f037e42010-12-19 22:13:26 +0000599</blockquote>
600<h3>LWS_CALLBACK_HTTP</h3>
601<blockquote>
602an http request has come from a client that is not
603asking to upgrade the connection to a websocket
604one. This is a chance to serve http content,
605for example, to send a script to the client
606which will then open the websockets connection.
Andy Green7619c472011-01-23 17:47:08 +0000607<tt><b>in</b></tt> points to the URI path requested and
Andy Green8f037e42010-12-19 22:13:26 +0000608<b>libwebsockets_serve_http_file</b> makes it very
609simple to send back a file to the client.
Andy Green24b588b2013-01-13 09:53:18 +0800610Normally after sending the file you are done
611with the http connection, since the rest of the
612activity will come by websockets from the script
613that was delivered by http, so you will want to
614return 1; to close and free up the connection.
615That's important because it uses a slot in the
616total number of client connections allowed set
617by MAX_CLIENTS.
Andy Green8f037e42010-12-19 22:13:26 +0000618</blockquote>
Andy Greene803c822013-02-14 23:18:10 +0800619<h3>LWS_CALLBACK_HTTP_WRITEABLE</h3>
620<blockquote>
621you can write more down the http protocol
622link now.
623</blockquote>
Andy Greend280b6e2013-01-15 13:40:23 +0800624<h3>LWS_CALLBACK_HTTP_FILE_COMPLETION</h3>
625<blockquote>
626a file requested to be send down
627http link has completed.
628</blockquote>
Andy Greene9739ed2011-03-07 21:40:59 +0000629<h3>LWS_CALLBACK_SERVER_WRITEABLE</h3>
Andy Green90c7cbc2011-01-27 06:26:52 +0000630<blockquote>
Andy Greene9739ed2011-03-07 21:40:59 +0000631If you call
Andy Green90c7cbc2011-01-27 06:26:52 +0000632<b>libwebsocket_callback_on_writable</b> on a connection, you will
Andy Greene9739ed2011-03-07 21:40:59 +0000633get one of these callbacks coming when the connection socket
634is able to accept another write packet without blocking.
635If it already was able to take another packet without blocking,
636you'll get this callback at the next call to the service loop
637function. Notice that CLIENTs get LWS_CALLBACK_CLIENT_WRITEABLE
638and servers get LWS_CALLBACK_SERVER_WRITEABLE.
Andy Green90c7cbc2011-01-27 06:26:52 +0000639</blockquote>
Andy Green07034092011-02-13 08:37:12 +0000640<h3>LWS_CALLBACK_FILTER_NETWORK_CONNECTION</h3>
641<blockquote>
642called when a client connects to
643the server at network level; the connection is accepted but then
644passed to this callback to decide whether to hang up immediately
Andy Green2672fb22013-02-22 09:54:35 +0800645or not, based on the client IP. <tt><b>in</b></tt> contains the connection
Andy Green07034092011-02-13 08:37:12 +0000646socket's descriptor. Return non-zero to terminate
647the connection before sending or receiving anything.
648Because this happens immediately after the network connection
649from the client, there's no websocket protocol selected yet so
650this callback is issued only to protocol 0.
651</blockquote>
Andy Greenc85619d2011-02-13 08:25:26 +0000652<h3>LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION</h3>
653<blockquote>
654called when the handshake has
655been received and parsed from the client, but the response is
656not sent yet. Return non-zero to disallow the connection.
Andy Green07034092011-02-13 08:37:12 +0000657<tt><b>user</b></tt> is a pointer to an array of struct lws_tokens, you can
658use the header enums lws_token_indexes from libwebsockets.h
659to check for and read the supported header presence and
660content before deciding to allow the handshake to proceed or
661to kill the connection.
Andy Green0894bda2011-02-19 09:09:11 +0000662</blockquote>
663<h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS</h3>
664<blockquote>
Andy Green6901cb32011-02-21 08:06:47 +0000665if configured for
Andy Green0894bda2011-02-19 09:09:11 +0000666including OpenSSL support, this callback allows your user code
667to perform extra <b>SSL_CTX_load_verify_locations</b> or similar
668calls to direct OpenSSL where to find certificates the client
669can use to confirm the remote server identity. <tt><b>user</b></tt> is the
670OpenSSL SSL_CTX*
Andy Green6901cb32011-02-21 08:06:47 +0000671</blockquote>
672<h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS</h3>
673<blockquote>
674if configured for
675including OpenSSL support, this callback allows your user code
676to load extra certifcates into the server which allow it to
677verify the validity of certificates returned by clients. <tt><b>user</b></tt>
678is the server's OpenSSL SSL_CTX*
679</blockquote>
680<h3>LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION</h3>
681<blockquote>
682if the
683libwebsockets context was created with the option
684LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT, then this
685callback is generated during OpenSSL verification of the cert
686sent from the client. It is sent to protocol[0] callback as
687no protocol has been negotiated on the connection yet.
688Notice that the libwebsockets context and wsi are both NULL
689during this callback. See
690</blockquote>
691<h3>http</h3>
692<blockquote>
693//www.openssl.org/docs/ssl/SSL_CTX_set_verify.html
694to understand more detail about the OpenSSL callback that
695generates this libwebsockets callback and the meanings of the
696arguments passed. In this callback, <tt><b>user</b></tt> is the x509_ctx,
697<tt><b>in</b></tt> is the ssl pointer and <tt><b>len</b></tt> is preverify_ok
698Notice that this callback maintains libwebsocket return
699conventions, return 0 to mean the cert is OK or 1 to fail it.
700This also means that if you don't handle this callback then
701the default callback action of returning 0 allows the client
702certificates.
Andy Green385e7ad2011-03-01 21:06:02 +0000703</blockquote>
704<h3>LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER</h3>
705<blockquote>
706this callback happens
707when a client handshake is being compiled. <tt><b>user</b></tt> is NULL,
708<tt><b>in</b></tt> is a char **, it's pointing to a char * which holds the
709next location in the header buffer where you can add
710headers, and <tt><b>len</b></tt> is the remaining space in the header buffer,
711which is typically some hundreds of bytes. So, to add a canned
712cookie, your handler code might look similar to:
713<p>
714char **p = (char **)in;
715<p>
716if (len &lt; 100)
717return 1;
718<p>
719*p += sprintf(*p, "Cookie: a=b\x0d\x0a");
720<p>
721return 0;
722<p>
723Notice if you add anything, you just have to take care about
724the CRLF on the line you added. Obviously this callback is
725optional, if you don't handle it everything is fine.
726<p>
727Notice the callback is coming to protocols[0] all the time,
728because there is no specific protocol handshook yet.
Andy Greenc5114822011-03-06 10:29:35 +0000729</blockquote>
730<h3>LWS_CALLBACK_CONFIRM_EXTENSION_OKAY</h3>
731<blockquote>
732When the server handshake code
733sees that it does support a requested extension, before
734accepting the extension by additing to the list sent back to
735the client it gives this callback just to check that it's okay
736to use that extension. It calls back to the requested protocol
737and with <tt><b>in</b></tt> being the extension name, <tt><b>len</b></tt> is 0 and <tt><b>user</b></tt> is
738valid. Note though at this time the ESTABLISHED callback hasn't
739happened yet so if you initialize <tt><b>user</b></tt> content there, <tt><b>user</b></tt>
740content during this callback might not be useful for anything.
741Notice this callback comes to protocols[0].
Andy Greenc6517fa2011-03-06 13:15:29 +0000742</blockquote>
743<h3>LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED</h3>
744<blockquote>
745When a client
746connection is being prepared to start a handshake to a server,
747each supported extension is checked with protocols[0] callback
748with this reason, giving the user code a chance to suppress the
749claim to support that extension by returning non-zero. If
750unhandled, by default 0 will be returned and the extension
751support included in the header to the server. Notice this
752callback comes to protocols[0].
Andy Greena7109e62013-02-11 12:05:54 +0800753</blockquote>
754<h3>LWS_CALLBACK_PROTOCOL_INIT</h3>
755<blockquote>
756One-time call per protocol so it can
757do initial setup / allocations etc
758</blockquote>
759<h3>LWS_CALLBACK_PROTOCOL_DESTROY</h3>
760<blockquote>
761One-time call per protocol indicating
762this protocol won't get used at all after this callback, the
763context is getting destroyed. Take the opportunity to
764deallocate everything that was allocated by the protocol.
Andy Greenc85619d2011-02-13 08:25:26 +0000765<p>
766The next four reasons are optional and only need taking care of if you
767will be integrating libwebsockets sockets into an external polling
768array.
769</blockquote>
770<h3>LWS_CALLBACK_ADD_POLL_FD</h3>
771<blockquote>
772libwebsocket deals with its <b>poll</b> loop
773internally, but in the case you are integrating with another
774server you will need to have libwebsocket sockets share a
775polling array with the other server. This and the other
776POLL_FD related callbacks let you put your specialized
777poll array interface code in the callback for protocol 0, the
778first protocol you support, usually the HTTP protocol in the
779serving case. This callback happens when a socket needs to be
780</blockquote>
781<h3>added to the polling loop</h3>
782<blockquote>
Andy Green50097dd2013-02-15 22:36:30 +0800783<tt><b>in</b></tt> contains the fd, and
Andy Greenc85619d2011-02-13 08:25:26 +0000784<tt><b>len</b></tt> is the events bitmap (like, POLLIN). If you are using the
785internal polling loop (the "service" callback), you can just
786ignore these callbacks.
787</blockquote>
788<h3>LWS_CALLBACK_DEL_POLL_FD</h3>
789<blockquote>
790This callback happens when a socket descriptor
Andy Green50097dd2013-02-15 22:36:30 +0800791needs to be removed from an external polling array. <tt><b>in</b></tt> is
Andy Greenc85619d2011-02-13 08:25:26 +0000792the socket desricptor. If you are using the internal polling
793loop, you can just ignore it.
794</blockquote>
795<h3>LWS_CALLBACK_SET_MODE_POLL_FD</h3>
796<blockquote>
797This callback happens when libwebsockets
Andy Green50097dd2013-02-15 22:36:30 +0800798wants to modify the events for the socket descriptor in <tt><b>in</b></tt>.
Andy Greenc85619d2011-02-13 08:25:26 +0000799The handler should OR <tt><b>len</b></tt> on to the events member of the pollfd
800struct for this socket descriptor. If you are using the
801internal polling loop, you can just ignore it.
802</blockquote>
803<h3>LWS_CALLBACK_CLEAR_MODE_POLL_FD</h3>
804<blockquote>
805This callback occurs when libwebsockets
Andy Green50097dd2013-02-15 22:36:30 +0800806wants to modify the events for the socket descriptor in <tt><b>in</b></tt>.
Andy Greenc85619d2011-02-13 08:25:26 +0000807The handler should AND ~<tt><b>len</b></tt> on to the events member of the
808pollfd struct for this socket descriptor. If you are using the
809internal polling loop, you can just ignore it.
810</blockquote>
Andy Green8f037e42010-12-19 22:13:26 +0000811<hr>
Andy Green57b4e9a2011-03-06 13:14:46 +0000812<h2>extension_callback - Hooks to allow extensions to operate</h2>
Andy Green07b56e62011-10-03 19:30:22 +0800813<i>LWS_EXTERN int</i>
Andy Green57b4e9a2011-03-06 13:14:46 +0000814<b>extension_callback</b>
815(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green46c2ea02011-03-22 09:04:01 +0000816<i>struct libwebsocket_extension *</i> <b>ext</b>,
Andy Green57b4e9a2011-03-06 13:14:46 +0000817<i>struct libwebsocket *</i> <b>wsi</b>,
David Brooks2c60d952012-04-20 12:19:01 +0800818<i>enum libwebsocket_extension_callback_reasons</i> <b>reason</b>,
Andy Green57b4e9a2011-03-06 13:14:46 +0000819<i>void *</i> <b>user</b>,
820<i>void *</i> <b>in</b>,
821<i>size_t</i> <b>len</b>)
822<h3>Arguments</h3>
823<dl>
824<dt><b>context</b>
825<dd>Websockets context
Andy Green46c2ea02011-03-22 09:04:01 +0000826<dt><b>ext</b>
827<dd>This extension
Andy Green57b4e9a2011-03-06 13:14:46 +0000828<dt><b>wsi</b>
829<dd>Opaque websocket instance pointer
830<dt><b>reason</b>
831<dd>The reason for the call
832<dt><b>user</b>
833<dd>Pointer to per-session user data allocated by library
834<dt><b>in</b>
835<dd>Pointer used for some callback reasons
836<dt><b>len</b>
837<dd>Length set for some callback reasons
838</dl>
839<h3>Description</h3>
840<blockquote>
841Each extension that is active on a particular connection receives
842callbacks during the connection lifetime to allow the extension to
843operate on websocket data and manage itself.
844<p>
845Libwebsockets takes care of allocating and freeing "user" memory for
846each active extension on each connection. That is what is pointed to
847by the <tt><b>user</b></tt> parameter.
848</blockquote>
849<h3>LWS_EXT_CALLBACK_CONSTRUCT</h3>
850<blockquote>
851called when the server has decided to
852select this extension from the list provided by the client,
853just before the server will send back the handshake accepting
854the connection with this extension active. This gives the
855extension a chance to initialize its connection context found
856in <tt><b>user</b></tt>.
857</blockquote>
Andy Green2366b1c2011-03-06 13:15:31 +0000858<h3>LWS_EXT_CALLBACK_CLIENT_CONSTRUCT</h3>
859<blockquote>
860same as LWS_EXT_CALLBACK_CONSTRUCT
861but called when client is instantiating this extension. Some
862extensions will work the same on client and server side and then
863you can just merge handlers for both CONSTRUCTS.
864</blockquote>
Andy Green57b4e9a2011-03-06 13:14:46 +0000865<h3>LWS_EXT_CALLBACK_DESTROY</h3>
866<blockquote>
867called when the connection the extension was
868being used on is about to be closed and deallocated. It's the
869last chance for the extension to deallocate anything it has
870allocated in the user data (pointed to by <tt><b>user</b></tt>) before the
Andy Green2366b1c2011-03-06 13:15:31 +0000871user data is deleted. This same callback is used whether you
872are in client or server instantiation context.
Andy Green57b4e9a2011-03-06 13:14:46 +0000873</blockquote>
874<h3>LWS_EXT_CALLBACK_PACKET_RX_PREPARSE</h3>
875<blockquote>
876when this extension was active on
877a connection, and a packet of data arrived at the connection,
878it is passed to this callback to give the extension a chance to
879change the data, eg, decompress it. <tt><b>user</b></tt> is pointing to the
880extension's private connection context data, <tt><b>in</b></tt> is pointing
881to an lws_tokens struct, it consists of a char * pointer called
882token, and an int called token_len. At entry, these are
883set to point to the received buffer and set to the content
884length. If the extension will grow the content, it should use
885a new buffer allocated in its private user context data and
886set the pointed-to lws_tokens members to point to its buffer.
887</blockquote>
888<h3>LWS_EXT_CALLBACK_PACKET_TX_PRESEND</h3>
889<blockquote>
890this works the same way as
891LWS_EXT_CALLBACK_PACKET_RX_PREPARSE above, except it gives the
892extension a chance to change websocket data just before it will
893be sent out. Using the same lws_token pointer scheme in <tt><b>in</b></tt>,
894the extension can change the buffer and the length to be
895transmitted how it likes. Again if it wants to grow the
896buffer safely, it should copy the data into its own buffer and
897set the lws_tokens token pointer to it.
898</blockquote>
899<hr>
Andy Green4f3943a2010-11-12 10:44:16 +0000900<h2>struct libwebsocket_protocols - List of protocols and handlers server supports.</h2>
901<b>struct libwebsocket_protocols</b> {<br>
902&nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
David Brooks2c60d952012-04-20 12:19:01 +0800903&nbsp; &nbsp; <i>callback_function *</i> <b>callback</b>;<br>
Andy Green4f3943a2010-11-12 10:44:16 +0000904&nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
Andy Green54495112013-02-06 21:10:16 +0900905&nbsp; &nbsp; <i>size_t</i> <b>rx_buffer_size</b>;<br>
Andy Greenb45993c2010-12-18 15:13:50 +0000906&nbsp; &nbsp; <i>struct libwebsocket_context *</i> <b>owning_server</b>;<br>
Andy Greenb45993c2010-12-18 15:13:50 +0000907&nbsp; &nbsp; <i>int</i> <b>protocol_index</b>;<br>
Andy Green4f3943a2010-11-12 10:44:16 +0000908};<br>
909<h3>Members</h3>
910<dl>
911<dt><b>name</b>
912<dd>Protocol name that must match the one given in the client
913Javascript new WebSocket(url, 'protocol') name
914<dt><b>callback</b>
915<dd>The service callback used for this protocol. It allows the
916service action for an entire protocol to be encapsulated in
917the protocol-specific callback
918<dt><b>per_session_data_size</b>
919<dd>Each new connection using this protocol gets
920this much memory allocated on connection establishment and
921freed on connection takedown. A pointer to this per-connection
922allocation is passed into the callback in the 'user' parameter
Andy Green54495112013-02-06 21:10:16 +0900923<dt><b>rx_buffer_size</b>
924<dd>if you want atomic frames delivered to the callback, you
925should set this to the size of the biggest legal frame that
926you support. If the frame size is exceeded, there is no
927error, but the buffer will spill to the user callback when
928full, which you can detect by using
929<b>libwebsockets_remaining_packet_payload</b>. Notice that you
930just talk about frame size here, the LWS_SEND_BUFFER_PRE_PADDING
931and post-padding are automatically also allocated on top.
Andy Greenb45993c2010-12-18 15:13:50 +0000932<dt><b>owning_server</b>
933<dd>the server init call fills in this opaque pointer when
934registering this protocol with the server.
Andy Greenb45993c2010-12-18 15:13:50 +0000935<dt><b>protocol_index</b>
936<dd>which protocol we are starting from zero
Andy Green4f3943a2010-11-12 10:44:16 +0000937</dl>
938<h3>Description</h3>
939<blockquote>
940This structure represents one protocol supported by the server. An
941array of these structures is passed to <b>libwebsocket_create_server</b>
942allows as many protocols as you like to be handled by one server.
943</blockquote>
944<hr>
Andy Greend6e09112011-03-05 16:12:15 +0000945<h2>struct libwebsocket_extension - An extension we know how to cope with</h2>
946<b>struct libwebsocket_extension</b> {<br>
947&nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
David Brooks2c60d952012-04-20 12:19:01 +0800948&nbsp; &nbsp; <i>extension_callback_function *</i> <b>callback</b>;<br>
Andy Greend6e09112011-03-05 16:12:15 +0000949&nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
Andy Greenaa6fc442012-04-12 13:26:49 +0800950&nbsp; &nbsp; <i>void *</i> <b>per_context_private_data</b>;<br>
Andy Greend6e09112011-03-05 16:12:15 +0000951};<br>
952<h3>Members</h3>
953<dl>
954<dt><b>name</b>
955<dd>Formal extension name, eg, "deflate-stream"
956<dt><b>callback</b>
957<dd>Service callback
958<dt><b>per_session_data_size</b>
959<dd>Libwebsockets will auto-malloc this much
960memory for the use of the extension, a pointer
961to it comes in the <tt><b>user</b></tt> callback parameter
Andy Greenaa6fc442012-04-12 13:26:49 +0800962<dt><b>per_context_private_data</b>
Andy Green75020012013-02-07 23:43:56 +0800963<dd>Optional storage for this extension that
Andy Greenaa6fc442012-04-12 13:26:49 +0800964is per-context, so it can track stuff across
965all sessions, etc, if it wants
Andy Greend6e09112011-03-05 16:12:15 +0000966</dl>
967<hr>
Andy Green1b265272013-02-09 14:01:09 +0800968<h2>struct lws_context_creation_info - </h2>
969<b>struct lws_context_creation_info</b> {<br>
970&nbsp; &nbsp; <i>int</i> <b>port</b>;<br>
Andy Green7a506ba2013-02-12 10:13:02 +0800971&nbsp; &nbsp; <i>const char *</i> <b>iface</b>;<br>
Andy Green1b265272013-02-09 14:01:09 +0800972&nbsp; &nbsp; <i>struct libwebsocket_protocols *</i> <b>protocols</b>;<br>
973&nbsp; &nbsp; <i>struct libwebsocket_extension *</i> <b>extensions</b>;<br>
974&nbsp; &nbsp; <i>const char *</i> <b>ssl_cert_filepath</b>;<br>
975&nbsp; &nbsp; <i>const char *</i> <b>ssl_private_key_filepath</b>;<br>
976&nbsp; &nbsp; <i>const char *</i> <b>ssl_ca_filepath</b>;<br>
Andy Green2672fb22013-02-22 09:54:35 +0800977&nbsp; &nbsp; <i>const char *</i> <b>ssl_cipher_list</b>;<br>
Andy Green1b265272013-02-09 14:01:09 +0800978&nbsp; &nbsp; <i>int</i> <b>gid</b>;<br>
979&nbsp; &nbsp; <i>int</i> <b>uid</b>;<br>
980&nbsp; &nbsp; <i>unsigned int</i> <b>options</b>;<br>
981&nbsp; &nbsp; <i>void *</i> <b>user</b>;<br>
Andy Greena690cd02013-02-09 12:25:31 +0800982&nbsp; &nbsp; <i>int</i> <b>ka_time</b>;<br>
983&nbsp; &nbsp; <i>int</i> <b>ka_probes</b>;<br>
984&nbsp; &nbsp; <i>int</i> <b>ka_interval</b>;<br>
Andy Green1b265272013-02-09 14:01:09 +0800985};<br>
986<h3>Members</h3>
987<dl>
988<dt><b>port</b>
989<dd>Port to listen on... you can use 0 to suppress listening on
990any port, that's what you want if you are not running a
991websocket server at all but just using it as a client
Andy Green7a506ba2013-02-12 10:13:02 +0800992<dt><b>iface</b>
993<dd>NULL to bind the listen socket to all interfaces, or the
994interface name, eg, "eth2"
Andy Green1b265272013-02-09 14:01:09 +0800995<dt><b>protocols</b>
996<dd>Array of structures listing supported protocols and a protocol-
997specific callback for each one. The list is ended with an
998entry that has a NULL callback pointer.
999It's not const because we write the owning_server member
1000<dt><b>extensions</b>
1001<dd>NULL or array of libwebsocket_extension structs listing the
1002extensions this context supports. If you configured with
1003--without-extensions, you should give NULL here.
1004<dt><b>ssl_cert_filepath</b>
1005<dd>If libwebsockets was compiled to use ssl, and you want
1006to listen using SSL, set to the filepath to fetch the
1007server cert from, otherwise NULL for unencrypted
1008<dt><b>ssl_private_key_filepath</b>
1009<dd>filepath to private key if wanting SSL mode,
1010else ignored
1011<dt><b>ssl_ca_filepath</b>
1012<dd>CA certificate filepath or NULL
Andy Green2672fb22013-02-22 09:54:35 +08001013<dt><b>ssl_cipher_list</b>
1014<dd>List of valid ciphers to use (eg,
1015"RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aNULL"
1016or you can leave it as NULL to get "DEFAULT"
Andy Green1b265272013-02-09 14:01:09 +08001017<dt><b>gid</b>
1018<dd>group id to change to after setting listen socket, or -1.
1019<dt><b>uid</b>
1020<dd>user id to change to after setting listen socket, or -1.
1021<dt><b>options</b>
1022<dd>0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK
1023<dt><b>user</b>
1024<dd>optional user pointer that can be recovered via the context
1025pointer using libwebsocket_context_user
Andy Greena690cd02013-02-09 12:25:31 +08001026<dt><b>ka_time</b>
1027<dd>0 for no keepalive, otherwise apply this keepalive timeout to
1028all libwebsocket sockets, client or server
1029<dt><b>ka_probes</b>
1030<dd>if ka_time was nonzero, after the timeout expires how many
1031times to try to get a response from the peer before giving up
1032and killing the connection
1033<dt><b>ka_interval</b>
1034<dd>if ka_time was nonzero, how long to wait before each ka_probes
1035attempt
Andy Green1b265272013-02-09 14:01:09 +08001036</dl>
1037<hr>