PageRenderTime 59ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/libwebsockets-api-doc.html

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