summaryrefslogtreecommitdiff
path: root/lib/ws.h
diff options
context:
space:
mode:
authorStefan Eissing <stefan@eissing.org>2023-04-18 15:02:34 +0200
committerDaniel Stenberg <daniel@haxx.se>2023-04-25 23:16:51 +0200
commit930c00c25988a65882fb9b120af66f08cb93e78b (patch)
tree9bdf200c91288eee8f6a00e48927b552e84c72fc /lib/ws.h
parent3f0b81c112ebfe826ed702a2987cc5e32082a7a6 (diff)
downloadcurl-930c00c25988a65882fb9b120af66f08cb93e78b.tar.gz
Websocket en-/decoding
- state is fully kept at connection, since curl_ws_send() and curl_ws_rec() have lifetime beyond usual transfers - no more limit on frame sizes Reported-by: simplerobot on github Fixes #10962 Closes #10999
Diffstat (limited to 'lib/ws.h')
-rw-r--r--lib/ws.h52
1 files changed, 34 insertions, 18 deletions
diff --git a/lib/ws.h b/lib/ws.h
index 176dda470..0308a4254 100644
--- a/lib/ws.h
+++ b/lib/ws.h
@@ -33,28 +33,44 @@
#define REQTYPE struct dynbuf
#endif
-/* this is the largest single fragment size we support */
-#define MAX_WS_SIZE 65535
+/* a client-side WS frame decoder, parsing frame headers and
+ * payload, keeping track of current position and stats */
+enum ws_dec_state {
+ WS_DEC_INIT,
+ WS_DEC_HEAD,
+ WS_DEC_PAYLOAD
+};
-/* part of 'struct HTTP', when used in the 'struct SingleRequest' in the
- Curl_easy struct */
-struct websocket {
- bool contfragment; /* set TRUE if the previous fragment sent was not final */
- unsigned char mask[4]; /* 32 bit mask for this connection */
- struct Curl_easy *data; /* used for write callback handling */
- struct dynbuf buf;
- size_t usedbuf; /* number of leading bytes in 'buf' the most recent complete
- websocket frame uses */
- struct curl_ws_frame frame; /* the struct used for frame state */
- size_t stillblen; /* number of bytes left in the buffer to deliver in
- the next curl_ws_recv() call */
- const char *stillb; /* the stillblen pending bytes are here */
- curl_off_t sleft; /* outstanding number of payload bytes left to send */
+struct ws_decoder {
+ int frame_age; /* zero */
+ int frame_flags; /* See the CURLWS_* defines */
+ curl_off_t payload_offset; /* the offset parsing is at */
+ curl_off_t payload_len;
+ unsigned char head[10];
+ int head_len, head_total;
+ enum ws_dec_state state;
+};
+
+/* a client-side WS frame encoder, generating frame headers and
+ * converting payloads, tracking remaining data in current frame */
+struct ws_encoder {
+ curl_off_t payload_len; /* payload length of current frame */
+ curl_off_t payload_remain; /* remaining payload of current */
unsigned int xori; /* xor index */
+ unsigned char mask[4]; /* 32 bit mask for this connection */
+ unsigned char firstbyte; /* first byte of frame we encode */
+ bool contfragment; /* set TRUE if the previous fragment sent was not final */
};
-struct ws_conn {
- struct dynbuf early; /* data already read when switching to ws */
+/* A websocket connection with en- and decoder that treat frames
+ * and keep track of boundaries. */
+struct websocket {
+ struct Curl_easy *data; /* used for write callback handling */
+ struct ws_decoder dec; /* decode of we frames */
+ struct ws_encoder enc; /* decode of we frames */
+ struct bufq recvbuf; /* raw data from the server */
+ struct bufq sendbuf; /* raw data to be sent to the server */
+ struct curl_ws_frame frame; /* the current WS FRAME received */
};
CURLcode Curl_ws_request(struct Curl_easy *data, REQTYPE *req);