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 20, 2023
1 parent d276ba4 commit 36d12b3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion 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 @@ -515,6 +515,8 @@ Sec-WebSocket-Key: %s\r\n\
Sec-WebSocket-Version: 13\r\n", path, host, ws->key);
if (protocol)
g_string_append_printf(request, "Sec-WebSocket-Protocol: %s\r\n", protocol);
if (cookies)
g_string_append_printf(request, "Cookie: %s\r\n", cookies);
g_string_append(request, "\r\n");

ws->output.len = request->len;
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);

gchar *cookie = NULL;
if (sa->d_cookie)
cookie = g_strconcat("d=", sa->d_cookie, NULL);

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);

g_free(cookie);

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

0 comments on commit 36d12b3

Please sign in to comment.