Fixed compilation on Windows.
[profile/ivi/libwebsockets.git] / libwebsockets-api-doc.html
1 <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
23 signed 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
32 the server, or just one.  The server will pick the one it
33 likes best.
34 <dt><b>ietf_version_or_minus_one</b>
35 <dd>-1 to ask to connect using the default, latest
36 protocol supported, or the specific protocol ordinal
37 </dl>
38 <h3>Description</h3>
39 <blockquote>
40 This 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
66 signed 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
75 the server, or just one.  The server will pick the one it
76 likes best.
77 <dt><b>ietf_version_or_minus_one</b>
78 <dd>-1 to ask to connect using the default, latest
79 protocol 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>
85 This function creates a connection to a remote server
86 </blockquote>
87 <hr>
88 <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>
100 returns a const char * to a string like "1.1 178d78c"
101 representing the library version followed by the git head hash it
102 was built from
103 </blockquote>
104 <hr>
105 <h2>libwebsockets_hangup_on_client - Server calls to terminate client connection</h2>
106 <i>void</i>
107 <b>libwebsockets_hangup_on_client</b>
108 (<i>struct libwebsocket_context *</i> <b>context</b>,
109 <i>int</i> <b>fd</b>)
110 <h3>Arguments</h3>
111 <dl>
112 <dt><b>context</b>
113 <dd>libwebsockets context
114 <dt><b>fd</b>
115 <dd>Connection socket descriptor
116 </dl>
117 <hr>
118 <h2>libwebsockets_get_peer_addresses - Get client address information</h2>
119 <i>void</i>
120 <b>libwebsockets_get_peer_addresses</b>
121 (<i>struct libwebsocket_context *</i> <b>context</b>,
122 <i>struct libwebsocket *</i> <b>wsi</b>,
123 <i>int</i> <b>fd</b>,
124 <i>char *</i> <b>name</b>,
125 <i>int</i> <b>name_len</b>,
126 <i>char *</i> <b>rip</b>,
127 <i>int</i> <b>rip_len</b>)
128 <h3>Arguments</h3>
129 <dl>
130 <dt><b>context</b>
131 <dd>Libwebsockets context
132 <dt><b>wsi</b>
133 <dd>Local struct libwebsocket associated with
134 <dt><b>fd</b>
135 <dd>Connection socket descriptor
136 <dt><b>name</b>
137 <dd>Buffer to take client address name
138 <dt><b>name_len</b>
139 <dd>Length of client address name buffer
140 <dt><b>rip</b>
141 <dd>Buffer to take client address IP qotted quad
142 <dt><b>rip_len</b>
143 <dd>Length of client address IP buffer
144 </dl>
145 <h3>Description</h3>
146 <blockquote>
147 This function fills in <tt><b>name</b></tt> and <tt><b>rip</b></tt> with the name and IP of
148 the client connected with socket descriptor <tt><b>fd</b></tt>.  Names may be
149 truncated if there is not enough room.  If either cannot be
150 determined, they will be returned as valid zero-length strings.
151 </blockquote>
152 <hr>
153 <h2>libwebsocket_service_fd - Service polled socket with something waiting</h2>
154 <i>int</i>
155 <b>libwebsocket_service_fd</b>
156 (<i>struct libwebsocket_context *</i> <b>context</b>,
157 <i>struct pollfd *</i> <b>pollfd</b>)
158 <h3>Arguments</h3>
159 <dl>
160 <dt><b>context</b>
161 <dd>Websocket context
162 <dt><b>pollfd</b>
163 <dd>The pollfd entry describing the socket fd and which events
164 happened.
165 </dl>
166 <h3>Description</h3>
167 <blockquote>
168 This function takes a pollfd that has POLLIN or POLLOUT activity and
169 services it according to the state of the associated
170 struct libwebsocket.
171 <p>
172 The one call deals with all "service" that might happen on a socket
173 including listen accepts, http files as well as websocket protocol.
174 </blockquote>
175 <hr>
176 <h2>libwebsocket_context_destroy - Destroy the websocket context</h2>
177 <i>void</i>
178 <b>libwebsocket_context_destroy</b>
179 (<i>struct libwebsocket_context *</i> <b>context</b>)
180 <h3>Arguments</h3>
181 <dl>
182 <dt><b>context</b>
183 <dd>Websocket context
184 </dl>
185 <h3>Description</h3>
186 <blockquote>
187 This function closes any active connections and then frees the
188 context.  After calling this, any further use of the context is
189 undefined.
190 </blockquote>
191 <hr>
192 <h2>libwebsocket_context_user - get the user data associated with the context</h2>
193 <i>LWS_EXTERN void *</i>
194 <b>libwebsocket_context_user</b>
195 (<i>struct libwebsocket_context *</i> <b>context</b>)
196 <h3>Arguments</h3>
197 <dl>
198 <dt><b>context</b>
199 <dd>Websocket context
200 </dl>
201 <h3>Description</h3>
202 <blockquote>
203 This returns the optional user allocation that can be attached to
204 the context the sockets live in at context_create time.  It's a way
205 to let all sockets serviced in the same context share data without
206 using globals statics in the user code.
207 </blockquote>
208 <hr>
209 <h2>libwebsocket_service - Service any pending websocket activity</h2>
210 <i>int</i>
211 <b>libwebsocket_service</b>
212 (<i>struct libwebsocket_context *</i> <b>context</b>,
213 <i>int</i> <b>timeout_ms</b>)
214 <h3>Arguments</h3>
215 <dl>
216 <dt><b>context</b>
217 <dd>Websocket context
218 <dt><b>timeout_ms</b>
219 <dd>Timeout for poll; 0 means return immediately if nothing needed
220 service otherwise block and service immediately, returning
221 after the timeout if nothing needed service.
222 </dl>
223 <h3>Description</h3>
224 <blockquote>
225 This function deals with any pending websocket traffic, for three
226 kinds of event.  It handles these events on both server and client
227 types of connection the same.
228 <p>
229 1) Accept new connections to our context's server
230 <p>
231 2) Call the receive callback for incoming frame data received by
232 server or client connections.
233 <p>
234 You need to call this service function periodically to all the above
235 functions to happen; if your application is single-threaded you can
236 just call it in your main event loop.
237 <p>
238 Alternatively you can fork a new process that asynchronously handles
239 calling this service in a loop.  In that case you are happy if this
240 call blocks your thread until it needs to take care of something and
241 would call it with a large nonzero timeout.  Your loop then takes no
242 CPU while there is nothing happening.
243 <p>
244 If you are calling it in a single-threaded app, you don't want it to
245 wait around blocking other things in your loop from happening, so you
246 would call it with a timeout_ms of 0, so it returns immediately if
247 nothing is pending, or as soon as it services whatever was pending.
248 </blockquote>
249 <hr>
250 <h2>libwebsocket_callback_on_writable - Request a callback when this socket becomes able to be written to without blocking</h2>
251 <i>int</i>
252 <b>libwebsocket_callback_on_writable</b>
253 (<i>struct libwebsocket_context *</i> <b>context</b>,
254 <i>struct libwebsocket *</i> <b>wsi</b>)
255 <h3>Arguments</h3>
256 <dl>
257 <dt><b>context</b>
258 <dd>libwebsockets context
259 <dt><b>wsi</b>
260 <dd>Websocket connection instance to get callback for
261 </dl>
262 <hr>
263 <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>
264 <i>int</i>
265 <b>libwebsocket_callback_on_writable_all_protocol</b>
266 (<i>const struct libwebsocket_protocols *</i> <b>protocol</b>)
267 <h3>Arguments</h3>
268 <dl>
269 <dt><b>protocol</b>
270 <dd>Protocol whose connections will get callbacks
271 </dl>
272 <hr>
273 <h2>libwebsocket_set_timeout - marks the wsi as subject to a timeout</h2>
274 <i>void</i>
275 <b>libwebsocket_set_timeout</b>
276 (<i>struct libwebsocket *</i> <b>wsi</b>,
277 <i>enum pending_timeout</i> <b>reason</b>,
278 <i>int</i> <b>secs</b>)
279 <h3>Arguments</h3>
280 <dl>
281 <dt><b>wsi</b>
282 <dd>Websocket connection instance
283 <dt><b>reason</b>
284 <dd>timeout reason
285 <dt><b>secs</b>
286 <dd>how many seconds
287 </dl>
288 <h3>Description</h3>
289 <blockquote>
290 <p>
291 You will not need this unless you are doing something special
292 </blockquote>
293 <hr>
294 <h2>libwebsocket_get_socket_fd - returns the socket file descriptor</h2>
295 <i>int</i>
296 <b>libwebsocket_get_socket_fd</b>
297 (<i>struct libwebsocket *</i> <b>wsi</b>)
298 <h3>Arguments</h3>
299 <dl>
300 <dt><b>wsi</b>
301 <dd>Websocket connection instance
302 </dl>
303 <h3>Description</h3>
304 <blockquote>
305 <p>
306 You will not need this unless you are doing something special
307 </blockquote>
308 <hr>
309 <h2>libwebsocket_rx_flow_control - Enable and disable socket servicing for receieved packets.</h2>
310 <i>int</i>
311 <b>libwebsocket_rx_flow_control</b>
312 (<i>struct libwebsocket *</i> <b>wsi</b>,
313 <i>int</i> <b>enable</b>)
314 <h3>Arguments</h3>
315 <dl>
316 <dt><b>wsi</b>
317 <dd>Websocket connection instance to get callback for
318 <dt><b>enable</b>
319 <dd>0 = disable read servicing for this connection, 1 = enable
320 </dl>
321 <h3>Description</h3>
322 <blockquote>
323 <p>
324 If the output side of a server process becomes choked, this allows flow
325 control for the input side.
326 </blockquote>
327 <hr>
328 <h2>libwebsocket_canonical_hostname - returns this host's hostname</h2>
329 <i>const char *</i>
330 <b>libwebsocket_canonical_hostname</b>
331 (<i>struct libwebsocket_context *</i> <b>context</b>)
332 <h3>Arguments</h3>
333 <dl>
334 <dt><b>context</b>
335 <dd>Websocket context
336 </dl>
337 <h3>Description</h3>
338 <blockquote>
339 <p>
340 This is typically used by client code to fill in the host parameter
341 when making a client connection.  You can only call it after the context
342 has been created.
343 </blockquote>
344 <hr>
345 <h2>libwebsocket_create_context - Create the websocket handler</h2>
346 <i>struct libwebsocket_context *</i>
347 <b>libwebsocket_create_context</b>
348 (<i>struct lws_context_creation_info *</i> <b>info</b>)
349 <h3>Arguments</h3>
350 <dl>
351 <dt><b>info</b>
352 <dd>pointer to struct with parameters
353 </dl>
354 <h3>Description</h3>
355 <blockquote>
356 This function creates the listening socket (if serving) and takes care
357 of all initialization in one step.
358 <p>
359 After initialization, it returns a struct libwebsocket_context * that
360 represents this server.  After calling, user code needs to take care
361 of calling <b>libwebsocket_service</b> with the context pointer to get the
362 server's sockets serviced.  This can be done in the same process context
363 or a forked process, or another thread,
364 <p>
365 The protocol callback functions are called for a handful of events
366 including http requests coming in, websocket connections becoming
367 established, and data arriving; it's also called periodically to allow
368 async transmission.
369 <p>
370 HTTP requests are sent always to the FIRST protocol in <tt><b>protocol</b></tt>, since
371 at that time websocket protocol has not been negotiated.  Other
372 protocols after the first one never see any HTTP callack activity.
373 <p>
374 The server created is a simple http server by default; part of the
375 websocket standard is upgrading this http connection to a websocket one.
376 <p>
377 This allows the same server to provide files like scripts and favicon /
378 images or whatever over http and dynamic data over websockets all in
379 one place; they're all handled in the user callback.
380 </blockquote>
381 <hr>
382 <h2>libwebsockets_get_protocol - Returns a protocol pointer from a websocket connection.</h2>
383 <i>const struct libwebsocket_protocols *</i>
384 <b>libwebsockets_get_protocol</b>
385 (<i>struct libwebsocket *</i> <b>wsi</b>)
386 <h3>Arguments</h3>
387 <dl>
388 <dt><b>wsi</b>
389 <dd>pointer to struct websocket you want to know the protocol of
390 </dl>
391 <h3>Description</h3>
392 <blockquote>
393 <p>
394 Some apis can act on all live connections of a given protocol,
395 this is how you can get a pointer to the active protocol if needed.
396 </blockquote>
397 <hr>
398 <h2>lws_set_log_level - Set the logging bitfield</h2>
399 <i>void</i>
400 <b>lws_set_log_level</b>
401 (<i>int</i> <b>level</b>,
402 <i>void (*</i><b>log_emit_function</b>) <i>(int level,                                                        const char *line)</i>)
403 <h3>Arguments</h3>
404 <dl>
405 <dt><b>level</b>
406 <dd>OR together the LLL_ debug contexts you want output from
407 <dt><b>log_emit_function</b>
408 <dd>NULL to leave it as it is, or a user-supplied
409 function to perform log string emission instead of
410 the default stderr one.
411 </dl>
412 <h3>Description</h3>
413 <blockquote>
414 log level defaults to "err" and "warn" contexts enabled only and
415 emission on stderr.
416 </blockquote>
417 <hr>
418 <h2>libwebsocket_write - Apply protocol then write data to client</h2>
419 <i>int</i>
420 <b>libwebsocket_write</b>
421 (<i>struct libwebsocket *</i> <b>wsi</b>,
422 <i>unsigned char *</i> <b>buf</b>,
423 <i>size_t</i> <b>len</b>,
424 <i>enum libwebsocket_write_protocol</i> <b>protocol</b>)
425 <h3>Arguments</h3>
426 <dl>
427 <dt><b>wsi</b>
428 <dd>Websocket instance (available from user callback)
429 <dt><b>buf</b>
430 <dd>The data to send.  For data being sent on a websocket
431 connection (ie, not default http), this buffer MUST have
432 LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE the pointer
433 and an additional LWS_SEND_BUFFER_POST_PADDING bytes valid
434 in the buffer after (buf + len).  This is so the protocol
435 header and trailer data can be added in-situ.
436 <dt><b>len</b>
437 <dd>Count of the data bytes in the payload starting from buf
438 <dt><b>protocol</b>
439 <dd>Use LWS_WRITE_HTTP to reply to an http connection, and one
440 of LWS_WRITE_BINARY or LWS_WRITE_TEXT to send appropriate
441 data on a websockets connection.  Remember to allow the extra
442 bytes before and after buf if LWS_WRITE_BINARY or LWS_WRITE_TEXT
443 are used.
444 </dl>
445 <h3>Description</h3>
446 <blockquote>
447 This function provides the way to issue data back to the client
448 for both http and websocket protocols.
449 <p>
450 In the case of sending using websocket protocol, be sure to allocate
451 valid storage before and after buf as explained above.  This scheme
452 allows maximum efficiency of sending data and protocol in a single
453 packet while not burdening the user code with any protocol knowledge.
454 </blockquote>
455 <hr>
456 <h2>libwebsockets_serve_http_file - Send a file back to the client using http</h2>
457 <i>int</i>
458 <b>libwebsockets_serve_http_file</b>
459 (<i>struct libwebsocket_context *</i> <b>context</b>,
460 <i>struct libwebsocket *</i> <b>wsi</b>,
461 <i>const char *</i> <b>file</b>,
462 <i>const char *</i> <b>content_type</b>)
463 <h3>Arguments</h3>
464 <dl>
465 <dt><b>context</b>
466 <dd>libwebsockets context
467 <dt><b>wsi</b>
468 <dd>Websocket instance (available from user callback)
469 <dt><b>file</b>
470 <dd>The file to issue over http
471 <dt><b>content_type</b>
472 <dd>The http content type, eg, text/html
473 </dl>
474 <h3>Description</h3>
475 <blockquote>
476 This function is intended to be called from the callback in response
477 to http requests from the client.  It allows the callback to issue
478 local files down the http link in a single step.
479 <p>
480 Returning &lt;0 indicates error and the wsi should be closed.  Returning
481 &gt;0 indicates the file was completely sent and the wsi should be closed.
482 ==0 indicates the file transfer is started and needs more service later,
483 the wsi should be left alone.
484 </blockquote>
485 <hr>
486 <h2>lws_frame_is_binary - </h2>
487 <i>int</i>
488 <b>lws_frame_is_binary</b>
489 (<i>struct libwebsocket *</i> <b>wsi</b>)
490 <h3>Arguments</h3>
491 <dl>
492 <dt><b>wsi</b>
493 <dd>the connection we are inquiring about
494 </dl>
495 <h3>Description</h3>
496 <blockquote>
497 This is intended to be called from the LWS_CALLBACK_RECEIVE callback if
498 it's interested to see if the frame it's dealing with was sent in binary
499 mode.
500 </blockquote>
501 <hr>
502 <h2>libwebsockets_remaining_packet_payload - Bytes to come before "overall" rx packet is complete</h2>
503 <i>size_t</i>
504 <b>libwebsockets_remaining_packet_payload</b>
505 (<i>struct libwebsocket *</i> <b>wsi</b>)
506 <h3>Arguments</h3>
507 <dl>
508 <dt><b>wsi</b>
509 <dd>Websocket instance (available from user callback)
510 </dl>
511 <h3>Description</h3>
512 <blockquote>
513 This function is intended to be called from the callback if the
514 user code is interested in "complete packets" from the client.
515 libwebsockets just passes through payload as it comes and issues a buffer
516 additionally when it hits a built-in limit.  The LWS_CALLBACK_RECEIVE
517 callback handler can use this API to find out if the buffer it has just
518 been given is the last piece of a "complete packet" from the client --
519 when that is the case <b>libwebsockets_remaining_packet_payload</b> will return
520 0.
521 <p>
522 Many protocols won't care becuse their packets are always small.
523 </blockquote>
524 <hr>
525 <h2>callback - User server actions</h2>
526 <i>LWS_EXTERN int</i>
527 <b>callback</b>
528 (<i>struct libwebsocket_context *</i> <b>context</b>,
529 <i>struct libwebsocket *</i> <b>wsi</b>,
530 <i>enum libwebsocket_callback_reasons</i> <b>reason</b>,
531 <i>void *</i> <b>user</b>,
532 <i>void *</i> <b>in</b>,
533 <i>size_t</i> <b>len</b>)
534 <h3>Arguments</h3>
535 <dl>
536 <dt><b>context</b>
537 <dd>Websockets context
538 <dt><b>wsi</b>
539 <dd>Opaque websocket instance pointer
540 <dt><b>reason</b>
541 <dd>The reason for the call
542 <dt><b>user</b>
543 <dd>Pointer to per-session user data allocated by library
544 <dt><b>in</b>
545 <dd>Pointer used for some callback reasons
546 <dt><b>len</b>
547 <dd>Length set for some callback reasons
548 </dl>
549 <h3>Description</h3>
550 <blockquote>
551 This callback is the way the user controls what is served.  All the
552 protocol detail is hidden and handled by the library.
553 <p>
554 For each connection / session there is user data allocated that is
555 pointed to by "user".  You set the size of this user data area when
556 the library is initialized with libwebsocket_create_server.
557 <p>
558 You get an opportunity to initialize user data when called back with
559 LWS_CALLBACK_ESTABLISHED reason.
560 </blockquote>
561 <h3>LWS_CALLBACK_ESTABLISHED</h3>
562 <blockquote>
563 after the server completes a handshake with
564 an incoming client
565 </blockquote>
566 <h3>LWS_CALLBACK_CLIENT_CONNECTION_ERROR</h3>
567 <blockquote>
568 the request client connection has
569 been unable to complete a handshake with the remote server
570 </blockquote>
571 <h3>LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH</h3>
572 <blockquote>
573 this is the last chance for the
574 client user code to examine the http headers
575 and decide to reject the connection.  If the
576 content in the headers is interesting to the
577 client (url, etc) it needs to copy it out at
578 this point since it will be destroyed before
579 the CLIENT_ESTABLISHED call
580 </blockquote>
581 <h3>LWS_CALLBACK_CLIENT_ESTABLISHED</h3>
582 <blockquote>
583 after your client connection completed
584 a handshake with the remote server
585 </blockquote>
586 <h3>LWS_CALLBACK_CLOSED</h3>
587 <blockquote>
588 when the websocket session ends
589 </blockquote>
590 <h3>LWS_CALLBACK_RECEIVE</h3>
591 <blockquote>
592 data has appeared for this server endpoint from a
593 remote client, it can be found at *in and is
594 len bytes long
595 </blockquote>
596 <h3>LWS_CALLBACK_CLIENT_RECEIVE_PONG</h3>
597 <blockquote>
598 if you elected to see PONG packets,
599 they appear with this callback reason.  PONG
600 packets only exist in 04+ protocol
601 </blockquote>
602 <h3>LWS_CALLBACK_CLIENT_RECEIVE</h3>
603 <blockquote>
604 data has appeared from the server for the
605 client connection, it can be found at *in and
606 is len bytes long
607 </blockquote>
608 <h3>LWS_CALLBACK_HTTP</h3>
609 <blockquote>
610 an http request has come from a client that is not
611 asking to upgrade the connection to a websocket
612 one.  This is a chance to serve http content,
613 for example, to send a script to the client
614 which will then open the websockets connection.
615 <tt><b>in</b></tt> points to the URI path requested and
616 <b>libwebsockets_serve_http_file</b> makes it very
617 simple to send back a file to the client.
618 Normally after sending the file you are done
619 with the http connection, since the rest of the
620 activity will come by websockets from the script
621 that was delivered by http, so you will want to
622 return 1; to close and free up the connection.
623 That's important because it uses a slot in the
624 total number of client connections allowed set
625 by MAX_CLIENTS.
626 </blockquote>
627 <h3>LWS_CALLBACK_HTTP_FILE_COMPLETION</h3>
628 <blockquote>
629 a file requested to be send down
630 http link has completed.
631 </blockquote>
632 <h3>LWS_CALLBACK_SERVER_WRITEABLE</h3>
633 <blockquote>
634 If you call
635 <b>libwebsocket_callback_on_writable</b> on a connection, you will
636 get one of these callbacks coming when the connection socket
637 is able to accept another write packet without blocking.
638 If it already was able to take another packet without blocking,
639 you'll get this callback at the next call to the service loop
640 function.  Notice that CLIENTs get LWS_CALLBACK_CLIENT_WRITEABLE
641 and servers get LWS_CALLBACK_SERVER_WRITEABLE.
642 </blockquote>
643 <h3>LWS_CALLBACK_FILTER_NETWORK_CONNECTION</h3>
644 <blockquote>
645 called when a client connects to
646 the server at network level; the connection is accepted but then
647 passed to this callback to decide whether to hang up immediately
648 or not, based on the client IP.  <tt><b>user</b></tt> contains the connection
649 socket's descriptor.  Return non-zero to terminate
650 the connection before sending or receiving anything.
651 Because this happens immediately after the network connection
652 from the client, there's no websocket protocol selected yet so
653 this callback is issued only to protocol 0.
654 </blockquote>
655 <h3>LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION</h3>
656 <blockquote>
657 called when the handshake has
658 been received and parsed from the client, but the response is
659 not sent yet.  Return non-zero to disallow the connection.
660 <tt><b>user</b></tt> is a pointer to an array of struct lws_tokens, you can
661 use the header enums lws_token_indexes from libwebsockets.h
662 to check for and read the supported header presence and
663 content before deciding to allow the handshake to proceed or
664 to kill the connection.
665 </blockquote>
666 <h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS</h3>
667 <blockquote>
668 if configured for
669 including OpenSSL support, this callback allows your user code
670 to perform extra <b>SSL_CTX_load_verify_locations</b> or similar
671 calls to direct OpenSSL where to find certificates the client
672 can use to confirm the remote server identity.  <tt><b>user</b></tt> is the
673 OpenSSL SSL_CTX*
674 </blockquote>
675 <h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS</h3>
676 <blockquote>
677 if configured for
678 including OpenSSL support, this callback allows your user code
679 to load extra certifcates into the server which allow it to
680 verify the validity of certificates returned by clients.  <tt><b>user</b></tt>
681 is the server's OpenSSL SSL_CTX*
682 </blockquote>
683 <h3>LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION</h3>
684 <blockquote>
685 if the
686 libwebsockets context was created with the option
687 LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT, then this
688 callback is generated during OpenSSL verification of the cert
689 sent from the client.  It is sent to protocol[0] callback as
690 no protocol has been negotiated on the connection yet.
691 Notice that the libwebsockets context and wsi are both NULL
692 during this callback.  See
693 </blockquote>
694 <h3>http</h3>
695 <blockquote>
696 //www.openssl.org/docs/ssl/SSL_CTX_set_verify.html
697 to understand more detail about the OpenSSL callback that
698 generates this libwebsockets callback and the meanings of the
699 arguments passed.  In this callback, <tt><b>user</b></tt> is the x509_ctx,
700 <tt><b>in</b></tt> is the ssl pointer and <tt><b>len</b></tt> is preverify_ok
701 Notice that this callback maintains libwebsocket return
702 conventions, return 0 to mean the cert is OK or 1 to fail it.
703 This also means that if you don't handle this callback then
704 the default callback action of returning 0 allows the client
705 certificates.
706 </blockquote>
707 <h3>LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER</h3>
708 <blockquote>
709 this callback happens
710 when a client handshake is being compiled.  <tt><b>user</b></tt> is NULL,
711 <tt><b>in</b></tt> is a char **, it's pointing to a char * which holds the
712 next location in the header buffer where you can add
713 headers, and <tt><b>len</b></tt> is the remaining space in the header buffer,
714 which is typically some hundreds of bytes.  So, to add a canned
715 cookie, your handler code might look similar to:
716 <p>
717 char **p = (char **)in;
718 <p>
719 if (len &lt; 100)
720 return 1;
721 <p>
722 *p += sprintf(*p, "Cookie: a=b\x0d\x0a");
723 <p>
724 return 0;
725 <p>
726 Notice if you add anything, you just have to take care about
727 the CRLF on the line you added.  Obviously this callback is
728 optional, if you don't handle it everything is fine.
729 <p>
730 Notice the callback is coming to protocols[0] all the time,
731 because there is no specific protocol handshook yet.
732 </blockquote>
733 <h3>LWS_CALLBACK_CONFIRM_EXTENSION_OKAY</h3>
734 <blockquote>
735 When the server handshake code
736 sees that it does support a requested extension, before
737 accepting the extension by additing to the list sent back to
738 the client it gives this callback just to check that it's okay
739 to use that extension.  It calls back to the requested protocol
740 and with <tt><b>in</b></tt> being the extension name, <tt><b>len</b></tt> is 0 and <tt><b>user</b></tt> is
741 valid.  Note though at this time the ESTABLISHED callback hasn't
742 happened yet so if you initialize <tt><b>user</b></tt> content there, <tt><b>user</b></tt>
743 content during this callback might not be useful for anything.
744 Notice this callback comes to protocols[0].
745 </blockquote>
746 <h3>LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED</h3>
747 <blockquote>
748 When a client
749 connection is being prepared to start a handshake to a server,
750 each supported extension is checked with protocols[0] callback
751 with this reason, giving the user code a chance to suppress the
752 claim to support that extension by returning non-zero.  If
753 unhandled, by default 0 will be returned and the extension
754 support included in the header to the server.  Notice this
755 callback comes to protocols[0].
756 </blockquote>
757 <h3>LWS_CALLBACK_PROTOCOL_INIT</h3>
758 <blockquote>
759 One-time call per protocol so it can
760 do initial setup / allocations etc
761 </blockquote>
762 <h3>LWS_CALLBACK_PROTOCOL_DESTROY</h3>
763 <blockquote>
764 One-time call per protocol indicating
765 this protocol won't get used at all after this callback, the
766 context is getting destroyed.  Take the opportunity to
767 deallocate everything that was allocated by the protocol.
768 <p>
769 The next four reasons are optional and only need taking care of if you
770 will be integrating libwebsockets sockets into an external polling
771 array.
772 </blockquote>
773 <h3>LWS_CALLBACK_ADD_POLL_FD</h3>
774 <blockquote>
775 libwebsocket deals with its <b>poll</b> loop
776 internally, but in the case you are integrating with another
777 server you will need to have libwebsocket sockets share a
778 polling array with the other server.  This and the other
779 POLL_FD related callbacks let you put your specialized
780 poll array interface code in the callback for protocol 0, the
781 first protocol you support, usually the HTTP protocol in the
782 serving case.  This callback happens when a socket needs to be
783 </blockquote>
784 <h3>added to the polling loop</h3>
785 <blockquote>
786 <tt><b>user</b></tt> contains the fd, and
787 <tt><b>len</b></tt> is the events bitmap (like, POLLIN).  If you are using the
788 internal polling loop (the "service" callback), you can just
789 ignore these callbacks.
790 </blockquote>
791 <h3>LWS_CALLBACK_DEL_POLL_FD</h3>
792 <blockquote>
793 This callback happens when a socket descriptor
794 needs to be removed from an external polling array.  <tt><b>user</b></tt> is
795 the socket desricptor.  If you are using the internal polling
796 loop, you can just ignore it.
797 </blockquote>
798 <h3>LWS_CALLBACK_SET_MODE_POLL_FD</h3>
799 <blockquote>
800 This callback happens when libwebsockets
801 wants to modify the events for the socket descriptor in <tt><b>user</b></tt>.
802 The handler should OR <tt><b>len</b></tt> on to the events member of the pollfd
803 struct for this socket descriptor.  If you are using the
804 internal polling loop, you can just ignore it.
805 </blockquote>
806 <h3>LWS_CALLBACK_CLEAR_MODE_POLL_FD</h3>
807 <blockquote>
808 This callback occurs when libwebsockets
809 wants to modify the events for the socket descriptor in <tt><b>user</b></tt>.
810 The handler should AND ~<tt><b>len</b></tt> on to the events member of the
811 pollfd struct for this socket descriptor.  If you are using the
812 internal polling loop, you can just ignore it.
813 </blockquote>
814 <hr>
815 <h2>extension_callback - Hooks to allow extensions to operate</h2>
816 <i>LWS_EXTERN int</i>
817 <b>extension_callback</b>
818 (<i>struct libwebsocket_context *</i> <b>context</b>,
819 <i>struct libwebsocket_extension *</i> <b>ext</b>,
820 <i>struct libwebsocket *</i> <b>wsi</b>,
821 <i>enum libwebsocket_extension_callback_reasons</i> <b>reason</b>,
822 <i>void *</i> <b>user</b>,
823 <i>void *</i> <b>in</b>,
824 <i>size_t</i> <b>len</b>)
825 <h3>Arguments</h3>
826 <dl>
827 <dt><b>context</b>
828 <dd>Websockets context
829 <dt><b>ext</b>
830 <dd>This extension
831 <dt><b>wsi</b>
832 <dd>Opaque websocket instance pointer
833 <dt><b>reason</b>
834 <dd>The reason for the call
835 <dt><b>user</b>
836 <dd>Pointer to per-session user data allocated by library
837 <dt><b>in</b>
838 <dd>Pointer used for some callback reasons
839 <dt><b>len</b>
840 <dd>Length set for some callback reasons
841 </dl>
842 <h3>Description</h3>
843 <blockquote>
844 Each extension that is active on a particular connection receives
845 callbacks during the connection lifetime to allow the extension to
846 operate on websocket data and manage itself.
847 <p>
848 Libwebsockets takes care of allocating and freeing "user" memory for
849 each active extension on each connection.  That is what is pointed to
850 by the <tt><b>user</b></tt> parameter.
851 </blockquote>
852 <h3>LWS_EXT_CALLBACK_CONSTRUCT</h3>
853 <blockquote>
854 called when the server has decided to
855 select this extension from the list provided by the client,
856 just before the server will send back the handshake accepting
857 the connection with this extension active.  This gives the
858 extension a chance to initialize its connection context found
859 in <tt><b>user</b></tt>.
860 </blockquote>
861 <h3>LWS_EXT_CALLBACK_CLIENT_CONSTRUCT</h3>
862 <blockquote>
863 same as LWS_EXT_CALLBACK_CONSTRUCT
864 but called when client is instantiating this extension.  Some
865 extensions will work the same on client and server side and then
866 you can just merge handlers for both CONSTRUCTS.
867 </blockquote>
868 <h3>LWS_EXT_CALLBACK_DESTROY</h3>
869 <blockquote>
870 called when the connection the extension was
871 being used on is about to be closed and deallocated.  It's the
872 last chance for the extension to deallocate anything it has
873 allocated in the user data (pointed to by <tt><b>user</b></tt>) before the
874 user data is deleted.  This same callback is used whether you
875 are in client or server instantiation context.
876 </blockquote>
877 <h3>LWS_EXT_CALLBACK_PACKET_RX_PREPARSE</h3>
878 <blockquote>
879 when this extension was active on
880 a connection, and a packet of data arrived at the connection,
881 it is passed to this callback to give the extension a chance to
882 change the data, eg, decompress it.  <tt><b>user</b></tt> is pointing to the
883 extension's private connection context data, <tt><b>in</b></tt> is pointing
884 to an lws_tokens struct, it consists of a char * pointer called
885 token, and an int called token_len.  At entry, these are
886 set to point to the received buffer and set to the content
887 length.  If the extension will grow the content, it should use
888 a new buffer allocated in its private user context data and
889 set the pointed-to lws_tokens members to point to its buffer.
890 </blockquote>
891 <h3>LWS_EXT_CALLBACK_PACKET_TX_PRESEND</h3>
892 <blockquote>
893 this works the same way as
894 LWS_EXT_CALLBACK_PACKET_RX_PREPARSE above, except it gives the
895 extension a chance to change websocket data just before it will
896 be sent out.  Using the same lws_token pointer scheme in <tt><b>in</b></tt>,
897 the extension can change the buffer and the length to be
898 transmitted how it likes.  Again if it wants to grow the
899 buffer safely, it should copy the data into its own buffer and
900 set the lws_tokens token pointer to it.
901 </blockquote>
902 <hr>
903 <h2>struct libwebsocket_protocols - List of protocols and handlers server supports.</h2>
904 <b>struct libwebsocket_protocols</b> {<br>
905 &nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
906 &nbsp; &nbsp; <i>callback_function *</i> <b>callback</b>;<br>
907 &nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
908 &nbsp; &nbsp; <i>size_t</i> <b>rx_buffer_size</b>;<br>
909 &nbsp; &nbsp; <i>struct libwebsocket_context *</i> <b>owning_server</b>;<br>
910 &nbsp; &nbsp; <i>int</i> <b>protocol_index</b>;<br>
911 };<br>
912 <h3>Members</h3>
913 <dl>
914 <dt><b>name</b>
915 <dd>Protocol name that must match the one given in the client
916 Javascript new WebSocket(url, 'protocol') name
917 <dt><b>callback</b>
918 <dd>The service callback used for this protocol.  It allows the
919 service action for an entire protocol to be encapsulated in
920 the protocol-specific callback
921 <dt><b>per_session_data_size</b>
922 <dd>Each new connection using this protocol gets
923 this much memory allocated on connection establishment and
924 freed on connection takedown.  A pointer to this per-connection
925 allocation is passed into the callback in the 'user' parameter
926 <dt><b>rx_buffer_size</b>
927 <dd>if you want atomic frames delivered to the callback, you
928 should set this to the size of the biggest legal frame that
929 you support.  If the frame size is exceeded, there is no
930 error, but the buffer will spill to the user callback when
931 full, which you can detect by using
932 <b>libwebsockets_remaining_packet_payload</b>.  Notice that you
933 just talk about frame size here, the LWS_SEND_BUFFER_PRE_PADDING
934 and post-padding are automatically also allocated on top.
935 <dt><b>owning_server</b>
936 <dd>the server init call fills in this opaque pointer when
937 registering this protocol with the server.
938 <dt><b>protocol_index</b>
939 <dd>which protocol we are starting from zero
940 </dl>
941 <h3>Description</h3>
942 <blockquote>
943 This structure represents one protocol supported by the server.  An
944 array of these structures is passed to <b>libwebsocket_create_server</b>
945 allows as many protocols as you like to be handled by one server.
946 </blockquote>
947 <hr>
948 <h2>struct libwebsocket_extension - An extension we know how to cope with</h2>
949 <b>struct libwebsocket_extension</b> {<br>
950 &nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
951 &nbsp; &nbsp; <i>extension_callback_function *</i> <b>callback</b>;<br>
952 &nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
953 &nbsp; &nbsp; <i>void *</i> <b>per_context_private_data</b>;<br>
954 };<br>
955 <h3>Members</h3>
956 <dl>
957 <dt><b>name</b>
958 <dd>Formal extension name, eg, "deflate-stream"
959 <dt><b>callback</b>
960 <dd>Service callback
961 <dt><b>per_session_data_size</b>
962 <dd>Libwebsockets will auto-malloc this much
963 memory for the use of the extension, a pointer
964 to it comes in the <tt><b>user</b></tt> callback parameter
965 <dt><b>per_context_private_data</b>
966 <dd>Optional storage for this extension that
967 is per-context, so it can track stuff across
968 all sessions, etc, if it wants
969 </dl>
970 <hr>
971 <h2>struct lws_context_creation_info - </h2>
972 <b>struct lws_context_creation_info</b> {<br>
973 &nbsp; &nbsp; <i>int</i> <b>port</b>;<br>
974 &nbsp; &nbsp; <i>struct libwebsocket_protocols *</i> <b>protocols</b>;<br>
975 &nbsp; &nbsp; <i>struct libwebsocket_extension *</i> <b>extensions</b>;<br>
976 &nbsp; &nbsp; <i>const char *</i> <b>ssl_cert_filepath</b>;<br>
977 &nbsp; &nbsp; <i>const char *</i> <b>ssl_private_key_filepath</b>;<br>
978 &nbsp; &nbsp; <i>const char *</i> <b>ssl_ca_filepath</b>;<br>
979 &nbsp; &nbsp; <i>int</i> <b>gid</b>;<br>
980 &nbsp; &nbsp; <i>int</i> <b>uid</b>;<br>
981 &nbsp; &nbsp; <i>unsigned int</i> <b>options</b>;<br>
982 &nbsp; &nbsp; <i>void *</i> <b>user</b>;<br>
983 &nbsp; &nbsp; <i>int</i> <b>ka_time</b>;<br>
984 &nbsp; &nbsp; <i>int</i> <b>ka_probes</b>;<br>
985 &nbsp; &nbsp; <i>int</i> <b>ka_interval</b>;<br>
986 };<br>
987 <h3>Members</h3>
988 <dl>
989 <dt><b>port</b>
990 <dd>Port to listen on... you can use 0 to suppress listening on
991 any port, that's what you want if you are not running a
992 websocket server at all but just using it as a client
993 <dt><b>protocols</b>
994 <dd>Array of structures listing supported protocols and a protocol-
995 specific callback for each one.  The list is ended with an
996 entry that has a NULL callback pointer.
997 It's not const because we write the owning_server member
998 <dt><b>extensions</b>
999 <dd>NULL or array of libwebsocket_extension structs listing the
1000 extensions this context supports.  If you configured with
1001 --without-extensions, you should give NULL here.
1002 <dt><b>ssl_cert_filepath</b>
1003 <dd>If libwebsockets was compiled to use ssl, and you want
1004 to listen using SSL, set to the filepath to fetch the
1005 server cert from, otherwise NULL for unencrypted
1006 <dt><b>ssl_private_key_filepath</b>
1007 <dd>filepath to private key if wanting SSL mode,
1008 else ignored
1009 <dt><b>ssl_ca_filepath</b>
1010 <dd>CA certificate filepath or NULL
1011 <dt><b>gid</b>
1012 <dd>group id to change to after setting listen socket, or -1.
1013 <dt><b>uid</b>
1014 <dd>user id to change to after setting listen socket, or -1.
1015 <dt><b>options</b>
1016 <dd>0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK
1017 <dt><b>user</b>
1018 <dd>optional user pointer that can be recovered via the context
1019 pointer using libwebsocket_context_user
1020 <dt><b>ka_time</b>
1021 <dd>0 for no keepalive, otherwise apply this keepalive timeout to
1022 all libwebsocket sockets, client or server
1023 <dt><b>ka_probes</b>
1024 <dd>if ka_time was nonzero, after the timeout expires how many
1025 times to try to get a response from the peer before giving up
1026 and killing the connection
1027 <dt><b>ka_interval</b>
1028 <dd>if ka_time was nonzero, how long to wait before each ka_probes
1029 attempt
1030 </dl>
1031 <hr>