From 59f72fa52bd560003af3c4635f92a885d1c07dbc Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 26 Feb 2019 13:55:31 +0300 Subject: XmlFirstChild / XmlGetAttr - safe wrappers for tinyxml2 --- protocols/JabberG/src/jabber_adhoc.cpp | 54 +++---- protocols/JabberG/src/jabber_agent.cpp | 20 +-- protocols/JabberG/src/jabber_archive.cpp | 26 ++-- protocols/JabberG/src/jabber_byte.cpp | 36 ++--- protocols/JabberG/src/jabber_caps.cpp | 6 +- protocols/JabberG/src/jabber_captcha.cpp | 14 +- protocols/JabberG/src/jabber_console.cpp | 4 +- protocols/JabberG/src/jabber_disco.cpp | 22 +-- protocols/JabberG/src/jabber_form.cpp | 36 ++--- protocols/JabberG/src/jabber_ft.cpp | 30 ++-- protocols/JabberG/src/jabber_groupchat.cpp | 44 +++--- protocols/JabberG/src/jabber_ibb.cpp | 4 +- protocols/JabberG/src/jabber_iq.cpp | 24 +-- protocols/JabberG/src/jabber_iq_handlers.cpp | 22 +-- protocols/JabberG/src/jabber_iqid.cpp | 178 +++++++++++----------- protocols/JabberG/src/jabber_iqid_muc.cpp | 22 +-- protocols/JabberG/src/jabber_message_handlers.cpp | 4 +- protocols/JabberG/src/jabber_message_manager.cpp | 10 +- protocols/JabberG/src/jabber_misc.cpp | 8 +- protocols/JabberG/src/jabber_notes.cpp | 4 +- protocols/JabberG/src/jabber_omemo.cpp | 36 ++--- protocols/JabberG/src/jabber_opt.cpp | 30 ++-- protocols/JabberG/src/jabber_privacy.cpp | 40 ++--- protocols/JabberG/src/jabber_proto.cpp | 13 +- protocols/JabberG/src/jabber_rc.cpp | 8 +- protocols/JabberG/src/jabber_search.cpp | 34 ++--- protocols/JabberG/src/jabber_strm_mgmt.cpp | 22 +-- protocols/JabberG/src/jabber_thread.cpp | 132 ++++++++-------- protocols/JabberG/src/jabber_util.cpp | 8 +- protocols/JabberG/src/jabber_xml.cpp | 129 ++++------------ protocols/JabberG/src/jabber_xml.h | 17 +-- protocols/JabberG/src/jabber_xstatus.cpp | 10 +- protocols/JabberG/src/stdafx.h | 4 +- 33 files changed, 488 insertions(+), 563 deletions(-) (limited to 'protocols/JabberG/src') diff --git a/protocols/JabberG/src/jabber_adhoc.cpp b/protocols/JabberG/src/jabber_adhoc.cpp index ea7e0a3b3e..91491c2774 100644 --- a/protocols/JabberG/src/jabber_adhoc.cpp +++ b/protocols/JabberG/src/jabber_adhoc.cpp @@ -114,9 +114,9 @@ int CJabberProto::AdHoc_ExecuteCommand(HWND hwndDlg, char*, JabberAdHocData *dat if (BST_UNCHECKED == IsDlgButtonChecked(GetDlgItem(hwndDlg, IDC_FRAME), i++)) continue; - const char *node = itemNode->Attribute("node"); + const char *node = XmlGetAttr(itemNode, "node"); if (node) { - const char *jid2 = itemNode->Attribute("jid"); + const char *jid2 = XmlGetAttr(itemNode, "jid"); m_ThreadInfo->send( XmlNodeIq(AddIQ(&CJabberProto::OnIqResult_CommandExecution, JABBER_IQ_TYPE_SET, jid2, 0, -1, hwndDlg)) << XCHILDNS("command", JABBER_FEAT_COMMANDS) << XATTR("node", node) << XATTR("action", "execute")); @@ -133,15 +133,15 @@ int CJabberProto::AdHoc_ExecuteCommand(HWND hwndDlg, char*, JabberAdHocData *dat int CJabberProto::AdHoc_OnJAHMCommandListResult(HWND hwndDlg, TiXmlElement *iqNode, JabberAdHocData *dat) { int nodeIdx = 0; - const char *type = iqNode->Attribute("type"); + const char *type = XmlGetAttr(iqNode, "type"); if (!type || !mir_strcmp(type, "error")) { // error occurred here const char *code = ""; const char *description = ""; - TiXmlElement *errorNode = iqNode->FirstChildElement("error"); + auto *errorNode = XmlFirstChild(iqNode, "error"); if (errorNode) { - code = errorNode->Attribute("code"); + code = XmlGetAttr(errorNode, "code"); description = errorNode->GetText(); } @@ -153,21 +153,21 @@ int CJabberProto::AdHoc_OnJAHMCommandListResult(HWND hwndDlg, TiXmlElement *iqNo dat->CurrentHeight = 0; dat->curPos = 0; SetScrollPos(GetDlgItem(hwndDlg, IDC_VSCROLL), SB_CTL, 0, FALSE); - auto *queryNode = iqNode->FirstChildElement("query"); + auto *queryNode = XmlFirstChild(iqNode, "query"); if (queryNode) { - const char *xmlns = queryNode->Attribute("xmlns"); - const char *node = queryNode->Attribute("node"); + const char *xmlns = XmlGetAttr(queryNode, "xmlns"); + const char *node = XmlGetAttr(queryNode, "node"); if (xmlns && node && !mir_strcmp(xmlns, JABBER_FEAT_DISCO_ITEMS) && !mir_strcmp(node, JABBER_FEAT_COMMANDS)) validResponse = TRUE; } - if (queryNode && queryNode->FirstChildElement(0) && validResponse) { + if (queryNode && XmlFirstChild(queryNode, 0) && validResponse) { dat->CommandsNode = queryNode->DeepClone(&dat->doc)->ToElement(); int ypos = 20; for (auto *itemNode : TiXmlFilter(queryNode, "item")) { - const char *name = itemNode->Attribute("name"); + const char *name = XmlGetAttr(itemNode, "name"); if (!name) - name = itemNode->Attribute("node"); + name = XmlGetAttr(itemNode, "node"); ypos = AdHoc_AddCommandRadio(GetDlgItem(hwndDlg, IDC_FRAME), name, nodeIdx, ypos, (nodeIdx == 1) ? 1 : 0); dat->CurrentHeight = ypos; } @@ -199,18 +199,18 @@ int CJabberProto::AdHoc_OnJAHMProcessResult(HWND hwndDlg, TiXmlElement *workNode dat->AdHocNode = workNode->DeepClone(&dat->doc)->ToElement(); const char *type; - if ((type = workNode->Attribute("type")) == nullptr) return TRUE; + if ((type = XmlGetAttr(workNode, "type")) == nullptr) return TRUE; if (!mir_strcmp(type, "result")) { // wParam = node from responder as a result of command execution - TiXmlElement *commandNode, *xNode; - if ((commandNode = dat->AdHocNode->FirstChildElement("command")) == nullptr) + const TiXmlElement *commandNode, *xNode; + if ((commandNode = XmlFirstChild(dat->AdHocNode, "command")) == nullptr) return TRUE; - const char *status = commandNode->Attribute("status"); + const char *status = XmlGetAttr(commandNode, "status"); if (!status) status = "completed"; - if ((xNode = commandNode->FirstChildElement("x"))) { + if ((xNode = XmlFirstChild(commandNode, "x"))) { // use jabber:x:data form HWND hFrame = GetDlgItem(hwndDlg, IDC_FRAME); if (auto *pszText = XmlGetChildText(xNode, "instructions")) @@ -232,11 +232,11 @@ int CJabberProto::AdHoc_OnJAHMProcessResult(HWND hwndDlg, TiXmlElement *workNode } // check actions - TiXmlElement *actionsNode = commandNode->FirstChildElement("actions"); + auto *actionsNode = XmlFirstChild(commandNode, "actions"); if (actionsNode != nullptr) { - ShowDlgItem(hwndDlg, IDC_PREV, (actionsNode->FirstChildElement("prev") != nullptr) ? SW_SHOW : SW_HIDE); - ShowDlgItem(hwndDlg, IDC_NEXT, (actionsNode->FirstChildElement("next") != nullptr) ? SW_SHOW : SW_HIDE); - ShowDlgItem(hwndDlg, IDC_COMPLETE, (actionsNode->FirstChildElement("complete") != nullptr) ? SW_SHOW : SW_HIDE); + ShowDlgItem(hwndDlg, IDC_PREV, (XmlFirstChild(actionsNode, "prev") != nullptr) ? SW_SHOW : SW_HIDE); + ShowDlgItem(hwndDlg, IDC_NEXT, (XmlFirstChild(actionsNode, "next") != nullptr) ? SW_SHOW : SW_HIDE); + ShowDlgItem(hwndDlg, IDC_COMPLETE, (XmlFirstChild(actionsNode, "complete") != nullptr) ? SW_SHOW : SW_HIDE); ShowDlgItem(hwndDlg, IDC_SUBMIT, SW_HIDE); int toEnable[] = { IDC_PREV, IDC_NEXT, IDC_COMPLETE, 0 }; @@ -262,9 +262,9 @@ int CJabberProto::AdHoc_OnJAHMProcessResult(HWND hwndDlg, TiXmlElement *workNode const char *code = ""; const char *description = ""; - TiXmlElement *errorNode = workNode->FirstChildElement("error"); + auto *errorNode = XmlFirstChild(workNode, "error"); if (errorNode) { - code = errorNode->Attribute("code"); + code = XmlGetAttr(errorNode, "code"); description = errorNode->GetText(); } @@ -276,18 +276,18 @@ int CJabberProto::AdHoc_OnJAHMProcessResult(HWND hwndDlg, TiXmlElement *workNode int CJabberProto::AdHoc_SubmitCommandForm(HWND hwndDlg, JabberAdHocData *dat, char* action) { - TiXmlElement *commandNode = dat->AdHocNode->FirstChildElement("command"); - TiXmlElement *xNode = commandNode->FirstChildElement("x"); + auto *commandNode = XmlFirstChild(dat->AdHocNode, "command"); + auto *xNode = XmlFirstChild(commandNode, "x"); - const char *jid2 = dat->AdHocNode->Attribute("from"); + const char *jid2 = XmlGetAttr(dat->AdHocNode, "from"); XmlNodeIq iq(AddIQ(&CJabberProto::OnIqResult_CommandExecution, JABBER_IQ_TYPE_SET, jid2, 0, -1, hwndDlg)); TiXmlElement *command = iq << XCHILDNS("command", JABBER_FEAT_COMMANDS); - const char *sessionId = commandNode->Attribute("sessionid"); + const char *sessionId = XmlGetAttr(commandNode, "sessionid"); if (sessionId) command << XATTR("sessionid", sessionId); - const char *node = commandNode->Attribute("node"); + const char *node = XmlGetAttr(commandNode, "node"); if (node) command << XATTR("node", node); diff --git a/protocols/JabberG/src/jabber_agent.cpp b/protocols/JabberG/src/jabber_agent.cpp index 87d9fe01cd..d005a3bb75 100644 --- a/protocols/JabberG/src/jabber_agent.cpp +++ b/protocols/JabberG/src/jabber_agent.cpp @@ -150,7 +150,7 @@ public: return TRUE; m_agentRegIqNode = m_agentRegIqNode->DeepClone(&m_doc)->ToElement(); - auto *queryNode = m_agentRegIqNode->FirstChildElement("query"); + auto *queryNode = XmlFirstChild(m_agentRegIqNode, "query"); if (queryNode == nullptr) return TRUE; @@ -163,7 +163,7 @@ public: GetClientRect(GetDlgItem(m_hwnd, IDC_FRAME), &rect); m_frameHeight = rect.bottom - rect.top; - if (auto *xNode = queryNode->FirstChildElement("x")) { + if (auto *xNode = XmlFirstChild(queryNode, "x")) { // use new jabber:x:data form if (const char *pszText = XmlGetChildText(xNode, "instructions")) JabberFormSetInstruction(m_hwnd, pszText); @@ -236,19 +236,19 @@ public: if (m_agentRegIqNode == nullptr) return; - TiXmlElement *queryNode; - const char *from; - if ((from = m_agentRegIqNode->Attribute("from")) == nullptr) return; - if ((queryNode = m_agentRegIqNode->FirstChildElement("query")) == nullptr) return; + auto *queryNode = XmlFirstChild(m_agentRegIqNode, "query"); + const char *from = XmlGetAttr(m_agentRegIqNode, "from"); + if (from == nullptr || queryNode == nullptr) + return; + HWND hwndFrame = GetDlgItem(m_hwnd, IDC_FRAME); - wchar_t *str2 = (wchar_t*)alloca(sizeof(wchar_t) * 128); int id = 0; XmlNodeIq iq(m_proto->AddIQ(&CJabberProto::OnIqResultSetRegister, JABBER_IQ_TYPE_SET, from)); TiXmlElement *query = iq << XQUERY(JABBER_FEAT_REGISTER); - if (auto *xNode = queryNode->FirstChildElement("x")) { + if (auto *xNode = XmlFirstChild(queryNode, "x")) { // use new jabber:x:data form JabberFormGetData(hwndFrame, query, xNode); } @@ -260,7 +260,7 @@ public: if (!mir_strcmp(pszName, "key")) { // field that must be passed along with the registration if (n->GetText()) - XmlAddChild(query, pszName, n->GetText()); + XmlAddChildA(query, pszName, n->GetText()); else XmlAddChild(query, pszName); } @@ -269,7 +269,7 @@ public: } else { GetDlgItemText(hwndFrame, id, str2, 128); - XmlAddChild(query, pszName, T2Utf(str2).get()); + XmlAddChildA(query, pszName, T2Utf(str2).get()); id++; } } diff --git a/protocols/JabberG/src/jabber_archive.cpp b/protocols/JabberG/src/jabber_archive.cpp index e60891f0d4..fd353a3a6d 100644 --- a/protocols/JabberG/src/jabber_archive.cpp +++ b/protocols/JabberG/src/jabber_archive.cpp @@ -57,17 +57,17 @@ void CJabberProto::RetrieveMessageArchive(MCONTACT hContact, JABBER_LIST_ITEM *p void CJabberProto::OnIqResultGetCollectionList(const TiXmlElement *iqNode, CJabberIqInfo*) { - const char *to = iqNode->Attribute("to"); - if (to == nullptr || mir_strcmp(iqNode->Attribute("type"), "result")) + const char *to = XmlGetAttr(iqNode, "to"); + if (to == nullptr || mir_strcmp(XmlGetAttr(iqNode, "type"), "result")) return; - auto *list = iqNode->FirstChildElement("list"); - if (!list || mir_strcmp(list->Attribute("xmlns"), JABBER_FEAT_ARCHIVE)) + auto *list = XmlFirstChild(iqNode, "list"); + if (mir_strcmp(XmlGetAttr(list, "xmlns"), JABBER_FEAT_ARCHIVE)) return; for (auto *itemNode : TiXmlFilter(list, "chat")) { - const char *start = itemNode->Attribute("start"); - const char *with = itemNode->Attribute("with"); + const char *start = XmlGetAttr(itemNode, "start"); + const char *with = XmlGetAttr(itemNode, "with"); if (!start || !with) continue; @@ -212,15 +212,15 @@ BOOL IsDuplicateEvent(MCONTACT hContact, DBEVENTINFO& dbei) void CJabberProto::OnIqResultGetCollection(const TiXmlElement *iqNode, CJabberIqInfo*) { - if (mir_strcmp(iqNode->Attribute("type"), "result")) + if (mir_strcmp(XmlGetAttr(iqNode, "type"), "result")) return; - auto *chatNode = iqNode->FirstChildElement("chat"); - if (!chatNode || mir_strcmp(chatNode->Attribute("xmlns"), JABBER_FEAT_ARCHIVE)) + auto *chatNode = XmlFirstChild(iqNode, "chat"); + if (!chatNode || mir_strcmp(XmlGetAttr(chatNode, "xmlns"), JABBER_FEAT_ARCHIVE)) return; - const char* start = chatNode->Attribute("start"); - const char* with = chatNode->Attribute("with"); + const char* start = XmlGetAttr(chatNode, "start"); + const char* with = XmlGetAttr(chatNode, "with"); if (!start || !with) return; @@ -243,12 +243,12 @@ void CJabberProto::OnIqResultGetCollection(const TiXmlElement *iqNode, CJabberIq else continue; - const TiXmlElement *body = itemNode->FirstChildElement("body"); + const TiXmlElement *body = XmlFirstChild(itemNode, "body"); if (!body) continue; const char *tszBody = body->GetText(); - const char *tszSecs = itemNode->Attribute("secs"); + const char *tszSecs = XmlGetAttr(itemNode, "secs"); if (!tszBody || !tszSecs) continue; diff --git a/protocols/JabberG/src/jabber_byte.cpp b/protocols/JabberG/src/jabber_byte.cpp index 96fd3e79b6..205e146c30 100644 --- a/protocols/JabberG/src/jabber_byte.cpp +++ b/protocols/JabberG/src/jabber_byte.cpp @@ -56,15 +56,15 @@ void CJabberProto::IqResultProxyDiscovery(const TiXmlElement *iqNode, CJabberIqI JABBER_BYTE_TRANSFER *jbt = (JABBER_BYTE_TRANSFER *)pInfo->GetUserData(); if (pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT) { - auto *queryNode = iqNode->FirstChildElement("query"); + auto *queryNode = XmlFirstChild(iqNode, "query"); if (queryNode) { - const char *queryXmlns = queryNode->Attribute("xmlns"); + const char *queryXmlns = XmlGetAttr(queryNode, "xmlns"); if (queryXmlns && !mir_strcmp(queryXmlns, JABBER_FEAT_BYTESTREAMS)) { - auto *streamHostNode = queryNode->FirstChildElement("streamhost"); + auto *streamHostNode = XmlFirstChild(queryNode, "streamhost"); if (streamHostNode) { - const char *streamJid = streamHostNode->Attribute("jid"); - const char *streamHost = streamHostNode->Attribute("host"); - const char *streamPort = streamHostNode->Attribute("port"); + const char *streamJid = XmlGetAttr(streamHostNode, "jid"); + const char *streamHost = XmlGetAttr(streamHostNode, "host"); + const char *streamPort = XmlGetAttr(streamHostNode, "port"); if (streamJid && streamHost && streamPort) { jbt->szProxyHost = mir_strdup(streamHost); jbt->szProxyJid = mir_strdup(streamJid); @@ -305,9 +305,9 @@ void CJabberProto::ByteInitiateResult(const TiXmlElement *iqNode, CJabberIqInfo if (pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT) { auto *queryNode = XmlGetChildByTag(iqNode, "query", "xmlns", JABBER_FEAT_BYTESTREAMS); if (queryNode) { - auto *streamHostNode = queryNode->FirstChildElement("streamhost-used"); + auto *streamHostNode = XmlFirstChild(queryNode, "streamhost-used"); if (streamHostNode) { - const char *streamJid = streamHostNode->Attribute("jid"); + const char *streamJid = XmlGetAttr(streamHostNode, "jid"); if (streamJid) jbt->szStreamhostUsed = mir_strdup(streamJid); } @@ -419,7 +419,7 @@ void CJabberProto::IqResultStreamActivate(const TiXmlElement *iqNode, CJabberIqI if (item == nullptr) return; - if (!mir_strcmp(iqNode->Attribute("type"), "result")) + if (!mir_strcmp(XmlGetAttr(iqNode, "type"), "result")) item->jbt->bStreamActivated = TRUE; if (item->jbt->hProxyEvent) @@ -577,7 +577,7 @@ int CJabberProto::ByteSendProxyParse(HNETLIBCONN hConn, JABBER_BYTE_TRANSFER *jb void __cdecl CJabberProto::ByteReceiveThread(JABBER_BYTE_TRANSFER *jbt) { - TiXmlElement *iqNode, *queryNode = nullptr; + const TiXmlElement *iqNode, *queryNode = nullptr; WORD port; char data[3]; char* buffer; @@ -591,13 +591,13 @@ void __cdecl CJabberProto::ByteReceiveThread(JABBER_BYTE_TRANSFER *jbt) const char *sid = nullptr, *from = nullptr, *to = nullptr, *szId = nullptr; if (iqNode = jbt->iqNode) { - from = iqNode->Attribute("from"); - to = iqNode->Attribute("to"); - szId = iqNode->Attribute("id"); + from = XmlGetAttr(iqNode, "from"); + to = XmlGetAttr(iqNode, "to"); + szId = XmlGetAttr(iqNode, "id"); - queryNode = iqNode->FirstChildElement("query"); + queryNode = XmlFirstChild(iqNode, "query"); if (queryNode) - sid = queryNode->Attribute("sid"); + sid = XmlGetAttr(queryNode, "sid"); } if (szId && from && to && sid) { @@ -608,9 +608,9 @@ void __cdecl CJabberProto::ByteReceiveThread(JABBER_BYTE_TRANSFER *jbt) if ((buffer = (char*)mir_alloc(JABBER_NETWORK_BUFFER_SIZE))) { for (auto *n : TiXmlFilter(queryNode, "streamhost")) { - const char *str = n->Attribute("jid"); - const char *szHost = n->Attribute("host"); - const char *szPort = n->Attribute("port"); + const char *str = XmlGetAttr(n, "jid"); + const char *szHost = XmlGetAttr(n, "host"); + const char *szPort = XmlGetAttr(n, "port"); if (str != nullptr && szHost != nullptr && szPort != nullptr) { port = (WORD)atoi(szPort); replaceStr(jbt->streamhostJID, str); diff --git a/protocols/JabberG/src/jabber_caps.cpp b/protocols/JabberG/src/jabber_caps.cpp index 94e949cbbf..d8ed2b6a35 100755 --- a/protocols/JabberG/src/jabber_caps.cpp +++ b/protocols/JabberG/src/jabber_caps.cpp @@ -134,7 +134,7 @@ void CJabberProto::OnIqResultCapsDiscoInfo(const TiXmlElement*, CJabberIqInfo *p JabberCapsBits jcbCaps = 0; for (auto *feature : TiXmlFilter(query, "feature")) { - const char *featureName = feature->Attribute("var"); + const char *featureName = XmlGetAttr(feature, "var"); if (!featureName) continue; @@ -155,7 +155,7 @@ void CJabberProto::OnIqResultCapsDiscoInfo(const TiXmlElement*, CJabberIqInfo *p } for (auto *identity : TiXmlFilter(query, "identity")) { - const char *identityName = identity->Attribute("name"); + const char *identityName = XmlGetAttr(identity, "name"); if (identityName) pCaps->SetVer(identityName); } @@ -168,7 +168,7 @@ void CJabberProto::OnIqResultCapsDiscoInfo(const TiXmlElement*, CJabberIqInfo *p JSONNode root; for (auto *field : TiXmlFilter(xform, "field")) { - const char *fieldName = field->Attribute("var"), *fieldValue = XmlGetChildText(field, "value"); + const char *fieldName = XmlGetAttr(field, "var"), *fieldValue = XmlGetChildText(field, "value"); if (!mir_strcmp(fieldName, "os")) root.push_back(JSONNode("o", pCaps->m_szOs = mir_strdup(fieldValue))); else if (!mir_strcmp(fieldName, "os_version")) diff --git a/protocols/JabberG/src/jabber_captcha.cpp b/protocols/JabberG/src/jabber_captcha.cpp index 148325e7a1..6ccecae9c8 100644 --- a/protocols/JabberG/src/jabber_captcha.cpp +++ b/protocols/JabberG/src/jabber_captcha.cpp @@ -119,7 +119,7 @@ bool CJabberProto::ProcessCaptcha(const TiXmlElement *node, const TiXmlElement * auto *y = XmlGetChildByTag(x, "field", "var", "from"); if (y == nullptr) return false; - if ((y = y->FirstChildElement("value")) == nullptr) + if ((y = XmlFirstChild(y, "value")) == nullptr) return false; CAPTCHA_FORM_PARAMS param; @@ -127,18 +127,18 @@ bool CJabberProto::ProcessCaptcha(const TiXmlElement *node, const TiXmlElement * if ((y = XmlGetChildByTag(x, "field", "var", "sid")) == nullptr) return false; - if ((y = y->FirstChildElement("value")) == nullptr) + if ((y = XmlFirstChild(y, "value")) == nullptr) return false; param.sid = y->GetText(); if ((y = XmlGetChildByTag(x, "field", "var", "ocr")) == nullptr) return false; - param.hint = y->Attribute("label"); + param.hint = XmlGetAttr(y, "label"); - param.from = parentNode->Attribute("from"); - param.to = parentNode->Attribute("to"); - param.challenge = parentNode->Attribute("id"); - auto *o = parentNode->FirstChildElement("data"); + param.from = XmlGetAttr(parentNode, "from"); + param.to = XmlGetAttr(parentNode, "to"); + param.challenge = XmlGetAttr(parentNode, "id"); + auto *o = XmlFirstChild(parentNode, "data"); if (o == nullptr || o->GetText() == nullptr) return false; diff --git a/protocols/JabberG/src/jabber_console.cpp b/protocols/JabberG/src/jabber_console.cpp index a8b804c5af..80510be24f 100644 --- a/protocols/JabberG/src/jabber_console.cpp +++ b/protocols/JabberG/src/jabber_console.cpp @@ -126,13 +126,13 @@ bool CJabberProto::FilterXml(const TiXmlElement *node, DWORD flags) const char *attrValue; switch (m_filterInfo.type) { case TFilterInfo::T_JID: - attrValue = node->Attribute((flags & JCPF_OUT) ? "to" : "from"); + attrValue = XmlGetAttr(node, (flags & JCPF_OUT) ? "to" : "from"); if (attrValue) return JabberStrIStr(Utf2T(attrValue), m_filterInfo.pattern) != nullptr; break; case TFilterInfo::T_XMLNS: - attrValue = node->FirstChildElement()->Attribute("xmlns"); + attrValue = XmlGetAttr(XmlFirstChild(node), "xmlns"); if (attrValue) return JabberStrIStr(Utf2T(attrValue), m_filterInfo.pattern) != nullptr; break; diff --git a/protocols/JabberG/src/jabber_disco.cpp b/protocols/JabberG/src/jabber_disco.cpp index a2a54e28d6..a892cdfc92 100644 --- a/protocols/JabberG/src/jabber_disco.cpp +++ b/protocols/JabberG/src/jabber_disco.cpp @@ -112,15 +112,15 @@ void CJabberProto::OnIqResultServiceDiscoveryInfo(const TiXmlElement *iqNode, CJ return; if (pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT) { - auto *query = iqNode->FirstChildElement("query"); + auto *query = XmlFirstChild(iqNode, "query"); if (query == nullptr) pNode->SetInfoRequestId(JABBER_DISCO_RESULT_ERROR); else { for (auto *feature : TiXmlFilter(query, "feature")) - pNode->AddFeature(feature->Attribute("var")); + pNode->AddFeature(XmlGetAttr(feature, "var")); for (auto *identity : TiXmlFilter(query, "identity")) - pNode->AddIdentity(identity->Attribute("category"), identity->Attribute("type"), identity->Attribute("name")); + pNode->AddIdentity(XmlGetAttr(identity, "category"), XmlGetAttr(identity, "type"), XmlGetAttr(identity, "name")); pNode->SetInfoRequestId(JABBER_DISCO_RESULT_OK); pNode->SetInfoRequestErrorText(nullptr); @@ -151,12 +151,12 @@ void CJabberProto::OnIqResultServiceDiscoveryItems(const TiXmlElement *iqNode, C return; if (pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT) { - auto *query = iqNode->FirstChildElement("query"); + auto *query = XmlFirstChild(iqNode, "query"); if (query == nullptr) pNode->SetItemsRequestId(JABBER_DISCO_RESULT_ERROR); else { for (auto *item : TiXmlEnum(query)) - pNode->AddChildNode(item->Attribute("jid"), item->Attribute("node"), item->Attribute("name")); + pNode->AddChildNode(XmlGetAttr(item, "jid"), XmlGetAttr(item, "node"), XmlGetAttr(item, "name")); pNode->SetItemsRequestId(JABBER_DISCO_RESULT_OK); pNode->SetItemsRequestErrorText(nullptr); @@ -185,9 +185,9 @@ void CJabberProto::OnIqResultServiceDiscoveryRootInfo(const TiXmlElement *iqNode mir_cslockfull lck(m_SDManager.cs()); if (pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT) { - for (auto *feature : TiXmlFilter(iqNode->FirstChildElement("query"), "feature")) { - if (!mir_strcmp(feature->Attribute("var"), (char*)pInfo->m_pUserData)) { - CJabberSDNode *pNode = m_SDManager.AddPrimaryNode(pInfo->GetReceiver(), iqNode->Attribute("node"), nullptr); + for (auto *feature : TiXmlFilter(XmlFirstChild(iqNode, "query"), "feature")) { + if (!mir_strcmp(XmlGetAttr(feature, "var"), (char*)pInfo->m_pUserData)) { + CJabberSDNode *pNode = m_SDManager.AddPrimaryNode(pInfo->GetReceiver(), XmlGetAttr(iqNode, "node"), nullptr); SendBothRequests(pNode); break; } @@ -206,9 +206,9 @@ void CJabberProto::OnIqResultServiceDiscoveryRootItems(const TiXmlElement *iqNod TiXmlDocument packet; mir_cslockfull lck(m_SDManager.cs()); if (pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT) { - for (auto *item : TiXmlFilter(iqNode->FirstChildElement("query"), "item")) { - const char *szJid = item->Attribute("jid"); - const char *szNode = item->Attribute("node"); + for (auto *item : TiXmlFilter(XmlFirstChild(iqNode, "query"), "item")) { + const char *szJid = XmlGetAttr(item, "jid"); + const char *szNode = XmlGetAttr(item, "node"); CJabberIqInfo *pNewInfo = AddIQ(&CJabberProto::OnIqResultServiceDiscoveryRootInfo, JABBER_IQ_TYPE_GET, szJid); pNewInfo->m_pUserData = pInfo->m_pUserData; pNewInfo->SetTimeout(30000); diff --git a/protocols/JabberG/src/jabber_form.cpp b/protocols/JabberG/src/jabber_form.cpp index 8637f66d91..16e517c822 100644 --- a/protocols/JabberG/src/jabber_form.cpp +++ b/protocols/JabberG/src/jabber_form.cpp @@ -372,7 +372,7 @@ static void JabberFormAddListItem(TJabberFormControlInfo *item, const char *text } } -void JabberFormCreateUI(HWND hwndStatic, TiXmlElement *xNode, int *formHeight, BOOL bCompact) +void JabberFormCreateUI(HWND hwndStatic, const TiXmlElement *xNode, int *formHeight, BOOL bCompact) { JabberFormDestroyUI(hwndStatic); @@ -383,14 +383,14 @@ void JabberFormCreateUI(HWND hwndStatic, TiXmlElement *xNode, int *formHeight, B CMStringA valueStr; for (auto *n : TiXmlFilter(xNode, "field")) { - const char *labelStr = n->Attribute("label"); + const char *labelStr = XmlGetAttr(n, "label"); if (labelStr == nullptr) - labelStr = n->Attribute("var"); + labelStr = XmlGetAttr(n, "var"); - TJabberFormControlType type = JabberFormTypeNameToId(n->Attribute("type")); + TJabberFormControlType type = JabberFormTypeNameToId(XmlGetAttr(n, "type")); const char *str, *valueText; - if (auto *v = n->FirstChildElement("value")) { + if (auto *v = XmlFirstChild(n, "value")) { valueText = v->GetText(); if (type != JFORM_CTYPE_TEXT_MULTI) valueStr = valueText; @@ -409,15 +409,15 @@ void JabberFormCreateUI(HWND hwndStatic, TiXmlElement *xNode, int *formHeight, B TJabberFormControlInfo *item = layout_info.AppendControl(type, labelStr, valueStr); - if (n->FirstChildElement("required")) + if (XmlFirstChild(n, "required")) item->bRequired = true; if (type == JFORM_CTYPE_LIST_SINGLE) { for (auto *o : TiXmlFilter(n, "option")) { - auto *v = o->FirstChildElement("value"); + auto *v = XmlFirstChild(o, "value"); if (v == nullptr || v->GetText() == nullptr) continue; - if ((str = o->Attribute("label")) == nullptr) + if ((str = XmlGetAttr(o, "label")) == nullptr) str = v->GetText(); if (str == nullptr) continue; @@ -428,11 +428,11 @@ void JabberFormCreateUI(HWND hwndStatic, TiXmlElement *xNode, int *formHeight, B } else if (type == JFORM_CTYPE_LIST_MULTI) { for (auto *o : TiXmlFilter(n, "option")) { - auto *v = o->FirstChildElement("value"); + auto *v = XmlFirstChild(o, "value"); if (v == nullptr || v->GetText() == nullptr) continue; - if ((str = o->Attribute("label")) == nullptr) + if ((str = XmlGetAttr(o, "label")) == nullptr) str = v->GetText(); if (str == nullptr) continue; @@ -463,7 +463,7 @@ void JabberFormDestroyUI(HWND hwndStatic) } } -void JabberFormGetData(HWND hwndStatic, TiXmlElement *xRoot, TiXmlElement *xNode) +void JabberFormGetData(HWND hwndStatic, TiXmlElement *xRoot, const TiXmlElement *xNode) { const char *varName, *labelText, *str2; wchar_t *p, *q, *str; @@ -476,10 +476,10 @@ void JabberFormGetData(HWND hwndStatic, TiXmlElement *xRoot, TiXmlElement *xNode auto *x = xRoot << XCHILD("x") << XATTR("xmlns", JABBER_FEAT_DATA_FORMS) << XATTR("type", "submit"); for (auto *n : TiXmlFilter(xNode, "field")) { - if ((varName = n->Attribute("var")) == nullptr) + if ((varName = XmlGetAttr(n, "var")) == nullptr) continue; - const char *type = n->Attribute("type"); + const char *type = XmlGetAttr(n, "type"); if (type == nullptr) type = "text-single"; @@ -512,9 +512,9 @@ void JabberFormGetData(HWND hwndStatic, TiXmlElement *xRoot, TiXmlElement *xNode GetDlgItemText(hFrame, id, str, len + 1); for (auto *o : TiXmlFilter(n, "option")) { - auto *v = o->FirstChildElement("value"); + auto *v = XmlFirstChild(o, "value"); if (v != nullptr && v->GetText()) { - if ((str2 = o->Attribute("label")) == nullptr) + if ((str2 = XmlGetAttr(o, "label")) == nullptr) str2 = v->GetText(); if (!mir_strcmp(str2, T2Utf(str))) { field << XCHILD("value", v->GetText()); @@ -536,9 +536,9 @@ void JabberFormGetData(HWND hwndStatic, TiXmlElement *xRoot, TiXmlElement *xNode SendMessage(hCtrl, LB_GETTEXT, j, (LPARAM)str); for (auto *o : TiXmlFilter(n, "option")) { - auto *v = o->FirstChildElement("value"); + auto *v = XmlFirstChild(o, "value"); if (v != nullptr && v->GetText()) { - if ((labelText = o->Attribute("label")) == nullptr) + if ((labelText = XmlGetAttr(o, "label")) == nullptr) labelText = v->GetText(); if (!mir_strcmp(labelText, T2Utf(str))) @@ -552,7 +552,7 @@ void JabberFormGetData(HWND hwndStatic, TiXmlElement *xRoot, TiXmlElement *xNode id++; } else if (!mir_strcmp(type, "fixed") || !mir_strcmp(type, "hidden")) { - auto *v = n->FirstChildElement("value"); + auto *v = XmlFirstChild(n, "value"); if (v != nullptr && v->GetText() != nullptr) field << XCHILD("value", v->GetText()); } diff --git a/protocols/JabberG/src/jabber_ft.cpp b/protocols/JabberG/src/jabber_ft.cpp index 4ebbcf9088..cd4884ebb1 100644 --- a/protocols/JabberG/src/jabber_ft.cpp +++ b/protocols/JabberG/src/jabber_ft.cpp @@ -128,15 +128,15 @@ void CJabberProto::OnFtSiResult(const TiXmlElement *iqNode, CJabberIqInfo *pInfo return; if ((pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT) && pInfo->m_szFrom && pInfo->m_szTo) { - if (auto *siNode = iqNode->FirstChildElement("si")) { + if (auto *siNode = XmlFirstChild(iqNode, "si")) { // fix for very smart clients, like gajim BOOL bDirect = m_bBsDirect; BOOL bProxy = m_bBsProxyManual; - if (auto *featureNode = siNode->FirstChildElement("feature")) { + if (auto *featureNode = XmlFirstChild(siNode, "feature")) { if (auto *xNode = XmlGetChildByTag(featureNode, "x", "xmlns", JABBER_FEAT_DATA_FORMS)) { if (auto *fieldNode = XmlGetChildByTag(xNode, "field", "var", "stream-method")) { - if (auto *valueNode = fieldNode->FirstChildElement("value")) { + if (auto *valueNode = XmlFirstChild(fieldNode, "value")) { if ((bDirect || bProxy) && !mir_strcmp(valueNode->GetText(), JABBER_FEAT_BYTESTREAMS)) { // Start Bytestream session JABBER_BYTE_TRANSFER *jbt = new JABBER_BYTE_TRANSFER; @@ -293,20 +293,20 @@ void CJabberProto::FtSendFinal(BOOL success, filetransfer *ft) void CJabberProto::FtHandleSiRequest(const TiXmlElement *iqNode) { - const char *from, *sid, *str, *szId, *filename; + const char *from, *sid, *str, *filename; const TiXmlElement *siNode, *fileNode, *featureNode, *xNode, *fieldNode; if (!iqNode || - (from = iqNode->Attribute("from")) == nullptr || - (str = iqNode->Attribute("type")) == nullptr || mir_strcmp(str, "set") || + (from = XmlGetAttr(iqNode, "from")) == nullptr || + (str = XmlGetAttr(iqNode, "type")) == nullptr || mir_strcmp(str, "set") || (siNode = XmlGetChildByTag(iqNode, "si", "xmlns", JABBER_FEAT_SI)) == nullptr) return; - szId = iqNode->Attribute("id"); - if ((sid = siNode->Attribute("id")) != nullptr && + const char *szId = XmlGetAttr(iqNode, "id"); + if ((sid = XmlGetAttr(siNode, "id")) != nullptr && (fileNode = XmlGetChildByTag(siNode, "file", "xmlns", JABBER_FEAT_SI_FT)) != nullptr && - (filename = fileNode->Attribute("name")) != nullptr && - (str = fileNode->Attribute("size")) != nullptr) { + (filename = XmlGetAttr(fileNode, "name")) != nullptr && + (str = XmlGetAttr(fileNode, "size")) != nullptr) { unsigned __int64 filesize = _atoi64(str); if ((featureNode = XmlGetChildByTag(siNode, "feature", "xmlns", JABBER_FEAT_FEATURE_NEG)) != nullptr && @@ -411,7 +411,7 @@ BOOL CJabberProto::FtHandleBytestreamRequest(const TiXmlElement *iqNode, CJabber { auto *queryNode = pInfo->GetChildNode(); - const char *sid = queryNode->Attribute("sid"); + const char *sid = XmlGetAttr(queryNode, "sid"); JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_FTRECV, sid); if ((sid ) != nullptr && (item ) != nullptr) { @@ -435,15 +435,15 @@ BOOL CJabberProto::FtHandleIbbRequest(const TiXmlElement *iqNode, BOOL bOpen) { if (iqNode == nullptr) return FALSE; - const char *id = iqNode->Attribute("id"); - const char *from = iqNode->Attribute("from"); - const char *to = iqNode->Attribute("to"); + const char *id = XmlGetAttr(iqNode, "id"); + const char *from = XmlGetAttr(iqNode, "from"); + const char *to = XmlGetAttr(iqNode, "to"); if (!id || !from || !to) return FALSE; auto *ibbNode = XmlGetChildByTag(iqNode, bOpen ? "open" : "close", "xmlns", JABBER_FEAT_IBB); if (!ibbNode) return FALSE; - const char *sid = ibbNode->Attribute("sid"); + const char *sid = XmlGetAttr(ibbNode, "sid"); if (!sid) return FALSE; // already closed? diff --git a/protocols/JabberG/src/jabber_groupchat.cpp b/protocols/JabberG/src/jabber_groupchat.cpp index a23038c6a2..cf416c96c1 100644 --- a/protocols/JabberG/src/jabber_groupchat.cpp +++ b/protocols/JabberG/src/jabber_groupchat.cpp @@ -297,7 +297,7 @@ void CJabberProto::OnIqResultDiscovery(const TiXmlElement *iqNode, CJabberIqInfo SendMessage(hwndList, CB_RESETCONTENT, 0, 0); if (pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT) { - auto *query = iqNode->FirstChildElement("query"); + auto *query = XmlFirstChild(iqNode, "query"); if (query == nullptr) { sttRoomListAppend(hwndList, RoomInfo::ROOM_FAIL, TranslateT("Jabber Error"), @@ -307,7 +307,7 @@ void CJabberProto::OnIqResultDiscovery(const TiXmlElement *iqNode, CJabberIqInfo else { bool found = false; for (auto *item : TiXmlFilter(query, "item")) { - const char *jid = item->Attribute("jid"); + const char *jid = XmlGetAttr(item, "jid"); char *name = NEWSTR_ALLOCA(jid); if (name) { if (char *p = strchr(name, '@')) @@ -317,7 +317,7 @@ void CJabberProto::OnIqResultDiscovery(const TiXmlElement *iqNode, CJabberIqInfo sttRoomListAppend(hwndList, ListGetItemPtr(LIST_BOOKMARK, jid) ? RoomInfo::ROOM_BOOKMARK : RoomInfo::ROOM_DEFAULT, - Utf2T(item->Attribute("name")), Utf2T(jid), Utf2T(name)); + Utf2T(XmlGetAttr(item, "name")), Utf2T(jid), Utf2T(name)); found = true; } @@ -756,11 +756,11 @@ static int sttGetStatusCode(const TiXmlElement *node) if (node == nullptr) return -1; - auto *statusNode = node->FirstChildElement("status"); + auto *statusNode = XmlFirstChild(node, "status"); if (statusNode == nullptr) return -1; - const char *statusCode = statusNode->Attribute("code"); + const char *statusCode = XmlGetAttr(statusNode, "code"); if (statusCode == nullptr) return -1; @@ -769,8 +769,8 @@ static int sttGetStatusCode(const TiXmlElement *node) void CJabberProto::RenameParticipantNick(JABBER_LIST_ITEM *item, const char *oldNick, const TiXmlElement *itemNode) { - const char *jid = itemNode->Attribute("jid"); - const char *newNick = itemNode->Attribute("nick"); + const char *jid = XmlGetAttr(itemNode, "jid"); + const char *newNick = XmlGetAttr(itemNode, "nick"); if (newNick == nullptr) return; @@ -806,7 +806,7 @@ void CJabberProto::GroupchatProcessPresence(const TiXmlElement *node) const char *from; if (!node || !node->Name() || mir_strcmp(node->Name(), "presence")) return; - if ((from = node->Attribute("from")) == nullptr) return; + if ((from = XmlGetAttr(node, "from")) == nullptr) return; const char *resource = strchr(from, '/'); if (resource == nullptr || *++resource == '\0') @@ -831,10 +831,10 @@ void CJabberProto::GroupchatProcessPresence(const TiXmlElement *node) const TiXmlElement *itemNode = nullptr; auto *xNode = XmlGetChildByTag(node, "x", "xmlns", JABBER_FEAT_MUC_USER); if (xNode) - itemNode = xNode->FirstChildElement("item"); + itemNode = XmlFirstChild(xNode, "item"); // entering room or a usual room presence - const char *type = node->Attribute("type"); + const char *type = XmlGetAttr(node, "type"); if (type == nullptr || !mir_strcmp(type, "available")) { if (ptrA(JabberNickFromJID(from)) == nullptr) return; @@ -868,14 +868,14 @@ void CJabberProto::GroupchatProcessPresence(const TiXmlElement *node) JABBER_GC_AFFILIATION affiliation = r->m_affiliation; JABBER_GC_ROLE role = r->m_role; - if ((str = itemNode->Attribute("affiliation")) != nullptr) { + if ((str = XmlGetAttr(itemNode, "affiliation")) != nullptr) { if (!mir_strcmp(str, "owner")) affiliation = AFFILIATION_OWNER; else if (!mir_strcmp(str, "admin")) affiliation = AFFILIATION_ADMIN; else if (!mir_strcmp(str, "member")) affiliation = AFFILIATION_MEMBER; else if (!mir_strcmp(str, "none")) affiliation = AFFILIATION_NONE; else if (!mir_strcmp(str, "outcast")) affiliation = AFFILIATION_OUTCAST; } - if ((str = itemNode->Attribute("role")) != nullptr) { + if ((str = XmlGetAttr(itemNode, "role")) != nullptr) { if (!mir_strcmp(str, "moderator")) role = ROLE_MODERATOR; else if (!mir_strcmp(str, "participant")) role = ROLE_PARTICIPANT; else if (!mir_strcmp(str, "visitor")) role = ROLE_VISITOR; @@ -898,7 +898,7 @@ void CJabberProto::GroupchatProcessPresence(const TiXmlElement *node) bRoleChanged = true; } - if (str = itemNode->Attribute("jid")) + if (str = XmlGetAttr(itemNode, "jid")) r->m_szRealJid = mir_strdup(str); // XEP-0115: Entity Capabilities @@ -937,8 +937,8 @@ void CJabberProto::GroupchatProcessPresence(const TiXmlElement *node) else if (!mir_strcmp(type, "unavailable")) { const char *str = nullptr; if (xNode != nullptr && item->nick != nullptr) { - auto *reasonNode = itemNode->FirstChildElement("reason"); - str = itemNode->Attribute("jid"); + auto *reasonNode = XmlFirstChild(itemNode, "reason"); + str = XmlGetAttr(itemNode, "jid"); int iStatus = sttGetStatusCode(xNode); if (iStatus == 301 && r != nullptr) @@ -972,7 +972,7 @@ void CJabberProto::GroupchatProcessPresence(const TiXmlElement *node) } } - auto *statusNode = node->FirstChildElement("status"); + auto *statusNode = XmlFirstChild(node, "status"); GcLogUpdateMemberStatus(item, resource, nick, str, GC_EVENT_PART, statusNode); ListRemoveResource(LIST_CHATROOM, from); @@ -1016,10 +1016,10 @@ void CJabberProto::GroupchatProcessMessage(const TiXmlElement *node) CMStringW imgLink; if (!node->Name() || mir_strcmp(node->Name(), "message")) return; - if ((from = node->Attribute("from")) == nullptr) return; + if ((from = XmlGetAttr(node, "from")) == nullptr) return; if ((item = ListGetItemPtr(LIST_CHATROOM, from)) == nullptr) return; - if ((type = node->Attribute("type")) == nullptr) return; + if ((type = XmlGetAttr(node, "type")) == nullptr) return; if (!mir_strcmp(type, "error")) return; @@ -1030,14 +1030,14 @@ void CJabberProto::GroupchatProcessMessage(const TiXmlElement *node) if (resource != nullptr && *++resource == '\0') resource = nullptr; - if ((n = node->FirstChildElement("subject")) != nullptr) { + if ((n = XmlFirstChild(node, "subject")) != nullptr) { msgText = n->GetText(); if (msgText == nullptr || msgText[0] == '\0') return; gce.iType = GC_EVENT_TOPIC; - if (resource == nullptr && (m = node->FirstChildElement("body")) != nullptr) { + if (resource == nullptr && (m = XmlFirstChild(node, "body")) != nullptr) { const char *tmpnick = m->GetText(); if (tmpnick == nullptr || *tmpnick == 0) return; @@ -1057,7 +1057,7 @@ void CJabberProto::GroupchatProcessMessage(const TiXmlElement *node) imgLink = ExtractImage(node); if ((n = XmlGetChildByTag(node, "body", "xml:lang", m_tszSelectedLang)) == nullptr) - if ((n = node->FirstChildElement("body")) == nullptr) + if ((n = XmlFirstChild(node, "body")) == nullptr) return; msgText = n->GetText(); @@ -1078,7 +1078,7 @@ void CJabberProto::GroupchatProcessMessage(const TiXmlElement *node) time_t msgTime = 0; if (!JabberReadXep203delay(node, msgTime)) { auto *xDelay = XmlGetChildByTag(node, "x", "xmlns", "jabber:x:delay"); - if (xDelay && (p = xDelay->Attribute("stamp")) != nullptr) + if (xDelay && (p = XmlGetAttr(xDelay, "stamp")) != nullptr) msgTime = JabberIsoToUnixTime(p); } diff --git a/protocols/JabberG/src/jabber_ibb.cpp b/protocols/JabberG/src/jabber_ibb.cpp index 94a10847cd..c0eadf883e 100644 --- a/protocols/JabberG/src/jabber_ibb.cpp +++ b/protocols/JabberG/src/jabber_ibb.cpp @@ -53,8 +53,8 @@ BOOL CJabberProto::OnFtHandleIbbIq(const TiXmlElement *iqNode, CJabberIqInfo *pI FtHandleIbbRequest(iqNode, FALSE); else if (!mir_strcmp(pInfo->GetChildNodeName(), "data")) { BOOL bOk = FALSE; - const char *sid = pInfo->GetChildNode()->Attribute("sid"); - const char *seq = pInfo->GetChildNode()->Attribute("seq"); + const char *sid = XmlGetAttr(pInfo->GetChildNode(), "sid"); + const char *seq = XmlGetAttr(pInfo->GetChildNode(), "seq"); if (sid && seq && pInfo->GetChildNode()->GetText()) bOk = OnIbbRecvdData(pInfo->GetChildNode()->GetText(), sid, seq); diff --git a/protocols/JabberG/src/jabber_iq.cpp b/protocols/JabberG/src/jabber_iq.cpp index b49c067554..a6888620f7 100644 --- a/protocols/JabberG/src/jabber_iq.cpp +++ b/protocols/JabberG/src/jabber_iq.cpp @@ -243,7 +243,7 @@ bool CJabberIqManager::HandleIq(int nIqId, const TiXmlElement *pNode) if (nIqId == -1 || pNode == nullptr) return false; - const char *szType = pNode->Attribute("type"); + const char *szType = XmlGetAttr(pNode, "type"); if (!szType) return false; @@ -263,24 +263,24 @@ bool CJabberIqManager::HandleIq(int nIqId, const TiXmlElement *pNode) pInfo->m_nIqType = nIqType; if (nIqType == JABBER_IQ_TYPE_RESULT) { if (pInfo->m_dwParamsToParse & JABBER_IQ_PARSE_CHILD_TAG_NODE) - pInfo->m_pChildNode = pNode->FirstChildElement(); + pInfo->m_pChildNode = XmlFirstChild(pNode); if (pInfo->m_pChildNode && (pInfo->m_dwParamsToParse & JABBER_IQ_PARSE_CHILD_TAG_NAME)) pInfo->m_szChildTagName = pInfo->m_pChildNode->Name(); if (pInfo->m_pChildNode && (pInfo->m_dwParamsToParse & JABBER_IQ_PARSE_CHILD_TAG_XMLNS)) - pInfo->m_szChildTagXmlns = pNode->Attribute("xmlns"); + pInfo->m_szChildTagXmlns = XmlGetAttr(pNode, "xmlns"); } if (pInfo->m_dwParamsToParse & JABBER_IQ_PARSE_TO) - pInfo->m_szTo = pNode->Attribute("to"); + pInfo->m_szTo = XmlGetAttr(pNode, "to"); if (pInfo->m_dwParamsToParse & JABBER_IQ_PARSE_FROM) - pInfo->m_szFrom = pNode->Attribute("from"); + pInfo->m_szFrom = XmlGetAttr(pNode, "from"); if (pInfo->m_szFrom && (pInfo->m_dwParamsToParse & JABBER_IQ_PARSE_HCONTACT)) pInfo->m_hContact = ppro->HContactFromJID(pInfo->m_szFrom); if (pInfo->m_dwParamsToParse & JABBER_IQ_PARSE_ID_STR) - pInfo->m_szId = pNode->Attribute("id"); + pInfo->m_szId = XmlGetAttr(pNode, "id"); (ppro->*(pInfo->m_pHandler))(pNode, pInfo); delete pInfo; @@ -293,7 +293,7 @@ bool CJabberIqManager::HandleIqPermanent(const TiXmlElement *pNode) { for (auto &pInfo : m_arHandlers) { // have to get all data here, in the loop, because there's always possibility that previous handler modified it - const char *szType = pNode->Attribute("type"); + const char *szType = XmlGetAttr(pNode, "type"); if (!szType) return FALSE; @@ -309,12 +309,12 @@ bool CJabberIqManager::HandleIqPermanent(const TiXmlElement *pNode) if (!(pInfo->m_nIqTypes & iqInfo.m_nIqType)) continue; - auto *pFirstChild = pNode->FirstChildElement(); + auto *pFirstChild = XmlFirstChild(pNode); if (!pFirstChild || !pFirstChild->Name()) return FALSE; const char *szTagName = pFirstChild->Name(); - const char *szXmlns = pFirstChild->Attribute("xmlns"); + const char *szXmlns = XmlGetAttr(pFirstChild, "xmlns"); if ((!pInfo->m_szXmlns || (szXmlns && !mir_strcmp(pInfo->m_szXmlns, szXmlns))) && (!pInfo->m_szTag || !mir_strcmp(pInfo->m_szTag, szTagName))) { @@ -322,14 +322,14 @@ bool CJabberIqManager::HandleIqPermanent(const TiXmlElement *pNode) iqInfo.m_pChildNode = pFirstChild; iqInfo.m_szChildTagName = szTagName; iqInfo.m_szChildTagXmlns = szXmlns; - iqInfo.m_szId = pNode->Attribute("id"); + iqInfo.m_szId = XmlGetAttr(pNode, "id"); iqInfo.m_pUserData = pInfo->m_pUserData; if (pInfo->m_dwParamsToParse & JABBER_IQ_PARSE_TO) - iqInfo.m_szTo = pNode->Attribute("to"); + iqInfo.m_szTo = XmlGetAttr(pNode, "to"); if (pInfo->m_dwParamsToParse & JABBER_IQ_PARSE_FROM) - iqInfo.m_szFrom = pNode->Attribute("from"); + iqInfo.m_szFrom = XmlGetAttr(pNode, "from"); if ((pInfo->m_dwParamsToParse & JABBER_IQ_PARSE_HCONTACT) && (iqInfo.m_szFrom)) iqInfo.m_hContact = ppro->HContactFromJID(iqInfo.m_szFrom); diff --git a/protocols/JabberG/src/jabber_iq_handlers.cpp b/protocols/JabberG/src/jabber_iq_handlers.cpp index d87b795700..8686e1f314 100644 --- a/protocols/JabberG/src/jabber_iq_handlers.cpp +++ b/protocols/JabberG/src/jabber_iq_handlers.cpp @@ -183,7 +183,7 @@ BOOL CJabberProto::OnIqRequestAvatar(const TiXmlElement*, CJabberIqInfo *pInfo) BOOL CJabberProto::OnSiRequest(const TiXmlElement *node, CJabberIqInfo *pInfo) { - const char *szProfile = pInfo->GetChildNode()->Attribute("profile"); + const char *szProfile = XmlGetAttr(pInfo->GetChildNode(), "profile"); if (szProfile && !mir_strcmp(szProfile, JABBER_FEAT_SI_FT)) FtHandleSiRequest(node); @@ -229,13 +229,13 @@ BOOL CJabberProto::OnRosterPushRequest(const TiXmlElement*, CJabberIqInfo *pInfo debugLogA(" Got roster push"); for (auto *itemNode : TiXmlFilter(queryNode, "item")) { - const char *jid = itemNode->Attribute("jid"), *str = itemNode->Attribute("subscription"); + const char *jid = XmlGetAttr(itemNode, "jid"), *str = XmlGetAttr(itemNode, "subscription"); if (jid == nullptr || str == nullptr) continue; // we will not add new account when subscription=remove if (!mir_strcmp(str, "to") || !mir_strcmp(str, "both") || !mir_strcmp(str, "from") || !mir_strcmp(str, "none")) { - const char *name = itemNode->Attribute("name"); + const char *name = XmlGetAttr(itemNode, "name"); ptrA nick((name != nullptr) ? mir_strdup(name) : JabberNickFromJID(jid)); if (nick != nullptr) { MCONTACT hContact = HContactFromJID(jid, false); @@ -315,7 +315,7 @@ BOOL CJabberProto::OnIqRequestOOB(const TiXmlElement*, CJabberIqInfo *pInfo) if (m_bBsOnlyIBB) { // reject XmlNodeIq iq("error", pInfo); - TiXmlElement *e = XmlAddChild(iq, "error", "File transfer refused"); e->SetAttribute("code", 406); + TiXmlElement *e = XmlAddChildA(iq, "error", "File transfer refused"); e->SetAttribute("code", 406); m_ThreadInfo->send(iq); return TRUE; } @@ -373,7 +373,7 @@ BOOL CJabberProto::OnIqRequestOOB(const TiXmlElement*, CJabberIqInfo *pInfo) } else { // reject XmlNodeIq iq("error", pInfo); - TiXmlElement *e = XmlAddChild(iq, "error", "File transfer refused"); e->SetAttribute("code", 406); + TiXmlElement *e = XmlAddChildA(iq, "error", "File transfer refused"); e->SetAttribute("code", 406); m_ThreadInfo->send(iq); delete ft; } @@ -385,7 +385,7 @@ BOOL CJabberProto::OnHandleDiscoInfoRequest(const TiXmlElement *iqNode, CJabberI if (!pInfo->GetChildNode()) return TRUE; - const char *szNode = pInfo->GetChildNode()->Attribute("node"); + const char *szNode = XmlGetAttr(pInfo->GetChildNode(), "node"); // caps hack if (m_clientCapsManager.HandleInfoRequest(iqNode, pInfo, szNode)) return TRUE; @@ -408,7 +408,7 @@ BOOL CJabberProto::OnHandleDiscoItemsRequest(const TiXmlElement *iqNode, CJabber return TRUE; // ad-hoc commands check: - const char *szNode = pInfo->GetChildNode()->Attribute("node"); + const char *szNode = XmlGetAttr(pInfo->GetChildNode(), "node"); if (szNode && m_adhocManager.HandleItemsRequest(iqNode, pInfo, szNode)) return TRUE; @@ -449,13 +449,13 @@ BOOL CJabberProto::OnIqHttpAuth(const TiXmlElement *node, CJabberIqInfo *pInfo) if (!node || !pInfo->GetChildNode() || !pInfo->GetFrom() || !pInfo->GetIdStr()) return TRUE; - auto *pConfirm = node->FirstChildElement("confirm"); + auto *pConfirm = XmlFirstChild(node, "confirm"); if (!pConfirm) return TRUE; - const char *szId = pConfirm->Attribute("id"); - const char *szMethod = pConfirm->Attribute("method"); - const char *szUrl = pConfirm->Attribute("url"); + const char *szId = XmlGetAttr(pConfirm, "id"); + const char *szUrl = XmlGetAttr(pConfirm, "url"); + const char *szMethod = XmlGetAttr(pConfirm, "method"); if (!szId || !szMethod || !szUrl) return TRUE; diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp index c9e32b6336..5fa6333525 100755 --- a/protocols/JabberG/src/jabber_iqid.cpp +++ b/protocols/JabberG/src/jabber_iqid.cpp @@ -34,7 +34,7 @@ void CJabberProto::OnIqResultServerDiscoInfo(const TiXmlElement *iqNode, CJabber if (iqNode == nullptr) return; - const char *type = iqNode->Attribute("type"); + const char *type = XmlGetAttr(iqNode, "type"); if (mir_strcmp(type, "result")) return; @@ -44,9 +44,9 @@ void CJabberProto::OnIqResultServerDiscoInfo(const TiXmlElement *iqNode, CJabber for (auto *identity : TiXmlFilter(query, "identity")) { JABBER_DISCO_FIELD tmp = { - identity->Attribute("category"), - identity->Attribute("type"), - identity->Attribute("name") }; + XmlGetAttr(identity, "category"), + XmlGetAttr(identity, "type"), + XmlGetAttr(identity, "name") }; if (!mir_strcmp(tmp.category, "pubsub") && !mir_strcmp(tmp.type, "pep")) { m_bPepSupported = true; @@ -64,7 +64,7 @@ void CJabberProto::OnIqResultServerDiscoInfo(const TiXmlElement *iqNode, CJabber if (m_ThreadInfo) { for (auto *feature : TiXmlFilter(query, "feature")) { - const char *featureName = feature->Attribute("var"); + const char *featureName = XmlGetAttr(feature, "var"); if (!featureName) continue; @@ -222,20 +222,20 @@ void CJabberProto::OnIqResultGetAuth(const TiXmlElement *iqNode, CJabberIqInfo*) const TiXmlElement *queryNode; const char *type; - if ((type = iqNode->Attribute("type")) == nullptr) return; - if ((queryNode = iqNode->FirstChildElement("query")) == nullptr) return; + if ((type = XmlGetAttr(iqNode, "type")) == nullptr) return; + if ((queryNode = XmlFirstChild(iqNode, "query")) == nullptr) return; if (!mir_strcmp(type, "result")) { XmlNodeIq iq(AddIQ(&CJabberProto::OnIqResultSetAuth, JABBER_IQ_TYPE_SET)); auto *query = iq << XQUERY("jabber:iq:auth"); query << XCHILD("username", m_ThreadInfo->conn.username); - if (queryNode->FirstChildElement("digest") != nullptr && m_ThreadInfo->szStreamId) { + if (XmlFirstChild(queryNode, "digest") != nullptr && m_ThreadInfo->szStreamId) { JabberShaStrBuf buf; char text[200]; mir_snprintf(text, "%s%s", m_ThreadInfo->szStreamId, m_ThreadInfo->conn.password); query << XCHILD("digest", JabberSha1(text, buf)); } - else if (queryNode->FirstChildElement("password") != nullptr) + else if (XmlFirstChild(queryNode, "password") != nullptr) query << XCHILD("password", m_ThreadInfo->conn.password); else { debugLogA("No known authentication mechanism accepted by the server."); @@ -243,7 +243,7 @@ void CJabberProto::OnIqResultGetAuth(const TiXmlElement *iqNode, CJabberIqInfo*) return; } - if (queryNode->FirstChildElement("resource") != nullptr) + if (XmlFirstChild(queryNode, "resource") != nullptr) query << XCHILD("resource", m_ThreadInfo->resource); m_ThreadInfo->send(iq); @@ -266,7 +266,7 @@ void CJabberProto::OnIqResultSetAuth(const TiXmlElement *iqNode, CJabberIqInfo*) // RECVED: authentication result // ACTION: if successfully logged in, continue by requesting roster list and set my initial status debugLogA(" iqIdSetAuth"); - if ((type = iqNode->Attribute("type")) == nullptr) return; + if ((type = XmlGetAttr(iqNode, "type")) == nullptr) return; if (!mir_strcmp(type, "result")) { ptrA tszNick(getUStringA("Nick")); @@ -355,11 +355,11 @@ void CJabberProto::OnIqResultGetRoster(const TiXmlElement *iqNode, CJabberIqInfo if (pInfo->GetIqType() != JABBER_IQ_TYPE_RESULT) return; - auto *queryNode = iqNode->FirstChildElement("query"); + auto *queryNode = XmlFirstChild(iqNode, "query"); if (queryNode == nullptr) return; - if (mir_strcmp(queryNode->Attribute("xmlns"), JABBER_FEAT_IQ_ROSTER)) + if (mir_strcmp(XmlGetAttr(queryNode, "xmlns"), JABBER_FEAT_IQ_ROSTER)) return; if (!mir_strcmp(szGroupDelimiter, "\\")) @@ -370,7 +370,7 @@ void CJabberProto::OnIqResultGetRoster(const TiXmlElement *iqNode, CJabberIqInfo for (auto *itemNode : TiXmlFilter(queryNode, "item")) { bool bIsTransport = false; - const char *str = itemNode->Attribute("subscription"); + const char *str = XmlGetAttr(itemNode, "subscription"); JABBER_SUBSCRIPTION sub; if (str == nullptr) sub = SUB_NONE; @@ -379,13 +379,13 @@ void CJabberProto::OnIqResultGetRoster(const TiXmlElement *iqNode, CJabberIqInfo else if (!mir_strcmp(str, "from")) sub = SUB_FROM; else sub = SUB_NONE; - const char *jid = itemNode->Attribute("jid"); + const char *jid = XmlGetAttr(itemNode, "jid"); if (jid == nullptr) continue; if (strchr(jid, '@') == nullptr) bIsTransport = true; - const char *name = itemNode->Attribute("name"); + const char *name = XmlGetAttr(itemNode, "name"); char *nick = (name != nullptr) ? mir_strdup(name) : JabberNickFromJID(jid); if (nick == nullptr) continue; @@ -455,7 +455,7 @@ void CJabberProto::OnIqResultGetRoster(const TiXmlElement *iqNode, CJabberIqInfo setByte(hContact, "IsTransport", false); } - const char *imagepath = itemNode->Attribute("vz:img"); + const char *imagepath = XmlGetAttr(itemNode, "vz:img"); if (imagepath) httpavatars->insert(new JABBER_HTTP_AVATARS(imagepath, hContact)); } @@ -506,8 +506,8 @@ void CJabberProto::OnIqResultGetRegister(const TiXmlElement *iqNode, CJabberIqIn const TiXmlElement *queryNode; const char *type; - if ((type = iqNode->Attribute("type")) == nullptr) return; - if ((queryNode = iqNode->FirstChildElement("query")) == nullptr) return; + if ((type = XmlGetAttr(iqNode, "type")) == nullptr) return; + if ((queryNode = XmlFirstChild(iqNode, "query")) == nullptr) return; if (!mir_strcmp(type, "result")) { if (m_hwndAgentRegInput) @@ -526,8 +526,8 @@ void CJabberProto::OnIqResultSetRegister(const TiXmlElement *iqNode, CJabberIqIn debugLogA(" iqIdSetRegister"); const char *type, *from; - if ((type = iqNode->Attribute("type")) == nullptr) return; - if ((from = iqNode->Attribute("from")) == nullptr) return; + if ((type = XmlGetAttr(iqNode, "type")) == nullptr) return; + if ((from = XmlGetAttr(iqNode, "from")) == nullptr) return; if (!mir_strcmp(type, "result")) { MCONTACT hContact = HContactFromJID(from); @@ -622,14 +622,14 @@ void CJabberProto::OnIqResultGetVcard(const TiXmlElement *iqNode, CJabberIqInfo* DBVARIANT dbv; debugLogA(" iqIdGetVcard"); - if ((type = iqNode->Attribute("type")) == nullptr) return; - if ((jid = iqNode->Attribute("from")) == nullptr) return; + if ((type = XmlGetAttr(iqNode, "type")) == nullptr) return; + if ((jid = XmlGetAttr(iqNode, "from")) == nullptr) return; int id = JabberGetPacketID(iqNode); if (id == m_nJabberSearchID) { m_nJabberSearchID = -1; - if ((vCardNode = iqNode->FirstChildElement("vCard")) != nullptr) { + if ((vCardNode = XmlFirstChild(iqNode, "vCard")) != nullptr) { if (!mir_strcmp(type, "result")) { PROTOSEARCHRESULT psr = { 0 }; psr.cbSize = sizeof(psr); @@ -677,7 +677,7 @@ void CJabberProto::OnIqResultGetVcard(const TiXmlElement *iqNode, CJabberIqInfo* hasOrgname = false, hasOrgunit = false, hasRole = false, hasTitle = false, hasDesc = false, hasPhoto = false; int nEmail = 0, nPhone = 0, nYear, nMonth, nDay; - if ((vCardNode = iqNode->FirstChildElement("vCard")) != nullptr) { + if ((vCardNode = XmlFirstChild(iqNode, "vCard")) != nullptr) { for (auto *n : TiXmlEnum(vCardNode)) { if (n->Name() == nullptr) continue; @@ -727,10 +727,10 @@ void CJabberProto::OnIqResultGetVcard(const TiXmlElement *iqNode, CJabberIqInfo* if (hContact == 0) { mir_snprintf(text, "e-mailFlag%d", nEmail); int nFlag = 0; - if (n->FirstChildElement("HOME") != nullptr) nFlag |= JABBER_VCEMAIL_HOME; - if (n->FirstChildElement("WORK") != nullptr) nFlag |= JABBER_VCEMAIL_WORK; - if (n->FirstChildElement("INTERNET") != nullptr) nFlag |= JABBER_VCEMAIL_INTERNET; - if (n->FirstChildElement("X400") != nullptr) nFlag |= JABBER_VCEMAIL_X400; + if (XmlFirstChild(n, "HOME") != nullptr) nFlag |= JABBER_VCEMAIL_HOME; + if (XmlFirstChild(n, "WORK") != nullptr) nFlag |= JABBER_VCEMAIL_WORK; + if (XmlFirstChild(n, "INTERNET") != nullptr) nFlag |= JABBER_VCEMAIL_INTERNET; + if (XmlFirstChild(n, "X400") != nullptr) nFlag |= JABBER_VCEMAIL_X400; setWord(text, nFlag); } nEmail++; @@ -777,7 +777,7 @@ void CJabberProto::OnIqResultGetVcard(const TiXmlElement *iqNode, CJabberIqInfo* } } else if (!mir_strcmp(n->Name(), "ADR")) { - if (!hasHome && n->FirstChildElement("HOME") != nullptr) { + if (!hasHome && XmlFirstChild(n, "HOME") != nullptr) { // Home address char text[128]; hasHome = true; @@ -824,7 +824,7 @@ void CJabberProto::OnIqResultGetVcard(const TiXmlElement *iqNode, CJabberIqInfo* } } - if (!hasWork && n->FirstChildElement("WORK") != nullptr) { + if (!hasWork && XmlFirstChild(n, "WORK") != nullptr) { // Work address hasWork = true; if (auto *p = XmlGetChildText(n, "STREET")) { @@ -876,25 +876,25 @@ void CJabberProto::OnIqResultGetVcard(const TiXmlElement *iqNode, CJabberIqInfo* // Telephone/Fax/Cellular if (auto *p = XmlGetChildText(n, "NUMBER")) { if (hContact != 0) { - if (!hasFax && n->FirstChildElement("FAX") != nullptr) { + if (!hasFax && XmlFirstChild(n, "FAX") != nullptr) { hasFax = true; setUString(hContact, "Fax", p); } - else if (!hasCell && n->FirstChildElement("CELL") != nullptr) { + else if (!hasCell && XmlFirstChild(n, "CELL") != nullptr) { hasCell = true; setUString(hContact, "Cellular", p); } else if (!hasPhone && - (n->FirstChildElement("HOME") != nullptr || n->FirstChildElement("WORK") != nullptr || n->FirstChildElement("VOICE") != nullptr || - (n->FirstChildElement("FAX") == nullptr && - n->FirstChildElement("PAGER") == nullptr && - n->FirstChildElement("MSG") == nullptr && - n->FirstChildElement("CELL") == nullptr && - n->FirstChildElement("VIDEO") == nullptr && - n->FirstChildElement("BBS") == nullptr && - n->FirstChildElement("MODEM") == nullptr && - n->FirstChildElement("ISDN") == nullptr && - n->FirstChildElement("PCS") == nullptr))) + (XmlFirstChild(n, "HOME") != nullptr || XmlFirstChild(n, "WORK") != nullptr || XmlFirstChild(n, "VOICE") != nullptr || + (XmlFirstChild(n, "FAX") == nullptr && + XmlFirstChild(n, "PAGER") == nullptr && + XmlFirstChild(n, "MSG") == nullptr && + XmlFirstChild(n, "CELL") == nullptr && + XmlFirstChild(n, "VIDEO") == nullptr && + XmlFirstChild(n, "BBS") == nullptr && + XmlFirstChild(n, "MODEM") == nullptr && + XmlFirstChild(n, "ISDN") == nullptr && + XmlFirstChild(n, "PCS") == nullptr))) { hasPhone = true; setUString(hContact, "Phone", p); @@ -907,18 +907,18 @@ void CJabberProto::OnIqResultGetVcard(const TiXmlElement *iqNode, CJabberIqInfo* mir_snprintf(text, "PhoneFlag%d", nPhone); int nFlag = 0; - if (n->FirstChildElement("HOME") != nullptr) nFlag |= JABBER_VCTEL_HOME; - if (n->FirstChildElement("WORK") != nullptr) nFlag |= JABBER_VCTEL_WORK; - if (n->FirstChildElement("VOICE") != nullptr) nFlag |= JABBER_VCTEL_VOICE; - if (n->FirstChildElement("FAX") != nullptr) nFlag |= JABBER_VCTEL_FAX; - if (n->FirstChildElement("PAGER") != nullptr) nFlag |= JABBER_VCTEL_PAGER; - if (n->FirstChildElement("MSG") != nullptr) nFlag |= JABBER_VCTEL_MSG; - if (n->FirstChildElement("CELL") != nullptr) nFlag |= JABBER_VCTEL_CELL; - if (n->FirstChildElement("VIDEO") != nullptr) nFlag |= JABBER_VCTEL_VIDEO; - if (n->FirstChildElement("BBS") != nullptr) nFlag |= JABBER_VCTEL_BBS; - if (n->FirstChildElement("MODEM") != nullptr) nFlag |= JABBER_VCTEL_MODEM; - if (n->FirstChildElement("ISDN") != nullptr) nFlag |= JABBER_VCTEL_ISDN; - if (n->FirstChildElement("PCS") != nullptr) nFlag |= JABBER_VCTEL_PCS; + if (XmlFirstChild(n, "HOME") != nullptr) nFlag |= JABBER_VCTEL_HOME; + if (XmlFirstChild(n, "WORK") != nullptr) nFlag |= JABBER_VCTEL_WORK; + if (XmlFirstChild(n, "VOICE") != nullptr) nFlag |= JABBER_VCTEL_VOICE; + if (XmlFirstChild(n, "FAX") != nullptr) nFlag |= JABBER_VCTEL_FAX; + if (XmlFirstChild(n, "PAGER") != nullptr) nFlag |= JABBER_VCTEL_PAGER; + if (XmlFirstChild(n, "MSG") != nullptr) nFlag |= JABBER_VCTEL_MSG; + if (XmlFirstChild(n, "CELL") != nullptr) nFlag |= JABBER_VCTEL_CELL; + if (XmlFirstChild(n, "VIDEO") != nullptr) nFlag |= JABBER_VCTEL_VIDEO; + if (XmlFirstChild(n, "BBS") != nullptr) nFlag |= JABBER_VCTEL_BBS; + if (XmlFirstChild(n, "MODEM") != nullptr) nFlag |= JABBER_VCTEL_MODEM; + if (XmlFirstChild(n, "ISDN") != nullptr) nFlag |= JABBER_VCTEL_ISDN; + if (XmlFirstChild(n, "PCS") != nullptr) nFlag |= JABBER_VCTEL_PCS; setWord(text, nFlag); nPhone++; } @@ -1103,7 +1103,7 @@ void CJabberProto::OnIqResultGetVcard(const TiXmlElement *iqNode, CJabberIqInfo* void CJabberProto::OnIqResultSetVcard(const TiXmlElement *iqNode, CJabberIqInfo*) { debugLogA(" iqIdSetVcard"); - if (iqNode->Attribute("type")) + if (XmlGetAttr(iqNode, "type")) WindowList_Broadcast(m_hWindowList, WM_JABBER_REFRESH_VCARD, 0, 0); } @@ -1114,17 +1114,17 @@ void CJabberProto::OnIqResultSetSearch(const TiXmlElement *iqNode, CJabberIqInfo int id; debugLogA(" iqIdGetSearch"); - if ((type = iqNode->Attribute("type")) == nullptr) return; + if ((type = XmlGetAttr(iqNode, "type")) == nullptr) return; if ((id = JabberGetPacketID(iqNode)) == -1) return; if (!mir_strcmp(type, "result")) { - if ((queryNode = iqNode->FirstChildElement("query")) == nullptr) + if ((queryNode = XmlFirstChild(iqNode, "query")) == nullptr) return; PROTOSEARCHRESULT psr = {}; psr.cbSize = sizeof(psr); for (auto *itemNode : TiXmlFilter(queryNode, "item")) { - if (auto *jid = itemNode->Attribute("jid")) { + if (auto *jid = XmlGetAttr(itemNode, "jid")) { psr.id.w = mir_utf8decodeW(jid); debugLogA("Result jid = %s", jid); if (auto *p = XmlGetChildText(itemNode, "nick")) @@ -1156,7 +1156,7 @@ void CJabberProto::OnIqResultExtSearch(const TiXmlElement *iqNode, CJabberIqInfo const TiXmlElement *queryNode; debugLogA(" iqIdGetExtSearch"); - const char *type = iqNode->Attribute("type"); + const char *type = XmlGetAttr(iqNode, "type"); if (type == nullptr) return; @@ -1165,19 +1165,19 @@ void CJabberProto::OnIqResultExtSearch(const TiXmlElement *iqNode, CJabberIqInfo return; if (!mir_strcmp(type, "result")) { - if ((queryNode = iqNode->FirstChildElement("query")) == nullptr) return; - if ((queryNode = queryNode->FirstChildElement("x")) == nullptr) return; + if ((queryNode = XmlFirstChild(iqNode, "query")) == nullptr) return; + if ((queryNode = XmlFirstChild(queryNode, "x")) == nullptr) return; for (auto *itemNode : TiXmlFilter(queryNode, "item")) { PROTOSEARCHRESULT psr = { 0 }; psr.cbSize = sizeof(psr); psr.flags = PSR_UNICODE; for (auto *fieldNode : TiXmlFilter(itemNode, "field")) { - const char *fieldName = fieldNode->Attribute("var"); + const char *fieldName = XmlGetAttr(fieldNode, "var"); if (fieldName == nullptr) continue; - auto *n = fieldNode->FirstChildElement("value"); + auto *n = XmlFirstChild(fieldNode, "value"); if (n == nullptr) continue; @@ -1216,7 +1216,7 @@ void CJabberProto::OnIqResultSetPassword(const TiXmlElement *iqNode, CJabberIqIn { debugLogA(" iqIdSetPassword"); - const char *type = iqNode->Attribute("type"); + const char *type = XmlGetAttr(iqNode, "type"); if (type == nullptr) return; @@ -1232,7 +1232,7 @@ void CJabberProto::OnIqResultGetVCardAvatar(const TiXmlElement *iqNode, CJabberI { debugLogA(" OnIqResultGetVCardAvatar"); - const char *from = iqNode->Attribute("from"); + const char *from = XmlGetAttr(iqNode, "from"); if (from == nullptr) return; @@ -1241,12 +1241,12 @@ void CJabberProto::OnIqResultGetVCardAvatar(const TiXmlElement *iqNode, CJabberI return; const char *type; - if ((type = iqNode->Attribute("type")) == nullptr) return; + if ((type = XmlGetAttr(iqNode, "type")) == nullptr) return; if (mir_strcmp(type, "result")) return; - auto *vCard = iqNode->FirstChildElement("vCard"); + auto *vCard = XmlFirstChild(iqNode, "vCard"); if (vCard == nullptr) return; - vCard = vCard->FirstChildElement("PHOTO"); + vCard = XmlFirstChild(vCard, "PHOTO"); if (vCard == nullptr) return; if (vCard->NoChildren()) { @@ -1270,7 +1270,7 @@ void CJabberProto::OnIqResultGetClientAvatar(const TiXmlElement *iqNode, CJabber debugLogA(" iqIdResultGetClientAvatar"); - const char *from = iqNode->Attribute("from"); + const char *from = XmlGetAttr(iqNode, "from"); if (from == nullptr) return; MCONTACT hContact = HContactFromJID(from); @@ -1278,17 +1278,17 @@ void CJabberProto::OnIqResultGetClientAvatar(const TiXmlElement *iqNode, CJabber return; const TiXmlElement *n = nullptr; - if ((type = iqNode->Attribute("type")) != nullptr && !mir_strcmp(type, "result")) { - auto *queryNode = iqNode->FirstChildElement("query"); + if ((type = XmlGetAttr(iqNode, "type")) != nullptr && !mir_strcmp(type, "result")) { + auto *queryNode = XmlFirstChild(iqNode, "query"); if (queryNode != nullptr) { - const char *xmlns = queryNode->Attribute("xmlns"); + const char *xmlns = XmlGetAttr(queryNode, "xmlns"); if (!mir_strcmp(xmlns, JABBER_FEAT_AVATAR)) - n = queryNode->FirstChildElement("data"); + n = XmlFirstChild(queryNode, "data"); } } if (n != nullptr) { - OnIqResultGotAvatar(hContact, n->GetText(), n->Attribute("mimetype")); + OnIqResultGotAvatar(hContact, n->GetText(), XmlGetAttr(n, "mimetype")); return; } @@ -1308,7 +1308,7 @@ void CJabberProto::OnIqResultGetServerAvatar(const TiXmlElement *iqNode, CJabber { debugLogA(" iqIdResultGetServerAvatar"); - const char *from = iqNode->Attribute("from"); + const char *from = XmlGetAttr(iqNode, "from"); if (from == nullptr) return; @@ -1317,18 +1317,18 @@ void CJabberProto::OnIqResultGetServerAvatar(const TiXmlElement *iqNode, CJabber return; const TiXmlElement *n = nullptr; - const char *type = iqNode->Attribute("type"); + const char *type = XmlGetAttr(iqNode, "type"); if (!mir_strcmp(type, "result")) { - auto *queryNode = iqNode->FirstChildElement("query"); + auto *queryNode = XmlFirstChild(iqNode, "query"); if (queryNode != nullptr) { - const char *xmlns = queryNode->Attribute("xmlns"); + const char *xmlns = XmlGetAttr(queryNode, "xmlns"); if (!mir_strcmp(xmlns, JABBER_FEAT_SERVER_AVATAR)) - n = queryNode->FirstChildElement("data"); + n = XmlFirstChild(queryNode, "data"); } } if (n != nullptr) { - OnIqResultGotAvatar(hContact, n->GetText(), n->Attribute("mimetype")); + OnIqResultGotAvatar(hContact, n->GetText(), XmlGetAttr(n, "mimetype")); return; } @@ -1403,7 +1403,7 @@ void CJabberProto::OnIqResultDiscoBookmarks(const TiXmlElement *iqNode, CJabberI // RECVED: list of bookmarks // ACTION: refresh bookmarks dialog debugLogA(" iqIdGetBookmarks"); - const char *type = iqNode->Attribute("type"); + const char *type = XmlGetAttr(iqNode, "type"); if (type == nullptr) return; @@ -1414,27 +1414,27 @@ void CJabberProto::OnIqResultDiscoBookmarks(const TiXmlElement *iqNode, CJabberI EnableMenuItems(true); } - if (auto *storageNode = XmlGetChildByTag(iqNode->FirstChildElement("query"), "storage", "xmlns", "storage:bookmarks")) { + if (auto *storageNode = XmlGetChildByTag(XmlFirstChild(iqNode, "query"), "storage", "xmlns", "storage:bookmarks")) { ListRemoveList(LIST_BOOKMARK); for (auto *itemNode : TiXmlEnum(storageNode)) { if (const char *name = itemNode->Name()) { - if (!mir_strcmp(name, "conference") && (jid = itemNode->Attribute("jid"))) { + if (!mir_strcmp(name, "conference") && (jid = XmlGetAttr(itemNode, "jid"))) { JABBER_LIST_ITEM *item = ListAdd(LIST_BOOKMARK, jid); - item->name = mir_utf8decodeW(itemNode->Attribute("name")); + item->name = mir_utf8decodeW(XmlGetAttr(itemNode, "name")); item->type = mir_strdup("conference"); item->bUseResource = true; item->nick = mir_strdup(XmlGetChildText(itemNode, "nick")); item->password = mir_strdup(XmlGetChildText(itemNode, "password")); - const char *autoJ = itemNode->Attribute("autojoin"); + const char *autoJ = XmlGetAttr(itemNode, "autojoin"); if (autoJ != nullptr) item->bAutoJoin = !mir_strcmp(autoJ, "true") || !mir_strcmp(autoJ, "1"); } - else if (!mir_strcmp(name, "url") && (jid = itemNode->Attribute("url"))) { + else if (!mir_strcmp(name, "url") && (jid = XmlGetAttr(itemNode, "url"))) { JABBER_LIST_ITEM *item = ListAdd(LIST_BOOKMARK, jid); item->bUseResource = true; - item->name = mir_utf8decodeW(itemNode->Attribute("name")); + item->name = mir_utf8decodeW(XmlGetAttr(itemNode, "name")); item->type = mir_strdup("url"); } } @@ -1492,7 +1492,7 @@ void CJabberProto::OnIqResultSetBookmarks(const TiXmlElement *iqNode, CJabberIqI debugLogA(" iqIdSetBookmarks"); - const char *type = iqNode->Attribute("type"); + const char *type = XmlGetAttr(iqNode, "type"); if (type == nullptr) return; diff --git a/protocols/JabberG/src/jabber_iqid_muc.cpp b/protocols/JabberG/src/jabber_iqid_muc.cpp index 03c9fff902..6cc9421c32 100644 --- a/protocols/JabberG/src/jabber_iqid_muc.cpp +++ b/protocols/JabberG/src/jabber_iqid_muc.cpp @@ -42,8 +42,8 @@ void CJabberProto::SetMucConfig(CJabberFormDlg *pDlg, void *from) void CJabberProto::OnIqResultGetMuc(const TiXmlElement *iqNode, CJabberIqInfo*) { debugLogA(" iqIdGetMuc"); - const char *type = iqNode->Attribute("type"); - const char *from = iqNode->Attribute("from"); + const char *type = XmlGetAttr(iqNode, "type"); + const char *from = XmlGetAttr(iqNode, "from"); if (type == nullptr || from == nullptr) return; @@ -110,13 +110,13 @@ class CJabberMucJidListDlg : public CJabberDlgBase wchar_t tszItemText[JABBER_MAX_JID_LEN + 256]; TiXmlElement *iqNode = m_info->iqNode; if (iqNode != nullptr) { - const char *from = iqNode->Attribute("from"); + const char *from = XmlGetAttr(iqNode, "from"); if (from != nullptr) { - TiXmlElement *queryNode = iqNode->FirstChildElement("query"); + auto *queryNode = XmlFirstChild(iqNode, "query"); if (queryNode != nullptr) { lvi.iItem = 0; for (auto *itemNode : TiXmlEnum(queryNode)) { - const char *jid = itemNode->Attribute("jid"); + const char *jid = XmlGetAttr(itemNode, "jid"); if (jid == nullptr) continue; @@ -128,7 +128,7 @@ class CJabberMucJidListDlg : public CJabberDlgBase } } else if (m_info->type == MUC_VOICELIST || m_info->type == MUC_MODERATORLIST) { - const char *nick = itemNode->Attribute("nick"); + const char *nick = XmlGetAttr(itemNode, "nick"); if (nick != nullptr) { mir_snwprintf(tszItemText, L"%s (%s)", Utf2T(nick).get(), Utf2T(jid).get()); lvi.pszText = tszItemText; @@ -259,10 +259,10 @@ public: if (pInfo != nullptr) { TiXmlElement *iqNode = pInfo->iqNode; if (iqNode != nullptr) { - const char *from = iqNode->Attribute("from"); + const char *from = XmlGetAttr(iqNode, "from"); if (from != nullptr) { pInfo->roomJid = mir_strdup(from); - TiXmlElement *queryNode = iqNode->FirstChildElement("query"); + auto *queryNode = XmlFirstChild(iqNode, "query"); if (queryNode != nullptr) mir_snwprintf(title, TranslateT("%s, %d items (%s)"), pInfo->type2str(), XmlGetChildCount(queryNode), Utf2T(from).get()); } @@ -348,11 +348,11 @@ static void CALLBACK JabberMucJidListCreateDialogApcProc(void* param) if (iqNode == nullptr) return; - const char *from = iqNode->Attribute("from"); + const char *from = XmlGetAttr(iqNode, "from"); if (from == nullptr) return; - TiXmlElement *queryNode = iqNode->FirstChildElement("query"); + auto *queryNode = XmlFirstChild(iqNode, "query"); if (queryNode == nullptr) return; @@ -371,7 +371,7 @@ static void CALLBACK JabberMucJidListCreateDialogApcProc(void* param) void CJabberProto::OnIqResultMucGetJidList(const TiXmlElement *iqNode, JABBER_MUC_JIDLIST_TYPE listType) { - const char *type = iqNode->Attribute("type"); + const char *type = XmlGetAttr(iqNode, "type"); if (type == nullptr) return; diff --git a/protocols/JabberG/src/jabber_message_handlers.cpp b/protocols/JabberG/src/jabber_message_handlers.cpp index 79bfd83f5c..1131d81c6a 100644 --- a/protocols/JabberG/src/jabber_message_handlers.cpp +++ b/protocols/JabberG/src/jabber_message_handlers.cpp @@ -54,8 +54,8 @@ BOOL CJabberProto::OnMessageError(const TiXmlElement *node, ThreadData*, CJabber BOOL CJabberProto::OnMessageIbb(const TiXmlElement*, ThreadData*, CJabberMessageInfo* pInfo) { BOOL bOk = FALSE; - const char *sid = pInfo->GetChildNode()->Attribute("sid"); - const char *seq = pInfo->GetChildNode()->Attribute("seq"); + const char *sid = XmlGetAttr(pInfo->GetChildNode(), "sid"); + const char *seq = XmlGetAttr(pInfo->GetChildNode(), "seq"); if (sid && seq && pInfo->GetChildNode()->GetText()) bOk = OnIbbRecvdData(pInfo->GetChildNode()->GetText(), sid, seq); diff --git a/protocols/JabberG/src/jabber_message_manager.cpp b/protocols/JabberG/src/jabber_message_manager.cpp index 486a7b49d6..1fe392abd7 100644 --- a/protocols/JabberG/src/jabber_message_manager.cpp +++ b/protocols/JabberG/src/jabber_message_manager.cpp @@ -55,7 +55,7 @@ bool CJabberMessageManager::HandleMessagePermanent(const TiXmlElement *node, Thr // have to get all data here, in the loop, because there's always possibility that previous handler modified it CJabberMessageInfo messageInfo; - const char *szType = node->Attribute("type"); + const char *szType = XmlGetAttr(node, "type"); if (szType) { if (!mir_strcmpi(szType, "normal")) messageInfo.m_nMessageType = JABBER_MESSAGE_TYPE_NORMAL; @@ -76,7 +76,7 @@ bool CJabberMessageManager::HandleMessagePermanent(const TiXmlElement *node, Thr // enumerate all children and see whether this node suits handler criteria for (auto *child : TiXmlEnum(node)) { const char *szTagName = child->Name(); - const char *szXmlns = child->Attribute("xmlns"); + const char *szXmlns = XmlGetAttr(child, "xmlns"); if ((!it->m_szXmlns || (szXmlns && !mir_strcmp(it->m_szXmlns, szXmlns))) && (!it->m_szTag || !mir_strcmp(it->m_szTag, szTagName))) { // node suits handler criteria, call the handler @@ -84,13 +84,13 @@ bool CJabberMessageManager::HandleMessagePermanent(const TiXmlElement *node, Thr messageInfo.m_szChildTagName = szTagName; messageInfo.m_szChildTagXmlns = szXmlns; messageInfo.m_pUserData = it->m_pUserData; - messageInfo.m_szFrom = node->Attribute("from"); // is necessary for ppro->debugLogA() below, that's why we must parse it even if JABBER_MESSAGE_PARSE_FROM flag is not set + messageInfo.m_szFrom = XmlGetAttr(node, "from"); // is necessary for ppro->debugLogA() below, that's why we must parse it even if JABBER_MESSAGE_PARSE_FROM flag is not set if (it->m_dwParamsToParse & JABBER_MESSAGE_PARSE_ID_STR) - messageInfo.m_szId = node->Attribute("id"); + messageInfo.m_szId = XmlGetAttr(node, "id"); if (it->m_dwParamsToParse & JABBER_IQ_PARSE_TO) - messageInfo.m_szTo = node->Attribute("to"); + messageInfo.m_szTo = XmlGetAttr(node, "to"); if (it->m_dwParamsToParse & JABBER_MESSAGE_PARSE_HCONTACT) messageInfo.m_hContact = ppro->HContactFromJID(messageInfo.m_szFrom); diff --git a/protocols/JabberG/src/jabber_misc.cpp b/protocols/JabberG/src/jabber_misc.cpp index 1ebda3ebf6..57c1fa9dfd 100755 --- a/protocols/JabberG/src/jabber_misc.cpp +++ b/protocols/JabberG/src/jabber_misc.cpp @@ -449,10 +449,10 @@ CMStringA CJabberProto::ExtractImage(const TiXmlElement *node) const char *src; CMStringA link; - if ((nHtml = node->FirstChildElement("html")) != nullptr && - (nBody = nHtml->FirstChildElement("body")) != nullptr && - (nImg = nBody->FirstChildElement("img")) != nullptr && - (src = nImg->Attribute("src")) != nullptr) { + if ((nHtml = XmlFirstChild(node, "html")) != nullptr && + (nBody = XmlFirstChild(nHtml, "body")) != nullptr && + (nImg = XmlFirstChild(nBody, "img")) != nullptr && + (src = XmlGetAttr(nImg, "src")) != nullptr) { CMStringA strSrc(src); if (strSrc.Left(11).Compare("data:image/") == 0) { diff --git a/protocols/JabberG/src/jabber_notes.cpp b/protocols/JabberG/src/jabber_notes.cpp index 3b346ff64c..aeb217c987 100644 --- a/protocols/JabberG/src/jabber_notes.cpp +++ b/protocols/JabberG/src/jabber_notes.cpp @@ -39,9 +39,9 @@ CNoteItem::CNoteItem(const TiXmlElement *hXml, const char *szFrom) { SetData( XmlGetChildText(hXml, "title"), - szFrom ? szFrom : hXml->Attribute("from"), + szFrom ? szFrom : XmlGetAttr(hXml, "from"), Utf2T(XmlGetChildText(hXml, "text")), - hXml->Attribute("tags")); + XmlGetAttr(hXml, "tags")); } CNoteItem::~CNoteItem() diff --git a/protocols/JabberG/src/jabber_omemo.cpp b/protocols/JabberG/src/jabber_omemo.cpp index 61834f80e5..4dc253d679 100755 --- a/protocols/JabberG/src/jabber_omemo.cpp +++ b/protocols/JabberG/src/jabber_omemo.cpp @@ -1486,12 +1486,12 @@ bool CJabberProto::OmemoHandleMessage(const TiXmlElement *node, const char *jid, debugLogA("Jabber OMEMO: sessions not yet created, session creation launched"); return false; } - auto *header_node = node->FirstChildElement("header"); + auto *header_node = XmlFirstChild(node, "header"); if (!header_node) { debugLogA("Jabber OMEMO: error: omemo message does not contain header"); return true; //this should never happen } - auto *payload_node = node->FirstChildElement("payload"); + auto *payload_node = XmlFirstChild(node, "payload"); if (!payload_node) { debugLogA("Jabber OMEMO: omemo message does not contain payload, it's may be \"KeyTransportElement\" which is currently unused by our implementation"); return true; //this is "KeyTransportElement" which is currently unused @@ -1501,12 +1501,12 @@ bool CJabberProto::OmemoHandleMessage(const TiXmlElement *node, const char *jid, debugLogA("Jabber OMEMO: error: failed to get payload data"); return true; //this should never happen } - const char *iv_base64 = header_node->FirstChildElement("iv")->GetText(); + const char *iv_base64 = XmlFirstChild(header_node, "iv")->GetText(); if (!iv_base64) { Netlib_Log(nullptr, "Jabber OMEMO: error: failed to get iv data"); return true; } - const char *sender_dev_id = header_node->Attribute("sid"); + const char *sender_dev_id = XmlGetAttr(header_node, "sid"); if (!sender_dev_id) { debugLogA("Jabber OMEMO: error: failed to get sender device id"); return true; @@ -1728,9 +1728,9 @@ void CJabberProto::OmemoHandleDeviceList(const TiXmlElement *node) auto *message = node->Parent()->ToElement(); message = message->Parent()->ToElement(); - const char *jid = message->Attribute("from"); + const char *jid = XmlGetAttr(message, "from"); MCONTACT hContact = HContactFromJID(jid); - node = node->FirstChildElement("item"); //get node + node = XmlFirstChild(node, "item"); //get node if (!node) { debugLogA("Jabber OMEMO: error: omemo devicelist does not have node"); return; @@ -1972,10 +1972,10 @@ void CJabberProto::OmemoOnIqResultGetBundle(const TiXmlElement *iqNode, CJabberI if (iqNode == nullptr) return; - const char *jid = iqNode->Attribute("from"); + const char *jid = XmlGetAttr(iqNode, "from"); MCONTACT hContact = HContactFromJID(jid); - const char *type = iqNode->Attribute("type"); + const char *type = XmlGetAttr(iqNode, "type"); if (mir_strcmp(type, "result")) { // failed to get bundle, do not try to build session unsigned int *dev_id = (unsigned int*)pInfo->GetUserData(); @@ -2008,44 +2008,44 @@ void CJabberProto::OmemoOnIqResultGetBundle(const TiXmlElement *iqNode, CJabberI return; } - auto *items = pubsub->FirstChildElement("items"); - const char *items_node_val = items->Attribute("node"); + auto *items = XmlFirstChild(pubsub, "items"); + const char *items_node_val = XmlGetAttr(items, "node"); const char *device_id = items_node_val; device_id += mir_wstrlen(JABBER_FEAT_OMEMO L".bundles:"); - auto *bundle = items->FirstChildElement("item")->FirstChildElement("bundle"); + auto *bundle = XmlFirstChild(XmlFirstChild(items, "item"), "bundle"); if (!bundle) { debugLogA("Jabber OMEMO: error: device bundle does not contain bundle node"); return; } - auto *signedPreKeyPublic = bundle->FirstChildElement("signedPreKeyPublic"); + auto *signedPreKeyPublic = XmlFirstChild(bundle, "signedPreKeyPublic"); if (!signedPreKeyPublic) { debugLogA("Jabber OMEMO: error: device bundle does not contain signedPreKeyPublic node"); return; } - const char *signedPreKeyId = signedPreKeyPublic->Attribute("signedPreKeyId"); + const char *signedPreKeyId = XmlGetAttr(signedPreKeyPublic, "signedPreKeyId"); if (!signedPreKeyId) { debugLogA("Jabber OMEMO: error: device bundle does not contain signedPreKeyId attr"); return; } - auto *signedPreKeySignature = bundle->FirstChildElement("signedPreKeySignature"); + auto *signedPreKeySignature = XmlFirstChild(bundle, "signedPreKeySignature"); if (!signedPreKeySignature) { debugLogA("Jabber OMEMO: error: device bundle does not contain signedPreKeySignature node"); return; } - auto *identityKey = bundle->FirstChildElement("identityKey"); + auto *identityKey = XmlFirstChild(bundle, "identityKey"); if (!identityKey) { debugLogA("Jabber OMEMO: error: device bundle does not contain identityKey node"); return; } - auto *prekeys = bundle->FirstChildElement("prekeys"); + auto *prekeys = XmlFirstChild(bundle, "prekeys"); if (!prekeys) { debugLogA("Jabber OMEMO: error: device bundle does not contain prekeys node"); return; } - auto *prekey_node = prekeys->FirstChildElement("preKeyPublic"); + auto *prekey_node = XmlFirstChild(prekeys, "preKeyPublic"); if (!prekey_node) { debugLogA("Jabber OMEMO: error: device bundle does not contain preKeyPublic node"); return; @@ -2057,7 +2057,7 @@ void CJabberProto::OmemoOnIqResultGetBundle(const TiXmlElement *iqNode, CJabberI return; } - const char *preKeyId = prekey_node->Attribute("preKeyId"); + const char *preKeyId = XmlGetAttr(prekey_node, "preKeyId"); if (!preKeyId) { debugLogA("Jabber OMEMO: error: failed to get preKeyId data"); return; diff --git a/protocols/JabberG/src/jabber_opt.cpp b/protocols/JabberG/src/jabber_opt.cpp index 22b869ddc4..61f2491cf0 100755 --- a/protocols/JabberG/src/jabber_opt.cpp +++ b/protocols/JabberG/src/jabber_opt.cpp @@ -688,7 +688,7 @@ private: m_cbServer.ResetContent(); if (node) for (auto *n : TiXmlFilter(node, "item")) - if (const char *jid = n->Attribute("jid")) { + if (const char *jid = XmlGetAttr(n, "jid")) { Utf2T wszJid(jid); if (m_cbServer.FindString(wszJid, -1, true) == CB_ERR) m_cbServer.AddString(wszJid); @@ -992,16 +992,16 @@ void CJabberProto::_RosterHandleGetRequest(const TiXmlElement *node, CJabberIqIn HWND hList = GetDlgItem(rrud.hwndDlg, IDC_ROSTER); if (rrud.bRRAction == RRA_FILLLIST) { _RosterListClear(rrud.hwndDlg); - auto *query = node->FirstChildElement("query"); + auto *query = XmlFirstChild(node, "query"); if (query == nullptr) return; for (auto *item : TiXmlFilter(query, "item")) { - const char *jid = item->Attribute("jid"); + const char *jid = XmlGetAttr(item, "jid"); if (jid == nullptr) continue; - const char *name = item->Attribute("name"); - const char *subscription = item->Attribute("subscription"); + const char *name = XmlGetAttr(item, "name"); + const char *subscription = XmlGetAttr(item, "subscription"); const char *group = XmlGetChildText(item, "group"); _RosterInsertListItem(hList, jid, name, group, subscription, TRUE); } @@ -1036,7 +1036,7 @@ void CJabberProto::_RosterHandleGetRequest(const TiXmlElement *node, CJabberIqIn if (rrud.bRRAction == RRA_SYNCROSTER) { SetDlgItemText(rrud.hwndDlg, IDC_UPLOAD, TranslateT("Uploading...")); - auto *queryRoster = node->FirstChildElement("query"); + auto *queryRoster = XmlFirstChild(node, "query"); if (!queryRoster) return; @@ -1067,11 +1067,11 @@ void CJabberProto::_RosterHandleGetRequest(const TiXmlElement *node, CJabberIqIn else if (!bRemove) { BOOL bPushed = itemRoster ? TRUE : FALSE; if (!bPushed) { - const char *rosterName = itemRoster->Attribute("name"); + const char *rosterName = XmlGetAttr(itemRoster, "name"); if ((rosterName != nullptr || name[0] != 0) && mir_strcmpi(rosterName, szName)) bPushed = TRUE; if (!bPushed) { - rosterName = itemRoster->Attribute("subscription"); + rosterName = XmlGetAttr(itemRoster, "subscription"); if ((rosterName != nullptr || subscr[0] != 0) && mir_strcmpi(rosterName, T2Utf(subscr))) bPushed = TRUE; } @@ -1269,14 +1269,14 @@ void CJabberProto::_RosterImportFromFile(HWND hwndDlg) const char *name = nullptr; const char *group = nullptr; const char *subscr = nullptr; - auto *Cell = Row->FirstChildElement("Cell"); - auto *Data = Cell->FirstChildElement("Data"); + auto *Cell = XmlFirstChild(Row, "Cell"); + auto *Data = XmlFirstChild(Cell, "Data"); if (Data) { if (!mir_strcmpi(Data->GetText(), "+")) bAdd = TRUE; else if (mir_strcmpi(Data->GetText(), "-")) continue; Cell = Cell->NextSiblingElement("Cell"); - if (Cell) Data = Cell->FirstChildElement("Data"); + if (Cell) Data = XmlFirstChild(Cell, "Data"); else Data = nullptr; if (Data) { jid = Data->GetText(); @@ -1284,17 +1284,17 @@ void CJabberProto::_RosterImportFromFile(HWND hwndDlg) } Cell = Cell->NextSiblingElement("Cell"); - if (Cell) Data = Cell->FirstChildElement("Data"); + if (Cell) Data = XmlFirstChild(Cell, "Data"); else Data = nullptr; if (Data) name = Data->GetText(); Cell = Cell->NextSiblingElement("Cell"); - if (Cell) Data = Cell->FirstChildElement("Data"); + if (Cell) Data = XmlFirstChild(Cell, "Data"); else Data = nullptr; if (Data) group = Data->GetText(); Cell = Cell->NextSiblingElement("Cell"); - if (Cell) Data = Cell->FirstChildElement("Data"); + if (Cell) Data = XmlFirstChild(Cell, "Data"); else Data = nullptr; if (Data) subscr = Data->GetText(); } @@ -2124,7 +2124,7 @@ private: m_cbServer.ResetContent(); if (node) for (auto *n : TiXmlFilter(node, "item")) - if (const char *jid = n->Attribute("jid")) { + if (const char *jid = XmlGetAttr(n, "jid")) { Utf2T wszJid(jid); if (m_cbServer.FindString(wszJid, -1, true) == CB_ERR) m_cbServer.AddString(wszJid); diff --git a/protocols/JabberG/src/jabber_privacy.cpp b/protocols/JabberG/src/jabber_privacy.cpp index 589fae2204..5cc56e0e84 100644 --- a/protocols/JabberG/src/jabber_privacy.cpp +++ b/protocols/JabberG/src/jabber_privacy.cpp @@ -73,21 +73,21 @@ void CJabberProto::OnIqResultPrivacyList(const TiXmlElement *iqNode, CJabberIqIn if (iqNode == nullptr) return; - const char *type = iqNode->Attribute("type"); + const char *type = XmlGetAttr(iqNode, "type"); if (type == nullptr) return; if (mir_strcmp(type, "result")) return; - auto *query = iqNode->FirstChildElement("query"); + auto *query = XmlFirstChild(iqNode, "query"); if (query == nullptr) return; - auto *list = query->FirstChildElement("list"); + auto *list = XmlFirstChild(query, "list"); if (list == nullptr) return; - const char *szListName = (char*)list->Attribute("name"); + const char *szListName = (char*)XmlGetAttr(list, "name"); if (!szListName) return; @@ -101,7 +101,7 @@ void CJabberProto::OnIqResultPrivacyList(const TiXmlElement *iqNode, CJabberIqIn } for (auto *item : TiXmlFilter(list, "item")) { - const char *itemType = item->Attribute("type"); + const char *itemType = XmlGetAttr(item, "type"); PrivacyListRuleType nItemType = Else; if (itemType) { if (!mir_strcmpi(itemType, "jid")) @@ -112,25 +112,25 @@ void CJabberProto::OnIqResultPrivacyList(const TiXmlElement *iqNode, CJabberIqIn nItemType = Subscription; } - const char *itemValue = item->Attribute("value"); - const char *itemAction = item->Attribute("action"); + const char *itemValue = XmlGetAttr(item, "value"); + const char *itemAction = XmlGetAttr(item, "action"); BOOL bAllow = TRUE; if (itemAction && !mir_strcmpi(itemAction, "deny")) bAllow = FALSE; - const char *itemOrder = item->Attribute("order"); + const char *itemOrder = XmlGetAttr(item, "order"); DWORD dwOrder = 0; if (itemOrder) dwOrder = atoi(itemOrder); DWORD dwPackets = 0; - if (item->FirstChildElement("message")) + if (XmlFirstChild(item, "message")) dwPackets |= JABBER_PL_RULE_TYPE_MESSAGE; - if (item->FirstChildElement("presence-in")) + if (XmlFirstChild(item, "presence-in")) dwPackets |= JABBER_PL_RULE_TYPE_PRESENCE_IN; - if (item->FirstChildElement("presence-out")) + if (XmlFirstChild(item, "presence-out")) dwPackets |= JABBER_PL_RULE_TYPE_PRESENCE_OUT; - if (item->FirstChildElement("iq")) + if (XmlFirstChild(item, "iq")) dwPackets |= JABBER_PL_RULE_TYPE_IQ; pList->AddRule(nItemType, itemValue, bAllow, dwOrder, dwPackets); } @@ -178,7 +178,7 @@ void CJabberProto::OnIqResultPrivacyListActive(const TiXmlElement *iqNode, CJabb if (iqNode == nullptr) return; - const char *type = iqNode->Attribute("type"); + const char *type = XmlGetAttr(iqNode, "type"); if (type == nullptr) return; @@ -213,7 +213,7 @@ void CJabberProto::OnIqResultPrivacyListDefault(const TiXmlElement *iqNode, CJab if (iqNode == nullptr) return; - const char *type = iqNode->Attribute("type"); + const char *type = XmlGetAttr(iqNode, "type"); if (type == nullptr) return; @@ -246,7 +246,7 @@ void CJabberProto::OnIqResultPrivacyLists(const TiXmlElement *iqNode, CJabberIqI if (pInfo->m_nIqType != JABBER_IQ_TYPE_RESULT) return; - auto *query = iqNode->FirstChildElement("query"); + auto *query = XmlFirstChild(iqNode, "query"); if (query == nullptr) return; @@ -257,7 +257,7 @@ void CJabberProto::OnIqResultPrivacyLists(const TiXmlElement *iqNode, CJabberIqI m_privacyListManager.RemoveAllLists(); for (auto *list : TiXmlFilter(query, "list")) { - const char *listName = list->Attribute("name"); + const char *listName = XmlGetAttr(list, "name"); if (listName) { m_privacyListManager.AddList(listName); @@ -270,15 +270,15 @@ void CJabberProto::OnIqResultPrivacyLists(const TiXmlElement *iqNode, CJabberIqI } const char *szName = nullptr; - auto *node = query->FirstChildElement("active"); + auto *node = XmlFirstChild(query, "active"); if (node) - szName = node->Attribute("name"); + szName = XmlGetAttr(node, "name"); m_privacyListManager.SetActiveListName(szName); szName = nullptr; - node = query->FirstChildElement("default"); + node = XmlFirstChild(query, "default"); if (node) - szName = node->Attribute("name"); + szName = XmlGetAttr(node, "name"); m_privacyListManager.SetDefaultListName(szName); } UI_SAFE_NOTIFY(m_pDlgPrivacyLists, WM_JABBER_REFRESH); diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index 9533b031dc..469a6b8626 100755 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -1002,6 +1002,8 @@ int CJabberProto::SendMsg(MCONTACT hContact, int unused_unknown, const char *psz if (jcb & JABBER_CAPS_CHATSTATES) m << XCHILDNS("active", JABBER_FEAT_CHATSTATES); + m << XATTR("to", szClientJid); + if ( // if message delivery check disabled by entity caps manager (jcb & JABBER_CAPS_MESSAGE_EVENTS_NO_DELIVERY) || @@ -1010,19 +1012,18 @@ int CJabberProto::SendMsg(MCONTACT hContact, int unused_unknown, const char *psz // if message sent to groupchat !mir_strcmp(msgType, "groupchat") || // if message delivery check disabled in settings - !m_bMsgAck || !getByte(hContact, "MsgAck", true)) { - if (!mir_strcmp(msgType, "groupchat")) - XmlAddAttr(m, "to", szClientJid); - else { + !m_bMsgAck || !getByte(hContact, "MsgAck", true)) + { + if (mir_strcmp(msgType, "groupchat")) { id = SerialNext(); - XmlAddAttr(m, "to", szClientJid); XmlAddAttrID(m, id); + XmlAddAttrID(m, id); } m_ThreadInfo->send(m); ForkThread(&CJabberProto::SendMessageAckThread, new TFakeAckParams(hContact, nullptr, id)); } else { - XmlAddAttr(m, "to", szClientJid); XmlAddAttrID(m, id); + XmlAddAttrID(m, id); // message receipts XEP priority if (jcb & JABBER_CAPS_MESSAGE_RECEIPTS) diff --git a/protocols/JabberG/src/jabber_rc.cpp b/protocols/JabberG/src/jabber_rc.cpp index 4d37c97b03..979d7b9a8d 100644 --- a/protocols/JabberG/src/jabber_rc.cpp +++ b/protocols/JabberG/src/jabber_rc.cpp @@ -58,7 +58,7 @@ BOOL CJabberProto::HandleAdhocCommandRequest(const TiXmlElement *iqNode, CJabber return TRUE; } - const char *szNode = pInfo->GetChildNode()->Attribute("node"); + const char *szNode = XmlGetAttr(pInfo->GetChildNode(), "node"); if (!szNode) return TRUE; @@ -154,7 +154,7 @@ BOOL CJabberAdhocManager::HandleCommandRequest(const TiXmlElement *iqNode, CJabb return FALSE; } - const char *szSessionId = commandNode->Attribute("sessionid"); + const char *szSessionId = XmlGetAttr(commandNode, "sessionid"); CJabberAdhocSession *pSession = nullptr; if (szSessionId) { @@ -341,7 +341,7 @@ int CJabberProto::AdhocSetStatusHandler(const TiXmlElement*, CJabberIqInfo *pInf if (!fieldNode) return JABBER_ADHOC_HANDLER_STATUS_CANCEL; - auto *nodeValue = fieldNode->FirstChildElement("value"); + auto *nodeValue = XmlFirstChild(fieldNode, "value"); if (nodeValue == nullptr) return JABBER_ADHOC_HANDLER_STATUS_CANCEL; @@ -367,7 +367,7 @@ int CJabberProto::AdhocSetStatusHandler(const TiXmlElement*, CJabberIqInfo *pInf const char *szStatusMessage = nullptr; if (fieldNode = XmlGetChildByTag(xNode, "field", "var", "status-message")) - if (auto *valueNode = fieldNode->FirstChildElement("value")) + if (auto *valueNode = XmlFirstChild(fieldNode, "value")) szStatusMessage = valueNode->GetText(); // skip f...ng away dialog diff --git a/protocols/JabberG/src/jabber_search.cpp b/protocols/JabberG/src/jabber_search.cpp index 05e19da136..8223ee5682 100644 --- a/protocols/JabberG/src/jabber_search.cpp +++ b/protocols/JabberG/src/jabber_search.cpp @@ -137,19 +137,19 @@ void CJabberProto::OnIqResultGetSearchFields(const TiXmlElement *iqNode, CJabber if (!searchHandleDlg) return; - const char *type = iqNode->Attribute("type"); + const char *type = XmlGetAttr(iqNode, "type"); if (type == nullptr) return; if (!mir_strcmp(type, "result")) { - auto *queryNode = iqNode->FirstChildElement("query"); + auto *queryNode = XmlFirstChild(iqNode, "query"); auto *xNode = XmlGetChildByTag(queryNode, "x", "xmlns", JABBER_FEAT_DATA_FORMS); ShowWindow(searchHandleDlg, SW_HIDE); if (xNode) { // 1. Form PostMessage(searchHandleDlg, WM_USER + 11, (WPARAM)xNode, 0); - auto *xcNode = xNode->FirstChildElement("instructions"); + auto *xcNode = XmlFirstChild(xNode, "instructions"); if (xcNode) SetDlgItemTextUtf(searchHandleDlg, IDC_INSTRUCTIONS, xcNode->GetText()); } @@ -173,7 +173,7 @@ void CJabberProto::OnIqResultGetSearchFields(const TiXmlElement *iqNode, CJabber } } - const char *szFrom = iqNode->Attribute("from"); + const char *szFrom = XmlGetAttr(iqNode, "from"); if (szFrom) SearchAddToRecent(szFrom, searchHandleDlg); PostMessage(searchHandleDlg, WM_USER + 10, 0, 0); @@ -182,9 +182,9 @@ void CJabberProto::OnIqResultGetSearchFields(const TiXmlElement *iqNode, CJabber else if (!mir_strcmp(type, "error")) { const char *code = ""; const char *description = ""; - auto *errorNode = iqNode->FirstChildElement("error"); + auto *errorNode = XmlFirstChild(iqNode, "error"); if (errorNode) { - code = errorNode->Attribute("code"); + code = XmlGetAttr(errorNode, "code"); description = errorNode->GetText(); } @@ -301,20 +301,20 @@ void CJabberProto::OnIqResultAdvancedSearch(const TiXmlElement *iqNode, CJabberI U_TCHAR_MAP mColumnsNames(10); LIST SearchResults(2); - if (((id = JabberGetPacketID(iqNode)) == -1) || ((type = iqNode->Attribute("type")) == nullptr)) { + if (((id = JabberGetPacketID(iqNode)) == -1) || ((type = XmlGetAttr(iqNode, "type")) == nullptr)) { ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)id, 0); return; } if (!mir_strcmp(type, "result")) { - auto *queryNode = iqNode->FirstChildElement("query"); + auto *queryNode = XmlFirstChild(iqNode, "query"); auto *xNode = XmlGetChildByTag(queryNode, "x", "xmlns", JABBER_FEAT_DATA_FORMS); if (xNode) { // 1. Form search results info - for (auto *fieldNode : TiXmlFilter(xNode->FirstChildElement("reported"), "field")) { - const char *var = fieldNode->Attribute("var"); + for (auto *fieldNode : TiXmlFilter(XmlFirstChild(xNode, "reported"), "field")) { + const char *var = XmlGetAttr(fieldNode, "var"); if (var) { - Utf2T wszVar(var), wszLabel(fieldNode->Attribute("label")); + Utf2T wszVar(var), wszLabel(XmlGetAttr(fieldNode, "label")); mColumnsNames.insert(wszVar, (wszLabel != nullptr) ? wszLabel: wszVar); } } @@ -322,8 +322,8 @@ void CJabberProto::OnIqResultAdvancedSearch(const TiXmlElement *iqNode, CJabberI for (auto *itemNode : TiXmlFilter(xNode, "item")) { U_TCHAR_MAP *pUserColumn = new U_TCHAR_MAP(10); for (auto *fieldNode : TiXmlFilter(itemNode, "field")) { - if (const char* var = fieldNode->Attribute("var")) { - if (auto *textNode = fieldNode->FirstChildElement("value")) { + if (const char* var = XmlGetAttr(fieldNode, "var")) { + if (auto *textNode = XmlFirstChild(fieldNode, "value")) { Utf2T wszVar(var), wszText(textNode->GetText()); if (!mColumnsNames[wszVar.get()]) mColumnsNames.insert(wszVar, wszVar); @@ -340,7 +340,7 @@ void CJabberProto::OnIqResultAdvancedSearch(const TiXmlElement *iqNode, CJabberI for (auto *itemNode : TiXmlFilter(queryNode, "item")) { U_TCHAR_MAP *pUserColumn = new U_TCHAR_MAP(10); - Utf2T jid(itemNode->Attribute("jid")); + Utf2T jid(XmlGetAttr(itemNode, "jid")); wchar_t *keyReturned; mColumnsNames.insertCopyKey(L"jid", L"jid", &keyReturned, CopyKey, DestroyKey); mColumnsNames.insert(L"jid", keyReturned); @@ -366,9 +366,9 @@ void CJabberProto::OnIqResultAdvancedSearch(const TiXmlElement *iqNode, CJabberI else if (!mir_strcmp(type, "error")) { const char *code = ""; const char *description = ""; - auto *errorNode = iqNode->FirstChildElement("error"); + auto *errorNode = XmlFirstChild(iqNode, "error"); if (errorNode) { - code = errorNode->Attribute("code"); + code = XmlGetAttr(errorNode, "code"); description = errorNode->GetText(); } @@ -750,7 +750,7 @@ HWND CJabberProto::SearchAdvanced(HWND hwndDlg) wchar_t szFieldValue[100]; GetWindowText(dat->pJSInf[i].hwndValueItem, szFieldValue, _countof(szFieldValue)); if (szFieldValue[0] != 0) { - XmlAddChild(query, T2Utf(dat->pJSInf[i].szFieldName).get(), T2Utf(szFieldValue).get()); + XmlAddChildA(query, T2Utf(dat->pJSInf[i].szFieldName).get(), T2Utf(szFieldValue).get()); fRequestNotEmpty = TRUE; } } diff --git a/protocols/JabberG/src/jabber_strm_mgmt.cpp b/protocols/JabberG/src/jabber_strm_mgmt.cpp index b7682364aa..798f808907 100755 --- a/protocols/JabberG/src/jabber_strm_mgmt.cpp +++ b/protocols/JabberG/src/jabber_strm_mgmt.cpp @@ -31,14 +31,14 @@ strm_mgmt::strm_mgmt(CJabberProto *_proto) : void strm_mgmt::OnProcessEnabled(const TiXmlElement *node, ThreadData * /*info*/) { m_bStrmMgmtEnabled = true; - auto *val = node->Attribute("max"); + auto *val = XmlGetAttr(node, "max"); if (val) m_nStrmMgmtResumeMaxSeconds = atoi(val); - val = node->Attribute("resume"); + val = XmlGetAttr(node, "resume"); if (val) { if (mir_strcmp(val, "true") || mir_strcmp(val, "1")) { m_bStrmMgmtResumeSupported = true; - m_sStrmMgmtResumeId = node->Attribute("id"); + m_sStrmMgmtResumeId = XmlGetAttr(node, "id"); } } //TODO: handle 'location' @@ -48,17 +48,17 @@ void strm_mgmt::OnProcessEnabled(const TiXmlElement *node, ThreadData * /*info*/ void strm_mgmt::OnProcessResumed(const TiXmlElement *node, ThreadData * /*info*/) { - if (mir_strcmp(node->Attribute("xmlns"), "urn:xmpp:sm:3")) + if (mir_strcmp(XmlGetAttr(node, "xmlns"), "urn:xmpp:sm:3")) return; - auto *var = node->Attribute("previd"); + auto *var = XmlGetAttr(node, "previd"); if (!var) return; if (m_sStrmMgmtResumeId != var) return; //TODO: unknown session, what we should do ? - var = node->Attribute("h"); + var = XmlGetAttr(node, "h"); if (!var) return; bSessionResumed = true; @@ -88,7 +88,7 @@ void strm_mgmt::OnProcessResumed(const TiXmlElement *node, ThreadData * /*info*/ void strm_mgmt::OnProcessSMa(const TiXmlElement *node) { - if (mir_strcmp(node->Attribute("xmlns"), "urn:xmpp:sm:3")) + if (mir_strcmp(XmlGetAttr(node, "xmlns"), "urn:xmpp:sm:3")) return; m_nStrmMgmtSrvHCount = node->IntAttribute("h"); @@ -139,13 +139,13 @@ void strm_mgmt::ResendNodes(uint32_t size) void strm_mgmt::OnProcessSMr(const TiXmlElement *node) { - if (!mir_strcmp(node->Attribute("xmlns"), "urn:xmpp:sm:3")) + if (!mir_strcmp(XmlGetAttr(node, "xmlns"), "urn:xmpp:sm:3")) SendAck(); } void strm_mgmt::OnProcessFailed(const TiXmlElement *node, ThreadData * info) //used failed instead of failure, notes: https://xmpp.org/extensions/xep-0198.html#errors { - if (mir_strcmp(node->Attribute("xmlns"), "urn:xmpp:sm:3")) + if (mir_strcmp(XmlGetAttr(node, "xmlns"), "urn:xmpp:sm:3")) return; proto->debugLogA("strm_mgmt: error: Failed to resume session %s", m_sStrmMgmtResumeId.c_str()); @@ -158,7 +158,7 @@ void strm_mgmt::OnProcessFailed(const TiXmlElement *node, ThreadData * info) //u for (auto &hContact : proto->AccContacts()) proto->SetContactOfflineStatus(hContact); - auto *subnode = node->FirstChildElement("item-not-found"); + auto *subnode = XmlFirstChild(node, "item-not-found"); if (subnode) { m_bStrmMgmtPendingEnable = true; FinishLoginProcess(info); @@ -170,7 +170,7 @@ void strm_mgmt::CheckStreamFeatures(const TiXmlElement *node) { if (!IsResumeIdPresent()) ResetState(); //this may be necessary to reset counters if session resume id is not set - if (mir_strcmp(node->Name(), "sm") || !node->Attribute("xmlns") || mir_strcmp(node->Attribute("xmlns"), "urn:xmpp:sm:3")) //we work only with version 3 or higher of sm + if (mir_strcmp(node->Name(), "sm") || !XmlGetAttr(node, "xmlns") || mir_strcmp(XmlGetAttr(node, "xmlns"), "urn:xmpp:sm:3")) //we work only with version 3 or higher of sm return; if (!(proto->m_bJabberOnline)) m_bStrmMgmtPendingEnable = true; diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index fa9ea84c14..be1d8e9671 100755 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -583,7 +583,7 @@ void CJabberProto::OnProcessStreamOpening(const TiXmlElement *node, ThreadData * return; if (!info->bIsReg) { - const char *sid = node->Attribute("id"); + const char *sid = XmlGetAttr(node, "id"); if (sid != nullptr) info->szStreamId = mir_strdup(sid); } @@ -732,7 +732,7 @@ void CJabberProto::OnProcessFeatures(const TiXmlElement *node, ThreadData *info) else if (!mir_strcmp(szMechanism, "GSSAPI")) m_AuthMechs.isKerberosAvailable = true; } else if (!mir_strcmp(c->Name(), "hostname")) { - const char *mech = c->Attribute("mechanism"); + const char *mech = XmlGetAttr(c, "mechanism"); if (mech && mir_strcmpi(mech, "GSSAPI") == 0) m_AuthMechs.m_gssapiHostName = mir_strdup(c->GetText()); } @@ -777,7 +777,7 @@ void CJabberProto::OnProcessFeatures(const TiXmlElement *node, ThreadData *info) void CJabberProto::OnProcessFailure(const TiXmlElement *node, ThreadData *info) { // failure xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" - const char *type = node->Attribute("xmlns"); + const char *type = XmlGetAttr(node, "xmlns"); if (!mir_strcmp(type, "urn:ietf:params:xml:ns:xmpp-sasl")) PerformAuthentication(info); } @@ -790,7 +790,7 @@ void CJabberProto::OnProcessFailed(const TiXmlElement *node, ThreadData *info) / void CJabberProto::OnProcessEnabled(const TiXmlElement *node, ThreadData * info) { - if (m_bEnableStreamMgmt && !mir_strcmp(node->Attribute("xmlns"), "urn:xmpp:sm:3")) + if (m_bEnableStreamMgmt && !mir_strcmp(XmlGetAttr(node, "xmlns"), "urn:xmpp:sm:3")) m_StrmMgmt.OnProcessEnabled(node, info); } @@ -798,7 +798,7 @@ void CJabberProto::OnProcessEnabled(const TiXmlElement *node, ThreadData * info) void CJabberProto::OnProcessError(const TiXmlElement *node, ThreadData *info) { //failure xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" - if (!node->FirstChildElement(0)) + if (!XmlFirstChild(node, 0)) return; bool skipMsg = false; @@ -831,7 +831,7 @@ void CJabberProto::OnProcessSuccess(const TiXmlElement *node, ThreadData *info) // int iqId; // RECVED: Attribute("xmlns")) == nullptr) + if ((type = XmlGetAttr(node, "xmlns")) == nullptr) return; if (!mir_strcmp(type, "urn:ietf:params:xml:ns:xmpp-sasl")) { @@ -857,7 +857,7 @@ void CJabberProto::OnProcessChallenge(const TiXmlElement *node, ThreadData *info return; } - if (mir_strcmp(node->Attribute("xmlns"), "urn:ietf:params:xml:ns:xmpp-sasl")) + if (mir_strcmp(XmlGetAttr(node, "xmlns"), "urn:ietf:params:xml:ns:xmpp-sasl")) return; char* challenge = info->auth->getChallenge(node->GetText()); @@ -914,7 +914,7 @@ void CJabberProto::OnProcessProtocol(const TiXmlElement *node, ThreadData *info) void CJabberProto::OnProcessProceed(const TiXmlElement *node, ThreadData *info) { const char *type; - if ((type = node->Attribute("xmlns")) != nullptr && !mir_strcmp(type, "error")) + if ((type = XmlGetAttr(node, "xmlns")) != nullptr && !mir_strcmp(type, "error")) return; if (!mir_strcmp(type, "urn:ietf:params:xml:ns:xmpp-tls")) { @@ -938,7 +938,7 @@ void CJabberProto::OnProcessCompressed(const TiXmlElement *node, ThreadData *inf { debugLogA("Compression confirmed"); - const char *type = node->Attribute("xmlns"); + const char *type = XmlGetAttr(node, "xmlns"); if (type != nullptr && !mir_strcmp(type, "error")) return; if (mir_strcmp(type, "http://jabber.org/protocol/compress")) @@ -954,7 +954,7 @@ void CJabberProto::OnProcessCompressed(const TiXmlElement *node, ThreadData *inf void CJabberProto::OnProcessPubsubEvent(const TiXmlElement *node) { - const char *from = node->Attribute("from"); + const char *from = XmlGetAttr(node, "from"); if (!from) return; @@ -980,12 +980,12 @@ void CJabberProto::OnProcessPubsubEvent(const TiXmlElement *node) if (m_bEnableUserTune) if (auto *itemsNode = XmlGetChildByTag(eventNode, "items", "node", JABBER_FEAT_USER_TUNE)) { // node retract? - if (itemsNode->FirstChildElement("retract")) { + if (XmlFirstChild(itemsNode, "retract")) { SetContactTune(hContact, nullptr, nullptr, nullptr, nullptr, nullptr); return; } - auto *tuneNode = XmlGetChildByTag(itemsNode->FirstChildElement("item"), "tune", "xmlns", JABBER_FEAT_USER_TUNE); + auto *tuneNode = XmlGetChildByTag(XmlFirstChild(itemsNode, "item"), "tune", "xmlns", JABBER_FEAT_USER_TUNE); if (!tuneNode) return; @@ -1049,11 +1049,11 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) if (!node->Name() || mir_strcmp(node->Name(), "message")) return; - const char *from, *type = node->Attribute("type"); - if ((from = node->Attribute("from")) == nullptr) + const char *from, *type = XmlGetAttr(node, "type"); + if ((from = XmlGetAttr(node, "from")) == nullptr) return; - const char *idStr = node->Attribute("id"); + const char *idStr = XmlGetAttr(node, "id"); pResourceStatus pFromResource(ResourceInfoFromJID(from)); // Message receipts delivery request. Reply here, before a call to HandleMessagePermanent() to make sure message receipts are handled for external plugins too. @@ -1088,22 +1088,22 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) const TiXmlElement *message = nullptr; // Carbons MUST have forwarded/message content if (!(forwarded = XmlGetChildByTag(carbon, "forwarded", "xmlns", JABBER_XMLNS_FORWARD)) - || !(message = forwarded->FirstChildElement("message"))) + || !(message = XmlFirstChild(forwarded, "message"))) return; //Unwrap the carbon in any case node = message; - type = node->Attribute("type"); + type = XmlGetAttr(node, "type"); if (!carbonSent) { // Received should just be treated like incoming messages, except maybe not flash the flasher. Simply unwrap. - from = node->Attribute("from"); + from = XmlGetAttr(node, "from"); if (from == nullptr) return; } else { // Sent should set SENT flag and invert from/to. - from = node->Attribute("to"); + from = XmlGetAttr(node, "to"); if (from == nullptr) return; } @@ -1113,7 +1113,7 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) MCONTACT hContact = HContactFromJID(from); JABBER_LIST_ITEM *chatItem = ListGetItemPtr(LIST_CHATROOM, from); if (chatItem) { - auto *xCaptcha = node->FirstChildElement("captcha"); + auto *xCaptcha = XmlFirstChild(node, "captcha"); if (xCaptcha) if (ProcessCaptcha(xCaptcha, node, info)) return; @@ -1122,7 +1122,7 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) CMStringA szMessage; auto *bodyNode = XmlGetChildByTag(node, "body", "xml:lang", m_tszSelectedLang); if (bodyNode == nullptr) - bodyNode = node->FirstChildElement("body"); + bodyNode = XmlFirstChild(node, "body"); auto *subject = XmlGetChildText(node, "subject"); if (subject) { @@ -1134,7 +1134,7 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) if (szMessage) if (auto *n = XmlGetChildByTag(node, "addresses", "xmlns", JABBER_FEAT_EXT_ADDRESSING)) { auto *addressNode = XmlGetChildByTag(n, "address", "type", "ofrom"); if (addressNode) { - const char *szJid = addressNode->Attribute("jid"); + const char *szJid = XmlGetAttr(addressNode, "jid"); if (szJid) { szMessage.AppendFormat(TranslateU("Message redirected from: %s\r\n"), from); from = szJid; @@ -1212,9 +1212,9 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) } if (auto *n = XmlGetChildByTag(node, "confirm", "xmlns", JABBER_FEAT_HTTP_AUTH)) if (m_bAcceptHttpAuth) { - const char *szId = n->Attribute("id"); - const char *szMethod = n->Attribute("method"); - const char *szUrl = n->Attribute("url"); + const char *szId = XmlGetAttr(n, "id"); + const char *szMethod = XmlGetAttr(n, "method"); + const char *szUrl = XmlGetAttr(n, "url"); if (!szId || !szMethod || !szUrl) return; @@ -1238,7 +1238,7 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) for (auto *xNode : TiXmlEnum(node)) { if (m_bUseOMEMO) { if (!mir_strcmp(xNode->Name(), "encrypted") && xNode->Attribute("xmlns", JABBER_FEAT_OMEMO)) { - const char *jid = xNode->Attribute("from"); + const char *jid = XmlGetAttr(xNode, "from"); if (jid) { if (!OmemoHandleMessage(xNode, jid, msgTime)) OmemoPutMessageToIncommingQueue(xNode, jid, msgTime); @@ -1250,12 +1250,12 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) if (0 != mir_strcmp(xNode->Name(), "x")) continue; - const char *pszXmlns = xNode->Attribute("xmlns"); + const char *pszXmlns = XmlGetAttr(xNode, "xmlns"); if (pszXmlns == nullptr) continue; if (!mir_strcmp(pszXmlns, JABBER_FEAT_MIRANDA_NOTES)) { - if (OnIncomingNote(from, xNode->FirstChildElement("note"))) + if (OnIncomingNote(from, XmlFirstChild(xNode, "note"))) return; } else if (!mir_strcmp(pszXmlns, "jabber:x:encrypted")) { @@ -1278,7 +1278,7 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) szMessage += tempstring; } else if (!mir_strcmp(pszXmlns, JABBER_FEAT_DELAY) && msgTime == 0) { - const char *ptszTimeStamp = xNode->Attribute("stamp"); + const char *ptszTimeStamp = XmlGetAttr(xNode, "stamp"); if (ptszTimeStamp != nullptr) msgTime = JabberIsoToUnixTime(ptszTimeStamp); } @@ -1293,8 +1293,8 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) // pFromResource->m_jcbManualDiscoveredCaps |= (JABBER_CAPS_MESSAGE_EVENTS | JABBER_CAPS_MESSAGE_EVENTS_NO_DELIVERY); if (bodyNode == nullptr) { - auto *idNode = xNode->FirstChildElement("id"); - if (xNode->FirstChildElement("delivered") != nullptr || xNode->FirstChildElement("offline") != nullptr) { + auto *idNode = XmlFirstChild(xNode, "id"); + if (XmlFirstChild(xNode, "delivered") != nullptr || XmlFirstChild(xNode, "offline") != nullptr) { int id = -1; if (idNode != nullptr && idNode->GetText() != nullptr) if (!strncmp(idNode->GetText(), JABBER_IQID, mir_strlen(JABBER_IQID))) @@ -1304,17 +1304,17 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)id, 0); } - if (hContact && xNode->FirstChildElement("composing") != nullptr) + if (hContact && XmlFirstChild(xNode, "composing") != nullptr) CallService(MS_PROTO_CONTACTISTYPING, hContact, 60); // Maybe a cancel to the previous composing - auto *child = xNode->FirstChildElement(0); + auto *child = XmlFirstChild(xNode, 0); if (hContact && (!child || (child && idNode != nullptr))) CallService(MS_PROTO_CONTACTISTYPING, hContact, PROTOTYPE_CONTACTTYPING_OFF); } else { // Check whether any event is requested - if (!isDelivered && xNode->FirstChildElement("delivered")) { + if (!isDelivered && XmlFirstChild(xNode, "delivered")) { isDelivered = true; XmlNode m("message"); m << XATTR("to", from); @@ -1324,7 +1324,7 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) info->send(m); } - if (item != nullptr && xNode->FirstChildElement("composing") != nullptr) { + if (item != nullptr && XmlFirstChild(xNode, "composing") != nullptr) { if (item->messageEventIdStr) mir_free(item->messageEventIdStr); item->messageEventIdStr = (idStr == nullptr) ? nullptr : mir_strdup(idStr); @@ -1340,9 +1340,9 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) } } else if (!mir_strcmp(pszXmlns, JABBER_FEAT_MUC_USER)) { - auto *inviteNode = xNode->FirstChildElement("invite"); + auto *inviteNode = XmlFirstChild(xNode, "invite"); if (inviteNode != nullptr) { - inviteFromJid = inviteNode->Attribute("from"); + inviteFromJid = XmlGetAttr(inviteNode, "from"); inviteReason = XmlGetChildText(inviteNode, "reason"); inviteRoomJid = from; if (inviteReason == nullptr) @@ -1355,9 +1355,9 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) char chkJID[JABBER_MAX_JID_LEN] = "@"; JabberStripJid(from, chkJID + 1, _countof(chkJID) - 1); for (auto *iNode : TiXmlFilter(xNode, "item")) { - const char *action = iNode->Attribute("action"); - const char *jid = iNode->Attribute("jid"); - const char *nick = iNode->Attribute("name"); + const char *action = XmlGetAttr(iNode, "action"); + const char *jid = XmlGetAttr(iNode, "jid"); + const char *nick = XmlGetAttr(iNode, "name"); auto *group = XmlGetChildText(iNode, "group"); if (action && jid && strstr(jid, chkJID)) { if (!mir_strcmp(action, "add")) { @@ -1374,7 +1374,7 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) } } else if (!isChatRoomInvitation && !mir_strcmp(pszXmlns, JABBER_FEAT_DIRECT_MUC_INVITE)) { - inviteRoomJid = xNode->Attribute("jid"); + inviteRoomJid = XmlGetAttr(xNode, "jid"); inviteFromJid = from; if (inviteReason == nullptr) inviteReason = xNode->GetText(); @@ -1454,7 +1454,7 @@ void CJabberProto::OnProcessPresenceCapabilites(const TiXmlElement *node, pResou if (r->m_pCaps != nullptr) return; - const char *from = node->Attribute("from"); + const char *from = XmlGetAttr(node, "from"); if (from == nullptr) return; @@ -1462,13 +1462,13 @@ void CJabberProto::OnProcessPresenceCapabilites(const TiXmlElement *node, pResou if (n == nullptr) return; - const char *szNode = n->Attribute("node"); - const char *szVer = n->Attribute("ver"); - const char *szExt = n->Attribute("ext"); + const char *szNode = XmlGetAttr(n, "node"); + const char *szVer = XmlGetAttr(n, "ver"); + const char *szExt = XmlGetAttr(n, "ext"); if (szNode == nullptr || szVer == nullptr) return; - const char *szHash = n->Attribute("hash"); + const char *szHash = XmlGetAttr(n, "hash"); if (szHash == nullptr) { // old version BYTE hashOut[MIR_SHA1_HASH_SIZE]; mir_sha1_hash((BYTE*)szVer, mir_strlen(szVer), hashOut); @@ -1568,7 +1568,7 @@ void CJabberProto::OnProcessPresence(const TiXmlElement *node, ThreadData *info) if (!node || !node->Name() || mir_strcmp(node->Name(), "presence")) return; - const char *from = node->Attribute("from"); + const char *from = XmlGetAttr(node, "from"); if (from == nullptr) return; @@ -1590,7 +1590,7 @@ void CJabberProto::OnProcessPresence(const TiXmlElement *node, ThreadData *info) if (!mir_strcmpi(szBareFrom, szBareOurJid)) bSelfPresence = true; - const char *type = node->Attribute("type"); + const char *type = XmlGetAttr(node, "type"); if (type == nullptr || !mir_strcmp(type, "available")) { ptrA nick(JabberNickFromJID(from)); if (nick == nullptr) @@ -1637,7 +1637,7 @@ void CJabberProto::OnProcessPresence(const TiXmlElement *node, ThreadData *info) debugLogA("Avatar enabled"); for (auto *xNode : TiXmlFilter(node, "x")) { - if (!bHasAvatar && !mir_strcmp(xNode->Attribute("xmlns"), "jabber:x:avatar")) { + if (!bHasAvatar && !mir_strcmp(XmlGetAttr(xNode, "xmlns"), "jabber:x:avatar")) { auto *szHash = XmlGetChildText(xNode, "hash"); if (szHash != nullptr) { delSetting(hContact, "AvatarXVcard"); @@ -1652,7 +1652,7 @@ void CJabberProto::OnProcessPresence(const TiXmlElement *node, ThreadData *info) } else bRemovedAvatar = true; } - else if (!mir_strcmp(xNode->Attribute("xmlns"), "vcard-temp:x:update")) { + else if (!mir_strcmp(XmlGetAttr(xNode, "xmlns"), "vcard-temp:x:update")) { auto *szPhoto = XmlGetChildText(xNode, "photo"); if (szPhoto && !bHasAvatar) { if (mir_strlen(szPhoto)) { @@ -1669,7 +1669,7 @@ void CJabberProto::OnProcessPresence(const TiXmlElement *node, ThreadData *info) else bRemovedAvatar = true; } - const char *txt = xNode->Attribute("vcard"); + const char *txt = XmlGetAttr(xNode, "vcard"); if (mir_strlen(txt)) { ptrA saved(getStringA(hContact, "VCardHash")); if (saved == nullptr || mir_strcmp(saved, txt)) { @@ -1799,11 +1799,11 @@ BOOL CJabberProto::OnProcessJingle(const TiXmlElement *node) auto *child = XmlGetChildByTag(node, "jingle", "xmlns", JABBER_FEAT_JINGLE); if (child) { - if ((type = node->Attribute("type")) == nullptr) return FALSE; + if ((type = XmlGetAttr(node, "type")) == nullptr) return FALSE; if ((!mir_strcmp(type, "get") || !mir_strcmp(type, "set"))) { - const char *szAction = child->Attribute("action"); - const char *idStr = node->Attribute("id"); - const char *from = node->Attribute("from"); + const char *szAction = XmlGetAttr(child, "action"); + const char *idStr = XmlGetAttr(node, "id"); + const char *from = XmlGetAttr(node, "from"); if (szAction && !mir_strcmp(szAction, "session-initiate")) { // if this is a Jingle 'session-initiate' and noone processed it yet, reply with "unsupported-applications" m_ThreadInfo->send(XmlNodeIq("result", idStr, from)); @@ -1812,10 +1812,10 @@ BOOL CJabberProto::OnProcessJingle(const TiXmlElement *node) TiXmlElement *jingleNode = iq << XCHILDNS("jingle", JABBER_FEAT_JINGLE); jingleNode << XATTR("action", "session-terminate"); - const char *szInitiator = child->Attribute("initiator"); + const char *szInitiator = XmlGetAttr(child, "initiator"); if (szInitiator) jingleNode << XATTR("initiator", szInitiator); - const char *szSid = child->Attribute("sid"); + const char *szSid = XmlGetAttr(child, "sid"); if (szSid) jingleNode << XATTR("sid", szSid); @@ -1844,7 +1844,7 @@ void CJabberProto::OnProcessIq(const TiXmlElement *node) if (!node->Name() || mir_strcmp(node->Name(), "iq")) return; const char *type; - if ((type = node->Attribute("type")) == nullptr) return; + if ((type = XmlGetAttr(node, "type")) == nullptr) return; int id = JabberGetPacketID(node); @@ -1879,9 +1879,9 @@ void CJabberProto::OnProcessIq(const TiXmlElement *node) } } else if ((!mir_strcmp(type, "get") || !mir_strcmp(type, "set"))) { - XmlNodeIq iq("error", node->Attribute("id"), node->Attribute("from")); + XmlNodeIq iq("error", XmlGetAttr(node, "id"), XmlGetAttr(node, "from")); - auto *pFirstChild = node->FirstChildElement(); + auto *pFirstChild = XmlFirstChild(node); if (pFirstChild) iq.InsertEndChild((TiXmlElement*)pFirstChild); @@ -1915,23 +1915,23 @@ void CJabberProto::SetRegConfig(CJabberFormDlg *pDlg, void *from) void CJabberProto::OnProcessRegIq(const TiXmlElement *node, ThreadData *info) { if (!node->Name() || mir_strcmp(node->Name(), "iq")) return; - const char *type = node->Attribute("type"); + const char *type = XmlGetAttr(node, "type"); if (type == nullptr) return; int id = JabberGetPacketID(node); if (!mir_strcmp(type, "result")) { - auto *queryNode = node->FirstChildElement("query"); + auto *queryNode = XmlFirstChild(node, "query"); if (queryNode != nullptr) { - const char *str = queryNode->Attribute("xmlns"); + const char *str = XmlGetAttr(queryNode, "xmlns"); if (!mir_strcmp(str, JABBER_FEAT_REGISTER)) { - auto *xNode = queryNode->FirstChildElement("x"); + auto *xNode = XmlFirstChild(queryNode, "x"); if (xNode != nullptr) { - if (!mir_strcmp(xNode->Attribute("xmlns"), JABBER_FEAT_DATA_FORMS)) { + if (!mir_strcmp(XmlGetAttr(xNode, "xmlns"), JABBER_FEAT_DATA_FORMS)) { g_pRegInfo = info; - auto *pDlg = new CJabberFormDlg(this, xNode, "Jabber register new user", &CJabberProto::SetRegConfig, mir_strdup(node->Attribute("from"))); + auto *pDlg = new CJabberFormDlg(this, xNode, "Jabber register new user", &CJabberProto::SetRegConfig, mir_strdup(XmlGetAttr(node, "from"))); pDlg->SetParent(info->conn.reg_hwndDlg); pDlg->SetCancel(&CJabberProto::CancelRegConfig); pDlg->Display(); diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp index 7ae125f069..30f4137d68 100755 --- a/protocols/JabberG/src/jabber_util.cpp +++ b/protocols/JabberG/src/jabber_util.cpp @@ -254,7 +254,7 @@ CMStringW JabberErrorMsg(const TiXmlElement *errorNode, int *pErrorCode) return ret; } - if (auto *pChild = errorNode->FirstChildElement("error")) + if (auto *pChild = XmlFirstChild(errorNode, "error")) errorNode = pChild; int errorCode = errorNode->IntAttribute("code"); @@ -265,7 +265,7 @@ CMStringW JabberErrorMsg(const TiXmlElement *errorNode, int *pErrorCode) if (str == nullptr) { for (auto *c : TiXmlEnum(errorNode)) { - const char *attr = c->Attribute("xmlns"); + const char *attr = XmlGetAttr(c, "xmlns"); if (attr && !mir_strcmp(attr, "urn:ietf:params:xml:ns:xmpp-stanzas")) { str = c->Name(); break; @@ -508,7 +508,7 @@ void CJabberProto::SendPresence(int status, bool bSendToAll) int JabberGetPacketID(const TiXmlElement *n) { - const char *str = n->Attribute("id"); + const char *str = XmlGetAttr(n, "id"); if (str) if (!strncmp(str, JABBER_IQID, _countof(JABBER_IQID) - 1)) return atoi(str + _countof(JABBER_IQID) - 1); @@ -833,7 +833,7 @@ bool JabberReadXep203delay(const TiXmlElement *node, time_t &msgTime) if (n == nullptr) return false; - const char *ptszTimeStamp = n->Attribute("stamp"); + const char *ptszTimeStamp = XmlGetAttr(n, "stamp"); if (ptszTimeStamp == nullptr) return false; diff --git a/protocols/JabberG/src/jabber_xml.cpp b/protocols/JabberG/src/jabber_xml.cpp index f2336123c7..6fa1c31610 100644 --- a/protocols/JabberG/src/jabber_xml.cpp +++ b/protocols/JabberG/src/jabber_xml.cpp @@ -34,28 +34,36 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. XmlNodeIq::XmlNodeIq(const char *type, int id, const char *to) : XmlNode("iq") { - if (type != nullptr) XmlAddAttr(*this, "type", type); - if (to != nullptr) XmlAddAttr(*this, "to", to); - if (id != -1 ) XmlAddAttrID(*this, id); + if (type != nullptr) + m_hXml->SetAttribute("type", type); + if (to != nullptr) + m_hXml->SetAttribute("to", to); + if (id != -1) + XmlAddAttrID(*this, id); } XmlNodeIq::XmlNodeIq(const char *type, const char *idStr, const char *to) : XmlNode("iq") { - if (type != nullptr) XmlAddAttr(*this, "type", type ); - if (to != nullptr) XmlAddAttr(*this, "to", to ); - if (idStr != nullptr) XmlAddAttr(*this, "id", idStr); + if (type != nullptr) + m_hXml->SetAttribute("type", type); + if (to != nullptr) + m_hXml->SetAttribute("to", to); + if (idStr != nullptr) + m_hXml->SetAttribute("id", idStr); } XmlNodeIq::XmlNodeIq(const char *type, TiXmlElement *node, const char *to) : XmlNode("iq") { - if (type != nullptr) XmlAddAttr(*this, "type", type ); - if (to != nullptr) XmlAddAttr(*this, "to", to ); - if (node != nullptr) { - const char *iqId = node->Attribute("id"); + if (type != nullptr) + m_hXml->SetAttribute("type", type); + if (to != nullptr) + m_hXml->SetAttribute("to", to); + if (node != nullptr) { + const char *iqId = XmlGetAttr(node, "id"); if (iqId != nullptr) - XmlAddAttr(*this, "id", iqId); + m_hXml->SetAttribute("id", iqId); } } @@ -63,19 +71,26 @@ XmlNodeIq::XmlNodeIq(CJabberIqInfo *pInfo) : XmlNode("iq") { if (pInfo) { - if (pInfo->GetCharIqType() != nullptr) XmlAddAttr(*this, "type", pInfo->GetCharIqType()); - if (pInfo->GetReceiver() != nullptr) XmlAddAttr(*this, "to", pInfo->GetReceiver()); - if (pInfo->GetIqId() != -1) XmlAddAttrID(*this, pInfo->GetIqId()); + if (pInfo->GetCharIqType() != nullptr) + m_hXml->SetAttribute("type", pInfo->GetCharIqType()); + if (pInfo->GetReceiver() != nullptr) + m_hXml->SetAttribute("to", pInfo->GetReceiver()); + if (pInfo->GetIqId() != -1) + XmlAddAttrID(*this, pInfo->GetIqId()); } } XmlNodeIq::XmlNodeIq(const char *type, CJabberIqInfo *pInfo) : XmlNode("iq") { - if (type != nullptr) XmlAddAttr(*this, "type", type); + if (type != nullptr) + m_hXml->SetAttribute("type", type); + if (pInfo) { - if (pInfo->GetFrom() != nullptr) XmlAddAttr(*this, "to", pInfo->GetFrom()); - if (pInfo->GetIdStr() != nullptr) XmlAddAttr(*this, "id", pInfo->GetIdStr()); + if (pInfo->GetFrom() != nullptr) + m_hXml->SetAttribute("to", pInfo->GetFrom()); + if (pInfo->GetIdStr() != nullptr) + m_hXml->SetAttribute("id", pInfo->GetIdStr()); } } @@ -112,12 +127,6 @@ TiXmlElement* __fastcall operator<<(TiXmlElement *node, const XQUERY &child) ///////////////////////////////////////////////////////////////////////////////////////// -void XmlAddAttr(TiXmlElement *hXml, const char *name, const char *value) -{ - if (value) - hXml->SetAttribute(name, value); -} - void XmlAddAttrID(TiXmlElement *hXml, int id) { char text[100]; @@ -125,77 +134,3 @@ void XmlAddAttrID(TiXmlElement *hXml, int id) hXml->SetAttribute("id", text); } -///////////////////////////////////////////////////////////////////////////////////////// - -TiXmlElement* XmlAddChild(TiXmlElement *hXml, const char *name) -{ - if (hXml == nullptr) - return nullptr; - - auto *res = hXml->GetDocument()->NewElement(name); - hXml->InsertEndChild(res); - return res; -} - -TiXmlElement* XmlAddChild(TiXmlElement *hXml, const char *name, const char *value) -{ - if (hXml == nullptr) - return nullptr; - - auto *res = hXml->GetDocument()->NewElement(name); - if (value) - res->SetText(value); - hXml->InsertEndChild(res); - return res; -} - -TiXmlElement* XmlAddChild(TiXmlElement *hXml, const char *name, int value) -{ - if (hXml == nullptr) - return nullptr; - - auto *res = hXml->GetDocument()->NewElement(name); - if (value) - res->SetText(value); - hXml->InsertEndChild(res); - return res; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -const char* XmlGetChildText(const TiXmlElement *hXml, const char *key) -{ - if (hXml == nullptr) - return nullptr; - - auto *pChild = hXml->FirstChildElement(key); - return (pChild == nullptr) ? nullptr : pChild->GetText(); -} - -int XmlGetChildInt(const TiXmlElement *hXml, const char *key) -{ - if (hXml == nullptr) - return 0; - - auto *pChild = hXml->FirstChildElement(key); - return (pChild == nullptr) ? 0 : atoi(pChild->GetText()); -} - -const TiXmlElement* XmlGetChildByTag(const TiXmlElement *hXml, const char *key, const char *attrName, const char *attrValue) -{ - for (auto *pChild : TiXmlFilter(hXml, key)) - if (pChild->Attribute(attrName, attrValue)) - return pChild; - - return nullptr; -} - -int XmlGetChildCount(const TiXmlElement *hXml) -{ - int iCount = 0; - for (auto *it : TiXmlEnum(hXml)) { - UNREFERENCED_PARAMETER(it); - iCount++; - } - return iCount; -} diff --git a/protocols/JabberG/src/jabber_xml.h b/protocols/JabberG/src/jabber_xml.h index 098e8ae346..32fb0136c5 100644 --- a/protocols/JabberG/src/jabber_xml.h +++ b/protocols/JabberG/src/jabber_xml.h @@ -26,21 +26,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef _JABBER_XML_H_ #define _JABBER_XML_H_ -int XmlGetChildCount(const TiXmlElement*); - -TiXmlElement* XmlAddChild(TiXmlElement*, const char *pszName); -TiXmlElement* XmlAddChild(TiXmlElement*, const char *pszName, const char *ptszValue); -TiXmlElement* XmlAddChild(TiXmlElement*, const char *pszName, int iValue); - -int XmlGetChildInt(const TiXmlElement *hXml, const char *key); -const char* XmlGetChildText(const TiXmlElement *hXml, const char *key); -const TiXmlElement* XmlGetChildByTag(const TiXmlElement *hXml, const char *key, const char *attrName, const char *attrValue); - -void XmlAddAttr(TiXmlElement*, const char *pszName, const char *ptszValue); void XmlAddAttrID(TiXmlElement*, int id); - class XmlNode : public TiXmlDocument, private MNonCopyable { +protected: TiXmlElement *m_hXml; public: @@ -140,7 +129,7 @@ struct XATTRID __forceinline TiXmlElement *operator<<(TiXmlElement *node, const XATTRID& attr) { - XmlAddAttrID(node, attr.id); + node->SetAttribute("id", attr.id); return node; } @@ -158,7 +147,7 @@ struct XCHILD __forceinline TiXmlElement *operator<<(TiXmlElement *node, const XCHILD &child) { - return XmlAddChild(node, child.name, child.value); + return XmlAddChildA(node, child.name, child.value); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/JabberG/src/jabber_xstatus.cpp b/protocols/JabberG/src/jabber_xstatus.cpp index 7909374f13..6f2b8a80fe 100644 --- a/protocols/JabberG/src/jabber_xstatus.cpp +++ b/protocols/JabberG/src/jabber_xstatus.cpp @@ -623,14 +623,14 @@ void CPepMood::ProcessItems(const char *from, const TiXmlElement *itemsNode) } else hSelfContact = m_proto->HContactFromJID(from); - if (itemsNode->FirstChildElement("retract")) { + if (XmlFirstChild(itemsNode, "retract")) { if (hSelfContact) SetMood(hSelfContact, nullptr, nullptr); SetMood(hContact, nullptr, nullptr); return; } - auto *moodNode = XmlGetChildByTag(itemsNode->FirstChildElement("item"), "mood", "xmlns", JABBER_FEAT_USER_MOOD); + auto *moodNode = XmlGetChildByTag(XmlFirstChild(itemsNode, "item"), "mood", "xmlns", JABBER_FEAT_USER_MOOD); if (!moodNode) return; @@ -992,14 +992,14 @@ void CPepActivity::ProcessItems(const char *from, const TiXmlElement *itemsNode) } else hSelfContact = m_proto->HContactFromJID(from); - if (itemsNode->FirstChildElement("retract")) { + if (XmlFirstChild(itemsNode, "retract")) { if (hSelfContact) SetActivity(hSelfContact, nullptr, nullptr, nullptr); SetActivity(hContact, nullptr, nullptr, nullptr); return; } - auto *actNode = XmlGetChildByTag(itemsNode->FirstChildElement("item"), "activity", "xmlns", JABBER_FEAT_USER_ACTIVITY); + auto *actNode = XmlGetChildByTag(XmlFirstChild(itemsNode, "item"), "activity", "xmlns", JABBER_FEAT_USER_ACTIVITY); if (!actNode) return; @@ -1009,7 +1009,7 @@ void CPepActivity::ProcessItems(const char *from, const TiXmlElement *itemsNode) for (auto *n : TiXmlFilter(actNode, "text")) { if (mir_strcmp(n->Name(), "text")) { szFirstNode = n->Name(); - auto *secondNode = n->FirstChildElement(); + auto *secondNode = XmlFirstChild(n); if (szFirstNode && secondNode && secondNode->Name()) szSecondNode = secondNode->Name(); break; diff --git a/protocols/JabberG/src/stdafx.h b/protocols/JabberG/src/stdafx.h index 40b4963de4..71cf8f6314 100755 --- a/protocols/JabberG/src/stdafx.h +++ b/protocols/JabberG/src/stdafx.h @@ -653,9 +653,9 @@ struct TJabberFormLayoutInfo bool m_bCompact; }; -void JabberFormCreateUI(HWND hwndStatic, TiXmlElement *xNode, int *formHeight, BOOL bCompact = FALSE); +void JabberFormCreateUI(HWND hwndStatic, const TiXmlElement *xNode, int *formHeight, BOOL bCompact = FALSE); void JabberFormDestroyUI(HWND hwndStatic); -void JabberFormGetData(HWND hwndStatic, TiXmlElement* pRoot, TiXmlElement *xNode); +void JabberFormGetData(HWND hwndStatic, TiXmlElement* pRoot, const TiXmlElement *xNode); void JabberFormSetInstruction(HWND hwndForm, const char *text); class CJabberFormDlg : public CJabberDlgBase -- cgit v1.2.3