ws-server: restrict returned Sec-Websocket-Protocol to the chosen name only
[platform/upstream/libwebsockets.git] / libwebsockets-api-doc.html
1 <h2>lws_client_reset - retarget a connected wsi to start over with a new connection (ie, redirect) this only works if still in HTTP, ie, not upgraded yet</h2>
2 <i>struct lws *</i>
3 <b>lws_client_reset</b>
4 (<i>struct lws *</i> <b>wsi</b>,
5 <i>int</i> <b>ssl</b>,
6 <i>const char *</i> <b>address</b>,
7 <i>int</i> <b>port</b>,
8 <i>const char *</i> <b>path</b>,
9 <i>const char *</i> <b>host</b>)
10 <h3>Arguments</h3>
11 <dl>
12 </dl>
13 <h3>wsi</h3>
14 <blockquote>
15 connection to reset
16 </blockquote>
17 <h3>address</h3>
18 <blockquote>
19 network address of the new server
20 </blockquote>
21 <h3>port</h3>
22 <blockquote>
23 port to connect to
24 </blockquote>
25 <h3>path</h3>
26 <blockquote>
27 uri path to connect to on the new server
28 </blockquote>
29 <h3>host</h3>
30 <blockquote>
31 host header to send to the new server
32 </blockquote>
33 <hr>
34 <h2>lws_client_connect_via_info - Connect to another websocket server</h2>
35 <i>struct lws *</i>
36 <b>lws_client_connect_via_info</b>
37 (<i>struct lws_client_connect_info *</i> <b>i</b>)
38 <h3>Arguments</h3>
39 <dl>
40 <dt><b>i</b>
41 <dd>pointer to lws_client_connect_info struct
42 </dl>
43 <h3>Description</h3>
44 <blockquote>
45 This function creates a connection to a remote server
46 </blockquote>
47 <hr>
48 <h2>lws_client_connect_extended - Connect to another websocket server DEPRECATED use lws_client_connect_via_info</h2>
49 <i>struct lws *</i>
50 <b>lws_client_connect_extended</b>
51 (<i>struct lws_context *</i> <b>context</b>,
52 <i>const char *</i> <b>address</b>,
53 <i>int</i> <b>port</b>,
54 <i>int</i> <b>ssl_connection</b>,
55 <i>const char *</i> <b>path</b>,
56 <i>const char *</i> <b>host</b>,
57 <i>const char *</i> <b>origin</b>,
58 <i>const char *</i> <b>protocol</b>,
59 <i>int</i> <b>ietf_version_or_minus_one</b>,
60 <i>void *</i> <b>userdata</b>)
61 <h3>Arguments</h3>
62 <dl>
63 <dt><b>context</b>
64 <dd>Websocket context
65 <dt><b>address</b>
66 <dd>Remote server address, eg, "myserver.com"
67 <dt><b>port</b>
68 <dd>Port to connect to on the remote server, eg, 80
69 <dt><b>ssl_connection</b>
70 <dd>0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self
71 signed certs
72 <dt><b>path</b>
73 <dd>Websocket path on server
74 <dt><b>host</b>
75 <dd>Hostname on server
76 <dt><b>origin</b>
77 <dd>Socket origin name
78 <dt><b>protocol</b>
79 <dd>Comma-separated list of protocols being asked for from
80 the server, or just one.  The server will pick the one it
81 likes best.
82 <dt><b>ietf_version_or_minus_one</b>
83 <dd>-1 to ask to connect using the default, latest
84 protocol supported, or the specific protocol ordinal
85 <dt><b>userdata</b>
86 <dd>Pre-allocated user data
87 </dl>
88 <h3>Description</h3>
89 <blockquote>
90 This function creates a connection to a remote server
91 </blockquote>
92 <hr>
93 <h2>lws_client_connect - Connect to another websocket server DEPRECATED use lws_client_connect_via_info</h2>
94 <i>struct lws *</i>
95 <b>lws_client_connect</b>
96 (<i>struct lws_context *</i> <b>context</b>,
97 <i>const char *</i> <b>address</b>,
98 <i>int</i> <b>port</b>,
99 <i>int</i> <b>ssl_connection</b>,
100 <i>const char *</i> <b>path</b>,
101 <i>const char *</i> <b>host</b>,
102 <i>const char *</i> <b>origin</b>,
103 <i>const char *</i> <b>protocol</b>,
104 <i>int</i> <b>ietf_version_or_minus_one</b>)
105 <h3>Arguments</h3>
106 <dl>
107 <dt><b>context</b>
108 <dd>Websocket context
109 <dt><b>address</b>
110 <dd>Remote server address, eg, "myserver.com"
111 <dt><b>port</b>
112 <dd>Port to connect to on the remote server, eg, 80
113 <dt><b>ssl_connection</b>
114 <dd>0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self
115 signed certs
116 <dt><b>path</b>
117 <dd>Websocket path on server
118 <dt><b>host</b>
119 <dd>Hostname on server
120 <dt><b>origin</b>
121 <dd>Socket origin name
122 <dt><b>protocol</b>
123 <dd>Comma-separated list of protocols being asked for from
124 the server, or just one.  The server will pick the one it
125 likes best.  If you don't want to specify a protocol, which is
126 legal, use NULL here.
127 <dt><b>ietf_version_or_minus_one</b>
128 <dd>-1 to ask to connect using the default, latest
129 protocol supported, or the specific protocol ordinal
130 </dl>
131 <h3>Description</h3>
132 <blockquote>
133 This function creates a connection to a remote server
134 </blockquote>
135 <hr>
136 <h2>lws_get_library_version - </h2>
137 <i>const char *</i>
138 <b>lws_get_library_version</b>
139 (<i></i> <b>void</b>)
140 <h3>Arguments</h3>
141 <dl>
142 <dt><b>void</b>
143 <dd>no arguments
144 </dl>
145 <h3>Description</h3>
146 <blockquote>
147 <p>
148 returns a const char * to a string like "1.1 178d78c"
149 representing the library version followed by the git head hash it
150 was built from
151 </blockquote>
152 <hr>
153 <h2>lws_create_context - Create the websocket handler</h2>
154 <i>struct lws_context *</i>
155 <b>lws_create_context</b>
156 (<i>struct lws_context_creation_info *</i> <b>info</b>)
157 <h3>Arguments</h3>
158 <dl>
159 <dt><b>info</b>
160 <dd>pointer to struct with parameters
161 </dl>
162 <h3>Description</h3>
163 <blockquote>
164 This function creates the listening socket (if serving) and takes care
165 of all initialization in one step.
166 <p>
167 After initialization, it returns a struct lws_context * that
168 represents this server.  After calling, user code needs to take care
169 of calling <b>lws_service</b> with the context pointer to get the
170 server's sockets serviced.  This must be done in the same process
171 context as the initialization call.
172 <p>
173 The protocol callback functions are called for a handful of events
174 including http requests coming in, websocket connections becoming
175 established, and data arriving; it's also called periodically to allow
176 async transmission.
177 <p>
178 HTTP requests are sent always to the FIRST protocol in <tt><b>protocol</b></tt>, since
179 at that time websocket protocol has not been negotiated.  Other
180 protocols after the first one never see any HTTP callack activity.
181 <p>
182 The server created is a simple http server by default; part of the
183 websocket standard is upgrading this http connection to a websocket one.
184 <p>
185 This allows the same server to provide files like scripts and favicon /
186 images or whatever over http and dynamic data over websockets all in
187 one place; they're all handled in the user callback.
188 </blockquote>
189 <hr>
190 <h2>lws_context_destroy - Destroy the websocket context</h2>
191 <i>void</i>
192 <b>lws_context_destroy</b>
193 (<i>struct lws_context *</i> <b>context</b>)
194 <h3>Arguments</h3>
195 <dl>
196 <dt><b>context</b>
197 <dd>Websocket context
198 </dl>
199 <h3>Description</h3>
200 <blockquote>
201 This function closes any active connections and then frees the
202 context.  After calling this, any further use of the context is
203 undefined.
204 </blockquote>
205 <hr>
206 <h2>lws_return_http_status - Return simple http status</h2>
207 <i>int</i>
208 <b>lws_return_http_status</b>
209 (<i>struct lws *</i> <b>wsi</b>,
210 <i>unsigned int</i> <b>code</b>,
211 <i>const char *</i> <b>html_body</b>)
212 <h3>Arguments</h3>
213 <dl>
214 <dt><b>wsi</b>
215 <dd>Websocket instance (available from user callback)
216 <dt><b>code</b>
217 <dd>Status index, eg, 404
218 <dt><b>html_body</b>
219 <dd>User-readable HTML description &lt; 1KB, or NULL
220 </dl>
221 <h3>Description</h3>
222 <blockquote>
223 Helper to report HTTP errors back to the client cleanly and
224 consistently
225 </blockquote>
226 <hr>
227 <h2>lws_set_timeout - marks the wsi as subject to a timeout</h2>
228 <i>void</i>
229 <b>lws_set_timeout</b>
230 (<i>struct lws *</i> <b>wsi</b>,
231 <i>enum pending_timeout</i> <b>reason</b>,
232 <i>int</i> <b>secs</b>)
233 <h3>Arguments</h3>
234 <dl>
235 <dt><b>wsi</b>
236 <dd>Websocket connection instance
237 <dt><b>reason</b>
238 <dd>timeout reason
239 <dt><b>secs</b>
240 <dd>how many seconds
241 </dl>
242 <h3>Description</h3>
243 <blockquote>
244 <p>
245 You will not need this unless you are doing something special
246 </blockquote>
247 <hr>
248 <h2>lws_get_peer_addresses - Get client address information</h2>
249 <i>void</i>
250 <b>lws_get_peer_addresses</b>
251 (<i>struct lws *</i> <b>wsi</b>,
252 <i>lws_sockfd_type</i> <b>fd</b>,
253 <i>char *</i> <b>name</b>,
254 <i>int</i> <b>name_len</b>,
255 <i>char *</i> <b>rip</b>,
256 <i>int</i> <b>rip_len</b>)
257 <h3>Arguments</h3>
258 <dl>
259 <dt><b>wsi</b>
260 <dd>Local struct lws associated with
261 <dt><b>fd</b>
262 <dd>Connection socket descriptor
263 <dt><b>name</b>
264 <dd>Buffer to take client address name
265 <dt><b>name_len</b>
266 <dd>Length of client address name buffer
267 <dt><b>rip</b>
268 <dd>Buffer to take client address IP dotted quad
269 <dt><b>rip_len</b>
270 <dd>Length of client address IP buffer
271 </dl>
272 <h3>Description</h3>
273 <blockquote>
274 This function fills in <tt><b>name</b></tt> and <tt><b>rip</b></tt> with the name and IP of
275 the client connected with socket descriptor <tt><b>fd</b></tt>.  Names may be
276 truncated if there is not enough room.  If either cannot be
277 determined, they will be returned as valid zero-length strings.
278 </blockquote>
279 <hr>
280 <h2>lws_context_user - get the user data associated with the context</h2>
281 <i>LWS_EXTERN void *</i>
282 <b>lws_context_user</b>
283 (<i>struct lws_context *</i> <b>context</b>)
284 <h3>Arguments</h3>
285 <dl>
286 <dt><b>context</b>
287 <dd>Websocket context
288 </dl>
289 <h3>Description</h3>
290 <blockquote>
291 This returns the optional user allocation that can be attached to
292 the context the sockets live in at context_create time.  It's a way
293 to let all sockets serviced in the same context share data without
294 using globals statics in the user code.
295 </blockquote>
296 <hr>
297 <h2>lws_callback_all_protocol - Callback all connections using the given protocol with the given reason</h2>
298 <i>int</i>
299 <b>lws_callback_all_protocol</b>
300 (<i>struct lws_context *</i> <b>context</b>,
301 <i>const struct lws_protocols *</i> <b>protocol</b>,
302 <i>int</i> <b>reason</b>)
303 <h3>Arguments</h3>
304 <dl>
305 <dt><b>protocol</b>
306 <dd>Protocol whose connections will get callbacks
307 <dt><b>reason</b>
308 <dd>Callback reason index
309 </dl>
310 <hr>
311 <h2>lws_get_socket_fd - returns the socket file descriptor</h2>
312 <i>int</i>
313 <b>lws_get_socket_fd</b>
314 (<i>struct lws *</i> <b>wsi</b>)
315 <h3>Arguments</h3>
316 <dl>
317 <dt><b>wsi</b>
318 <dd>Websocket connection instance
319 </dl>
320 <h3>Description</h3>
321 <blockquote>
322 <p>
323 You will not need this unless you are doing something special
324 </blockquote>
325 <hr>
326 <h2>lws_rx_flow_control - Enable and disable socket servicing for received packets.</h2>
327 <i>int</i>
328 <b>lws_rx_flow_control</b>
329 (<i>struct lws *</i> <b>wsi</b>,
330 <i>int</i> <b>enable</b>)
331 <h3>Arguments</h3>
332 <dl>
333 <dt><b>wsi</b>
334 <dd>Websocket connection instance to get callback for
335 <dt><b>enable</b>
336 <dd>0 = disable read servicing for this connection, 1 = enable
337 </dl>
338 <h3>Description</h3>
339 <blockquote>
340 <p>
341 If the output side of a server process becomes choked, this allows flow
342 control for the input side.
343 </blockquote>
344 <hr>
345 <h2>lws_rx_flow_allow_all_protocol - Allow all connections with this protocol to receive</h2>
346 <i>void</i>
347 <b>lws_rx_flow_allow_all_protocol</b>
348 (<i>const struct lws_context *</i> <b>context</b>,
349 <i>const struct lws_protocols *</i> <b>protocol</b>)
350 <h3>Arguments</h3>
351 <dl>
352 <dt><b>protocol</b>
353 <dd>all connections using this protocol will be allowed to receive
354 </dl>
355 <h3>Description</h3>
356 <blockquote>
357 <p>
358 When the user server code realizes it can accept more input, it can
359 call this to have the RX flow restriction removed from all connections using
360 the given protocol.
361 </blockquote>
362 <hr>
363 <h2>lws_canonical_hostname - returns this host's hostname</h2>
364 <i>const char *</i>
365 <b>lws_canonical_hostname</b>
366 (<i>struct lws_context *</i> <b>context</b>)
367 <h3>Arguments</h3>
368 <dl>
369 <dt><b>context</b>
370 <dd>Websocket context
371 </dl>
372 <h3>Description</h3>
373 <blockquote>
374 <p>
375 This is typically used by client code to fill in the host parameter
376 when making a client connection.  You can only call it after the context
377 has been created.
378 </blockquote>
379 <hr>
380 <h2>lws_set_proxy - Setups proxy to lws_context.</h2>
381 <i>int</i>
382 <b>lws_set_proxy</b>
383 (<i>struct lws_context *</i> <b>context</b>,
384 <i>const char *</i> <b>proxy</b>)
385 <h3>Arguments</h3>
386 <dl>
387 <dt><b>context</b>
388 <dd>pointer to struct lws_context you want set proxy to
389 <dt><b>proxy</b>
390 <dd>pointer to c string containing proxy in format address:port
391 </dl>
392 <h3>Description</h3>
393 <blockquote>
394 Returns 0 if proxy string was parsed and proxy was setup.
395 Returns -1 if <tt><b>proxy</b></tt> is NULL or has incorrect format.
396 <p>
397 This is only required if your OS does not provide the http_proxy
398 environment variable (eg, OSX)
399 <p>
400 IMPORTANT! You should call this function right after creation of the
401 lws_context and before call to connect. If you call this
402 function after connect behavior is undefined.
403 This function will override proxy settings made on lws_context
404 creation with <b>genenv</b> call.
405 </blockquote>
406 <hr>
407 <h2>lws_get_protocol - Returns a protocol pointer from a websocket connection.</h2>
408 <i>const struct lws_protocols *</i>
409 <b>lws_get_protocol</b>
410 (<i>struct lws *</i> <b>wsi</b>)
411 <h3>Arguments</h3>
412 <dl>
413 <dt><b>wsi</b>
414 <dd>pointer to struct websocket you want to know the protocol of
415 </dl>
416 <h3>Description</h3>
417 <blockquote>
418 <p>
419 Some apis can act on all live connections of a given protocol,
420 this is how you can get a pointer to the active protocol if needed.
421 </blockquote>
422 <hr>
423 <h2>lws_set_log_level - Set the logging bitfield</h2>
424 <i>void</i>
425 <b>lws_set_log_level</b>
426 (<i>int</i> <b>level</b>,
427 <i>void (*</i><b>func</b>) <i>(int level, const char *line)</i>)
428 <h3>Arguments</h3>
429 <dl>
430 <dt><b>level</b>
431 <dd>OR together the LLL_ debug contexts you want output from
432 </dl>
433 <h3>Description</h3>
434 <blockquote>
435 log level defaults to "err", "warn" and "notice" contexts enabled and
436 emission on stderr.
437 </blockquote>
438 <hr>
439 <h2>lws_is_ssl - Find out if connection is using SSL</h2>
440 <i>int</i>
441 <b>lws_is_ssl</b>
442 (<i>struct lws *</i> <b>wsi</b>)
443 <h3>Arguments</h3>
444 <dl>
445 <dt><b>wsi</b>
446 <dd>websocket connection to check
447 </dl>
448 <h3>Description</h3>
449 <blockquote>
450 Returns 0 if the connection is not using SSL, 1 if using SSL and
451 using verified cert, and 2 if using SSL but the cert was not
452 checked (appears for client wsi told to skip check on connection)
453 </blockquote>
454 <hr>
455 <h2>lws_partial_buffered - find out if lws buffered the last write</h2>
456 <i>int</i>
457 <b>lws_partial_buffered</b>
458 (<i>struct lws *</i> <b>wsi</b>)
459 <h3>Arguments</h3>
460 <dl>
461 <dt><b>wsi</b>
462 <dd>websocket connection to check
463 </dl>
464 <h3>Description</h3>
465 <blockquote>
466 Returns 1 if you cannot use lws_write because the last
467 write on this connection is still buffered, and can't be cleared without
468 returning to the service loop and waiting for the connection to be
469 writeable again.
470 <p>
471 If you will try to do &gt;1 lws_write call inside a single
472 WRITEABLE callback, you must check this after every write and bail if
473 set, ask for a new writeable callback and continue writing from there.
474 <p>
475 This is never set at the start of a writeable callback, but any write
476 may set it.
477 </blockquote>
478 <hr>
479 <h2>lws_parse_uri - </h2>
480 <i>LWS_EXTERN int</i>
481 <b>lws_parse_uri</b>
482 (<i>char *</i> <b>p</b>,
483 <i>const char **</i> <b>prot</b>,
484 <i>const char **</i> <b>ads</b>,
485 <i>int *</i> <b>port</b>,
486 <i>const char **</i> <b>path</b>)
487 <h3>Arguments</h3>
488 <dl>
489 <dt><b>p</b>
490 <dd>incoming uri string.. will get written to
491 <dt><b>prot</b>
492 <dd>result pointer for protocol part (https://)
493 <dt><b>ads</b>
494 <dd>result pointer for address part
495 <dt><b>port</b>
496 <dd>result pointer for port part
497 <dt><b>path</b>
498 <dd>result pointer for path part
499 </dl>
500 <h3>Description</h3>
501 <blockquote>
502 Notice it does so by dropping '\0' into input string
503 and the leading / on the path is consequently lost
504 </blockquote>
505 <hr>
506 <h2>lws_cancel_service - Cancel servicing of pending websocket activity</h2>
507 <i>void</i>
508 <b>lws_cancel_service</b>
509 (<i>struct lws_context *</i> <b>context</b>)
510 <h3>Arguments</h3>
511 <dl>
512 <dt><b>context</b>
513 <dd>Websocket context
514 </dl>
515 <h3>Description</h3>
516 <blockquote>
517 This function let a call to <b>lws_service</b> waiting for a timeout
518 immediately return.
519 <p>
520 There is no <b>poll</b> in MBED3, he will fire callbacks when he feels like
521 it.
522 </blockquote>
523 <hr>
524 <h2>lws_cancel_service_pt - Cancel servicing of pending socket activity on one thread</h2>
525 <i>void</i>
526 <b>lws_cancel_service_pt</b>
527 (<i>struct lws *</i> <b>wsi</b>)
528 <h3>Arguments</h3>
529 <dl>
530 <dt><b>wsi</b>
531 <dd>Cancel service on the thread this wsi is serviced by
532 </dl>
533 <h3>Description</h3>
534 <blockquote>
535 This function let a call to <b>lws_service</b> waiting for a timeout
536 immediately return.
537 </blockquote>
538 <hr>
539 <h2>lws_cancel_service - Cancel ALL servicing of pending socket activity</h2>
540 <i>void</i>
541 <b>lws_cancel_service</b>
542 (<i>struct lws_context *</i> <b>context</b>)
543 <h3>Arguments</h3>
544 <dl>
545 <dt><b>context</b>
546 <dd>Websocket context
547 </dl>
548 <h3>Description</h3>
549 <blockquote>
550 This function let a call to <b>lws_service</b> waiting for a timeout
551 immediately return.
552 </blockquote>
553 <hr>
554 <h2>lws_cancel_service - Cancel servicing of pending websocket activity</h2>
555 <i>void</i>
556 <b>lws_cancel_service</b>
557 (<i>struct lws_context *</i> <b>context</b>)
558 <h3>Arguments</h3>
559 <dl>
560 <dt><b>context</b>
561 <dd>Websocket context
562 </dl>
563 <h3>Description</h3>
564 <blockquote>
565 This function let a call to <b>lws_service</b> waiting for a timeout
566 immediately return.
567 </blockquote>
568 <hr>
569 <h2>lws_write - Apply protocol then write data to client</h2>
570 <i>int</i>
571 <b>lws_write</b>
572 (<i>struct lws *</i> <b>wsi</b>,
573 <i>unsigned char *</i> <b>buf</b>,
574 <i>size_t</i> <b>len</b>,
575 <i>enum lws_write_protocol</i> <b>wp</b>)
576 <h3>Arguments</h3>
577 <dl>
578 <dt><b>wsi</b>
579 <dd>Websocket instance (available from user callback)
580 <dt><b>buf</b>
581 <dd>The data to send.  For data being sent on a websocket
582 connection (ie, not default http), this buffer MUST have
583 LWS_PRE bytes valid BEFORE the pointer.
584 This is so the protocol header data can be added in-situ.
585 <dt><b>len</b>
586 <dd>Count of the data bytes in the payload starting from buf
587 </dl>
588 <h3>Description</h3>
589 <blockquote>
590 This function provides the way to issue data back to the client
591 for both http and websocket protocols.
592 <p>
593 In the case of sending using websocket protocol, be sure to allocate
594 valid storage before and after buf as explained above.  This scheme
595 allows maximum efficiency of sending data and protocol in a single
596 packet while not burdening the user code with any protocol knowledge.
597 <p>
598 Return may be -1 for a fatal error needing connection close, or a
599 positive number reflecting the amount of bytes actually sent.  This
600 can be less than the requested number of bytes due to OS memory
601 pressure at any given time.
602 </blockquote>
603 <hr>
604 <h2>lws_hdr_fragment_length - </h2>
605 <i>int</i>
606 <b>lws_hdr_fragment_length</b>
607 (<i>struct lws *</i> <b>wsi</b>,
608 <i>enum lws_token_indexes</i> <b>h</b>,
609 <i>int</i> <b>frag_idx</b>)
610 <h3>Arguments</h3>
611 <dl>
612 <dt><b>wsi</b>
613 <dd>websocket connection
614 <dt><b>h</b>
615 <dd>which header index we are interested in
616 <dt><b>frag_idx</b>
617 <dd>which fragment of <tt><b>h</b></tt> we want to get the length of
618 </dl>
619 <h3>Description</h3>
620 <blockquote>
621 The returned length does not include the space for a
622 terminating '\0'
623 </blockquote>
624 <hr>
625 <h2>lws_hdr_total_length - </h2>
626 <i>int</i>
627 <b>lws_hdr_total_length</b>
628 (<i>struct lws *</i> <b>wsi</b>,
629 <i>enum lws_token_indexes</i> <b>h</b>)
630 <h3>Arguments</h3>
631 <dl>
632 <dt><b>wsi</b>
633 <dd>websocket connection
634 <dt><b>h</b>
635 <dd>which header index we are interested in
636 </dl>
637 <h3>Description</h3>
638 <blockquote>
639 The returned length does not include the space for a
640 terminating '\0'
641 </blockquote>
642 <hr>
643 <h2>lws_hdr_copy_fragment - </h2>
644 <i>int</i>
645 <b>lws_hdr_copy_fragment</b>
646 (<i>struct lws *</i> <b>wsi</b>,
647 <i>char *</i> <b>dst</b>,
648 <i>int</i> <b>len</b>,
649 <i>enum lws_token_indexes</i> <b>h</b>,
650 <i>int</i> <b>frag_idx</b>)
651 <h3>Arguments</h3>
652 <dl>
653 <dt><b>wsi</b>
654 <dd>websocket connection
655 <dt><b>dst</b>
656 <dd>destination buffer
657 <dt><b>len</b>
658 <dd>length of destination buffer
659 <dt><b>h</b>
660 <dd>which header index we are interested in
661 </dl>
662 <h3>Description</h3>
663 <blockquote>
664 The buffer length <tt><b>len</b></tt> must include space for an additional
665 terminating '\0', or it will fail returning -1.
666 If the requested fragment index is not present, it fails
667 returning -1.
668 </blockquote>
669 <hr>
670 <h2>lws_hdr_copy - </h2>
671 <i>int</i>
672 <b>lws_hdr_copy</b>
673 (<i>struct lws *</i> <b>wsi</b>,
674 <i>char *</i> <b>dst</b>,
675 <i>int</i> <b>len</b>,
676 <i>enum lws_token_indexes</i> <b>h</b>)
677 <h3>Arguments</h3>
678 <dl>
679 <dt><b>wsi</b>
680 <dd>websocket connection
681 <dt><b>dst</b>
682 <dd>destination buffer
683 <dt><b>len</b>
684 <dd>length of destination buffer
685 <dt><b>h</b>
686 <dd>which header index we are interested in
687 </dl>
688 <h3>Description</h3>
689 <blockquote>
690 The buffer length <tt><b>len</b></tt> must include space for an additional
691 terminating '\0', or it will fail returning -1.
692 </blockquote>
693 <hr>
694 <h2>lws_frame_is_binary - </h2>
695 <i>int</i>
696 <b>lws_frame_is_binary</b>
697 (<i>struct lws *</i> <b>wsi</b>)
698 <h3>Arguments</h3>
699 <dl>
700 <dt><b>wsi</b>
701 <dd>the connection we are inquiring about
702 </dl>
703 <h3>Description</h3>
704 <blockquote>
705 This is intended to be called from the LWS_CALLBACK_RECEIVE callback if
706 it's interested to see if the frame it's dealing with was sent in binary
707 mode.
708 </blockquote>
709 <hr>
710 <h2>lws_remaining_packet_payload - Bytes to come before "overall" rx packet is complete</h2>
711 <i>size_t</i>
712 <b>lws_remaining_packet_payload</b>
713 (<i>struct lws *</i> <b>wsi</b>)
714 <h3>Arguments</h3>
715 <dl>
716 <dt><b>wsi</b>
717 <dd>Websocket instance (available from user callback)
718 </dl>
719 <h3>Description</h3>
720 <blockquote>
721 This function is intended to be called from the callback if the
722 user code is interested in "complete packets" from the client.
723 libwebsockets just passes through payload as it comes and issues a buffer
724 additionally when it hits a built-in limit.  The LWS_CALLBACK_RECEIVE
725 callback handler can use this API to find out if the buffer it has just
726 been given is the last piece of a "complete packet" from the client --
727 when that is the case <b>lws_remaining_packet_payload</b> will return
728 0.
729 <p>
730 Many protocols won't care becuse their packets are always small.
731 </blockquote>
732 <hr>
733 <h2>lws_callback_on_writable - Request a callback when this socket becomes able to be written to without blocking</h2>
734 <i>int</i>
735 <b>lws_callback_on_writable</b>
736 (<i>struct lws *</i> <b>wsi</b>)
737 <h3>Arguments</h3>
738 <dl>
739 <dt><b>wsi</b>
740 <dd>Websocket connection instance to get callback for
741 </dl>
742 <hr>
743 <h2>lws_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>
744 <i>int</i>
745 <b>lws_callback_on_writable_all_protocol</b>
746 (<i>const struct lws_context *</i> <b>context</b>,
747 <i>const struct lws_protocols *</i> <b>protocol</b>)
748 <h3>Arguments</h3>
749 <dl>
750 <dt><b>context</b>
751 <dd>lws_context
752 <dt><b>protocol</b>
753 <dd>Protocol whose connections will get callbacks
754 </dl>
755 <hr>
756 <h2>lws_http_transaction_completed - wait for new http transaction or close</h2>
757 <i>int LWS_WARN_UNUSED_RESULT</i>
758 <b>lws_http_transaction_completed</b>
759 (<i>struct lws *</i> <b>wsi</b>)
760 <h3>Arguments</h3>
761 <dl>
762 <dt><b>wsi</b>
763 <dd>websocket connection
764 </dl>
765 <h3>Description</h3>
766 <blockquote>
767 Returns 1 if the HTTP connection must close now
768 Returns 0 and resets connection to wait for new HTTP header /
769 transaction if possible
770 </blockquote>
771 <hr>
772 <h2>lws_adopt_socket - adopt foreign socket as if listen socket accepted it</h2>
773 <i>struct lws *</i>
774 <b>lws_adopt_socket</b>
775 (<i>struct lws_context *</i> <b>context</b>,
776 <i>lws_sockfd_type</i> <b>accept_fd</b>)
777 <h3>Arguments</h3>
778 <dl>
779 <dt><b>context</b>
780 <dd>lws context
781 <dt><b>accept_fd</b>
782 <dd>fd of already-accepted socket to adopt
783 </dl>
784 <h3>Description</h3>
785 <blockquote>
786 Either returns new wsi bound to accept_fd, or closes accept_fd and
787 returns NULL, having cleaned up any new wsi pieces.
788 <p>
789 LWS adopts the socket in http serving mode, it's ready to accept an upgrade
790 to ws or just serve http.
791 </blockquote>
792 <hr>
793 <h2>lws_serve_http_file - Send a file back to the client using http</h2>
794 <i>int</i>
795 <b>lws_serve_http_file</b>
796 (<i>struct lws *</i> <b>wsi</b>,
797 <i>const char *</i> <b>file</b>,
798 <i>const char *</i> <b>content_type</b>,
799 <i>const char *</i> <b>other_headers</b>,
800 <i>int</i> <b>other_headers_len</b>)
801 <h3>Arguments</h3>
802 <dl>
803 <dt><b>wsi</b>
804 <dd>Websocket instance (available from user callback)
805 <dt><b>file</b>
806 <dd>The file to issue over http
807 <dt><b>content_type</b>
808 <dd>The http content type, eg, text/html
809 <dt><b>other_headers</b>
810 <dd>NULL or pointer to header string
811 <dt><b>other_headers_len</b>
812 <dd>length of the other headers if non-NULL
813 </dl>
814 <h3>Description</h3>
815 <blockquote>
816 This function is intended to be called from the callback in response
817 to http requests from the client.  It allows the callback to issue
818 local files down the http link in a single step.
819 <p>
820 Returning &lt;0 indicates error and the wsi should be closed.  Returning
821 &gt;0 indicates the file was completely sent and
822 <b>lws_http_transaction_completed</b> called on the wsi (and close if != 0)
823 ==0 indicates the file transfer is started and needs more service later,
824 the wsi should be left alone.
825 </blockquote>
826 <hr>
827 <h2>lws_service_fd_tsi - Service polled socket with something waiting</h2>
828 <i>int</i>
829 <b>lws_service_fd_tsi</b>
830 (<i>struct lws_context *</i> <b>context</b>,
831 <i>struct lws_pollfd *</i> <b>pollfd</b>,
832 <i>int</i> <b>tsi</b>)
833 <h3>Arguments</h3>
834 <dl>
835 <dt><b>context</b>
836 <dd>Websocket context
837 <dt><b>pollfd</b>
838 <dd>The pollfd entry describing the socket fd and which events
839 happened.
840 </dl>
841 <h3>Description</h3>
842 <blockquote>
843 This function takes a pollfd that has POLLIN or POLLOUT activity and
844 services it according to the state of the associated
845 struct lws.
846 <p>
847 The one call deals with all "service" that might happen on a socket
848 including listen accepts, http files as well as websocket protocol.
849 <p>
850 If a pollfd says it has something, you can just pass it to
851 <b>lws_service_fd</b> whether it is a socket handled by lws or not.
852 If it sees it is a lws socket, the traffic will be handled and
853 pollfd-&gt;revents will be zeroed now.
854 <p>
855 If the socket is foreign to lws, it leaves revents alone.  So you can
856 see if you should service yourself by checking the pollfd revents
857 after letting lws try to service it.
858 </blockquote>
859 <hr>
860 <h2>lws_service - Service any pending websocket activity</h2>
861 <i>int</i>
862 <b>lws_service</b>
863 (<i>struct lws_context *</i> <b>context</b>,
864 <i>int</i> <b>timeout_ms</b>)
865 <h3>Arguments</h3>
866 <dl>
867 <dt><b>context</b>
868 <dd>Websocket context
869 <dt><b>timeout_ms</b>
870 <dd>Timeout for poll; 0 means return immediately if nothing needed
871 service otherwise block and service immediately, returning
872 after the timeout if nothing needed service.
873 </dl>
874 <h3>Description</h3>
875 <blockquote>
876 This function deals with any pending websocket traffic, for three
877 kinds of event.  It handles these events on both server and client
878 types of connection the same.
879 <p>
880 1) Accept new connections to our context's server
881 <p>
882 2) Call the receive callback for incoming frame data received by
883 server or client connections.
884 <p>
885 You need to call this service function periodically to all the above
886 functions to happen; if your application is single-threaded you can
887 just call it in your main event loop.
888 <p>
889 Alternatively you can fork a new process that asynchronously handles
890 calling this service in a loop.  In that case you are happy if this
891 call blocks your thread until it needs to take care of something and
892 would call it with a large nonzero timeout.  Your loop then takes no
893 CPU while there is nothing happening.
894 <p>
895 If you are calling it in a single-threaded app, you don't want it to
896 wait around blocking other things in your loop from happening, so you
897 would call it with a timeout_ms of 0, so it returns immediately if
898 nothing is pending, or as soon as it services whatever was pending.
899 </blockquote>
900 <hr>
901 <h2>struct lws_plat_file_ops - Platform-specific file operations</h2>
902 <b>struct lws_plat_file_ops</b> {<br>
903 &nbsp; &nbsp; <i>lws_filefd_type (*</i><b>open</b>) <i>(struct lws *wsi, const char *filename,unsigned long *filelen, int flags)</i>;<br>
904 &nbsp; &nbsp; <i>int (*</i><b>close</b>) <i>(struct lws *wsi, lws_filefd_type fd)</i>;<br>
905 &nbsp; &nbsp; <i>unsigned long (*</i><b>seek_cur</b>) <i>(struct lws *wsi, lws_filefd_type fd,long offset_from_cur_pos)</i>;<br>
906 &nbsp; &nbsp; <i>int (*</i><b>read</b>) <i>(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,unsigned char *buf, unsigned long len)</i>;<br>
907 &nbsp; &nbsp; <i>int (*</i><b>write</b>) <i>(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,unsigned char *buf, unsigned long len)</i>;<br>
908 };<br>
909 <h3>Members</h3>
910 <dl>
911 <dt><b>open</b>
912 <dd>Open file (always binary access if plat supports it)
913 filelen is filled on exit to be the length of the file
914 flags should be set to O_RDONLY or O_RDWR
915 <dt><b>close</b>
916 <dd>Close file
917 <dt><b>seek_cur</b>
918 <dd>Seek from current position
919 <dt><b>read</b>
920 <dd>Read fron file *amount is set on exit to amount read
921 <dt><b>write</b>
922 <dd>Write to file *amount is set on exit as amount written
923 </dl>
924 <h3>Description</h3>
925 <blockquote>
926 <p>
927 These provide platform-agnostic ways to deal with filesystem access in the
928 library and in the user code.
929 </blockquote>
930 <hr>
931 <h2>lws_callback_function - User server actions</h2>
932 <i>typedef int</i>
933 <b>lws_callback_function</b>
934 (<i>struct lws *</i> <b>wsi</b>,
935 <i>enum lws_callback_reasons</i> <b>reason</b>,
936 <i>void *</i> <b>user</b>,
937 <i>void *</i> <b>in</b>,
938 <i>size_t</i> <b>len</b>)
939 <h3>Arguments</h3>
940 <dl>
941 <dt><b>wsi</b>
942 <dd>Opaque websocket instance pointer
943 <dt><b>reason</b>
944 <dd>The reason for the call
945 <dt><b>user</b>
946 <dd>Pointer to per-session user data allocated by library
947 <dt><b>in</b>
948 <dd>Pointer used for some callback reasons
949 <dt><b>len</b>
950 <dd>Length set for some callback reasons
951 </dl>
952 <h3>Description</h3>
953 <blockquote>
954 This callback is the way the user controls what is served.  All the
955 protocol detail is hidden and handled by the library.
956 <p>
957 For each connection / session there is user data allocated that is
958 pointed to by "user".  You set the size of this user data area when
959 the library is initialized with lws_create_server.
960 <p>
961 You get an opportunity to initialize user data when called back with
962 LWS_CALLBACK_ESTABLISHED reason.
963 </blockquote>
964 <h3>LWS_CALLBACK_ESTABLISHED</h3>
965 <blockquote>
966 after the server completes a handshake with
967 an incoming client.  If you built the library
968 with ssl support, <tt><b>in</b></tt> is a pointer to the
969 ssl struct associated with the connection or
970 NULL.
971 </blockquote>
972 <h3>LWS_CALLBACK_CLIENT_CONNECTION_ERROR</h3>
973 <blockquote>
974 the request client connection has
975 been unable to complete a handshake with the remote server.  If
976 in is non-NULL, you can find an error string of length len where
977 it points to.
978 </blockquote>
979 <h3>LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH</h3>
980 <blockquote>
981 this is the last chance for the
982 client user code to examine the http headers
983 and decide to reject the connection.  If the
984 content in the headers is interesting to the
985 client (url, etc) it needs to copy it out at
986 this point since it will be destroyed before
987 the CLIENT_ESTABLISHED call
988 </blockquote>
989 <h3>LWS_CALLBACK_CLIENT_ESTABLISHED</h3>
990 <blockquote>
991 after your client connection completed
992 a handshake with the remote server
993 </blockquote>
994 <h3>LWS_CALLBACK_CLOSED</h3>
995 <blockquote>
996 when the websocket session ends
997 </blockquote>
998 <h3>LWS_CALLBACK_CLOSED_HTTP</h3>
999 <blockquote>
1000 when a HTTP (non-websocket) session ends
1001 </blockquote>
1002 <h3>LWS_CALLBACK_RECEIVE</h3>
1003 <blockquote>
1004 data has appeared for this server endpoint from a
1005 remote client, it can be found at *in and is
1006 len bytes long
1007 </blockquote>
1008 <h3>LWS_CALLBACK_CLIENT_RECEIVE_PONG</h3>
1009 <blockquote>
1010 if you elected to see PONG packets,
1011 they appear with this callback reason.  PONG
1012 packets only exist in 04+ protocol
1013 </blockquote>
1014 <h3>LWS_CALLBACK_CLIENT_RECEIVE</h3>
1015 <blockquote>
1016 data has appeared from the server for the
1017 client connection, it can be found at *in and
1018 is len bytes long
1019 </blockquote>
1020 <h3>LWS_CALLBACK_HTTP</h3>
1021 <blockquote>
1022 an http request has come from a client that is not
1023 asking to upgrade the connection to a websocket
1024 one.  This is a chance to serve http content,
1025 for example, to send a script to the client
1026 which will then open the websockets connection.
1027 <tt><b>in</b></tt> points to the URI path requested and
1028 <b>lws_serve_http_file</b> makes it very
1029 simple to send back a file to the client.
1030 Normally after sending the file you are done
1031 with the http connection, since the rest of the
1032 activity will come by websockets from the script
1033 that was delivered by http, so you will want to
1034 return 1; to close and free up the connection.
1035 That's important because it uses a slot in the
1036 total number of client connections allowed set
1037 by MAX_CLIENTS.
1038 </blockquote>
1039 <h3>LWS_CALLBACK_HTTP_BODY</h3>
1040 <blockquote>
1041 the next <tt><b>len</b></tt> bytes data from the http
1042 request body HTTP connection is now available in <tt><b>in</b></tt>.
1043 </blockquote>
1044 <h3>LWS_CALLBACK_HTTP_BODY_COMPLETION</h3>
1045 <blockquote>
1046 the expected amount of http request
1047 body has been delivered
1048 </blockquote>
1049 <h3>LWS_CALLBACK_HTTP_WRITEABLE</h3>
1050 <blockquote>
1051 you can write more down the http protocol
1052 link now.
1053 </blockquote>
1054 <h3>LWS_CALLBACK_HTTP_FILE_COMPLETION</h3>
1055 <blockquote>
1056 a file requested to be send down
1057 http link has completed.
1058 </blockquote>
1059 <h3>LWS_CALLBACK_SERVER_WRITEABLE</h3>
1060 <blockquote>
1061 If you call
1062 <b>lws_callback_on_writable</b> on a connection, you will
1063 get one of these callbacks coming when the connection socket
1064 is able to accept another write packet without blocking.
1065 If it already was able to take another packet without blocking,
1066 you'll get this callback at the next call to the service loop
1067 function.  Notice that CLIENTs get LWS_CALLBACK_CLIENT_WRITEABLE
1068 and servers get LWS_CALLBACK_SERVER_WRITEABLE.
1069 </blockquote>
1070 <h3>LWS_CALLBACK_FILTER_NETWORK_CONNECTION</h3>
1071 <blockquote>
1072 called when a client connects to
1073 the server at network level; the connection is accepted but then
1074 passed to this callback to decide whether to hang up immediately
1075 or not, based on the client IP.  <tt><b>in</b></tt> contains the connection
1076 socket's descriptor. Since the client connection information is
1077 not available yet, <tt><b>wsi</b></tt> still pointing to the main server socket.
1078 Return non-zero to terminate the connection before sending or
1079 receiving anything. Because this happens immediately after the
1080 network connection from the client, there's no websocket protocol
1081 selected yet so this callback is issued only to protocol 0.
1082 </blockquote>
1083 <h3>LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED</h3>
1084 <blockquote>
1085 A new client just had
1086 been connected, accepted, and instantiated into the pool. This
1087 callback allows setting any relevant property to it. Because this
1088 happens immediately after the instantiation of a new client,
1089 there's no websocket protocol selected yet so this callback is
1090 issued only to protocol 0. Only <tt><b>wsi</b></tt> is defined, pointing to the
1091 new client, and the return value is ignored.
1092 </blockquote>
1093 <h3>LWS_CALLBACK_FILTER_HTTP_CONNECTION</h3>
1094 <blockquote>
1095 called when the request has
1096 been received and parsed from the client, but the response is
1097 not sent yet.  Return non-zero to disallow the connection.
1098 <tt><b>user</b></tt> is a pointer to the connection user space allocation,
1099 <tt><b>in</b></tt> is the URI, eg, "/"
1100 In your handler you can use the public APIs
1101 <b>lws_hdr_total_length</b> / <b>lws_hdr_copy</b> to access all of the
1102 headers using the header enums lws_token_indexes from
1103 libwebsockets.h to check for and read the supported header
1104 presence and content before deciding to allow the http
1105 connection to proceed or to kill the connection.
1106 </blockquote>
1107 <h3>LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION</h3>
1108 <blockquote>
1109 called when the handshake has
1110 been received and parsed from the client, but the response is
1111 not sent yet.  Return non-zero to disallow the connection.
1112 <tt><b>user</b></tt> is a pointer to the connection user space allocation,
1113 <tt><b>in</b></tt> is the requested protocol name
1114 In your handler you can use the public APIs
1115 <b>lws_hdr_total_length</b> / <b>lws_hdr_copy</b> to access all of the
1116 headers using the header enums lws_token_indexes from
1117 libwebsockets.h to check for and read the supported header
1118 presence and content before deciding to allow the handshake
1119 to proceed or to kill the connection.
1120 </blockquote>
1121 <h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS</h3>
1122 <blockquote>
1123 if configured for
1124 including OpenSSL support, this callback allows your user code
1125 to perform extra <b>SSL_CTX_load_verify_locations</b> or similar
1126 calls to direct OpenSSL where to find certificates the client
1127 can use to confirm the remote server identity.  <tt><b>user</b></tt> is the
1128 OpenSSL SSL_CTX*
1129 </blockquote>
1130 <h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS</h3>
1131 <blockquote>
1132 if configured for
1133 including OpenSSL support, this callback allows your user code
1134 to load extra certifcates into the server which allow it to
1135 verify the validity of certificates returned by clients.  <tt><b>user</b></tt>
1136 is the server's OpenSSL SSL_CTX*
1137 </blockquote>
1138 <h3>LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY</h3>
1139 <blockquote>
1140 if configured for
1141 including OpenSSL support but no private key file has been
1142 specified (ssl_private_key_filepath is NULL), this is called to
1143 allow the user to set the private key directly via libopenssl
1144 and perform further operations if required; this might be useful
1145 in situations where the private key is not directly accessible
1146 by the OS, for example if it is stored on a smartcard
1147 <tt><b>user</b></tt> is the server's OpenSSL SSL_CTX*
1148 </blockquote>
1149 <h3>LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION</h3>
1150 <blockquote>
1151 if the
1152 libwebsockets context was created with the option
1153 LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT, then this
1154 callback is generated during OpenSSL verification of the cert
1155 sent from the client.  It is sent to protocol[0] callback as
1156 no protocol has been negotiated on the connection yet.
1157 Notice that the libwebsockets context and wsi are both NULL
1158 during this callback.  See
1159 </blockquote>
1160 <h3>http</h3>
1161 <blockquote>
1162 //www.openssl.org/docs/ssl/SSL_CTX_set_verify.html
1163 to understand more detail about the OpenSSL callback that
1164 generates this libwebsockets callback and the meanings of the
1165 arguments passed.  In this callback, <tt><b>user</b></tt> is the x509_ctx,
1166 <tt><b>in</b></tt> is the ssl pointer and <tt><b>len</b></tt> is preverify_ok
1167 Notice that this callback maintains libwebsocket return
1168 conventions, return 0 to mean the cert is OK or 1 to fail it.
1169 This also means that if you don't handle this callback then
1170 the default callback action of returning 0 allows the client
1171 certificates.
1172 </blockquote>
1173 <h3>LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER</h3>
1174 <blockquote>
1175 this callback happens
1176 when a client handshake is being compiled.  <tt><b>user</b></tt> is NULL,
1177 <tt><b>in</b></tt> is a char **, it's pointing to a char * which holds the
1178 next location in the header buffer where you can add
1179 headers, and <tt><b>len</b></tt> is the remaining space in the header buffer,
1180 which is typically some hundreds of bytes.  So, to add a canned
1181 cookie, your handler code might look similar to:
1182 <p>
1183 char **p = (char **)in;
1184 <p>
1185 if (len &lt; 100)
1186 return 1;
1187 <p>
1188 *p += sprintf(*p, "Cookie: a=b\x0d\x0a");
1189 <p>
1190 return 0;
1191 <p>
1192 Notice if you add anything, you just have to take care about
1193 the CRLF on the line you added.  Obviously this callback is
1194 optional, if you don't handle it everything is fine.
1195 <p>
1196 Notice the callback is coming to protocols[0] all the time,
1197 because there is no specific protocol handshook yet.
1198 </blockquote>
1199 <h3>LWS_CALLBACK_CONFIRM_EXTENSION_OKAY</h3>
1200 <blockquote>
1201 When the server handshake code
1202 sees that it does support a requested extension, before
1203 accepting the extension by additing to the list sent back to
1204 the client it gives this callback just to check that it's okay
1205 to use that extension.  It calls back to the requested protocol
1206 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
1207 valid.  Note though at this time the ESTABLISHED callback hasn't
1208 happened yet so if you initialize <tt><b>user</b></tt> content there, <tt><b>user</b></tt>
1209 content during this callback might not be useful for anything.
1210 Notice this callback comes to protocols[0].
1211 </blockquote>
1212 <h3>LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED</h3>
1213 <blockquote>
1214 When a client
1215 connection is being prepared to start a handshake to a server,
1216 each supported extension is checked with protocols[0] callback
1217 with this reason, giving the user code a chance to suppress the
1218 claim to support that extension by returning non-zero.  If
1219 unhandled, by default 0 will be returned and the extension
1220 support included in the header to the server.  Notice this
1221 callback comes to protocols[0].
1222 </blockquote>
1223 <h3>LWS_CALLBACK_PROTOCOL_INIT</h3>
1224 <blockquote>
1225 One-time call per protocol so it can
1226 do initial setup / allocations etc
1227 </blockquote>
1228 <h3>LWS_CALLBACK_PROTOCOL_DESTROY</h3>
1229 <blockquote>
1230 One-time call per protocol indicating
1231 this protocol won't get used at all after this callback, the
1232 context is getting destroyed.  Take the opportunity to
1233 deallocate everything that was allocated by the protocol.
1234 </blockquote>
1235 <h3>LWS_CALLBACK_WSI_CREATE</h3>
1236 <blockquote>
1237 outermost (earliest) wsi create notification
1238 </blockquote>
1239 <h3>LWS_CALLBACK_WSI_DESTROY</h3>
1240 <blockquote>
1241 outermost (latest) wsi destroy notification
1242 <p>
1243 The next five reasons are optional and only need taking care of if you
1244 will be integrating libwebsockets sockets into an external polling
1245 array.
1246 <p>
1247 For these calls, <tt><b>in</b></tt> points to a struct lws_pollargs that
1248 contains <tt><b>fd</b></tt>, <tt><b>events</b></tt> and <tt><b>prev_events</b></tt> members
1249 </blockquote>
1250 <h3>LWS_CALLBACK_ADD_POLL_FD</h3>
1251 <blockquote>
1252 libwebsocket deals with its <b>poll</b> loop
1253 internally, but in the case you are integrating with another
1254 server you will need to have libwebsocket sockets share a
1255 polling array with the other server.  This and the other
1256 POLL_FD related callbacks let you put your specialized
1257 poll array interface code in the callback for protocol 0, the
1258 first protocol you support, usually the HTTP protocol in the
1259 serving case.
1260 This callback happens when a socket needs to be
1261 </blockquote>
1262 <h3>added to the polling loop</h3>
1263 <blockquote>
1264 <tt><b>in</b></tt> points to a struct
1265 lws_pollargs; the <tt><b>fd</b></tt> member of the struct is the file
1266 descriptor, and <tt><b>events</b></tt> contains the active events.
1267 <p>
1268 If you are using the internal polling loop (the "service"
1269 callback), you can just ignore these callbacks.
1270 </blockquote>
1271 <h3>LWS_CALLBACK_DEL_POLL_FD</h3>
1272 <blockquote>
1273 This callback happens when a socket descriptor
1274 needs to be removed from an external polling array.  <tt><b>in</b></tt> is
1275 again the struct lws_pollargs containing the <tt><b>fd</b></tt> member
1276 to be removed.  If you are using the internal polling
1277 loop, you can just ignore it.
1278 </blockquote>
1279 <h3>LWS_CALLBACK_CHANGE_MODE_POLL_FD</h3>
1280 <blockquote>
1281 This callback happens when
1282 libwebsockets wants to modify the events for a connectiion.
1283 <tt><b>in</b></tt> is the struct lws_pollargs with the <tt><b>fd</b></tt> to change.
1284 The new event mask is in <tt><b>events</b></tt> member and the old mask is in
1285 the <tt><b>prev_events</b></tt> member.
1286 If you are using the internal polling loop, you can just ignore
1287 it.
1288 </blockquote>
1289 <h3>LWS_CALLBACK_UNLOCK_POLL</h3>
1290 <blockquote>
1291 These allow the external poll changes driven
1292 by libwebsockets to participate in an external thread locking
1293 scheme around the changes, so the whole thing is threadsafe.
1294 These are called around three activities in the library,
1295 - inserting a new wsi in the wsi / fd table (len=1)
1296 - deleting a wsi from the wsi / fd table (len=1)
1297 - changing a wsi's POLLIN/OUT state (len=0)
1298 Locking and unlocking external synchronization objects when
1299 len == 1 allows external threads to be synchronized against
1300 wsi lifecycle changes if it acquires the same lock for the
1301 duration of wsi dereference from the other thread context.
1302 </blockquote>
1303 <h3>LWS_CALLBACK_WS_PEER_INITIATED_CLOSE</h3>
1304 <blockquote>
1305 The peer has sent an unsolicited Close WS packet.  <tt><b>in</b></tt> and
1306 <tt><b>len</b></tt> are the optional close code (first 2 bytes, network
1307 order) and the optional additional information which is not
1308 defined in the standard, and may be a string or non-human-
1309 readble data.
1310 If you return 0 lws will echo the close and then close the
1311 connection.  If you return nonzero lws will just close the
1312 connection.
1313 </blockquote>
1314 <hr>
1315 <h2>lws_extension_callback_function - Hooks to allow extensions to operate</h2>
1316 <i>typedef int</i>
1317 <b>lws_extension_callback_function</b>
1318 (<i>struct lws_context *</i> <b>context</b>,
1319 <i>const struct lws_extension *</i> <b>ext</b>,
1320 <i>struct lws *</i> <b>wsi</b>,
1321 <i>enum lws_extension_callback_reasons</i> <b>reason</b>,
1322 <i>void *</i> <b>user</b>,
1323 <i>void *</i> <b>in</b>,
1324 <i>size_t</i> <b>len</b>)
1325 <h3>Arguments</h3>
1326 <dl>
1327 <dt><b>context</b>
1328 <dd>Websockets context
1329 <dt><b>ext</b>
1330 <dd>This extension
1331 <dt><b>wsi</b>
1332 <dd>Opaque websocket instance pointer
1333 <dt><b>reason</b>
1334 <dd>The reason for the call
1335 <dt><b>user</b>
1336 <dd>Pointer to ptr to per-session user data allocated by library
1337 <dt><b>in</b>
1338 <dd>Pointer used for some callback reasons
1339 <dt><b>len</b>
1340 <dd>Length set for some callback reasons
1341 </dl>
1342 <h3>Description</h3>
1343 <blockquote>
1344 Each extension that is active on a particular connection receives
1345 callbacks during the connection lifetime to allow the extension to
1346 operate on websocket data and manage itself.
1347 <p>
1348 Libwebsockets takes care of allocating and freeing "user" memory for
1349 each active extension on each connection.  That is what is pointed to
1350 by the <tt><b>user</b></tt> parameter.
1351 </blockquote>
1352 <h3>LWS_EXT_CB_CONSTRUCT</h3>
1353 <blockquote>
1354 called when the server has decided to
1355 select this extension from the list provided by the client,
1356 just before the server will send back the handshake accepting
1357 the connection with this extension active.  This gives the
1358 extension a chance to initialize its connection context found
1359 in <tt><b>user</b></tt>.
1360 </blockquote>
1361 <h3>LWS_EXT_CB_CLIENT_CONSTRUCT</h3>
1362 <blockquote>
1363 same as LWS_EXT_CB_CONSTRUCT
1364 but called when client is instantiating this extension.  Some
1365 extensions will work the same on client and server side and then
1366 you can just merge handlers for both CONSTRUCTS.
1367 </blockquote>
1368 <h3>LWS_EXT_CB_DESTROY</h3>
1369 <blockquote>
1370 called when the connection the extension was
1371 being used on is about to be closed and deallocated.  It's the
1372 last chance for the extension to deallocate anything it has
1373 allocated in the user data (pointed to by <tt><b>user</b></tt>) before the
1374 user data is deleted.  This same callback is used whether you
1375 are in client or server instantiation context.
1376 </blockquote>
1377 <h3>LWS_EXT_CB_PACKET_RX_PREPARSE</h3>
1378 <blockquote>
1379 when this extension was active on
1380 a connection, and a packet of data arrived at the connection,
1381 it is passed to this callback to give the extension a chance to
1382 change the data, eg, decompress it.  <tt><b>user</b></tt> is pointing to the
1383 extension's private connection context data, <tt><b>in</b></tt> is pointing
1384 to an lws_tokens struct, it consists of a char * pointer called
1385 token, and an int called token_len.  At entry, these are
1386 set to point to the received buffer and set to the content
1387 length.  If the extension will grow the content, it should use
1388 a new buffer allocated in its private user context data and
1389 set the pointed-to lws_tokens members to point to its buffer.
1390 </blockquote>
1391 <h3>LWS_EXT_CB_PACKET_TX_PRESEND</h3>
1392 <blockquote>
1393 this works the same way as
1394 LWS_EXT_CB_PACKET_RX_PREPARSE above, except it gives the
1395 extension a chance to change websocket data just before it will
1396 be sent out.  Using the same lws_token pointer scheme in <tt><b>in</b></tt>,
1397 the extension can change the buffer and the length to be
1398 transmitted how it likes.  Again if it wants to grow the
1399 buffer safely, it should copy the data into its own buffer and
1400 set the lws_tokens token pointer to it.
1401 </blockquote>
1402 <hr>
1403 <h2>struct lws_protocols - List of protocols and handlers server supports.</h2>
1404 <b>struct lws_protocols</b> {<br>
1405 &nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
1406 &nbsp; &nbsp; <i>lws_callback_function *</i> <b>callback</b>;<br>
1407 &nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
1408 &nbsp; &nbsp; <i>size_t</i> <b>rx_buffer_size</b>;<br>
1409 &nbsp; &nbsp; <i>unsigned int</i> <b>id</b>;<br>
1410 &nbsp; &nbsp; <i>void *</i> <b>user</b>;<br>
1411 };<br>
1412 <h3>Members</h3>
1413 <dl>
1414 <dt><b>name</b>
1415 <dd>Protocol name that must match the one given in the client
1416 Javascript new WebSocket(url, 'protocol') name.
1417 <dt><b>callback</b>
1418 <dd>The service callback used for this protocol.  It allows the
1419 service action for an entire protocol to be encapsulated in
1420 the protocol-specific callback
1421 <dt><b>per_session_data_size</b>
1422 <dd>Each new connection using this protocol gets
1423 this much memory allocated on connection establishment and
1424 freed on connection takedown.  A pointer to this per-connection
1425 allocation is passed into the callback in the 'user' parameter
1426 <dt><b>rx_buffer_size</b>
1427 <dd>if you want atomic frames delivered to the callback, you
1428 should set this to the size of the biggest legal frame that
1429 you support.  If the frame size is exceeded, there is no
1430 error, but the buffer will spill to the user callback when
1431 full, which you can detect by using
1432 <b>lws_remaining_packet_payload</b>.  Notice that you
1433 just talk about frame size here, the LWS_PRE
1434 and post-padding are automatically also allocated on top.
1435 <dt><b>id</b>
1436 <dd>ignored by lws, but useful to contain user information bound
1437 to the selected protocol.  For example if this protocol was
1438 called "myprotocol-v2", you might set id to 2, and the user
1439 code that acts differently according to the version can do so by
1440 switch (wsi-&gt;protocol-&gt;id), user code might use some bits as
1441 capability flags based on selected protocol version, etc.
1442 <dt><b>user</b>
1443 <dd>User provided context data at the protocol level.
1444 Accessible via lws_get_protocol(wsi)-&gt;user
1445 This should not be confused with wsi-&gt;user, it is not the same.
1446 The library completely ignores any value in here.
1447 </dl>
1448 <h3>Description</h3>
1449 <blockquote>
1450 This structure represents one protocol supported by the server.  An
1451 array of these structures is passed to <b>lws_create_server</b>
1452 allows as many protocols as you like to be handled by one server.
1453 <p>
1454 The first protocol given has its callback used for user callbacks when
1455 there is no agreed protocol name, that's true during HTTP part of the
1456 </blockquote>
1457 <h3>connection and true if the client did not send a Protocol</h3>
1458 <blockquote>
1459 header.
1460 </blockquote>
1461 <hr>
1462 <h2>struct lws_ext_options - Option arguments to the extension.  These are used in the negotiation at ws upgrade time. The helper function lws_ext_parse_options() uses these to generate callbacks</h2>
1463 <b>struct lws_ext_options</b> {<br>
1464 &nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
1465 &nbsp; &nbsp; <i>enum lws_ext_options_types</i> <b>type</b>;<br>
1466 };<br>
1467 <h3>Members</h3>
1468 <dl>
1469 <dt><b>name</b>
1470 <dd>Option name, eg, "server_no_context_takeover"
1471 <dt><b>type</b>
1472 <dd>What kind of args the option can take
1473 </dl>
1474 <hr>
1475 <h2>struct lws_extension - An extension we know how to cope with</h2>
1476 <b>struct lws_extension</b> {<br>
1477 &nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
1478 &nbsp; &nbsp; <i>lws_extension_callback_function *</i> <b>callback</b>;<br>
1479 &nbsp; &nbsp; <i>const char *</i> <b>client_offer</b>;<br>
1480 };<br>
1481 <h3>Members</h3>
1482 <dl>
1483 <dt><b>name</b>
1484 <dd>Formal extension name, eg, "permessage-deflate"
1485 <dt><b>callback</b>
1486 <dd>Service callback
1487 <dt><b>client_offer</b>
1488 <dd>String containing exts and options client offers
1489 </dl>
1490 <hr>
1491 <h2>struct lws_context_creation_info - parameters to create context with</h2>
1492 <b>struct lws_context_creation_info</b> {<br>
1493 &nbsp; &nbsp; <i>int</i> <b>port</b>;<br>
1494 &nbsp; &nbsp; <i>const char *</i> <b>iface</b>;<br>
1495 &nbsp; &nbsp; <i>const struct lws_protocols *</i> <b>protocols</b>;<br>
1496 &nbsp; &nbsp; <i>const struct lws_extension *</i> <b>extensions</b>;<br>
1497 &nbsp; &nbsp; <i>const struct lws_token_limits *</i> <b>token_limits</b>;<br>
1498 &nbsp; &nbsp; <i>const char *</i> <b>ssl_cert_filepath</b>;<br>
1499 &nbsp; &nbsp; <i>const char *</i> <b>ssl_private_key_filepath</b>;<br>
1500 &nbsp; &nbsp; <i>const char *</i> <b>ssl_ca_filepath</b>;<br>
1501 &nbsp; &nbsp; <i>const char *</i> <b>ssl_cipher_list</b>;<br>
1502 &nbsp; &nbsp; <i>const char *</i> <b>http_proxy_address</b>;<br>
1503 &nbsp; &nbsp; <i>unsigned int</i> <b>http_proxy_port</b>;<br>
1504 &nbsp; &nbsp; <i>int</i> <b>gid</b>;<br>
1505 &nbsp; &nbsp; <i>int</i> <b>uid</b>;<br>
1506 &nbsp; &nbsp; <i>unsigned int</i> <b>options</b>;<br>
1507 &nbsp; &nbsp; <i>void *</i> <b>user</b>;<br>
1508 &nbsp; &nbsp; <i>int</i> <b>ka_time</b>;<br>
1509 &nbsp; &nbsp; <i>int</i> <b>ka_probes</b>;<br>
1510 &nbsp; &nbsp; <i>int</i> <b>ka_interval</b>;<br>
1511 #ifdef LWS_OPENSSL_SUPPORT<br>
1512 &nbsp; &nbsp; <i>void *</i> <b>provided_client_ssl_ctx</b>;<br>
1513 #else<br>
1514 &nbsp; &nbsp; <i>void *</i> <b>provided_client_ssl_ctx</b>;<br>
1515 #endif<br>
1516 &nbsp; &nbsp; <i>short</i> <b>max_http_header_data</b>;<br>
1517 &nbsp; &nbsp; <i>short</i> <b>max_http_header_pool</b>;<br>
1518 &nbsp; &nbsp; <i>unsigned int</i> <b>count_threads</b>;<br>
1519 &nbsp; &nbsp; <i>unsigned int</i> <b>fd_limit_per_thread</b>;<br>
1520 &nbsp; &nbsp; <i>unsigned int</i> <b>timeout_secs</b>;<br>
1521 };<br>
1522 <h3>Members</h3>
1523 <dl>
1524 <dt><b>port</b>
1525 <dd>Port to listen on... you can use CONTEXT_PORT_NO_LISTEN to
1526 suppress listening on any port, that's what you want if you are
1527 not running a websocket server at all but just using it as a
1528 client
1529 <dt><b>iface</b>
1530 <dd>NULL to bind the listen socket to all interfaces, or the
1531 interface name, eg, "eth2"
1532 <dt><b>protocols</b>
1533 <dd>Array of structures listing supported protocols and a protocol-
1534 specific callback for each one.  The list is ended with an
1535 entry that has a NULL callback pointer.
1536 It's not const because we write the owning_server member
1537 <dt><b>extensions</b>
1538 <dd>NULL or array of lws_extension structs listing the
1539 extensions this context supports.  If you configured with
1540 --without-extensions, you should give NULL here.
1541 <dt><b>token_limits</b>
1542 <dd>NULL or struct lws_token_limits pointer which is initialized
1543 with a token length limit for each possible WSI_TOKEN_***
1544 <dt><b>ssl_cert_filepath</b>
1545 <dd>If libwebsockets was compiled to use ssl, and you want
1546 to listen using SSL, set to the filepath to fetch the
1547 server cert from, otherwise NULL for unencrypted
1548 <dt><b>ssl_private_key_filepath</b>
1549 <dd>filepath to private key if wanting SSL mode;
1550 if this is set to NULL but sll_cert_filepath is set, the
1551 OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY callback is called
1552 to allow setting of the private key directly via openSSL
1553 library calls
1554 <dt><b>ssl_ca_filepath</b>
1555 <dd>CA certificate filepath or NULL
1556 <dt><b>ssl_cipher_list</b>
1557 <dd>List of valid ciphers to use (eg,
1558 "RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aNULL"
1559 or you can leave it as NULL to get "DEFAULT"
1560 <dt><b>http_proxy_address</b>
1561 <dd>If non-NULL, attempts to proxy via the given address.
1562 If proxy auth is required, use format
1563 "username:password<tt><b>server</b></tt>:port"
1564 <dt><b>http_proxy_port</b>
1565 <dd>If http_proxy_address was non-NULL, uses this port at
1566 the address
1567 <dt><b>gid</b>
1568 <dd>group id to change to after setting listen socket, or -1.
1569 <dt><b>uid</b>
1570 <dd>user id to change to after setting listen socket, or -1.
1571 <dt><b>options</b>
1572 <dd>0, or LWS_SERVER_OPTION_... bitfields
1573 <dt><b>user</b>
1574 <dd>optional user pointer that can be recovered via the context
1575 pointer using lws_context_user
1576 <dt><b>ka_time</b>
1577 <dd>0 for no keepalive, otherwise apply this keepalive timeout to
1578 all libwebsocket sockets, client or server
1579 <dt><b>ka_probes</b>
1580 <dd>if ka_time was nonzero, after the timeout expires how many
1581 times to try to get a response from the peer before giving up
1582 and killing the connection
1583 <dt><b>ka_interval</b>
1584 <dd>if ka_time was nonzero, how long to wait before each ka_probes
1585 attempt
1586 <dt><b>provided_client_ssl_ctx</b>
1587 <dd>If non-null, swap out libwebsockets ssl
1588 implementation for the one provided by provided_ssl_ctx.
1589 Libwebsockets no longer is responsible for freeing the context
1590 if this option is selected.
1591 <dt><b>provided_client_ssl_ctx</b>
1592 <dd>If non-null, swap out libwebsockets ssl
1593 implementation for the one provided by provided_ssl_ctx.
1594 Libwebsockets no longer is responsible for freeing the context
1595 if this option is selected.
1596 <dt><b>max_http_header_data</b>
1597 <dd>The max amount of header payload that can be handled
1598 in an http request (unrecognized header payload is dropped)
1599 <dt><b>max_http_header_pool</b>
1600 <dd>The max number of connections with http headers that
1601 can be processed simultaneously (the corresponding memory is
1602 allocated for the lifetime of the context).  If the pool is
1603 busy new incoming connections must wait for accept until one
1604 becomes free.
1605 <dt><b>count_threads</b>
1606 <dd>how many contexts to create in an array, 0 = 1
1607 <dt><b>fd_limit_per_thread</b>
1608 <dd>nonzero means restrict each service thread to this
1609 many fds, 0 means the default which is divide the process fd
1610 limit by the number of threads.
1611 <dt><b>timeout_secs</b>
1612 <dd>various processes involving network roundtrips in the
1613 library are protected from hanging forever by timeouts.  If
1614 nonzero, this member lets you set the timeout used in seconds.
1615 Otherwise a default timeout is used.
1616 </dl>
1617 <hr>
1618 <h2>struct lws_client_connect_info - parameters to connect with when using lws_client_connect_via_info()</h2>
1619 <b>struct lws_client_connect_info</b> {<br>
1620 &nbsp; &nbsp; <i>struct lws_context *</i> <b>context</b>;<br>
1621 &nbsp; &nbsp; <i>const char *</i> <b>address</b>;<br>
1622 &nbsp; &nbsp; <i>int</i> <b>port</b>;<br>
1623 &nbsp; &nbsp; <i>int</i> <b>ssl_connection</b>;<br>
1624 &nbsp; &nbsp; <i>const char *</i> <b>path</b>;<br>
1625 &nbsp; &nbsp; <i>const char *</i> <b>host</b>;<br>
1626 &nbsp; &nbsp; <i>const char *</i> <b>origin</b>;<br>
1627 &nbsp; &nbsp; <i>const char *</i> <b>protocol</b>;<br>
1628 &nbsp; &nbsp; <i>int</i> <b>ietf_version_or_minus_one</b>;<br>
1629 &nbsp; &nbsp; <i>void *</i> <b>userdata</b>;<br>
1630 &nbsp; &nbsp; <i>const struct lws_extension *</i> <b>client_exts</b>;<br>
1631 };<br>
1632 <h3>Members</h3>
1633 <dl>
1634 <dt><b>context</b>
1635 <dd>lws context to create connection in
1636 <dt><b>address</b>
1637 <dd>remote address to connect to
1638 <dt><b>port</b>
1639 <dd>remote port to connect to
1640 <dt><b>ssl_connection</b>
1641 <dd>nonzero for ssl
1642 <dt><b>path</b>
1643 <dd>uri path
1644 <dt><b>host</b>
1645 <dd>content of host header
1646 <dt><b>origin</b>
1647 <dd>content of origin header
1648 <dt><b>protocol</b>
1649 <dd>list of ws protocols
1650 <dt><b>ietf_version_or_minus_one</b>
1651 <dd>currently leave at 0 or -1
1652 <dt><b>userdata</b>
1653 <dd>if non-NULL, use this as wsi user_data instead of malloc it
1654 <dt><b>client_exts</b>
1655 <dd>array of extensions that may be used on connection
1656 </dl>
1657 <hr>
1658 <h2>lws_close_reason - Set reason and aux data to send with Close packet If you are going to return nonzero from the callback requesting the connection to close, you can optionally call this to set the reason the peer will be told if possible.</h2>
1659 <i>LWS_EXTERN void</i>
1660 <b>lws_close_reason</b>
1661 (<i>struct lws *</i> <b>wsi</b>,
1662 <i>enum lws_close_status</i> <b>status</b>,
1663 <i>unsigned char *</i> <b>buf</b>,
1664 <i>size_t</i> <b>len</b>)
1665 <h3>Arguments</h3>
1666 <dl>
1667 <dt><b>wsi</b>
1668 <dd>The websocket connection to set the close reason on
1669 <dt><b>status</b>
1670 <dd>A valid close status from websocket standard
1671 <dt><b>buf</b>
1672 <dd>NULL or buffer containing up to 124 bytes of auxiliary data
1673 <dt><b>len</b>
1674 <dd>Length of data in <tt><b>buf</b></tt> to send
1675 </dl>
1676 <hr>
1677 <h2>lws_snprintf - </h2>
1678 <i>LWS_EXTERN int</i>
1679 <b>lws_snprintf</b>
1680 (<i>char *</i> <b>str</b>,
1681 <i>size_t</i> <b>size</b>,
1682 <i>const char *</i> <b>format</b>,
1683 <i></i> <b>...</b>)
1684 <h3>Arguments</h3>
1685 <dl>
1686 <dt><b>...</b>
1687 <dd>variable arguments
1688 </dl>
1689 <h3>Description</h3>
1690 <blockquote>
1691 <p>
1692 \param str: destination buffer
1693 \param size: bytes left in destination buffer
1694 \param format: format string
1695 \param ...: args for format
1696 <p>
1697 This lets you correctly truncate buffers by concatenating lengths, if you
1698 reach the limit the reported length doesn't exceed the limit.
1699 </blockquote>
1700 <hr>