summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-04-17 16:26:35 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-04-17 16:26:35 +0300
commitbec09dbab4b07281f3da8478618deb9c10aa0a29 (patch)
treebc73ac00fbc2e4c04665163efd1bcf7d0ef722b8 /protocols
parent3e05d92dcb5f6c2017bc462554901ba27816bdb4 (diff)
Facebook: unstable server connection makes persistent connections crazy
Diffstat (limited to 'protocols')
-rw-r--r--protocols/FacebookRM/src/client.h37
-rw-r--r--protocols/FacebookRM/src/communication.cpp41
-rw-r--r--protocols/FacebookRM/src/connection.cpp21
-rw-r--r--protocols/FacebookRM/src/version.h2
4 files changed, 13 insertions, 88 deletions
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h
index d6c1fcb137..7089be47ea 100644
--- a/protocols/FacebookRM/src/client.h
+++ b/protocols/FacebookRM/src/client.h
@@ -36,30 +36,15 @@ public:
facebook_client()
{
- msgid_ = error_count_ = last_feeds_update_ = last_notification_time_ = random_ = chat_msgs_recv_ = chat_req_ = 0;
-
- hChannelCon = nullptr;
- hMessagesCon = nullptr;
- hFcbCon = nullptr;
- handle_ = nullptr;
- parent = nullptr;
-
- mbasicWorks = true;
- loading_history = false;
}
- HNETLIBCONN hChannelCon;
- HNETLIBCONN hMessagesCon;
- HNETLIBCONN hFcbCon;
- mir_cs fcb_conn_lock_;
-
// Random generator value for this client
- unsigned int random_;
+ unsigned int random_ = 0;
// Parent handle
- FacebookProto *parent;
+ FacebookProto *parent = nullptr;
// User data
@@ -81,13 +66,13 @@ public:
std::string chat_conn_num_;
std::string chat_clientid_;
std::string chat_traceid_;
- time_t last_feeds_update_;
- time_t last_notification_time_;
- volatile unsigned int msgid_;
- int chat_msgs_recv_;
- volatile unsigned int chat_req_;
+ time_t last_feeds_update_ = 0;
+ time_t last_notification_time_ = 0;
+ volatile unsigned int msgid_ = 0;
+ int chat_msgs_recv_ = 0;
+ volatile unsigned int chat_req_ = 0;
- bool mbasicWorks;
+ bool mbasicWorks = true;
////////////////////////////////////////////////////////////
// Client vs protocol communication
@@ -130,7 +115,7 @@ public:
// Connection handling
- unsigned int error_count_;
+ unsigned int error_count_ = 0;
bool handle_entry(const std::string &method);
bool handle_success(const std::string &method);
@@ -186,7 +171,7 @@ public:
std::map<std::string, int> messages_ignore;
std::map<int, time_t> messages_timestamp;
- bool loading_history;
+ bool loading_history = false;
mir_cs loading_history_lock_;
bool channel();
@@ -272,7 +257,7 @@ public:
////////////////////////////////////////////////////////////
// Netlib handle
- HNETLIBUSER handle_;
+ HNETLIBUSER handle_ = nullptr;
void set_handle(HNETLIBUSER h)
{
handle_ = h;
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp
index c8f0f4572a..ee1049079f 100644
--- a/protocols/FacebookRM/src/communication.cpp
+++ b/protocols/FacebookRM/src/communication.cpp
@@ -54,50 +54,11 @@ http::response facebook_client::sendRequest(HttpRequest *request)
if (request->requestType == REQUEST_POST)
request->Headers << CHAR_PARAM("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
- mir_cslockfull s(fcb_conn_lock_); s.unlock();
-
- // Set persistent connection (or not)
- switch (request->Persistent) {
- case HttpRequest::PersistentType::NONE:
- request->nlc = nullptr;
- request->flags &= ~NLHRF_PERSISTENT;
- break;
- case HttpRequest::PersistentType::CHANNEL:
- request->nlc = hChannelCon;
- request->flags |= NLHRF_PERSISTENT;
- break;
- case HttpRequest::PersistentType::MESSAGES:
- request->nlc = hMessagesCon;
- request->flags |= NLHRF_PERSISTENT;
- break;
- case HttpRequest::PersistentType::DEFAULT:
- s.lock();
- request->nlc = hFcbCon;
- request->flags |= NLHRF_PERSISTENT;
- break;
- }
-
parent->debugLogA("@@@ Sending request to '%s'", request->szUrl);
// Send the request
NETLIBHTTPREQUEST *pnlhr = request->Send(handle_);
- // Remember the persistent connection handle (or not)
- switch (request->Persistent) {
- case HttpRequest::PersistentType::NONE:
- break;
- case HttpRequest::PersistentType::CHANNEL:
- hChannelCon = pnlhr ? pnlhr->nlc : nullptr;
- break;
- case HttpRequest::PersistentType::MESSAGES:
- hMessagesCon = pnlhr ? pnlhr->nlc : nullptr;
- break;
- case HttpRequest::PersistentType::DEFAULT:
- s.unlock();
- hFcbCon = pnlhr ? pnlhr->nlc : nullptr;
- break;
- }
-
// Check and copy response data
if (pnlhr != nullptr) {
parent->debugLogA("@@@ Got response with code %d", pnlhr->resultCode);
@@ -1138,7 +1099,7 @@ bool facebook_client::save_url(const std::string &url, const std::wstring &filen
NETLIBHTTPREQUEST req = { sizeof(req) };
req.requestType = REQUEST_GET;
req.szUrl = const_cast<char*>(url.c_str());
- req.flags = NLHRF_HTTP11 | NLHRF_REDIRECT | NLHRF_PERSISTENT | NLHRF_NODUMP;
+ req.flags = NLHRF_HTTP11 | NLHRF_REDIRECT | NLHRF_NODUMP;
req.nlc = nlc;
bool ret = false;
diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp
index b99ab28544..4b54c41187 100644
--- a/protocols/FacebookRM/src/connection.cpp
+++ b/protocols/FacebookRM/src/connection.cpp
@@ -36,18 +36,6 @@ void FacebookProto::ChangeStatus(void*)
SetEvent(update_loop_event);
- // Shutdown and close channel handle
- Netlib_Shutdown(facy.hChannelCon);
- if (facy.hChannelCon)
- Netlib_CloseHandle(facy.hChannelCon);
- facy.hChannelCon = nullptr;
-
- // Shutdown and close messages handle
- Netlib_Shutdown(facy.hMessagesCon);
- if (facy.hMessagesCon)
- Netlib_CloseHandle(facy.hMessagesCon);
- facy.hMessagesCon = nullptr;
-
// Turn off chat on Facebook
if (getByte(FACEBOOK_KEY_DISCONNECT_CHAT, DEFAULT_DISCONNECT_CHAT))
facy.chat_state(false);
@@ -74,11 +62,6 @@ void FacebookProto::ChangeStatus(void*)
facy.pages.clear();
facy.typers.clear();
- // Close connection handle
- if (facy.hFcbCon)
- Netlib_CloseHandle(facy.hFcbCon);
- facy.hFcbCon = nullptr;
-
m_iStatus = facy.self_.status_id = ID_STATUS_OFFLINE;
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
@@ -135,10 +118,6 @@ void FacebookProto::ChangeStatus(void*)
else {
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_FAILED, (HANDLE)old_status, m_iStatus);
- if (facy.hFcbCon)
- Netlib_CloseHandle(facy.hFcbCon);
- facy.hFcbCon = nullptr;
-
facy.clear_cookies();
// Set to offline
diff --git a/protocols/FacebookRM/src/version.h b/protocols/FacebookRM/src/version.h
index 130684e559..82e341a973 100644
--- a/protocols/FacebookRM/src/version.h
+++ b/protocols/FacebookRM/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 4
#define __RELEASE_NUM 1
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>