2 * libwebsockets - small server side websockets and web server implementation
4 * Copyright (C) 2010 - 2018 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,
21 * This is included from private-lib-core.h if LWS_ROLE_WS
24 extern struct lws_role_ops role_ops_ws;
26 #define lwsi_role_ws(wsi) (wsi->role_ops == &role_ops_ws)
28 enum lws_rx_parse_state {
35 LWS_RXPS_04_FRAME_HDR_1,
36 LWS_RXPS_04_FRAME_HDR_LEN,
37 LWS_RXPS_04_FRAME_HDR_LEN16_2,
38 LWS_RXPS_04_FRAME_HDR_LEN16_1,
39 LWS_RXPS_04_FRAME_HDR_LEN64_8,
40 LWS_RXPS_04_FRAME_HDR_LEN64_7,
41 LWS_RXPS_04_FRAME_HDR_LEN64_6,
42 LWS_RXPS_04_FRAME_HDR_LEN64_5,
43 LWS_RXPS_04_FRAME_HDR_LEN64_4,
44 LWS_RXPS_04_FRAME_HDR_LEN64_3,
45 LWS_RXPS_04_FRAME_HDR_LEN64_2,
46 LWS_RXPS_04_FRAME_HDR_LEN64_1,
48 LWS_RXPS_07_COLLECT_FRAME_KEY_1,
49 LWS_RXPS_07_COLLECT_FRAME_KEY_2,
50 LWS_RXPS_07_COLLECT_FRAME_KEY_3,
51 LWS_RXPS_07_COLLECT_FRAME_KEY_4,
53 LWS_RXPS_WS_FRAME_PAYLOAD
56 enum lws_websocket_opcodes_07 {
57 LWSWSOPC_CONTINUATION = 0,
58 LWSWSOPC_TEXT_FRAME = 1,
59 LWSWSOPC_BINARY_FRAME = 2,
61 LWSWSOPC_NOSPEC__MUX = 7,
63 /* control extensions 8+ */
70 /* this is not usable directly by user code any more, lws_close_reason() */
71 #define LWS_WRITE_CLOSE 4
73 #define ALREADY_PROCESSED_IGNORE_CHAR 1
74 #define ALREADY_PROCESSED_NO_CB 2
76 #if !defined(LWS_WITHOUT_EXTENSIONS)
77 struct lws_vhost_role_ws {
78 const struct lws_extension *extensions;
81 struct lws_pt_role_ws {
82 struct lws *rx_draining_ext_list;
83 struct lws *tx_draining_ext_list;
87 struct _lws_websocket_related {
88 unsigned char *rx_ubuf;
89 #if !defined(LWS_WITHOUT_EXTENSIONS)
90 const struct lws_extension *active_extensions[LWS_MAX_EXTENSIONS_ACTIVE];
91 void *act_ext_user[LWS_MAX_EXTENSIONS_ACTIVE];
92 struct lws *rx_draining_ext_list;
93 struct lws *tx_draining_ext_list;
96 #if defined(LWS_WITH_HTTP_PROXY)
97 struct lws_dll2_owner proxy_owner;
98 char actual_protocol[16];
99 size_t proxy_buffered;
102 /* Also used for close content... control opcode == < 128 */
103 uint8_t ping_payload_buf[128 - 3 + LWS_PRE];
106 size_t rx_packet_length;
107 uint32_t rx_ubuf_head;
108 uint32_t rx_ubuf_alloc;
110 uint8_t ping_payload_len;
114 uint8_t rsv_first_msg;
115 /* zero if no info, or length including 2-byte close code */
116 uint8_t close_in_ping_buffer_len;
118 uint8_t stashed_write_type;
119 uint8_t tx_draining_stashed_wp;
120 uint8_t ietf_spec_revision;
122 unsigned int final:1;
123 unsigned int frame_is_binary:1;
124 unsigned int all_zero_nonce:1;
125 unsigned int this_frame_masked:1;
126 unsigned int inside_frame:1; /* next write will be more of frame */
127 unsigned int clean_buffer:1; /* buffer not rewritten by extension */
128 unsigned int payload_is_close:1; /* process as PONG, but it is close */
129 unsigned int ping_pending_flag:1;
130 unsigned int continuation_possible:1;
131 unsigned int owed_a_fin:1;
132 unsigned int check_utf8:1;
133 unsigned int defeat_check_utf8:1;
134 unsigned int stashed_write_pending:1;
135 unsigned int send_check_ping:1;
136 unsigned int first_fragment:1;
137 unsigned int peer_has_sent_close:1;
138 unsigned int await_pong;
139 #if !defined(LWS_WITHOUT_EXTENSIONS)
140 unsigned int extension_data_pending:1;
141 unsigned int rx_draining_ext:1;
142 unsigned int tx_draining_ext:1;
143 unsigned int pmd_trailer_application:1;
145 uint8_t count_act_ext;
150 * we need to separately track what's happening with both compressed rx in
151 * and with inflated rx out that will be passed to the user code
154 struct lws_ext_pm_deflate_rx_ebufs {
155 struct lws_tokens eb_in;
156 struct lws_tokens eb_out;
160 lws_ws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len);
162 #if !defined(LWS_WITHOUT_EXTENSIONS)
164 lws_context_init_extensions(const struct lws_context_creation_info *info,
165 struct lws_context *context);
167 lws_any_extension_handled(struct lws *wsi, enum lws_extension_callback_reasons r,
168 void *v, size_t len);
171 lws_ext_cb_active(struct lws *wsi, int reason, void *buf, int len);
173 lws_ext_cb_all_exts(struct lws_context *context, struct lws *wsi, int reason,
178 handshake_0405(struct lws_context *context, struct lws *wsi);
180 lws_process_ws_upgrade(struct lws *wsi);
183 lws_process_ws_upgrade2(struct lws *wsi);
185 extern const struct lws_protocols lws_ws_proxy;
188 lws_server_init_wsi_for_ws(struct lws *wsi);
191 lws_sul_wsping_cb(lws_sorted_usec_list_t *sul);