@@ -263,6 +263,7 @@ typedef struct {
263263
264264 gchar * username ;
265265 gchar * server ;
266+ gchar * websocket_server ;
266267 gchar * path ;
267268 gboolean tls ;
268269 gchar * http_str ;
@@ -832,6 +833,11 @@ rc_fetch_url(RocketChatAccount *ya, const gchar *url, const gchar *postdata, Roc
832833#if PURPLE_VERSION_CHECK (3 , 0 , 0 )
833834
834835 PurpleHttpRequest * request = purple_http_request_new (url );
836+ if (ya -> websocket_server != ya -> server ) {
837+ purple_http_request_header_set (request , "Host" , g_strdup (ya -> websocket_server ));
838+ purple_debug_misc ("rocketchat" , "Proxy enabled, sending %s instead of %s\n" ,
839+ host , ya -> server );
840+ }
835841 purple_http_request_header_set (request , "Accept" , "*/*" );
836842 purple_http_request_header_set (request , "User-Agent" , ROCKETCHAT_USERAGENT );
837843 purple_http_request_header_set (request , "Cookie" , cookies );
@@ -864,9 +870,15 @@ rc_fetch_url(RocketChatAccount *ya, const gchar *url, const gchar *postdata, Roc
864870 gchar * host = NULL , * path = NULL , * user = NULL , * password = NULL ;
865871 int port ;
866872 purple_url_parse (url , & host , & port , & path , & user , & password );
867-
873+
868874 headers = g_string_new (NULL );
869-
875+
876+ if (ya -> websocket_server != ya -> server ) {
877+ host = g_strdup (ya -> websocket_server );
878+ purple_debug_misc ("rocketchat" , "Proxy enabled, sending %s instead of %s\n" ,
879+ host , ya -> server );
880+ }
881+
870882 //Use the full 'url' until libpurple can handle path's longer than 256 chars
871883 g_string_append_printf (headers , "%s /%s HTTP/1.0\r\n" , (postdata ? "POST" : "GET" ), path );
872884 //g_string_append_printf(headers, "%s %s HTTP/1.0\r\n", (postdata ? "POST" : "GET"), url);
@@ -2126,6 +2138,7 @@ rc_login(PurpleAccount *account)
21262138 gchar * url ;
21272139 PurpleConnectionFlags pc_flags ;
21282140 const char * connection_security ;
2141+ char * proxy ;
21292142
21302143 pc_flags = purple_connection_get_flags (pc );
21312144 pc_flags |= PURPLE_CONNECTION_FLAG_HTML ;
@@ -2182,7 +2195,15 @@ rc_login(PurpleAccount *account)
21822195 ya -> http_str = g_strdup ("https://" );
21832196 }
21842197
2185- ya -> session_token = g_strdup (purple_account_get_string (account , "personal_access_token" , NULL ));
2198+ ya -> websocket_server = g_strdup (ya -> server );
2199+ purple_debug_info ("rocketchat" , "websocket_server: %s\n" , ya -> websocket_server );
2200+
2201+ proxy = g_strdup (purple_account_get_string (account , "proxy" , NULL ));
2202+ if (proxy && !purple_strequal (proxy , "" )) {
2203+ ya -> server = proxy ;
2204+ }
2205+
2206+ ya -> session_token = g_strdup (purple_account_get_string (account , "personal_access_token" , NULL ));
21862207 if (ya -> session_token && * ya -> session_token ) {
21872208 const gchar * user_id = purple_account_get_string (account , "personal_access_token_user_id" , NULL );
21882209
@@ -2290,6 +2311,7 @@ rc_close(PurpleConnection *pc)
22902311 g_free (ya -> username ); ya -> username = NULL ;
22912312 g_free (ya -> server ); ya -> server = NULL ;
22922313 g_free (ya -> http_str ); ya -> http_str = NULL ;
2314+ g_free (ya -> websocket_server ); ya -> websocket_server = NULL ;
22932315 g_free (ya -> path ); ya -> path = NULL ;
22942316 g_free (ya -> frame ); ya -> frame = NULL ;
22952317 g_free (ya -> session_token ); ya -> session_token = NULL ;
@@ -2677,8 +2699,11 @@ rc_socket_upgrade(RocketChatAccount *ya)
26772699 "User-Agent: " ROCKETCHAT_USERAGENT "\r\n"
26782700 "Cookie: %s\r\n"
26792701 //"Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n"
2680- "\r\n" , url -> str , ya -> server ,
2702+ "\r\n" , url -> str , ya -> websocket_server ,
26812703 websocket_key , cookies );
2704+
2705+ purple_debug_misc ("rocketchat" , "websocket_header: %s" ,
2706+ websocket_header );
26822707 rc_sock_write (ya , websocket_header , strlen (websocket_header ));
26832708
26842709 g_free (websocket_header );
@@ -3791,6 +3816,9 @@ rc_add_account_options(GList *account_options)
37913816 "connection_security" , encryption_values );
37923817 account_options = g_list_append (account_options , option );
37933818
3819+ option = purple_account_option_string_new (N_ ("Proxy" ), "proxy" , "" );
3820+ account_options = g_list_append (account_options , option );
3821+
37943822 return account_options ;
37953823}
37963824
0 commit comments