summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-02-14 18:33:08 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-02-14 18:33:08 +0300
commitaa5b93489cf1185018e00a48033ac8a844dca533 (patch)
treef616b8e1c927aaa87b87b4478d8b596001f92d98 /protocols
parent2d7fd070323ab3a9623702c67bece350fce4ab68 (diff)
Skype -> TinyXml
Diffstat (limited to 'protocols')
-rw-r--r--protocols/SkypeWeb/src/skype_chatrooms.cpp128
-rw-r--r--protocols/SkypeWeb/src/skype_events.cpp102
-rw-r--r--protocols/SkypeWeb/src/skype_files.cpp38
-rw-r--r--protocols/SkypeWeb/src/skype_utils.cpp3
-rw-r--r--protocols/SkypeWeb/src/version.h2
5 files changed, 114 insertions, 159 deletions
diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp
index 62ed991ddd..1236756b3e 100644
--- a/protocols/SkypeWeb/src/skype_chatrooms.cpp
+++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp
@@ -245,7 +245,6 @@ INT_PTR CSkypeProto::OnLeaveChatRoom(WPARAM hContact, LPARAM)
void CSkypeProto::OnChatEvent(const JSONNode &node)
{
- //CMStringA szMessageId = node["clientmessageid"] ? node["clientmessageid"].as_string().c_str() : node["skypeeditedid"].as_string().c_str();
CMStringA szConversationName(UrlToSkypename(node["conversationLink"].as_string().c_str()));
CMStringA szFromSkypename(UrlToSkypename(node["from"].as_string().c_str()));
@@ -256,7 +255,6 @@ void CSkypeProto::OnChatEvent(const JSONNode &node)
std::string strContent = node["content"].as_string();
int nEmoteOffset = node["skypeemoteoffset"].as_int();
-
if (FindChatRoom(szConversationName) == NULL)
SendRequest(new GetChatInfoRequest(szConversationName, li), &CSkypeProto::OnGetChatInfo, szTopic.Detach());
@@ -266,97 +264,71 @@ void CSkypeProto::OnChatEvent(const JSONNode &node)
AddMessageToChat(_A2T(szConversationName), _A2T(szFromSkypename), szClearedContent, nEmoteOffset != NULL, nEmoteOffset, timestamp);
}
else if (messageType == "ThreadActivity/AddMember") {
- ptrA xinitiator, xtarget, initiator;
- //content = <addmember><eventtime>1429186229164</eventtime><initiator>8:initiator</initiator><target>8:user</target></addmember>
-
- HXML xml = xmlParseString(ptrW(mir_utf8decodeW(strContent.c_str())), nullptr, L"addmember");
- if (xml == nullptr)
+ // <addmember><eventtime>1429186229164</eventtime><initiator>8:initiator</initiator><target>8:user</target></addmember>
+ TiXmlDocument doc;
+ if (0 != doc.Parse(strContent.c_str()))
return;
- for (int i = 0; i < xmlGetChildCount(xml); i++) {
- HXML xmlNode = xmlGetNthChild(xml, L"target", i);
- if (xmlNode == nullptr)
- break;
-
- xtarget = mir_u2a(xmlGetText(xmlNode));
-
- CMStringA target = ParseUrl(xtarget, "8:");
+ if (auto *pRoot = doc.FirstChildElement("addMember")) {
+ CMStringA target = ParseUrl(pRoot->FirstChildElement("target")->Value(), "8:");
AddChatContact(_A2T(szConversationName), target, target, L"User");
}
- xmlDestroyNode(xml);
}
else if (messageType == "ThreadActivity/DeleteMember") {
- ptrA xinitiator, xtarget;
- //content = <addmember><eventtime>1429186229164</eventtime><initiator>8:initiator</initiator><target>8:user</target></addmember>
-
- HXML xml = xmlParseString(ptrW(mir_utf8decodeW(strContent.c_str())), nullptr, L"deletemember");
- if (xml != nullptr) {
- HXML xmlNode = xmlGetChildByPath(xml, L"initiator", 0);
- xinitiator = node != NULL ? mir_u2a(xmlGetText(xmlNode)) : nullptr;
-
- xmlNode = xmlGetChildByPath(xml, L"target", 0);
- xtarget = xmlNode != nullptr ? mir_u2a(xmlGetText(xmlNode)) : nullptr;
-
- xmlDestroyNode(xml);
- }
- if (xtarget == NULL)
+ // <deletemember><eventtime>1429186229164</eventtime><initiator>8:initiator</initiator><target>8:user</target></deletemember>
+ TiXmlDocument doc;
+ if (0 != doc.Parse(strContent.c_str()))
return;
- CMStringA target = ParseUrl(xtarget, "8:");
- CMStringA initiator = ParseUrl(xinitiator, "8:");
- RemoveChatContact(_A2T(szConversationName), target, target, true, initiator);
-
+ if (auto *pRoot = doc.FirstChildElement("deletemember")) {
+ CMStringA target = ParseUrl(pRoot->FirstChildElement("target")->Value(), "8:");
+ CMStringA initiator = ParseUrl(pRoot->FirstChildElement("initiator")->Value(), "8:");
+ RemoveChatContact(_A2T(szConversationName), target, target, true, initiator);
+ }
}
else if (messageType == "ThreadActivity/TopicUpdate") {
- //content=<topicupdate><eventtime>1429532702130</eventtime><initiator>8:user</initiator><value>test topic</value></topicupdate>
- ptrA xinitiator, value;
- HXML xml = xmlParseString(ptrW(mir_utf8decodeW(strContent.c_str())), nullptr, L"topicupdate");
- if (xml != nullptr) {
- HXML xmlNode = xmlGetChildByPath(xml, L"initiator", 0);
- xinitiator = xmlNode != nullptr ? mir_u2a(xmlGetText(xmlNode)) : nullptr;
-
- xmlNode = xmlGetChildByPath(xml, L"value", 0);
- value = xmlNode != nullptr ? mir_u2a(xmlGetText(xmlNode)) : nullptr;
+ // <topicupdate><eventtime>1429532702130</eventtime><initiator>8:user</initiator><value>test topic</value></topicupdate>
+ TiXmlDocument doc;
+ if (0 != doc.Parse(strContent.c_str()))
+ return;
- xmlDestroyNode(xml);
+ auto *pRoot = doc.FirstChildElement("topicupdate");
+ if (pRoot) {
+ CMStringA initiator = ParseUrl(pRoot->FirstChildElement("initiator")->Value(), "8:");
+ CMStringA value = pRoot->FirstChildElement("value")->Value();
+ RenameChat(szConversationName, value);
+ ChangeChatTopic(szConversationName, value, initiator);
}
-
- CMStringA initiator = ParseUrl(xinitiator, "8:");
- RenameChat(szConversationName, value);
- ChangeChatTopic(szConversationName, value, initiator);
}
else if (messageType == "ThreadActivity/RoleUpdate") {
- //content=<roleupdate><eventtime>1429551258363</eventtime><initiator>8:user</initiator><target><id>8:user1</id><role>admin</role></target></roleupdate>
- ptrA xinitiator, xId, xRole;
- HXML xml = xmlParseString(ptrW(mir_utf8decodeW(strContent.c_str())), nullptr, L"roleupdate");
- if (xml != nullptr) {
- HXML xmlNode = xmlGetChildByPath(xml, L"initiator", 0);
- xinitiator = xmlNode != nullptr ? mir_u2a(xmlGetText(xmlNode)) : nullptr;
-
- xmlNode = xmlGetChildByPath(xml, L"target", 0);
- if (xmlNode != nullptr) {
- HXML xmlId = xmlGetChildByPath(xmlNode, L"id", 0);
- HXML xmlRole = xmlGetChildByPath(xmlNode, L"role", 0);
- xId = xmlId != nullptr ? mir_u2a(xmlGetText(xmlId)) : nullptr;
- xRole = xmlRole != nullptr ? mir_u2a(xmlGetText(xmlRole)) : nullptr;
+ // <roleupdate><eventtime>1429551258363</eventtime><initiator>8:user</initiator><target><id>8:user1</id><role>admin</role></target></roleupdate>
+ TiXmlDocument doc;
+ if (0 != doc.Parse(strContent.c_str()))
+ return;
+
+ auto *pRoot = doc.FirstChildElement("roleupdate");
+ if (pRoot) {
+ CMStringA initiator = ParseUrl(pRoot->FirstChildElement("initiator")->Value(), "8:");
+
+ auto *pTarget = pRoot->FirstChildElement("target");
+ if (pTarget) {
+ CMStringA id = ParseUrl(pTarget->FirstChildElement("id")->Value(), "8:");
+ const char *role = pTarget->FirstChildElement("role")->Value();
+
+ ptrW tszId(mir_a2u(id));
+ ptrW tszRole(mir_a2u(role));
+ ptrW tszInitiator(mir_a2u(initiator));
+
+ GCEVENT gce = { m_szModuleName, _A2T(szConversationName), !mir_strcmpi(role, "Admin") ? GC_EVENT_ADDSTATUS : GC_EVENT_REMOVESTATUS };
+ gce.dwFlags = GCEF_ADDTOLOG;
+ gce.ptszNick = tszId;
+ gce.ptszUID = tszId;
+ gce.ptszText = tszInitiator;
+ gce.time = time(0);
+ gce.bIsMe = IsMe(id);
+ gce.ptszStatus = TranslateT("Admin");
+ Chat_Event(&gce);
}
- xmlDestroyNode(xml);
-
- CMStringA initiator = ParseUrl(xinitiator, "8:");
- CMStringA id = ParseUrl(xId, "8:");
- ptrW tszId(mir_a2u(id));
- ptrW tszRole(mir_a2u(xRole));
- ptrW tszInitiator(mir_a2u(initiator));
-
- GCEVENT gce = { m_szModuleName, _A2T(szConversationName), !mir_strcmpi(xRole, "Admin") ? GC_EVENT_ADDSTATUS : GC_EVENT_REMOVESTATUS };
- gce.dwFlags = GCEF_ADDTOLOG;
- gce.ptszNick = tszId;
- gce.ptszUID = tszId;
- gce.ptszText = tszInitiator;
- gce.time = time(0);
- gce.bIsMe = IsMe(id);
- gce.ptszStatus = TranslateT("Admin");
- Chat_Event(&gce);
}
}
}
diff --git a/protocols/SkypeWeb/src/skype_events.cpp b/protocols/SkypeWeb/src/skype_events.cpp
index 4a0c2cec69..f5124b96da 100644
--- a/protocols/SkypeWeb/src/skype_events.cpp
+++ b/protocols/SkypeWeb/src/skype_events.cpp
@@ -16,13 +16,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
-#define INVALID_DATA Translate("SkypeWeb error: Invalid data!")
INT_PTR CSkypeProto::GetEventText(WPARAM pEvent, LPARAM datatype)
{
DBEVENTINFO *dbei = (DBEVENTINFO*)pEvent;
- CMStringA szText;
+ CMStringA szText = Translate("SkypeWeb error: Invalid data!");
BOOL bUseBB = db_get_b(0, dbei->szModule, "UseBBCodes", 1);
switch (dbei->eventType) {
@@ -42,74 +41,54 @@ INT_PTR CSkypeProto::GetEventText(WPARAM pEvent, LPARAM datatype)
szText.AppendFormat(bUseBB ? Translate("[b]Edited at %s:[/b]\n%s\n") : Translate("Edited at %s:\n%s\n"), szTime, mir_utf8decodeA(jEdit["text"].as_string().c_str()));
}
-
- }
- else {
- szText = INVALID_DATA;
}
- break;
}
+ break;
case SKYPE_DB_EVENT_TYPE_CALL_INFO:
{
- HXML xml = xmlParseString(ptrW(mir_utf8decodeW((char*)dbei->pBlob)), nullptr, L"partlist");
- if (xml != nullptr) {
- ptrA type(mir_u2a(xmlGetAttrValue(xml, L"type")));
- bool bType = (!mir_strcmpi(type, "started")) ? 1 : 0;
- time_t callDuration = 0;
+ TiXmlDocument doc;
+ if (0 != doc.Parse((char*)dbei->pBlob))
+ break;
- for (int i = 0; i < xmlGetChildCount(xml); i++) {
- HXML xmlPart = xmlGetNthChild(xml, L"part", i);
- if (xmlPart != nullptr) {
- HXML xmlDuration = xmlGetChildByPath(xmlPart, L"duration", 0);
+ if (auto *pRoot = doc.FirstChildElement("partlist")) {
+ bool bType = pRoot->IntAttribute("started") ? 1 : 0;
- if (xmlDuration != nullptr) {
- callDuration = _wtol(xmlGetText(xmlDuration));
- break;
- }
+ time_t callDuration = 0;
+ for (auto *it : TiXmlFilter(pRoot, "part")) {
+ auto *xmlDuration = it->FirstChildElement("duration");
+ if (xmlDuration != nullptr) {
+ callDuration = atoi(xmlDuration->GetText());
+ break;
}
}
- if (bType) {
+ if (bType)
szText = Translate("Call");
- }
+ else if (callDuration == 0)
+ szText = Translate("Call missed");
else {
- if (callDuration == 0) {
- szText = Translate("Call missed");
- }
- else {
- char szTime[100];
- strftime(szTime, sizeof(szTime), "%X", gmtime(&callDuration));
- szText.Format(Translate("Call ended (%s)"), szTime);
- }
+ char szTime[100];
+ strftime(szTime, sizeof(szTime), "%X", gmtime(&callDuration));
+ szText.Format(Translate("Call ended (%s)"), szTime);
}
- xmlDestroyNode(xml);
- }
- else {
- szText = INVALID_DATA;
}
- break;
}
+ break;
+
case SKYPE_DB_EVENT_TYPE_FILETRANSFER_INFO:
{
- HXML xml = xmlParseString(ptrW(mir_utf8decodeW((char*)dbei->pBlob)), nullptr, L"files");
- if (xml != nullptr) {
- for (int i = 0; i < xmlGetChildCount(xml); i++) {
- LONGLONG fileSize = 0;
- HXML xmlNode = xmlGetNthChild(xml, L"file", i);
- if (xmlNode != nullptr) {
- fileSize = _wtol(xmlGetAttrValue(xmlNode, L"size"));
- char *fileName = _T2A(xmlGetText(xmlNode));
- if (fileName != nullptr) {
- szText.AppendFormat(Translate("File transfer:\n\tFile name: %s \n\tSize: %lld bytes \n"), fileName, fileSize);
- }
-
- }
+ TiXmlDocument doc;
+ if (0 != doc.Parse((char*)dbei->pBlob))
+ break;
+
+ if (auto *pRoot = doc.FirstChildElement("files")) {
+ for (auto *it : TiXmlFilter(pRoot, "file")) {
+ LONGLONG fileSize = it->Int64Attribute("size");
+ const char *fileName = it->GetText();
+ if (fileName != nullptr)
+ szText.AppendFormat(Translate("File transfer:\n\tFile name: %s \n\tSize: %lld bytes \n"), fileName, fileSize);
}
- xmlDestroyNode(xml);
- }
- else {
- szText = INVALID_DATA;
}
}
break;
@@ -118,18 +97,13 @@ INT_PTR CSkypeProto::GetEventText(WPARAM pEvent, LPARAM datatype)
case SKYPE_DB_EVENT_TYPE_MOJI:
case SKYPE_DB_EVENT_TYPE_URIOBJ:
{
- HXML xml = xmlParseString(ptrW(mir_utf8decodeW((char*)dbei->pBlob)), nullptr, L"URIObject");
- if (xml != nullptr) {
- //szText.Append(_T2A(xmlGetText(xml)));
- HXML xmlA = xmlGetChildByPath(xml, L"a", 0);
- if (xmlA != nullptr) {
- szText += T2Utf(xmlGetAttrValue(xmlA, L"href"));
- }
- xmlDestroyNode(xml);
- }
- else {
- szText = INVALID_DATA;
- }
+ TiXmlDocument doc;
+ if (0 != doc.Parse((char*)dbei->pBlob))
+ break;
+
+ if (auto *pRoot = doc.FirstChildElement("URIObject"))
+ if (auto *xmlA = pRoot->FirstChildElement("a"))
+ szText += xmlA->Attribute("href");
}
break;
diff --git a/protocols/SkypeWeb/src/skype_files.cpp b/protocols/SkypeWeb/src/skype_files.cpp
index 1ce9e54808..28a1f1e908 100644
--- a/protocols/SkypeWeb/src/skype_files.cpp
+++ b/protocols/SkypeWeb/src/skype_files.cpp
@@ -74,22 +74,28 @@ void CSkypeProto::OnASMObjectUploaded(const NETLIBHTTPREQUEST *response, void *a
wchar_t *tszFile = wcsrchr(fup->tszFileName, L'\\') + 1;
- HXML xml = xmlCreateNode(L"URIObject", nullptr, 0);
- xmlAddChild(xml, L"Title", tszFile);
- xmlAddChild(xml, L"Description", fup->tszDesc);
- HXML xmlA = xmlAddChild(xml, L"a", CMStringW(FORMAT, L"https://login.skype.com/login/sso?go=webclient.xmm&docid=%s", _A2T(fup->uid)));
- xmlAddAttr(xmlA, L"href", CMStringW(FORMAT, L"https://login.skype.com/login/sso?go=webclient.xmm&docid=%s", _A2T(fup->uid)));
- HXML xmlOrigName = xmlAddChild(xml, L"OriginalName", nullptr);
- xmlAddAttr(xmlOrigName, L"v", tszFile);
- HXML xmlSize = xmlAddChild(xml, L"FileSize", nullptr);
- xmlAddAttr(xmlSize, L"v", CMStringW(FORMAT, L"%d", fup->size));
-
- xmlAddAttr(xml, L"Type", L"File.1");
- xmlAddAttr(xml, L"uri", CMStringW(FORMAT, L"https://api.asm.skype.com/v1/objects/%s", _A2T(fup->uid)));
- xmlAddAttr(xml, L"url_thumbnail", CMStringW(FORMAT, L"https://api.asm.skype.com/v1/objects/%s/views/thumbnail", _A2T(fup->uid)));
-
- SendRequest(new SendMessageRequest(Contacts[fup->hContact], time(NULL), T2Utf(ptrW(xmlToString(xml, nullptr))), li, "RichText/Media_GenericFile"));
- xmlDestroyNode(xml);
+ TiXmlDocument doc;
+ auto *pRoot = doc.NewElement("URIObject");
+ doc.InsertEndChild(pRoot);
+
+ auto *pTitle = doc.NewElement("Title"); pTitle->SetText(tszFile); pRoot->InsertEndChild(pTitle);
+ auto *pDescr = doc.NewElement("Description"); pDescr->SetText(fup->tszDesc.get()); pRoot->InsertEndChild(pDescr);
+
+ auto *xmlA = doc.NewElement("a"); xmlA->SetText(CMStringA(FORMAT, "https://login.skype.com/login/sso?go=webclient.xmm&docid=%s", fup->uid));
+ xmlA->SetAttribute("href", CMStringA(FORMAT, "https://login.skype.com/login/sso?go=webclient.xmm&docid=%s", fup->uid));
+ pRoot->InsertEndChild(xmlA);
+
+ auto *xmlOrigName = doc.NewElement("OriginalName"); xmlOrigName->SetAttribute("v", tszFile); pRoot->InsertEndChild(xmlOrigName);
+ auto *xmlSize = doc.NewElement("FileSize"); xmlSize->SetAttribute("v", (int)fup->size); pRoot->InsertEndChild(xmlSize);
+
+ pRoot->SetAttribute("Type", "File.1");
+ pRoot->SetAttribute("uri", CMStringA(FORMAT, "https://api.asm.skype.com/v1/objects/%s", fup->uid));
+ pRoot->SetAttribute("url_thumbnail", CMStringA(FORMAT, "https://api.asm.skype.com/v1/objects/%s/views/thumbnail", fup->uid));
+
+ tinyxml2::XMLPrinter printer(0, true);
+ doc.Print(&printer);
+ SendRequest(new SendMessageRequest(Contacts[fup->hContact], time(NULL), printer.CStr(), li, "RichText/Media_GenericFile"));
+
ProtoBroadcastAck(fup->hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, (HANDLE)fup);
delete fup;
}
diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp
index 723df9a4b1..66f68b297f 100644
--- a/protocols/SkypeWeb/src/skype_utils.cpp
+++ b/protocols/SkypeWeb/src/skype_utils.cpp
@@ -470,6 +470,9 @@ bool CSkypeProto::IsFileExists(std::wstring path)
CMStringA CSkypeProto::ParseUrl(const char *url, const char *token)
{
+ if (url == nullptr)
+ return CMStringA();
+
const char *start = strstr(url, token);
if (start == nullptr)
return CMStringA();
diff --git a/protocols/SkypeWeb/src/version.h b/protocols/SkypeWeb/src/version.h
index 351d653f24..81bd4d2567 100644
--- a/protocols/SkypeWeb/src/version.h
+++ b/protocols/SkypeWeb/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 12
#define __RELEASE_NUM 3
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
#include <stdver.h>