From 2a704d136a65cc39ead589a6bbbc99b28a4bab82 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 13 Feb 2019 20:52:43 +0300 Subject: GG -> TinyXml --- protocols/Gadu-Gadu/src/avatar.cpp | 32 ++++++++++---------- protocols/Gadu-Gadu/src/core.cpp | 31 -------------------- protocols/Gadu-Gadu/src/filetransfer.cpp | 4 +-- protocols/Gadu-Gadu/src/gg.cpp | 2 +- protocols/Gadu-Gadu/src/image.cpp | 6 ++-- protocols/Gadu-Gadu/src/import.cpp | 8 ++--- protocols/Gadu-Gadu/src/oauth.cpp | 50 +++++++++++++------------------- protocols/Gadu-Gadu/src/services.cpp | 8 ++--- protocols/Gadu-Gadu/src/version.h | 6 ++-- 9 files changed, 52 insertions(+), 95 deletions(-) (limited to 'protocols/Gadu-Gadu/src') diff --git a/protocols/Gadu-Gadu/src/avatar.cpp b/protocols/Gadu-Gadu/src/avatar.cpp index 58ec424d37..a4bbb7dde7 100644 --- a/protocols/Gadu-Gadu/src/avatar.cpp +++ b/protocols/Gadu-Gadu/src/avatar.cpp @@ -81,27 +81,25 @@ bool GaduProto::getAvatarFileInfo(uin_t uin, char **avatarurl, char **avatarts) } if ((strncmp(resp->pData, "", 8) == 0) || (strncmp(resp->pData, "pData); - HXML hXml = xmlParseString(xmlAction, nullptr, L"result"); - if (hXml != nullptr) { - HXML node = xmlGetChildByPath(hXml, L"users/user/avatars/avatar", 0); - const wchar_t *blank = (node != nullptr) ? xmlGetAttrValue(node, L"blank") : nullptr; - if (blank != nullptr && mir_wstrcmp(blank, L"1")) { - node = xmlGetChildByPath(hXml, L"users/user/avatars/avatar/timestamp", 0); - *avatarts = node != nullptr ? mir_u2a(xmlGetText(node)) : nullptr; - node = xmlGetChildByPath(hXml, L"users/user/avatars/avatar/bigavatar", 0); //new gg convention - if (node == nullptr) { - node = xmlGetChildByPath(hXml, L"users/user/avatars/avatar/originBigAvatar", 0); //old gg convention - } - *avatarurl = node != nullptr ? mir_u2a(xmlGetText(node)) : nullptr; + // if this url returned xml data (before and after 11.2013 gg convention) + TiXmlDocument doc; + if (doc.Parse(resp->pData) == 0) { + tinyxml2::XMLConstHandle pRoot(doc.FirstChildElement("result")); + auto *node = pRoot.FirstChildElement("users").FirstChildElement("user").FirstChildElement("avatars").FirstChildElement("avatar").ToElement(); + const char *blank = (node != nullptr) ? node->Attribute("blank") : nullptr; + if (mir_strcmp(blank, "1")) { + auto *p = node->FirstChildElement("timestamp"); + if (p) + *avatarts = mir_strdup(p->GetText()); + + p = node->FirstChildElement("bigavatar"); // new gg convention + if (p) + *avatarurl = mir_strdup(p->GetText()); } - xmlDestroyNode(hXml); } - mir_free(xmlAction); } else if (strncmp(resp->pData, "{\"result\":", 10) == 0) { - //if this url returns json data (11.2013 gg convention) + // if this url returns json data (11.2013 gg convention) JSONNode root = JSONNode::parse(resp->pData); if (root) { const JSONNode &respJSONavatars = root["result"].at("users").at("user").at("avatars"); diff --git a/protocols/Gadu-Gadu/src/core.cpp b/protocols/Gadu-Gadu/src/core.cpp index 41ec9a9a9b..d9c96a6a97 100644 --- a/protocols/Gadu-Gadu/src/core.cpp +++ b/protocols/Gadu-Gadu/src/core.cpp @@ -1126,37 +1126,6 @@ retry: } break; - //case GG_EVENT_XML_ACTION: - // if (getByte(GG_KEY_ENABLEAVATARS, GG_KEYDEF_ENABLEAVATARS)) { - // wchar_t *xmlAction = mir_a2u(e->event.xml_action.data); - // wchar_t *tag = mir_a2u("events"); - // HXML hXml = xmlParseString(xmlAction, nullptr, tag); - - // if (hXml != nullptr) { - // mir_free(tag); - // tag = mir_a2u("event/type"); - // HXML node = xmlGetChildByPath(hXml, tag, 0); - // char *type = node != nullptr ? mir_u2a(xmlGetText(node)) : nullptr; - - // mir_free(tag); - // tag = mir_a2u("event/sender"); - // node = xmlGetChildByPath(hXml, tag, 0); - // char *sender = node != nullptr ? mir_u2a(xmlGetText(node)) : nullptr; - // debugLogA("mainthread() (%x): XML Action type: %s.", this, type != nullptr ? type : "unknown"); - // // Avatar change notify - // if (type != nullptr && !mir_strcmp(type, "28")) { - // debugLogA("mainthread() (%x): Client %s changed his avatar.", this, sender); - // requestAvatarInfo(getcontact(atoi(sender), 0, 0, nullptr), 0); - // } - // mir_free(type); - // mir_free(sender); - // xmlDestroyNode(hXml); - // } - // mir_free(tag); - // mir_free(xmlAction); - // } - // break; - case GG_EVENT_TYPING_NOTIFICATION: { MCONTACT hContact = getcontact(e->event.typing_notification.uin, 0, 0, nullptr); diff --git a/protocols/Gadu-Gadu/src/filetransfer.cpp b/protocols/Gadu-Gadu/src/filetransfer.cpp index 6a8ff9ee89..c3f3363dd0 100644 --- a/protocols/Gadu-Gadu/src/filetransfer.cpp +++ b/protocols/Gadu-Gadu/src/filetransfer.cpp @@ -693,7 +693,7 @@ HANDLE GaduProto::dccfileallow(HANDLE hTransfer, const wchar_t* szPath) { debugLogA("dccfileallow(): Failed to create file \"%s\". errno=%d: %s", fileName, errno, strerror(errno)); wchar_t error[512]; - mir_snwprintf(error, TranslateT("Cannot create transfer file. ERROR: %d: %s (dcc)\n%s"), errno, _tcserror(errno), szPath); + mir_snwprintf(error, TranslateT("Cannot create transfer file. ERROR: %d: %s (dcc)\n%s"), errno, _wcserror(errno), szPath); showpopup(m_tszUserName, error, GG_POPUP_ERROR); ProtoBroadcastAck((UINT_PTR)dcc->contact, ACKTYPE_FILE, ACKRESULT_FAILED, dcc, 0); // Free transfer @@ -744,7 +744,7 @@ HANDLE GaduProto::dcc7fileallow(HANDLE hTransfer, const wchar_t* szPath) { debugLogA("dcc7fileallow(): Failed to create file \"%s\". errno=%d: %s", fileName, errno, strerror(errno)); wchar_t error[512]; - mir_snwprintf(error, TranslateT("Cannot create transfer file. ERROR: %d: %s (dcc7)\n%s"), errno, _tcserror(errno), szPath); + mir_snwprintf(error, TranslateT("Cannot create transfer file. ERROR: %d: %s (dcc7)\n%s"), errno, _wcserror(errno), szPath); showpopup(m_tszUserName, error, GG_POPUP_ERROR); gg_dcc7_reject(dcc7, GG_DCC7_REJECT_USER); ProtoBroadcastAck((UINT_PTR)dcc7->contact, ACKTYPE_FILE, ACKRESULT_FAILED, dcc7, 0); diff --git a/protocols/Gadu-Gadu/src/gg.cpp b/protocols/Gadu-Gadu/src/gg.cpp index 1910f7b305..ad6f811ade 100644 --- a/protocols/Gadu-Gadu/src/gg.cpp +++ b/protocols/Gadu-Gadu/src/gg.cpp @@ -77,7 +77,7 @@ wchar_t* ws_strerror(int code) } // Return normal error - return _tcserror(code); + return _wcserror(code); } char* as_strerror(int code) diff --git a/protocols/Gadu-Gadu/src/image.cpp b/protocols/Gadu-Gadu/src/image.cpp index 3dc9fed3f7..2585155bcd 100644 --- a/protocols/Gadu-Gadu/src/image.cpp +++ b/protocols/Gadu-Gadu/src/image.cpp @@ -820,7 +820,7 @@ int GaduProto::img_displayasmsg(MCONTACT hContact, void *img) else { debugLogW(L"img_displayasmsg(): Can not create directory for image cache: %s. errno=%d: %s", szPath, errno, strerror(errno)); wchar_t error[512]; - mir_snwprintf(error, TranslateT("Cannot create image cache directory. ERROR: %d: %s\n%s"), errno, _tcserror(errno), szPath); + mir_snwprintf(error, TranslateT("Cannot create image cache directory. ERROR: %d: %s\n%s"), errno, _wcserror(errno), szPath); showpopup(m_tszUserName, error, GG_POPUP_ERROR | GG_POPUP_ALLOW_MSGBOX | GG_POPUP_ONCE); } } @@ -854,7 +854,7 @@ int GaduProto::img_displayasmsg(MCONTACT hContact, void *img) else { debugLogW(L"img_displayasmsg(): Cannot open file %s for write image. errno=%d: %s", szPath, errno, strerror(errno)); wchar_t error[512]; - mir_snwprintf(error, TranslateT("Cannot save received image to file. ERROR: %d: %s\n%s"), errno, _tcserror(errno), szPath); + mir_snwprintf(error, TranslateT("Cannot save received image to file. ERROR: %d: %s\n%s"), errno, _wcserror(errno), szPath); showpopup(m_tszUserName, error, GG_POPUP_ERROR); return 0; @@ -986,7 +986,7 @@ void* GaduProto::img_loadpicture(gg_event* e, wchar_t *szFileName) free(dat); debugLogW(L"img_loadpicture(): fopen(\"%s\", \"rb\" failed. errno=%d: %s)", szFileName, errno, strerror(errno)); wchar_t error[512]; - mir_snwprintf(error, TranslateT("Cannot open image file. ERROR: %d: %s\n%s"), errno, _tcserror(errno), szFileName); + mir_snwprintf(error, TranslateT("Cannot open image file. ERROR: %d: %s\n%s"), errno, _wcserror(errno), szFileName); showpopup(m_tszUserName, error, GG_POPUP_ERROR); return nullptr; } diff --git a/protocols/Gadu-Gadu/src/import.cpp b/protocols/Gadu-Gadu/src/import.cpp index 80f4bc9a28..8c8a73128f 100644 --- a/protocols/Gadu-Gadu/src/import.cpp +++ b/protocols/Gadu-Gadu/src/import.cpp @@ -404,9 +404,9 @@ INT_PTR GaduProto::import_text(WPARAM, LPARAM) else { wchar_t error[256]; - mir_snwprintf(error, TranslateT("List cannot be imported from file \"%s\" because of error:\n\t%s (Error: %d)"), str, _tcserror(errno), errno); + mir_snwprintf(error, TranslateT("List cannot be imported from file \"%s\" because of error:\n\t%s (Error: %d)"), str, _wcserror(errno), errno); MessageBox(nullptr, error, m_tszUserName, MB_OK | MB_ICONSTOP); - debugLogW(L"import_text(): Cannot import list from file \"%s\". errno=%d: %s", str, errno, _tcserror(errno)); + debugLogW(L"import_text(): Cannot import list from file \"%s\". errno=%d: %s", str, errno, _wcserror(errno)); if (f) fclose(f); @@ -473,9 +473,9 @@ INT_PTR GaduProto::export_text(WPARAM, LPARAM) else { wchar_t error[128]; - mir_snwprintf(error, TranslateT("List cannot be exported to file \"%s\" because of error:\n\t%s (Error: %d)"), str, _tcserror(errno), errno); + mir_snwprintf(error, TranslateT("List cannot be exported to file \"%s\" because of error:\n\t%s (Error: %d)"), str, _wcserror(errno), errno); MessageBox(nullptr, error, m_tszUserName, MB_OK | MB_ICONSTOP); - debugLogW(L"export_text(): Cannot export list to file \"%s\". errno=%d: %s", str, errno, _tcserror(errno)); + debugLogW(L"export_text(): Cannot export list to file \"%s\". errno=%d: %s", str, errno, _wcserror(errno)); } return 0; diff --git a/protocols/Gadu-Gadu/src/oauth.cpp b/protocols/Gadu-Gadu/src/oauth.cpp index 92abd7feaa..4142ac5598 100644 --- a/protocols/Gadu-Gadu/src/oauth.cpp +++ b/protocols/Gadu-Gadu/src/oauth.cpp @@ -302,26 +302,21 @@ int GaduProto::oauth_receivetoken() if (resp) { nlc = resp->nlc; if (resp->resultCode == 200 && resp->dataLength > 0 && resp->pData) { - wchar_t *xmlAction = mir_a2u(resp->pData); - HXML hXml = xmlParseString(xmlAction, nullptr, L"result"); - if (hXml != nullptr) { - HXML node = xmlGetChildByPath(hXml, L"oauth_token", 0); - token = node != nullptr ? mir_u2a(xmlGetText(node)) : nullptr; - - node = xmlGetChildByPath(hXml, L"oauth_token_secret", 0); - token_secret = node != nullptr ? mir_u2a(xmlGetText(node)) : nullptr; - - xmlDestroyNode(hXml); + TiXmlDocument doc; + if (0 == doc.Parse(resp->pData)) { + tinyxml2::XMLConstHandle hXml(doc.FirstChildElement("result")); + if (auto *p = hXml.FirstChildElement("oauth_token").ToElement()) + token = mir_strdup(p->GetText()); + + if (auto *p = hXml.FirstChildElement("oauth_token_secret").ToElement()) + token_secret = mir_strdup(p->GetText()); } - mir_free(xmlAction); } - else - debugLogA("oauth_receivetoken(): Invalid response code from HTTP request"); + else debugLogA("oauth_receivetoken(): Invalid response code from HTTP request"); Netlib_FreeHttpRequest(resp); } - else - debugLogA("oauth_receivetoken(): No response from HTTP request"); + else debugLogA("oauth_receivetoken(): No response from HTTP request"); // 2. Obtaining User Authorization debugLogA("oauth_receivetoken(): Obtaining User Authorization..."); @@ -376,27 +371,22 @@ int GaduProto::oauth_receivetoken() resp = Netlib_HttpTransaction(m_hNetlibUser, &req); if (resp) { if (resp->resultCode == 200 && resp->dataLength > 0 && resp->pData) { - wchar_t *xmlAction = mir_a2u(resp->pData); - HXML hXml = xmlParseString(xmlAction, nullptr, L"result"); - if (hXml != nullptr) { - HXML node = xmlGetChildByPath(hXml, L"oauth_token", 0); - token = mir_u2a(xmlGetText(node)); - - node = xmlGetChildByPath(hXml, L"oauth_token_secret", 0); - token_secret = mir_u2a(xmlGetText(node)); - - xmlDestroyNode(hXml); + TiXmlDocument doc; + if (0 == doc.Parse(resp->pData)) { + tinyxml2::XMLConstHandle hXml(doc.FirstChildElement("result")); + if (auto *p = hXml.FirstChildElement("oauth_token").ToElement()) + token = mir_strdup(p->GetText()); + + if (auto *p = hXml.FirstChildElement("oauth_token_secret").ToElement()) + token_secret = mir_strdup(p->GetText()); } - mir_free(xmlAction); } - else - debugLogA("oauth_receivetoken(): Invalid response code from HTTP request"); + else debugLogA("oauth_receivetoken(): Invalid response code from HTTP request"); Netlib_CloseHandle(resp->nlc); Netlib_FreeHttpRequest(resp); } - else - debugLogA("oauth_receivetoken(): No response from HTTP request"); + else debugLogA("oauth_receivetoken(): No response from HTTP request"); mir_free(password); mir_free(str); diff --git a/protocols/Gadu-Gadu/src/services.cpp b/protocols/Gadu-Gadu/src/services.cpp index 37b148c012..9c5b3ac64f 100644 --- a/protocols/Gadu-Gadu/src/services.cpp +++ b/protocols/Gadu-Gadu/src/services.cpp @@ -244,9 +244,9 @@ INT_PTR GaduProto::getavatarinfo(WPARAM wParam, LPARAM lParam) } if ((wParam & GAIF_FORCE) != 0) { if (_wremove(pai->filename) != 0) { - debugLogW(L"getavatarinfo(): refresh. _wremove 1 file %s error. errno=%d: %s", pai->filename, errno, _tcserror(errno)); + debugLogW(L"getavatarinfo(): refresh. _wremove 1 file %s error. errno=%d: %s", pai->filename, errno, _wcserror(errno)); wchar_t error[512]; - mir_snwprintf(error, TranslateT("Cannot remove old avatar file before refresh. ERROR: %d: %s\n%s"), errno, _tcserror(errno), pai->filename); + mir_snwprintf(error, TranslateT("Cannot remove old avatar file before refresh. ERROR: %d: %s\n%s"), errno, _wcserror(errno), pai->filename); showpopup(m_tszUserName, error, GG_POPUP_ERROR); } setString(pai->hContact, GG_KEY_AVATARHASH, AvatarHash); @@ -259,9 +259,9 @@ INT_PTR GaduProto::getavatarinfo(WPARAM wParam, LPARAM lParam) if (AvatarHash == NULL && AvatarSavedHash != NULL) { getAvatarFilename(pai->hContact, pai->filename, _countof(pai->filename)); if (_wremove(pai->filename) != 0) { - debugLogW(L"getavatarinfo(): delete. _wremove file %s error. errno=%d: %s", pai->filename, errno, _tcserror(errno)); + debugLogW(L"getavatarinfo(): delete. _wremove file %s error. errno=%d: %s", pai->filename, errno, _wcserror(errno)); wchar_t error[512]; - mir_snwprintf(error, TranslateT("Cannot remove old avatar file. ERROR: %d: %s\n%s"), errno, _tcserror(errno), pai->filename); + mir_snwprintf(error, TranslateT("Cannot remove old avatar file. ERROR: %d: %s\n%s"), errno, _wcserror(errno), pai->filename); showpopup(m_tszUserName, error, GG_POPUP_ERROR); } delSetting(pai->hContact, GG_KEY_AVATARHASH); diff --git a/protocols/Gadu-Gadu/src/version.h b/protocols/Gadu-Gadu/src/version.h index 234854a06a..8bc802a55e 100644 --- a/protocols/Gadu-Gadu/src/version.h +++ b/protocols/Gadu-Gadu/src/version.h @@ -19,9 +19,9 @@ //////////////////////////////////////////////////////////////////////////////// #define __MAJOR_VERSION 0 -#define __MINOR_VERSION 11 -#define __RELEASE_NUM 0 -#define __BUILD_NUM 4 +#define __MINOR_VERSION 95 +#define __RELEASE_NUM 11 +#define __BUILD_NUM 1 #include -- cgit v1.2.3