From 2fcca210a1f695d7a932b873ae00dc702d42cfeb Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 29 May 2015 14:53:33 +0000 Subject: SkypeWeb to use new json parser git-svn-id: http://svn.miranda-ng.org/main/trunk@13891 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/SkypeWeb/src/skype_polling.cpp | 73 ++++++++++++++++---------------- 1 file changed, 36 insertions(+), 37 deletions(-) (limited to 'protocols/SkypeWeb/src/skype_polling.cpp') diff --git a/protocols/SkypeWeb/src/skype_polling.cpp b/protocols/SkypeWeb/src/skype_polling.cpp index 41ade45ec3..3ab4461079 100644 --- a/protocols/SkypeWeb/src/skype_polling.cpp +++ b/protocols/SkypeWeb/src/skype_polling.cpp @@ -17,40 +17,41 @@ along with this program. If not, see . #include "stdafx.h" -void CSkypeProto::ParsePollData(JSONNODE *data) +void CSkypeProto::ParsePollData(const JSONNode &data) { debugLogA("CSkypeProto::ParsePollData"); - JSONNODE *node = json_get(data, "eventMessages"); - if (node != NULL) + + const JSONNode &node = data["eventMessages"]; + if (!node) + return; + + const JSONNode &messages = node.as_array(); + for (size_t i = 0; i < messages.size(); i++) { - JSONNODE *messages = json_as_array(node); - for (size_t i = 0; i < json_size(messages); i++) - { - JSONNODE *message = json_at(messages, i); - JSONNODE *resType = json_get(message, "resourceType"); - ptrA resourceType(mir_t2a(ptrT(json_as_string(resType)))); - JSONNODE *resource = json_get(message, "resource"); + const JSONNode &message = messages.at(i); + const JSONNode &resType = message["resourceType"]; + const JSONNode &resource = message["resource"]; - if (!mir_strcmpi(resourceType, "NewMessage")) - { - ProcessNewMessageRes(resource); - } - else if (!mir_strcmpi(resourceType, "UserPresence")) - { - ProcessUserPresenceRes(resource); - } - else if (!mir_strcmpi(resourceType, "EndpointPresence")) - { - ProcessEndpointPresenceRes(resource); - } - else if (!mir_strcmpi(resourceType, "ConversationUpdate")) - { - ProcessConversationUpdateRes(resource); - } - else if (!mir_strcmpi(resourceType, "ThreadUpdate")) - { - ProcessThreadUpdateRes(resource); - } + std::string resourceType = resType.as_string(); + if (!mir_strcmpi(resourceType.c_str(), "NewMessage")) + { + ProcessNewMessageRes(resource); + } + else if (!mir_strcmpi(resourceType.c_str(), "UserPresence")) + { + ProcessUserPresenceRes(resource); + } + else if (!mir_strcmpi(resourceType.c_str(), "EndpointPresence")) + { + ProcessEndpointPresenceRes(resource); + } + else if (!mir_strcmpi(resourceType.c_str(), "ConversationUpdate")) + { + ProcessConversationUpdateRes(resource); + } + else if (!mir_strcmpi(resourceType.c_str(), "ThreadUpdate")) + { + ProcessThreadUpdateRes(resource); } } } @@ -78,9 +79,8 @@ void CSkypeProto::PollingThread(void*) { if (response->pData) { - JSONROOT root(response->pData); - JSONNODE *events = json_get(root, "eventMessages"); - if (events != NULL) + JSONNode root = JSONNode::parse(response->pData); + if (root["eventMessages"]) { ParsePollData(root); } @@ -92,12 +92,11 @@ void CSkypeProto::PollingThread(void*) if (response->pData) { - JSONROOT root(response->pData); - JSONNODE *error = json_get(root, "errorCode"); + JSONNode root = JSONNode::parse(response->pData); + const JSONNode &error = root["errorCode"]; if (error != NULL) { - int errorCode = json_as_int(error); - + int errorCode = error.as_int(); if (errorCode == 729) { SendRequest(new CreateEndpointRequest(TokenSecret), &CSkypeProto::OnEndpointCreated); -- cgit v1.2.3