From 70452ae985e7109b1eb9a66e39c039dacf0e2ecd Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 16 Aug 2024 20:15:38 +0300 Subject: =?UTF-8?q?fixes=20#4568=20(Skypeweb:=20=D0=BC=D0=BE=D0=B6=D0=B5?= =?UTF-8?q?=D1=82=20=D0=B2=D0=BF=D0=B0=D0=B4=D0=B0=D1=82=D1=8C=20=D0=B2=20?= =?UTF-8?q?=D1=81=D1=82=D1=83=D0=BF=D0=BE=D1=80=20=D0=BF=D0=BE=D1=81=D0=BB?= =?UTF-8?q?=D0=B5=20=D1=81=D0=BF=D1=8F=D1=87=D0=BA=D0=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/SkypeWeb/src/request_queue.cpp | 7 +++-- protocols/SkypeWeb/src/requests/poll.h | 1 + protocols/SkypeWeb/src/skype_login.cpp | 5 ++-- protocols/SkypeWeb/src/skype_polling.cpp | 50 ++++++++++++++------------------ protocols/SkypeWeb/src/skype_proto.cpp | 2 -- protocols/SkypeWeb/src/skype_proto.h | 7 ++--- 6 files changed, 34 insertions(+), 38 deletions(-) diff --git a/protocols/SkypeWeb/src/request_queue.cpp b/protocols/SkypeWeb/src/request_queue.cpp index e4cf75669c..580658d4b6 100644 --- a/protocols/SkypeWeb/src/request_queue.cpp +++ b/protocols/SkypeWeb/src/request_queue.cpp @@ -59,12 +59,15 @@ void CSkypeProto::StartQueue() void CSkypeProto::StopQueue() { m_isTerminated = true; + m_iPollingId = -1; if (m_hRequestQueueThread) m_hRequestQueueEvent.Set(); - if (m_hPollingThread) - m_hPollingEvent.Set(); + if (m_hPollingConn) { + Netlib_Shutdown(m_hPollingConn); + m_hPollingConn = 0; + } } void CSkypeProto::PushRequest(AsyncHttpRequest *request) diff --git a/protocols/SkypeWeb/src/requests/poll.h b/protocols/SkypeWeb/src/requests/poll.h index 20f260fb64..b0ea4de52a 100644 --- a/protocols/SkypeWeb/src/requests/poll.h +++ b/protocols/SkypeWeb/src/requests/poll.h @@ -23,6 +23,7 @@ struct PollRequest : public AsyncHttpRequest PollRequest(CSkypeProto *ppro) : AsyncHttpRequest(REQUEST_POST, HOST_DEFAULT, "/users/ME/endpoints/" + mir_urlEncode(ppro->m_szId) + "/subscriptions/0/poll") { + flags |= NLHRF_PERSISTENT; timeout = 120000; if (ppro->m_iPollingId != -1) diff --git a/protocols/SkypeWeb/src/skype_login.cpp b/protocols/SkypeWeb/src/skype_login.cpp index 83ad944745..406f484278 100644 --- a/protocols/SkypeWeb/src/skype_login.cpp +++ b/protocols/SkypeWeb/src/skype_login.cpp @@ -218,6 +218,9 @@ void CSkypeProto::OnEndpointCreated(MHttpResponse *response, AsyncHttpRequest*) } } + if (m_szId && m_hPollingThread == nullptr) + ForkThread(&CSkypeProto::PollingThread); + PushRequest(new CreateSubscriptionsRequest()); } @@ -274,8 +277,6 @@ void CSkypeProto::OnCapabilitiesSended(MHttpResponse *response, AsyncHttpRequest FreeList(skypenames); skypenames.destroy(); - m_hPollingEvent.Set(); - PushRequest(new GetContactListRequest()); PushRequest(new GetAvatarRequest(ptrA(getStringA("AvatarUrl")), 0)); PushRequest(new SyncConversations()); diff --git a/protocols/SkypeWeb/src/skype_polling.cpp b/protocols/SkypeWeb/src/skype_polling.cpp index e1d51e49a5..20b65abd60 100644 --- a/protocols/SkypeWeb/src/skype_polling.cpp +++ b/protocols/SkypeWeb/src/skype_polling.cpp @@ -21,44 +21,38 @@ void CSkypeProto::PollingThread(void *) { debugLogA(__FUNCTION__ ": entering"); + int nErrors = 0; + m_iPollingId = -1; + while (true) { - m_hPollingEvent.Wait(); - if (m_isTerminated) + if (m_isTerminated || m_szId == nullptr) break; - int nErrors = 0; - m_iPollingId = -1; + std::unique_ptr request(new PollRequest(this)); + request->nlc = m_hPollingConn; + NLHR_PTR response(DoSend(request.get())); + if (m_isTerminated || m_szId == nullptr) + break; - while ((nErrors < POLLING_ERRORS_LIMIT) && m_iStatus != ID_STATUS_OFFLINE) { - std::unique_ptr request(new PollRequest(this)); - NLHR_PTR response(DoSend(request.get())); - if (response == nullptr) { + if (response == nullptr || response->resultCode != 200) { + if (nErrors < POLLING_ERRORS_LIMIT) { nErrors++; continue; } - - if (response->resultCode == 200) { - nErrors = 0; - if (!response->body.IsEmpty()) - ParsePollData(response->body); - } - else { - nErrors++; - - if (!response->body.IsEmpty()) { - JSONNode root = JSONNode::parse(response->body); - const JSONNode &error = root["errorCode"]; - if (error && error.as_int() == 729) - break; - } - } + break; } - if (m_iStatus != ID_STATUS_OFFLINE) { - debugLogA(__FUNCTION__ ": unexpected termination; switching protocol to offline"); - SetStatus(ID_STATUS_OFFLINE); - } + m_hPollingConn = response->nlc; + if (!response->body.IsEmpty()) + ParsePollData(response->body); } + + if (!m_isTerminated) { + debugLogA(__FUNCTION__ ": unexpected termination; switching protocol to offline"); + SetStatus(ID_STATUS_OFFLINE); + } + + m_hPollingConn = nullptr; m_hPollingThread = nullptr; debugLogA(__FUNCTION__ ": leaving"); } diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index 1b4bc415c5..9cee58b515 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -58,8 +58,6 @@ CSkypeProto::CSkypeProto(const char* protoName, const wchar_t* userName) : g_plugin.addSound("skype_inc_call", L"SkypeWeb", LPGENW("Incoming call")); g_plugin.addSound("skype_call_canceled", L"SkypeWeb", LPGENW("Incoming call canceled")); - m_hPollingThread = ForkThreadEx(&CSkypeProto::PollingThread, NULL, NULL); - CheckConvert(); InitGroupChatModule(); } diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 32c634f3c6..b242ad4142 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -176,8 +176,6 @@ private: std::map cookies; static std::map languages; - HANDLE m_hPollingThread; - LIST m_PopupClasses; LIST m_OutMessages; @@ -186,8 +184,9 @@ private: mir_cs messageSyncLock; mir_cs m_StatusLock; - EventHandle m_hPollingEvent; - + HANDLE m_hPollingThread; + HNETLIBCONN m_hPollingConn; + INT_PTR __cdecl SvcGetAvatarInfo(WPARAM, LPARAM); INT_PTR __cdecl SvcGetAvatarCaps(WPARAM, LPARAM); INT_PTR __cdecl SvcGetMyAvatar(WPARAM, LPARAM); -- cgit v1.2.3