summaryrefslogtreecommitdiff
path: root/protocols/ICQ-WIM
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-03-11 12:19:00 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-03-11 12:19:00 +0300
commit79b5149e872319dcf0f2b6d5c4da5ece3ddc7993 (patch)
treef8733f7a1b1a918ca706bdad9ea696647dc7ed25 /protocols/ICQ-WIM
parent0d6b9512088d959126c965d82403623196a8ff85 (diff)
fixes #1892 (ICQ: still online even if network adapter is disabled)
Diffstat (limited to 'protocols/ICQ-WIM')
-rw-r--r--protocols/ICQ-WIM/src/http.cpp26
-rw-r--r--protocols/ICQ-WIM/src/poll.cpp6
-rw-r--r--protocols/ICQ-WIM/src/proto.h3
-rw-r--r--protocols/ICQ-WIM/src/server.cpp3
-rw-r--r--protocols/ICQ-WIM/src/version.h2
5 files changed, 30 insertions, 10 deletions
diff --git a/protocols/ICQ-WIM/src/http.cpp b/protocols/ICQ-WIM/src/http.cpp
index abcedca18a..e8b616fb46 100644
--- a/protocols/ICQ-WIM/src/http.cpp
+++ b/protocols/ICQ-WIM/src/http.cpp
@@ -22,6 +22,12 @@
#pragma comment(lib, "Rpcrt4.lib")
+bool CIcqProto::IsQueueEmpty()
+{
+ mir_cslock lck(m_csHttpQueue);
+ return m_arHttpQueue.getCount() == 0;
+}
+
void __cdecl CIcqProto::ServerThread(void*)
{
memset(&m_ConnPool, 0, sizeof(m_ConnPool));
@@ -116,7 +122,7 @@ void AsyncHttpRequest::ReplaceJsonParam(const JSONNode &n)
dataLength = 0;
}
-void CIcqProto::ExecuteRequest(AsyncHttpRequest *pReq)
+bool CIcqProto::ExecuteRequest(AsyncHttpRequest *pReq)
{
CMStringA str;
@@ -139,7 +145,7 @@ void CIcqProto::ExecuteRequest(AsyncHttpRequest *pReq)
if (m_szRToken.IsEmpty()) {
if (!RefreshRobustToken()) {
delete pReq;
- return;
+ return false;
}
pReq->ReplaceJsonParam(JSONNode("clientId", m_iRClientId));
@@ -157,6 +163,7 @@ void CIcqProto::ExecuteRequest(AsyncHttpRequest *pReq)
m_ConnPool[pReq->m_conn].lastTs = time(0);
}
+ bool bRet;
NETLIBHTTPREQUEST *reply = Netlib_HttpTransaction(m_hNetlibUser, pReq);
if (reply != nullptr) {
if (pReq->m_conn != CONN_NONE) {
@@ -179,12 +186,14 @@ void CIcqProto::ExecuteRequest(AsyncHttpRequest *pReq)
m_szRToken.Empty();
// if token refresh succeeded, replace it in the query and push request back
- if (RefreshRobustToken()) {
- pReq->ReplaceJsonParam(JSONNode("authToken", m_szRToken));
- Push(pReq);
+ if (!RefreshRobustToken()) {
+ delete pReq;
+ return false;
}
- else delete pReq;
- return;
+
+ pReq->ReplaceJsonParam(JSONNode("authToken", m_szRToken));
+ Push(pReq);
+ return true;
}
}
@@ -192,6 +201,7 @@ void CIcqProto::ExecuteRequest(AsyncHttpRequest *pReq)
(this->*(pReq->m_pFunc))(reply, pReq);
Netlib_FreeHttpRequest(reply);
+ bRet = true;
}
else {
debugLogA("Request %s failed", pReq->m_reqId);
@@ -201,9 +211,11 @@ void CIcqProto::ExecuteRequest(AsyncHttpRequest *pReq)
ConnectionFailed(LOGINERR_NONETWORK);
m_ConnPool[pReq->m_conn].s = nullptr;
}
+ bRet = false;
}
delete pReq;
+ return bRet;
}
void CIcqProto::Push(MHttpRequest *p)
diff --git a/protocols/ICQ-WIM/src/poll.cpp b/protocols/ICQ-WIM/src/poll.cpp
index 5ff5cdbb16..7004af5716 100644
--- a/protocols/ICQ-WIM/src/poll.cpp
+++ b/protocols/ICQ-WIM/src/poll.cpp
@@ -315,7 +315,11 @@ void __cdecl CIcqProto::PollThread(void*)
auto *pReq = new AsyncHttpRequest(CONN_FETCH, REQUEST_GET, szUrl, &CIcqProto::OnFetchEvents);
if (!m_bFirstBos)
pReq->timeout = 62000;
- ExecuteRequest(pReq);
+
+ if (!ExecuteRequest(pReq)) {
+ ShutdownSession();
+ break;
+ }
m_bFirstBos = false;
}
diff --git a/protocols/ICQ-WIM/src/proto.h b/protocols/ICQ-WIM/src/proto.h
index cfaf780fd0..96374acfee 100644
--- a/protocols/ICQ-WIM/src/proto.h
+++ b/protocols/ICQ-WIM/src/proto.h
@@ -263,7 +263,8 @@ class CIcqProto : public PROTO<CIcqProto>
LIST<AsyncHttpRequest> m_arHttpQueue;
void CalcHash(AsyncHttpRequest*);
- void ExecuteRequest(AsyncHttpRequest*);
+ bool ExecuteRequest(AsyncHttpRequest*);
+ bool IsQueueEmpty();
void Push(MHttpRequest*);
bool RefreshRobustToken();
diff --git a/protocols/ICQ-WIM/src/server.cpp b/protocols/ICQ-WIM/src/server.cpp
index 21f0b57ddb..217760f12c 100644
--- a/protocols/ICQ-WIM/src/server.cpp
+++ b/protocols/ICQ-WIM/src/server.cpp
@@ -516,6 +516,9 @@ void CIcqProto::ShutdownSession()
debugLogA("CIcqProto::ShutdownSession");
// shutdown all resources
+ while (!IsQueueEmpty())
+ Sleep(50);
+
if (m_hWorkerThread)
SetEvent(m_evRequestsQueue);
diff --git a/protocols/ICQ-WIM/src/version.h b/protocols/ICQ-WIM/src/version.h
index f023323c28..bb1e4cc050 100644
--- a/protocols/ICQ-WIM/src/version.h
+++ b/protocols/ICQ-WIM/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 95
#define __RELEASE_NUM 11
-#define __BUILD_NUM 3
+#define __BUILD_NUM 4
#include <stdver.h>