From a9a1da437a9388a34c35a62992130480d8e5986c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 5 Mar 2019 18:45:04 +0300 Subject: fixes #1875 (Facebook fails to log in) --- protocols/FacebookRM/src/communication.cpp | 52 ++++++++++++++---------------- 1 file changed, 25 insertions(+), 27 deletions(-) (limited to 'protocols/FacebookRM/src') diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 39f4a1866d..d865b85c06 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -797,42 +797,40 @@ bool facebook_client::reconnect() // Request reconnect http::response resp = sendRequest(reconnectRequest()); + if (resp.code != HTTP_CODE_OK) + return handle_error("reconnect", FORCE_DISCONNECT); - switch (resp.code) { - case HTTP_CODE_OK: - { - this->chat_channel_ = utils::text::source_get_value(&resp.data, 2, "\"user_channel\":\"", "\""); - parent->debugLogA(" Got self channel: %s", this->chat_channel_.c_str()); - - this->chat_channel_partition_ = utils::text::source_get_value2(&resp.data, "\"partition\":", ",}"); - parent->debugLogA(" Got self channel partition: %s", this->chat_channel_partition_.c_str()); + std::string redir = utils::text::source_get_value(&resp.data, 2, "\"redirect\":\"", "\""); + if (!redir.empty()) { + parent->debugLogA("Redirecting to %s", redir.c_str()); - this->chat_channel_host_ = utils::text::source_get_value(&resp.data, 2, "\"host\":\"", "\""); - parent->debugLogA(" Got self channel host: %s", this->chat_channel_host_.c_str()); + auto *p = new HttpRequest(REQUEST_GET, FACEBOOK_SERVER_REGULAR); + p->m_szUrl = redir.c_str(); + resp = sendRequest(p); + if (resp.code != HTTP_CODE_OK) + return handle_error("reconnect", FORCE_DISCONNECT); + } - this->chat_sequence_num_ = utils::text::source_get_value2(&resp.data, "\"seq\":", ",}"); - parent->debugLogA(" Got self sequence number: %s", this->chat_sequence_num_.c_str()); + this->chat_channel_ = utils::text::source_get_value(&resp.data, 2, "\"user_channel\":\"", "\""); + parent->debugLogA(" Got self channel: %s", this->chat_channel_.c_str()); - this->chat_conn_num_ = utils::text::source_get_value2(&resp.data, "\"max_conn\":", ",}"); - parent->debugLogA(" Got self max_conn: %s", this->chat_conn_num_.c_str()); + this->chat_channel_partition_ = utils::text::source_get_value2(&resp.data, "\"partition\":", ",}"); + parent->debugLogA(" Got self channel partition: %s", this->chat_channel_partition_.c_str()); - this->chat_sticky_num_ = utils::text::source_get_value(&resp.data, 2, "\"sticky_token\":\"", "\""); - parent->debugLogA(" Got self sticky_token: %s", this->chat_sticky_num_.c_str()); + this->chat_channel_host_ = utils::text::source_get_value(&resp.data, 2, "\"host\":\"", "\""); + parent->debugLogA(" Got self channel host: %s", this->chat_channel_host_.c_str()); - //std::string retry_interval = utils::text::source_get_value2(&resp.data, "\"retry_interval\":", ",}"); - //parent->debugLogA(" Got self retry_interval: %s", retry_interval.c_str()); + this->chat_sequence_num_ = utils::text::source_get_value2(&resp.data, "\"seq\":", ",}"); + parent->debugLogA(" Got self sequence number: %s", this->chat_sequence_num_.c_str()); - //std::string visibility = utils::text::source_get_value2(&resp.data, "\"visibility\":", ",}"); - //parent->debugLogA(" Got self visibility: %s", visibility.c_str()); + this->chat_conn_num_ = utils::text::source_get_value2(&resp.data, "\"max_conn\":", ",}"); + parent->debugLogA(" Got self max_conn: %s", this->chat_conn_num_.c_str()); - // Send activity_ping after each reconnect - activity_ping(); - } - return handle_success("reconnect"); + this->chat_sticky_num_ = utils::text::source_get_value(&resp.data, 2, "\"sticky_token\":\"", "\""); + parent->debugLogA(" Got self sticky_token: %s", this->chat_sticky_num_.c_str()); - default: - return handle_error("reconnect", FORCE_DISCONNECT); - } + activity_ping(); + return handle_success("reconnect"); } bool facebook_client::channel() -- cgit v1.2.3