introduce LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER
[platform/upstream/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>this</b>,
5 <i>int</i> <b>fd</b>)
6 <h3>Arguments</h3>
7 <dl>
8 <dt><b>this</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>this</b>,
47 <i>struct pollfd *</i> <b>pollfd</b>)
48 <h3>Arguments</h3>
49 <dl>
50 <dt><b>this</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>this</b>)
67 <h3>Arguments</h3>
68 <dl>
69 <dt><b>this</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>this</b>,
83 <i>int</i> <b>timeout_ms</b>)
84 <h3>Arguments</h3>
85 <dl>
86 <dt><b>this</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>this</b>,
127 <i>struct libwebsocket *</i> <b>wsi</b>)
128 <h3>Arguments</h3>
129 <dl>
130 <dt><b>this</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>this</b>)
205 <h3>Arguments</h3>
206 <dl>
207 <dt><b>this</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>interface</b>,
223 <i>struct libwebsocket_protocols *</i> <b>protocols</b>,
224 <i>const char *</i> <b>ssl_cert_filepath</b>,
225 <i>const char *</i> <b>ssl_private_key_filepath</b>,
226 <i>int</i> <b>gid</b>,
227 <i>int</i> <b>uid</b>,
228 <i>unsigned int</i> <b>options</b>)
229 <h3>Arguments</h3>
230 <dl>
231 <dt><b>port</b>
232 <dd>Port to listen on... you can use 0 to suppress listening on
233 any port, that's what you want if you are not running a
234 websocket server at all but just using it as a client
235 <dt><b>interface</b>
236 <dd>NULL to bind the listen socket to all interfaces, or the
237 interface name, eg, "eth2"
238 <dt><b>protocols</b>
239 <dd>Array of structures listing supported protocols and a protocol-
240 specific callback for each one.  The list is ended with an
241 entry that has a NULL callback pointer.
242 It's not const because we write the owning_server member
243 <dt><b>ssl_cert_filepath</b>
244 <dd>If libwebsockets was compiled to use ssl, and you want
245 to listen using SSL, set to the filepath to fetch the
246 server cert from, otherwise NULL for unencrypted
247 <dt><b>ssl_private_key_filepath</b>
248 <dd>filepath to private key if wanting SSL mode,
249 else ignored
250 <dt><b>gid</b>
251 <dd>group id to change to after setting listen socket, or -1.
252 <dt><b>uid</b>
253 <dd>user id to change to after setting listen socket, or -1.
254 <dt><b>options</b>
255 <dd>0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK
256 </dl>
257 <h3>Description</h3>
258 <blockquote>
259 This function creates the listening socket and takes care
260 of all initialization in one step.
261 <p>
262 After initialization, it returns a struct libwebsocket_context * that
263 represents this server.  After calling, user code needs to take care
264 of calling <b>libwebsocket_service</b> with the context pointer to get the
265 server's sockets serviced.  This can be done in the same process context
266 or a forked process, or another thread,
267 <p>
268 The protocol callback functions are called for a handful of events
269 including http requests coming in, websocket connections becoming
270 established, and data arriving; it's also called periodically to allow
271 async transmission.
272 <p>
273 HTTP requests are sent always to the FIRST protocol in <tt><b>protocol</b></tt>, since
274 at that time websocket protocol has not been negotiated.  Other
275 protocols after the first one never see any HTTP callack activity.
276 <p>
277 The server created is a simple http server by default; part of the
278 websocket standard is upgrading this http connection to a websocket one.
279 <p>
280 This allows the same server to provide files like scripts and favicon /
281 images or whatever over http and dynamic data over websockets all in
282 one place; they're all handled in the user callback.
283 </blockquote>
284 <hr>
285 <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>
286 <i>int</i>
287 <b>libwebsockets_fork_service_loop</b>
288 (<i>struct libwebsocket_context *</i> <b>this</b>)
289 <h3>Arguments</h3>
290 <dl>
291 <dt><b>this</b>
292 <dd>server context returned by creation function
293 </dl>
294 <hr>
295 <h2>libwebsockets_get_protocol - Returns a protocol pointer from a websocket connection.</h2>
296 <i>const struct libwebsocket_protocols *</i>
297 <b>libwebsockets_get_protocol</b>
298 (<i>struct libwebsocket *</i> <b>wsi</b>)
299 <h3>Arguments</h3>
300 <dl>
301 <dt><b>wsi</b>
302 <dd>pointer to struct websocket you want to know the protocol of
303 </dl>
304 <h3>Description</h3>
305 <blockquote>
306 <p>
307 This is useful to get the protocol to broadcast back to from inside
308 the callback.
309 </blockquote>
310 <hr>
311 <h2>libwebsockets_broadcast - Sends a buffer to the callback for all active connections of the given protocol.</h2>
312 <i>int</i>
313 <b>libwebsockets_broadcast</b>
314 (<i>const struct libwebsocket_protocols *</i> <b>protocol</b>,
315 <i>unsigned char *</i> <b>buf</b>,
316 <i>size_t</i> <b>len</b>)
317 <h3>Arguments</h3>
318 <dl>
319 <dt><b>protocol</b>
320 <dd>pointer to the protocol you will broadcast to all members of
321 <dt><b>buf</b>
322 <dd>buffer containing the data to be broadcase.  NOTE: this has to be
323 allocated with LWS_SEND_BUFFER_PRE_PADDING valid bytes before
324 the pointer and LWS_SEND_BUFFER_POST_PADDING afterwards in the
325 case you are calling this function from callback context.
326 <dt><b>len</b>
327 <dd>length of payload data in buf, starting from buf.
328 </dl>
329 <h3>Description</h3>
330 <blockquote>
331 This function allows bulk sending of a packet to every connection using
332 the given protocol.  It does not send the data directly; instead it calls
333 the callback with a reason type of LWS_CALLBACK_BROADCAST.  If the callback
334 wants to actually send the data for that connection, the callback itself
335 should call <b>libwebsocket_write</b>.
336 <p>
337 <b>libwebsockets_broadcast</b> can be called from another fork context without
338 having to take any care about data visibility between the processes, it'll
339 "just work".
340 </blockquote>
341 <hr>
342 <h2>libwebsocket_write - Apply protocol then write data to client</h2>
343 <i>int</i>
344 <b>libwebsocket_write</b>
345 (<i>struct libwebsocket *</i> <b>wsi</b>,
346 <i>unsigned char *</i> <b>buf</b>,
347 <i>size_t</i> <b>len</b>,
348 <i>enum libwebsocket_write_protocol</i> <b>protocol</b>)
349 <h3>Arguments</h3>
350 <dl>
351 <dt><b>wsi</b>
352 <dd>Websocket instance (available from user callback)
353 <dt><b>buf</b>
354 <dd>The data to send.  For data being sent on a websocket
355 connection (ie, not default http), this buffer MUST have
356 LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE the pointer
357 and an additional LWS_SEND_BUFFER_POST_PADDING bytes valid
358 in the buffer after (buf + len).  This is so the protocol
359 header and trailer data can be added in-situ.
360 <dt><b>len</b>
361 <dd>Count of the data bytes in the payload starting from buf
362 <dt><b>protocol</b>
363 <dd>Use LWS_WRITE_HTTP to reply to an http connection, and one
364 of LWS_WRITE_BINARY or LWS_WRITE_TEXT to send appropriate
365 data on a websockets connection.  Remember to allow the extra
366 bytes before and after buf if LWS_WRITE_BINARY or LWS_WRITE_TEXT
367 are used.
368 </dl>
369 <h3>Description</h3>
370 <blockquote>
371 This function provides the way to issue data back to the client
372 for both http and websocket protocols.
373 <p>
374 In the case of sending using websocket protocol, be sure to allocate
375 valid storage before and after buf as explained above.  This scheme
376 allows maximum efficiency of sending data and protocol in a single
377 packet while not burdening the user code with any protocol knowledge.
378 </blockquote>
379 <hr>
380 <h2>libwebsockets_serve_http_file - Send a file back to the client using http</h2>
381 <i>int</i>
382 <b>libwebsockets_serve_http_file</b>
383 (<i>struct libwebsocket *</i> <b>wsi</b>,
384 <i>const char *</i> <b>file</b>,
385 <i>const char *</i> <b>content_type</b>)
386 <h3>Arguments</h3>
387 <dl>
388 <dt><b>wsi</b>
389 <dd>Websocket instance (available from user callback)
390 <dt><b>file</b>
391 <dd>The file to issue over http
392 <dt><b>content_type</b>
393 <dd>The http content type, eg, text/html
394 </dl>
395 <h3>Description</h3>
396 <blockquote>
397 This function is intended to be called from the callback in response
398 to http requests from the client.  It allows the callback to issue
399 local files down the http link in a single step.
400 </blockquote>
401 <hr>
402 <h2>libwebsockets_remaining_packet_payload - Bytes to come before "overall" rx packet is complete</h2>
403 <i>size_t</i>
404 <b>libwebsockets_remaining_packet_payload</b>
405 (<i>struct libwebsocket *</i> <b>wsi</b>)
406 <h3>Arguments</h3>
407 <dl>
408 <dt><b>wsi</b>
409 <dd>Websocket instance (available from user callback)
410 </dl>
411 <h3>Description</h3>
412 <blockquote>
413 This function is intended to be called from the callback if the
414 user code is interested in "complete packets" from the client.
415 libwebsockets just passes through payload as it comes and issues a buffer
416 additionally when it hits a built-in limit.  The LWS_CALLBACK_RECEIVE
417 callback handler can use this API to find out if the buffer it has just
418 been given is the last piece of a "complete packet" from the client --
419 when that is the case <b>libwebsockets_remaining_packet_payload</b> will return
420 0.
421 <p>
422 Many protocols won't care becuse their packets are always small.
423 </blockquote>
424 <hr>
425 <h2>libwebsocket_client_connect - Connect to another websocket server</h2>
426 <i>struct libwebsocket *</i>
427 <b>libwebsocket_client_connect</b>
428 (<i>struct libwebsocket_context *</i> <b>this</b>,
429 <i>const char *</i> <b>address</b>,
430 <i>int</i> <b>port</b>,
431 <i>int</i> <b>ssl_connection</b>,
432 <i>const char *</i> <b>path</b>,
433 <i>const char *</i> <b>host</b>,
434 <i>const char *</i> <b>origin</b>,
435 <i>const char *</i> <b>protocol</b>,
436 <i>int</i> <b>ietf_version_or_minus_one</b>)
437 <h3>Arguments</h3>
438 <dl>
439 <dt><b>this</b>
440 <dd>Websocket context
441 <dt><b>address</b>
442 <dd>Remote server address, eg, "myserver.com"
443 <dt><b>port</b>
444 <dd>Port to connect to on the remote server, eg, 80
445 <dt><b>ssl_connection</b>
446 <dd>0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self
447 signed certs
448 <dt><b>path</b>
449 <dd>Websocket path on server
450 <dt><b>host</b>
451 <dd>Hostname on server
452 <dt><b>origin</b>
453 <dd>Socket origin name
454 <dt><b>protocol</b>
455 <dd>Comma-separated list of protocols being asked for from
456 the server, or just one.  The server will pick the one it
457 likes best.
458 <dt><b>ietf_version_or_minus_one</b>
459 <dd>-1 to ask to connect using the default, latest
460 protocol supported, or the specific protocol ordinal
461 </dl>
462 <h3>Description</h3>
463 <blockquote>
464 This function creates a connection to a remote server
465 </blockquote>
466 <hr>
467 <h2>callback - User server actions</h2>
468 <i>int</i>
469 <b>callback</b>
470 (<i>struct libwebsocket_context *</i> <b>context</b>,
471 <i>struct libwebsocket *</i> <b>wsi</b>,
472 <i>enum libwebsocket_callback_reasons</i> <b>reason</b>,
473 <i>void *</i> <b>user</b>,
474 <i>void *</i> <b>in</b>,
475 <i>size_t</i> <b>len</b>)
476 <h3>Arguments</h3>
477 <dl>
478 <dt><b>context</b>
479 <dd>Websockets context
480 <dt><b>wsi</b>
481 <dd>Opaque websocket instance pointer
482 <dt><b>reason</b>
483 <dd>The reason for the call
484 <dt><b>user</b>
485 <dd>Pointer to per-session user data allocated by library
486 <dt><b>in</b>
487 <dd>Pointer used for some callback reasons
488 <dt><b>len</b>
489 <dd>Length set for some callback reasons
490 </dl>
491 <h3>Description</h3>
492 <blockquote>
493 This callback is the way the user controls what is served.  All the
494 protocol detail is hidden and handled by the library.
495 <p>
496 For each connection / session there is user data allocated that is
497 pointed to by "user".  You set the size of this user data area when
498 the library is initialized with libwebsocket_create_server.
499 <p>
500 You get an opportunity to initialize user data when called back with
501 LWS_CALLBACK_ESTABLISHED reason.
502 </blockquote>
503 <h3>LWS_CALLBACK_ESTABLISHED</h3>
504 <blockquote>
505 after the server completes a handshake with
506 an incoming client
507 </blockquote>
508 <h3>LWS_CALLBACK_CLIENT_ESTABLISHED</h3>
509 <blockquote>
510 after your client connection completed
511 a handshake with the remote server
512 </blockquote>
513 <h3>LWS_CALLBACK_CLOSED</h3>
514 <blockquote>
515 when the websocket session ends
516 </blockquote>
517 <h3>LWS_CALLBACK_BROADCAST</h3>
518 <blockquote>
519 signal to send to client (you would use
520 <b>libwebsocket_write</b> taking care about the
521 special buffer requirements
522 </blockquote>
523 <h3>LWS_CALLBACK_RECEIVE</h3>
524 <blockquote>
525 data has appeared for this server endpoint from a
526 remote client, it can be found at *in and is
527 len bytes long
528 </blockquote>
529 <h3>LWS_CALLBACK_CLIENT_RECEIVE_PONG</h3>
530 <blockquote>
531 if you elected to see PONG packets,
532 they appear with this callback reason.  PONG
533 packets only exist in 04+ protocol
534 </blockquote>
535 <h3>LWS_CALLBACK_CLIENT_RECEIVE</h3>
536 <blockquote>
537 data has appeared from the server for the
538 client connection, it can be found at *in and
539 is len bytes long
540 </blockquote>
541 <h3>LWS_CALLBACK_HTTP</h3>
542 <blockquote>
543 an http request has come from a client that is not
544 asking to upgrade the connection to a websocket
545 one.  This is a chance to serve http content,
546 for example, to send a script to the client
547 which will then open the websockets connection.
548 <tt><b>in</b></tt> points to the URI path requested and
549 <b>libwebsockets_serve_http_file</b> makes it very
550 simple to send back a file to the client.
551 </blockquote>
552 <h3>LWS_CALLBACK_CLIENT_WRITEABLE</h3>
553 <blockquote>
554 if you call
555 <b>libwebsocket_callback_on_writable</b> on a connection, you will
556 get this callback coming when the connection socket is able to
557 accept another write packet without blocking.  If it already
558 was able to take another packet without blocking, you'll get
559 this callback at the next call to the service loop function.
560 </blockquote>
561 <h3>LWS_CALLBACK_FILTER_NETWORK_CONNECTION</h3>
562 <blockquote>
563 called when a client connects to
564 the server at network level; the connection is accepted but then
565 passed to this callback to decide whether to hang up immediately
566 or not, based on the client IP.  <tt><b>user</b></tt> contains the connection
567 socket's descriptor.  Return non-zero to terminate
568 the connection before sending or receiving anything.
569 Because this happens immediately after the network connection
570 from the client, there's no websocket protocol selected yet so
571 this callback is issued only to protocol 0.
572 </blockquote>
573 <h3>LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION</h3>
574 <blockquote>
575 called when the handshake has
576 been received and parsed from the client, but the response is
577 not sent yet.  Return non-zero to disallow the connection.
578 <tt><b>user</b></tt> is a pointer to an array of struct lws_tokens, you can
579 use the header enums lws_token_indexes from libwebsockets.h
580 to check for and read the supported header presence and
581 content before deciding to allow the handshake to proceed or
582 to kill the connection.
583 </blockquote>
584 <h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS</h3>
585 <blockquote>
586 if configured for
587 including OpenSSL support, this callback allows your user code
588 to perform extra <b>SSL_CTX_load_verify_locations</b> or similar
589 calls to direct OpenSSL where to find certificates the client
590 can use to confirm the remote server identity.  <tt><b>user</b></tt> is the
591 OpenSSL SSL_CTX*
592 </blockquote>
593 <h3>LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS</h3>
594 <blockquote>
595 if configured for
596 including OpenSSL support, this callback allows your user code
597 to load extra certifcates into the server which allow it to
598 verify the validity of certificates returned by clients.  <tt><b>user</b></tt>
599 is the server's OpenSSL SSL_CTX*
600 </blockquote>
601 <h3>LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION</h3>
602 <blockquote>
603 if the
604 libwebsockets context was created with the option
605 LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT, then this
606 callback is generated during OpenSSL verification of the cert
607 sent from the client.  It is sent to protocol[0] callback as
608 no protocol has been negotiated on the connection yet.
609 Notice that the libwebsockets context and wsi are both NULL
610 during this callback.  See
611 </blockquote>
612 <h3>http</h3>
613 <blockquote>
614 //www.openssl.org/docs/ssl/SSL_CTX_set_verify.html
615 to understand more detail about the OpenSSL callback that
616 generates this libwebsockets callback and the meanings of the
617 arguments passed.  In this callback, <tt><b>user</b></tt> is the x509_ctx,
618 <tt><b>in</b></tt> is the ssl pointer and <tt><b>len</b></tt> is preverify_ok
619 Notice that this callback maintains libwebsocket return
620 conventions, return 0 to mean the cert is OK or 1 to fail it.
621 This also means that if you don't handle this callback then
622 the default callback action of returning 0 allows the client
623 certificates.
624 </blockquote>
625 <h3>LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER</h3>
626 <blockquote>
627 this callback happens
628 when a client handshake is being compiled.  <tt><b>user</b></tt> is NULL,
629 <tt><b>in</b></tt> is a char **, it's pointing to a char * which holds the
630 next location in the header buffer where you can add
631 headers, and <tt><b>len</b></tt> is the remaining space in the header buffer,
632 which is typically some hundreds of bytes.  So, to add a canned
633 cookie, your handler code might look similar to:
634 <p>
635 char **p = (char **)in;
636 <p>
637 if (len &lt; 100)
638 return 1;
639 <p>
640 *p += sprintf(*p, "Cookie: a=b\x0d\x0a");
641 <p>
642 return 0;
643 <p>
644 Notice if you add anything, you just have to take care about
645 the CRLF on the line you added.  Obviously this callback is
646 optional, if you don't handle it everything is fine.
647 <p>
648 Notice the callback is coming to protocols[0] all the time,
649 because there is no specific protocol handshook yet.
650 <p>
651 The next four reasons are optional and only need taking care of if you
652 will be integrating libwebsockets sockets into an external polling
653 array.
654 </blockquote>
655 <h3>LWS_CALLBACK_ADD_POLL_FD</h3>
656 <blockquote>
657 libwebsocket deals with its <b>poll</b> loop
658 internally, but in the case you are integrating with another
659 server you will need to have libwebsocket sockets share a
660 polling array with the other server.  This and the other
661 POLL_FD related callbacks let you put your specialized
662 poll array interface code in the callback for protocol 0, the
663 first protocol you support, usually the HTTP protocol in the
664 serving case.  This callback happens when a socket needs to be
665 </blockquote>
666 <h3>added to the polling loop</h3>
667 <blockquote>
668 <tt><b>user</b></tt> contains the fd, and
669 <tt><b>len</b></tt> is the events bitmap (like, POLLIN).  If you are using the
670 internal polling loop (the "service" callback), you can just
671 ignore these callbacks.
672 </blockquote>
673 <h3>LWS_CALLBACK_DEL_POLL_FD</h3>
674 <blockquote>
675 This callback happens when a socket descriptor
676 needs to be removed from an external polling array.  <tt><b>user</b></tt> is
677 the socket desricptor.  If you are using the internal polling
678 loop, you can just ignore it.
679 </blockquote>
680 <h3>LWS_CALLBACK_SET_MODE_POLL_FD</h3>
681 <blockquote>
682 This callback happens when libwebsockets
683 wants to modify the events for the socket descriptor in <tt><b>user</b></tt>.
684 The handler should OR <tt><b>len</b></tt> on to the events member of the pollfd
685 struct for this socket descriptor.  If you are using the
686 internal polling loop, you can just ignore it.
687 </blockquote>
688 <h3>LWS_CALLBACK_CLEAR_MODE_POLL_FD</h3>
689 <blockquote>
690 This callback occurs when libwebsockets
691 wants to modify the events for the socket descriptor in <tt><b>user</b></tt>.
692 The handler should AND ~<tt><b>len</b></tt> on to the events member of the
693 pollfd struct for this socket descriptor.  If you are using the
694 internal polling loop, you can just ignore it.
695 </blockquote>
696 <hr>
697 <h2>struct libwebsocket_protocols - List of protocols and handlers server supports.</h2>
698 <b>struct libwebsocket_protocols</b> {<br>
699 &nbsp; &nbsp; <i>const char *</i> <b>name</b>;<br>
700 &nbsp; &nbsp; <i>int (*</i><b>callback</b>) <i>(struct libwebsocket_context * context,struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, void *user,void *in, size_t len)</i>;<br>
701 &nbsp; &nbsp; <i>size_t</i> <b>per_session_data_size</b>;<br>
702 &nbsp; &nbsp; <i>struct libwebsocket_context *</i> <b>owning_server</b>;<br>
703 &nbsp; &nbsp; <i>int</i> <b>broadcast_socket_port</b>;<br>
704 &nbsp; &nbsp; <i>int</i> <b>broadcast_socket_user_fd</b>;<br>
705 &nbsp; &nbsp; <i>int</i> <b>protocol_index</b>;<br>
706 };<br>
707 <h3>Members</h3>
708 <dl>
709 <dt><b>name</b>
710 <dd>Protocol name that must match the one given in the client
711 Javascript new WebSocket(url, 'protocol') name
712 <dt><b>callback</b>
713 <dd>The service callback used for this protocol.  It allows the
714 service action for an entire protocol to be encapsulated in
715 the protocol-specific callback
716 <dt><b>per_session_data_size</b>
717 <dd>Each new connection using this protocol gets
718 this much memory allocated on connection establishment and
719 freed on connection takedown.  A pointer to this per-connection
720 allocation is passed into the callback in the 'user' parameter
721 <dt><b>owning_server</b>
722 <dd>the server init call fills in this opaque pointer when
723 registering this protocol with the server.
724 <dt><b>broadcast_socket_port</b>
725 <dd>the server init call fills this in with the
726 localhost port number used to forward broadcasts for this
727 protocol
728 <dt><b>broadcast_socket_user_fd</b>
729 <dd>the server init call fills this in ... the <b>main</b>
730 process context can write to this socket to perform broadcasts
731 (use the <b>libwebsockets_broadcast</b> api to do this instead,
732 it works from any process context)
733 <dt><b>protocol_index</b>
734 <dd>which protocol we are starting from zero
735 </dl>
736 <h3>Description</h3>
737 <blockquote>
738 This structure represents one protocol supported by the server.  An
739 array of these structures is passed to <b>libwebsocket_create_server</b>
740 allows as many protocols as you like to be handled by one server.
741 </blockquote>
742 <hr>