summaryrefslogtreecommitdiff
path: root/src/plugins/relay/relay-websocket.h
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2024-01-14 10:24:41 +0100
committerSébastien Helleu <flashcode@flashtux.org>2024-02-01 21:38:53 +0100
commit6cfb31c306b9deb120a9fb5c564a1456a72af665 (patch)
tree44b1cc7940b852d4fd215a5b269365b9652ac3ba /src/plugins/relay/relay-websocket.h
parent8971fc069a1c1a9e8c3f6fa1f83e64a50b2876c1 (diff)
downloadweechat-6cfb31c306b9deb120a9fb5c564a1456a72af665.zip
relay: add support of websocket extension "permessage-deflate" (closes #1549)
This extension is used to compress and decompress websocket frames (using the DEFLATE algorithm, with zlib).
Diffstat (limited to 'src/plugins/relay/relay-websocket.h')
-rw-r--r--src/plugins/relay/relay-websocket.h55
1 files changed, 46 insertions, 9 deletions
diff --git a/src/plugins/relay/relay-websocket.h b/src/plugins/relay/relay-websocket.h
index 18e2002fb..6e48569fd 100644
--- a/src/plugins/relay/relay-websocket.h
+++ b/src/plugins/relay/relay-websocket.h
@@ -20,6 +20,10 @@
#ifndef WEECHAT_PLUGIN_RELAY_WEBSOCKET_H
#define WEECHAT_PLUGIN_RELAY_WEBSOCKET_H
+#include "relay.h"
+
+#include <zlib.h>
+
#define WEBSOCKET_FRAME_OPCODE_CONTINUATION 0x00
#define WEBSOCKET_FRAME_OPCODE_TEXT 0x01
#define WEBSOCKET_FRAME_OPCODE_BINARY 0x02
@@ -27,17 +31,50 @@
#define WEBSOCKET_FRAME_OPCODE_PING 0x09
#define WEBSOCKET_FRAME_OPCODE_PONG 0x0A
-extern int relay_websocket_is_valid_http_get (struct t_relay_client *client,
+struct t_relay_client;
+struct t_relay_http_request;
+
+struct t_relay_websocket_deflate
+{
+ int enabled; /* 1 if permessage-deflate is enabled*/
+ int server_context_takeover; /* context takeover for server */
+ int client_context_takeover; /* context takeover for client */
+ int window_bits_deflate; /* window bits for server (comp.) */
+ /* ("server_max_window_bits") */
+ int window_bits_inflate; /* window bits for client (decomp.) */
+ /* ("client_max_window_bits") */
+ z_stream *strm_deflate; /* stream for deflate (compression) */
+ z_stream *strm_inflate; /* stream for inflate (decompression)*/
+};
+
+struct t_relay_websocket_frame
+{
+ int opcode; /* frame opcode */
+ int payload_size; /* size of payload */
+ char *payload; /* payload */
+};
+
+extern struct t_relay_websocket_deflate *relay_websocket_deflate_alloc ();
+extern int relay_websocket_deflate_init_stream_deflate (struct t_relay_websocket_deflate *ws_deflate);
+extern int relay_websocket_deflate_init_stream_inflate (struct t_relay_websocket_deflate *ws_deflate);
+extern void relay_websocket_deflate_free (struct t_relay_websocket_deflate *ws_deflate);
+extern int relay_websocket_is_valid_http_get (enum t_relay_protocol protocol,
const char *message);
-extern int relay_websocket_client_handshake_valid (struct t_relay_client *client);
-extern char *relay_websocket_build_handshake (struct t_relay_client *client);
-extern int relay_websocket_decode_frame (const unsigned char *buffer,
+extern int relay_websocket_client_handshake_valid (struct t_relay_http_request *request);
+extern void relay_websocket_parse_extensions (const char *extensions,
+ struct t_relay_websocket_deflate *ws_deflate);
+extern char *relay_websocket_build_handshake (struct t_relay_http_request *request);
+extern int relay_websocket_decode_frame (struct t_relay_client *client,
+ const unsigned char *buffer,
unsigned long long length,
- unsigned char *decoded,
- unsigned long long *decoded_length);
-extern char *relay_websocket_encode_frame (int opcode,
- const char *buffer,
- unsigned long long length,
+ struct t_relay_websocket_frame **frames,
+ int *num_frames);
+extern char *relay_websocket_encode_frame (struct t_relay_client *client,
+ int opcode,
+ const char *payload,
+ unsigned long long payload_size,
unsigned long long *length_frame);
+extern void relay_websocket_deflate_print_log (struct t_relay_websocket_deflate *ws_deflate,
+ const char *prefix);
#endif /* WEECHAT_PLUGIN_RELAY_WEBSOCKET_H */