From 5cc00bfae505d55ad1a2e7a7c0aea17bc6e557dd Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Wed, 17 Jun 2015 07:20:36 +0000 Subject: SkypeWeb: More fixes. Version bump. git-svn-id: http://svn.miranda-ng.org/main/trunk@14227 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/SkypeWeb/src/skype_trouter.cpp | 97 ++++++++++++++++---------------- 1 file changed, 49 insertions(+), 48 deletions(-) (limited to 'protocols/SkypeWeb/src/skype_trouter.cpp') diff --git a/protocols/SkypeWeb/src/skype_trouter.cpp b/protocols/SkypeWeb/src/skype_trouter.cpp index 72f1ded025..bc3003336b 100644 --- a/protocols/SkypeWeb/src/skype_trouter.cpp +++ b/protocols/SkypeWeb/src/skype_trouter.cpp @@ -107,6 +107,8 @@ void CSkypeProto::OnGetTrouter(const NETLIBHTTPREQUEST *response, void *p) TRouter.sessId = szToken.GetString(); if (!m_hTrouterThread) m_hTrouterThread = ForkThreadEx(&CSkypeProto::TRouterThread, 0, NULL); + else + SetEvent(m_hTrouterEvent); if (!isHealth) SendRequest(new RegisterTrouterRequest(m_szTokenSecret, TRouter.url.c_str(), TRouter.sessId.c_str())); @@ -125,6 +127,53 @@ void CSkypeProto::OnHealth(const NETLIBHTTPREQUEST*) &CSkypeProto::OnGetTrouter, (void *)1); } +void CSkypeProto::TRouterThread(void*) +{ + debugLogA(__FUNCTION__": entering"); + + int errors = 0; + + while (!isTerminated && errors < POLLING_ERRORS_LIMIT) + { + TrouterPollRequest *request = new TrouterPollRequest(TRouter.socketIo, TRouter.connId, TRouter.st, TRouter.se, TRouter.sig, TRouter.instance, TRouter.ccid, TRouter.sessId); + request->nlc = m_TrouterConnection; + NLHR_PTR response(request->Send(m_hNetlibUser)); + + if (response == NULL) + { + errors++; + delete request; + continue; + } + + if (response->resultCode == 200) + { + if (response->pData) + { + char *json = strstr(response->pData, "{"); + if (json != NULL) + { + JSONNode root = JSONNode::parse(json); + std::string szBody = root["body"].as_string(); + const JSONNode &headers = root["headers"]; + const JSONNode body = JSONNode::parse(szBody.c_str()); + OnTrouterEvent(body, headers); + } + } + } + else + { + SendRequest(new HealthTrouterRequest(TRouter.ccid.c_str()), &CSkypeProto::OnHealth); + WaitForSingleObject(m_hTrouterEvent, INFINITE); + } + m_TrouterConnection = response->nlc; + delete request; + } + m_hTrouterThread = NULL; + m_TrouterConnection = NULL; + debugLogA(__FUNCTION__": leaving"); +} + void CSkypeProto::OnTrouterEvent(const JSONNode &body, const JSONNode &) { //std::string displayname = body["displayName"].as_string(); @@ -172,54 +221,6 @@ void CSkypeProto::OnTrouterEvent(const JSONNode &body, const JSONNode &) } } -void CSkypeProto::TRouterThread(void*) -{ - debugLogA(__FUNCTION__": entering"); - - int errors = 0; - - while (!isTerminated && errors < POLLING_ERRORS_LIMIT) - { - TrouterPollRequest *request = new TrouterPollRequest(TRouter.socketIo, TRouter.connId, TRouter.st, TRouter.se, TRouter.sig, TRouter.instance, TRouter.ccid, TRouter.sessId); - request->nlc = m_TrouterConnection; - NLHR_PTR response(request->Send(m_hNetlibUser)); - - if (response == NULL) - { - errors++; - delete request; - continue; - } - - if (response->resultCode == 200) - { - if (response->pData) - { - char *json = strstr(response->pData, "{"); - if (json != NULL) - { - JSONNode root = JSONNode::parse(json); - std::string szBody = root["body"].as_string(); - const JSONNode &headers = root["headers"]; - const JSONNode body = JSONNode::parse(szBody.c_str()); - OnTrouterEvent(body, headers); - } - } - } - else - { - SendRequest(new HealthTrouterRequest(TRouter.ccid.c_str()), &CSkypeProto::OnHealth); - delete request; - break; - } - m_TrouterConnection = response->nlc; - delete request; - } - m_hTrouterThread = NULL; - m_TrouterConnection = NULL; - debugLogA(__FUNCTION__": leaving"); -} - INT_PTR CSkypeProto::OnIncomingCallCLE(WPARAM, LPARAM lParam) { CLISTEVENT *cle = (CLISTEVENT*)lParam; -- cgit v1.2.3