summaryrefslogtreecommitdiff
path: root/protocols/JabberG
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-03-03 19:33:22 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-03-03 19:33:22 +0300
commit1ced735747fa3c0b4e46c94adcb354a0decff929 (patch)
treeb471750fd8c9755f329b6712be05675b79e05173 /protocols/JabberG
parent5ce5965da1db4cfd5e39a89b0dd922e2fe6cf59e (diff)
Jabber: code cleaning
Diffstat (limited to 'protocols/JabberG')
-rwxr-xr-xprotocols/JabberG/src/jabber.cpp4
-rwxr-xr-xprotocols/JabberG/src/jabber_caps.cpp44
-rwxr-xr-xprotocols/JabberG/src/jabber_caps.h11
3 files changed, 29 insertions, 30 deletions
diff --git a/protocols/JabberG/src/jabber.cpp b/protocols/JabberG/src/jabber.cpp
index e6066538d6..6dae866193 100755
--- a/protocols/JabberG/src/jabber.cpp
+++ b/protocols/JabberG/src/jabber.cpp
@@ -178,9 +178,9 @@ int CMPlugin::Load()
HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
JabberUserInfoInit();
- if (!db_get_b(0, "Compatibility", "JabberCaps", 0)) {
+ if (db_get_b(0, "Compatibility", "JabberCaps", 0) < 2) {
db_delete_module(0, "JabberCaps");
- db_set_b(0, "Compatibility", "JabberCaps", 1);
+ db_set_b(0, "Compatibility", "JabberCaps", 2);
}
g_clientCapsManager.Load();
diff --git a/protocols/JabberG/src/jabber_caps.cpp b/protocols/JabberG/src/jabber_caps.cpp
index d696b687d5..a9ab470973 100755
--- a/protocols/JabberG/src/jabber_caps.cpp
+++ b/protocols/JabberG/src/jabber_caps.cpp
@@ -117,10 +117,10 @@ void CJabberProto::AddDefaultCaps()
OS_GetDisplayString(szOsBuffer, _countof(szOsBuffer));
CJabberClientPartialCaps *pCaps = g_clientCapsManager.SetClientCaps(JABBER_CAPS_MIRANDA_NODE, m_szFeaturesCrc, __VERSION_STRING_DOTS, myCaps);
- pCaps->m_szOs = mir_strdup("Microsoft Windows");
- pCaps->m_szOsVer = mir_strdup(szOsBuffer);
- pCaps->m_szSoft = mir_strdup("Miranda NG Jabber Protocol");
- pCaps->m_szSoftMir = mir_strdup(szCoreVersion);
+ pCaps->SetOs("Microsoft Windows");
+ pCaps->SetOsVer(szOsBuffer);
+ pCaps->SetSoft("Miranda NG Jabber Protocol");
+ pCaps->SetSoftMir(szCoreVersion);
}
void CJabberProto::OnIqResultCapsDiscoInfo(const TiXmlElement*, CJabberIqInfo *pInfo)
@@ -166,28 +166,22 @@ void CJabberProto::OnIqResultCapsDiscoInfo(const TiXmlElement*, CJabberIqInfo *p
if (!formType || mir_strcmp(formType, "urn:xmpp:dataforms:softwareinfo"))
continue;
- JSONNode root;
for (auto *field : TiXmlFilter(xform, "field")) {
const char *fieldName = XmlGetAttr(field, "var"), *fieldValue = XmlGetChildText(field, "value");
if (fieldValue == nullptr)
continue;
if (!mir_strcmp(fieldName, "os"))
- root.push_back(JSONNode("o", pCaps->m_szOs = mir_strdup(fieldValue)));
+ pCaps->SetOs(fieldValue);
else if (!mir_strcmp(fieldName, "os_version"))
- root.push_back(JSONNode("ov", pCaps->m_szOsVer = mir_strdup(fieldValue)));
+ pCaps->SetOsVer(fieldValue);
else if (!mir_strcmp(fieldName, "software"))
- root.push_back(JSONNode("s", pCaps->m_szSoft = mir_strdup(fieldValue)));
+ pCaps->SetSoft(fieldValue);
else if (!mir_strcmp(fieldName, "software_version"))
- root.push_back(JSONNode("sv", pCaps->m_szSoftVer = mir_strdup(fieldValue)));
+ pCaps->SetSoftVer(fieldValue);
else if (!mir_strcmp(fieldName, "x-miranda-core-version"))
- root.push_back(JSONNode("sm", pCaps->m_szSoftMir = mir_strdup(fieldValue)));
+ pCaps->SetSoftMir(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());
@@ -624,9 +618,9 @@ CJabberClientPartialCaps* CJabberClientCapsManager::SetClientCaps(const char *sz
/////////////////////////////////////////////////////////////////////////////////////////
-static char *str2buf(const std::string str)
+static const char *str2buf(const std::string str)
{
- return (str.empty()) ? nullptr : mir_strdup(str.c_str());
+ return (str.empty()) ? nullptr : str.c_str();
}
void CJabberClientCapsManager::Load()
@@ -662,12 +656,12 @@ void CJabberClientCapsManager::Load()
JabberCapsBits jcbCaps = _atoi64(ver["caps"].as_string().c_str());
auto *res = pClient->SetPartialCaps(szHash.c_str(), szVer.c_str(), jcbCaps);
- res->m_iTime = ver["time"].as_int();
- res->m_szOs = str2buf(ver["os"].as_string());
- res->m_szOsVer = str2buf(ver["osver"].as_string());
- res->m_szSoft = str2buf(ver["soft"].as_string());
- res->m_szSoftVer = str2buf(ver["softver"].as_string());
- res->m_szSoftMir = str2buf(ver["softmir"].as_string());
+ res->SetTime(ver["time"].as_int());
+ res->SetOs(str2buf(ver["os"].as_string()));
+ res->SetOsVer(str2buf(ver["osver"].as_string()));
+ res->SetSoft(str2buf(ver["soft"].as_string()));
+ res->SetSoftVer(str2buf(ver["softver"].as_string()));
+ res->SetSoftMir(str2buf(ver["softmir"].as_string()));
}
}
}
@@ -680,11 +674,11 @@ void CJabberClientCapsManager::Save()
for (auto &it : m_arCaps) {
JSONNode versions(JSON_ARRAY); versions.set_name("versions");
for (auto *p = it->GetFirst(); p != nullptr; p = p->GetNext()) {
- if (p->m_iTime < iFilterTime)
+ if (p->GetTime() < iFilterTime)
continue;
JSONNode ver;
- ver << CHAR_PARAM("hash", p->GetHash()) << INT64_PARAM("caps", p->GetCaps()) << INT_PARAM("time", p->m_iTime)
+ ver << CHAR_PARAM("hash", p->GetHash()) << INT64_PARAM("caps", p->GetCaps()) << INT_PARAM("time", p->GetTime())
<< CHAR_PARAM("os", p->GetOs()) << CHAR_PARAM("osver", p->GetOsVer())
<< CHAR_PARAM("soft", p->GetSoft()) << CHAR_PARAM("softver", p->GetSoftVer()) << CHAR_PARAM("softmir", p->GetSoftMir());
versions.push_back(ver);
diff --git a/protocols/JabberG/src/jabber_caps.h b/protocols/JabberG/src/jabber_caps.h
index b78f64ebb9..8da657548c 100755
--- a/protocols/JabberG/src/jabber_caps.h
+++ b/protocols/JabberG/src/jabber_caps.h
@@ -260,9 +260,6 @@ typedef unsigned __int64 JabberCapsBits;
class CJabberClientPartialCaps
{
- friend struct CJabberProto;
- friend class CJabberClientCapsManager;
-
ptrA m_szHash, m_szOs, m_szOsVer, m_szSoft, m_szSoftVer, m_szSoftMir;
JabberCapsBits m_jcbCaps = JABBER_RESOURCE_CAPS_UNINIT;
int m_nIqId = -1, m_iTime;
@@ -283,6 +280,7 @@ public:
void SetCaps(JabberCapsBits jcbCaps, int nIqId = -1);
JabberCapsBits GetCaps();
+ __inline int GetTime() const { return m_iTime; }
__inline const char* GetHash() const { return m_szHash.get(); }
__inline const char* GetNode() const;
@@ -292,6 +290,13 @@ public:
__inline const char* GetSoftVer() const { return m_szSoftVer.get(); }
__inline const char* GetSoftMir() const { return m_szSoftMir.get(); }
+ __inline void SetTime(int val) { m_iTime = val; }
+ __inline void SetOs(const char *str) { m_szOs = mir_strdup(str); }
+ __inline void SetOsVer(const char *str) { m_szOsVer = mir_strdup(str); }
+ __inline void SetSoft(const char *str) { m_szSoft = mir_strdup(str); }
+ __inline void SetSoftVer(const char *str) { m_szSoftVer = mir_strdup(str); }
+ __inline void SetSoftMir(const char *str) { m_szSoftMir = mir_strdup(str); }
+
__inline int GetIqId() const { return m_nIqId; }
__inline void SetVer(const char *szVer)