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