diff options
author | George Hazan <ghazan@miranda.im> | 2020-01-29 19:14:39 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-01-29 19:14:39 +0300 |
commit | 8d60f01ae16e88730284757f0a062300b63b2b2d (patch) | |
tree | 16b490084d48c8d7a889d2b503ab0421f1c2c825 | |
parent | 1a1474ff783f5e6a3759110bf63ace1d0d53bd83 (diff) |
fixes #2149 (SkypeWeb doesn't parse error codes)
-rw-r--r-- | protocols/SkypeWeb/src/skype_avatars.cpp | 4 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_chatrooms.cpp | 10 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_contacts.cpp | 16 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_history_sync.cpp | 10 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_profile.cpp | 5 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.cpp | 5 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_search.cpp | 5 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_trouter.cpp | 10 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_utils.cpp | 27 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_utils.h | 12 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/version.h | 2 |
11 files changed, 79 insertions, 27 deletions
diff --git a/protocols/SkypeWeb/src/skype_avatars.cpp b/protocols/SkypeWeb/src/skype_avatars.cpp index 4bb57b1e73..2c71902fc4 100644 --- a/protocols/SkypeWeb/src/skype_avatars.cpp +++ b/protocols/SkypeWeb/src/skype_avatars.cpp @@ -83,8 +83,8 @@ void CSkypeProto::OnSentAvatar(const NETLIBHTTPREQUEST *response) if (response == nullptr)
return;
- JSONNode root = JSONNode::parse(response->pData);
- if (!root)
+ JsonReply root(response);
+ if (root.error())
return;
}
diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp index d0577bb99f..3491416078 100644 --- a/protocols/SkypeWeb/src/skype_chatrooms.cpp +++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp @@ -59,10 +59,11 @@ void CSkypeProto::OnLoadChats(const NETLIBHTTPREQUEST *response) if (response == nullptr)
return;
- JSONNode root = JSONNode::parse(response->pData);
- if (!root)
+ JsonReply reply(response);
+ if (reply.error())
return;
+ auto &root = reply.data();
const JSONNode &metadata = root["_metadata"];
const JSONNode &conversations = root["conversations"].as_array();
@@ -369,10 +370,11 @@ void CSkypeProto::OnGetChatInfo(const NETLIBHTTPREQUEST *response, void *p) if (response == nullptr || response->pData == nullptr)
return;
- JSONNode root = JSONNode::parse(response->pData);
- if (!root)
+ JsonReply reply(response);
+ if (reply.error())
return;
+ auto &root = reply.data();
const JSONNode &members = root["members"];
const JSONNode &properties = root["properties"];
if (!properties["capabilities"] || properties["capabilities"].empty())
diff --git a/protocols/SkypeWeb/src/skype_contacts.cpp b/protocols/SkypeWeb/src/skype_contacts.cpp index aadd5b22c2..0b6131a422 100644 --- a/protocols/SkypeWeb/src/skype_contacts.cpp +++ b/protocols/SkypeWeb/src/skype_contacts.cpp @@ -95,10 +95,11 @@ void CSkypeProto::LoadContactsAuth(const NETLIBHTTPREQUEST *response) if (response == nullptr)
return;
- JSONNode root = JSONNode::parse(response->pData);
- if (!root)
+ JsonReply reply(response);
+ if (reply.error())
return;
+ auto &root = reply.data();
for (auto &item : root["invite_list"]) {
std::string skypename = item["mri"].as_string().erase(0, 2);
std::string reason = item["greeting"].as_string();
@@ -132,11 +133,11 @@ void CSkypeProto::LoadContactsInfo(const NETLIBHTTPREQUEST *response) if (response == nullptr)
return;
- JSONNode root = JSONNode::parse(response->pData);
- if (!root)
+ JsonReply root(response);
+ if (root.error())
return;
- for (auto &item : root) {
+ for (auto &item : root.data()) {
std::string skypename = item["username"].as_string();
MCONTACT hContact = AddContact(skypename.c_str());
if (hContact) {
@@ -155,10 +156,11 @@ void CSkypeProto::LoadContactList(const NETLIBHTTPREQUEST *response) if (response == nullptr)
return;
- JSONNode root = JSONNode::parse(response->pData);
- if (!root)
+ JsonReply reply(response);
+ if (reply.error())
return;
+ auto &root = reply.data();
LIST<char> skypenames(1);
bool loadAll = getBool("LoadAllContacts", false);
for (auto &item : root["contacts"]) {
diff --git a/protocols/SkypeWeb/src/skype_history_sync.cpp b/protocols/SkypeWeb/src/skype_history_sync.cpp index 362065ad98..23392313b4 100644 --- a/protocols/SkypeWeb/src/skype_history_sync.cpp +++ b/protocols/SkypeWeb/src/skype_history_sync.cpp @@ -24,10 +24,11 @@ void CSkypeProto::OnGetServerHistory(const NETLIBHTTPREQUEST *response) if (response == nullptr)
return;
- JSONNode root = JSONNode::parse(response->pData);
- if (!root)
+ JsonReply reply(response);
+ if (reply.error())
return;
+ auto &root = reply.data();
const JSONNode &metadata = root["_metadata"];
const JSONNode &conversations = root["messages"].as_array();
@@ -116,10 +117,11 @@ void CSkypeProto::OnSyncHistory(const NETLIBHTTPREQUEST *response) if (response == nullptr || response->pData == nullptr)
return;
- JSONNode root = JSONNode::parse(response->pData);
- if (!root)
+ JsonReply reply(response);
+ if (reply.error())
return;
+ auto &root = reply.data();
const JSONNode &metadata = root["_metadata"];
const JSONNode &conversations = root["conversations"].as_array();
diff --git a/protocols/SkypeWeb/src/skype_profile.cpp b/protocols/SkypeWeb/src/skype_profile.cpp index 24b6aa375a..5d9c1cf8da 100644 --- a/protocols/SkypeWeb/src/skype_profile.cpp +++ b/protocols/SkypeWeb/src/skype_profile.cpp @@ -406,12 +406,13 @@ void CSkypeProto::LoadProfile(const NETLIBHTTPREQUEST *response, void *arg) return;
}
- JSONNode root = JSONNode::parse(response->pData);
- if (!root) {
+ JsonReply reply(response);
+ if (reply.error()) {
ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_FAILED, 0);
return;
}
+ auto &root = reply.data();
std::string username = root["username"].as_string();
if (username.empty()) {
ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_FAILED, 0);
diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index 9fc6d07fb2..581bee884c 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -137,8 +137,11 @@ HANDLE CSkypeProto::GetAwayMsg(MCONTACT hContact) if (!response || !response->pData) return; - JSONNode root = JSONNode::parse(response->pData); + JsonReply reply(response); + if (reply.error()) + return; + auto &root = reply.data(); if (JSONNode &mood = root["mood"]) { CMStringW str = mood.as_mstring(); this->ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, (LPARAM)str.c_str()); diff --git a/protocols/SkypeWeb/src/skype_search.cpp b/protocols/SkypeWeb/src/skype_search.cpp index 56e29adb18..31b460aa62 100644 --- a/protocols/SkypeWeb/src/skype_search.cpp +++ b/protocols/SkypeWeb/src/skype_search.cpp @@ -44,12 +44,13 @@ void CSkypeProto::OnSearch(const NETLIBHTTPREQUEST *response) return;
}
- JSONNode root = JSONNode::parse(response->pData);
- if (!root) {
+ JsonReply reply(response);
+ if (reply.error()) {
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
return;
}
+ auto &root = reply.data();
const JSONNode &items = root["results"].as_array();
for (auto &it : items) {
const JSONNode &item = it["nodeProfileData"];
diff --git a/protocols/SkypeWeb/src/skype_trouter.cpp b/protocols/SkypeWeb/src/skype_trouter.cpp index 767398ea29..b3452e8ce8 100644 --- a/protocols/SkypeWeb/src/skype_trouter.cpp +++ b/protocols/SkypeWeb/src/skype_trouter.cpp @@ -25,10 +25,11 @@ LBL_Error: return;
}
- JSONNode root = JSONNode::parse(response->pData);
- if (!root)
+ JsonReply reply(response);
+ if (reply.error())
goto LBL_Error;
+ auto &root = reply.data();
const JSONNode &ccid = root["ccid"];
const JSONNode &connId = root["connId"];
const JSONNode &instance = root["instance"];
@@ -55,10 +56,11 @@ LBL_Error: return;
}
- JSONNode root = JSONNode::parse(response->pData);
- if (!root)
+ JsonReply reply(response);
+ if (reply.error())
goto LBL_Error;
+ auto &root = reply.data();
const JSONNode &st = root["st"];
const JSONNode &se = root["se"];
const JSONNode &sig = root["sig"];
diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp index a895fa64f8..a3a1d3419f 100644 --- a/protocols/SkypeWeb/src/skype_utils.cpp +++ b/protocols/SkypeWeb/src/skype_utils.cpp @@ -602,3 +602,30 @@ INT_PTR CSkypeProto::GlobalParseSkypeUriService(WPARAM wParam, LPARAM lParam) return 1; } + +///////////////////////////////////////////////////////////////////////////////////////// + +JsonReply::JsonReply(const NETLIBHTTPREQUEST *pReply) +{ + if (pReply == nullptr) { + m_errorCode = 500; + return; + } + + m_errorCode = pReply->resultCode; + if (m_errorCode != 200) + return; + + m_root = json_parse(pReply->pData); + if (m_root == nullptr) { + m_errorCode = 500; + return; + } + + m_errorCode = (*m_root)["status"]["code"].as_int(); +} + +JsonReply::~JsonReply() +{ + json_delete(m_root); +} diff --git a/protocols/SkypeWeb/src/skype_utils.h b/protocols/SkypeWeb/src/skype_utils.h index b50fcee659..1340caf599 100644 --- a/protocols/SkypeWeb/src/skype_utils.h +++ b/protocols/SkypeWeb/src/skype_utils.h @@ -43,5 +43,17 @@ struct CFileUploadParam : public MZeroedObject { __forceinline bool IsAccess() { return ::_waccess(tszFileName, 0) == 0; }
};
+class JsonReply
+{
+ JSONNode *m_root = nullptr;
+ int m_errorCode = 0;
+
+public:
+ JsonReply(const NETLIBHTTPREQUEST *response);
+ ~JsonReply();
+
+ __forceinline JSONNode &data() const { return *m_root; }
+ __forceinline int error() const { return m_errorCode; }
+};
#endif //_UTILS_H_
\ No newline at end of file diff --git a/protocols/SkypeWeb/src/version.h b/protocols/SkypeWeb/src/version.h index e185b05171..bbddcb1114 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 4
+#define __BUILD_NUM 5
#include <stdver.h>
|