summaryrefslogtreecommitdiff
path: root/protocols/JabberG/src/jabber_caps.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-02-25 15:16:23 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-02-25 15:16:23 +0300
commit899e841aea8e54721ce9771780b05a07de05ce71 (patch)
treea8d87fb94ccb1534a41fbb711053b5e70bdec420 /protocols/JabberG/src/jabber_caps.cpp
parent94cf6af342027cfaf486eefaad9f6f1450ecb8f0 (diff)
Jabber:
- obsolete class Xpath removed, its functionality replaced with helpers & iterators; - JABBER_FEAT_BIND added to enchance code reading & understanding; - unused function CNoteItem::AddNote removed; - fix for improper jabber:x:last behavior
Diffstat (limited to 'protocols/JabberG/src/jabber_caps.cpp')
-rwxr-xr-xprotocols/JabberG/src/jabber_caps.cpp41
1 files changed, 23 insertions, 18 deletions
diff --git a/protocols/JabberG/src/jabber_caps.cpp b/protocols/JabberG/src/jabber_caps.cpp
index 305cf845eb..94e949cbbf 100755
--- a/protocols/JabberG/src/jabber_caps.cpp
+++ b/protocols/JabberG/src/jabber_caps.cpp
@@ -161,25 +161,30 @@ void CJabberProto::OnIqResultCapsDiscoInfo(const TiXmlElement*, CJabberIqInfo *p
}
for (auto *xform : TiXmlFilter(query, "x")) {
- const char *szFormTypeValue = XPath(xform, "field[@var='FORM_TYPE']/value");
- if (!mir_strcmp(szFormTypeValue, "urn:xmpp:dataforms:softwareinfo")) {
- JSONNode root;
- if (pCaps->m_szOs = mir_strdup(XPath(xform, "field[@var='os']/value")))
- root.push_back(JSONNode("o", pCaps->m_szOs.get()));
- if (pCaps->m_szOsVer = mir_strdup(XPath(xform, "field[@var='os_version']/value")))
- root.push_back(JSONNode("ov", pCaps->m_szOsVer.get()));
- if (pCaps->m_szSoft = mir_strdup(XPath(xform, "field[@var='software']/value")))
- root.push_back(JSONNode("s", pCaps->m_szSoft.get()));
- if (pCaps->m_szSoftVer = mir_strdup(XPath(xform, "field[@var='software_version']/value")))
- root.push_back(JSONNode("sv", pCaps->m_szSoftVer.get()));
- if (pCaps->m_szSoftMir = mir_strdup(XPath(xform, "field[@var='x-miranda-core-version']/value")))
- root.push_back(JSONNode("sm", pCaps->m_szSoftMir.get()));
- root.push_back(JSONNode("c", CMStringA(FORMAT, "%lld", jcbCaps)));
-
- CMStringA szName(FORMAT, "%s#%s", pCaps->GetNode(), pCaps->GetHash());
- json_string szValue = root.write();
- db_set_s(0, "JabberCaps", szName, szValue.c_str());
+ // check that this is a form of required type
+ auto *formType = XmlGetChildText(XmlGetChildByTag(xform, "field", "var", "FORM_TYPE"), "value");
+ if (!formType || mir_strcmp(formType, "urn:xmpp:dataforms:softwareinfo"))
+ continue;
+
+ JSONNode root;
+ for (auto *field : TiXmlFilter(xform, "field")) {
+ const char *fieldName = field->Attribute("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"))
+ root.push_back(JSONNode("ov", pCaps->m_szOsVer = mir_strdup(fieldValue)));
+ else if (!mir_strcmp(fieldName, "software"))
+ root.push_back(JSONNode("s", pCaps->m_szSoft = mir_strdup(fieldValue)));
+ else if (!mir_strcmp(fieldName, "software_version"))
+ root.push_back(JSONNode("sv", pCaps->m_szSoftVer = mir_strdup(fieldValue)));
+ else if (!mir_strcmp(fieldName, "x-miranda-core-version"))
+ root.push_back(JSONNode("sm", pCaps->m_szSoftMir = mir_strdup(fieldValue)));
}
+ root.push_back(JSONNode("c", CMStringA(FORMAT, "%lld", jcbCaps)));
+
+ CMStringA szName(FORMAT, "%s#%s", pCaps->GetNode(), pCaps->GetHash());
+ json_string szValue = root.write();
+ db_set_s(0, "JabberCaps", szName, szValue.c_str());
}
pCaps->SetCaps(jcbCaps, pInfo->GetIqId());