diff --git a/purple-websocket.c b/purple-websocket.c index 55eb371..0554766 100644 --- a/purple-websocket.c +++ b/purple-websocket.c @@ -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; @@ -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; diff --git a/purple-websocket.h b/purple-websocket.h index 0416750..0f3eae0 100644 --- a/purple-websocket.h +++ b/purple-websocket.h @@ -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); diff --git a/slack-rtm.c b/slack-rtm.c index d4ee8f2..e32216e 100644 --- a/slack-rtm.c +++ b/slack-rtm.c @@ -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;