1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-07 14:03:14 +02:00

JSON-RPC over Websockets: Fix bug with >64Kb responses.

Eg if there are 10.000 users online and you do user.list.
The old websocket framing assumed no response was >64Kb.

This also creates a new function websocket_create_packet_ex()
This commit is contained in:
Bram Matthys
2023-01-04 13:07:10 +01:00
parent d6a3db4ad2
commit b33628b765
6 changed files with 66 additions and 13 deletions
+8 -3
View File
@@ -431,11 +431,16 @@ void rpc_sendto(Client *client, const char *buf, int len)
if (MyConnect(client) && IsRPC(client) && WSU(client) && WSU(client)->handshake_completed)
{
/* Websocket */
static char utf8buf[65535]; // TODO: dynamic!!!
char *newbuf = unrl_utf8_make_valid(buf, utf8buf, sizeof(utf8buf), 1);
int utf8bufsize = len*2 + 16;
char *utf8buf = safe_alloc(utf8bufsize);
char *newbuf = unrl_utf8_make_valid(buf, utf8buf, utf8bufsize, 1);
int newlen = strlen(newbuf);
websocket_create_packet(WSOP_TEXT, &newbuf, &newlen);
int ws_sendbufsize = newlen + 64 + ((newlen / 1024) * 64); // some random magic
char *ws_sendbuf = safe_alloc(ws_sendbufsize);
websocket_create_packet_ex(WSOP_TEXT, &newbuf, &newlen, ws_sendbuf, ws_sendbufsize);
dbuf_put(&client->local->sendQ, newbuf, newlen);
safe_free(ws_sendbuf);
safe_free(utf8buf);
} else {
/* Unix domain socket or HTTP */
dbuf_put(&client->local->sendQ, buf, len);