summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2015-05-02 14:34:42 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2015-05-02 14:34:42 +0000
commitcf379ef3c47b386c970d7d0f8724f85abcbff8cc (patch)
tree2d4ee097db62491c252e987bfc3a74835f52389b /protocols
parent438d7d37135645c4c57c87b9375a4c96e2359d46 (diff)
SkypeWeb: Polling refactoring. Small fix.
git-svn-id: http://svn.miranda-ng.org/main/trunk@13374 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/SkypeWeb/src/requests/trouter.h4
-rw-r--r--protocols/SkypeWeb/src/skype_messages.cpp2
-rw-r--r--protocols/SkypeWeb/src/skype_polling.cpp46
-rw-r--r--protocols/SkypeWeb/src/skype_proto.cpp1
-rw-r--r--protocols/SkypeWeb/src/skype_trouter.cpp50
5 files changed, 54 insertions, 49 deletions
diff --git a/protocols/SkypeWeb/src/requests/trouter.h b/protocols/SkypeWeb/src/requests/trouter.h
index 30cd906992..0e64aa9590 100644
--- a/protocols/SkypeWeb/src/requests/trouter.h
+++ b/protocols/SkypeWeb/src/requests/trouter.h
@@ -52,7 +52,7 @@ public:
class RegisterTrouterRequest : public HttpRequest
{
public:
- RegisterTrouterRequest(const char *token, const char *trouterUrl) :
+ RegisterTrouterRequest(const char *token, const char *trouterUrl, const char *id) :
HttpRequest(REQUEST_POST, "prod.registrar.skype.com/v2/registrations")
{
Headers
@@ -60,7 +60,7 @@ public:
<< CHAR_VALUE("X-Skypetoken", token);
CMStringA data;
- data.AppendFormat("{\"clientDescription\":{\"aesKey\":\"\",\"languageId\":\"en-US\",\"platform\":\"SWX\",\"templateKey\":\"SkypeWeb_1.0\"},\"registrationId\":\"eafc0311-7bb4-4a93-4f32-7fce2496d724\",\"nodeId\":\"\",\"transports\":{\"TROUTER\":[{\"context\":\"\",\"path\":\"%s\",\"ttl\":3600}]}}", trouterUrl);
+ data.AppendFormat("{\"clientDescription\":{\"aesKey\":\"\",\"languageId\":\"en-US\",\"platform\":\"SWX\",\"templateKey\":\"SkypeWeb_1.0\"},\"registrationId\":\"%s\",\"nodeId\":\"\",\"transports\":{\"TROUTER\":[{\"context\":\"\",\"path\":\"%s\",\"ttl\":3600}]}}", id, trouterUrl);
Body << VALUE(data);
}
diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp
index d259963bc3..2082370811 100644
--- a/protocols/SkypeWeb/src/skype_messages.cpp
+++ b/protocols/SkypeWeb/src/skype_messages.cpp
@@ -70,7 +70,7 @@ MEVENT CSkypeProto::AddCallToDb(MCONTACT hContact, DWORD timestamp, DWORD flags,
{
const char *message = Translate("Incoming call");
size_t callIdLength = mir_strlen(callId);
- size_t messageLength = mir_strlen(message);
+ size_t messageLength = mir_strlen(message) + 1;
size_t cbBlob = messageLength + callIdLength;
PBYTE pBlob = (PBYTE)mir_alloc(cbBlob);
memcpy(pBlob, message, messageLength);
diff --git a/protocols/SkypeWeb/src/skype_polling.cpp b/protocols/SkypeWeb/src/skype_polling.cpp
index 5c069c06a4..df80efc787 100644
--- a/protocols/SkypeWeb/src/skype_polling.cpp
+++ b/protocols/SkypeWeb/src/skype_polling.cpp
@@ -73,33 +73,41 @@ void CSkypeProto::PollingThread(void*)
continue;
}
- if (response->resultCode != 200)
+ if (response->resultCode == 200)
{
- errors++;
+ if (response->pData)
+ {
+ JSONROOT root(response->pData);
+ JSONNODE *events = json_get(root, "eventMessages");
+ if (events != NULL)
+ {
+ ParsePollData(root);
+ }
+ }
}
-
- if (response->pData)
+ else
{
- JSONROOT root(response->pData);
- JSONNODE *eventMsgs = json_get(root, "eventMessages");
- JSONNODE *errorCode = json_get(root, "errorCode");
-
- if (eventMsgs != NULL)
- ParsePollData(root);
+ errors++;
- else if (errorCode != NULL)
+ if (response->pData)
{
- errors++;
- debugLogA(__FUNCTION__": polling error %d", json_as_int(errorCode));
- if (json_as_int(errorCode) == 729)
+ JSONROOT root(response->pData);
+ JSONNODE *error = json_get(root, "errorCode");
+ if (error != NULL)
{
- SendRequest(new CreateEndpointRequest(TokenSecret), &CSkypeProto::OnEndpointCreated);
- CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response);
- delete request;
- break;
- }
+ int errorCode = json_as_int(error);
+
+ if (errorCode == 729)
+ {
+ SendRequest(new CreateEndpointRequest(TokenSecret), &CSkypeProto::OnEndpointCreated);
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response);
+ delete request;
+ break;
+ }
+ }
}
}
+
m_pollingConnection = response->nlc;
CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response);
delete request;
diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp
index 0d3b1f7578..70124ca692 100644
--- a/protocols/SkypeWeb/src/skype_proto.cpp
+++ b/protocols/SkypeWeb/src/skype_proto.cpp
@@ -218,7 +218,6 @@ int CSkypeProto::SetStatus(int iNewStatus)
delSetting("registrationRoken");
delSetting("endpointId");
delSetting("expires");
-
}
requestQueue->Stop();
diff --git a/protocols/SkypeWeb/src/skype_trouter.cpp b/protocols/SkypeWeb/src/skype_trouter.cpp
index 854a4e75d7..0f22c3d98f 100644
--- a/protocols/SkypeWeb/src/skype_trouter.cpp
+++ b/protocols/SkypeWeb/src/skype_trouter.cpp
@@ -72,7 +72,7 @@ void CSkypeProto::OnGetTrouter(const NETLIBHTTPREQUEST *response)
CMStringA szToken = data.Tokenize(":", iStart).Trim();
setString("Trouter_SessId", szToken);
m_hTrouterThread = ForkThreadEx(&CSkypeProto::TRouterThread, 0, NULL);
- SendRequest(new RegisterTrouterRequest(TokenSecret, ptrA(getStringA("Trouter_url"))));
+ SendRequest(new RegisterTrouterRequest(TokenSecret, ptrA(getStringA("Trouter_url")), szToken));
}
void CSkypeProto::OnHealth(const NETLIBHTTPREQUEST*)
@@ -158,34 +158,32 @@ void CSkypeProto::TRouterThread(void*)
request->nlc = m_TrouterConnection;
NETLIBHTTPREQUEST *response = request->Send(m_hNetlibUser);
- if (response == NULL)
+ if (response != NULL)
{
- errors++;
- delete request;
- continue;
- }
-
- if (response->resultCode != 200)
- {
- SendRequest(new HealthTrouterRequest(ccid), &CSkypeProto::OnHealth);
- break;
- }
-
- if (response->pData)
- {
- char *json = strstr(response->pData, "{");
-
- if (json == NULL) continue;
+ if (response->resultCode == 200)
+ {
+ if (response->pData)
+ {
+ char *json = strstr(response->pData, "{");
+
+ if (json == NULL)
+ continue;
+
+ JSONROOT root(json);
+ ptrA szBody(mir_t2a(ptrT(json_as_string(json_get(root, "body")))));
+ JSONNODE *headers = json_get(root, "headers");
+ JSONNODE *body = json_parse(szBody);
+ OnTrouterEvent(body, headers);
+ }
+ }
+ else
+ {
+ SendRequest(new HealthTrouterRequest(ccid), &CSkypeProto::OnHealth);
+ }
- JSONROOT root(json);
- ptrA szBody(mir_t2a(ptrT(json_as_string(json_get(root, "body")))));
- JSONNODE *headers = json_get(root, "headers");
- JSONNODE *body = json_parse(szBody);
- OnTrouterEvent(body, headers);
+ m_TrouterConnection = response->nlc;
+ CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response);
}
-
- m_TrouterConnection = response->nlc;
- CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response);
delete request;
}
m_hTrouterThread = NULL;