summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-05-26 14:39:09 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-05-26 14:39:09 +0300
commitbd85e9779e4ba479e2b60fd55fd60184f81dd69a (patch)
treece377d36916f5d2257753ab22cd1a38223b43675 /protocols/FacebookRM/src
parent1baa80632f0084ce847e63aadad898a85c62b196 (diff)
Facebook:
- packet timeout extended to 10 minutes (specially for Karamil Alhady); - persistent connections restored; - this reverts commit bec09dbab4b07281f3da8478618deb9c10aa0a29
Diffstat (limited to 'protocols/FacebookRM/src')
-rw-r--r--protocols/FacebookRM/src/client.h5
-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, 67 insertions, 2 deletions
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h
index 7089be47ea..bd3104114c 100644
--- a/protocols/FacebookRM/src/client.h
+++ b/protocols/FacebookRM/src/client.h
@@ -38,6 +38,11 @@ public:
{
}
+ HNETLIBCONN hChannelCon;
+ HNETLIBCONN hMessagesCon;
+ HNETLIBCONN hFcbCon;
+ mir_cs fcb_conn_lock_;
+
// Random generator value for this client
unsigned int random_ = 0;
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp
index dbec3c4e32..2dd2c7aac7 100644
--- a/protocols/FacebookRM/src/communication.cpp
+++ b/protocols/FacebookRM/src/communication.cpp
@@ -54,11 +54,50 @@ 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);
@@ -1099,7 +1138,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_NODUMP;
+ req.flags = NLHRF_HTTP11 | NLHRF_REDIRECT | NLHRF_PERSISTENT | NLHRF_NODUMP;
req.nlc = nlc;
bool ret = false;
diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp
index 79a0f5e03b..e2ebc70f56 100644
--- a/protocols/FacebookRM/src/connection.cpp
+++ b/protocols/FacebookRM/src/connection.cpp
@@ -36,6 +36,18 @@ 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);
@@ -62,6 +74,11 @@ 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);
@@ -118,6 +135,10 @@ 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 82e341a973..5c4c0f4f93 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 2
+#define __BUILD_NUM 3
#include <stdver.h>