blob: 7a150456c8d6970913f7ef1a03a65d933cedbb60 [file] [log] [blame]
Andy Green2577c832013-03-11 20:37:03 +08001<h2>lws_frame_is_binary - </h2>
2<i>int</i>
3<b>lws_frame_is_binary</b>
4(<i>struct libwebsocket *</i> <b>wsi</b>)
Andy Greend88146d2013-01-22 12:40:35 +08005<h3>Arguments</h3>
6<dl>
Andy Green2577c832013-03-11 20:37:03 +08007<dt><b>wsi</b>
8<dd>the connection we are inquiring about
Andy Greend88146d2013-01-22 12:40:35 +08009</dl>
10<h3>Description</h3>
11<blockquote>
Andy Green2577c832013-03-11 20:37:03 +080012This is intended to be called from the LWS_CALLBACK_RECEIVE callback if
13it's interested to see if the frame it's dealing with was sent in binary
14mode.
Andy Greend88146d2013-01-22 12:40:35 +080015</blockquote>
16<hr>
Andy Green2577c832013-03-11 20:37:03 +080017<h2>libwebsockets_remaining_packet_payload - Bytes to come before "overall" rx packet is complete</h2>
18<i>size_t</i>
19<b>libwebsockets_remaining_packet_payload</b>
20(<i>struct libwebsocket *</i> <b>wsi</b>)
Andy Greend88146d2013-01-22 12:40:35 +080021<h3>Arguments</h3>
22<dl>
Andy Green2577c832013-03-11 20:37:03 +080023<dt><b>wsi</b>
24<dd>Websocket instance (available from user callback)
Andy Greend88146d2013-01-22 12:40:35 +080025</dl>
26<h3>Description</h3>
27<blockquote>
Andy Green2577c832013-03-11 20:37:03 +080028This function is intended to be called from the callback if the
29user code is interested in "complete packets" from the client.
30libwebsockets just passes through payload as it comes and issues a buffer
31additionally when it hits a built-in limit. The LWS_CALLBACK_RECEIVE
32callback handler can use this API to find out if the buffer it has just
33been given is the last piece of a "complete packet" from the client --
34when that is the case <b>libwebsockets_remaining_packet_payload</b> will return
350.
36<p>
37Many protocols won't care becuse their packets are always small.
Andy Greend88146d2013-01-22 12:40:35 +080038</blockquote>
39<hr>
Andy Green7b405452013-02-01 10:50:15 +080040<h2>lws_get_library_version - </h2>
41<i>const char *</i>
42<b>lws_get_library_version</b>
43(<i></i> <b>void</b>)
44<h3>Arguments</h3>
45<dl>
46<dt><b>void</b>
47<dd>no arguments
48</dl>
49<h3>Description</h3>
50<blockquote>
51<p>
52returns a const char * to a string like "1.1 178d78c"
53representing the library version followed by the git head hash it
54was built from
55</blockquote>
56<hr>
Andy Green07034092011-02-13 08:37:12 +000057<h2>libwebsockets_get_peer_addresses - Get client address information</h2>
58<i>void</i>
59<b>libwebsockets_get_peer_addresses</b>
Andy Greenaaf0b9f2013-01-30 08:12:20 +080060(<i>struct libwebsocket_context *</i> <b>context</b>,
61<i>struct libwebsocket *</i> <b>wsi</b>,
62<i>int</i> <b>fd</b>,
Andy Green07034092011-02-13 08:37:12 +000063<i>char *</i> <b>name</b>,
64<i>int</i> <b>name_len</b>,
65<i>char *</i> <b>rip</b>,
66<i>int</i> <b>rip_len</b>)
67<h3>Arguments</h3>
68<dl>
Andy Greenaaf0b9f2013-01-30 08:12:20 +080069<dt><b>context</b>
70<dd>Libwebsockets context
71<dt><b>wsi</b>
72<dd>Local struct libwebsocket associated with
Andy Green07034092011-02-13 08:37:12 +000073<dt><b>fd</b>
74<dd>Connection socket descriptor
75<dt><b>name</b>
76<dd>Buffer to take client address name
77<dt><b>name_len</b>
78<dd>Length of client address name buffer
79<dt><b>rip</b>
80<dd>Buffer to take client address IP qotted quad
81<dt><b>rip_len</b>
82<dd>Length of client address IP buffer
83</dl>
84<h3>Description</h3>
85<blockquote>
86This function fills in <tt><b>name</b></tt> and <tt><b>rip</b></tt> with the name and IP of
87the client connected with socket descriptor <tt><b>fd</b></tt>. Names may be
88truncated if there is not enough room. If either cannot be
89determined, they will be returned as valid zero-length strings.
90</blockquote>
91<hr>
Andy Green9f990342011-02-12 11:57:45 +000092<h2>libwebsocket_service_fd - Service polled socket with something waiting</h2>
93<i>int</i>
94<b>libwebsocket_service_fd</b>
Peter Hinz56885f32011-03-02 22:03:47 +000095(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green9f990342011-02-12 11:57:45 +000096<i>struct pollfd *</i> <b>pollfd</b>)
97<h3>Arguments</h3>
98<dl>
Peter Hinz56885f32011-03-02 22:03:47 +000099<dt><b>context</b>
Andy Green9f990342011-02-12 11:57:45 +0000100<dd>Websocket context
101<dt><b>pollfd</b>
102<dd>The pollfd entry describing the socket fd and which events
103happened.
104</dl>
105<h3>Description</h3>
106<blockquote>
Andy Green75006172013-01-22 12:32:11 +0800107This function takes a pollfd that has POLLIN or POLLOUT activity and
Andy Greenb5b23192013-02-11 17:13:32 +0800108services it according to the state of the associated
109struct libwebsocket.
Andy Green75006172013-01-22 12:32:11 +0800110<p>
111The one call deals with all "service" that might happen on a socket
112including listen accepts, http files as well as websocket protocol.
Andy Green2577c832013-03-11 20:37:03 +0800113<p>
114If a pollfd says it has something, you can just pass it to
115<b>libwebsocket_serice_fd</b> whether it is a socket handled by lws or not.
116If it sees it is a lws socket, the traffic will be handled and
117pollfd-&gt;revents will be zeroed now.
118<p>
119If the socket is foreign to lws, it leaves revents alone. So you can
120see if you should service yourself by checking the pollfd revents
121after letting lws try to service it.
Andy Green9f990342011-02-12 11:57:45 +0000122</blockquote>
123<hr>
Andy Green6964bb52011-01-23 16:50:33 +0000124<h2>libwebsocket_context_destroy - Destroy the websocket context</h2>
125<i>void</i>
126<b>libwebsocket_context_destroy</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000127(<i>struct libwebsocket_context *</i> <b>context</b>)
Andy Green6964bb52011-01-23 16:50:33 +0000128<h3>Arguments</h3>
129<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000130<dt><b>context</b>
Andy Green6964bb52011-01-23 16:50:33 +0000131<dd>Websocket context
132</dl>
133<h3>Description</h3>
134<blockquote>
135This function closes any active connections and then frees the
136context. After calling this, any further use of the context is
137undefined.
138</blockquote>
139<hr>
Andy Greenb5b23192013-02-11 17:13:32 +0800140<h2>libwebsocket_context_user - get the user data associated with the context</h2>
Andy Greend88146d2013-01-22 12:40:35 +0800141<i>LWS_EXTERN void *</i>
142<b>libwebsocket_context_user</b>
143(<i>struct libwebsocket_context *</i> <b>context</b>)
144<h3>Arguments</h3>
145<dl>
146<dt><b>context</b>
147<dd>Websocket context
148</dl>
149<h3>Description</h3>
150<blockquote>
151This returns the optional user allocation that can be attached to
152the context the sockets live in at context_create time. It's a way
153to let all sockets serviced in the same context share data without
154using globals statics in the user code.
155</blockquote>
156<hr>
Andy Green6964bb52011-01-23 16:50:33 +0000157<h2>libwebsocket_service - Service any pending websocket activity</h2>
158<i>int</i>
159<b>libwebsocket_service</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000160(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green6964bb52011-01-23 16:50:33 +0000161<i>int</i> <b>timeout_ms</b>)
162<h3>Arguments</h3>
163<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000164<dt><b>context</b>
Andy Green6964bb52011-01-23 16:50:33 +0000165<dd>Websocket context
166<dt><b>timeout_ms</b>
167<dd>Timeout for poll; 0 means return immediately if nothing needed
168service otherwise block and service immediately, returning
169after the timeout if nothing needed service.
170</dl>
171<h3>Description</h3>
172<blockquote>
173This function deals with any pending websocket traffic, for three
174kinds of event. It handles these events on both server and client
175types of connection the same.
176<p>
1771) Accept new connections to our context's server
178<p>
Andy Green6f520a52013-01-29 17:57:39 +08001792) Call the receive callback for incoming frame data received by
Andy Green6964bb52011-01-23 16:50:33 +0000180server or client connections.
181<p>
182You need to call this service function periodically to all the above
183functions to happen; if your application is single-threaded you can
184just call it in your main event loop.
185<p>
186Alternatively you can fork a new process that asynchronously handles
187calling this service in a loop. In that case you are happy if this
188call blocks your thread until it needs to take care of something and
189would call it with a large nonzero timeout. Your loop then takes no
190CPU while there is nothing happening.
191<p>
192If you are calling it in a single-threaded app, you don't want it to
193wait around blocking other things in your loop from happening, so you
194would call it with a timeout_ms of 0, so it returns immediately if
195nothing is pending, or as soon as it services whatever was pending.
196</blockquote>
197<hr>
Andy Green32375b72011-02-19 08:32:53 +0000198<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 +0000199<i>int</i>
200<b>libwebsocket_callback_on_writable</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000201(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green62c54d22011-02-14 09:14:25 +0000202<i>struct libwebsocket *</i> <b>wsi</b>)
Andy Green90c7cbc2011-01-27 06:26:52 +0000203<h3>Arguments</h3>
204<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000205<dt><b>context</b>
Andy Green32375b72011-02-19 08:32:53 +0000206<dd>libwebsockets context
Andy Green90c7cbc2011-01-27 06:26:52 +0000207<dt><b>wsi</b>
208<dd>Websocket connection instance to get callback for
209</dl>
210<hr>
211<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>
212<i>int</i>
213<b>libwebsocket_callback_on_writable_all_protocol</b>
214(<i>const struct libwebsocket_protocols *</i> <b>protocol</b>)
215<h3>Arguments</h3>
216<dl>
217<dt><b>protocol</b>
218<dd>Protocol whose connections will get callbacks
219</dl>
220<hr>
Andy Greenbe93fef2011-02-14 20:25:43 +0000221<h2>libwebsocket_set_timeout - marks the wsi as subject to a timeout</h2>
222<i>void</i>
223<b>libwebsocket_set_timeout</b>
224(<i>struct libwebsocket *</i> <b>wsi</b>,
225<i>enum pending_timeout</i> <b>reason</b>,
226<i>int</i> <b>secs</b>)
227<h3>Arguments</h3>
228<dl>
229<dt><b>wsi</b>
230<dd>Websocket connection instance
231<dt><b>reason</b>
232<dd>timeout reason
233<dt><b>secs</b>
234<dd>how many seconds
235</dl>
236<h3>Description</h3>
237<blockquote>
238<p>
239You will not need this unless you are doing something special
240</blockquote>
241<hr>
Andy Greena6cbece2011-01-27 20:06:03 +0000242<h2>libwebsocket_get_socket_fd - returns the socket file descriptor</h2>
243<i>int</i>
244<b>libwebsocket_get_socket_fd</b>
245(<i>struct libwebsocket *</i> <b>wsi</b>)
246<h3>Arguments</h3>
247<dl>
248<dt><b>wsi</b>
249<dd>Websocket connection instance
250</dl>
251<h3>Description</h3>
252<blockquote>
253<p>
254You will not need this unless you are doing something special
255</blockquote>
256<hr>
Andy Green90c7cbc2011-01-27 06:26:52 +0000257<h2>libwebsocket_rx_flow_control - Enable and disable socket servicing for receieved packets.</h2>
258<i>int</i>
259<b>libwebsocket_rx_flow_control</b>
260(<i>struct libwebsocket *</i> <b>wsi</b>,
261<i>int</i> <b>enable</b>)
262<h3>Arguments</h3>
263<dl>
264<dt><b>wsi</b>
265<dd>Websocket connection instance to get callback for
266<dt><b>enable</b>
267<dd>0 = disable read servicing for this connection, 1 = enable
268</dl>
269<h3>Description</h3>
270<blockquote>
271<p>
272If the output side of a server process becomes choked, this allows flow
273control for the input side.
274</blockquote>
275<hr>
Andy Greenb55451c2013-03-16 12:32:27 +0800276<h2>libwebsocket_rx_flow_allow_all_protocol - Allow all connections with this protocol to receive</h2>
277<i>void</i>
278<b>libwebsocket_rx_flow_allow_all_protocol</b>
279(<i>const struct libwebsocket_protocols *</i> <b>protocol</b>)
280<h3>Arguments</h3>
281<dl>
282<dt><b>protocol</b>
283<dd>all connections using this protocol will be allowed to receive
284</dl>
285<h3>Description</h3>
286<blockquote>
287<p>
288When the user server code realizes it can accept more input, it can
289call this to have the RX flow restriction removed from all connections using
290the given protocol.
291</blockquote>
292<hr>
Andy Green2ac5a6f2011-01-28 10:00:18 +0000293<h2>libwebsocket_canonical_hostname - returns this host's hostname</h2>
294<i>const char *</i>
295<b>libwebsocket_canonical_hostname</b>
Peter Hinz56885f32011-03-02 22:03:47 +0000296(<i>struct libwebsocket_context *</i> <b>context</b>)
Andy Green2ac5a6f2011-01-28 10:00:18 +0000297<h3>Arguments</h3>
298<dl>
Peter Hinz56885f32011-03-02 22:03:47 +0000299<dt><b>context</b>
Andy Green2ac5a6f2011-01-28 10:00:18 +0000300<dd>Websocket context
301</dl>
302<h3>Description</h3>
303<blockquote>
304<p>
305This is typically used by client code to fill in the host parameter
306when making a client connection. You can only call it after the context
307has been created.
308</blockquote>
309<hr>
Andy Green4739e5c2011-01-22 12:51:57 +0000310<h2>libwebsocket_create_context - Create the websocket handler</h2>
Andy Greene92cd172011-01-19 13:11:55 +0000311<i>struct libwebsocket_context *</i>
Andy Green4739e5c2011-01-22 12:51:57 +0000312<b>libwebsocket_create_context</b>
Andy Green1b265272013-02-09 14:01:09 +0800313(<i>struct lws_context_creation_info *</i> <b>info</b>)
Andy Green62a12932010-11-03 11:19:23 +0000314<h3>Arguments</h3>
315<dl>
Andy Green1b265272013-02-09 14:01:09 +0800316<dt><b>info</b>
317<dd>pointer to struct with parameters
Andy Green62a12932010-11-03 11:19:23 +0000318</dl>
319<h3>Description</h3>
320<blockquote>
Andy Green1b265272013-02-09 14:01:09 +0800321This function creates the listening socket (if serving) and takes care
Andy Green62a12932010-11-03 11:19:23 +0000322of all initialization in one step.
323<p>
Andy Greene92cd172011-01-19 13:11:55 +0000324After initialization, it returns a struct libwebsocket_context * that
325represents this server. After calling, user code needs to take care
326of calling <b>libwebsocket_service</b> with the context pointer to get the
327server's sockets serviced. This can be done in the same process context
328or a forked process, or another thread,
Andy Green47943ae2010-11-12 11:15:49 +0000329<p>
330The protocol callback functions are called for a handful of events
331including http requests coming in, websocket connections becoming
Andy Green62a12932010-11-03 11:19:23 +0000332established, and data arriving; it's also called periodically to allow
333async transmission.
334<p>
Andy Green47943ae2010-11-12 11:15:49 +0000335HTTP requests are sent always to the FIRST protocol in <tt><b>protocol</b></tt>, since
336at that time websocket protocol has not been negotiated. Other
337protocols after the first one never see any HTTP callack activity.
338<p>
Andy Green62a12932010-11-03 11:19:23 +0000339The server created is a simple http server by default; part of the
340websocket standard is upgrading this http connection to a websocket one.
341<p>
342This allows the same server to provide files like scripts and favicon /
343images or whatever over http and dynamic data over websockets all in
344one place; they're all handled in the user callback.
345</blockquote>
346<hr>
Andy Greenb45993c2010-12-18 15:13:50 +0000347<h2>libwebsockets_get_protocol - Returns a protocol pointer from a websocket connection.</h2>
348<i>const struct libwebsocket_protocols *</i>
349<b>libwebsockets_get_protocol</b>
350(<i>struct libwebsocket *</i> <b>wsi</b>)
351<h3>Arguments</h3>
352<dl>
353<dt><b>wsi</b>
354<dd>pointer to struct websocket you want to know the protocol of
355</dl>
356<h3>Description</h3>
357<blockquote>
358<p>
Andy Green6f520a52013-01-29 17:57:39 +0800359Some apis can act on all live connections of a given protocol,
360this is how you can get a pointer to the active protocol if needed.
Andy Greenacbaee62013-01-18 22:00:22 +0800361</blockquote>
362<hr>
Andy Green43db0452013-01-10 19:50:35 +0800363<h2>lws_set_log_level - Set the logging bitfield</h2>
364<i>void</i>
365<b>lws_set_log_level</b>
Andy Greende8f27a2013-01-12 09:17:42 +0800366(<i>int</i> <b>level</b>,
Andy Greenb5b23192013-02-11 17:13:32 +0800367<i>void (*</i><b>log_emit_function</b>) <i>(int level, const char *line)</i>)
Andy Green43db0452013-01-10 19:50:35 +0800368<h3>Arguments</h3>
369<dl>
370<dt><b>level</b>
371<dd>OR together the LLL_ debug contexts you want output from
Andy Greende8f27a2013-01-12 09:17:42 +0800372<dt><b>log_emit_function</b>
373<dd>NULL to leave it as it is, or a user-supplied
374function to perform log string emission instead of
375the default stderr one.
Andy Green43db0452013-01-10 19:50:35 +0800376</dl>
377<h3>Description</h3>
378<blockquote>
Andy Greenc6511a02013-02-19 10:01:48 +0800379log level defaults to "err", "warn" and "notice" contexts enabled and
Andy Greende8f27a2013-01-12 09:17:42 +0800380emission on stderr.
Andy Green43db0452013-01-10 19:50:35 +0800381</blockquote>
382<hr>
Andy Greend88146d2013-01-22 12:40:35 +0800383<h2>libwebsocket_write - Apply protocol then write data to client</h2>
384<i>int</i>
385<b>libwebsocket_write</b>
386(<i>struct libwebsocket *</i> <b>wsi</b>,
387<i>unsigned char *</i> <b>buf</b>,
388<i>size_t</i> <b>len</b>,
389<i>enum libwebsocket_write_protocol</i> <b>protocol</b>)
390<h3>Arguments</h3>
391<dl>
392<dt><b>wsi</b>
393<dd>Websocket instance (available from user callback)
394<dt><b>buf</b>
395<dd>The data to send. For data being sent on a websocket
396connection (ie, not default http), this buffer MUST have
397LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE the pointer
398and an additional LWS_SEND_BUFFER_POST_PADDING bytes valid
399in the buffer after (buf + len). This is so the protocol
400header and trailer data can be added in-situ.
401<dt><b>len</b>
402<dd>Count of the data bytes in the payload starting from buf
403<dt><b>protocol</b>
404<dd>Use LWS_WRITE_HTTP to reply to an http connection, and one
405of LWS_WRITE_BINARY or LWS_WRITE_TEXT to send appropriate
406data on a websockets connection. Remember to allow the extra
407bytes before and after buf if LWS_WRITE_BINARY or LWS_WRITE_TEXT
408are used.
409</dl>
410<h3>Description</h3>
411<blockquote>
412This function provides the way to issue data back to the client
413for both http and websocket protocols.
414<p>
415In the case of sending using websocket protocol, be sure to allocate
416valid storage before and after buf as explained above. This scheme
417allows maximum efficiency of sending data and protocol in a single
418packet while not burdening the user code with any protocol knowledge.
Andy Greenfc7c5e42013-02-23 10:50:10 +0800419<p>
420Return may be -1 for a fatal error needing connection close, or a
421positive number reflecting the amount of bytes actually sent. This
422can be less than the requested number of bytes due to OS memory
423pressure at any given time.
Andy Greend88146d2013-01-22 12:40:35 +0800424</blockquote>
425<hr>
426<h2>libwebsockets_serve_http_file - Send a file back to the client using http</h2>
427<i>int</i>
428<b>libwebsockets_serve_http_file</b>
429(<i>struct libwebsocket_context *</i> <b>context</b>,
430<i>struct libwebsocket *</i> <b>wsi</b>,
431<i>const char *</i> <b>file</b>,
432<i>const char *</i> <b>content_type</b>)
433<h3>Arguments</h3>
434<dl>
435<dt><b>context</b>
436<dd>libwebsockets context
437<dt><b>wsi</b>
438<dd>Websocket instance (available from user callback)
439<dt><b>file</b>
440<dd>The file to issue over http
441<dt><b>content_type</b>
442<dd>The http content type, eg, text/html
443</dl>
444<h3>Description</h3>
445<blockquote>
446This function is intended to be called from the callback in response
447to http requests from the client. It allows the callback to issue
448local files down the http link in a single step.
Andy Greenb8b247d2013-01-22 07:20:08 +0800449<p>
450Returning &lt;0 indicates error and the wsi should be closed. Returning
451&gt;0 indicates the file was completely sent and the wsi should be closed.
452==0 indicates the file transfer is started and needs more service later,
453the wsi should be left alone.
Andy Greend88146d2013-01-22 12:40:35 +0800454</blockquote>
455<hr>
Andy Green2577c832013-03-11 20:37:03 +0800456<h2>libwebsocket_client_connect - Connect to another websocket server</h2>
457<i>struct libwebsocket *</i>
458<b>libwebsocket_client_connect</b>
459(<i>struct libwebsocket_context *</i> <b>context</b>,
460<i>const char *</i> <b>address</b>,
461<i>int</i> <b>port</b>,
462<i>int</i> <b>ssl_connection</b>,
463<i>const char *</i> <b>path</b>,
464<i>const char *</i> <b>host</b>,
465<i>const char *</i> <b>origin</b>,
466<i>const char *</i> <b>protocol</b>,
467<i>int</i> <b>ietf_version_or_minus_one</b>)
Andy Green2fd3f2f2013-01-18 09:49:20 +0800468<h3>Arguments</h3>
469<dl>
Andy Green2577c832013-03-11 20:37:03 +0800470<dt><b>context</b>
471<dd>Websocket context
472<dt><b>address</b>
473<dd>Remote server address, eg, "myserver.com"
474<dt><b>port</b>
475<dd>Port to connect to on the remote server, eg, 80
476<dt><b>ssl_connection</b>
477<dd>0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self
478signed certs
479<dt><b>path</b>
480<dd>Websocket path on server
481<dt><b>host</b>
482<dd>Hostname on server
483<dt><b>origin</b>
484<dd>Socket origin name
485<dt><b>protocol</b>
486<dd>Comma-separated list of protocols being asked for from
487the server, or just one. The server will pick the one it
488likes best.
489<dt><b>ietf_version_or_minus_one</b>
490<dd>-1 to ask to connect using the default, latest
491protocol supported, or the specific protocol ordinal
Andy Green2fd3f2f2013-01-18 09:49:20 +0800492</dl>
493<h3>Description</h3>
494<blockquote>
Andy Green2577c832013-03-11 20:37:03 +0800495This function creates a connection to a remote server
Andy Green2fd3f2f2013-01-18 09:49:20 +0800496</blockquote>
497<hr>
Andy Green2577c832013-03-11 20:37:03 +0800498<h2>libwebsocket_client_connect_extended - Connect to another websocket server</h2>
499<i>struct libwebsocket *</i>
500<b>libwebsocket_client_connect_extended</b>
501(<i>struct libwebsocket_context *</i> <b>context</b>,
502<i>const char *</i> <b>address</b>,
503<i>int</i> <b>port</b>,
504<i>int</i> <b>ssl_connection</b>,
505<i>const char *</i> <b>path</b>,
506<i>const char *</i> <b>host</b>,
507<i>const char *</i> <b>origin</b>,
508<i>const char *</i> <b>protocol</b>,
509<i>int</i> <b>ietf_version_or_minus_one</b>,
510<i>void *</i> <b>userdata</b>)
Andy Green38e57bb2011-01-19 12:20:27 +0000511<h3>Arguments</h3>
512<dl>
Andy Green2577c832013-03-11 20:37:03 +0800513<dt><b>context</b>
514<dd>Websocket context
515<dt><b>address</b>
516<dd>Remote server address, eg, "myserver.com"
517<dt><b>port</b>
518<dd>Port to connect to on the remote server, eg, 80
519<dt><b>ssl_connection</b>
520<dd>0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self
521signed certs
522<dt><b>path</b>
523<dd>Websocket path on server
524<dt><b>host</b>
525<dd>Hostname on server
526<dt><b>origin</b>
527<dd>Socket origin name
528<dt><b>protocol</b>
529<dd>Comma-separated list of protocols being asked for from
530the server, or just one. The server will pick the one it
531likes best.
532<dt><b>ietf_version_or_minus_one</b>
533<dd>-1 to ask to connect using the default, latest
534protocol supported, or the specific protocol ordinal
535<dt><b>userdata</b>
536<dd>Pre-allocated user data
Andy Green38e57bb2011-01-19 12:20:27 +0000537</dl>
538<h3>Description</h3>
539<blockquote>
Andy Green2577c832013-03-11 20:37:03 +0800540This function creates a connection to a remote server
Andy Green38e57bb2011-01-19 12:20:27 +0000541</blockquote>
542<hr>
Andy Green8f037e42010-12-19 22:13:26 +0000543<h2>callback - User server actions</h2>
Andy Green07b56e62011-10-03 19:30:22 +0800544<i>LWS_EXTERN int</i>
Andy Green8f037e42010-12-19 22:13:26 +0000545<b>callback</b>
Darin Willitsc19456f2011-02-14 17:52:39 +0000546(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green62c54d22011-02-14 09:14:25 +0000547<i>struct libwebsocket *</i> <b>wsi</b>,
Andy Green8f037e42010-12-19 22:13:26 +0000548<i>enum libwebsocket_callback_reasons</i> <b>reason</b>,
549<i>void *</i> <b>user</b>,
550<i>void *</i> <b>in</b>,
551<i>size_t</i> <b>len</b>)
552<h3>Arguments</h3>
553<dl>
Andy Green32375b72011-02-19 08:32:53 +0000554<dt><b>context</b>
555<dd>Websockets context
Andy Green8f037e42010-12-19 22:13:26 +0000556<dt><b>wsi</b>
557<dd>Opaque websocket instance pointer
558<dt><b>reason</b>
559<dd>The reason for the call
560<dt><b>user</b>
561<dd>Pointer to per-session user data allocated by library
562<dt><b>in</b>
563<dd>Pointer used for some callback reasons
564<dt><b>len</b>
565<dd>Length set for some callback reasons
566</dl>
567<h3>Description</h3>
568<blockquote>
569This callback is the way the user controls what is served. All the
570protocol detail is hidden and handled by the library.
571<p>
572For each connection / session there is user data allocated that is
573pointed to by "user". You set the size of this user data area when
574the library is initialized with libwebsocket_create_server.
575<p>
576You get an opportunity to initialize user data when called back with
577LWS_CALLBACK_ESTABLISHED reason.
578</blockquote>
579<h3>LWS_CALLBACK_ESTABLISHED</h3>
580<blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000581after the server completes a handshake with
582an incoming client
583</blockquote>
David Brooks2c60d952012-04-20 12:19:01 +0800584<h3>LWS_CALLBACK_CLIENT_CONNECTION_ERROR</h3>
585<blockquote>
586the request client connection has
587been unable to complete a handshake with the remote server
588</blockquote>
Andy Green2b57a342013-02-06 15:15:25 +0900589<h3>LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH</h3>
590<blockquote>
591this is the last chance for the
592client user code to examine the http headers
593and decide to reject the connection. If the
594content in the headers is interesting to the
595client (url, etc) it needs to copy it out at
596this point since it will be destroyed before
597the CLIENT_ESTABLISHED call
598</blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000599<h3>LWS_CALLBACK_CLIENT_ESTABLISHED</h3>
600<blockquote>
601after your client connection completed
602a handshake with the remote server
Andy Green8f037e42010-12-19 22:13:26 +0000603</blockquote>
604<h3>LWS_CALLBACK_CLOSED</h3>
605<blockquote>
606when the websocket session ends
607</blockquote>
Andy Green8f037e42010-12-19 22:13:26 +0000608<h3>LWS_CALLBACK_RECEIVE</h3>
609<blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000610data has appeared for this server endpoint from a
611remote client, it can be found at *in and is
612len bytes long
613</blockquote>
Andy Greena6cbece2011-01-27 20:06:03 +0000614<h3>LWS_CALLBACK_CLIENT_RECEIVE_PONG</h3>
615<blockquote>
616if you elected to see PONG packets,
617they appear with this callback reason. PONG
618packets only exist in 04+ protocol
619</blockquote>
Andy Green90c7cbc2011-01-27 06:26:52 +0000620<h3>LWS_CALLBACK_CLIENT_RECEIVE</h3>
621<blockquote>
622data has appeared from the server for the
623client connection, it can be found at *in and
624is len bytes long
Andy Green8f037e42010-12-19 22:13:26 +0000625</blockquote>
626<h3>LWS_CALLBACK_HTTP</h3>
627<blockquote>
628an http request has come from a client that is not
629asking to upgrade the connection to a websocket
630one. This is a chance to serve http content,
631for example, to send a script to the client
632which will then open the websockets connection.
Andy Green7619c472011-01-23 17:47:08 +0000633<tt><b>in</b></tt> points to the URI path requested and
Andy Green8f037e42010-12-19 22:13:26 +0000634<b>libwebsockets_serve_http_file</b> makes it very
635simple to send back a file to the client.
Andy Green24b588b2013-01-13 09:53:18 +0800636Normally after sending the file you are done
637with the http connection, since the rest of the
638activity will come by websockets from the script
639that was delivered by http, so you will want to
640return 1; to close and free up the connection.
641That's important because it uses a slot in the
642total number of client connections allowed set
643by MAX_CLIENTS.
Andy Green8f037e42010-12-19 22:13:26 +0000644</blockquote>
Andy Greene803c822013-02-14 23:18:10 +0800645<h3>LWS_CALLBACK_HTTP_WRITEABLE</h3>
646<blockquote>
647you can write more down the http protocol
648link now.
649</blockquote>
Andy Greend280b6e2013-01-15 13:40:23 +0800650<h3>LWS_CALLBACK_HTTP_FILE_COMPLETION</h3>
651<blockquote>
652a file requested to be send down
653http link has completed.
654</blockquote>
Andy Greene9739ed2011-03-07 21:40:59 +0000655<h3>LWS_CALLBACK_SERVER_WRITEABLE</h3>
Andy Green90c7cbc2011-01-27 06:26:52 +0000656<blockquote>
Andy Greene9739ed2011-03-07 21:40:59 +0000657If you call
Andy Green90c7cbc2011-01-27 06:26:52 +0000658<b>libwebsocket_callback_on_writable</b> on a connection, you will
Andy Greene9739ed2011-03-07 21:40:59 +0000659get one of these callbacks coming when the connection socket
660is able to accept another write packet without blocking.
661If it already was able to take another packet without blocking,
662you'll get this callback at the next call to the service loop
663function. Notice that CLIENTs get LWS_CALLBACK_CLIENT_WRITEABLE
664and servers get LWS_CALLBACK_SERVER_WRITEABLE.
Andy Green90c7cbc2011-01-27 06:26:52 +0000665</blockquote>
Andy Green07034092011-02-13 08:37:12 +0000666<h3>LWS_CALLBACK_FILTER_NETWORK_CONNECTION</h3>
667<blockquote>
668called when a client connects to
669the server at network level; the connection is accepted but then
670passed to this callback to decide whether to hang up immediately
Andy Green2672fb22013-02-22 09:54:35 +0800671or not, based on the client IP. <tt><b>in</b></tt> contains the connection
Andy Green07034092011-02-13 08:37:12 +0000672socket's descriptor. Return non-zero to terminate
673the connection before sending or receiving anything.
674Because this happens immediately after the network connection
675from the client, there's no websocket protocol selected yet so
676this callback is issued only to protocol 0.
677</blockquote>
Andy Greenc85619d2011-02-13 08:25:26 +0000678<h3>LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION</h3>
679<blockquote>
680called when the handshake has
681been received and parsed from the client, but the response is
682not sent yet. Return non-zero to disallow the connection.
Andy Green07034092011-02-13 08:37:12 +0000683<tt><b>user</b></tt> is a pointer to an array of struct lws_tokens, you can
684use the header enums lws_token_indexes from libwebsockets.h
685to check for and read the supported header presence and
686content before deciding to allow the handshake to proceed or
687to kill the connection.
Andy Green0894bda2011-02-19 09:09:11 +0000688</blockquote>
689<h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS</h3>
690<blockquote>
Andy Green6901cb32011-02-21 08:06:47 +0000691if configured for
Andy Green0894bda2011-02-19 09:09:11 +0000692including OpenSSL support, this callback allows your user code
693to perform extra <b>SSL_CTX_load_verify_locations</b> or similar
694calls to direct OpenSSL where to find certificates the client
695can use to confirm the remote server identity. <tt><b>user</b></tt> is the
696OpenSSL SSL_CTX*
Andy Green6901cb32011-02-21 08:06:47 +0000697</blockquote>
698<h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS</h3>
699<blockquote>
700if configured for
701including OpenSSL support, this callback allows your user code
702to load extra certifcates into the server which allow it to
703verify the validity of certificates returned by clients. <tt><b>user</b></tt>
704is the server's OpenSSL SSL_CTX*
705</blockquote>
706<h3>LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION</h3>
707<blockquote>
708if the
709libwebsockets context was created with the option
710LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT, then this
711callback is generated during OpenSSL verification of the cert
712sent from the client. It is sent to protocol[0] callback as
713no protocol has been negotiated on the connection yet.
714Notice that the libwebsockets context and wsi are both NULL
715during this callback. See
716</blockquote>
717<h3>http</h3>
718<blockquote>
719//www.openssl.org/docs/ssl/SSL_CTX_set_verify.html
720to understand more detail about the OpenSSL callback that
721generates this libwebsockets callback and the meanings of the
722arguments passed. In this callback, <tt><b>user</b></tt> is the x509_ctx,
723<tt><b>in</b></tt> is the ssl pointer and <tt><b>len</b></tt> is preverify_ok
724Notice that this callback maintains libwebsocket return
725conventions, return 0 to mean the cert is OK or 1 to fail it.
726This also means that if you don't handle this callback then
727the default callback action of returning 0 allows the client
728certificates.
Andy Green385e7ad2011-03-01 21:06:02 +0000729</blockquote>
730<h3>LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER</h3>
731<blockquote>
732this callback happens
733when a client handshake is being compiled. <tt><b>user</b></tt> is NULL,
734<tt><b>in</b></tt> is a char **, it's pointing to a char * which holds the
735next location in the header buffer where you can add
736headers, and <tt><b>len</b></tt> is the remaining space in the header buffer,
737which is typically some hundreds of bytes. So, to add a canned
738cookie, your handler code might look similar to:
739<p>
740char **p = (char **)in;
741<p>
742if (len &lt; 100)
743return 1;
744<p>
745*p += sprintf(*p, "Cookie: a=b\x0d\x0a");
746<p>
747return 0;
748<p>
749Notice if you add anything, you just have to take care about
750the CRLF on the line you added. Obviously this callback is
751optional, if you don't handle it everything is fine.
752<p>
753Notice the callback is coming to protocols[0] all the time,
754because there is no specific protocol handshook yet.
Andy Greenc5114822011-03-06 10:29:35 +0000755</blockquote>
756<h3>LWS_CALLBACK_CONFIRM_EXTENSION_OKAY</h3>
757<blockquote>
758When the server handshake code
759sees that it does support a requested extension, before
760accepting the extension by additing to the list sent back to
761the client it gives this callback just to check that it's okay
762to use that extension. It calls back to the requested protocol
763and with <tt><b>in</b></tt> being the extension name, <tt><b>len</b></tt> is 0 and <tt><b>user</b></tt> is
764valid. Note though at this time the ESTABLISHED callback hasn't
765happened yet so if you initialize <tt><b>user</b></tt> content there, <tt><b>user</b></tt>
766content during this callback might not be useful for anything.
767Notice this callback comes to protocols[0].
Andy Greenc6517fa2011-03-06 13:15:29 +0000768</blockquote>
769<h3>LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED</h3>
770<blockquote>
771When a client
772connection is being prepared to start a handshake to a server,
773each supported extension is checked with protocols[0] callback
774with this reason, giving the user code a chance to suppress the
775claim to support that extension by returning non-zero. If
776unhandled, by default 0 will be returned and the extension
777support included in the header to the server. Notice this
778callback comes to protocols[0].
Andy Greena7109e62013-02-11 12:05:54 +0800779</blockquote>
780<h3>LWS_CALLBACK_PROTOCOL_INIT</h3>
781<blockquote>
782One-time call per protocol so it can
783do initial setup / allocations etc
784</blockquote>
785<h3>LWS_CALLBACK_PROTOCOL_DESTROY</h3>
786<blockquote>
787One-time call per protocol indicating
788this protocol won't get used at all after this callback, the
789context is getting destroyed. Take the opportunity to
790deallocate everything that was allocated by the protocol.
Andy Greenc85619d2011-02-13 08:25:26 +0000791<p>
792The next four reasons are optional and only need taking care of if you
793will be integrating libwebsockets sockets into an external polling
794array.
795</blockquote>
796<h3>LWS_CALLBACK_ADD_POLL_FD</h3>
797<blockquote>
798libwebsocket deals with its <b>poll</b> loop
799internally, but in the case you are integrating with another
800server you will need to have libwebsocket sockets share a
801polling array with the other server. This and the other
802POLL_FD related callbacks let you put your specialized
803poll array interface code in the callback for protocol 0, the
804first protocol you support, usually the HTTP protocol in the
805serving case. This callback happens when a socket needs to be
806</blockquote>
807<h3>added to the polling loop</h3>
808<blockquote>
Andy Green50097dd2013-02-15 22:36:30 +0800809<tt><b>in</b></tt> contains the fd, and
Andy Greenc85619d2011-02-13 08:25:26 +0000810<tt><b>len</b></tt> is the events bitmap (like, POLLIN). If you are using the
811internal polling loop (the "service" callback), you can just
812ignore these callbacks.
813</blockquote>
814<h3>LWS_CALLBACK_DEL_POLL_FD</h3>
815<blockquote>
816This callback happens when a socket descriptor
Andy Green50097dd2013-02-15 22:36:30 +0800817needs to be removed from an external polling array. <tt><b>in</b></tt> is
Andy Greenc85619d2011-02-13 08:25:26 +0000818the socket desricptor. If you are using the internal polling
819loop, you can just ignore it.
820</blockquote>
821<h3>LWS_CALLBACK_SET_MODE_POLL_FD</h3>
822<blockquote>
823This callback happens when libwebsockets
Andy Green50097dd2013-02-15 22:36:30 +0800824wants to modify the events for the socket descriptor in <tt><b>in</b></tt>.
Andy Greenc85619d2011-02-13 08:25:26 +0000825The handler should OR <tt><b>len</b></tt> on to the events member of the pollfd
826struct for this socket descriptor. If you are using the
827internal polling loop, you can just ignore it.
828</blockquote>
829<h3>LWS_CALLBACK_CLEAR_MODE_POLL_FD</h3>
830<blockquote>
831This callback occurs when libwebsockets
Andy Green50097dd2013-02-15 22:36:30 +0800832wants to modify the events for the socket descriptor in <tt><b>in</b></tt>.
Andy Greenc85619d2011-02-13 08:25:26 +0000833The handler should AND ~<tt><b>len</b></tt> on to the events member of the
834pollfd struct for this socket descriptor. If you are using the
835internal polling loop, you can just ignore it.
836</blockquote>
Andy Green8f037e42010-12-19 22:13:26 +0000837<hr>
Andy Green57b4e9a2011-03-06 13:14:46 +0000838<h2>extension_callback - Hooks to allow extensions to operate</h2>
Andy Green07b56e62011-10-03 19:30:22 +0800839<i>LWS_EXTERN int</i>
Andy Green57b4e9a2011-03-06 13:14:46 +0000840<b>extension_callback</b>
841(<i>struct libwebsocket_context *</i> <b>context</b>,
Andy Green46c2ea02011-03-22 09:04:01 +0000842<i>struct libwebsocket_extension *</i> <b>ext</b>,
Andy Green57b4e9a2011-03-06 13:14:46 +0000843<i>struct libwebsocket *</i> <b>wsi</b>,
David Brooks2c60d952012-04-20 12:19:01 +0800844<i>enum libwebsocket_extension_callback_reasons</i> <b>reason</b>,
Andy Green57b4e9a2011-03-06 13:14:46 +0000845<i>void *</i> <b>user</b>,
846<i>void *</i> <b>in</b>,
847<i>size_t</i> <b>len</b>)
848<h3>Arguments</h3>
849<dl>
850<dt><b>context</b>
851<dd>Websockets context
Andy Green46c2ea02011-03-22 09:04:01 +0000852<dt><b>ext</b>
853<dd>This extension
Andy Green57b4e9a2011-03-06 13:14:46 +0000854<dt><b>wsi</b>
855<dd>Opaque websocket instance pointer
856<dt><b>reason</b>
857<dd>The reason for the call
858<dt><b>user</b>
859<dd>Pointer to per-session user data allocated by library
860<dt><b>in</b>
861<dd>Pointer used for some callback reasons
862<dt><b>len</b>
863<dd>Length set for some callback reasons
864</dl>
865<h3>Description</h3>
866<blockquote>
867Each extension that is active on a particular connection receives
868callbacks during the connection lifetime to allow the extension to
869operate on websocket data and manage itself.
870<p>
871Libwebsockets takes care of allocating and freeing "user" memory for
872each active extension on each connection. That is what is pointed to
873by the <tt><b>user</b></tt> parameter.
874</blockquote>
875<h3>LWS_EXT_CALLBACK_CONSTRUCT</h3>
876<blockquote>
877called when the server has decided to
878select this extension from the list provided by the client,
879just before the server will send back the handshake accepting
880the connection with this extension active. This gives the
881extension a chance to initialize its connection context found
882in <tt><b>user</b></tt>.
883</blockquote>
Andy Green2366b1c2011-03-06 13:15:31 +0000884<h3>LWS_EXT_CALLBACK_CLIENT_CONSTRUCT</h3>
885<blockquote>
886same as LWS_EXT_CALLBACK_CONSTRUCT
887but called when client is instantiating this extension. Some
888extensions will work the same on client and server side and then
889you can just merge handlers for both CONSTRUCTS.
890</blockquote>
Andy Green57b4e9a2011-03-06 13:14:46 +0000891<h3>LWS_EXT_CALLBACK_DESTROY</h3>
892<blockquote>
893called when the connection the extension was
894being used on is about to be closed and deallocated. It's the
895last chance for the extension to deallocate anything it has
896allocated in the user data (pointed to by <tt><b>user</b></tt>) before the
Andy Green2366b1c2011-03-06 13:15:31 +0000897user data is deleted. This same callback is used whether you
898are in client or server instantiation context.
Andy Green57b4e9a2011-03-06 13:14:46 +0000899</blockquote>
900<h3>LWS_EXT_CALLBACK_PACKET_RX_PREPARSE</h3>
901<blockquote>
902when this extension was active on
903a connection, and a packet of data arrived at the connection,
904it is passed to this callback to give the extension a chance to
905change the data, eg, decompress it. <tt><b>user</b></tt> is pointing to the
906extension's private connection context data, <tt><b>in</b></tt> is pointing
907to an lws_tokens struct, it consists of a char * pointer called
908token, and an int called token_len. At entry, these are
909set to point to the received buffer and set to the content
910length. If the extension will grow the content, it should use
911a new buffer allocated in its private user context data and
912set the pointed-to lws_tokens members to point to its buffer.
913</blockquote>
914<h3>LWS_EXT_CALLBACK_PACKET_TX_PRESEND</h3>
915<blockquote>
916this works the same way as
917LWS_EXT_CALLBACK_PACKET_RX_PREPARSE above, except it gives the
918extension a chance to change websocket data just before it will
919be sent out. Using the same lws_token pointer scheme in <tt><b>in</b></tt>,
920the extension can change the buffer and the length to be
921transmitted how it likes. Again if it wants to grow the
922buffer safely, it should copy the data into its own buffer and
923set the lws_tokens token pointer to it.
924</blockquote>
925<hr>
Andy Green4f3943a2010-11-12 10:44:16 +0000926<h2>struct libwebsocket_protocols - List of protocols and handlers server supports.</h2>
927<b>struct libwebsocket_protocols</b> {<br>
928&nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
David Brooks2c60d952012-04-20 12:19:01 +0800929&nbsp; &nbsp; <i>callback_function *</i> <b>callback</b>;<br>
Andy Green4f3943a2010-11-12 10:44:16 +0000930&nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
Andy Green54495112013-02-06 21:10:16 +0900931&nbsp; &nbsp; <i>size_t</i> <b>rx_buffer_size</b>;<br>
Andy Greenb45993c2010-12-18 15:13:50 +0000932&nbsp; &nbsp; <i>struct libwebsocket_context *</i> <b>owning_server</b>;<br>
Andy Greenb45993c2010-12-18 15:13:50 +0000933&nbsp; &nbsp; <i>int</i> <b>protocol_index</b>;<br>
Andy Green4f3943a2010-11-12 10:44:16 +0000934};<br>
935<h3>Members</h3>
936<dl>
937<dt><b>name</b>
938<dd>Protocol name that must match the one given in the client
939Javascript new WebSocket(url, 'protocol') name
940<dt><b>callback</b>
941<dd>The service callback used for this protocol. It allows the
942service action for an entire protocol to be encapsulated in
943the protocol-specific callback
944<dt><b>per_session_data_size</b>
945<dd>Each new connection using this protocol gets
946this much memory allocated on connection establishment and
947freed on connection takedown. A pointer to this per-connection
948allocation is passed into the callback in the 'user' parameter
Andy Green54495112013-02-06 21:10:16 +0900949<dt><b>rx_buffer_size</b>
950<dd>if you want atomic frames delivered to the callback, you
951should set this to the size of the biggest legal frame that
952you support. If the frame size is exceeded, there is no
953error, but the buffer will spill to the user callback when
954full, which you can detect by using
955<b>libwebsockets_remaining_packet_payload</b>. Notice that you
956just talk about frame size here, the LWS_SEND_BUFFER_PRE_PADDING
957and post-padding are automatically also allocated on top.
Andy Greenb45993c2010-12-18 15:13:50 +0000958<dt><b>owning_server</b>
959<dd>the server init call fills in this opaque pointer when
960registering this protocol with the server.
Andy Greenb45993c2010-12-18 15:13:50 +0000961<dt><b>protocol_index</b>
962<dd>which protocol we are starting from zero
Andy Green4f3943a2010-11-12 10:44:16 +0000963</dl>
964<h3>Description</h3>
965<blockquote>
966This structure represents one protocol supported by the server. An
967array of these structures is passed to <b>libwebsocket_create_server</b>
968allows as many protocols as you like to be handled by one server.
969</blockquote>
970<hr>
Andy Greend6e09112011-03-05 16:12:15 +0000971<h2>struct libwebsocket_extension - An extension we know how to cope with</h2>
972<b>struct libwebsocket_extension</b> {<br>
973&nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
David Brooks2c60d952012-04-20 12:19:01 +0800974&nbsp; &nbsp; <i>extension_callback_function *</i> <b>callback</b>;<br>
Andy Greend6e09112011-03-05 16:12:15 +0000975&nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
Andy Greenaa6fc442012-04-12 13:26:49 +0800976&nbsp; &nbsp; <i>void *</i> <b>per_context_private_data</b>;<br>
Andy Greend6e09112011-03-05 16:12:15 +0000977};<br>
978<h3>Members</h3>
979<dl>
980<dt><b>name</b>
981<dd>Formal extension name, eg, "deflate-stream"
982<dt><b>callback</b>
983<dd>Service callback
984<dt><b>per_session_data_size</b>
985<dd>Libwebsockets will auto-malloc this much
986memory for the use of the extension, a pointer
987to it comes in the <tt><b>user</b></tt> callback parameter
Andy Greenaa6fc442012-04-12 13:26:49 +0800988<dt><b>per_context_private_data</b>
Andy Green75020012013-02-07 23:43:56 +0800989<dd>Optional storage for this extension that
Andy Greenaa6fc442012-04-12 13:26:49 +0800990is per-context, so it can track stuff across
991all sessions, etc, if it wants
Andy Greend6e09112011-03-05 16:12:15 +0000992</dl>
993<hr>
Andy Green1b265272013-02-09 14:01:09 +0800994<h2>struct lws_context_creation_info - </h2>
995<b>struct lws_context_creation_info</b> {<br>
996&nbsp; &nbsp; <i>int</i> <b>port</b>;<br>
Andy Green7a506ba2013-02-12 10:13:02 +0800997&nbsp; &nbsp; <i>const char *</i> <b>iface</b>;<br>
Andy Green1b265272013-02-09 14:01:09 +0800998&nbsp; &nbsp; <i>struct libwebsocket_protocols *</i> <b>protocols</b>;<br>
999&nbsp; &nbsp; <i>struct libwebsocket_extension *</i> <b>extensions</b>;<br>
1000&nbsp; &nbsp; <i>const char *</i> <b>ssl_cert_filepath</b>;<br>
1001&nbsp; &nbsp; <i>const char *</i> <b>ssl_private_key_filepath</b>;<br>
1002&nbsp; &nbsp; <i>const char *</i> <b>ssl_ca_filepath</b>;<br>
Andy Green2672fb22013-02-22 09:54:35 +08001003&nbsp; &nbsp; <i>const char *</i> <b>ssl_cipher_list</b>;<br>
Andy Green1b265272013-02-09 14:01:09 +08001004&nbsp; &nbsp; <i>int</i> <b>gid</b>;<br>
1005&nbsp; &nbsp; <i>int</i> <b>uid</b>;<br>
1006&nbsp; &nbsp; <i>unsigned int</i> <b>options</b>;<br>
1007&nbsp; &nbsp; <i>void *</i> <b>user</b>;<br>
Andy Greena690cd02013-02-09 12:25:31 +08001008&nbsp; &nbsp; <i>int</i> <b>ka_time</b>;<br>
1009&nbsp; &nbsp; <i>int</i> <b>ka_probes</b>;<br>
1010&nbsp; &nbsp; <i>int</i> <b>ka_interval</b>;<br>
Andy Green1b265272013-02-09 14:01:09 +08001011};<br>
1012<h3>Members</h3>
1013<dl>
1014<dt><b>port</b>
1015<dd>Port to listen on... you can use 0 to suppress listening on
1016any port, that's what you want if you are not running a
1017websocket server at all but just using it as a client
Andy Green7a506ba2013-02-12 10:13:02 +08001018<dt><b>iface</b>
1019<dd>NULL to bind the listen socket to all interfaces, or the
1020interface name, eg, "eth2"
Andy Green1b265272013-02-09 14:01:09 +08001021<dt><b>protocols</b>
1022<dd>Array of structures listing supported protocols and a protocol-
1023specific callback for each one. The list is ended with an
1024entry that has a NULL callback pointer.
1025It's not const because we write the owning_server member
1026<dt><b>extensions</b>
1027<dd>NULL or array of libwebsocket_extension structs listing the
1028extensions this context supports. If you configured with
1029--without-extensions, you should give NULL here.
1030<dt><b>ssl_cert_filepath</b>
1031<dd>If libwebsockets was compiled to use ssl, and you want
1032to listen using SSL, set to the filepath to fetch the
1033server cert from, otherwise NULL for unencrypted
1034<dt><b>ssl_private_key_filepath</b>
1035<dd>filepath to private key if wanting SSL mode,
1036else ignored
1037<dt><b>ssl_ca_filepath</b>
1038<dd>CA certificate filepath or NULL
Andy Green2672fb22013-02-22 09:54:35 +08001039<dt><b>ssl_cipher_list</b>
1040<dd>List of valid ciphers to use (eg,
1041"RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aNULL"
1042or you can leave it as NULL to get "DEFAULT"
Andy Green1b265272013-02-09 14:01:09 +08001043<dt><b>gid</b>
1044<dd>group id to change to after setting listen socket, or -1.
1045<dt><b>uid</b>
1046<dd>user id to change to after setting listen socket, or -1.
1047<dt><b>options</b>
1048<dd>0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK
1049<dt><b>user</b>
1050<dd>optional user pointer that can be recovered via the context
1051pointer using libwebsocket_context_user
Andy Greena690cd02013-02-09 12:25:31 +08001052<dt><b>ka_time</b>
1053<dd>0 for no keepalive, otherwise apply this keepalive timeout to
1054all libwebsocket sockets, client or server
1055<dt><b>ka_probes</b>
1056<dd>if ka_time was nonzero, after the timeout expires how many
1057times to try to get a response from the peer before giving up
1058and killing the connection
1059<dt><b>ka_interval</b>
1060<dd>if ka_time was nonzero, how long to wait before each ka_probes
1061attempt
Andy Green1b265272013-02-09 14:01:09 +08001062</dl>
1063<hr>