summaryrefslogtreecommitdiff
path: root/protocols/SkypeWeb/src/skype_trouter.cpp
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2015-06-17 07:20:36 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2015-06-17 07:20:36 +0000
commit5cc00bfae505d55ad1a2e7a7c0aea17bc6e557dd (patch)
tree6a052c9a690be47c2af166df0656c5ea2b6feee3 /protocols/SkypeWeb/src/skype_trouter.cpp
parent06b7222a8359baa84e2dc185f4397a2fbb40ff58 (diff)
SkypeWeb: More fixes. Version bump.
git-svn-id: http://svn.miranda-ng.org/main/trunk@14227 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/SkypeWeb/src/skype_trouter.cpp')
-rw-r--r--protocols/SkypeWeb/src/skype_trouter.cpp97
1 files changed, 49 insertions, 48 deletions
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;