Debian Codegraph @

src/websocket.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2014-2022 Joris Vink <[email protected]>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include <sys/param.h>
18 #include <sys/types.h>
19
20 #include <limits.h>
21 #include <string.h>
22
23 #include "kore.h"cxx . . $ `<file>/include/kore/kore.h`/
24 #include "http.h"cxx . . $ `<file>/include/kore/http.h`/
25 #include "sha1.h"cxx . . $ `<file>/include/kore/sha1.h`/
26
27 #define WEBSOCKET_FRAME_HDRcxx . . $ `src/websocket.c:27:9`! 2
28 #define WEBSOCKET_MASK_LENcxx . . $ `src/websocket.c:28:9`! 4
29 #define WEBSOCKET_PAYLOAD_SINGLEcxx . . $ `src/websocket.c:29:9`! 125
30 #define WEBSOCKET_PAYLOAD_EXTEND_1cxx . . $ `src/websocket.c:30:9`! 126
31 #define WEBSOCKET_PAYLOAD_EXTEND_2cxx . . $ `src/websocket.c:31:9`! 127
32 #define WEBSOCKET_OPCODE_MASKcxx . . $ `src/websocket.c:32:9`! 0x0f
33 #define WEBSOCKET_FRAME_LENGTHcxx . . $ `src/websocket.c:33:9`!(x) ((x) & ~(1 << 7))
34 #define WEBSOCKET_HAS_MASKcxx . . $ `src/websocket.c:34:9`!(x) ((x) & (1 << 7))
35 #define WEBSOCKET_HAS_FINFLAGcxx . . $ `src/websocket.c:35:9`!(x) ((x) & (1 << 7))
36 #define WEBSOCKET_RSVcxx . . $ `src/websocket.c:36:9`!(x, i) ((x) & (1 << (7 - i)))
37
38 #define WEBSOCKET_SERVER_RESPONSEcxx . . $ `src/websocket.c:38:9`! "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
39
40
41 u_int64_tcxx . . $ u_int64_t# kore_websocket_timeoutcxx . . $ kore_websocket_timeout. = 120000;
42 u_int64_tcxx . . $ u_int64_t# kore_websocket_maxframecxx . . $ kore_websocket_maxframe. = 16384;
43
44 static int websocket_recv_framecxx . . $ websocket_recv_frame(82c4d452dc2a871a).(struct netbufcxx . . $ netbuf# *);
45 static int websocket_recv_opcodecxx . . $ websocket_recv_opcode(82c4d452dc2a871a).(struct netbufcxx . . $ netbuf# *);
46 static void websocket_disconnectcxx . . $ websocket_disconnect(8475afdb72fd1ebb).(struct connectioncxx . . $ connection# *);
47 static void websocket_frame_buildcxx . . $ websocket_frame_build(c92a3e84bfd4da51).(struct kore_bufcxx . . $ kore_buf# *, u_int8_tcxx . . $ u_int8_t#,
48 const void *, size_t);
49
50 void
51 kore_websocket_handshakecxx . . $ kore_websocket_handshake(a7416651239249ec).(struct http_requestcxx . . $ http_request# *req, const char *onconnect,
52 const char *onmessage, const char *ondisconnect)
53 {
54 SHA1_CTXcxx . . $ SHA1_CTX# sctx;
55 struct kore_bufcxx . . $ kore_buf# *buf;
56 char *base64;
57 const char *key, *version;
58 u_int8_tcxx . . $ u_int8_t# digest[SHA1_DIGEST_LENGTHcxx . . $ `include/kore/sha1.h:15:9`!];
59
60 if (!http_request_headercxx . . $ http_request_header(8b4805cea1886632).(req, "sec-websocket-key", &key)) {
61 http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, HTTP_STATUS_BAD_REQUESTcxx . . $ HTTP_STATUS_BAD_REQUEST., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
62 return;
63 }
64
65 if (!http_request_headercxx . . $ http_request_header(8b4805cea1886632).(req, "sec-websocket-version", &version)) {
66 http_response_headercxx . . $ http_response_header(84119343264ef6a5).(req, "sec-websocket-version", "13");
67 http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, HTTP_STATUS_BAD_REQUESTcxx . . $ HTTP_STATUS_BAD_REQUEST., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
68 return;
69 }
70
71 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(version, "13")) {
72 http_response_headercxx . . $ http_response_header(84119343264ef6a5).(req, "sec-websocket-version", "13");
73 http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, HTTP_STATUS_BAD_REQUESTcxx . . $ HTTP_STATUS_BAD_REQUEST., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
74 return;
75 }
76
77 buf = kore_buf_alloccxx . . $ kore_buf_alloc(ae982dcc82edde78).(128);
78 kore_buf_appendfcxx . . $ kore_buf_appendf(e492ffcef53d871e).(buf, "%s%s", key, WEBSOCKET_SERVER_RESPONSEcxx . . $ `src/websocket.c:38:9`!);
79
80 SHA1Initcxx . . $ SHA1Init(8c27123f67653ebf).(&sctx);
81 SHA1Updatecxx . . $ SHA1Update(76023a93d229875a).(&sctx, buf->datacxx . . $ kore_buf#data., buf->offsetcxx . . $ kore_buf#offset.);
82 SHA1Finalcxx . . $ SHA1Final(33126880bb167b82).(digest, &sctx);
83
84 kore_buf_freecxx . . $ kore_buf_free(2648f45d13d14762).(buf);
85
86 if (!kore_base64_encodecxx . . $ kore_base64_encode(e8e709264bfeee74).(digest, sizeof(digest), &base64)) {
87 http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, HTTP_STATUS_INTERNAL_ERRORcxx . . $ HTTP_STATUS_INTERNAL_ERROR., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
88 return;
89 }
90
91 http_response_headercxx . . $ http_response_header(84119343264ef6a5).(req, "upgrade", "websocket");
92 http_response_headercxx . . $ http_response_header(84119343264ef6a5).(req, "connection", "upgrade");
93 http_response_headercxx . . $ http_response_header(84119343264ef6a5).(req, "sec-websocket-accept", base64);
94 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(base64);
95
96 req->ownercxx . . $ http_request#owner.->protocxx . . $ connection#proto. = CONN_PROTO_WEBSOCKETcxx . . $ `include/kore/kore.h:183:9`!;
97 http_responsecxx . . $ http_response(8f2daeb0fc6e2740).(req, HTTP_STATUS_SWITCHING_PROTOCOLScxx . . $ HTTP_STATUS_SWITCHING_PROTOCOLS., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
98 net_recv_resetcxx . . $ net_recv_reset(174c4f3588921332).(req->ownercxx . . $ http_request#owner., WEBSOCKET_FRAME_HDRcxx . . $ `src/websocket.c:27:9`!, websocket_recv_opcodecxx . . $ websocket_recv_opcode(82c4d452dc2a871a).);
99
100 req->ownercxx . . $ http_request#owner.->disconnectcxx . . $ connection#disconnect. = websocket_disconnectcxx . . $ websocket_disconnect(8475afdb72fd1ebb).;
101 req->ownercxx . . $ http_request#owner.->rnbcxx . . $ connection#rnb.->flagscxx . . $ netbuf#flags. &= ~NETBUF_CALL_CB_ALWAYScxx . . $ `include/kore/kore.h:115:9`!;
102
103 req->ownercxx . . $ http_request#owner.->http_timeoutcxx . . $ connection#http_timeout. = 0;
104 req->ownercxx . . $ http_request#owner.->idle_timercxx . . $ connection#idle_timer..startcxx . . $ connection#$anonymous_type_3#start. = kore_time_mscxx . . $ kore_time_ms(f708dce9a8856c70).();
105 req->ownercxx . . $ http_request#owner.->idle_timercxx . . $ connection#idle_timer..lengthcxx . . $ connection#$anonymous_type_3#length. = kore_websocket_timeoutcxx . . $ kore_websocket_timeout.;
106
107 if (onconnect != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
108 req->ownercxx . . $ http_request#owner.->ws_connectcxx . . $ connection#ws_connect. = kore_runtime_getcallcxx . . $ kore_runtime_getcall(b514b5951ac4d62f).(onconnect);
109 if (req->ownercxx . . $ http_request#owner.->ws_connectcxx . . $ connection#ws_connect. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
110 fatalcxx . . $ fatal(f6bc48f0426f26ee).("no symbol '%s' for ws_connect", onconnect);
111 } else {
112 req->ownercxx . . $ http_request#owner.->ws_connectcxx . . $ connection#ws_connect. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
113 }
114
115 if (onmessage != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
116 req->ownercxx . . $ http_request#owner.->ws_messagecxx . . $ connection#ws_message. = kore_runtime_getcallcxx . . $ kore_runtime_getcall(b514b5951ac4d62f).(onmessage);
117 if (req->ownercxx . . $ http_request#owner.->ws_messagecxx . . $ connection#ws_message. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
118 fatalcxx . . $ fatal(f6bc48f0426f26ee).("no symbol '%s' for ws_message", onmessage);
119 } else {
120 req->ownercxx . . $ http_request#owner.->ws_messagecxx . . $ connection#ws_message. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
121 }
122
123 if (ondisconnect != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
124 req->ownercxx . . $ http_request#owner.->ws_disconnectcxx . . $ connection#ws_disconnect. = kore_runtime_getcallcxx . . $ kore_runtime_getcall(b514b5951ac4d62f).(ondisconnect);
125 if (req->ownercxx . . $ http_request#owner.->ws_disconnectcxx . . $ connection#ws_disconnect. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
126 fatalcxx . . $ fatal(f6bc48f0426f26ee).("no symbol '%s' for ws_disconnect", ondisconnect);
127 } else {
128 req->ownercxx . . $ http_request#owner.->ws_disconnectcxx . . $ connection#ws_disconnect. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
129 }
130
131 if (req->ownercxx . . $ http_request#owner.->ws_connectcxx . . $ connection#ws_connect. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
132 kore_runtime_wsconnectcxx . . $ kore_runtime_wsconnect(7abb6533877ecf95).(req->ownercxx . . $ http_request#owner.->ws_connectcxx . . $ connection#ws_connect., req->ownercxx . . $ http_request#owner.);
133 }
134
135 int
136 kore_websocket_send_cleancxx . . $ kore_websocket_send_clean(82c4d452dc2a871a).(struct netbufcxx . . $ netbuf# *nb)
137 {
138 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(nb->bufcxx . . $ netbuf#buf.);
139 return (0);
140 }
141
142 void
143 kore_websocket_sendcxx . . $ kore_websocket_send(8a6abe24d8402bf3).(struct connectioncxx . . $ connection# *c, u_int8_tcxx . . $ u_int8_t# op, const void *data,
144 size_t len)
145 {
146 struct kore_bufcxx . . $ kore_buf# frame;
147
148 kore_buf_initcxx . . $ kore_buf_init(bd90e0817a56138f).(&frame, len);
149 websocket_frame_buildcxx . . $ websocket_frame_build(c92a3e84bfd4da51).(&frame, op, data, len);
150 net_send_streamcxx . . $ net_send_stream(d6d8aac503cfaaf3).(c, frame.datacxx . . $ kore_buf#data., frame.offsetcxx . . $ kore_buf#offset.,
151 kore_websocket_send_cleancxx . . $ kore_websocket_send_clean(82c4d452dc2a871a)., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
152
153 /* net_send_stream() takes over the buffer data pointer. */
154 frame.datacxx . . $ kore_buf#data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
155 kore_buf_cleanupcxx . . $ kore_buf_cleanup(2648f45d13d14762).(&frame);
156
157 net_send_flushcxx . . $ net_send_flush(d3ce87d3c6fa6963).(c);
158 }
159
160 void
161 kore_websocket_broadcastcxx . . $ kore_websocket_broadcast(ffc8ad2cdc7cda60).(struct connectioncxx . . $ connection# *src, u_int8_tcxx . . $ u_int8_t# op, const void *data,
162 size_t len, int scope)
163 {
164 struct connectioncxx . . $ connection# *c;
165 struct kore_bufcxx . . $ kore_buf# *frame;
166
167 frame = kore_buf_alloccxx . . $ kore_buf_alloc(ae982dcc82edde78).(len);
168 websocket_frame_buildcxx . . $ websocket_frame_build(c92a3e84bfd4da51).(frame, op, data, len);
169
170 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(c, &connections, list) {
171 if (c != src && c->protocxx . . $ connection#proto. == CONN_PROTO_WEBSOCKETcxx . . $ `include/kore/kore.h:183:9`!) {
172 net_send_queuecxx . . $ net_send_queue(afc888e1ea7fb691).(c, frame->datacxx . . $ kore_buf#data., frame->offsetcxx . . $ kore_buf#offset.);
173 net_send_flushcxx . . $ net_send_flush(d3ce87d3c6fa6963).(c);
174 }
175 }
176
177 if (scope == WEBSOCKET_BROADCAST_GLOBALcxx . . $ `include/kore/kore.h:209:9`!) {
178 kore_msg_sendcxx . . $ kore_msg_send(6afaa3cccbe95a50).(KORE_MSG_WORKER_ALLcxx . . $ `include/kore/kore.h:680:9`!,
179 KORE_MSG_WEBSOCKETcxx . . $ `include/kore/kore.h:660:9`!, frame->datacxx . . $ kore_buf#data., frame->offsetcxx . . $ kore_buf#offset.);
180 }
181
182 kore_buf_freecxx . . $ kore_buf_free(2648f45d13d14762).(frame);
183 }
184
185 static void
186 websocket_frame_buildcxx . . $ websocket_frame_build(c92a3e84bfd4da51).(struct kore_bufcxx . . $ kore_buf# *frame, u_int8_tcxx . . $ u_int8_t# op, const void *data,
187 size_t len)
188 {
189 u_int8_tcxx . . $ u_int8_t# len_1;
190 u_int16_tcxx . . $ u_int16_t# len16;
191 u_int64_tcxx . . $ u_int64_t# len64;
192
193 if (len > WEBSOCKET_PAYLOAD_SINGLEcxx . . $ `src/websocket.c:29:9`!) {
194 if (len <= USHRT_MAXcxx . . $ `<external>/67164224788392828/limits.h:113:10`!)
195 len_1 = WEBSOCKET_PAYLOAD_EXTEND_1cxx . . $ `src/websocket.c:30:9`!;
196 else
197 len_1 = WEBSOCKET_PAYLOAD_EXTEND_2cxx . . $ `src/websocket.c:31:9`!;
198 } else {
199 len_1 = len;
200 }
201
202 op |= (1 << 7);
203 kore_buf_appendcxx . . $ kore_buf_append(4909ebf68ec24f4d).(frame, &op, sizeof(op));
204
205 len_1 &= ~(1 << 7);
206 kore_buf_appendcxx . . $ kore_buf_append(4909ebf68ec24f4d).(frame, &len_1, sizeof(len_1));
207
208 if (len_1 > WEBSOCKET_PAYLOAD_SINGLEcxx . . $ `src/websocket.c:29:9`!) {
209 switch (len_1) {
210 case WEBSOCKET_PAYLOAD_EXTEND_1cxx . . $ `src/websocket.c:30:9`!:
211 net_write16cxx . . $ net_write16(5f425e2ac950790c).((u_int8_tcxx . . $ u_int8_t# *)&len16, len);
212 kore_buf_appendcxx . . $ kore_buf_append(4909ebf68ec24f4d).(frame, &len16, sizeof(len16));
213 break;
214 case WEBSOCKET_PAYLOAD_EXTEND_2cxx . . $ `src/websocket.c:31:9`!:
215 net_write64cxx . . $ net_write64(6165b45f45ef689c).((u_int8_tcxx . . $ u_int8_t# *)&len64, len);
216 kore_buf_appendcxx . . $ kore_buf_append(4909ebf68ec24f4d).(frame, &len64, sizeof(len64));
217 break;
218 }
219 }
220
221 if (data != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && len > 0)
222 kore_buf_appendcxx . . $ kore_buf_append(4909ebf68ec24f4d).(frame, data, len);
223 }
224
225 static int
226 websocket_recv_opcodecxx . . $ websocket_recv_opcode(82c4d452dc2a871a).(struct netbufcxx . . $ netbuf# *nb)
227 {
228 u_int8_tcxx . . $ u_int8_t# op, len;
229 struct connectioncxx . . $ connection# *c = nb->ownercxx . . $ netbuf#owner.;
230
231 if (!WEBSOCKET_HAS_MASKcxx . . $ `src/websocket.c:34:9`!(nb->buf[1]))
232 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
233
234 if (WEBSOCKET_RSVcxx . . $ `src/websocket.c:36:9`!(nb->buf[0], 1) || WEBSOCKET_RSVcxx . . $ `src/websocket.c:36:9`!(nb->buf[0], 2) ||
235 WEBSOCKET_RSVcxx . . $ `src/websocket.c:36:9`!(nb->buf[0], 3))
236 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
237
238 len = WEBSOCKET_FRAME_LENGTHcxx . . $ `src/websocket.c:33:9`!(nb->buf[1]);
239
240 op = nb->bufcxx . . $ netbuf#buf.[0] & WEBSOCKET_OPCODE_MASKcxx . . $ `src/websocket.c:32:9`!;
241 switch (op) {
242 case WEBSOCKET_OP_CONTcxx . . $ `include/kore/kore.h:201:9`!:
243 case WEBSOCKET_OP_TEXTcxx . . $ `include/kore/kore.h:202:9`!:
244 case WEBSOCKET_OP_BINARYcxx . . $ `include/kore/kore.h:203:9`!:
245 break;
246 case WEBSOCKET_OP_CLOSEcxx . . $ `include/kore/kore.h:204:9`!:
247 case WEBSOCKET_OP_PINGcxx . . $ `include/kore/kore.h:205:9`!:
248 case WEBSOCKET_OP_PONGcxx . . $ `include/kore/kore.h:206:9`!:
249 if (len > WEBSOCKET_PAYLOAD_SINGLEcxx . . $ `src/websocket.c:29:9`! ||
250 !WEBSOCKET_HAS_FINFLAGcxx . . $ `src/websocket.c:35:9`!(nb->buf[0]))
251 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
252 break;
253 default:
254 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
255 }
256
257 switch (len) {
258 case WEBSOCKET_PAYLOAD_EXTEND_1cxx . . $ `src/websocket.c:30:9`!:
259 len += sizeof(u_int16_tcxx . . $ u_int16_t#);
260 break;
261 case WEBSOCKET_PAYLOAD_EXTEND_2cxx . . $ `src/websocket.c:31:9`!:
262 len += sizeof(u_int64_tcxx . . $ u_int64_t#);
263 break;
264 }
265
266 len += WEBSOCKET_MASK_LENcxx . . $ `src/websocket.c:28:9`!;
267 net_recv_expandcxx . . $ net_recv_expand(174c4f3588921332).(c, len, websocket_recv_framecxx . . $ websocket_recv_frame(82c4d452dc2a871a).);
268
269 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
270 }
271
272 static int
273 websocket_recv_framecxx . . $ websocket_recv_frame(82c4d452dc2a871a).(struct netbufcxx . . $ netbuf# *nb)
274 {
275 struct connectioncxx . . $ connection# *c;
276 int ret;
277 u_int64_tcxx . . $ u_int64_t# len, i, total;
278 u_int8_tcxx . . $ u_int8_t# op, moff, extra;
279
280 c = nb->ownercxx . . $ netbuf#owner.;
281 op = nb->bufcxx . . $ netbuf#buf.[0] & WEBSOCKET_OPCODE_MASKcxx . . $ `src/websocket.c:32:9`!;
282 len = WEBSOCKET_FRAME_LENGTHcxx . . $ `src/websocket.c:33:9`!(nb->buf[1]);
283
284 switch (len) {
285 case WEBSOCKET_PAYLOAD_EXTEND_1cxx . . $ `src/websocket.c:30:9`!:
286 moff = 4;
287 extra = sizeof(u_int16_tcxx . . $ u_int16_t#);
288 len = net_read16cxx . . $ net_read16(e56f59a1c9f445b3).(&nb->bufcxx . . $ netbuf#buf.[2]);
289 break;
290 case WEBSOCKET_PAYLOAD_EXTEND_2cxx . . $ `src/websocket.c:31:9`!:
291 moff = 10;
292 extra = sizeof(u_int64_tcxx . . $ u_int64_t#);
293 len = net_read64cxx . . $ net_read64(71a4eab05fe48ca1).(&nb->bufcxx . . $ netbuf#buf.[2]);
294 break;
295 default:
296 extra = 0;
297 moff = 2;
298 break;
299 }
300
301 if (len > kore_websocket_maxframecxx . . $ kore_websocket_maxframe.)
302 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
303
304 extra += WEBSOCKET_FRAME_HDRcxx . . $ `src/websocket.c:27:9`!;
305 total = len + extra + WEBSOCKET_MASK_LENcxx . . $ `src/websocket.c:28:9`!;
306 if (total > nb->b_lencxx . . $ netbuf#b_len.) {
307 total -= nb->b_lencxx . . $ netbuf#b_len.;
308 net_recv_expandcxx . . $ net_recv_expand(174c4f3588921332).(c, total, websocket_recv_framecxx . . $ websocket_recv_frame(82c4d452dc2a871a).);
309 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
310 }
311
312 if (total != nb->b_lencxx . . $ netbuf#b_len.)
313 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
314
315 for (i = 0; i < len; i++)
316 nb->bufcxx . . $ netbuf#buf.[moff + 4 + i] ^= nb->bufcxx . . $ netbuf#buf.[moff + (i % 4)];
317
318 ret = KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!;
319 switch (op) {
320 case WEBSOCKET_OP_PONGcxx . . $ `include/kore/kore.h:206:9`!:
321 break;
322 case WEBSOCKET_OP_CONTcxx . . $ `include/kore/kore.h:201:9`!:
323 ret = KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!;
324 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_ERRcxx . . $ `<external>/6168640806541382331/syslog.h:54:9`!,
325 "%p: we do not support op 0x%02x yet", (void *)c, op);
326 break;
327 case WEBSOCKET_OP_TEXTcxx . . $ `include/kore/kore.h:202:9`!:
328 case WEBSOCKET_OP_BINARYcxx . . $ `include/kore/kore.h:203:9`!:
329 if (c->ws_messagecxx . . $ connection#ws_message. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
330 kore_runtime_wsmessagecxx . . $ kore_runtime_wsmessage(d015b3a583ab822f).(c->ws_messagecxx . . $ connection#ws_message.,
331 c, op, &nb->bufcxx . . $ netbuf#buf.[moff + 4], len);
332 }
333 break;
334 case WEBSOCKET_OP_CLOSEcxx . . $ `include/kore/kore.h:204:9`!:
335 c->evtcxx . . $ connection#evt..flagscxx . . $ kore_event#flags. &= ~KORE_EVENT_READcxx . . $ `include/kore/kore.h:187:9`!;
336 if (!(c->flagscxx . . $ connection#flags. & CONN_WS_CLOSE_SENTcxx . . $ `include/kore/kore.h:193:9`!)) {
337 c->flagscxx . . $ connection#flags. |= CONN_WS_CLOSE_SENTcxx . . $ `include/kore/kore.h:193:9`!;
338 kore_websocket_sendcxx . . $ kore_websocket_send(8a6abe24d8402bf3).(c, WEBSOCKET_OP_CLOSEcxx . . $ `include/kore/kore.h:204:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
339 }
340 kore_connection_disconnectcxx . . $ kore_connection_disconnect(8475afdb72fd1ebb).(c);
341 break;
342 case WEBSOCKET_OP_PINGcxx . . $ `include/kore/kore.h:205:9`!:
343 kore_websocket_sendcxx . . $ kore_websocket_send(8a6abe24d8402bf3).(c, WEBSOCKET_OP_PONGcxx . . $ `include/kore/kore.h:206:9`!,
344 &nb->bufcxx . . $ netbuf#buf.[moff + 4], len);
345 break;
346 default:
347 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
348 }
349
350 net_recv_resetcxx . . $ net_recv_reset(174c4f3588921332).(c, WEBSOCKET_FRAME_HDRcxx . . $ `src/websocket.c:27:9`!, websocket_recv_opcodecxx . . $ websocket_recv_opcode(82c4d452dc2a871a).);
351
352 return (ret);
353 }
354
355 static void
356 websocket_disconnectcxx . . $ websocket_disconnect(8475afdb72fd1ebb).(struct connectioncxx . . $ connection# *c)
357 {
358 if (c->ws_disconnectcxx . . $ connection#ws_disconnect. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
359 kore_runtime_wsdisconnectcxx . . $ kore_runtime_wsdisconnect(7abb6533877ecf95).(c->ws_disconnectcxx . . $ connection#ws_disconnect., c);
360
361 if (!(c->flagscxx . . $ connection#flags. & CONN_WS_CLOSE_SENTcxx . . $ `include/kore/kore.h:193:9`!)) {
362 c->flagscxx . . $ connection#flags. |= CONN_WS_CLOSE_SENTcxx . . $ `include/kore/kore.h:193:9`!;
363 c->evtcxx . . $ connection#evt..flagscxx . . $ kore_event#flags. &= ~KORE_EVENT_READcxx . . $ `include/kore/kore.h:187:9`!;
364 kore_websocket_sendcxx . . $ kore_websocket_send(8a6abe24d8402bf3).(c, WEBSOCKET_OP_CLOSEcxx . . $ `include/kore/kore.h:204:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
365 }
366 }