2 * libwebsockets - small server side websockets and web server implementation
4 * Copyright (C) 2010-2016 Andy Green <andy@warmcat.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation:
9 * version 2.1 of the License.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 #ifndef LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C
23 #define LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C
29 #include "mbed-drivers/mbed.h"
30 #include "sal-iface-eth/EthernetInterface.h"
31 #include "sockets/TCPListener.h"
32 #include "sal-stack-lwip/lwipv4_init.h"
36 using namespace mbed::Sockets::v0;
48 awaiting_on_writeable(0)
53 void set_wsi(struct lws *_wsi) { wsi = _wsi; }
54 int actual_onRX(Socket *s);
56 void onError(Socket *s, socket_error_t err);
57 void onDisconnect(TCPStream *s);
58 void onSent(Socket *s, uint16_t len);
59 void serialized_writeable(struct lws *wsi);
67 char awaiting_on_writeable;
70 class lws_conn_listener : lws_conn {
73 srv(SOCKET_STACK_LWIP_IPV4)
75 srv.setOnError(TCPStream::ErrorHandler_t(this,
76 &lws_conn_listener::onError));
79 void start(const uint16_t port);
83 void onError(Socket *s, socket_error_t err);
84 void onIncoming(TCPListener *s, void *impl);
85 void onDisconnect(TCPStream *s);
105 #include "lws_config.h"
107 #if defined(WIN32) || defined(_WIN32)
108 #ifndef WIN32_LEAN_AND_MEAN
109 #define WIN32_LEAN_AND_MEAN
112 #include <winsock2.h>
113 #include <ws2tcpip.h>
119 #define strcasecmp stricmp
120 #define getdtablesize() 30000
122 #define LWS_INLINE __inline
124 #define LWS_WARN_UNUSED_RESULT
125 #define LWS_WARN_DEPRECATED
129 #define LWS_EXTERN extern __declspec(dllexport)
131 #define LWS_EXTERN extern __declspec(dllimport)
137 #define LWS_INVALID_FILE INVALID_HANDLE_VALUE
138 #define LWS_O_RDONLY _O_RDONLY
140 #else /* NOT WIN32 */
143 #define LWS_INLINE inline
144 #define LWS_O_RDONLY O_RDONLY
146 #ifndef MBED_OPERATORS
149 #define LWS_INVALID_FILE -1
151 #define getdtablesize() (20)
152 #define LWS_INVALID_FILE NULL
155 #if defined(__GNUC__)
156 #define LWS_VISIBLE __attribute__((visibility("default")))
157 #define LWS_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
158 #define LWS_WARN_DEPRECATED __attribute__ ((deprecated))
161 #define LWS_WARN_UNUSED_RESULT
162 #define LWS_WARN_DEPRECATED
165 #if defined(__ANDROID__)
167 #define getdtablesize() sysconf(_SC_OPEN_MAX)
174 #endif /* LWS_USE_LIBEV */
177 #endif /* LWS_USE_LIBUV */
180 #define LWS_EXTERN extern
186 #include <sys/time.h>
190 #ifdef LWS_OPENSSL_SUPPORT
192 #ifdef USE_OLD_CYASSL
193 #include <cyassl/openssl/ssl.h>
195 #include <wolfssl/openssl/ssl.h>
196 #endif /* not USE_OLD_CYASSL */
198 #include <openssl/ssl.h>
199 #endif /* not USE_WOLFSSL */
202 #define CONTEXT_PORT_NO_LISTEN -1
204 enum lws_log_levels {
214 LLL_LATENCY = 1 << 9,
216 LLL_COUNT = 10 /* set to count of valid flags */
219 LWS_VISIBLE LWS_EXTERN void _lws_log(int filter, const char *format, ...);
220 LWS_VISIBLE LWS_EXTERN void _lws_logv(int filter, const char *format, va_list vl);
222 /* notice, warn and log are always compiled in */
223 #define lwsl_notice(...) _lws_log(LLL_NOTICE, __VA_ARGS__)
224 #define lwsl_warn(...) _lws_log(LLL_WARN, __VA_ARGS__)
225 #define lwsl_err(...) _lws_log(LLL_ERR, __VA_ARGS__)
227 * weaker logging can be deselected at configure time using --disable-debug
228 * that gets rid of the overhead of checking while keeping _warn and _err
233 #define lwsl_info(...) _lws_log(LLL_INFO, __VA_ARGS__)
234 #define lwsl_debug(...) _lws_log(LLL_DEBUG, __VA_ARGS__)
235 #define lwsl_parser(...) _lws_log(LLL_PARSER, __VA_ARGS__)
236 #define lwsl_header(...) _lws_log(LLL_HEADER, __VA_ARGS__)
237 #define lwsl_ext(...) _lws_log(LLL_EXT, __VA_ARGS__)
238 #define lwsl_client(...) _lws_log(LLL_CLIENT, __VA_ARGS__)
239 #define lwsl_latency(...) _lws_log(LLL_LATENCY, __VA_ARGS__)
240 LWS_VISIBLE LWS_EXTERN void lwsl_hexdump(void *buf, size_t len);
244 #define lwsl_info(...) {}
245 #define lwsl_debug(...) {}
246 #define lwsl_parser(...) {}
247 #define lwsl_header(...) {}
248 #define lwsl_ext(...) {}
249 #define lwsl_client(...) {}
250 #define lwsl_latency(...) {}
251 #define lwsl_hexdump(a, b)
255 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
257 /* api change list for user code to test against */
259 #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG
261 /* the struct lws_protocols has the id field present */
262 #define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD
264 /* you can call lws_get_peer_write_allowance */
265 #define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE
267 /* extra parameter introduced in 917f43ab821 */
268 #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_LEN
270 /* File operations stuff exists */
271 #define LWS_FEATURE_FOPS
274 * NOTE: These public enums are part of the abi. If you want to add one,
275 * add it at where specified so existing users are unaffected.
277 enum lws_context_options {
278 LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT = (1 << 1),
279 LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME = (1 << 2),
280 LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT = (1 << 3),
281 LWS_SERVER_OPTION_LIBEV = (1 << 4),
282 LWS_SERVER_OPTION_DISABLE_IPV6 = (1 << 5),
283 LWS_SERVER_OPTION_DISABLE_OS_CA_CERTS = (1 << 6),
284 LWS_SERVER_OPTION_PEER_CERT_NOT_REQUIRED = (1 << 7),
285 LWS_SERVER_OPTION_VALIDATE_UTF8 = (1 << 8),
286 LWS_SERVER_OPTION_SSL_ECDH = (1 << 9),
287 LWS_SERVER_OPTION_LIBUV = (1 << 10),
289 /****** add new things just above ---^ ******/
293 * NOTE: These public enums are part of the abi. If you want to add one,
294 * add it at where specified so existing users are unaffected.
296 enum lws_callback_reasons {
297 LWS_CALLBACK_ESTABLISHED = 0,
298 LWS_CALLBACK_CLIENT_CONNECTION_ERROR = 1,
299 LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH = 2,
300 LWS_CALLBACK_CLIENT_ESTABLISHED = 3,
301 LWS_CALLBACK_CLOSED = 4,
302 LWS_CALLBACK_CLOSED_HTTP = 5,
303 LWS_CALLBACK_RECEIVE = 6,
304 LWS_CALLBACK_RECEIVE_PONG = 7,
305 LWS_CALLBACK_CLIENT_RECEIVE = 8,
306 LWS_CALLBACK_CLIENT_RECEIVE_PONG = 9,
307 LWS_CALLBACK_CLIENT_WRITEABLE = 10,
308 LWS_CALLBACK_SERVER_WRITEABLE = 11,
309 LWS_CALLBACK_HTTP = 12,
310 LWS_CALLBACK_HTTP_BODY = 13,
311 LWS_CALLBACK_HTTP_BODY_COMPLETION = 14,
312 LWS_CALLBACK_HTTP_FILE_COMPLETION = 15,
313 LWS_CALLBACK_HTTP_WRITEABLE = 16,
314 LWS_CALLBACK_FILTER_NETWORK_CONNECTION = 17,
315 LWS_CALLBACK_FILTER_HTTP_CONNECTION = 18,
316 LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED = 19,
317 LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION = 20,
318 LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS = 21,
319 LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS = 22,
320 LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION = 23,
321 LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER = 24,
322 LWS_CALLBACK_CONFIRM_EXTENSION_OKAY = 25,
323 LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED = 26,
324 LWS_CALLBACK_PROTOCOL_INIT = 27,
325 LWS_CALLBACK_PROTOCOL_DESTROY = 28,
326 LWS_CALLBACK_WSI_CREATE /* always protocol[0] */ = 29,
327 LWS_CALLBACK_WSI_DESTROY /* always protocol[0] */ = 30,
328 LWS_CALLBACK_GET_THREAD_ID = 31,
330 /* external poll() management support */
331 LWS_CALLBACK_ADD_POLL_FD = 32,
332 LWS_CALLBACK_DEL_POLL_FD = 33,
333 LWS_CALLBACK_CHANGE_MODE_POLL_FD = 34,
334 LWS_CALLBACK_LOCK_POLL = 35,
335 LWS_CALLBACK_UNLOCK_POLL = 36,
337 LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY = 37,
338 LWS_CALLBACK_WS_PEER_INITIATED_CLOSE = 38,
340 LWS_CALLBACK_WS_EXT_DEFAULTS = 39,
342 /****** add new things just above ---^ ******/
344 LWS_CALLBACK_USER = 1000, /* user code can use any including / above */
349 typedef SOCKET lws_sockfd_type;
350 typedef HANDLE lws_filefd_type;
351 #define lws_sockfd_valid(sfd) (!!sfd)
359 #if defined(MBED_OPERATORS)
360 /* it's a class lws_conn * */
361 typedef void * lws_sockfd_type;
362 typedef void * lws_filefd_type;
363 #define lws_sockfd_valid(sfd) (!!sfd)
369 #define POLLIN 0x0001
370 #define POLLPRI 0x0002
371 #define POLLOUT 0x0004
372 #define POLLERR 0x0008
373 #define POLLHUP 0x0010
374 #define POLLNVAL 0x0020
378 void * mbed3_create_tcp_stream_socket(void);
379 void mbed3_delete_tcp_stream_socket(void *sockfd);
380 void mbed3_tcp_stream_bind(void *sock, int port, struct lws *);
381 void mbed3_tcp_stream_accept(void *sock, struct lws *);
383 typedef int lws_sockfd_type;
384 typedef int lws_filefd_type;
385 #define lws_sockfd_valid(sfd) (sfd >= 0)
388 #define lws_pollfd pollfd
391 /* argument structure for all external poll related calls
394 struct lws_pollargs {
395 lws_sockfd_type fd; /* applicable socket descriptor */
396 int events; /* the new event mask */
397 int prev_events; /* the previous event mask */
401 * struct lws_plat_file_ops - Platform-specific file operations
403 * These provide platform-agnostic ways to deal with filesystem access in the
404 * library and in the user code.
406 * @open: Open file (always binary access if plat supports it)
407 * filelen is filled on exit to be the length of the file
408 * flags should be set to O_RDONLY or O_RDWR
410 * @seek_cur: Seek from current position
411 * @read: Read fron file *amount is set on exit to amount read
412 * @write: Write to file *amount is set on exit as amount written
414 struct lws_plat_file_ops {
415 lws_filefd_type (*open)(struct lws *wsi, const char *filename,
416 unsigned long *filelen, int flags);
417 int (*close)(struct lws *wsi, lws_filefd_type fd);
418 unsigned long (*seek_cur)(struct lws *wsi, lws_filefd_type fd,
419 long offset_from_cur_pos);
420 int (*read)(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
421 unsigned char *buf, unsigned long len);
422 int (*write)(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
423 unsigned char *buf, unsigned long len);
425 /* Add new things just above here ---^
426 * This is part of the ABI, don't needlessly break compatibility */
430 * NOTE: These public enums are part of the abi. If you want to add one,
431 * add it at where specified so existing users are unaffected.
433 enum lws_extension_callback_reasons {
434 LWS_EXT_CB_SERVER_CONTEXT_CONSTRUCT = 0,
435 LWS_EXT_CB_CLIENT_CONTEXT_CONSTRUCT = 1,
436 LWS_EXT_CB_SERVER_CONTEXT_DESTRUCT = 2,
437 LWS_EXT_CB_CLIENT_CONTEXT_DESTRUCT = 3,
438 LWS_EXT_CB_CONSTRUCT = 4,
439 LWS_EXT_CB_CLIENT_CONSTRUCT = 5,
440 LWS_EXT_CB_CHECK_OK_TO_REALLY_CLOSE = 6,
441 LWS_EXT_CB_CHECK_OK_TO_PROPOSE_EXTENSION = 7,
442 LWS_EXT_CB_DESTROY = 8,
443 LWS_EXT_CB_DESTROY_ANY_WSI_CLOSING = 9,
444 LWS_EXT_CB_ANY_WSI_ESTABLISHED = 10,
445 LWS_EXT_CB_PACKET_RX_PREPARSE = 11,
446 LWS_EXT_CB_PACKET_TX_PRESEND = 12,
447 LWS_EXT_CB_PACKET_TX_DO_SEND = 13,
448 LWS_EXT_CB_HANDSHAKE_REPLY_TX = 14,
449 LWS_EXT_CB_FLUSH_PENDING_TX = 15,
450 LWS_EXT_CB_EXTENDED_PAYLOAD_RX = 16,
451 LWS_EXT_CB_CAN_PROXY_CLIENT_CONNECTION = 17,
453 LWS_EXT_CB_REQUEST_ON_WRITEABLE = 19,
454 LWS_EXT_CB_IS_WRITEABLE = 20,
455 LWS_EXT_CB_PAYLOAD_TX = 21,
456 LWS_EXT_CB_PAYLOAD_RX = 22,
457 LWS_EXT_CB_OPTION_DEFAULT = 23,
458 LWS_EXT_CB_OPTION_SET = 24,
459 LWS_EXT_CB_OPTION_CONFIRM = 25,
461 /****** add new things just above ---^ ******/
465 * NOTE: These public enums are part of the abi. If you want to add one,
466 * add it at where specified so existing users are unaffected.
468 enum lws_write_protocol {
470 LWS_WRITE_BINARY = 1,
471 LWS_WRITE_CONTINUATION = 2,
474 /* special 04+ opcodes */
476 /* LWS_WRITE_CLOSE is handled by lws_close_reason() */
480 /* Same as write_http but we know this write ends the transaction */
481 LWS_WRITE_HTTP_FINAL = 7,
485 LWS_WRITE_HTTP_HEADERS = 8,
487 /****** add new things just above ---^ ******/
491 LWS_WRITE_NO_FIN = 0x40,
493 * client packet payload goes out on wire unmunged
494 * only useful for security tests since normal servers cannot
495 * decode the content if used
497 LWS_WRITE_CLIENT_IGNORE_XOR_MASK = 0x80
501 * you need these to look at headers that have been parsed if using the
502 * LWS_CALLBACK_FILTER_CONNECTION callback. If a header from the enum
503 * list below is absent, .token = NULL and token_len = 0. Otherwise .token
504 * points to .token_len chars containing that header content.
513 * these have to be kept in sync with lextable.h / minilex.c
515 * NOTE: These public enums are part of the abi. If you want to add one,
516 * add it at where specified so existing users are unaffected.
518 enum lws_token_indexes {
519 WSI_TOKEN_GET_URI = 0,
520 WSI_TOKEN_POST_URI = 1,
521 WSI_TOKEN_OPTIONS_URI = 2,
523 WSI_TOKEN_CONNECTION = 4,
524 WSI_TOKEN_UPGRADE = 5,
525 WSI_TOKEN_ORIGIN = 6,
527 WSI_TOKEN_CHALLENGE = 8,
528 WSI_TOKEN_EXTENSIONS = 9,
531 WSI_TOKEN_PROTOCOL = 12,
532 WSI_TOKEN_ACCEPT = 13,
533 WSI_TOKEN_NONCE = 14,
535 WSI_TOKEN_HTTP2_SETTINGS = 16,
536 WSI_TOKEN_HTTP_ACCEPT = 17,
537 WSI_TOKEN_HTTP_AC_REQUEST_HEADERS = 18,
538 WSI_TOKEN_HTTP_IF_MODIFIED_SINCE = 19,
539 WSI_TOKEN_HTTP_IF_NONE_MATCH = 20,
540 WSI_TOKEN_HTTP_ACCEPT_ENCODING = 21,
541 WSI_TOKEN_HTTP_ACCEPT_LANGUAGE = 22,
542 WSI_TOKEN_HTTP_PRAGMA = 23,
543 WSI_TOKEN_HTTP_CACHE_CONTROL = 24,
544 WSI_TOKEN_HTTP_AUTHORIZATION = 25,
545 WSI_TOKEN_HTTP_COOKIE = 26,
546 WSI_TOKEN_HTTP_CONTENT_LENGTH = 27,
547 WSI_TOKEN_HTTP_CONTENT_TYPE = 28,
548 WSI_TOKEN_HTTP_DATE = 29,
549 WSI_TOKEN_HTTP_RANGE = 30,
550 WSI_TOKEN_HTTP_REFERER = 31,
552 WSI_TOKEN_VERSION = 33,
553 WSI_TOKEN_SWORIGIN = 34,
555 WSI_TOKEN_HTTP_COLON_AUTHORITY = 35,
556 WSI_TOKEN_HTTP_COLON_METHOD = 36,
557 WSI_TOKEN_HTTP_COLON_PATH = 37,
558 WSI_TOKEN_HTTP_COLON_SCHEME = 38,
559 WSI_TOKEN_HTTP_COLON_STATUS = 39,
561 WSI_TOKEN_HTTP_ACCEPT_CHARSET = 40,
562 WSI_TOKEN_HTTP_ACCEPT_RANGES = 41,
563 WSI_TOKEN_HTTP_ACCESS_CONTROL_ALLOW_ORIGIN = 42,
564 WSI_TOKEN_HTTP_AGE = 43,
565 WSI_TOKEN_HTTP_ALLOW = 44,
566 WSI_TOKEN_HTTP_CONTENT_DISPOSITION = 45,
567 WSI_TOKEN_HTTP_CONTENT_ENCODING = 46,
568 WSI_TOKEN_HTTP_CONTENT_LANGUAGE = 47,
569 WSI_TOKEN_HTTP_CONTENT_LOCATION = 48,
570 WSI_TOKEN_HTTP_CONTENT_RANGE = 49,
571 WSI_TOKEN_HTTP_ETAG = 50,
572 WSI_TOKEN_HTTP_EXPECT = 51,
573 WSI_TOKEN_HTTP_EXPIRES = 52,
574 WSI_TOKEN_HTTP_FROM = 53,
575 WSI_TOKEN_HTTP_IF_MATCH = 54,
576 WSI_TOKEN_HTTP_IF_RANGE = 55,
577 WSI_TOKEN_HTTP_IF_UNMODIFIED_SINCE = 56,
578 WSI_TOKEN_HTTP_LAST_MODIFIED = 57,
579 WSI_TOKEN_HTTP_LINK = 58,
580 WSI_TOKEN_HTTP_LOCATION = 59,
581 WSI_TOKEN_HTTP_MAX_FORWARDS = 60,
582 WSI_TOKEN_HTTP_PROXY_AUTHENTICATE = 61,
583 WSI_TOKEN_HTTP_PROXY_AUTHORIZATION = 62,
584 WSI_TOKEN_HTTP_REFRESH = 63,
585 WSI_TOKEN_HTTP_RETRY_AFTER = 64,
586 WSI_TOKEN_HTTP_SERVER = 65,
587 WSI_TOKEN_HTTP_SET_COOKIE = 66,
588 WSI_TOKEN_HTTP_STRICT_TRANSPORT_SECURITY = 67,
589 WSI_TOKEN_HTTP_TRANSFER_ENCODING = 68,
590 WSI_TOKEN_HTTP_USER_AGENT = 69,
591 WSI_TOKEN_HTTP_VARY = 70,
592 WSI_TOKEN_HTTP_VIA = 71,
593 WSI_TOKEN_HTTP_WWW_AUTHENTICATE = 72,
595 WSI_TOKEN_PATCH_URI = 73,
596 WSI_TOKEN_PUT_URI = 74,
597 WSI_TOKEN_DELETE_URI = 75,
599 WSI_TOKEN_HTTP_URI_ARGS = 76,
600 WSI_TOKEN_PROXY = 77,
601 WSI_TOKEN_HTTP_X_REAL_IP = 78,
603 /****** add new things just above ---^ ******/
605 /* use token storage to stash these internally, not for
608 _WSI_TOKEN_CLIENT_SENT_PROTOCOLS,
609 _WSI_TOKEN_CLIENT_PEER_ADDRESS,
610 _WSI_TOKEN_CLIENT_URI,
611 _WSI_TOKEN_CLIENT_HOST,
612 _WSI_TOKEN_CLIENT_ORIGIN,
614 /* always last real token index*/
617 /* parser state additions, no storage associated */
620 WSI_TOKEN_SKIPPING_SAW_CR,
621 WSI_PARSING_COMPLETE,
622 WSI_INIT_TOKEN_MUXURL,
625 struct lws_token_limits {
626 unsigned short token_limit[WSI_TOKEN_COUNT];
633 1000 indicates a normal closure, meaning that the purpose for
634 which the connection was established has been fulfilled.
638 1001 indicates that an endpoint is "going away", such as a server
639 going down or a browser having navigated away from a page.
643 1002 indicates that an endpoint is terminating the connection due
648 1003 indicates that an endpoint is terminating the connection
649 because it has received a type of data it cannot accept (e.g., an
650 endpoint that understands only text data MAY send this if it
651 receives a binary message).
655 Reserved. The specific meaning might be defined in the future.
659 1005 is a reserved value and MUST NOT be set as a status code in a
660 Close control frame by an endpoint. It is designated for use in
661 applications expecting a status code to indicate that no status
662 code was actually present.
666 1006 is a reserved value and MUST NOT be set as a status code in a
667 Close control frame by an endpoint. It is designated for use in
668 applications expecting a status code to indicate that the
669 connection was closed abnormally, e.g., without sending or
670 receiving a Close control frame.
674 1007 indicates that an endpoint is terminating the connection
675 because it has received data within a message that was not
676 consistent with the type of the message (e.g., non-UTF-8 [RFC3629]
677 data within a text message).
681 1008 indicates that an endpoint is terminating the connection
682 because it has received a message that violates its policy. This
683 is a generic status code that can be returned when there is no
684 other more suitable status code (e.g., 1003 or 1009) or if there
685 is a need to hide specific details about the policy.
689 1009 indicates that an endpoint is terminating the connection
690 because it has received a message that is too big for it to
695 1010 indicates that an endpoint (client) is terminating the
696 connection because it has expected the server to negotiate one or
697 more extension, but the server didn't return them in the response
698 message of the WebSocket handshake. The list of extensions that
699 are needed SHOULD appear in the /reason/ part of the Close frame.
700 Note that this status code is not used by the server, because it
701 can fail the WebSocket handshake instead.
705 1011 indicates that a server is terminating the connection because
706 it encountered an unexpected condition that prevented it from
707 fulfilling the request.
711 1015 is a reserved value and MUST NOT be set as a status code in a
712 Close control frame by an endpoint. It is designated for use in
713 applications expecting a status code to indicate that the
714 connection was closed due to a failure to perform a TLS handshake
715 (e.g., the server certificate can't be verified).
719 * NOTE: These public enums are part of the abi. If you want to add one,
720 * add it at where specified so existing users are unaffected.
722 enum lws_close_status {
723 LWS_CLOSE_STATUS_NOSTATUS = 0,
724 LWS_CLOSE_STATUS_NORMAL = 1000,
725 LWS_CLOSE_STATUS_GOINGAWAY = 1001,
726 LWS_CLOSE_STATUS_PROTOCOL_ERR = 1002,
727 LWS_CLOSE_STATUS_UNACCEPTABLE_OPCODE = 1003,
728 LWS_CLOSE_STATUS_RESERVED = 1004,
729 LWS_CLOSE_STATUS_NO_STATUS = 1005,
730 LWS_CLOSE_STATUS_ABNORMAL_CLOSE = 1006,
731 LWS_CLOSE_STATUS_INVALID_PAYLOAD = 1007,
732 LWS_CLOSE_STATUS_POLICY_VIOLATION = 1008,
733 LWS_CLOSE_STATUS_MESSAGE_TOO_LARGE = 1009,
734 LWS_CLOSE_STATUS_EXTENSION_REQUIRED = 1010,
735 LWS_CLOSE_STATUS_UNEXPECTED_CONDITION = 1011,
736 LWS_CLOSE_STATUS_TLS_FAILURE = 1015,
738 /****** add new things just above ---^ ******/
740 LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY = 9999,
744 HTTP_STATUS_OK = 200,
745 HTTP_STATUS_NO_CONTENT = 204,
747 HTTP_STATUS_BAD_REQUEST = 400,
748 HTTP_STATUS_UNAUTHORIZED,
749 HTTP_STATUS_PAYMENT_REQUIRED,
750 HTTP_STATUS_FORBIDDEN,
751 HTTP_STATUS_NOT_FOUND,
752 HTTP_STATUS_METHOD_NOT_ALLOWED,
753 HTTP_STATUS_NOT_ACCEPTABLE,
754 HTTP_STATUS_PROXY_AUTH_REQUIRED,
755 HTTP_STATUS_REQUEST_TIMEOUT,
756 HTTP_STATUS_CONFLICT,
758 HTTP_STATUS_LENGTH_REQUIRED,
759 HTTP_STATUS_PRECONDITION_FAILED,
760 HTTP_STATUS_REQ_ENTITY_TOO_LARGE,
761 HTTP_STATUS_REQ_URI_TOO_LONG,
762 HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE,
763 HTTP_STATUS_REQ_RANGE_NOT_SATISFIABLE,
764 HTTP_STATUS_EXPECTATION_FAILED,
766 HTTP_STATUS_INTERNAL_SERVER_ERROR = 500,
767 HTTP_STATUS_NOT_IMPLEMENTED,
768 HTTP_STATUS_BAD_GATEWAY,
769 HTTP_STATUS_SERVICE_UNAVAILABLE,
770 HTTP_STATUS_GATEWAY_TIMEOUT,
771 HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED,
776 /* needed even with extensions disabled for create context */
777 struct lws_extension;
780 * typedef lws_callback_function() - User server actions
781 * @wsi: Opaque websocket instance pointer
782 * @reason: The reason for the call
783 * @user: Pointer to per-session user data allocated by library
784 * @in: Pointer used for some callback reasons
785 * @len: Length set for some callback reasons
787 * This callback is the way the user controls what is served. All the
788 * protocol detail is hidden and handled by the library.
790 * For each connection / session there is user data allocated that is
791 * pointed to by "user". You set the size of this user data area when
792 * the library is initialized with lws_create_server.
794 * You get an opportunity to initialize user data when called back with
795 * LWS_CALLBACK_ESTABLISHED reason.
797 * LWS_CALLBACK_ESTABLISHED: after the server completes a handshake with
798 * an incoming client. If you built the library
799 * with ssl support, @in is a pointer to the
800 * ssl struct associated with the connection or
803 * LWS_CALLBACK_CLIENT_CONNECTION_ERROR: the request client connection has
804 * been unable to complete a handshake with the remote server. If
805 * in is non-NULL, you can find an error string of length len where
808 * LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH: this is the last chance for the
809 * client user code to examine the http headers
810 * and decide to reject the connection. If the
811 * content in the headers is interesting to the
812 * client (url, etc) it needs to copy it out at
813 * this point since it will be destroyed before
814 * the CLIENT_ESTABLISHED call
816 * LWS_CALLBACK_CLIENT_ESTABLISHED: after your client connection completed
817 * a handshake with the remote server
819 * LWS_CALLBACK_CLOSED: when the websocket session ends
821 * LWS_CALLBACK_CLOSED_HTTP: when a HTTP (non-websocket) session ends
823 * LWS_CALLBACK_RECEIVE: data has appeared for this server endpoint from a
824 * remote client, it can be found at *in and is
827 * LWS_CALLBACK_CLIENT_RECEIVE_PONG: if you elected to see PONG packets,
828 * they appear with this callback reason. PONG
829 * packets only exist in 04+ protocol
831 * LWS_CALLBACK_CLIENT_RECEIVE: data has appeared from the server for the
832 * client connection, it can be found at *in and
835 * LWS_CALLBACK_HTTP: an http request has come from a client that is not
836 * asking to upgrade the connection to a websocket
837 * one. This is a chance to serve http content,
838 * for example, to send a script to the client
839 * which will then open the websockets connection.
840 * @in points to the URI path requested and
841 * lws_serve_http_file() makes it very
842 * simple to send back a file to the client.
843 * Normally after sending the file you are done
844 * with the http connection, since the rest of the
845 * activity will come by websockets from the script
846 * that was delivered by http, so you will want to
847 * return 1; to close and free up the connection.
848 * That's important because it uses a slot in the
849 * total number of client connections allowed set
852 * LWS_CALLBACK_HTTP_BODY: the next @len bytes data from the http
853 * request body HTTP connection is now available in @in.
855 * LWS_CALLBACK_HTTP_BODY_COMPLETION: the expected amount of http request
856 * body has been delivered
858 * LWS_CALLBACK_HTTP_WRITEABLE: you can write more down the http protocol
861 * LWS_CALLBACK_HTTP_FILE_COMPLETION: a file requested to be send down
862 * http link has completed.
864 * LWS_CALLBACK_CLIENT_WRITEABLE:
865 * LWS_CALLBACK_SERVER_WRITEABLE: If you call
866 * lws_callback_on_writable() on a connection, you will
867 * get one of these callbacks coming when the connection socket
868 * is able to accept another write packet without blocking.
869 * If it already was able to take another packet without blocking,
870 * you'll get this callback at the next call to the service loop
871 * function. Notice that CLIENTs get LWS_CALLBACK_CLIENT_WRITEABLE
872 * and servers get LWS_CALLBACK_SERVER_WRITEABLE.
874 * LWS_CALLBACK_FILTER_NETWORK_CONNECTION: called when a client connects to
875 * the server at network level; the connection is accepted but then
876 * passed to this callback to decide whether to hang up immediately
877 * or not, based on the client IP. @in contains the connection
878 * socket's descriptor. Since the client connection information is
879 * not available yet, @wsi still pointing to the main server socket.
880 * Return non-zero to terminate the connection before sending or
881 * receiving anything. Because this happens immediately after the
882 * network connection from the client, there's no websocket protocol
883 * selected yet so this callback is issued only to protocol 0.
885 * LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED: A new client just had
886 * been connected, accepted, and instantiated into the pool. This
887 * callback allows setting any relevant property to it. Because this
888 * happens immediately after the instantiation of a new client,
889 * there's no websocket protocol selected yet so this callback is
890 * issued only to protocol 0. Only @wsi is defined, pointing to the
891 * new client, and the return value is ignored.
893 * LWS_CALLBACK_FILTER_HTTP_CONNECTION: called when the request has
894 * been received and parsed from the client, but the response is
895 * not sent yet. Return non-zero to disallow the connection.
896 * @user is a pointer to the connection user space allocation,
897 * @in is the URI, eg, "/"
898 * In your handler you can use the public APIs
899 * lws_hdr_total_length() / lws_hdr_copy() to access all of the
900 * headers using the header enums lws_token_indexes from
901 * libwebsockets.h to check for and read the supported header
902 * presence and content before deciding to allow the http
903 * connection to proceed or to kill the connection.
905 * LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION: called when the handshake has
906 * been received and parsed from the client, but the response is
907 * not sent yet. Return non-zero to disallow the connection.
908 * @user is a pointer to the connection user space allocation,
909 * @in is the requested protocol name
910 * In your handler you can use the public APIs
911 * lws_hdr_total_length() / lws_hdr_copy() to access all of the
912 * headers using the header enums lws_token_indexes from
913 * libwebsockets.h to check for and read the supported header
914 * presence and content before deciding to allow the handshake
915 * to proceed or to kill the connection.
917 * LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS: if configured for
918 * including OpenSSL support, this callback allows your user code
919 * to perform extra SSL_CTX_load_verify_locations() or similar
920 * calls to direct OpenSSL where to find certificates the client
921 * can use to confirm the remote server identity. @user is the
924 * LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS: if configured for
925 * including OpenSSL support, this callback allows your user code
926 * to load extra certifcates into the server which allow it to
927 * verify the validity of certificates returned by clients. @user
928 * is the server's OpenSSL SSL_CTX*
930 * LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY: if configured for
931 * including OpenSSL support but no private key file has been
932 * specified (ssl_private_key_filepath is NULL), this is called to
933 * allow the user to set the private key directly via libopenssl
934 * and perform further operations if required; this might be useful
935 * in situations where the private key is not directly accessible
936 * by the OS, for example if it is stored on a smartcard
937 * @user is the server's OpenSSL SSL_CTX*
939 * LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION: if the
940 * libwebsockets context was created with the option
941 * LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT, then this
942 * callback is generated during OpenSSL verification of the cert
943 * sent from the client. It is sent to protocol[0] callback as
944 * no protocol has been negotiated on the connection yet.
945 * Notice that the libwebsockets context and wsi are both NULL
946 * during this callback. See
947 * http://www.openssl.org/docs/ssl/SSL_CTX_set_verify.html
948 * to understand more detail about the OpenSSL callback that
949 * generates this libwebsockets callback and the meanings of the
950 * arguments passed. In this callback, @user is the x509_ctx,
951 * @in is the ssl pointer and @len is preverify_ok
952 * Notice that this callback maintains libwebsocket return
953 * conventions, return 0 to mean the cert is OK or 1 to fail it.
954 * This also means that if you don't handle this callback then
955 * the default callback action of returning 0 allows the client
958 * LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: this callback happens
959 * when a client handshake is being compiled. @user is NULL,
960 * @in is a char **, it's pointing to a char * which holds the
961 * next location in the header buffer where you can add
962 * headers, and @len is the remaining space in the header buffer,
963 * which is typically some hundreds of bytes. So, to add a canned
964 * cookie, your handler code might look similar to:
966 * char **p = (char **)in;
971 * *p += sprintf(*p, "Cookie: a=b\x0d\x0a");
975 * Notice if you add anything, you just have to take care about
976 * the CRLF on the line you added. Obviously this callback is
977 * optional, if you don't handle it everything is fine.
979 * Notice the callback is coming to protocols[0] all the time,
980 * because there is no specific protocol handshook yet.
982 * LWS_CALLBACK_CONFIRM_EXTENSION_OKAY: When the server handshake code
983 * sees that it does support a requested extension, before
984 * accepting the extension by additing to the list sent back to
985 * the client it gives this callback just to check that it's okay
986 * to use that extension. It calls back to the requested protocol
987 * and with @in being the extension name, @len is 0 and @user is
988 * valid. Note though at this time the ESTABLISHED callback hasn't
989 * happened yet so if you initialize @user content there, @user
990 * content during this callback might not be useful for anything.
991 * Notice this callback comes to protocols[0].
993 * LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED: When a client
994 * connection is being prepared to start a handshake to a server,
995 * each supported extension is checked with protocols[0] callback
996 * with this reason, giving the user code a chance to suppress the
997 * claim to support that extension by returning non-zero. If
998 * unhandled, by default 0 will be returned and the extension
999 * support included in the header to the server. Notice this
1000 * callback comes to protocols[0].
1002 * LWS_CALLBACK_PROTOCOL_INIT: One-time call per protocol so it can
1003 * do initial setup / allocations etc
1005 * LWS_CALLBACK_PROTOCOL_DESTROY: One-time call per protocol indicating
1006 * this protocol won't get used at all after this callback, the
1007 * context is getting destroyed. Take the opportunity to
1008 * deallocate everything that was allocated by the protocol.
1010 * LWS_CALLBACK_WSI_CREATE: outermost (earliest) wsi create notification
1012 * LWS_CALLBACK_WSI_DESTROY: outermost (latest) wsi destroy notification
1014 * The next five reasons are optional and only need taking care of if you
1015 * will be integrating libwebsockets sockets into an external polling
1018 * For these calls, @in points to a struct lws_pollargs that
1019 * contains @fd, @events and @prev_events members
1021 * LWS_CALLBACK_ADD_POLL_FD: libwebsocket deals with its poll() loop
1022 * internally, but in the case you are integrating with another
1023 * server you will need to have libwebsocket sockets share a
1024 * polling array with the other server. This and the other
1025 * POLL_FD related callbacks let you put your specialized
1026 * poll array interface code in the callback for protocol 0, the
1027 * first protocol you support, usually the HTTP protocol in the
1029 * This callback happens when a socket needs to be
1030 * added to the polling loop: @in points to a struct
1031 * lws_pollargs; the @fd member of the struct is the file
1032 * descriptor, and @events contains the active events.
1034 * If you are using the internal polling loop (the "service"
1035 * callback), you can just ignore these callbacks.
1037 * LWS_CALLBACK_DEL_POLL_FD: This callback happens when a socket descriptor
1038 * needs to be removed from an external polling array. @in is
1039 * again the struct lws_pollargs containing the @fd member
1040 * to be removed. If you are using the internal polling
1041 * loop, you can just ignore it.
1043 * LWS_CALLBACK_CHANGE_MODE_POLL_FD: This callback happens when
1044 * libwebsockets wants to modify the events for a connectiion.
1045 * @in is the struct lws_pollargs with the @fd to change.
1046 * The new event mask is in @events member and the old mask is in
1047 * the @prev_events member.
1048 * If you are using the internal polling loop, you can just ignore
1051 * LWS_CALLBACK_LOCK_POLL:
1052 * LWS_CALLBACK_UNLOCK_POLL: These allow the external poll changes driven
1053 * by libwebsockets to participate in an external thread locking
1054 * scheme around the changes, so the whole thing is threadsafe.
1055 * These are called around three activities in the library,
1056 * - inserting a new wsi in the wsi / fd table (len=1)
1057 * - deleting a wsi from the wsi / fd table (len=1)
1058 * - changing a wsi's POLLIN/OUT state (len=0)
1059 * Locking and unlocking external synchronization objects when
1060 * len == 1 allows external threads to be synchronized against
1061 * wsi lifecycle changes if it acquires the same lock for the
1062 * duration of wsi dereference from the other thread context.
1064 * LWS_CALLBACK_WS_PEER_INITIATED_CLOSE:
1065 * The peer has sent an unsolicited Close WS packet. @in and
1066 * @len are the optional close code (first 2 bytes, network
1067 * order) and the optional additional information which is not
1068 * defined in the standard, and may be a string or non-human-
1070 * If you return 0 lws will echo the close and then close the
1071 * connection. If you return nonzero lws will just close the
1075 lws_callback_function(struct lws *wsi, enum lws_callback_reasons reason,
1076 void *user, void *in, size_t len);
1079 * typedef lws_extension_callback_function() - Hooks to allow extensions to operate
1080 * @context: Websockets context
1081 * @ext: This extension
1082 * @wsi: Opaque websocket instance pointer
1083 * @reason: The reason for the call
1084 * @user: Pointer to ptr to per-session user data allocated by library
1085 * @in: Pointer used for some callback reasons
1086 * @len: Length set for some callback reasons
1088 * Each extension that is active on a particular connection receives
1089 * callbacks during the connection lifetime to allow the extension to
1090 * operate on websocket data and manage itself.
1092 * Libwebsockets takes care of allocating and freeing "user" memory for
1093 * each active extension on each connection. That is what is pointed to
1094 * by the @user parameter.
1096 * LWS_EXT_CB_CONSTRUCT: called when the server has decided to
1097 * select this extension from the list provided by the client,
1098 * just before the server will send back the handshake accepting
1099 * the connection with this extension active. This gives the
1100 * extension a chance to initialize its connection context found
1103 * LWS_EXT_CB_CLIENT_CONSTRUCT: same as LWS_EXT_CB_CONSTRUCT
1104 * but called when client is instantiating this extension. Some
1105 * extensions will work the same on client and server side and then
1106 * you can just merge handlers for both CONSTRUCTS.
1108 * LWS_EXT_CB_DESTROY: called when the connection the extension was
1109 * being used on is about to be closed and deallocated. It's the
1110 * last chance for the extension to deallocate anything it has
1111 * allocated in the user data (pointed to by @user) before the
1112 * user data is deleted. This same callback is used whether you
1113 * are in client or server instantiation context.
1115 * LWS_EXT_CB_PACKET_RX_PREPARSE: when this extension was active on
1116 * a connection, and a packet of data arrived at the connection,
1117 * it is passed to this callback to give the extension a chance to
1118 * change the data, eg, decompress it. @user is pointing to the
1119 * extension's private connection context data, @in is pointing
1120 * to an lws_tokens struct, it consists of a char * pointer called
1121 * token, and an int called token_len. At entry, these are
1122 * set to point to the received buffer and set to the content
1123 * length. If the extension will grow the content, it should use
1124 * a new buffer allocated in its private user context data and
1125 * set the pointed-to lws_tokens members to point to its buffer.
1127 * LWS_EXT_CB_PACKET_TX_PRESEND: this works the same way as
1128 * LWS_EXT_CB_PACKET_RX_PREPARSE above, except it gives the
1129 * extension a chance to change websocket data just before it will
1130 * be sent out. Using the same lws_token pointer scheme in @in,
1131 * the extension can change the buffer and the length to be
1132 * transmitted how it likes. Again if it wants to grow the
1133 * buffer safely, it should copy the data into its own buffer and
1134 * set the lws_tokens token pointer to it.
1136 * LWS_EXT_CB_ARGS_VALIDATE:
1139 lws_extension_callback_function(struct lws_context *context,
1140 const struct lws_extension *ext, struct lws *wsi,
1141 enum lws_extension_callback_reasons reason,
1142 void *user, void *in, size_t len);
1145 * struct lws_protocols - List of protocols and handlers server
1147 * @name: Protocol name that must match the one given in the client
1148 * Javascript new WebSocket(url, 'protocol') name.
1149 * @callback: The service callback used for this protocol. It allows the
1150 * service action for an entire protocol to be encapsulated in
1151 * the protocol-specific callback
1152 * @per_session_data_size: Each new connection using this protocol gets
1153 * this much memory allocated on connection establishment and
1154 * freed on connection takedown. A pointer to this per-connection
1155 * allocation is passed into the callback in the 'user' parameter
1156 * @rx_buffer_size: if you want atomic frames delivered to the callback, you
1157 * should set this to the size of the biggest legal frame that
1158 * you support. If the frame size is exceeded, there is no
1159 * error, but the buffer will spill to the user callback when
1160 * full, which you can detect by using
1161 * lws_remaining_packet_payload(). Notice that you
1162 * just talk about frame size here, the LWS_PRE
1163 * and post-padding are automatically also allocated on top.
1164 * @id: ignored by lws, but useful to contain user information bound
1165 * to the selected protocol. For example if this protocol was
1166 * called "myprotocol-v2", you might set id to 2, and the user
1167 * code that acts differently according to the version can do so by
1168 * switch (wsi->protocol->id), user code might use some bits as
1169 * capability flags based on selected protocol version, etc.
1170 * @user: User provided context data at the protocol level.
1171 * Accessible via lws_get_protocol(wsi)->user
1172 * This should not be confused with wsi->user, it is not the same.
1173 * The library completely ignores any value in here.
1175 * This structure represents one protocol supported by the server. An
1176 * array of these structures is passed to lws_create_server()
1177 * allows as many protocols as you like to be handled by one server.
1179 * The first protocol given has its callback used for user callbacks when
1180 * there is no agreed protocol name, that's true during HTTP part of the
1181 * connection and true if the client did not send a Protocol: header.
1184 struct lws_protocols {
1186 lws_callback_function *callback;
1187 size_t per_session_data_size;
1188 size_t rx_buffer_size;
1192 /* Add new things just above here ---^
1193 * This is part of the ABI, don't needlessly break compatibility */
1196 enum lws_ext_options_types {
1201 /* Add new things just above here ---^
1202 * This is part of the ABI, don't needlessly break compatibility */
1206 * struct lws_ext_options - Option arguments to the extension. These are
1207 * used in the negotiation at ws upgrade time.
1208 * The helper function lws_ext_parse_options()
1209 * uses these to generate callbacks
1211 * @name: Option name, eg, "server_no_context_takeover"
1212 * @type: What kind of args the option can take
1214 struct lws_ext_options {
1216 enum lws_ext_options_types type;
1218 /* Add new things just above here ---^
1219 * This is part of the ABI, don't needlessly break compatibility */
1222 struct lws_ext_option_arg {
1229 * struct lws_extension - An extension we know how to cope with
1231 * @name: Formal extension name, eg, "permessage-deflate"
1232 * @callback: Service callback
1233 * @client_offer: String containing exts and options client offers
1236 struct lws_extension {
1238 lws_extension_callback_function *callback;
1239 const char *client_offer;
1241 /* Add new things just above here ---^
1242 * This is part of the ABI, don't needlessly break compatibility */
1246 * The internal exts are part of the public abi
1247 * If we add more extensions, publish the callback here ------v
1250 extern int lws_extension_callback_pm_deflate(
1251 struct lws_context *context, const struct lws_extension *ext,
1252 struct lws *wsi, enum lws_extension_callback_reasons reason,
1253 void *user, void *in, size_t len);
1257 * struct lws_context_creation_info - parameters to create context with
1259 * @port: Port to listen on... you can use CONTEXT_PORT_NO_LISTEN to
1260 * suppress listening on any port, that's what you want if you are
1261 * not running a websocket server at all but just using it as a
1263 * @iface: NULL to bind the listen socket to all interfaces, or the
1264 * interface name, eg, "eth2"
1265 * @protocols: Array of structures listing supported protocols and a protocol-
1266 * specific callback for each one. The list is ended with an
1267 * entry that has a NULL callback pointer.
1268 * It's not const because we write the owning_server member
1269 * @extensions: NULL or array of lws_extension structs listing the
1270 * extensions this context supports. If you configured with
1271 * --without-extensions, you should give NULL here.
1272 * @token_limits: NULL or struct lws_token_limits pointer which is initialized
1273 * with a token length limit for each possible WSI_TOKEN_***
1274 * @ssl_cert_filepath: If libwebsockets was compiled to use ssl, and you want
1275 * to listen using SSL, set to the filepath to fetch the
1276 * server cert from, otherwise NULL for unencrypted
1277 * @ssl_private_key_filepath: filepath to private key if wanting SSL mode;
1278 * if this is set to NULL but sll_cert_filepath is set, the
1279 * OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY callback is called
1280 * to allow setting of the private key directly via openSSL
1282 * @ssl_ca_filepath: CA certificate filepath or NULL
1283 * @ssl_cipher_list: List of valid ciphers to use (eg,
1284 * "RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aNULL"
1285 * or you can leave it as NULL to get "DEFAULT"
1286 * @http_proxy_address: If non-NULL, attempts to proxy via the given address.
1287 * If proxy auth is required, use format
1288 * "username:password@server:port"
1289 * @http_proxy_port: If http_proxy_address was non-NULL, uses this port at
1291 * @gid: group id to change to after setting listen socket, or -1.
1292 * @uid: user id to change to after setting listen socket, or -1.
1293 * @options: 0, or LWS_SERVER_OPTION_... bitfields
1294 * @user: optional user pointer that can be recovered via the context
1295 * pointer using lws_context_user
1296 * @ka_time: 0 for no keepalive, otherwise apply this keepalive timeout to
1297 * all libwebsocket sockets, client or server
1298 * @ka_probes: if ka_time was nonzero, after the timeout expires how many
1299 * times to try to get a response from the peer before giving up
1300 * and killing the connection
1301 * @ka_interval: if ka_time was nonzero, how long to wait before each ka_probes
1303 * @provided_client_ssl_ctx: If non-null, swap out libwebsockets ssl
1304 * implementation for the one provided by provided_ssl_ctx.
1305 * Libwebsockets no longer is responsible for freeing the context
1306 * if this option is selected.
1307 * @max_http_header_data: The max amount of header payload that can be handled
1308 * in an http request (unrecognized header payload is dropped)
1309 * @max_http_header_pool: The max number of connections with http headers that
1310 * can be processed simultaneously (the corresponding memory is
1311 * allocated for the lifetime of the context). If the pool is
1312 * busy new incoming connections must wait for accept until one
1314 * @count_threads: how many contexts to create in an array, 0 = 1
1315 * @fd_limit_per_thread: nonzero means restrict each service thread to this
1316 * many fds, 0 means the default which is divide the process fd
1317 * limit by the number of threads.
1318 * @timeout_secs: various processes involving network roundtrips in the
1319 * library are protected from hanging forever by timeouts. If
1320 * nonzero, this member lets you set the timeout used in seconds.
1321 * Otherwise a default timeout is used.
1322 * @ecdh_curve: if NULL, defaults to initializing server with "prime256v1"
1325 struct lws_context_creation_info {
1328 const struct lws_protocols *protocols;
1329 const struct lws_extension *extensions;
1330 const struct lws_token_limits *token_limits;
1331 const char *ssl_private_key_password;
1332 const char *ssl_cert_filepath;
1333 const char *ssl_private_key_filepath;
1334 const char *ssl_ca_filepath;
1335 const char *ssl_cipher_list;
1336 const char *http_proxy_address;
1337 unsigned int http_proxy_port;
1340 unsigned int options;
1345 #ifdef LWS_OPENSSL_SUPPORT
1346 SSL_CTX *provided_client_ssl_ctx;
1347 #else /* maintain structure layout either way */
1348 void *provided_client_ssl_ctx;
1351 short max_http_header_data;
1352 short max_http_header_pool;
1354 unsigned int count_threads;
1355 unsigned int fd_limit_per_thread;
1356 unsigned int timeout_secs;
1357 const char *ecdh_curve;
1359 /* Add new things just above here ---^
1360 * This is part of the ABI, don't needlessly break compatibility
1362 * The below is to ensure later library versions with new
1363 * members added above will see 0 (default) even if the app
1364 * was not built against the newer headers.
1371 * struct lws_client_connect_info - parameters to connect with when using
1372 * lws_client_connect_via_info()
1374 * @context: lws context to create connection in
1375 * @address: remote address to connect to
1376 * @port: remote port to connect to
1377 * @ssl_connection: nonzero for ssl
1379 * @host: content of host header
1380 * @origin: content of origin header
1381 * @protocol: list of ws protocols
1382 * @ietf_version_or_minus_one: currently leave at 0 or -1
1383 * @userdata: if non-NULL, use this as wsi user_data instead of malloc it
1384 * @client_exts: array of extensions that may be used on connection
1387 struct lws_client_connect_info {
1388 struct lws_context *context;
1389 const char *address;
1395 const char *protocol;
1396 int ietf_version_or_minus_one;
1398 const struct lws_extension *client_exts;
1400 /* Add new things just above here ---^
1401 * This is part of the ABI, don't needlessly break compatibility
1403 * The below is to ensure later library versions with new
1404 * members added above will see 0 (default) even if the app
1405 * was not built against the newer headers.
1411 LWS_VISIBLE LWS_EXTERN void
1412 lws_set_log_level(int level,
1413 void (*log_emit_function)(int level, const char *line));
1415 LWS_VISIBLE LWS_EXTERN void
1416 lwsl_emit_syslog(int level, const char *line);
1418 LWS_VISIBLE LWS_EXTERN struct lws_context *
1419 lws_create_context(struct lws_context_creation_info *info);
1421 LWS_VISIBLE LWS_EXTERN int
1422 lws_set_proxy(struct lws_context *context, const char *proxy);
1424 LWS_VISIBLE LWS_EXTERN void
1425 lws_context_destroy(struct lws_context *context);
1427 LWS_VISIBLE LWS_EXTERN int
1428 lws_service(struct lws_context *context, int timeout_ms);
1430 LWS_VISIBLE LWS_EXTERN int
1431 lws_service_tsi(struct lws_context *context, int timeout_ms, int tsi);
1433 LWS_VISIBLE LWS_EXTERN void
1434 lws_cancel_service_pt(struct lws *wsi);
1436 LWS_VISIBLE LWS_EXTERN void
1437 lws_cancel_service(struct lws_context *context);
1439 LWS_VISIBLE LWS_EXTERN int
1440 lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr,
1443 LWS_VISIBLE LWS_EXTERN const unsigned char *
1444 lws_token_to_string(enum lws_token_indexes token);
1446 LWS_VISIBLE LWS_EXTERN int
1447 lws_add_http_header_by_name(struct lws *wsi, const unsigned char *name,
1448 const unsigned char *value, int length,
1449 unsigned char **p, unsigned char *end);
1450 LWS_VISIBLE LWS_EXTERN int
1451 lws_finalize_http_header(struct lws *wsi, unsigned char **p,
1452 unsigned char *end);
1453 LWS_VISIBLE LWS_EXTERN int
1454 lws_add_http_header_by_token(struct lws *wsi, enum lws_token_indexes token,
1455 const unsigned char *value, int length,
1456 unsigned char **p, unsigned char *end);
1457 LWS_VISIBLE LWS_EXTERN int
1458 lws_add_http_header_content_length(struct lws *wsi,
1459 unsigned long content_length,
1460 unsigned char **p, unsigned char *end);
1461 LWS_VISIBLE LWS_EXTERN int
1462 lws_add_http_header_status(struct lws *wsi,
1463 unsigned int code, unsigned char **p,
1464 unsigned char *end);
1466 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
1467 lws_http_transaction_completed(struct lws *wsi);
1469 #ifdef LWS_USE_LIBEV
1470 typedef void (lws_ev_signal_cb_t)(EV_P_ struct ev_signal *w, int revents);
1472 LWS_VISIBLE LWS_EXTERN int
1473 lws_ev_sigint_cfg(struct lws_context *context, int use_ev_sigint,
1474 lws_ev_signal_cb_t *cb);
1476 LWS_VISIBLE LWS_EXTERN int
1477 lws_ev_initloop(struct lws_context *context, struct ev_loop *loop, int tsi);
1480 lws_ev_sigint_cb(struct ev_loop *loop, struct ev_signal *watcher, int revents);
1481 #endif /* LWS_USE_LIBEV */
1483 #ifdef LWS_USE_LIBUV
1484 typedef void (lws_uv_signal_cb_t)(uv_loop_t *l, uv_signal_t *w, int revents);
1486 LWS_VISIBLE LWS_EXTERN int
1487 lws_uv_sigint_cfg(struct lws_context *context, int use_uv_sigint,
1488 lws_uv_signal_cb_t *cb);
1490 LWS_VISIBLE LWS_EXTERN void
1491 lws_libuv_run(const struct lws_context *context, int tsi);
1494 lws_libuv_stop(struct lws_context *context);
1496 LWS_VISIBLE LWS_EXTERN int
1497 lws_uv_initloop(struct lws_context *context, uv_loop_t *loop, uv_signal_cb cb, int tsi);
1499 LWS_VISIBLE LWS_EXTERN uv_loop_t *
1500 lws_uv_getloop(struct lws_context *context, int tsi);
1503 lws_uv_sigint_cb(uv_loop_t *loop, uv_signal_t *watcher, int revents);
1504 #endif /* LWS_USE_LIBUV */
1506 LWS_VISIBLE LWS_EXTERN int
1507 lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd);
1509 LWS_VISIBLE LWS_EXTERN int
1510 lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd,
1513 LWS_VISIBLE LWS_EXTERN void *
1514 lws_context_user(struct lws_context *context);
1516 LWS_VISIBLE LWS_EXTERN void *
1517 lws_wsi_user(struct lws *wsi);
1520 * NOTE: These public enums are part of the abi. If you want to add one,
1521 * add it at where specified so existing users are unaffected.
1523 enum pending_timeout {
1524 NO_PENDING_TIMEOUT = 0,
1525 PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE = 1,
1526 PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE = 2,
1527 PENDING_TIMEOUT_ESTABLISH_WITH_SERVER = 3,
1528 PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE = 4,
1529 PENDING_TIMEOUT_AWAITING_PING = 5,
1530 PENDING_TIMEOUT_CLOSE_ACK = 6,
1531 PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE = 7,
1532 PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE = 8,
1533 PENDING_TIMEOUT_SSL_ACCEPT = 9,
1534 PENDING_TIMEOUT_HTTP_CONTENT = 10,
1535 PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND = 11,
1536 PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE = 12,
1537 PENDING_TIMEOUT_SHUTDOWN_FLUSH = 13,
1539 /****** add new things just above ---^ ******/
1542 LWS_VISIBLE LWS_EXTERN void
1543 lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs);
1548 * When sending with websocket protocol
1552 * LWS_WRITE_CONTINUATION,
1556 * the send buffer has to have LWS_PRE bytes valid BEFORE
1557 * the buffer pointer you pass to lws_write().
1559 * This allows us to add protocol info before and after the data, and send as
1560 * one packet on the network without payload copying, for maximum efficiency.
1562 * So for example you need this kind of code to use lws_write with a
1565 * char buf[LWS_PRE + 128];
1567 * // fill your part of the buffer... for example here it's all zeros
1568 * memset(&buf[LWS_PRE], 0, 128);
1570 * lws_write(wsi, &buf[LWS_PRE], 128, LWS_WRITE_TEXT);
1572 * When sending HTTP, with
1575 * LWS_WRITE_HTTP_HEADERS
1576 * LWS_WRITE_HTTP_FINAL
1578 * there is no protocol data prepended, and don't need to take care about the
1579 * LWS_PRE bytes valid before the buffer pointer.
1581 * LWS_PRE is at least the frame nonce + 2 header + 8 length
1582 * LWS_SEND_BUFFER_POST_PADDING is deprecated, it's now 0 and can be left off.
1583 * The example apps no longer use it.
1585 * Pad LWS_PRE to the CPU word size, so that word references
1586 * to the address immediately after the padding won't cause an unaligned access
1587 * error. Sometimes for performance reasons the recommended padding is even
1588 * larger than sizeof(void *).
1591 #if !defined(LWS_SIZEOFPTR)
1592 #define LWS_SIZEOFPTR (sizeof (void *))
1594 #if !defined(u_int64_t)
1595 #define u_int64_t unsigned long long
1599 #define _LWS_PAD_SIZE 16 /* Intel recommended for best performance */
1601 #define _LWS_PAD_SIZE LWS_SIZEOFPTR /* Size of a pointer on the target arch */
1603 #define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? \
1604 ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n))
1605 #define LWS_PRE _LWS_PAD(4 + 10)
1606 /* used prior to 1.7 and retained for backward compatibility */
1607 #define LWS_SEND_BUFFER_PRE_PADDING LWS_PRE
1608 #define LWS_SEND_BUFFER_POST_PADDING 0
1610 LWS_VISIBLE LWS_EXTERN int
1611 lws_write(struct lws *wsi, unsigned char *buf, size_t len,
1612 enum lws_write_protocol protocol);
1615 * lws_close_reason - Set reason and aux data to send with Close packet
1616 * If you are going to return nonzero from the callback
1617 * requesting the connection to close, you can optionally
1618 * call this to set the reason the peer will be told if
1621 * @wsi: The websocket connection to set the close reason on
1622 * @status: A valid close status from websocket standard
1623 * @buf: NULL or buffer containing up to 124 bytes of auxiliary data
1624 * @len: Length of data in @buf to send
1626 LWS_VISIBLE LWS_EXTERN void
1627 lws_close_reason(struct lws *wsi, enum lws_close_status status,
1628 unsigned char *buf, size_t len);
1630 /* helper for case where buffer may be const */
1631 #define lws_write_http(wsi, buf, len) \
1632 lws_write(wsi, (unsigned char *)(buf), len, LWS_WRITE_HTTP)
1634 LWS_VISIBLE LWS_EXTERN int
1635 lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type,
1636 const char *other_headers, int other_headers_len);
1637 LWS_VISIBLE LWS_EXTERN int
1638 lws_serve_http_file_fragment(struct lws *wsi);
1640 LWS_VISIBLE LWS_EXTERN int
1641 lws_return_http_status(struct lws *wsi, unsigned int code,
1642 const char *html_body);
1644 LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
1645 lws_get_protocol(struct lws *wsi);
1647 LWS_VISIBLE LWS_EXTERN int
1648 lws_callback_on_writable(struct lws *wsi);
1650 LWS_VISIBLE LWS_EXTERN int
1651 lws_callback_on_writable_all_protocol(const struct lws_context *context,
1652 const struct lws_protocols *protocol);
1654 LWS_VISIBLE LWS_EXTERN int
1655 lws_callback_all_protocol(struct lws_context *context,
1656 const struct lws_protocols *protocol, int reason);
1658 LWS_VISIBLE LWS_EXTERN int
1659 lws_get_socket_fd(struct lws *wsi);
1661 LWS_VISIBLE LWS_EXTERN int
1662 lws_is_final_fragment(struct lws *wsi);
1664 LWS_VISIBLE LWS_EXTERN unsigned char
1665 lws_get_reserved_bits(struct lws *wsi);
1667 LWS_VISIBLE LWS_EXTERN int
1668 lws_rx_flow_control(struct lws *wsi, int enable);
1670 LWS_VISIBLE LWS_EXTERN void
1671 lws_rx_flow_allow_all_protocol(const struct lws_context *context,
1672 const struct lws_protocols *protocol);
1674 LWS_VISIBLE LWS_EXTERN size_t
1675 lws_remaining_packet_payload(struct lws *wsi);
1678 * if the protocol does not have any guidance, returns -1. Currently only
1679 * http2 connections get send window information from this API. But your code
1680 * should use it so it can work properly with any protocol.
1682 * If nonzero return is the amount of payload data the peer or intermediary has
1683 * reported it has buffer space for. That has NO relationship with the amount
1684 * of buffer space your OS can accept on this connection for a write action.
1686 * This number represents the maximum you could send to the peer or intermediary
1687 * on this connection right now without it complaining.
1689 * lws manages accounting for send window updates and payload writes
1690 * automatically, so this number reflects the situation at the peer or
1691 * intermediary dynamically.
1693 LWS_VISIBLE LWS_EXTERN size_t
1694 lws_get_peer_write_allowance(struct lws *wsi);
1696 /* deprecated, use lws_client_connect_via_info() */
1697 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
1698 lws_client_connect(struct lws_context *clients, const char *address,
1699 int port, int ssl_connection, const char *path,
1700 const char *host, const char *origin, const char *protocol,
1701 int ietf_version_or_minus_one) LWS_WARN_DEPRECATED;
1702 /* deprecated, use lws_client_connect_via_info() */
1703 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
1704 lws_client_connect_extended(struct lws_context *clients, const char *address,
1705 int port, int ssl_connection, const char *path,
1706 const char *host, const char *origin,
1707 const char *protocol, int ietf_version_or_minus_one,
1708 void *userdata) LWS_WARN_DEPRECATED;
1710 LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
1711 lws_client_connect_via_info(struct lws_client_connect_info * ccinfo);
1713 LWS_VISIBLE LWS_EXTERN struct lws *
1714 lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd);
1716 LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
1717 lws_canonical_hostname(struct lws_context *context);
1720 LWS_VISIBLE LWS_EXTERN void
1721 lws_get_peer_addresses(struct lws *wsi, lws_sockfd_type fd, char *name,
1722 int name_len, char *rip, int rip_len);
1724 LWS_VISIBLE LWS_EXTERN int
1725 lws_get_random(struct lws_context *context, void *buf, int len);
1727 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
1728 lws_daemonize(const char *_lock_path);
1730 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
1731 lws_send_pipe_choked(struct lws *wsi);
1733 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
1734 lws_partial_buffered(struct lws *wsi);
1736 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
1737 lws_frame_is_binary(struct lws *wsi);
1739 LWS_VISIBLE LWS_EXTERN int
1740 lws_is_ssl(struct lws *wsi);
1741 #ifdef LWS_SHA1_USE_OPENSSL_NAME
1742 #define lws_SHA1 SHA1
1744 LWS_VISIBLE LWS_EXTERN unsigned char *
1745 lws_SHA1(const unsigned char *d, size_t n, unsigned char *md);
1748 LWS_VISIBLE LWS_EXTERN int
1749 lws_b64_encode_string(const char *in, int in_len, char *out, int out_size);
1751 LWS_VISIBLE LWS_EXTERN int
1752 lws_b64_decode_string(const char *in, char *out, int out_size);
1754 LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
1755 lws_get_library_version(void);
1757 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
1758 lws_parse_uri(char *p, const char **prot, const char **ads, int *port,
1762 * Access to http headers
1764 * In lws the client http headers are temporarily malloc'd only for the
1765 * duration of the http part of the handshake. It's because in most cases,
1766 * the header content is ignored for the whole rest of the connection lifetime
1767 * and would then just be taking up space needlessly.
1769 * During LWS_CALLBACK_HTTP when the URI path is delivered is the last time
1770 * the http headers are still allocated, you can use these apis then to
1771 * look at and copy out interesting header content (cookies, etc)
1773 * Notice that the header total length reported does not include a terminating
1774 * '\0', however you must allocate for it when using the _copy apis. So the
1775 * length reported for a header containing "123" is 3, but you must provide
1776 * a buffer of length 4 so that "123\0" may be copied into it, or the copy
1777 * will fail with a nonzero return code.
1780 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
1781 lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h);
1783 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
1784 lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag_idx);
1787 * copies the whole, aggregated header, even if it was delivered in
1788 * several actual headers piece by piece
1790 LWS_VISIBLE LWS_EXTERN int
1791 lws_hdr_copy(struct lws *wsi, char *dest, int len, enum lws_token_indexes h);
1794 * copies only fragment frag_idx of a header. Normally this is only useful
1795 * to parse URI arguments like ?x=1&y=2, token index WSI_TOKEN_HTTP_URI_ARGS
1796 * fragment 0 will contain "x=1" and fragment 1 "y=2"
1798 LWS_VISIBLE LWS_EXTERN int
1799 lws_hdr_copy_fragment(struct lws *wsi, char *dest, int len,
1800 enum lws_token_indexes h, int frag_idx);
1803 /* get the active file operations struct */
1804 LWS_VISIBLE LWS_EXTERN struct lws_plat_file_ops * LWS_WARN_UNUSED_RESULT
1805 lws_get_fops(struct lws_context *context);
1807 LWS_VISIBLE LWS_EXTERN struct lws_context * LWS_WARN_UNUSED_RESULT
1808 lws_get_context(const struct lws *wsi);
1810 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
1811 lws_get_count_threads(struct lws_context *context);
1814 * Wsi-associated File Operations access helpers
1816 * Use these helper functions if you want to access a file from the perspective
1817 * of a specific wsi, which is usually the case. If you just want contextless
1818 * file access, use the fops callbacks directly with NULL wsi instead of these
1821 * If so, then it calls the platform handler or user overrides where present
1822 * (as defined in info->fops)
1824 * The advantage from all this is user code can be portable for file operations
1825 * without having to deal with differences between platforms.
1828 static LWS_INLINE lws_filefd_type LWS_WARN_UNUSED_RESULT
1829 lws_plat_file_open(struct lws *wsi, const char *filename,
1830 unsigned long *filelen, int flags)
1832 return lws_get_fops(lws_get_context(wsi))->open(wsi, filename,
1836 static LWS_INLINE int
1837 lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
1839 return lws_get_fops(lws_get_context(wsi))->close(wsi, fd);
1842 static LWS_INLINE unsigned long
1843 lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
1845 return lws_get_fops(lws_get_context(wsi))->seek_cur(wsi, fd, offset);
1848 static LWS_INLINE int LWS_WARN_UNUSED_RESULT
1849 lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
1850 unsigned char *buf, unsigned long len)
1852 return lws_get_fops(lws_get_context(wsi))->read(wsi, fd, amount, buf,
1856 static LWS_INLINE int LWS_WARN_UNUSED_RESULT
1857 lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
1858 unsigned char *buf, unsigned long len)
1860 return lws_get_fops(lws_get_context(wsi))->write(wsi, fd, amount, buf,
1865 * Note: this is not normally needed as a user api. It's provided in case it is
1866 * useful when integrating with other app poll loop service code.
1868 LWS_VISIBLE LWS_EXTERN int
1869 lws_read(struct lws *wsi, unsigned char *buf, size_t len);
1871 #ifndef LWS_NO_EXTENSIONS
1874 * There is no longer a set internal extensions table. The table is provided
1875 * by user code along with application-specific settings. See the test
1876 * client and server for how to do.
1878 static LWS_INLINE LWS_WARN_DEPRECATED const struct lws_extension *
1879 lws_get_internal_extensions() { return NULL; }
1880 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
1881 lws_ext_parse_options(const struct lws_extension *ext, struct lws *wsi,
1882 void *ext_user, const struct lws_ext_options *opts,
1883 const char *o, int len);
1887 * custom allocator support
1889 LWS_VISIBLE LWS_EXTERN void
1890 lws_set_allocator(void *(*realloc)(void *ptr, size_t size));