Skip to content

Commit

Permalink
Start sending d-cookie in WebSocket requests.
Browse files Browse the repository at this point in the history
Started being required by Slack around 2023-09-19.

Signed-off-by: Kristian Amlie <kristian.amlie@northern.tech>
  • Loading branch information
Kristian Amlie committed Sep 19, 2023
1 parent d276ba4 commit 256c0ec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions purple-websocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ static void ws_connect_cb(gpointer data, gint source, const gchar *error_message
}

PurpleWebsocket *purple_websocket_connect(PurpleAccount *account,
const char *url, const char *protocol,
const char *url, const char *protocol, const char *cookies,
PurpleWebsocketCallback callback, void *user_data) {
gboolean ssl = FALSE;

Expand Down Expand Up @@ -510,9 +510,10 @@ PurpleWebsocket *purple_websocket_connect(PurpleAccount *account,
GET /%s HTTP/1.1\r\n\
Host: %s\r\n\
Connection: Upgrade\r\n\
Cookie: %s\r\n\
Upgrade: websocket\r\n\
Sec-WebSocket-Key: %s\r\n\
Sec-WebSocket-Version: 13\r\n", path, host, ws->key);
Sec-WebSocket-Version: 13\r\n", path, host, cookies, ws->key);
if (protocol)
g_string_append_printf(request, "Sec-WebSocket-Protocol: %s\r\n", protocol);
g_string_append(request, "\r\n");
Expand Down
2 changes: 1 addition & 1 deletion purple-websocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ typedef enum _PurpleWebsocketOp {

typedef void (*PurpleWebsocketCallback)(PurpleWebsocket *ws, gpointer user_data, PurpleWebsocketOp op, const guchar *msg, size_t len);

PurpleWebsocket *purple_websocket_connect(PurpleAccount *account, const char *url, const char *protocol, PurpleWebsocketCallback callback, void *user_data);
PurpleWebsocket *purple_websocket_connect(PurpleAccount *account, const char *url, const char *protocol, const char *cookies, PurpleWebsocketCallback callback, void *user_data);
void purple_websocket_send(PurpleWebsocket *ws, PurpleWebsocketOp op, const guchar *msg, size_t len);
void purple_websocket_abort(PurpleWebsocket *ws);

Expand Down
9 changes: 8 additions & 1 deletion slack-rtm.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,15 @@ static gboolean rtm_connect_cb(SlackAccount *sa, gpointer data, json_value *json
slack_blist_init(sa);

slack_login_step(sa);

size_t cookie_size = strlen("d=") + strlen(sa->d_cookie) + 1;
char *cookie = malloc(cookie_size);
snprintf(cookie, cookie_size, "d=%s", sa->d_cookie);

purple_debug_info("slack", "RTM URL: %s\n", url);
sa->rtm = purple_websocket_connect(sa->account, url, NULL, rtm_cb, sa);
sa->rtm = purple_websocket_connect(sa->account, url, NULL, cookie, rtm_cb, sa);

free(cookie);

sa->ping_timer = purple_timeout_add_seconds(60, ping_timer, sa);
return FALSE;
Expand Down

0 comments on commit 256c0ec

Please sign in to comment.