private.h: rename to contain dir
[platform/upstream/libwebsockets.git] / lib / roles / ws / private-lib-roles-ws.h
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010 - 2018 Andy Green <andy@warmcat.com>
5  *
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.
10  *
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.
15  *
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,
19  *  MA  02110-1301  USA
20  *
21  *  This is included from private-lib-core.h if LWS_ROLE_WS
22  */
23
24 extern struct lws_role_ops role_ops_ws;
25
26 #define lwsi_role_ws(wsi) (wsi->role_ops == &role_ops_ws)
27
28 enum lws_rx_parse_state {
29         LWS_RXPS_NEW,
30
31         LWS_RXPS_04_mask_1,
32         LWS_RXPS_04_mask_2,
33         LWS_RXPS_04_mask_3,
34
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,
47
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,
52
53         LWS_RXPS_WS_FRAME_PAYLOAD
54 };
55
56 enum lws_websocket_opcodes_07 {
57         LWSWSOPC_CONTINUATION = 0,
58         LWSWSOPC_TEXT_FRAME = 1,
59         LWSWSOPC_BINARY_FRAME = 2,
60
61         LWSWSOPC_NOSPEC__MUX = 7,
62
63         /* control extensions 8+ */
64
65         LWSWSOPC_CLOSE = 8,
66         LWSWSOPC_PING = 9,
67         LWSWSOPC_PONG = 0xa,
68 };
69
70 /* this is not usable directly by user code any more, lws_close_reason() */
71 #define LWS_WRITE_CLOSE 4
72
73 #define ALREADY_PROCESSED_IGNORE_CHAR 1
74 #define ALREADY_PROCESSED_NO_CB 2
75
76 #if !defined(LWS_WITHOUT_EXTENSIONS)
77 struct lws_vhost_role_ws {
78         const struct lws_extension *extensions;
79 };
80
81 struct lws_pt_role_ws {
82         struct lws *rx_draining_ext_list;
83         struct lws *tx_draining_ext_list;
84 };
85 #endif
86
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;
94 #endif
95
96 #if defined(LWS_WITH_HTTP_PROXY)
97         struct lws_dll2_owner proxy_owner;
98         char actual_protocol[16];
99         size_t proxy_buffered;
100 #endif
101
102         /* Also used for close content... control opcode == < 128 */
103         uint8_t ping_payload_buf[128 - 3 + LWS_PRE];
104         uint8_t mask[4];
105
106         size_t rx_packet_length;
107         uint32_t rx_ubuf_head;
108         uint32_t rx_ubuf_alloc;
109
110         uint8_t ping_payload_len;
111         uint8_t mask_idx;
112         uint8_t opcode;
113         uint8_t rsv;
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;
117         uint8_t utf8;
118         uint8_t stashed_write_type;
119         uint8_t tx_draining_stashed_wp;
120         uint8_t ietf_spec_revision;
121
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;
144
145         uint8_t count_act_ext;
146 #endif
147 };
148
149 /*
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
152  */
153
154 struct lws_ext_pm_deflate_rx_ebufs {
155         struct lws_tokens eb_in;
156         struct lws_tokens eb_out;
157 };
158
159 int
160 lws_ws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len);
161
162 #if !defined(LWS_WITHOUT_EXTENSIONS)
163 LWS_VISIBLE void
164 lws_context_init_extensions(const struct lws_context_creation_info *info,
165                             struct lws_context *context);
166 LWS_EXTERN int
167 lws_any_extension_handled(struct lws *wsi, enum lws_extension_callback_reasons r,
168                           void *v, size_t len);
169
170 LWS_EXTERN int
171 lws_ext_cb_active(struct lws *wsi, int reason, void *buf, int len);
172 LWS_EXTERN int
173 lws_ext_cb_all_exts(struct lws_context *context, struct lws *wsi, int reason,
174                     void *arg, int len);
175 #endif
176
177 int
178 handshake_0405(struct lws_context *context, struct lws *wsi);
179 int
180 lws_process_ws_upgrade(struct lws *wsi);
181
182 int
183 lws_process_ws_upgrade2(struct lws *wsi);
184
185 extern const struct lws_protocols lws_ws_proxy;
186
187 int
188 lws_server_init_wsi_for_ws(struct lws *wsi);
189
190 void
191 lws_sul_wsping_cb(lws_sorted_usec_list_t *sul);