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/requests/capabilities.h | 54 ++++------ protocols/SkypeWeb/src/requests/chatrooms.h | 32 +++--- protocols/SkypeWeb/src/requests/messages.h | 48 ++++----- protocols/SkypeWeb/src/requests/subscriptions.h | 27 ++--- protocols/SkypeWeb/src/requests/trouter.h | 89 +++++++-------- protocols/SkypeWeb/src/skype_avatars.cpp | 4 +- protocols/SkypeWeb/src/skype_chatrooms.cpp | 113 ++++++++++--------- protocols/SkypeWeb/src/skype_contacts.cpp | 87 ++++++--------- protocols/SkypeWeb/src/skype_history_sync.cpp | 131 +++++++++++------------ protocols/SkypeWeb/src/skype_login.cpp | 15 ++- protocols/SkypeWeb/src/skype_messages.cpp | 88 ++++++++------- protocols/SkypeWeb/src/skype_poll_processing.cpp | 87 ++++++++------- protocols/SkypeWeb/src/skype_polling.cpp | 73 +++++++------ protocols/SkypeWeb/src/skype_profile.cpp | 130 ++++++++++------------ protocols/SkypeWeb/src/skype_proto.h | 78 +++++++------- protocols/SkypeWeb/src/skype_search.cpp | 28 +++-- protocols/SkypeWeb/src/skype_trouter.cpp | 124 ++++++++++----------- protocols/SkypeWeb/src/skype_utils.cpp | 16 +-- protocols/SkypeWeb/src/version.h | 4 +- 19 files changed, 566 insertions(+), 662 deletions(-) (limited to 'protocols/SkypeWeb') diff --git a/protocols/SkypeWeb/src/requests/capabilities.h b/protocols/SkypeWeb/src/requests/capabilities.h index fb7c668c20..ef0da77f92 100644 --- a/protocols/SkypeWeb/src/requests/capabilities.h +++ b/protocols/SkypeWeb/src/requests/capabilities.h @@ -30,38 +30,30 @@ public: << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken); - char compName[MAX_COMPUTERNAME_LENGTH + 1]; + TCHAR compName[MAX_COMPUTERNAME_LENGTH + 1]; DWORD size = SIZEOF(compName); - GetComputerNameA(compName, &size); - - JSONNODE *node = json_new(5); - JSONNODE *privateInfo = json_new(5); - JSONNODE *publicInfo = json_new(5); - - json_set_name(privateInfo, "privateInfo"); - json_set_name(publicInfo, "publicInfo"); - - json_push_back(node, json_new_a("id", "messagingService")); - json_push_back(node, json_new_a("type", "EndpointPresenceDoc")); - json_push_back(node, json_new_a("selfLink", "uri")); - - json_push_back(privateInfo, json_new_a("epname", compName)); - - json_push_back(publicInfo, json_new_a("capabilities", "Audio|Video")); - json_push_back(publicInfo, json_new_i("typ", 125)); - json_push_back(publicInfo, json_new_a("skypeNameVersion", "Miranda NG Skype")); - json_push_back(publicInfo, json_new_a("nodeInfo", "xx")); - json_push_back(publicInfo, json_new_a("version", g_szMirVer)); - - json_push_back(node, privateInfo); - json_push_back(node, publicInfo); - - ptrA data(mir_utf8encodeT(ptrT(json_write(node)))); - - Body << - VALUE(data); - - json_delete(node); + GetComputerName(compName, &size); + + JSONNode privateInfo(JSON_NODE); + privateInfo.set_name("privateInfo"); + privateInfo.push_back(JSONNode("epname", T2Utf(compName))); + + JSONNode publicInfo(JSON_NODE); + publicInfo.set_name("publicInfo"); + publicInfo.push_back(JSONNode("capabilities", "Audio|Video")); + publicInfo.push_back(JSONNode("typ", 125)); + publicInfo.push_back(JSONNode("skypeNameVersion", "Miranda NG Skype")); + publicInfo.push_back(JSONNode("nodeInfo", "xx")); + publicInfo.push_back(JSONNode("version", g_szMirVer)); + + JSONNode node(JSON_NODE); + node.push_back(JSONNode("id", "messagingService")); + node.push_back(JSONNode("type", "EndpointPresenceDoc")); + node.push_back(JSONNode("selfLink", "uri")); + node.push_back(privateInfo); + node.push_back(publicInfo); + + Body << VALUE(node.write().c_str()); } }; #endif //_SKYPE_REQUEST_CAPS_H_ \ No newline at end of file diff --git a/protocols/SkypeWeb/src/requests/chatrooms.h b/protocols/SkypeWeb/src/requests/chatrooms.h index 57e76b2cf2..fa91a712a9 100644 --- a/protocols/SkypeWeb/src/requests/chatrooms.h +++ b/protocols/SkypeWeb/src/requests/chatrooms.h @@ -48,16 +48,13 @@ public: << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken) << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8"); - JSONNODE *node = json_new(5); - json_push_back(node, json_new_i("clientmessageid", timestamp)); - json_push_back(node, json_new_a("messagetype", "RichText")); - json_push_back(node, json_new_a("contenttype", "text")); - json_push_back(node, json_new_a("content", ptrA(mir_utf8encode(message)))); + JSONNode node(JSON_NODE); + node.push_back(JSONNode("clientmessageid", (long)timestamp)); + node.push_back(JSONNode("messagetype", "RichText")); + node.push_back(JSONNode("contenttype", "text")); + node.push_back(JSONNode("content", ptrA(mir_utf8encode(message)))); - T2Utf data(ptrT(json_write(node))); - Body << VALUE(data); - - json_delete(node); + Body << VALUE(node.write().c_str()); } }; @@ -72,17 +69,14 @@ public: << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken) << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8"); - JSONNODE *node = json_new(5); - json_push_back(node, json_new_i("clientmessageid", timestamp)); - json_push_back(node, json_new_a("messagetype", "RichText")); - json_push_back(node, json_new_a("contenttype", "text")); - json_push_back(node, json_new_a("content", ptrA(mir_utf8encode(message)))); - json_push_back(node, json_new_i("skypeemoteoffset", 4)); - - T2Utf data(ptrT(json_write(node))); - Body << VALUE(data); + JSONNode node(JSON_NODE); + node.push_back(JSONNode("clientmessageid", (long)timestamp)); + node.push_back(JSONNode("messagetype", "RichText")); + node.push_back(JSONNode("contenttype", "text")); + node.push_back(JSONNode("content", ptrA(mir_utf8encode(message)))); + node.push_back(JSONNode("skypeemoteoffset", 4)); - json_delete(node); + Body << VALUE(node.write().c_str()); } }; diff --git a/protocols/SkypeWeb/src/requests/messages.h b/protocols/SkypeWeb/src/requests/messages.h index 3523a95f47..b55d759a22 100644 --- a/protocols/SkypeWeb/src/requests/messages.h +++ b/protocols/SkypeWeb/src/requests/messages.h @@ -28,16 +28,14 @@ public: << CHAR_VALUE("Accept", "application/json, text/javascript") << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken) << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8"); - JSONNODE *node = json_new(5); - json_push_back(node, json_new_i("clientmessageid", timestamp)); - json_push_back(node, json_new_a("messagetype", "RichText")); - json_push_back(node, json_new_a("contenttype", "text")); - json_push_back(node, json_new_a("content", message)); - T2Utf data(ptrT(json_write(node))); - Body << VALUE(data); + JSONNode node(JSON_NODE); + node.push_back(JSONNode("clientmessageid", (long)timestamp)); + node.push_back(JSONNode("messagetype", "RichText")); + node.push_back(JSONNode("contenttype", "text")); + node.push_back(JSONNode("content", message)); - json_delete(node); + Body << VALUE(node.write().c_str()); } }; @@ -55,17 +53,14 @@ public: CMStringA content; content.AppendFormat("%s %s", username, message); - JSONNODE *node = json_new(5); - json_push_back(node, json_new_i("clientmessageid", timestamp)); - json_push_back(node, json_new_a("messagetype", "RichText")); - json_push_back(node, json_new_a("contenttype", "text")); - json_push_back(node, json_new_a("content", content)); - json_push_back(node, json_new_i("skypeemoteoffset", (int)(mir_strlen(username) + 1))); - - T2Utf data(ptrT(json_write(node))); - Body << VALUE(data); + JSONNode node(JSON_NODE); + node.push_back(JSONNode("clientmessageid", (long)timestamp)); + node.push_back(JSONNode("messagetype", "RichText")); + node.push_back(JSONNode("contenttype", "text")); + node.push_back(JSONNode("content", content)); + node.push_back(JSONNode("skypeemoteoffset", (int)(mir_strlen(username) + 1))); - json_delete(node); + Body << VALUE(node.write().c_str()); } }; @@ -82,23 +77,20 @@ public: char *state = (iState == PROTOTYPE_SELFTYPING_ON) ? "Control/Typing" : "Control/ClearTyping"; - JSONNODE *node = json_new(5); - json_push_back(node, json_new_i("clientmessageid", time(NULL))); - json_push_back(node, json_new_a("messagetype", state)); - json_push_back(node, json_new_a("contenttype", "text")); - json_push_back(node, json_new_a("content", "")); - - T2Utf data(ptrT(json_write(node))); - Body << VALUE(data); + JSONNode node(JSON_NODE); + node.push_back(JSONNode("clientmessageid", (long)time(NULL))); + node.push_back(JSONNode("messagetype", state)); + node.push_back(JSONNode("contenttype", "text")); + node.push_back(JSONNode("content", "")); - json_delete(node); + Body << VALUE(node.write().c_str()); } }; class MarkMessageReadRequest : public HttpRequest { public: - MarkMessageReadRequest(const char *username, const char *regToken, LONGLONG msgId = 0, LONGLONG msgTimestamp = 0, bool isChat = false, const char *server = SKYPE_ENDPOINTS_HOST) : + MarkMessageReadRequest(const char *username, const char *regToken, LONGLONG /*msgId*/ = 0, LONGLONG msgTimestamp = 0, bool isChat = false, const char *server = SKYPE_ENDPOINTS_HOST) : HttpRequest(REQUEST_PUT, FORMAT, "%s/v1/users/ME/conversations/%s:%s/properties?name=consumptionhorizon", server, !isChat ? "8" : "19", username) { Headers diff --git a/protocols/SkypeWeb/src/requests/subscriptions.h b/protocols/SkypeWeb/src/requests/subscriptions.h index c0777819b0..7c46df3f35 100644 --- a/protocols/SkypeWeb/src/requests/subscriptions.h +++ b/protocols/SkypeWeb/src/requests/subscriptions.h @@ -29,24 +29,19 @@ public: << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken) << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8"); - JSONNODE *node = json_new(5); - JSONNODE *interestedResources = json_new(4); - json_set_name(interestedResources, "interestedResources"); + JSONNode interestedResources(JSON_ARRAY); + interestedResources.set_name("interestedResources"); + interestedResources.push_back(JSONNode("", "/v1/users/ME/conversations/ALL/properties")); + interestedResources.push_back(JSONNode("", "/v1/users/ME/conversations/ALL/messages")); + interestedResources.push_back(JSONNode("", "/v1/users/ME/contacts/ALL")); + interestedResources.push_back(JSONNode("", "/v1/threads/ALL")); - json_push_back(node, json_new_a("channelType", "httpLongPoll")); - json_push_back(node, json_new_a("template", "raw")); + JSONNode node(JSON_NODE); + node.push_back(JSONNode("channelType", "httpLongPoll")); + node.push_back(JSONNode("template", "raw")); + node.push_back(interestedResources); - json_push_back(interestedResources, json_new_a(NULL, "/v1/users/ME/conversations/ALL/properties")); - json_push_back(interestedResources, json_new_a(NULL, "/v1/users/ME/conversations/ALL/messages")); - json_push_back(interestedResources, json_new_a(NULL, "/v1/users/ME/contacts/ALL")); - json_push_back(interestedResources, json_new_a(NULL, "/v1/threads/ALL")); - json_push_back(node, interestedResources); - - T2Utf data(ptrT(json_write(node))); - - Body << VALUE(data); - - json_delete(node); + Body << VALUE(node.write().c_str()); } }; diff --git a/protocols/SkypeWeb/src/requests/trouter.h b/protocols/SkypeWeb/src/requests/trouter.h index 1d68e78470..7a9a0ca684 100644 --- a/protocols/SkypeWeb/src/requests/trouter.h +++ b/protocols/SkypeWeb/src/requests/trouter.h @@ -38,11 +38,10 @@ public: << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8") << CHAR_VALUE("X-Skypetoken", token); - JSONNODE *node = json_new(5); - json_push_back(node, json_new_a("sr", sr)); + JSONNode node(JSON_NODE); + node.push_back(JSONNode("sr", sr)); - Body << VALUE(T2Utf(ptrT(json_write(node)))); - json_delete(node); + Body << VALUE(node.write().c_str()); } //{"sr":"AUKRNgA8_eKV0Ibsx037Gbd8GVrsDg8zLQRt1pH8sCyIAile3gtoWmlq2x1yZ_VNZ3tf","issuer":"edf","sp":"connect","st":"1430236511619","se":"1430318082619","sig":"nYczCdlBENCxoAFLy7lPkGELVV1w5TcUnpSUE2G7GLA"} }; @@ -57,37 +56,31 @@ public: << CHAR_VALUE("Accept", "application/json, text/javascript, text/html,application/xhtml+xml, application/xml") << CHAR_VALUE("X-Skypetoken", token); - JSONNODE *node = json_new(5); - JSONNODE *clientDescription = json_new(5); - JSONNODE *transports = json_new(5); - JSONNODE *TRouter = json_new(5); - JSONNODE *TROUTER = json_new(4); + JSONNode clientDescription(JSON_NODE); + clientDescription.set_name("clientDescription"); + clientDescription.push_back(JSONNode("aesKey", "")); + clientDescription.push_back(JSONNode("languageId", "en-US")); + clientDescription.push_back(JSONNode("platform", "SWX")); + clientDescription.push_back(JSONNode("templateKey", "SkypeWeb_1.0")); - json_set_name(clientDescription, "clientDescription"); - json_set_name(transports, "transports"); - json_set_name(TROUTER, "TROUTER"); + JSONNode TRouter(JSON_NODE); + TRouter.push_back(JSONNode("context", "")); + TRouter.push_back(JSONNode("path", trouterUrl)); + TRouter.push_back(JSONNode("ttl", 3600)); - json_push_back(node, json_new_a("registrationId", id)); - json_push_back(node, json_new_a("nodeId", "")); + JSONNode TROUTER (JSON_ARRAY); TROUTER.set_name("TROUTER"); + TROUTER.push_back(TRouter); - json_push_back(clientDescription, json_new_a("aesKey", "")); - json_push_back(clientDescription, json_new_a("languageId", "en-US")); - json_push_back(clientDescription, json_new_a("platform", "SWX")); - json_push_back(clientDescription, json_new_a("templateKey", "SkypeWeb_1.0")); - json_push_back(node, clientDescription); + JSONNode transports(JSON_NODE); transports.set_name("transports"); + transports.push_back(TROUTER); - json_push_back(TRouter, json_new_a("context", "")); - json_push_back(TRouter, json_new_a("path", trouterUrl)); - json_push_back(TRouter, json_new_i("ttl", 3600)); - json_push_back(TROUTER, TRouter); - json_push_back(transports, TROUTER); - json_push_back(node, transports); + JSONNode node(JSON_NODE); + node.push_back(JSONNode("registrationId", id)); + node.push_back(JSONNode("nodeId", "")); + node.push_back(clientDescription); + node.push_back(transports); - T2Utf data(ptrT(json_write(node))); - - Body << VALUE(data); - - json_delete(node); + Body << VALUE(node.write().c_str()); } }; @@ -109,21 +102,21 @@ public: class GetTrouterRequest : public HttpRequest { public: - GetTrouterRequest(const char *socketio, const char *sr, const char *st, const char *se, const char *sig, - const char *instance, const char *ccid) : - HttpRequest(REQUEST_GET, FORMAT, "%ssocket.io/1/", socketio) + GetTrouterRequest(const std::string &socketio, const std::string &sr, const std::string &st, const std::string &se, const std::string &sig, + const std::string &instance, const std::string &ccid) : + HttpRequest(REQUEST_GET, FORMAT, "%ssocket.io/1/", socketio.c_str()) { Url - << CHAR_VALUE("sr", sr) + << CHAR_VALUE("sr", sr.c_str()) << CHAR_VALUE("issuer", "edf") << CHAR_VALUE("sp", "connect") - << CHAR_VALUE("st", st) - << CHAR_VALUE("se", se) - << CHAR_VALUE("sig", sig) - << CHAR_VALUE("r", instance) + << CHAR_VALUE("st", st.c_str()) + << CHAR_VALUE("se", se.c_str()) + << CHAR_VALUE("sig", sig.c_str()) + << CHAR_VALUE("r", instance.c_str()) << CHAR_VALUE("v", "v2") << INT_VALUE("p", 443) - << CHAR_VALUE("ccid", ccid) + << CHAR_VALUE("ccid", ccid.c_str()) << CHAR_VALUE("tc", ptrA(mir_urlEncode("{\"cv\":\"2014.8.26\",\"hr\":\"\",\"ua\":\"Miranda_NG\",\"v\":\"\"}"))) << INT_VALUE("t", time(NULL) * 1000); @@ -135,23 +128,23 @@ public: class TrouterPollRequest : public HttpRequest { public: - TrouterPollRequest(const char *socketio, const char *sr, const char *st, const char *se, const char *sig, - const char *instance, const char *ccid, const char *sessId) : - HttpRequest(REQUEST_GET, FORMAT, "%ssocket.io/1/xhr-polling/%s", socketio, sessId) + TrouterPollRequest(const std::string &socketio, const std::string &sr, const std::string &st, const std::string &se, const std::string &sig, + const std::string &instance, const std::string &ccid, const std::string &sessId) : + HttpRequest(REQUEST_GET, FORMAT, "%ssocket.io/1/xhr-polling/%s", socketio.c_str(), sessId.c_str()) { timeout = INFINITE; flags |= NLHRF_PERSISTENT; Url - << CHAR_VALUE("sr", sr) + << CHAR_VALUE("sr", sr.c_str()) << CHAR_VALUE("issuer", "edf") << CHAR_VALUE("sp", "connect") - << CHAR_VALUE("st", st) - << CHAR_VALUE("se", se) - << CHAR_VALUE("sig", sig) - << CHAR_VALUE("r", instance) + << CHAR_VALUE("st", st.c_str()) + << CHAR_VALUE("se", se.c_str()) + << CHAR_VALUE("sig", sig.c_str()) + << CHAR_VALUE("r", instance.c_str()) << CHAR_VALUE("v", "v2") << INT_VALUE("p", 443) - << CHAR_VALUE("ccid", ccid) + << CHAR_VALUE("ccid", ccid.c_str()) << CHAR_VALUE("tc", ptrA(mir_urlEncode("{\"cv\":\"2014.8.26\",\"hr\":\"\",\"ua\":\"Miranda_NG\",\"v\":\"\"}"))) << INT_VALUE("t", time(NULL) * 1000); diff --git a/protocols/SkypeWeb/src/skype_avatars.cpp b/protocols/SkypeWeb/src/skype_avatars.cpp index 9effeb2554..c283258d1e 100644 --- a/protocols/SkypeWeb/src/skype_avatars.cpp +++ b/protocols/SkypeWeb/src/skype_avatars.cpp @@ -82,8 +82,8 @@ void CSkypeProto::OnSentAvatar(const NETLIBHTTPREQUEST *response) if (response == NULL) return; - JSONROOT root(response->pData); - if (root == NULL) + JSONNode root = JSONNode::parse(response->pData); + if (!root) return; } diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp index 9b4fb075cd..b9feae34e1 100644 --- a/protocols/SkypeWeb/src/skype_chatrooms.cpp +++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp @@ -103,38 +103,33 @@ void CSkypeProto::OnLoadChats(const NETLIBHTTPREQUEST *response) if (response == NULL) return; - JSONROOT root(response->pData); - - if (root == NULL) + JSONNode root = JSONNode::parse(response->pData); + if (!root) return; - JSONNODE *metadata = json_get(root, "_metadata"); - JSONNODE *conversations = json_as_array(json_get(root, "conversations")); + const JSONNode &metadata = root["_metadata"]; + const JSONNode &conversations = root["conversations"].as_array(); - int totalCount = json_as_int(json_get(metadata, "totalCount")); - ptrA syncState(mir_t2a(ptrT(json_as_string(json_get(metadata, "syncState"))))); + int totalCount = metadata["totalCount"].as_int(); + std::string syncState = metadata["syncState"].as_string(); - if (totalCount >= 99 || json_size(conversations) >= 99) - PushRequest(new SyncHistoryFirstRequest(syncState, RegToken), &CSkypeProto::OnSyncHistory); + if (totalCount >= 99 || conversations.size() >= 99) + PushRequest(new SyncHistoryFirstRequest(syncState.c_str(), RegToken), &CSkypeProto::OnSyncHistory); - for (size_t i = 0; i < json_size(conversations); i++) + for (size_t i = 0; i < conversations.size(); i++) { - JSONNODE *conversation = json_at(conversations, i); - JSONNODE *lastMessage = json_get(conversation, "lastMessage"); - JSONNODE *threadProperties = json_get(conversation, "threadProperties"); - if (json_empty(lastMessage)) + const JSONNode &conversation = conversations.at(i); + const JSONNode &lastMessage = conversation["lastMessage"]; + const JSONNode &threadProperties = conversation["threadProperties"]; + if (!lastMessage) continue; - char *conversationLink = mir_t2a(json_as_string(json_get(lastMessage, "conversationLink"))); - - ptrA skypename; - TCHAR *topic; - - if (conversationLink != NULL && strstr(conversationLink, "/19:")) + std::string conversationLink = lastMessage["conversationLink"].as_string(); + if (conversationLink.find("/19:") != -1) { - skypename = ChatUrlToName(conversationLink); - topic = json_as_string(json_get(threadProperties, "topic")); - SendRequest(new GetChatInfoRequest(RegToken, skypename, Server), &CSkypeProto::OnGetChatInfo, topic); + ptrA skypename(ChatUrlToName(conversationLink.c_str())); + CMString topic(threadProperties["topic"].as_mstring()); + SendRequest(new GetChatInfoRequest(RegToken, skypename, Server), &CSkypeProto::OnGetChatInfo, topic.Detach()); } } } @@ -265,37 +260,37 @@ INT_PTR CSkypeProto::OnLeaveChatRoom(WPARAM hContact, LPARAM) /* CHAT EVENT */ -void CSkypeProto::OnChatEvent(JSONNODE *node) +void CSkypeProto::OnChatEvent(const JSONNode &node) { - ptrA clientMsgId(mir_t2a(ptrT(json_as_string(json_get(node, "clientmessageid"))))); - ptrA skypeEditedId(mir_t2a(ptrT(json_as_string(json_get(node, "skypeeditedid"))))); + std::string clientMsgId = node["clientmessageid"].as_string(); + std::string skypeEditedId = node["skypeeditedid"].as_string(); - ptrA fromLink(mir_t2a(ptrT(json_as_string(json_get(node, "from"))))); - ptrA from(ContactUrlToName(fromLink)); + std::string fromLink = node["from"].as_string(); + ptrA from(ContactUrlToName(fromLink.c_str())); - time_t timestamp = IsoToUnixTime(ptrT(json_as_string(json_get(node, "composetime")))); + time_t timestamp = IsoToUnixTime(node["composetime"].as_string().c_str()); - ptrA content(mir_t2a(ptrT(json_as_string(json_get(node, "content"))))); - int emoteOffset = atoi(ptrA(mir_t2a(ptrT(json_as_string(json_get(node, "skypeemoteoffset")))))); + std::string content = node["content"].as_string(); + int emoteOffset = node["skypeemoteoffset"].as_int(); - ptrA conversationLink(mir_t2a(ptrT(json_as_string(json_get(node, "conversationLink"))))); - ptrA chatname(ChatUrlToName(conversationLink)); + std::string conversationLink = node["conversationLink"].as_string(); + ptrA chatname(ChatUrlToName(conversationLink.c_str())); - TCHAR *topic(json_as_string(json_get(node, "threadtopic"))); + CMString topic(node["threadtopic"].as_mstring()); + if (FindChatRoom(chatname) == NULL) + SendRequest(new GetChatInfoRequest(RegToken, chatname, Server), &CSkypeProto::OnGetChatInfo, topic.Detach()); - if (FindChatRoom(chatname) == NULL) SendRequest(new GetChatInfoRequest(RegToken, chatname, Server), &CSkypeProto::OnGetChatInfo, topic); - - ptrA messageType(mir_t2a(ptrT(json_as_string(json_get(node, "messagetype"))))); - if (!mir_strcmpi(messageType, "Text") || !mir_strcmpi(messageType, "RichText")) + std::string messageType = node["messagetype"].as_string(); + if (!mir_strcmpi(messageType.c_str(), "Text") || !mir_strcmpi(messageType.c_str(), "RichText")) { - AddMessageToChat(_A2T(chatname), _A2T(from), content, emoteOffset != NULL, emoteOffset, timestamp); + AddMessageToChat(_A2T(chatname), _A2T(from), content.c_str(), emoteOffset != NULL, emoteOffset, timestamp); } - else if (!mir_strcmpi(messageType, "ThreadActivity/AddMember")) + else if (!mir_strcmpi(messageType.c_str(), "ThreadActivity/AddMember")) { ptrA xinitiator, xtarget, initiator, target; //content = 14291862291648:initiator8:user - HXML xml = xi.parseString(ptrT(mir_a2t(content)), 0, _T("addmember")); + HXML xml = xi.parseString(ptrT(mir_a2t(content.c_str())), 0, _T("addmember")); if (xml == NULL) return; @@ -305,7 +300,7 @@ void CSkypeProto::OnChatEvent(JSONNODE *node) if (xmlNode == NULL) break; - xtarget = xmlNode != NULL ? mir_t2a(xi.getText(xmlNode)) : NULL; + xtarget = mir_t2a(xi.getText(xmlNode)); target = ParseUrl(xtarget, "8:"); @@ -313,12 +308,12 @@ void CSkypeProto::OnChatEvent(JSONNODE *node) } xi.destroyNode(xml); } - else if (!mir_strcmpi(messageType, "ThreadActivity/DeleteMember")) + else if (!mir_strcmpi(messageType.c_str(), "ThreadActivity/DeleteMember")) { ptrA xinitiator, xtarget, initiator, target; //content = 14291862291648:initiator8:user - HXML xml = xi.parseString(ptrT(mir_a2t(content)), 0, _T("deletemember")); + HXML xml = xi.parseString(ptrT(mir_a2t(content.c_str())), 0, _T("deletemember")); if (xml != NULL) { HXML xmlNode = xi.getChildByPath(xml, _T("initiator"), 0); xinitiator = node != NULL ? mir_t2a(xi.getText(xmlNode)) : NULL; @@ -337,11 +332,11 @@ void CSkypeProto::OnChatEvent(JSONNODE *node) RemoveChatContact(_A2T(chatname), target, target, true, initiator); } - else if (!mir_strcmpi(messageType, "ThreadActivity/TopicUpdate")) + else if (!mir_strcmpi(messageType.c_str(), "ThreadActivity/TopicUpdate")) { //content=14295327021308:usertest topic ptrA xinitiator, value, initiator; - HXML xml = xi.parseString(ptrT(mir_a2t(content)), 0, _T("topicupdate")); + HXML xml = xi.parseString(ptrT(mir_a2t(content.c_str())), 0, _T("topicupdate")); if (xml != NULL) { HXML xmlNode = xi.getChildByPath(xml, _T("initiator"), 0); xinitiator = xmlNode != NULL ? mir_t2a(xi.getText(xmlNode)) : NULL; @@ -356,11 +351,11 @@ void CSkypeProto::OnChatEvent(JSONNODE *node) RenameChat(chatname, value); ChangeChatTopic(chatname, value, initiator); } - else if (!mir_strcmpi(messageType, "ThreadActivity/RoleUpdate")) + else if (!mir_strcmpi(messageType.c_str(), "ThreadActivity/RoleUpdate")) { //content=14295512583638:user8:user1admin ptrA xinitiator, xId, initiator, id, xRole; - HXML xml = xi.parseString(ptrT(mir_a2t(content)), 0, _T("roleupdate")); + HXML xml = xi.parseString(ptrT(mir_a2t(content.c_str())), 0, _T("roleupdate")); if (xml != NULL) { HXML xmlNode = xi.getChildByPath(xml, _T("initiator"), 0); xinitiator = xmlNode != NULL ? mir_t2a(xi.getText(xmlNode)) : NULL; @@ -439,23 +434,25 @@ void CSkypeProto::OnGetChatInfo(const NETLIBHTTPREQUEST *response, void *p) if (response == NULL || response->pData == NULL) return; - JSONROOT root(response->pData); - JSONNODE *members = json_get(root, "members"); - JSONNODE *properties = json_get(root, "properties"); + JSONNode root = JSONNode::parse(response->pData); + if (!root) + return; - if (json_empty(json_get(properties, "capabilities"))) + const JSONNode &members = root["members"]; + const JSONNode &properties = root["properties"]; + if (!properties["capabilities"]) return; - ptrA chatId(ChatUrlToName(mir_t2a(ptrT(json_as_string(json_get(root, "messages")))))); + ptrA chatId(ChatUrlToName(root["messages"].as_string().c_str())); StartChatRoom(_A2T(chatId), mir_tstrdup(topic)); - for (size_t i = 0; i < json_size(members); i++) + for (size_t i = 0; i < members.size(); i++) { - JSONNODE *member = json_at(members, i); + const JSONNode &member = members.at(i); - ptrA username(ContactUrlToName(ptrA(mir_t2a(ptrT(json_as_string(json_get(member, "userLink"))))))); - ptrT role(json_as_string(json_get(member, "role"))); + ptrA username(ContactUrlToName(member["userLink"].as_string().c_str())); + std::string role = member["role"].as_string(); if (!IsChatContact(_A2T(chatId), username)) - AddChatContact(_A2T(chatId), username, username, role, true); + AddChatContact(_A2T(chatId), username, username, _A2T(role.c_str()), true); } PushRequest(new GetHistoryRequest(RegToken, chatId, 15, true, 0, Server), &CSkypeProto::OnGetServerHistory); mir_free(topic); diff --git a/protocols/SkypeWeb/src/skype_contacts.cpp b/protocols/SkypeWeb/src/skype_contacts.cpp index 42366808d4..76e6b83a3c 100644 --- a/protocols/SkypeWeb/src/skype_contacts.cpp +++ b/protocols/SkypeWeb/src/skype_contacts.cpp @@ -115,32 +115,22 @@ void CSkypeProto::LoadContactsAuth(const NETLIBHTTPREQUEST *response) if (response == NULL) return; - - JSONROOT root(response->pData); - if (root == NULL) + JSONNode root = JSONNode::parse(response->pData); + if (!root) return; - JSONNODE *items = json_as_array(root), *item, *node; - for (size_t i = 0; i < json_size(items); i++) + const JSONNode &items = root.as_array(); + for (size_t i = 0; i < items.size(); i++) { - item = json_at(items, i); - if (item == NULL) + const JSONNode &item = items.at(i); + if (!item) break; - node = json_get(item, "sender"); - ptrA skypename(mir_t2a(ptrT(json_as_string(node)))); - - node = json_get(root, "greeting"); - CMStringA reason = ptrA(mir_t2a(ptrT(json_as_string(node)))); - - node = json_get(root, "event_time_iso"); - ptrT eventTimeStr(json_as_string(node)); - time_t eventTime = IsoToUnixTime(eventTimeStr); + std::string skypename = item["sender"].as_string(); + std::string reason = root["greeting"].as_string(); + time_t eventTime = IsoToUnixTime(root["event_time_iso"].as_string().c_str()); - //if (reason == "null") - // reason.Empty(); - - MCONTACT hContact = AddContact(skypename); + MCONTACT hContact = AddContact(skypename.c_str()); if (hContact) { time_t lastEventTime = db_get_dw(hContact, m_szModuleName, "LastAuthRequestTime", 0); @@ -152,7 +142,7 @@ void CSkypeProto::LoadContactsAuth(const NETLIBHTTPREQUEST *response) PROTORECVEVENT pre = { 0 }; pre.timestamp = time(NULL); - pre.lParam = (DWORD)(sizeof(DWORD) * 2 + mir_strlen(skypename) + reason.GetLength() + 5); + pre.lParam = (DWORD)(sizeof(DWORD) * 2 + skypename.size() + reason.size() + 5); /*blob is: 0(DWORD), hContact(DWORD), nick(ASCIIZ), firstName(ASCIIZ), lastName(ASCIIZ), id(ASCIIZ), reason(ASCIIZ)*/ PBYTE pBlob, pCurBlob; @@ -163,16 +153,15 @@ void CSkypeProto::LoadContactsAuth(const NETLIBHTTPREQUEST *response) *((PDWORD)pCurBlob) = (DWORD)hContact; pCurBlob += sizeof(DWORD); pCurBlob += 3; - mir_strcpy((char*)pCurBlob, skypename); - pCurBlob += mir_strlen(skypename) + 1; - mir_strcpy((char*)pCurBlob, reason); + mir_strcpy((char*)pCurBlob, skypename.c_str()); + pCurBlob += skypename.size() + 1; + mir_strcpy((char*)pCurBlob, reason.c_str()); pre.szMessage = (char*)pBlob; ProtoChainRecv(hContact, PSR_AUTH, 0, (LPARAM)&pre); } } } - json_delete(items); } //[{"username":"echo123", "firstname" : "Echo \/ Sound Test Service", "lastname" : null, "avatarUrl" : null, "mood" : null, "richMood" : null, "displayname" : null, "country" : null, "city" : null},...] @@ -181,20 +170,19 @@ void CSkypeProto::LoadContactsInfo(const NETLIBHTTPREQUEST *response) if (response == NULL) return; - JSONROOT root(response->pData); - if (root == NULL) + JSONNode root = JSONNode::parse(response->pData); + if (!root) return; - JSONNODE *items = json_as_array(root), *item, *node; - for (size_t i = 0; i < json_size(items); i++) + const JSONNode &items = root.as_array(); + for (size_t i = 0; i < items.size(); i++) { - item = json_at(items, i); - if (item == NULL) + const JSONNode &item = items.at(i); + if (!item) break; - node = json_get(item, "username"); - ptrA skypename(mir_t2a(ptrT(json_as_string(node)))); - MCONTACT hContact = AddContact(skypename); + std::string skypename = item["username"].as_string(); + MCONTACT hContact = AddContact(skypename.c_str()); if (hContact) { UpdateProfileFirstName(item, hContact); @@ -206,7 +194,6 @@ void CSkypeProto::LoadContactsInfo(const NETLIBHTTPREQUEST *response) UpdateProfileAvatar(item, hContact); } } - json_delete(items); } //[{"skypename":"echo123", "authorized" : true, "blocked" : false, ...},...] @@ -216,36 +203,31 @@ void CSkypeProto::LoadContactList(const NETLIBHTTPREQUEST *response) if (response == NULL) return; - JSONROOT root(response->pData); - if (root == NULL) + JSONNode root = JSONNode::parse(response->pData); + if (!root) return; LIST skypenames(1); - JSONNODE *items = json_as_array(root), *item, *node; - for (size_t i = 0; i < json_size(items); i++) + const JSONNode &items = root.as_array(); + for (size_t i = 0; i < items.size(); i++) { - item = json_at(items, i); - if (item == NULL) + const JSONNode &item = items.at(i); + if (!item) break; - node = json_get(item, "skypename"); - ptrA skypename(mir_t2a(ptrT(json_as_string(node)))); - MCONTACT hContact = AddContact(skypename); + std::string skypename = item["skypename"].as_string(); + MCONTACT hContact = AddContact(skypename.c_str()); if (hContact) { - node = json_get(item, "authorized"); - if (json_as_bool(node)) + if (item["authorized"].as_bool()) { delSetting(hContact, "Auth"); delSetting(hContact, "Grant"); } - else - setByte(hContact, "Grant", 1); + else setByte(hContact, "Grant", 1); - node = json_get(item, "blocked"); - bool isBlocked = (json_as_bool(node) != 0); - if (isBlocked) + if (item["blocked"].as_bool()) { db_set_dw(hContact, "Ignore", "Mask1", 127); db_set_b(hContact, "CList", "Hidden", 1); @@ -261,10 +243,9 @@ void CSkypeProto::LoadContactList(const NETLIBHTTPREQUEST *response) } } - skypenames.insert(mir_strdup(skypename)); + skypenames.insert(mir_strdup(skypename.c_str())); } } - json_delete(items); ptrA token(getStringA("TokenSecret")); if (skypenames.getCount() > 0) diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp index 834b9a8c12..e60131b490 100644 --- a/protocols/SkypeWeb/src/skype_history_sync.cpp +++ b/protocols/SkypeWeb/src/skype_history_sync.cpp @@ -24,41 +24,39 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) if (response == NULL) return; - JSONROOT root(response->pData); - if (root == NULL) + JSONNode root = JSONNode::parse(response->pData); + if (!root) return; - JSONNODE *metadata = json_get(root, "_metadata"); - JSONNODE *conversations = json_as_array(json_get(root, "messages")); + const JSONNode &metadata = root["_metadata"]; + const JSONNode &conversations = root["messages"].as_array(); - int totalCount = json_as_int(json_get(metadata, "totalCount")); - ptrA syncState(mir_t2a(ptrT(json_as_string(json_get(metadata, "syncState"))))); + int totalCount = metadata["totalCount"].as_int(); + std::string syncState = metadata["syncState"].as_string(); bool markAllAsUnread = getBool("MarkMesUnread", false); - if (totalCount >= 99 || json_size(conversations) >= 99) - PushRequest(new GetHistoryOnUrlRequest(syncState, RegToken), &CSkypeProto::OnGetServerHistory); + if (totalCount >= 99 || conversations.size() >= 99) + PushRequest(new GetHistoryOnUrlRequest(syncState.c_str(), RegToken), &CSkypeProto::OnGetServerHistory); - for (int i = json_size(conversations); i >= 0; i--) + for (int i = (int)conversations.size(); i >= 0; i--) { - JSONNODE *message = json_at(conversations, i); - - ptrA clientMsgId(mir_t2a(ptrT(json_as_string(json_get(message, "clientmessageid"))))); - ptrA skypeEditedId(mir_t2a(ptrT(json_as_string(json_get(message, "skypeeditedid"))))); - ptrA messageType(mir_t2a(ptrT(json_as_string(json_get(message, "messagetype"))))); - ptrA from(mir_t2a(ptrT(json_as_string(json_get(message, "from"))))); - ptrA content(mir_t2a(ptrT(json_as_string(json_get(message, "content"))))); - ptrT composeTime(json_as_string(json_get(message, "composetime"))); - ptrA conversationLink(mir_t2a(ptrT(json_as_string(json_get(message, "conversationLink"))))); - int emoteOffset = atoi(ptrA(mir_t2a(ptrT(json_as_string(json_get(message, "skypeemoteoffset")))))); - time_t timestamp = IsoToUnixTime(composeTime); - ptrA skypename(ContactUrlToName(from)); - - bool isEdited = (json_get(message, "skypeeditedid") != NULL); - - MCONTACT hContact = FindContact(ptrA(ContactUrlToName(conversationLink))); - - + const JSONNode &message = conversations.at(i); + + std::string clientMsgId = message["clientmessageid"].as_string(); + std::string skypeEditedId = message["skypeeditedid"].as_string(); + std::string messageType = message["messagetype"].as_string(); + std::string from = message["from"].as_string(); + std::string content = message["content"].as_string(); + std::string conversationLink = message["conversationLink"].as_string(); + int emoteOffset = message["skypeemoteoffset"].as_int(); + time_t timestamp = IsoToUnixTime(message["composetime"].as_string().c_str()); + ptrA skypename(ContactUrlToName(from.c_str())); + + bool isEdited = message["skypeeditedid"]; + + MCONTACT hContact = FindContact(ptrA(ContactUrlToName(conversationLink.c_str()))); + if (timestamp > db_get_dw(hContact, m_szModuleName, "LastMsgTime", 0)) db_set_dw(hContact, m_szModuleName, "LastMsgTime", (DWORD)timestamp); @@ -70,13 +68,12 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) if (IsMe(skypename)) flags |= DBEF_SENT; - if (conversationLink != NULL && strstr(conversationLink, "/8:")) + if (strstr(conversationLink.c_str(), "/8:")) { - if (!mir_strcmpi(messageType, "Text") || !mir_strcmpi(messageType, "RichText")) + if (!mir_strcmpi(messageType.c_str(), "Text") || !mir_strcmpi(messageType.c_str(), "RichText")) { - - ptrA message(RemoveHtml(content)); - MEVENT dbevent = GetMessageFromDb(hContact, skypeEditedId); + ptrA message(RemoveHtml(content.c_str())); + MEVENT dbevent = GetMessageFromDb(hContact, skypeEditedId.c_str()); if (isEdited && dbevent != NULL) { @@ -100,20 +97,19 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) msg.AppendFormat("%s\n%s %s:\n%s", dbMsgText, Translate("Edited at"), _T2A(time), message); db_event_delete(hContact, dbevent); - AddMessageToDb(hContact, dbEventTimestamp, flags, clientMsgId, msg.GetBuffer(), emoteOffset); + AddMessageToDb(hContact, dbEventTimestamp, flags, clientMsgId.c_str(), msg.GetBuffer(), emoteOffset); } - else - AddMessageToDb(hContact, timestamp, flags, clientMsgId, message, emoteOffset); + else AddMessageToDb(hContact, timestamp, flags, clientMsgId.c_str(), message, emoteOffset); } - else if (!mir_strcmpi(messageType, "Event/Call")) + else if (!mir_strcmpi(messageType.c_str(), "Event/Call")) { //content=user name6 //Echo / Sound Test Service6 //content=user name int iType = 3, iDuration = 0; - ptrA skypename(ContactUrlToName(from)); - HXML xml = xi.parseString(ptrT(mir_a2t(content)), 0, _T("partlist")); + ptrA skypename(ContactUrlToName(from.c_str())); + HXML xml = xi.parseString(ptrT(mir_a2t(content.c_str())), 0, _T("partlist")); if (xml != NULL) { @@ -148,12 +144,12 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) csec.AppendFormat(sec < 10 ? "0%d" : "%d", sec); text.AppendFormat("%s\n%s: %s:%s:%s", Translate("Call ended"), Translate("Duration"), chours, cmins, csec); } - AddCallInfoToDb(hContact, timestamp, flags, clientMsgId, text.GetBuffer()); + AddCallInfoToDb(hContact, timestamp, flags, clientMsgId.c_str(), text.GetBuffer()); } - else if (!mir_strcmpi(messageType, "RichText/Files")) + else if (!mir_strcmpi(messageType.c_str(), "RichText/Files")) { //content=run.bat - HXML xml = xi.parseString(ptrT(mir_a2t(content)), 0, _T("files")); + HXML xml = xi.parseString(ptrT(mir_a2t(content.c_str())), 0, _T("files")); if (xml != NULL) { for (int i = 0; i < xi.getChildCount(xml); i++) @@ -169,15 +165,14 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) msg.Empty(); msg.AppendFormat("%s:\n\t%s: %s\n\t%s: %d %s", Translate("File transfer"), Translate("File name"), fileName, Translate("Size"), fileSize, Translate("bytes")); - AddMessageToDb(hContact, timestamp, flags, clientMsgId, msg.GetBuffer()); - + AddMessageToDb(hContact, timestamp, flags, clientMsgId.c_str(), msg.GetBuffer()); } } } - else if (!mir_strcmpi(messageType, "RichText/UriObject")) + else if (!mir_strcmpi(messageType.c_str(), "RichText/UriObject")) { //content=Для просмотра этого общего фото перейдите по ссылке: https://api.asm.skype.com/s/i?0-weu-d1-262f0a1ee256d03b8e4b8360d9208834 - HXML xml = xi.parseString(ptrT(mir_a2t(content)), 0, _T("URIObject")); + HXML xml = xi.parseString(ptrT(mir_a2t(content.c_str())), 0, _T("URIObject")); if (xml != NULL) { ptrA url(mir_t2a(xi.getAttrValue(xml, L"uri"))); @@ -185,17 +180,15 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) CMStringA data(FORMAT, "%s: https://api.asm.skype.com/s/i?%s", Translate("Image"), object); - AddMessageToDb(hContact, timestamp, flags, clientMsgId, data.GetBuffer()); + AddMessageToDb(hContact, timestamp, flags, clientMsgId.c_str(), data.GetBuffer()); } } //Picture } - else if (conversationLink != NULL && strstr(conversationLink, "/19:")) + else if (conversationLink.find("/19:") != -1) { - ptrA chatname(ChatUrlToName(conversationLink)); - if (!mir_strcmpi(messageType, "Text") || !mir_strcmpi(messageType, "RichText")) - { - AddMessageToChat(_A2T(chatname), _A2T(skypename), content, emoteOffset != NULL, emoteOffset, timestamp, true); - } + ptrA chatname(ChatUrlToName(conversationLink.c_str())); + if (!mir_strcmpi(messageType.c_str(), "Text") || !mir_strcmpi(messageType.c_str(), "RichText")) + AddMessageToChat(_A2T(chatname), _A2T(skypename), content.c_str(), emoteOffset != NULL, emoteOffset, timestamp, true); } } } @@ -210,35 +203,33 @@ void CSkypeProto::OnSyncHistory(const NETLIBHTTPREQUEST *response) { if (response == NULL || response->pData == NULL) return; - JSONROOT root(response->pData); - if (root == NULL) + JSONNode root = JSONNode::parse(response->pData); + if (!root) return; - JSONNODE *metadata = json_get(root, "_metadata"); - JSONNODE *conversations = json_as_array(json_get(root, "conversations")); + const JSONNode &metadata = root["_metadata"]; + const JSONNode &conversations = root["conversations"].as_array(); - int totalCount = json_as_int(json_get(metadata, "totalCount")); - ptrA syncState(mir_t2a(ptrT(json_as_string(json_get(metadata, "syncState"))))); + int totalCount = metadata["totalCount"].as_int(); + std::string syncState = metadata["syncState"].as_string(); - if (totalCount >= 99 || json_size(conversations) >= 99) - PushRequest(new SyncHistoryFirstRequest(syncState, RegToken), &CSkypeProto::OnSyncHistory); + if (totalCount >= 99 || conversations.size() >= 99) + PushRequest(new SyncHistoryFirstRequest(syncState.c_str(), RegToken), &CSkypeProto::OnSyncHistory); - for (size_t i = 0; i < json_size(conversations); i++) + for (size_t i = 0; i < conversations.size(); i++) { - JSONNODE *conversation = json_at(conversations, i); - JSONNODE *lastMessage = json_get(conversation, "lastMessage"); - if (json_empty(lastMessage)) + const JSONNode &conversation = conversations.at(i); + const JSONNode &lastMessage = conversation["lastMessage"]; + if (!lastMessage) continue; - char *conversationLink = mir_t2a(json_as_string(json_get(lastMessage, "conversationLink"))); - time_t composeTime(IsoToUnixTime(ptrT(json_as_string(json_get(lastMessage, "composetime"))))); - - ptrA skypename; + std::string conversationLink = lastMessage["conversationLink"].as_string(); + time_t composeTime(IsoToUnixTime(lastMessage["composetime"].as_string().c_str())); - if (conversationLink != NULL && strstr(conversationLink, "/8:")) + if (conversationLink.find("/8:") != -1) { - skypename = ContactUrlToName(conversationLink); + ptrA skypename(ContactUrlToName(conversationLink.c_str())); MCONTACT hContact = FindContact(skypename); if (hContact == NULL) continue; diff --git a/protocols/SkypeWeb/src/skype_login.cpp b/protocols/SkypeWeb/src/skype_login.cpp index 4c8462bf65..2f7738ae7c 100644 --- a/protocols/SkypeWeb/src/skype_login.cpp +++ b/protocols/SkypeWeb/src/skype_login.cpp @@ -223,12 +223,10 @@ void CSkypeProto::OnCapabilitiesSended(const NETLIBHTTPREQUEST *response) if (response == NULL || response->pData == NULL) return; - JSONROOT root(response->pData); - if (root == NULL) - return; - ptrA SelfEndpointName(SelfUrlToName(mir_t2a(ptrT(json_as_string(json_get(root, "selfLink")))))); - setString("SelfEndpointName", SelfEndpointName); + JSONNode root = JSONNode::parse(response->pData); + if (root) + setString("SelfEndpointName", root["selfLink"].as_string().c_str()); } void CSkypeProto::OnStatusChanged(const NETLIBHTTPREQUEST *response) @@ -241,7 +239,7 @@ void CSkypeProto::OnStatusChanged(const NETLIBHTTPREQUEST *response) return; } - JSONROOT json(response->pData); + JSONNode json = JSONNode::parse(response->pData); if (json == NULL) { debugLogA(__FUNCTION__ ": failed to change status"); @@ -250,8 +248,7 @@ void CSkypeProto::OnStatusChanged(const NETLIBHTTPREQUEST *response) return; } - ptrT status(json_as_string(json_get(json, "status"))); - int iNewStatus = SkypeToMirandaStatus(_T2A(status)); + int iNewStatus = SkypeToMirandaStatus(json["status"].as_string().c_str()); if (iNewStatus == ID_STATUS_OFFLINE) { debugLogA(__FUNCTION__ ": failed to change status"); @@ -264,4 +261,4 @@ void CSkypeProto::OnStatusChanged(const NETLIBHTTPREQUEST *response) m_iStatus = m_iDesiredStatus = iNewStatus; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus); ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_SUCCESS, NULL, 0); -} \ No newline at end of file +} diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index cdb52b4356..674033175b 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -84,17 +84,16 @@ void CSkypeProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg) if (response == NULL || (response->resultCode != 200 && response->resultCode != 201)) { - CMStringA error = "Unknown error"; + std::string error("Unknown error"); if (response) { - JSONROOT root(response->pData); - JSONNODE *node = json_get(root, "errorCode"); - error = _T2A(json_as_string(node)); + JSONNode root = JSONNode::parse(response->pData); + const JSONNode &node = root["errorCode"]; + error = node.as_string(); } ptrT username(getTStringA(hContact, "Skypename")); - debugLogA(__FUNCTION__": failed to send message for %s (%s)", username, error); - ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, hMessage, (LPARAM)error.GetBuffer()); - return; + debugLogA(__FUNCTION__": failed to send message for %s (%s)", username, error.c_str()); + ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, hMessage, (LPARAM)error.c_str()); } } @@ -123,51 +122,51 @@ int CSkypeProto::OnPreCreateMessage(WPARAM, LPARAM lParam) /* MESSAGE EVENT */ -void CSkypeProto::OnPrivateMessageEvent(JSONNODE *node) +void CSkypeProto::OnPrivateMessageEvent(const JSONNode &node) { - ptrA clientMsgId(mir_t2a(ptrT(json_as_string(json_get(node, "clientmessageid"))))); - ptrA skypeEditedId(mir_t2a(ptrT(json_as_string(json_get(node, "skypeeditedid"))))); + std::string clientMsgId = node["clientmessageid"].as_string(); + std::string skypeEditedId = node["skypeeditedid"].as_string(); - bool isEdited = (json_get(node, "skypeeditedid") != NULL); + bool isEdited = node["skypeeditedid"]; - ptrT composeTime(json_as_string(json_get(node, "composetime"))); - time_t timestamp = getByte("UseLocalTime", 0) ? time(NULL) : IsoToUnixTime(composeTime); + std::string composeTime = node["composetime"].as_string(); + time_t timestamp = getByte("UseLocalTime", 0) ? time(NULL) : IsoToUnixTime(composeTime.c_str()); - ptrA conversationLink(mir_t2a(ptrT(json_as_string(json_get(node, "conversationLink"))))); - ptrA fromLink(mir_t2a(ptrT(json_as_string(json_get(node, "from"))))); + std::string conversationLink = node["conversationLink"].as_string(); + std::string fromLink = node["from"].as_string(); - ptrA skypename(ContactUrlToName(conversationLink)); - ptrA from(ContactUrlToName(fromLink)); + ptrA skypename(ContactUrlToName(conversationLink.c_str())); + ptrA from(ContactUrlToName(fromLink.c_str())); - ptrA content(mir_t2a(ptrT(json_as_string(json_get(node, "content"))))); - int emoteOffset = json_as_int(json_get(node, "skypeemoteoffset")); + std::string content = node["content"].as_string(); + int emoteOffset = node["skypeemoteoffset"].as_int(); - ptrA message(RemoveHtml(content)); + ptrA message(RemoveHtml(content.c_str())); - - ptrA messageType(mir_t2a(ptrT(json_as_string(json_get(node, "messagetype"))))); + std::string messageType= node["messagetype"].as_string(); MCONTACT hContact = AddContact(skypename, true); - if (HistorySynced) db_set_dw(hContact, m_szModuleName, "LastMsgTime", (DWORD)timestamp); + if (HistorySynced) + db_set_dw(hContact, m_szModuleName, "LastMsgTime", (DWORD)timestamp); - if (!mir_strcmpi(messageType, "Control/Typing")) + if (!mir_strcmpi(messageType.c_str(), "Control/Typing")) CallService(MS_PROTO_CONTACTISTYPING, hContact, PROTOTYPE_CONTACTTYPING_INFINITE); - else if (!mir_strcmpi(messageType, "Control/ClearTyping")) + else if (!mir_strcmpi(messageType.c_str(), "Control/ClearTyping")) CallService(MS_PROTO_CONTACTISTYPING, hContact, PROTOTYPE_CONTACTTYPING_OFF); - else if (!mir_strcmpi(messageType, "Text") || !mir_strcmpi(messageType, "RichText")) + else if (!mir_strcmpi(messageType.c_str(), "Text") || !mir_strcmpi(messageType.c_str(), "RichText")) { if (IsMe(from)) { - int hMessage = atoi(clientMsgId); + int hMessage = atoi(clientMsgId.c_str()); ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)hMessage, 0); debugLogA(__FUNCTION__" timestamp = %d clientmsgid = %s", timestamp, clientMsgId); - AddMessageToDb(hContact, timestamp, DBEF_UTF | DBEF_SENT, clientMsgId, message, emoteOffset); + AddMessageToDb(hContact, timestamp, DBEF_UTF | DBEF_SENT, clientMsgId.c_str(), message, emoteOffset); return; } debugLogA(__FUNCTION__" timestamp = %d clientmsgid = %s", timestamp, clientMsgId); - MEVENT dbevent = GetMessageFromDb(hContact, skypeEditedId); + MEVENT dbevent = GetMessageFromDb(hContact, skypeEditedId.c_str()); if (isEdited && dbevent != NULL) { DBEVENTINFO dbei = { sizeof(dbei) }; @@ -189,19 +188,18 @@ void CSkypeProto::OnPrivateMessageEvent(JSONNODE *node) msg.AppendFormat("%s\n%s %s:\n%s", dbMsgText, Translate("Edited at"), _T2A(time), message); db_event_delete(hContact, dbevent); - AddMessageToDb(hContact, dbEventTimestamp, DBEF_UTF, skypeEditedId, msg.GetBuffer()); + AddMessageToDb(hContact, dbEventTimestamp, DBEF_UTF, skypeEditedId.c_str(), msg.GetBuffer()); } - else - OnReceiveMessage(clientMsgId, conversationLink, timestamp, message, emoteOffset); + else OnReceiveMessage(clientMsgId.c_str(), conversationLink.c_str(), timestamp, message, emoteOffset); } - else if (!mir_strcmpi(messageType, "Event/SkypeVideoMessage")){} - else if (!mir_strcmpi(messageType, "Event/Call")) + else if (!mir_strcmpi(messageType.c_str(), "Event/SkypeVideoMessage")) {} + else if (!mir_strcmpi(messageType.c_str(), "Event/Call")) { //content=user name6 //Echo / Sound Test Service6 //content=user name int iType = 3, iDuration = 0; - HXML xml = xi.parseString(ptrT(mir_a2t(content)), 0, _T("partlist")); + HXML xml = xi.parseString(ptrT(mir_a2t(content.c_str())), 0, _T("partlist")); if (xml != NULL) { @@ -241,12 +239,12 @@ void CSkypeProto::OnPrivateMessageEvent(JSONNODE *node) int flags = DBEF_UTF; if (IsMe(from)) flags |= DBEF_SENT; - AddCallInfoToDb(hContact, timestamp, flags, clientMsgId, text.GetBuffer()); + AddCallInfoToDb(hContact, timestamp, flags, clientMsgId.c_str(), text.GetBuffer()); } - else if (!mir_strcmpi(messageType, "RichText/Files")) + else if (!mir_strcmpi(messageType.c_str(), "RichText/Files")) { //content=run.bat - HXML xml = xi.parseString(ptrT(mir_a2t(content)), 0, _T("files")); + HXML xml = xi.parseString(ptrT(mir_a2t(content.c_str())), 0, _T("files")); if (xml != NULL) { for (int i = 0; i < xi.getChildCount(xml); i++) @@ -261,15 +259,15 @@ void CSkypeProto::OnPrivateMessageEvent(JSONNODE *node) continue; CMStringA msg(FORMAT, "%s:\n\t%s: %s\n\t%s: %d %s", Translate("File transfer"), Translate("File name"), fileName, Translate("Size"), fileSize, Translate("bytes")); - AddMessageToDb(hContact, timestamp, DBEF_UTF | DBEF_READ, clientMsgId, msg.GetBuffer()); + AddMessageToDb(hContact, timestamp, DBEF_UTF | DBEF_READ, clientMsgId.c_str(), msg.GetBuffer()); } } } - else if (!mir_strcmpi(messageType, "RichText/Location")){} - else if (!mir_strcmpi(messageType, "RichText/UriObject")) + else if (!mir_strcmpi(messageType.c_str(), "RichText/Location")) {} + else if (!mir_strcmpi(messageType.c_str(), "RichText/UriObject")) { //content=Для просмотра этого общего фото перейдите по ссылке: https://api.asm.skype.com/s/i?0-weu-d1-262f0a1ee256d03b8e4b8360d9208834 - HXML xml = xi.parseString(ptrT(mir_a2t(content)), 0, _T("URIObject")); + HXML xml = xi.parseString(ptrT(mir_a2t(content.c_str())), 0, _T("URIObject")); if (xml != NULL) { ptrA url(mir_t2a(xi.getAttrValue(xml, L"uri"))); @@ -277,10 +275,10 @@ void CSkypeProto::OnPrivateMessageEvent(JSONNODE *node) CMStringA data(FORMAT, "%s: https://api.asm.skype.com/s/i?%s", Translate("Image"), object); - AddMessageToDb(hContact, timestamp, DBEF_UTF, clientMsgId, data.GetBuffer()); + AddMessageToDb(hContact, timestamp, DBEF_UTF, clientMsgId.c_str(), data.GetBuffer()); } } - else if (!mir_strcmpi(messageType, "RichText/Contacts")){} + else if (!mir_strcmpi(messageType.c_str(), "RichText/Contacts")) {} //if (clientMsgId && (!mir_strcmpi(messageType, "Text") || !mir_strcmpi(messageType, "RichText"))) //{ @@ -307,4 +305,4 @@ void CSkypeProto::MarkMessagesRead(MCONTACT hContact, MEVENT hDbEvent) time_t timestamp = dbei.timestamp; PushRequest(new MarkMessageReadRequest(username, RegToken, timestamp, timestamp, false, Server)); -} \ No newline at end of file +} diff --git a/protocols/SkypeWeb/src/skype_poll_processing.cpp b/protocols/SkypeWeb/src/skype_poll_processing.cpp index 1cddd3fe2e..6a349a7bc1 100644 --- a/protocols/SkypeWeb/src/skype_poll_processing.cpp +++ b/protocols/SkypeWeb/src/skype_poll_processing.cpp @@ -17,31 +17,31 @@ along with this program. If not, see . #include "stdafx.h" -void CSkypeProto::ProcessEndpointPresenceRes(JSONNODE *node) +void CSkypeProto::ProcessEndpointPresenceRes(const JSONNode &node) { debugLogA("CSkypeProto::ProcessEndpointPresenceRes"); - ptrA selfLink(mir_t2a(ptrT(json_as_string(json_get(node, "selfLink"))))); - ptrA skypename(ContactUrlToName(selfLink)); - if (skypename == NULL) + std::string selfLink = node["selfLink"].as_string(); + std::string skypename(ContactUrlToName(selfLink.c_str())); + if (skypename.empty()) return; - MCONTACT hContact = FindContact(skypename); + MCONTACT hContact = FindContact(skypename.c_str()); if (hContact == NULL) return; //"publicInfo":{"capabilities":"","typ":"11","skypeNameVersion":"0/7.1.0.105//","nodeInfo":"","version":"24"} //"privateInfo": {"epname": "Skype"} - JSONNODE *publicInfo = json_get(node, "publicInfo"); - JSONNODE *privateInfo = json_get(node, "privateInfo"); + const JSONNode &publicInfo = node["publicInfo"]; + const JSONNode &privateInfo = node["privateInfo"]; CMStringA MirVer = ""; - if (publicInfo != NULL) + if (publicInfo) { - ptrA skypeNameVersion(mir_t2a(ptrT(json_as_string(json_get(publicInfo, "skypeNameVersion"))))); - ptrA version(mir_t2a(ptrT(json_as_string(json_get(publicInfo, "version"))))); - ptrA typ(mir_t2a(ptrT(json_as_string(json_get(publicInfo, "typ"))))); - if (typ != NULL) + std::string skypeNameVersion = publicInfo["skypeNameVersion"].as_string(); + std::string version = publicInfo["version"].as_string(); + std::string typ = publicInfo["typ"].as_string(); + if (!typ.empty()) { - int iTyp = atoi(typ); + int iTyp = atoi(typ.c_str()); switch (iTyp) { case 17: @@ -76,7 +76,7 @@ void CSkypeProto::ProcessEndpointPresenceRes(JSONNODE *node) break; default: { - if (!mir_strcmpi(typ, "website")) + if (!mir_strcmpi(typ.c_str(), "website")) MirVer.Append("Skype (Outlook)"); else MirVer.Append("Skype (Unknown)"); @@ -86,42 +86,42 @@ void CSkypeProto::ProcessEndpointPresenceRes(JSONNODE *node) if (iTyp == 125) MirVer.AppendFormat(" %s", version); else - MirVer.AppendFormat(" %s", ParseUrl(skypeNameVersion, "/")); + MirVer.AppendFormat(" %s", ParseUrl(skypeNameVersion.c_str(), "/")); } } if (privateInfo != NULL) { - ptrA epname(mir_t2a(ptrT(json_as_string(json_get(privateInfo, "epname"))))); - if (epname != NULL && *epname) + std::string epname = privateInfo["epname"].as_string(); + if (!epname.empty()) { - MirVer.AppendFormat(" [%s]", epname); + MirVer.AppendFormat(" [%s]", epname.c_str()); } } db_set_s(hContact, m_szModuleName, "MirVer", MirVer); } -void CSkypeProto::ProcessUserPresenceRes(JSONNODE *node) +void CSkypeProto::ProcessUserPresenceRes(const JSONNode &node) { debugLogA("CSkypeProto::ProcessUserPresenceRes"); - ptrA selfLink(mir_t2a(ptrT(json_as_string(json_get(node, "selfLink"))))); - ptrA status(mir_t2a(ptrT(json_as_string(json_get(node, "status"))))); - ptrA skypename; + std::string selfLink = node["selfLink"].as_string(); + std::string status = node["status"].as_string(); + std::string skypename; - if (strstr(selfLink, "/8:")) + if (selfLink.find("/8:") != std::string::npos) { - skypename = ContactUrlToName(selfLink); + skypename = ContactUrlToName(selfLink.c_str()); } - else if (strstr(selfLink, "/1:")) + else if (selfLink.find("/1:") != std::string::npos) { - skypename = SelfUrlToName(selfLink); + skypename = SelfUrlToName(selfLink.c_str()); } - if (skypename != NULL) + if (!skypename.empty()) { - if (IsMe(skypename)) + if (IsMe(skypename.c_str())) { - int iNewStatus = SkypeToMirandaStatus(status); + int iNewStatus = SkypeToMirandaStatus(status.c_str()); int old_status = m_iStatus; m_iDesiredStatus = iNewStatus; m_iStatus = iNewStatus; @@ -131,41 +131,41 @@ void CSkypeProto::ProcessUserPresenceRes(JSONNODE *node) } else { - MCONTACT hContact = FindContact(skypename); + MCONTACT hContact = FindContact(skypename.c_str()); if (hContact != NULL) - SetContactStatus(hContact, SkypeToMirandaStatus(status)); + SetContactStatus(hContact, SkypeToMirandaStatus(status.c_str())); } } } -void CSkypeProto::ProcessNewMessageRes(JSONNODE *node) +void CSkypeProto::ProcessNewMessageRes(const JSONNode &node) { debugLogA("CSkypeProto::ProcessNewMessageRes"); - ptrA conversationLink(mir_t2a(ptrT(json_as_string(json_get(node, "conversationLink"))))); + std::string conversationLink = node["conversationLink"].as_string(); - if (strstr(conversationLink, "/8:")) + if (conversationLink.find("/8:") != std::string::npos) OnPrivateMessageEvent(node); - else if (strstr(conversationLink, "/19:")) + else if (conversationLink.find("/19:") != std::string::npos) OnChatEvent(node); } -void CSkypeProto::ProcessConversationUpdateRes(JSONNODE *node) +void CSkypeProto::ProcessConversationUpdateRes(const JSONNode&) { - /*JSONNODE *lastMessage = json_get(node, "lastMessage"); - JSONNODE *properties = json_get(node, "properties"); + /*const JSONNode &lastMessage = node, "lastMessage"); + const JSONNode &properties = node, "properties"); - ptrA convLink(mir_t2a(json_as_string(json_get(lastMessage, "conversationLink")))); - ptrA fromLink(mir_t2a(json_as_string(json_get(lastMessage, "from")))); + std::string convLink(mir_t2a(json_as_string(lastMessage, "conversationLink")))); + std::string fromLink(mir_t2a(json_as_string(lastMessage, "from")))); if (strstr(convLink, "/8:") && IsMe(ContactUrlToName(fromLink))) { - ptrA skypename(ContactUrlToName(convLink)); + std::string skypename(ContactUrlToName(convLink)); MCONTACT hContact = FindContact(skypename); if (hContact != NULL) { - CMStringA consumptionhorizon(mir_t2a(json_as_string(json_get(properties, "consumptionhorizon")))); + CMStringA consumptionhorizon(mir_t2a(json_as_string(properties, "consumptionhorizon")))); int iStart = 0; CMStringA szToken1 = consumptionhorizon.Tokenize(";", iStart).Trim(); @@ -185,7 +185,6 @@ void CSkypeProto::ProcessConversationUpdateRes(JSONNODE *node) }*/ } -void CSkypeProto::ProcessThreadUpdateRes(JSONNODE *node) +void CSkypeProto::ProcessThreadUpdateRes(const JSONNode&) { - return; } \ No newline at end of file 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); diff --git a/protocols/SkypeWeb/src/skype_profile.cpp b/protocols/SkypeWeb/src/skype_profile.cpp index 57b7c97b17..4f8069e06d 100644 --- a/protocols/SkypeWeb/src/skype_profile.cpp +++ b/protocols/SkypeWeb/src/skype_profile.cpp @@ -243,27 +243,25 @@ void CSkypeProto::InitLanguages() result[_T("zu")] = _T("Zulu"); } -void CSkypeProto::UpdateProfileFirstName(JSONNODE *root, MCONTACT hContact) +void CSkypeProto::UpdateProfileFirstName(const JSONNode &root, MCONTACT hContact) { - JSONNODE *node = json_get(root, "firstname"); - CMString firstname = ptrT(json_as_string(node)); + CMString firstname = root["firstname"].as_mstring(); if (!firstname.IsEmpty() && firstname != "null") setTString(hContact, "FirstName", firstname); else delSetting(hContact, "FirstName"); } -void CSkypeProto::UpdateProfileLastName(JSONNODE *root, MCONTACT hContact) +void CSkypeProto::UpdateProfileLastName(const JSONNode &root, MCONTACT hContact) { - JSONNODE *node = json_get(root, "lastname"); - CMString lastname = ptrT(json_as_string(node)); + CMString lastname = root["lastname"].as_mstring(); if (!lastname.IsEmpty() && lastname != "null") setTString(hContact, "LastName", lastname); else delSetting(hContact, "LastName"); } -void CSkypeProto::UpdateProfileDisplayName(JSONNODE *root, MCONTACT hContact) +void CSkypeProto::UpdateProfileDisplayName(const JSONNode &root, MCONTACT hContact) { ptrT firstname(getTStringA(hContact, "FirstName")); ptrT lastname(getTStringA(hContact, "LastName")); @@ -276,10 +274,9 @@ void CSkypeProto::UpdateProfileDisplayName(JSONNODE *root, MCONTACT hContact) else if (lastname) setTString(hContact, "Nick", lastname); else { - JSONNODE *node = json_get(root, "displayname"); - if (node == NULL) - node = json_get(root, "username"); - CMString displayname = ptrT(json_as_string(node)); + + const JSONNode &node = root["displayname"]; + CMString displayname((!node) ? root["username"].as_mstring() : node.as_mstring()); if (!displayname.IsEmpty() && displayname != "null") setTString(hContact, "Nick", displayname); else @@ -287,20 +284,18 @@ void CSkypeProto::UpdateProfileDisplayName(JSONNODE *root, MCONTACT hContact) } } -void CSkypeProto::UpdateProfileGender(JSONNODE *root, MCONTACT hContact) +void CSkypeProto::UpdateProfileGender(const JSONNode &root, MCONTACT hContact) { - JSONNODE *node = json_get(root, "gender"); - CMString gender = ptrT(json_as_string(node)); + CMString gender = root["gender"].as_mstring(); if (!gender.IsEmpty() && gender != "null") setByte(hContact, "Gender", (BYTE)(_ttoi(gender) == 1 ? 'M' : 'F')); else delSetting(hContact, "Gender"); } -void CSkypeProto::UpdateProfileBirthday(JSONNODE *root, MCONTACT hContact) +void CSkypeProto::UpdateProfileBirthday(const JSONNode &root, MCONTACT hContact) { - JSONNODE *node = json_get(root, "birthday"); - CMString birthday = ptrT(json_as_string(node)); + CMString birthday = root["birthday"].as_mstring(); if (!birthday.IsEmpty() && birthday != "null") { int d, m, y; @@ -317,86 +312,77 @@ void CSkypeProto::UpdateProfileBirthday(JSONNODE *root, MCONTACT hContact) } } -void CSkypeProto::UpdateProfileCountry(JSONNODE *root, MCONTACT hContact) +void CSkypeProto::UpdateProfileCountry(const JSONNode &root, MCONTACT hContact) { - JSONNODE *node = json_get(root, "country"); - CMStringA isocode = mir_t2a(ptrT(json_as_string(node))); - if (!isocode.IsEmpty() && isocode != "null") + std::string isocode = root["country"].as_string(); + if (!isocode.empty() && isocode != "null") { - char *country = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)(char*)isocode.GetBuffer(), 0); - setTString(hContact, "Country", _A2T(country)); + char *country = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)isocode.c_str(), 0); + setString(hContact, "Country", country); } - else - delSetting(hContact, "Country"); + else delSetting(hContact, "Country"); } -void CSkypeProto::UpdateProfileState(JSONNODE *root, MCONTACT hContact) +void CSkypeProto::UpdateProfileState(const JSONNode &root, MCONTACT hContact) { - JSONNODE *node = json_get(root, "province"); - CMString province = mir_t2a(ptrT(json_as_string(node))); + CMString province = root["province"].as_mstring(); if (!province.IsEmpty() && province != "null") setTString(hContact, "State", province); else delSetting(hContact, "State"); } -void CSkypeProto::UpdateProfileCity(JSONNODE *root, MCONTACT hContact) +void CSkypeProto::UpdateProfileCity(const JSONNode &root, MCONTACT hContact) { - JSONNODE *node = json_get(root, "city"); - CMString city = ptrT(json_as_string(node)); + CMString city = root["city"].as_mstring(); if (!city.IsEmpty() && city != "null") setTString(hContact, "City", city); else delSetting(hContact, "City"); } -void CSkypeProto::UpdateProfileLanguage(JSONNODE *root, MCONTACT hContact) +void CSkypeProto::UpdateProfileLanguage(const JSONNode &root, MCONTACT hContact) { - JSONNODE *node = json_get(root, "language"); - CMString isocode = ptrT(json_as_string(node)); + CMString isocode = root["language"].as_mstring(); if (!isocode.IsEmpty() && isocode != "null") setTString(hContact, "Language0", languages[isocode.GetBuffer()].c_str()); else delSetting(hContact, "Language0"); } -void CSkypeProto::UpdateProfileHomepage(JSONNODE *root, MCONTACT hContact) +void CSkypeProto::UpdateProfileHomepage(const JSONNode &root, MCONTACT hContact) { - JSONNODE *node = json_get(root, "homepage"); - CMString homepage = ptrT(json_as_string(node)); + CMString homepage = root["homepage"].as_mstring(); if (!homepage.IsEmpty() && homepage != "null") setTString(hContact, "Homepage", homepage); else delSetting(hContact, "Homepage"); } -void CSkypeProto::UpdateProfileAbout(JSONNODE *root, MCONTACT hContact) +void CSkypeProto::UpdateProfileAbout(const JSONNode &root, MCONTACT hContact) { - JSONNODE *node = json_get(root, "about"); - CMString about = ptrT(json_as_string(node)); + CMString about = root["about"].as_mstring(); if (!about.IsEmpty() && about != "null") setTString(hContact, "About", about); else delSetting(hContact, "About"); } -void CSkypeProto::UpdateProfileEmails(JSONNODE *root, MCONTACT hContact) +void CSkypeProto::UpdateProfileEmails(const JSONNode &root, MCONTACT hContact) { - JSONNODE *node = json_get(root, "emails"); - if (!json_empty(node)) + const JSONNode &node = root["emails"]; + if (node) { - JSONNODE *items = json_as_array(node), *item; - for (size_t i = 0; i < min(json_size(items), 3); i++) + const JSONNode &items = node.as_array(); + for (size_t i = 0; i < min(items.size(), 3); i++) { - item = json_at(items, i); - if (item == NULL) + const JSONNode &item = items.at(i); + if (!item) break; CMStringA name(FORMAT, "e-mail%d", i); - CMString value = ptrT(json_as_string(item)); - setTString(hContact, name, value); + setTString(hContact, name, item.as_mstring()); } - json_delete(items); } else { @@ -406,62 +392,57 @@ void CSkypeProto::UpdateProfileEmails(JSONNODE *root, MCONTACT hContact) } } -void CSkypeProto::UpdateProfilePhoneMobile(JSONNODE *root, MCONTACT hContact) +void CSkypeProto::UpdateProfilePhoneMobile(const JSONNode &root, MCONTACT hContact) { - JSONNODE *node = json_get(root, "phoneMobile"); - CMString province = mir_t2a(ptrT(json_as_string(node))); + CMString province = root["phoneMobile"].as_mstring(); if (!province.IsEmpty() && province != "null") setTString(hContact, "Cellular", province); else delSetting(hContact, "Cellular"); } -void CSkypeProto::UpdateProfilePhoneHome(JSONNODE *root, MCONTACT hContact) +void CSkypeProto::UpdateProfilePhoneHome(const JSONNode &root, MCONTACT hContact) { - JSONNODE *node = json_get(root, "phone"); - CMString province = mir_t2a(ptrT(json_as_string(node))); + CMString province = root["phone"].as_mstring(); if (!province.IsEmpty() && province != "null") setTString(hContact, "Phone", province); else delSetting(hContact, "Phone"); } -void CSkypeProto::UpdateProfilePhoneOffice(JSONNODE *root, MCONTACT hContact) +void CSkypeProto::UpdateProfilePhoneOffice(const JSONNode &root, MCONTACT hContact) { - JSONNODE *node = json_get(root, "phoneOffice"); - CMString province = mir_t2a(ptrT(json_as_string(node))); + CMString province = root["phoneOffice"].as_mstring(); if (!province.IsEmpty() && province != "null") setTString(hContact, "CompanyPhone", province); else delSetting(hContact, "CompanyPhone"); } -void CSkypeProto::UpdateProfileStatusMessage(JSONNODE *root, MCONTACT hContact) +void CSkypeProto::UpdateProfileStatusMessage(const JSONNode &root, MCONTACT hContact) { - JSONNODE *node = json_get(root, "mood"); if (hContact == NULL) return; - CMString province = mir_t2a(ptrT(json_as_string(node))); + + CMString province = root["mood"].as_mstring(); if (!province.IsEmpty() && province != "null") db_set_ts(hContact, "CList", "StatusMsg", province); else db_unset(hContact, "CList", "StatusMsg"); } -void CSkypeProto::UpdateProfileXStatusMessage(JSONNODE *root, MCONTACT hContact) +void CSkypeProto::UpdateProfileXStatusMessage(const JSONNode &root, MCONTACT hContact) { - JSONNODE *node = json_get(root, "richMood"); - CMString province = mir_t2a(ptrT(json_as_string(node))); + CMString province = root["richMood"].as_mstring(); if (!province.IsEmpty() && province != "null") setTString(hContact, "XStatusMsg", province); else delSetting(hContact, "XStatusMsg"); } -void CSkypeProto::UpdateProfileAvatar(JSONNODE *root, MCONTACT hContact) +void CSkypeProto::UpdateProfileAvatar(const JSONNode &root, MCONTACT hContact) { - JSONNODE *node = json_get(root, "avatarUrl"); - CMString province = mir_t2a(ptrT(json_as_string(node))); + CMString province = root["avatarUrl"].as_mstring(); if (!province.IsEmpty() && province != "null") { SetAvatarUrl(hContact, province); @@ -475,13 +456,14 @@ void CSkypeProto::LoadProfile(const NETLIBHTTPREQUEST *response) if (response == NULL) return; - JSONROOT root(response->pData); - if (root == NULL) + JSONNode root = JSONNode::parse(response->pData); + if (!root) return; - ptrA username(mir_t2a(ptrT(json_as_string(json_get(root, "username"))))); + + std::string username = root["username"].as_string(); MCONTACT hContact = NULL; - if (!IsMe(username)) - hContact = FindContact(username); + if (!IsMe(username.c_str())) + hContact = FindContact(username.c_str()); UpdateProfileFirstName(root, hContact); UpdateProfileLastName(root, hContact); @@ -502,4 +484,4 @@ void CSkypeProto::LoadProfile(const NETLIBHTTPREQUEST *response) UpdateProfileStatusMessage(root, hContact); //richMood UpdateProfileAvatar(root, hContact); -} \ No newline at end of file +} diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 0f58cbbaaf..fd2b600bdb 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -25,15 +25,15 @@ typedef HRESULT(MarkupCallback)(IHTMLDocument3 *pHtmlDoc, BSTR &message); struct TRInfo { - char *socketIo; - char *connId; - char *st; - char *se; - char *instance; - char *ccid; - char *sessId; - char *sig; - char *url; + std::string socketIo; + std::string connId; + std::string st; + std::string se; + std::string instance; + std::string ccid; + std::string sessId; + std::string sig; + std::string url; }; struct CSkypeProto : public PROTO < CSkypeProto > @@ -184,28 +184,28 @@ private: void OnTrouterPoliciesCreated(const NETLIBHTTPREQUEST *response); void OnGetTrouter(const NETLIBHTTPREQUEST *response, void *p); void OnHealth(const NETLIBHTTPREQUEST *response); - void OnTrouterEvent(JSONNODE *body, JSONNODE *headers); + void OnTrouterEvent(const JSONNode &body, const JSONNode &headers); void __cdecl CSkypeProto::TRouterThread(void*); // profile - void UpdateProfileFirstName(JSONNODE *root, MCONTACT hContact = NULL); - void UpdateProfileLastName(JSONNODE *root, MCONTACT hContact = NULL); - void UpdateProfileDisplayName(JSONNODE *root, MCONTACT hContact = NULL); - void UpdateProfileGender(JSONNODE *root, MCONTACT hContact = NULL); - void UpdateProfileBirthday(JSONNODE *root, MCONTACT hContact = NULL); - void UpdateProfileCountry(JSONNODE *node, MCONTACT hContact = NULL); - void UpdateProfileState(JSONNODE *node, MCONTACT hContact = NULL); - void UpdateProfileCity(JSONNODE *node, MCONTACT hContact = NULL); - void UpdateProfileLanguage(JSONNODE *root, MCONTACT hContact = NULL); - void UpdateProfileHomepage(JSONNODE *root, MCONTACT hContact = NULL); - void UpdateProfileAbout(JSONNODE *node, MCONTACT hContact = NULL); - void UpdateProfileEmails(JSONNODE *root, MCONTACT hContact = NULL); - void UpdateProfilePhoneMobile(JSONNODE *root, MCONTACT hContact = NULL); - void UpdateProfilePhoneHome(JSONNODE *root, MCONTACT hContact = NULL); - void UpdateProfilePhoneOffice(JSONNODE *root, MCONTACT hContact = NULL); - void UpdateProfileStatusMessage(JSONNODE *root, MCONTACT hContact = NULL); - void UpdateProfileXStatusMessage(JSONNODE *root, MCONTACT hContact = NULL); - void UpdateProfileAvatar(JSONNODE *root, MCONTACT hContact = NULL); + void UpdateProfileFirstName(const JSONNode &root, MCONTACT hContact = NULL); + void UpdateProfileLastName(const JSONNode &root, MCONTACT hContact = NULL); + void UpdateProfileDisplayName(const JSONNode &root, MCONTACT hContact = NULL); + void UpdateProfileGender(const JSONNode &root, MCONTACT hContact = NULL); + void UpdateProfileBirthday(const JSONNode &root, MCONTACT hContact = NULL); + void UpdateProfileCountry(const JSONNode &node, MCONTACT hContact = NULL); + void UpdateProfileState(const JSONNode &node, MCONTACT hContact = NULL); + void UpdateProfileCity(const JSONNode &node, MCONTACT hContact = NULL); + void UpdateProfileLanguage(const JSONNode &root, MCONTACT hContact = NULL); + void UpdateProfileHomepage(const JSONNode &root, MCONTACT hContact = NULL); + void UpdateProfileAbout(const JSONNode &node, MCONTACT hContact = NULL); + void UpdateProfileEmails(const JSONNode &root, MCONTACT hContact = NULL); + void UpdateProfilePhoneMobile(const JSONNode &root, MCONTACT hContact = NULL); + void UpdateProfilePhoneHome(const JSONNode &root, MCONTACT hContact = NULL); + void UpdateProfilePhoneOffice(const JSONNode &root, MCONTACT hContact = NULL); + void UpdateProfileStatusMessage(const JSONNode &root, MCONTACT hContact = NULL); + void UpdateProfileXStatusMessage(const JSONNode &root, MCONTACT hContact = NULL); + void UpdateProfileAvatar(const JSONNode &root, MCONTACT hContact = NULL); void LoadProfile(const NETLIBHTTPREQUEST *response); @@ -251,7 +251,7 @@ private: void MarkMessagesRead(MCONTACT hContact, MEVENT hDbEvent); - void OnPrivateMessageEvent(JSONNODE *node); + void OnPrivateMessageEvent(const JSONNode &node); // sync void OnGetServerHistory(const NETLIBHTTPREQUEST *response); @@ -276,7 +276,7 @@ private: INT_PTR __cdecl OnJoinChatRoom(WPARAM hContact, LPARAM); INT_PTR __cdecl OnLeaveChatRoom(WPARAM hContact, LPARAM); - void OnChatEvent(JSONNODE *node); + void OnChatEvent(const JSONNode &node); void OnSendChatMessage(const TCHAR *chat_id, const TCHAR * tszMessage); char *GetChatUsers(const TCHAR *chat_id); bool IsChatContact(const TCHAR *chat_id, const char *id); @@ -296,27 +296,27 @@ private: //polling void __cdecl PollingThread(void*); - void ParsePollData(JSONNODE *data); - void ProcessEndpointPresenceRes(JSONNODE *node); - void ProcessUserPresenceRes(JSONNODE *node); - void ProcessNewMessageRes(JSONNODE *node); - void ProcessConversationUpdateRes(JSONNODE *node); - void ProcessThreadUpdateRes(JSONNODE *node); + void ParsePollData(const JSONNode &data); + void ProcessEndpointPresenceRes(const JSONNode &node); + void ProcessUserPresenceRes(const JSONNode &node); + void ProcessNewMessageRes(const JSONNode &node); + void ProcessConversationUpdateRes(const JSONNode &node); + void ProcessThreadUpdateRes(const JSONNode &node); // utils bool IsOnline(); bool IsMe(const char *skypeName); MEVENT AddEventToDb(MCONTACT hContact, WORD type, DWORD timestamp, DWORD flags, DWORD cbBlob, PBYTE pBlob); - time_t IsoToUnixTime(const TCHAR *stamp); + time_t IsoToUnixTime(const char *stamp); char *RemoveHtml(const char *text); char *GetStringChunk(const char *haystack, size_t len, const char *start, const char *end); int SkypeToMirandaStatus(const char *status); char *MirandaToSkypeStatus(int status); - void ShowNotification(const TCHAR *message, int flags = 0, MCONTACT hContact = NULL); - void ShowNotification(const TCHAR *caption, const TCHAR *message, int flags = 0, MCONTACT hContact = NULL, int type = 0); + void ShowNotification(const TCHAR *message, MCONTACT hContact = NULL); + void ShowNotification(const TCHAR *caption, const TCHAR *message, MCONTACT hContact = NULL, int type = 0); static bool IsFileExists(std::tstring path); static LRESULT CALLBACK PopupDlgProcCall(HWND hPopup, UINT uMsg, WPARAM wParam, LPARAM lParam); diff --git a/protocols/SkypeWeb/src/skype_search.cpp b/protocols/SkypeWeb/src/skype_search.cpp index b74daf47c1..1b77576d66 100644 --- a/protocols/SkypeWeb/src/skype_search.cpp +++ b/protocols/SkypeWeb/src/skype_search.cpp @@ -37,8 +37,7 @@ void CSkypeProto::SearchBasicThread(void* id) void CSkypeProto::OnSearch(const NETLIBHTTPREQUEST *response) { debugLogA(__FUNCTION__); - if (response == NULL) - { + if (response == NULL) { ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0); return; } @@ -49,29 +48,28 @@ void CSkypeProto::OnSearch(const NETLIBHTTPREQUEST *response) return; } - JSONROOT root(response->pData); - if (root == NULL) - { + JSONNode root = JSONNode::parse(response->pData); + if (!root) { ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0); return; } - JSONNODE *items = json_as_array(root); - for (size_t i = 0; i < json_size(items); i++) + const JSONNode &items = root.as_array(); + for (size_t i = 0; i < items.size(); i++) { - JSONNODE *item = json_at(items, i); - JSONNODE *ContactCards = json_get(item, "ContactCards"); - JSONNODE *Skype = json_get(ContactCards, "Skype"); + const JSONNode &item = items.at(i); + const JSONNode &ContactCards = item["ContactCards"]; + const JSONNode &Skype = ContactCards["Skype"]; - TCHAR *sDisplayName = json_as_string(json_get(Skype, "DisplayName")); - TCHAR *sSkypeName = json_as_string(json_get(Skype, "SkypeName")); + CMString tszDisplayName(Skype["DisplayName"].as_mstring()); + CMString tszNick(Skype["SkypeName"].as_mstring()); PROTOSEARCHRESULT psr = { sizeof(psr) }; psr.flags = PSR_TCHAR; - psr.id = mir_wstrdup(sSkypeName); - psr.nick = mir_wstrdup(sDisplayName); + psr.id = tszDisplayName.GetBuffer(); + psr.nick = tszNick.GetBuffer(); ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr); } - json_free(items); + ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0); } \ No newline at end of file diff --git a/protocols/SkypeWeb/src/skype_trouter.cpp b/protocols/SkypeWeb/src/skype_trouter.cpp index 65dff96136..6f8f9b77ad 100644 --- a/protocols/SkypeWeb/src/skype_trouter.cpp +++ b/protocols/SkypeWeb/src/skype_trouter.cpp @@ -21,90 +21,85 @@ void CSkypeProto::OnCreateTrouter(const NETLIBHTTPREQUEST *response) { if (response == NULL || response->pData == NULL) { - ShowNotification(_A2T(m_szModuleName), TranslateT("Failed establish a TRouter connection."), 0, NULL, 1); + ShowNotification(m_tszUserName, TranslateT("Failed establish a TRouter connection."), NULL, 1); return; } - JSONROOT root(response->pData); - if (root == NULL) - { - ShowNotification(_A2T(m_szModuleName), TranslateT("Failed establish a TRouter connection."), 0, NULL, 1); + JSONNode root = JSONNode::parse(response->pData); + if (!root) { + ShowNotification(m_tszUserName, TranslateT("Failed establish a TRouter connection."), NULL, 1); return; } - ptrA ccid(mir_t2a(ptrT(json_as_string(json_get(root, "ccid"))))); - ptrA connId(mir_t2a(ptrT(json_as_string(json_get(root, "connId"))))); - ptrA instance(mir_t2a(ptrT(json_as_string(json_get(root, "instance"))))); - ptrA socketio(mir_t2a(ptrT(json_as_string(json_get(root, "socketio"))))); - ptrA url(mir_t2a(ptrT(json_as_string(json_get(root, "url"))))); + const JSONNode &ccid = root["ccid"]; + const JSONNode &connId = root["connId"]; + const JSONNode &instance = root["instance"]; + const JSONNode &socketio = root["socketio"]; + const JSONNode &url = root["url"]; - if (ccid == NULL || connId == NULL || instance == NULL || socketio == NULL || url == NULL) + if (!ccid || !connId || !instance || !socketio || !url) { - ShowNotification(_A2T(m_szModuleName), TranslateT("Failed establish a TRouter connection."), 0, NULL, 1); + ShowNotification(m_tszUserName, TranslateT("Failed establish a TRouter connection."), NULL, 1); return; } - TRouter.ccid = mir_strdup(ccid); - TRouter.connId = mir_strdup(connId); - TRouter.instance = mir_strdup(instance); - TRouter.socketIo = mir_strdup(socketio); - TRouter.url = mir_strdup(url); + TRouter.ccid = ccid.as_string(); + TRouter.connId = connId.as_string(); + TRouter.instance = instance.as_string(); + TRouter.socketIo = socketio.as_string(); + TRouter.url = url.as_string(); - SendRequest(new CreateTrouterPoliciesRequest(TokenSecret, TRouter.connId), &CSkypeProto::OnTrouterPoliciesCreated); + SendRequest(new CreateTrouterPoliciesRequest(TokenSecret, TRouter.connId.c_str()), &CSkypeProto::OnTrouterPoliciesCreated); } void CSkypeProto::OnTrouterPoliciesCreated(const NETLIBHTTPREQUEST *response) { if (response == NULL || response->pData == NULL) { - ShowNotification(_A2T(m_szModuleName), TranslateT("Failed establish a TRouter connection."), 0, NULL, 1); + ShowNotification(m_tszUserName, TranslateT("Failed establish a TRouter connection."), NULL, 1); return; } - JSONROOT root(response->pData); - - if (root == NULL) + JSONNode root = JSONNode::parse(response->pData); + if (!root) { - ShowNotification(_A2T(m_szModuleName), TranslateT("Failed establish a TRouter connection."), 0, NULL, 1); + ShowNotification(m_tszUserName, TranslateT("Failed establish a TRouter connection."), NULL, 1); return; } - ptrA st(mir_t2a(ptrT(json_as_string(json_get(root, "st"))))); - ptrA se(mir_t2a(ptrT(json_as_string(json_get(root, "se"))))); - ptrA sig(mir_t2a(ptrT(json_as_string(json_get(root, "sig"))))); + const JSONNode &st = root["st"]; + const JSONNode &se = root["se"]; + const JSONNode &sig = root["sig"]; - if (st == NULL || se == NULL || sig == NULL) + if (!st || !se || !sig) { - ShowNotification(_A2T(m_szModuleName), TranslateT("Failed establish a TRouter connection."), 0, NULL, 1); + ShowNotification(m_tszUserName, TranslateT("Failed establish a TRouter connection."), NULL, 1); return; } - TRouter.st = mir_strdup(st); - TRouter.se = mir_strdup(se); - TRouter.sig = mir_strdup(sig); + TRouter.st = st.as_string(); + TRouter.se = se.as_string(); + TRouter.sig = sig.as_string(); - SendRequest(new GetTrouterRequest - ( + SendRequest(new GetTrouterRequest( TRouter.socketIo, TRouter.connId, TRouter.st, TRouter.se, TRouter.sig, TRouter.instance, - TRouter.ccid - ), &CSkypeProto::OnGetTrouter, (void *)false); - - + TRouter.ccid), &CSkypeProto::OnGetTrouter, NULL); } void CSkypeProto::OnGetTrouter(const NETLIBHTTPREQUEST *response, void *p) { if (response == NULL || response->pData == NULL) { - ShowNotification(_A2T(m_szModuleName), TranslateT("Failed establish a TRouter connection."), 0, NULL, 1); + ShowNotification(m_tszUserName, TranslateT("Failed establish a TRouter connection."), NULL, 1); return; } - bool isHealth = (bool)p; + + bool isHealth = p != NULL; CMStringA data(response->pData); int iStart = 0; @@ -113,40 +108,40 @@ void CSkypeProto::OnGetTrouter(const NETLIBHTTPREQUEST *response, void *p) m_hTrouterThread = ForkThreadEx(&CSkypeProto::TRouterThread, 0, NULL); if (!isHealth) - SendRequest(new RegisterTrouterRequest(TokenSecret, TRouter.url, TRouter.sessId)); + SendRequest(new RegisterTrouterRequest(TokenSecret, TRouter.url.c_str(), TRouter.sessId.c_str())); } void CSkypeProto::OnHealth(const NETLIBHTTPREQUEST*) { - - SendRequest(new GetTrouterRequest(TRouter.socketIo, + SendRequest(new GetTrouterRequest( + TRouter.socketIo, TRouter.connId, TRouter.st, TRouter.se, TRouter.sig, TRouter.instance, TRouter.ccid), - &CSkypeProto::OnGetTrouter, (void *)true); + &CSkypeProto::OnGetTrouter, (void *)1); } -void CSkypeProto::OnTrouterEvent(JSONNODE *body, JSONNODE *) +void CSkypeProto::OnTrouterEvent(const JSONNode &body, const JSONNode &) { - ptrT displayname(json_as_string(json_get(body, "displayName"))); - ptrT cuid(json_as_string(json_get(body, "callerId"))); - ptrT uid(json_as_string(json_get(body, "conversationId"))); - ptrT gp(json_as_string(json_get(body, "gp"))); - int evt = json_as_int(json_get(body, "evt")); + std::string displayname = body["displayName"].as_string(); + std::string cuid = body["callerId"].as_string(); + std::string uid = body["conversationId"].as_string(); + std::string gp = body["gp"].as_string(); + int evt = body["evt"].as_int(); switch (evt) { case 100: //incoming call { - ptrA callId(mir_t2a(ptrT(json_as_string(json_get(body, "convoCallId"))))); - if (uid != NULL) + std::string callId = body["convoCallId"].as_string(); + if (!uid.empty()) { - MCONTACT hContact = AddContact(_T2A(uid), true); + MCONTACT hContact = AddContact(uid.c_str(), true); - MEVENT hEvent = AddCallToDb(hContact, time(NULL), DBEF_READ, callId, _T2A(gp)); + MEVENT hEvent = AddCallToDb(hContact, time(NULL), DBEF_READ, callId.c_str(), gp.c_str()); SkinPlaySound("skype_inc_call"); CLISTEVENT cle = { sizeof(cle) }; @@ -164,16 +159,15 @@ void CSkypeProto::OnTrouterEvent(JSONNODE *body, JSONNODE *) CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle); - ShowNotification(pcli->pfnGetContactDisplayName(hContact, 0), TranslateT("Incoming call"), 0, hContact, SKYPE_DB_EVENT_TYPE_INCOMING_CALL); + ShowNotification(pcli->pfnGetContactDisplayName(hContact, 0), TranslateT("Incoming call"), hContact, SKYPE_DB_EVENT_TYPE_INCOMING_CALL); } - break; } + break; + case 104: //call canceled: callerId=""; conversationId=NULL; callId=call id - { - ptrA callId(mir_t2a(ptrT(json_as_string(json_get(body, "callId"))))); - SkinPlaySound("skype_call_canceled"); - break; - } + // std::string callId = body["callId"].as_string(); + SkinPlaySound("skype_call_canceled"); + break; } } @@ -203,17 +197,17 @@ void CSkypeProto::TRouterThread(void*) char *json = strstr(response->pData, "{"); if (json != NULL) { - 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); + 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), &CSkypeProto::OnHealth); + SendRequest(new HealthTrouterRequest(TRouter.ccid.c_str()), &CSkypeProto::OnHealth); CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response); delete request; break; diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp index 0dc12a71b3..d07dabf45f 100644 --- a/protocols/SkypeWeb/src/skype_utils.cpp +++ b/protocols/SkypeWeb/src/skype_utils.cpp @@ -17,6 +17,8 @@ along with this program. If not, see . #include "stdafx.h" +#pragma warning(disable:4566) + bool CSkypeProto::IsOnline() { return m_iStatus > ID_STATUS_OFFLINE && m_hPollingThread; @@ -40,15 +42,15 @@ void CSkypeProto::SetSrmmReadStatus(MCONTACT hContact) CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hContact, (LPARAM)&st); } -time_t CSkypeProto::IsoToUnixTime(const TCHAR *stamp) +time_t CSkypeProto::IsoToUnixTime(const char *stamp) { - TCHAR date[9]; + char date[9]; int i, y; if (stamp == NULL) return 0; - TCHAR *p = NEWTSTR_ALLOCA(stamp); + char *p = NEWSTR_ALLOCA(stamp); // skip '-' chars int si = 0, sj = 0; @@ -89,7 +91,7 @@ time_t CSkypeProto::IsoToUnixTime(const TCHAR *stamp) for (; *p != '\0' && !isdigit(*p); p++); // Parse time - if (_stscanf(p, _T("%d:%d:%d"), ×tamp.tm_hour, ×tamp.tm_min, ×tamp.tm_sec) != 3) + if (sscanf(p, "%d:%d:%d", ×tamp.tm_hour, ×tamp.tm_min, ×tamp.tm_sec) != 3) return (time_t)0; timestamp.tm_isdst = 0; // DST is already present in _timezone below @@ -459,7 +461,7 @@ int CSkypeProto::SkypeToMirandaStatus(const char *status) return ID_STATUS_OFFLINE; } -void CSkypeProto::ShowNotification(const TCHAR *caption, const TCHAR *message, int flags, MCONTACT hContact, int type) +void CSkypeProto::ShowNotification(const TCHAR *caption, const TCHAR *message, MCONTACT hContact, int type) { if (Miranda_Terminated()) return; @@ -516,9 +518,9 @@ LRESULT CSkypeProto::PopupDlgProcCall(HWND hPopup, UINT uMsg, WPARAM wParam, LPA return DefWindowProc(hPopup, uMsg, wParam, lParam); } -void CSkypeProto::ShowNotification(const TCHAR *message, int flags, MCONTACT hContact) +void CSkypeProto::ShowNotification(const TCHAR *message, MCONTACT hContact) { - ShowNotification(_T(MODULE), message, flags, hContact); + ShowNotification(_T(MODULE), message, hContact); } bool CSkypeProto::IsFileExists(std::tstring path) diff --git a/protocols/SkypeWeb/src/version.h b/protocols/SkypeWeb/src/version.h index ac4f137709..d50ace6aa7 100644 --- a/protocols/SkypeWeb/src/version.h +++ b/protocols/SkypeWeb/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 -#define __MINOR_VERSION 11 +#define __MINOR_VERSION 12 #define __RELEASE_NUM 0 -#define __BUILD_NUM 3 +#define __BUILD_NUM 1 #include -- cgit v1.2.3