diff options
author | George Hazan <ghazan@miranda.im> | 2019-02-19 15:21:04 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-02-19 19:24:17 +0300 |
commit | fc8f2a3b692878aa581bf3fcd5c1c3c2295bbcb5 (patch) | |
tree | 17ed9d45de9d7f293578150081b5e7e4617290eb /protocols | |
parent | c9e483e0fb1566d210530339d13a0e6e91260200 (diff) |
Jabber:
- XmlGetChildText / XmlGetChildInt - new handy helpers for tinyxml2;
- Unicode logging replaced with ANSI when appropriate;
- JabberErrorMsg rewritten to be more useful
Diffstat (limited to 'protocols')
31 files changed, 317 insertions, 400 deletions
diff --git a/protocols/JabberG/src/jabber_adhoc.cpp b/protocols/JabberG/src/jabber_adhoc.cpp index e9856a685d..d958721e2b 100644 --- a/protocols/JabberG/src/jabber_adhoc.cpp +++ b/protocols/JabberG/src/jabber_adhoc.cpp @@ -153,7 +153,7 @@ int CJabberProto::AdHoc_OnJAHMCommandListResult(HWND hwndDlg, TiXmlElement *iqNo dat->CurrentHeight = 0;
dat->curPos = 0;
SetScrollPos(GetDlgItem(hwndDlg, IDC_VSCROLL), SB_CTL, 0, FALSE);
- TiXmlElement *queryNode = iqNode->FirstChildElement("query");
+ auto *queryNode = iqNode->FirstChildElement("query");
if (queryNode) {
const char *xmlns = queryNode->Attribute("xmlns");
const char *node = queryNode->Attribute("node");
@@ -214,10 +214,10 @@ int CJabberProto::AdHoc_OnJAHMProcessResult(HWND hwndDlg, TiXmlElement *workNode // use jabber:x:data form
HWND hFrame = GetDlgItem(hwndDlg, IDC_FRAME);
ShowWindow(GetDlgItem(hwndDlg, IDC_FRAME_TEXT), SW_HIDE);
- if (auto *n = xNode->FirstChildElement("instructions"))
- JabberFormSetInstruction(hwndDlg, n->GetText());
- else if (n = xNode->FirstChildElement("title"))
- JabberFormSetInstruction(hwndDlg, n->GetText());
+ if (auto *pszText = XmlGetChildText(xNode, "instructions"))
+ JabberFormSetInstruction(hwndDlg, pszText);
+ else if (pszText = XmlGetChildText(xNode, "title"))
+ JabberFormSetInstruction(hwndDlg, pszText);
else
JabberFormSetInstruction(hwndDlg, Translate(status));
JabberFormCreateUI(hFrame, xNode, &dat->CurrentHeight);
@@ -228,8 +228,8 @@ int CJabberProto::AdHoc_OnJAHMProcessResult(HWND hwndDlg, TiXmlElement *workNode int toHide[] = { IDC_FRAME_TEXT, IDC_FRAME, IDC_VSCROLL, 0 };
sttShowControls(hwndDlg, FALSE, toHide);
- auto *note = commandNode->FirstChildElement("note");
- JabberFormSetInstruction(hwndDlg, note ? note->GetText() : Translate(status));
+ auto *pszText = XmlGetChildText(commandNode, "note");
+ JabberFormSetInstruction(hwndDlg, pszText ? pszText : Translate(status));
}
// check actions
diff --git a/protocols/JabberG/src/jabber_agent.cpp b/protocols/JabberG/src/jabber_agent.cpp index 1cb0aceae4..07894f0f1d 100644 --- a/protocols/JabberG/src/jabber_agent.cpp +++ b/protocols/JabberG/src/jabber_agent.cpp @@ -161,8 +161,8 @@ public: if (auto *xNode = queryNode->FirstChildElement("x")) {
// use new jabber:x:data form
- if (auto *n = xNode->FirstChildElement("instructions"))
- JabberFormSetInstruction(m_hwnd, n->GetText());
+ if (const char *pszText = XmlGetChildText(xNode, "instructions"))
+ JabberFormSetInstruction(m_hwnd, pszText);
JabberFormCreateUI(hFrame, xNode, &m_formHeight /*dummy*/);
}
diff --git a/protocols/JabberG/src/jabber_byte.cpp b/protocols/JabberG/src/jabber_byte.cpp index bf4c98c6c2..96fd3e79b6 100644 --- a/protocols/JabberG/src/jabber_byte.cpp +++ b/protocols/JabberG/src/jabber_byte.cpp @@ -615,7 +615,7 @@ void __cdecl CJabberProto::ByteReceiveThread(JABBER_BYTE_TRANSFER *jbt) port = (WORD)atoi(szPort);
replaceStr(jbt->streamhostJID, str);
- debugLogW(L"bytestream_recv connecting to %s:%d", szHost, port);
+ debugLogA("bytestream_recv connecting to %s:%d", szHost, port);
NETLIBOPENCONNECTION nloc = { 0 };
nloc.cbSize = sizeof(nloc);
nloc.szHost = mir_strdup(szHost);
diff --git a/protocols/JabberG/src/jabber_console.cpp b/protocols/JabberG/src/jabber_console.cpp index 733a2a1c89..e0c4d8589a 100644 --- a/protocols/JabberG/src/jabber_console.cpp +++ b/protocols/JabberG/src/jabber_console.cpp @@ -132,7 +132,7 @@ bool CJabberProto::FilterXml(const TiXmlElement *node, DWORD flags) break;
case TFilterInfo::T_XMLNS:
- attrValue = node->FirstChildElement(0)->Attribute("xmlns");
+ attrValue = node->FirstChildElement()->Attribute("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 ed9898f5e1..a82b328c75 100644 --- a/protocols/JabberG/src/jabber_disco.cpp +++ b/protocols/JabberG/src/jabber_disco.cpp @@ -128,13 +128,10 @@ void CJabberProto::OnIqResultServiceDiscoveryInfo(const TiXmlElement *iqNode, CJ }
}
else {
- if (pInfo->GetIqType() == JABBER_IQ_TYPE_ERROR) {
- auto *errorNode = iqNode->FirstChildElement("error");
- wchar_t *str = JabberErrorMsg(errorNode);
- pNode->SetInfoRequestErrorText(str);
- mir_free(str);
- }
- else pNode->SetInfoRequestErrorText(TranslateT("request timeout."));
+ if (pInfo->GetIqType() == JABBER_IQ_TYPE_ERROR)
+ pNode->SetInfoRequestErrorText(JabberErrorMsg(iqNode));
+ else
+ pNode->SetInfoRequestErrorText(TranslateT("request timeout."));
pNode->SetInfoRequestId(JABBER_DISCO_RESULT_ERROR);
}
@@ -167,13 +164,11 @@ void CJabberProto::OnIqResultServiceDiscoveryItems(const TiXmlElement *iqNode, C }
}
else {
- if (pInfo->GetIqType() == JABBER_IQ_TYPE_ERROR) {
- auto *errorNode = iqNode->FirstChildElement("error");
- pNode->SetItemsRequestErrorText(JabberErrorMsg(errorNode));
- }
- else {
+ if (pInfo->GetIqType() == JABBER_IQ_TYPE_ERROR)
+ pNode->SetItemsRequestErrorText(JabberErrorMsg(iqNode));
+ else
pNode->SetItemsRequestErrorText(L"request timeout.");
- }
+
pNode->SetItemsRequestId(JABBER_DISCO_RESULT_ERROR);
}
@@ -191,14 +186,11 @@ void CJabberProto::OnIqResultServiceDiscoveryRootInfo(const TiXmlElement *iqNode mir_cslockfull lck(m_SDManager.cs());
if (pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT) {
- auto *query = iqNode->FirstChildElement("query");
- if (query) {
- for (auto *feature : TiXmlFilter(query, "feature")) {
- if (!mir_strcmp(feature->Attribute("var"), (char*)pInfo->m_pUserData)) {
- CJabberSDNode *pNode = m_SDManager.AddPrimaryNode(pInfo->GetReceiver(), iqNode->Attribute("node"), nullptr);
- SendBothRequests(pNode, nullptr);
- break;
- }
+ 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);
+ SendBothRequests(pNode, nullptr);
+ break;
}
}
}
@@ -215,19 +207,16 @@ void CJabberProto::OnIqResultServiceDiscoveryRootItems(const TiXmlElement *iqNod TiXmlDocument packet;
mir_cslockfull lck(m_SDManager.cs());
if (pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT) {
- auto *query = iqNode->FirstChildElement("query");
- if (query) {
- for (auto *item : TiXmlFilter(query, "item")) {
- const char *szJid = item->Attribute("jid");
- const char *szNode = item->Attribute("node");
- CJabberIqInfo *pNewInfo = AddIQ(&CJabberProto::OnIqResultServiceDiscoveryRootInfo, JABBER_IQ_TYPE_GET, szJid);
- pNewInfo->m_pUserData = pInfo->m_pUserData;
- pNewInfo->SetTimeout(30000);
-
- XmlNodeIq iq(pNewInfo);
- iq << XQUERY(JABBER_FEAT_DISCO_INFO) << XATTR("node", szNode);
- packet.InsertEndChild(iq);
- }
+ for (auto *item : TiXmlFilter(iqNode->FirstChildElement("query"), "item")) {
+ const char *szJid = item->Attribute("jid");
+ const char *szNode = item->Attribute("node");
+ CJabberIqInfo *pNewInfo = AddIQ(&CJabberProto::OnIqResultServiceDiscoveryRootInfo, JABBER_IQ_TYPE_GET, szJid);
+ pNewInfo->m_pUserData = pInfo->m_pUserData;
+ pNewInfo->SetTimeout(30000);
+
+ XmlNodeIq iq(pNewInfo);
+ iq << XQUERY(JABBER_FEAT_DISCO_INFO) << XATTR("node", szNode);
+ packet.InsertEndChild(iq);
}
}
lck.unlock();
diff --git a/protocols/JabberG/src/jabber_disco.h b/protocols/JabberG/src/jabber_disco.h index 1c3863dd9c..418c7ed178 100644 --- a/protocols/JabberG/src/jabber_disco.h +++ b/protocols/JabberG/src/jabber_disco.h @@ -341,7 +341,7 @@ public: return TRUE;
}
- BOOL SetInfoRequestErrorText(wchar_t *szError)
+ BOOL SetInfoRequestErrorText(const wchar_t *szError)
{
replaceStrW(m_szInfoError, szError);
return TRUE;
diff --git a/protocols/JabberG/src/jabber_events.cpp b/protocols/JabberG/src/jabber_events.cpp index e2d906792e..8f30874711 100644 --- a/protocols/JabberG/src/jabber_events.cpp +++ b/protocols/JabberG/src/jabber_events.cpp @@ -98,7 +98,7 @@ void __cdecl CJabberProto::OnRenameGroup(DBCONTACTWRITESETTING *cws, MCONTACT hC else {
char *p = sttSettingToTchar(cws);
if (cws->value.pszVal != nullptr && mir_strcmp(p, item->group)) {
- debugLogW(L"Group set to %s", p);
+ debugLogA("Group set to %s", p);
if (p)
AddContactToRoster(item->jid, tszNick, p);
}
@@ -121,7 +121,7 @@ void __cdecl CJabberProto::OnRenameContact(DBCONTACTWRITESETTING *cws, MCONTACT ptrA newNick(sttSettingToTchar(cws));
if (newNick && mir_strcmp(item->nick, newNick)) {
- debugLogW(L"Renaming contact %s: %s -> %s", item->jid, item->nick, newNick);
+ debugLogA("Renaming contact %s: %s -> %s", item->jid, item->nick, newNick);
AddContactToRoster(item->jid, newNick, item->group);
}
}
@@ -132,7 +132,7 @@ void __cdecl CJabberProto::OnAddContactForever(MCONTACT hContact) if (jid == nullptr)
return;
- debugLogW(L"Add %s permanently to list", jid);
+ debugLogA("Add %s permanently to list", jid);
ptrA nick(db_get_utfa(hContact, "CList", "MyHandle"));
if (nick == nullptr)
nick = getUStringA(hContact, "Nick");
diff --git a/protocols/JabberG/src/jabber_form.cpp b/protocols/JabberG/src/jabber_form.cpp index 01eab07b01..440bf89a57 100644 --- a/protocols/JabberG/src/jabber_form.cpp +++ b/protocols/JabberG/src/jabber_form.cpp @@ -648,23 +648,20 @@ static INT_PTR CALLBACK JabberFormDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, ShowWindow(GetDlgItem(hwndDlg, IDC_FRAME_TEXT), SW_HIDE);
jfi = (JABBER_FORM_INFO*)lParam;
if (jfi != nullptr) {
- TiXmlElement *n;
LONG frameExStyle;
// Set dialog title
- if (jfi->xNode != nullptr && (n = jfi->xNode->FirstChildElement("title")) != nullptr && n->GetText() != nullptr)
- SetWindowText(hwndDlg, Utf2T(n->GetText()));
+ if (auto *pszText = XmlGetChildText(jfi->xNode, "title"))
+ SetWindowTextUtf(hwndDlg, pszText);
else
SetWindowText(hwndDlg, TranslateW(jfi->defTitle));
// Set instruction field
- if (jfi->xNode != nullptr && (n = jfi->xNode->FirstChildElement("instructions")) != nullptr && n->GetText() != nullptr)
- JabberFormSetInstruction(hwndDlg, n->GetText());
- else {
- if (jfi->xNode != nullptr && (n = jfi->xNode->FirstChildElement("title")) != nullptr && n->GetText() != nullptr)
- JabberFormSetInstruction(hwndDlg, n->GetText());
- else
- JabberFormSetInstruction(hwndDlg, Translate(T2Utf(jfi->defTitle)));
- }
+ if (auto *pszText = XmlGetChildText(jfi->xNode, "instructions"))
+ JabberFormSetInstruction(hwndDlg, pszText);
+ else if (pszText = XmlGetChildText(jfi->xNode, "title"))
+ JabberFormSetInstruction(hwndDlg, pszText);
+ else
+ JabberFormSetInstruction(hwndDlg, Translate(T2Utf(jfi->defTitle)));
// Create form
if (jfi->xNode != nullptr) {
diff --git a/protocols/JabberG/src/jabber_ft.cpp b/protocols/JabberG/src/jabber_ft.cpp index 8095a97b65..515219b8fb 100644 --- a/protocols/JabberG/src/jabber_ft.cpp +++ b/protocols/JabberG/src/jabber_ft.cpp @@ -187,7 +187,7 @@ BOOL CJabberProto::FtSend(HNETLIBCONN hConn, filetransfer *ft) debugLogW(L"Sending [%s]", ft->std.pszFiles.w[ft->std.currentFileNumber]);
_wstat64(ft->std.pszFiles.w[ft->std.currentFileNumber], &statbuf); // file size in statbuf.st_size
if ((fd = _wopen(ft->std.pszFiles.w[ft->std.currentFileNumber], _O_BINARY | _O_RDONLY)) < 0) {
- debugLogW(L"File cannot be opened");
+ debugLogA("File cannot be opened");
return FALSE;
}
@@ -319,12 +319,10 @@ void CJabberProto::FtHandleSiRequest(const TiXmlElement *iqNode) if (!bIbbOnly) {
for (auto *it : TiXmlFilter(fieldNode, "option")) {
- if (auto *n = it->FirstChildElement("value")) {
- if (!mir_strcmp(n->GetText(), JABBER_FEAT_BYTESTREAMS)) {
- optionNode = it;
- ftType = FT_BYTESTREAM;
- break;
- }
+ if (!mir_strcmp(XmlGetChildText(it, "value"), JABBER_FEAT_BYTESTREAMS)) {
+ optionNode = it;
+ ftType = FT_BYTESTREAM;
+ break;
}
}
}
@@ -332,12 +330,10 @@ void CJabberProto::FtHandleSiRequest(const TiXmlElement *iqNode) // try IBB only if bytestreams support not found or BsOnlyIBB flag exists
if (bIbbOnly || !optionNode) {
for (auto *it : TiXmlFilter(fieldNode, "option")) {
- if (auto *n = it->FirstChildElement("value")) {
- if (!mir_strcmp(n->GetText(), JABBER_FEAT_IBB)) {
- optionNode = it;
- ftType = FT_IBB;
- break;
- }
+ if (!mir_strcmp(XmlGetChildText(it, "value"), JABBER_FEAT_IBB)) {
+ optionNode = it;
+ ftType = FT_IBB;
+ break;
}
}
}
@@ -355,7 +351,7 @@ void CJabberProto::FtHandleSiRequest(const TiXmlElement *iqNode) ft->std.szCurrentFile.w = mir_utf8decodeW(filename);
ft->std.totalBytes = ft->std.currentFileSize = filesize;
- CMStringW wszDescr;
+ Utf2T wszDescr(XmlGetChildText(fileNode, "desc"));
PROTORECVFILE pre = { 0 };
pre.dwFlags = PRFF_UNICODE;
@@ -363,10 +359,7 @@ void CJabberProto::FtHandleSiRequest(const TiXmlElement *iqNode) pre.timestamp = time(0);
pre.files.w = (wchar_t**)&filename;
pre.lParam = (LPARAM)ft;
- if (auto *n = fileNode->FirstChildElement("desc"))
- wszDescr = Utf2T(n->GetText());
- pre.descr.w = wszDescr.GetBuffer();
-
+ pre.descr.w = wszDescr;
ProtoChainRecvFile(ft->std.hContact, &pre);
return;
}
diff --git a/protocols/JabberG/src/jabber_groupchat.cpp b/protocols/JabberG/src/jabber_groupchat.cpp index d4c595d391..49906f9f8d 100644 --- a/protocols/JabberG/src/jabber_groupchat.cpp +++ b/protocols/JabberG/src/jabber_groupchat.cpp @@ -331,13 +331,10 @@ void CJabberProto::OnIqResultDiscovery(const TiXmlElement *iqNode, CJabberIqInfo }
}
else if (pInfo->GetIqType() == JABBER_IQ_TYPE_ERROR) {
- auto *errorNode = iqNode->FirstChildElement("error");
- wchar_t *str = JabberErrorMsg(errorNode);
sttRoomListAppend(hwndList, RoomInfo::ROOM_FAIL,
TranslateT("Jabber Error"),
- str,
+ JabberErrorMsg(iqNode),
L"");
- mir_free(str);
}
else
sttRoomListAppend(hwndList, RoomInfo::ROOM_FAIL,
@@ -841,25 +838,18 @@ void CJabberProto::GroupchatProcessPresence(const TiXmlElement *node) // Update status of room participant
int status = ID_STATUS_ONLINE;
- if (auto *n = node->FirstChildElement("show")) {
- if (!mir_strcmp(n->GetText(), "away")) status = ID_STATUS_AWAY;
- else if (!mir_strcmp(n->GetText(), "xa")) status = ID_STATUS_NA;
- else if (!mir_strcmp(n->GetText(), "dnd")) status = ID_STATUS_DND;
- else if (!mir_strcmp(n->GetText(), "chat")) status = ID_STATUS_FREECHAT;
+ if (auto *pszStatus = XmlGetChildText(node, "show")) {
+ if (!mir_strcmp(pszStatus, "away")) status = ID_STATUS_AWAY;
+ else if (!mir_strcmp(pszStatus, "xa")) status = ID_STATUS_NA;
+ else if (!mir_strcmp(pszStatus, "dnd")) status = ID_STATUS_DND;
+ else if (!mir_strcmp(pszStatus, "chat")) status = ID_STATUS_FREECHAT;
}
- const char *str = nullptr;
- if (auto *n = node->FirstChildElement("status"))
- str = n->GetText();
-
- char priority = 0;
- if (auto *n = node->FirstChildElement("priority"))
- if (n->GetText())
- priority = atoi(n->GetText());
+ const char *str = XmlGetChildText(node, "status");
+ int priority = XmlGetChildInt(node, "priority");
+ int newRes = ListAddResource(LIST_CHATROOM, from, status, str, priority, cnick) ? GC_EVENT_JOIN : 0;
bool bStatusChanged = false, bRoomCreated = false, bAffiliationChanged = false, bRoleChanged = false;
- int newRes = ListAddResource(LIST_CHATROOM, from, status, str, priority, cnick) ? GC_EVENT_JOIN : 0;
-
if (pResourceStatus oldRes = ListFindResource(LIST_CHATROOM, from))
if ((oldRes->m_iStatus != status) || mir_strcmp(oldRes->m_szStatusMessage, str))
bStatusChanged = true;
@@ -930,13 +920,10 @@ void CJabberProto::GroupchatProcessPresence(const TiXmlElement *node) // Check <created/>
if (bRoomCreated) {
- auto *n = node->FirstChildElement("created");
- if (n != nullptr && (str = n->Attribute("xmlns")) != nullptr && !mir_strcmp(str, JABBER_FEAT_MUC_OWNER))
+ if (XmlGetChildByTag(node, "created", "xmlns", JABBER_FEAT_MUC_OWNER))
// A new room just created by me
// Request room config
- m_ThreadInfo->send(
- XmlNodeIq(AddIQ(&CJabberProto::OnIqResultGetMuc, JABBER_IQ_TYPE_GET, item->jid))
- << XQUERY(JABBER_FEAT_MUC_OWNER));
+ m_ThreadInfo->send(XmlNodeIq(AddIQ(&CJabberProto::OnIqResultGetMuc, JABBER_IQ_TYPE_GET, item->jid)) << XQUERY(JABBER_FEAT_MUC_OWNER));
}
}
@@ -991,8 +978,7 @@ void CJabberProto::GroupchatProcessPresence(const TiXmlElement *node) // processing room errors
else if (!mir_strcmp(type, "error")) {
int errorCode = 0;
- auto *errorNode = node->FirstChildElement("error");
- ptrW str(JabberErrorMsg(errorNode, &errorCode));
+ CMStringW str(JabberErrorMsg(node, &errorCode));
if (errorCode == JABBER_ERROR_CONFLICT) {
ptrA newNick(getUStringA("GcAltNick"));
diff --git a/protocols/JabberG/src/jabber_iq.cpp b/protocols/JabberG/src/jabber_iq.cpp index 162d60e7a6..b49c067554 100644 --- a/protocols/JabberG/src/jabber_iq.cpp +++ b/protocols/JabberG/src/jabber_iq.cpp @@ -171,7 +171,7 @@ void CJabberIqManager::ExpireInfo(CJabberIqInfo *pInfo) if ((pInfo->m_dwParamsToParse & JABBER_IQ_PARSE_HCONTACT) && (pInfo->m_szFrom))
pInfo->m_hContact = ppro->HContactFromJID(pInfo->m_szFrom);
- ppro->debugLogW(L"Expiring iq id %d, sent to %s", pInfo->m_nIqId, pInfo->m_szReceiver ? pInfo->m_szReceiver : "server");
+ ppro->debugLogA("Expiring iq id %d, sent to %s", pInfo->m_nIqId, pInfo->m_szReceiver ? pInfo->m_szReceiver : "server");
pInfo->m_nIqType = JABBER_IQ_TYPE_FAIL;
(ppro->*(pInfo->m_pHandler))(nullptr, pInfo);
@@ -334,7 +334,7 @@ bool CJabberIqManager::HandleIqPermanent(const TiXmlElement *pNode) if ((pInfo->m_dwParamsToParse & JABBER_IQ_PARSE_HCONTACT) && (iqInfo.m_szFrom))
iqInfo.m_hContact = ppro->HContactFromJID(iqInfo.m_szFrom);
- ppro->debugLogW(L"Handling iq id %s, type %s, from %s", iqInfo.m_szId, szType, iqInfo.m_szFrom);
+ ppro->debugLogA("Handling iq id %s, type %s, from %s", iqInfo.m_szId, szType, iqInfo.m_szFrom);
if ((ppro->*(pInfo->m_pHandler))(pNode, &iqInfo))
return true;
}
diff --git a/protocols/JabberG/src/jabber_iq_handlers.cpp b/protocols/JabberG/src/jabber_iq_handlers.cpp index 2050c6350e..e1c3bd9e49 100644 --- a/protocols/JabberG/src/jabber_iq_handlers.cpp +++ b/protocols/JabberG/src/jabber_iq_handlers.cpp @@ -248,8 +248,7 @@ BOOL CJabberProto::OnRosterPushRequest(const TiXmlElement*, CJabberIqInfo *pInfo replaceStr(item->nick, nick);
item->bRealContact = true;
- auto *groupNode = itemNode->FirstChildElement("group");
- replaceStr(item->group, groupNode->GetText());
+ replaceStr(item->group, XmlGetChildText(itemNode, "group"));
if (name != nullptr) {
ptrA tszNick(getUStringA(hContact, "Nick"));
@@ -283,7 +282,7 @@ BOOL CJabberProto::OnRosterPushRequest(const TiXmlElement*, CJabberIqInfo *pInfo else
item->subscription = SUB_NONE;
- debugLogW(L"Roster push for jid=%s (hContact=%d), set subscription to %s", jid, item->hContact, str);
+ debugLogA("Roster push for jid=%s (hContact=%d), set subscription to %s", jid, item->hContact, str);
// subscription = remove is to remove from roster list
// but we will just set the contact to offline and not actually
@@ -309,8 +308,8 @@ BOOL CJabberProto::OnIqRequestOOB(const TiXmlElement*, CJabberIqInfo *pInfo) if (!pInfo->GetFrom() || !pInfo->GetHContact())
return TRUE;
- auto *n = pInfo->GetChildNode()->FirstChildElement("url");
- if (!n || !n->GetText())
+ const char *pszUrl = XmlGetChildText(pInfo->GetChildNode(), "url");
+ if (!pszUrl)
return TRUE;
if (m_bBsOnlyIBB) {
@@ -331,9 +330,8 @@ BOOL CJabberProto::OnIqRequestOOB(const TiXmlElement*, CJabberIqInfo *pInfo) ft->httpPath = nullptr;
// Parse the URL
- const char *str = n->GetText(); // URL of the file to get
- if (!mir_strncmpi(str, "http://", 7)) {
- const char *p = str + 7, *q;
+ if (!mir_strncmpi(pszUrl, "http://", 7)) {
+ const char *p = pszUrl + 7, *q;
if ((q = strchr(p, '/')) != nullptr) {
char text[1024];
if (q - p < _countof(text)) {
@@ -352,14 +350,12 @@ BOOL CJabberProto::OnIqRequestOOB(const TiXmlElement*, CJabberIqInfo *pInfo) ft->szId = JabberId2string(pInfo->GetIqId());
if (ft->httpHostName && ft->httpPath) {
- const char *desc = nullptr;
-
debugLogA("Host=%s Port=%d Path=%s", ft->httpHostName, ft->httpPort, ft->httpPath);
- if ((n = pInfo->GetChildNode()->FirstChildElement("desc")) != nullptr)
- desc = n->GetText();
+
+ const char *desc = XmlGetChildText(pInfo->GetChildNode(), "desc");
+ debugLogA("description = %s", desc);
wchar_t *str2;
- debugLogW(L"description = %s", desc);
if ((str2 = wcsrchr(ft->httpPath, '/')) != nullptr)
str2++;
else
diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp index 17bb43304f..627f404a8a 100755 --- a/protocols/JabberG/src/jabber_iqid.cpp +++ b/protocols/JabberG/src/jabber_iqid.cpp @@ -296,9 +296,9 @@ void CJabberProto::OnIqResultBind(const TiXmlElement *iqNode, CJabberIqInfo *pIn const char *szJid = XPath(iqNode, "bind[@xmlns='urn:ietf:params:xml:ns:xmpp-bind']/jid");
if (szJid) {
if (!strncmp(m_ThreadInfo->fullJID, szJid, _countof(m_ThreadInfo->fullJID)))
- debugLogW(L"Result Bind: %s confirmed ", m_ThreadInfo->fullJID);
+ debugLogA("Result Bind: %s confirmed ", m_ThreadInfo->fullJID);
else {
- debugLogW(L"Result Bind: %s changed to %s", m_ThreadInfo->fullJID, szJid);
+ debugLogA("Result Bind: %s changed to %s", m_ThreadInfo->fullJID, szJid);
strncpy_s(m_ThreadInfo->fullJID, szJid, _TRUNCATE);
}
}
@@ -399,9 +399,7 @@ void CJabberProto::OnIqResultGetRoster(const TiXmlElement *iqNode, CJabberIqInfo item->bRealContact = true;
mir_free(item->nick); item->nick = nick;
-
- if (auto *groupNode = itemNode->FirstChildElement("group"))
- replaceStr(item->group, groupNode->GetText());
+ replaceStr(item->group, XmlGetChildText(itemNode, "group"));
// check group delimiters
if (item->group && szGroupDelimeter) {
@@ -473,7 +471,7 @@ void CJabberProto::OnIqResultGetRoster(const TiXmlElement *iqNode, CJabberIqInfo {
JABBER_LIST_ITEM *item = ListGetItemPtrFromIndex(i);
if (item && item->hContact && !item->bRealContact) {
- debugLogW(L"Syncing roster: preparing to delete %s (hContact=0x%x)", item->jid, item->hContact);
+ debugLogA("Syncing roster: preparing to delete %s (hContact=0x%x)", item->jid, item->hContact);
db_delete_contact(item->hContact);
}
}
@@ -516,12 +514,8 @@ void CJabberProto::OnIqResultGetRegister(const TiXmlElement *iqNode, CJabberIqIn SendMessage(m_hwndAgentRegInput, WM_JABBER_REGINPUT_ACTIVATE, 1 /*success*/, (LPARAM)iqNode);
}
else if (!mir_strcmp(type, "error")) {
- if (m_hwndAgentRegInput) {
- auto *errorNode = iqNode->FirstChildElement("error");
- wchar_t *str = JabberErrorMsg(errorNode);
- SendMessage(m_hwndAgentRegInput, WM_JABBER_REGINPUT_ACTIVATE, 0 /*error*/, (LPARAM)str);
- mir_free(str);
- }
+ if (m_hwndAgentRegInput)
+ SendMessage(m_hwndAgentRegInput, WM_JABBER_REGINPUT_ACTIVATE, 0 /*error*/, (LPARAM)JabberErrorMsg(iqNode).c_str());
}
}
@@ -544,12 +538,8 @@ void CJabberProto::OnIqResultSetRegister(const TiXmlElement *iqNode, CJabberIqIn SendMessage(m_hwndRegProgress, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)TranslateT("Registration successful"));
}
else if (!mir_strcmp(type, "error")) {
- if (m_hwndRegProgress) {
- auto *errorNode = iqNode->FirstChildElement("error");
- wchar_t *str = JabberErrorMsg(errorNode);
- SendMessage(m_hwndRegProgress, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)str);
- mir_free(str);
- }
+ if (m_hwndRegProgress)
+ SendMessage(m_hwndRegProgress, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)JabberErrorMsg(iqNode).c_str());
}
}
@@ -562,9 +552,8 @@ void CJabberProto::OnIqResultGetVcardPhoto(const TiXmlElement *n, MCONTACT hCont if (hasPhoto)
return;
- auto *o = n->FirstChildElement("BINVAL");
- const char *ptszBinval = o->GetText();
- if (o == nullptr || ptszBinval == nullptr)
+ const char *ptszBinval = XmlGetChildText(n, "BINVAL");
+ if (ptszBinval == nullptr)
return;
size_t bufferLen;
@@ -572,14 +561,9 @@ void CJabberProto::OnIqResultGetVcardPhoto(const TiXmlElement *n, MCONTACT hCont if (buffer == nullptr)
return;
- const char *szPicType = nullptr;
- if (auto *t = n->FirstChildElement("TYPE"))
- if (ProtoGetAvatarFormatByMimeType(t->GetText()) != PA_FORMAT_UNKNOWN)
- szPicType = t->GetText();
-
- if (szPicType == nullptr)
+ const char *szPicType = XmlGetChildText(n, "TYPE");
+ if (ProtoGetAvatarFormatByMimeType(szPicType) == PA_FORMAT_UNKNOWN)
szPicType = ProtoGetAvatarMimeType(ProtoGetBufferFormat(buffer));
-
if (szPicType == nullptr)
return;
@@ -621,7 +605,7 @@ void CJabberProto::OnIqResultGetVcardPhoto(const TiXmlElement *n, MCONTACT hCont DeleteFile(oldFile);
replaceStr(item->photoFileName, T2Utf(szAvatarFileName));
debugLogW(L"Contact's picture saved to %s", szAvatarFileName);
- OnIqResultGotAvatar(hContact, o, szPicType);
+ OnIqResultGotAvatar(hContact, ptszBinval, szPicType);
}
}
}
@@ -630,18 +614,9 @@ void CJabberProto::OnIqResultGetVcardPhoto(const TiXmlElement *n, MCONTACT hCont DeleteFile(szAvatarFileName);
}
-static char* sttGetText(const TiXmlElement *node, const char *tag)
-{
- auto *n = node->FirstChildElement(tag);
- if (n == nullptr)
- return nullptr;
-
- return (char*)n->GetText();
-}
-
void CJabberProto::OnIqResultGetVcard(const TiXmlElement *iqNode, CJabberIqInfo*)
{
- const TiXmlElement *vCardNode, *m, *o;
+ const TiXmlElement *vCardNode;
const char *type, *jid;
MCONTACT hContact;
DBVARIANT dbv;
@@ -658,10 +633,10 @@ void CJabberProto::OnIqResultGetVcard(const TiXmlElement *iqNode, CJabberIqInfo* if (!mir_strcmp(type, "result")) {
PROTOSEARCHRESULT psr = { 0 };
psr.cbSize = sizeof(psr);
- psr.nick.a = sttGetText(vCardNode, "NICKNAME");
- psr.firstName.a = sttGetText(vCardNode, "FN");
+ psr.nick.a = (char*)XmlGetChildText(vCardNode, "NICKNAME");
+ psr.firstName.a = (char*)XmlGetChildText(vCardNode, "FN");
psr.lastName.a = "";
- psr.email.a = sttGetText(vCardNode, "EMAIL");
+ psr.email.a = (char*)XmlGetChildText(vCardNode, "EMAIL");
psr.id.a = NEWSTR_ALLOCA(jid);
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)id, (LPARAM)&psr);
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)id, 0);
@@ -722,25 +697,23 @@ void CJabberProto::OnIqResultGetVcard(const TiXmlElement *iqNode, CJabberIqInfo* else if (!mir_strcmp(n->Name(), "N")) {
// First/Last name
if (!hasGiven && !hasFamily && !hasMiddle) {
- if ((m = n->FirstChildElement("GIVEN")) != nullptr && m->GetText() != nullptr) {
+ if (auto *p = XmlGetChildText(n, "GIVEN")) {
hasGiven = true;
- setUString(hContact, "FirstName", m->GetText());
+ setUString(hContact, "FirstName", p);
}
- if ((m = n->FirstChildElement("FAMILY")) != nullptr && m->GetText() != nullptr) {
+ if (auto *p = XmlGetChildText(n, "FAMILY")) {
hasFamily = true;
- setUString(hContact, "LastName", m->GetText());
+ setUString(hContact, "LastName", p);
}
- if ((m = n->FirstChildElement("MIDDLE")) != nullptr && m->GetText() != nullptr) {
+ if (auto *p = XmlGetChildText(n, "MIDDLE")) {
hasMiddle = true;
- setUString(hContact, "MiddleName", m->GetText());
+ setUString(hContact, "MiddleName", p);
}
}
}
else if (!mir_strcmp(n->Name(), "EMAIL")) {
// E-mail address(es)
- if ((m = n->FirstChildElement("USERID")) == nullptr) // Some bad client put e-mail directly in <EMAIL/> instead of <USERID/>
- m = n;
- if (m->GetText() != nullptr) {
+ if (auto *p = XmlGetChildText(n, "USERID")) {
char text[100];
if (hContact != 0) {
if (nEmail == 0)
@@ -749,7 +722,7 @@ void CJabberProto::OnIqResultGetVcard(const TiXmlElement *iqNode, CJabberIqInfo* mir_snprintf(text, "e-mail%d", nEmail - 1);
}
else mir_snprintf(text, "e-mail%d", nEmail);
- setUString(hContact, text, m->GetText());
+ setUString(hContact, text, p);
if (hContact == 0) {
mir_snprintf(text, "e-mailFlag%d", nEmail);
@@ -808,107 +781,108 @@ void CJabberProto::OnIqResultGetVcard(const TiXmlElement *iqNode, CJabberIqInfo* // Home address
char text[128];
hasHome = true;
- if ((m = n->FirstChildElement("STREET")) != nullptr && m->GetText() != nullptr) {
+ if (auto *p = XmlGetChildText(n, "STREET")) {
hasHomeStreet = true;
if (hContact != 0) {
- if ((o = n->FirstChildElement("EXTADR")) != nullptr && o->GetText() != nullptr)
- mir_snprintf(text, "%s\r\n%s", m->GetText(), o->GetText());
- else if ((o = n->FirstChildElement("EXTADD")) != nullptr && o->GetText() != nullptr)
- mir_snprintf(text, "%s\r\n%s", m->GetText(), o->GetText());
+ if (auto *o = XmlGetChildText(n, "EXTADR"))
+ mir_snprintf(text, "%s\r\n%s", p, o);
+ else if (o = XmlGetChildText(n, "EXTADD"))
+ mir_snprintf(text, "%s\r\n%s", p, o);
else
- strncpy_s(text, m->GetText(), _TRUNCATE);
+ strncpy_s(text, p, _TRUNCATE);
setUString(hContact, "Street", text);
}
else {
- setUString(hContact, "Street", m->GetText());
- if ((m = n->FirstChildElement("EXTADR")) == nullptr)
- m = n->FirstChildElement("EXTADD");
- if (m != nullptr && m->GetText() != nullptr) {
+ setUString(hContact, "Street", p);
+ if (p = XmlGetChildText(n, "EXTADR")) {
+ hasHomeStreet2 = true;
+ setUString(hContact, "Street2", p);
+ }
+ else if (p = XmlGetChildText(n, "EXTADD")) {
hasHomeStreet2 = true;
- setUString(hContact, "Street2", m->GetText());
+ setUString(hContact, "Street2", p);
}
}
}
- if ((m = n->FirstChildElement("LOCALITY")) != nullptr && m->GetText() != nullptr) {
+ if (auto *p = XmlGetChildText(n, "LOCALITY")) {
hasHomeLocality = true;
- setUString(hContact, "City", m->GetText());
+ setUString(hContact, "City", p);
}
- if ((m = n->FirstChildElement("REGION")) != nullptr && m->GetText() != nullptr) {
+ if (auto *p = XmlGetChildText(n, "REGION")) {
hasHomeRegion = true;
- setUString(hContact, "State", m->GetText());
+ setUString(hContact, "State", p);
}
- if ((m = n->FirstChildElement("PCODE")) != nullptr && m->GetText() != nullptr) {
+ if (auto *p = XmlGetChildText(n, "PCODE")) {
hasHomePcode = true;
- setUString(hContact, "ZIP", m->GetText());
+ setUString(hContact, "ZIP", p);
}
- if ((m = n->FirstChildElement("CTRY")) == nullptr || m->GetText() == nullptr) // Some bad client use <COUNTRY/> instead of <CTRY/>
- m = n->FirstChildElement("COUNTRY");
- if (m != nullptr && m->GetText() != nullptr) {
+ if (auto *p = XmlGetChildText(n, "CTRY")) { // Some bad client use <COUNTRY/> instead of <CTRY/>
hasHomeCtry = true;
- setUString(hContact, "Country", m->GetText());
+ setUString(hContact, "Country", p);
}
}
if (!hasWork && n->FirstChildElement("WORK") != nullptr) {
// Work address
hasWork = true;
- if ((m = n->FirstChildElement("STREET")) != nullptr && m->GetText() != nullptr) {
+ if (auto *p = XmlGetChildText(n, "STREET")) {
char text[128];
hasWorkStreet = true;
if (hContact != 0) {
- if ((o = n->FirstChildElement("EXTADR")) != nullptr && o->GetText() != nullptr)
- mir_snprintf(text, "%s\r\n%s", m->GetText(), o->GetText());
- else if ((o = n->FirstChildElement("EXTADD")) != nullptr && o->GetText() != nullptr)
- mir_snprintf(text, "%s\r\n%s", m->GetText(), o->GetText());
+ if (auto *o = XmlGetChildText(n, "EXTADR"))
+ mir_snprintf(text, "%s\r\n%s", p, o);
+ else if (o = XmlGetChildText(n, "EXTADD"))
+ mir_snprintf(text, "%s\r\n%s", p, o);
else
- strncpy_s(text, m->GetText(), _TRUNCATE);
+ strncpy_s(text, p, _TRUNCATE);
text[_countof(text) - 1] = '\0';
setUString(hContact, "CompanyStreet", text);
}
else {
- setUString(hContact, "CompanyStreet", m->GetText());
- if ((m = n->FirstChildElement("EXTADR")) == nullptr)
- m = n->FirstChildElement("EXTADD");
- if (m != nullptr && m->GetText() != nullptr) {
+ setUString(hContact, "CompanyStreet", p);
+
+ if (p = XmlGetChildText(n, "EXTADR")) {
+ hasWorkStreet2 = true;
+ setUString(hContact, "CompanyStreet2", p);
+ }
+ else if (p = XmlGetChildText(n, "EXTADD")) {
hasWorkStreet2 = true;
- setUString(hContact, "CompanyStreet2", m->GetText());
+ setUString(hContact, "CompanyStreet2", p);
}
}
}
- if ((m = n->FirstChildElement("LOCALITY")) != nullptr && m->GetText() != nullptr) {
+ if (auto *p = XmlGetChildText(n, "LOCALITY")) {
hasWorkLocality = true;
- setUString(hContact, "CompanyCity", m->GetText());
+ setUString(hContact, "CompanyCity", p);
}
- if ((m = n->FirstChildElement("REGION")) != nullptr && m->GetText() != nullptr) {
+ if (auto *p = XmlGetChildText(n, "REGION")) {
hasWorkRegion = true;
- setUString(hContact, "CompanyState", m->GetText());
+ setUString(hContact, "CompanyState", p);
}
- if ((m = n->FirstChildElement("PCODE")) != nullptr && m->GetText() != nullptr) {
+ if (auto *p = XmlGetChildText(n, "PCODE")) {
hasWorkPcode = true;
- setUString(hContact, "CompanyZIP", m->GetText());
+ setUString(hContact, "CompanyZIP", p);
}
- if ((m = n->FirstChildElement("CTRY")) == nullptr || m->GetText() == nullptr) // Some bad client use <COUNTRY/> instead of <CTRY/>
- m = n->FirstChildElement("COUNTRY");
- if (m != nullptr && m->GetText() != nullptr) {
+ if (auto *p = XmlGetChildText(n, "CTRY")) {
hasWorkCtry = true;
- setUString(hContact, "CompanyCountry", m->GetText());
+ setUString(hContact, "CompanyCountry", p);
}
}
}
else if (!mir_strcmp(n->Name(), "TEL")) {
// Telephone/Fax/Cellular
- if ((m = n->FirstChildElement("NUMBER")) != nullptr && m->GetText() != nullptr) {
+ if (auto *p = XmlGetChildText(n, "NUMBER")) {
if (hContact != 0) {
if (!hasFax && n->FirstChildElement("FAX") != nullptr) {
hasFax = true;
- setUString(hContact, "Fax", m->GetText());
+ setUString(hContact, "Fax", p);
}
else if (!hasCell && n->FirstChildElement("CELL") != nullptr) {
hasCell = true;
- setUString(hContact, "Cellular", m->GetText());
+ setUString(hContact, "Cellular", p);
}
else if (!hasPhone &&
(n->FirstChildElement("HOME") != nullptr || n->FirstChildElement("WORK") != nullptr || n->FirstChildElement("VOICE") != nullptr ||
@@ -923,13 +897,13 @@ void CJabberProto::OnIqResultGetVcard(const TiXmlElement *iqNode, CJabberIqInfo* n->FirstChildElement("PCS") == nullptr)))
{
hasPhone = true;
- setUString(hContact, "Phone", m->GetText());
+ setUString(hContact, "Phone", p);
}
}
else {
char text[100];
mir_snprintf(text, "Phone%d", nPhone);
- setUString(text, m->GetText());
+ setUString(text, p);
mir_snprintf(text, "PhoneFlag%d", nPhone);
int nFlag = 0;
@@ -959,13 +933,13 @@ void CJabberProto::OnIqResultGetVcard(const TiXmlElement *iqNode, CJabberIqInfo* }
else if (!mir_strcmp(n->Name(), "ORG")) {
if (!hasOrgname && !hasOrgunit) {
- if ((m = n->FirstChildElement("ORGNAME")) != nullptr && m->GetText() != nullptr) {
+ if (auto *p = XmlGetChildText(n, "ORGNAME")) {
hasOrgname = true;
- setUString(hContact, "Company", m->GetText());
+ setUString(hContact, "Company", p);
}
- if ((m = n->FirstChildElement("ORGUNIT")) != nullptr && m->GetText() != nullptr) { // The real vCard can have multiple <ORGUNIT/> but we will only display the first one
+ if (auto *p = XmlGetChildText(n, "ORGUNIT")) {
hasOrgunit = true;
- setUString(hContact, "CompanyDepartment", m->GetText());
+ setUString(hContact, "CompanyDepartment", p);
}
}
}
@@ -1152,15 +1126,15 @@ void CJabberProto::OnIqResultSetSearch(const TiXmlElement *iqNode, CJabberIqInfo for (auto *itemNode : TiXmlFilter(queryNode, "item")) {
if (auto *jid = itemNode->Attribute("jid")) {
psr.id.w = mir_utf8decodeW(jid);
- debugLogW(L"Result jid = %s", jid);
- if (auto *p = itemNode->FirstChildElement("nick"))
- psr.nick.w = mir_utf8decodeW(p->GetText());
- if (auto *p = itemNode->FirstChildElement("first"))
- psr.firstName.w = mir_utf8decodeW(p->GetText());
- if (auto *p = itemNode->FirstChildElement("last"))
- psr.lastName.w = mir_utf8decodeW(p->GetText());
- if (auto *p = itemNode->FirstChildElement("email"))
- psr.email.w = mir_utf8decodeW(p->GetText());
+ debugLogA("Result jid = %s", jid);
+ if (auto *p = XmlGetChildText(itemNode, "nick"))
+ psr.nick.w = mir_utf8decodeW(p);
+ if (auto *p = XmlGetChildText(itemNode, "first"))
+ psr.firstName.w = mir_utf8decodeW(p);
+ if (auto *p = XmlGetChildText(itemNode, "last"))
+ psr.lastName.w = mir_utf8decodeW(p);
+ if (auto *p = XmlGetChildText(itemNode, "email"))
+ psr.email.w = mir_utf8decodeW(p);
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)id, (LPARAM)&psr);
replaceStrW(psr.id.w, 0);
@@ -1284,13 +1258,10 @@ void CJabberProto::OnIqResultGetVCardAvatar(const TiXmlElement *iqNode, CJabberI return;
}
- auto *mimeType = vCard->FirstChildElement("TYPE");
- auto *n = vCard->FirstChildElement("BINVAL");
- if (n == nullptr)
- return;
-
- setByte(hContact, "AvatarXVcard", 1);
- OnIqResultGotAvatar(hContact, n, mimeType->GetText());
+ if (auto *pszText = XmlGetChildText(vCard, "BINVAL")) {
+ setByte(hContact, "AvatarXVcard", 1);
+ OnIqResultGotAvatar(hContact, pszText, XmlGetChildText(vCard, "TYPE"));
+ }
}
void CJabberProto::OnIqResultGetClientAvatar(const TiXmlElement *iqNode, CJabberIqInfo*)
@@ -1317,7 +1288,7 @@ void CJabberProto::OnIqResultGetClientAvatar(const TiXmlElement *iqNode, CJabber }
if (n != nullptr) {
- OnIqResultGotAvatar(hContact, n, n->Attribute("mimetype"));
+ OnIqResultGotAvatar(hContact, n->GetText(), n->Attribute("mimetype"));
return;
}
@@ -1357,7 +1328,7 @@ void CJabberProto::OnIqResultGetServerAvatar(const TiXmlElement *iqNode, CJabber }
if (n != nullptr) {
- OnIqResultGotAvatar(hContact, n, n->Attribute("mimetype"));
+ OnIqResultGotAvatar(hContact, n->GetText(), n->Attribute("mimetype"));
return;
}
@@ -1373,10 +1344,10 @@ void CJabberProto::OnIqResultGetServerAvatar(const TiXmlElement *iqNode, CJabber }
-void CJabberProto::OnIqResultGotAvatar(MCONTACT hContact, const TiXmlElement *n, const char *mimeType)
+void CJabberProto::OnIqResultGotAvatar(MCONTACT hContact, const char *pszText, const char *mimeType)
{
size_t resultLen;
- ptrA body((char*)mir_base64_decode(n->GetText(), &resultLen));
+ ptrA body((char*)mir_base64_decode(pszText, &resultLen));
if (body == nullptr)
return;
@@ -1386,7 +1357,7 @@ void CJabberProto::OnIqResultGotAvatar(MCONTACT hContact, const TiXmlElement *n, else
pictureType = ProtoGetBufferFormat(body, nullptr);
if (pictureType == PA_FORMAT_UNKNOWN) {
- debugLogW(L"Invalid mime type specified for picture: %s", mimeType);
+ debugLogA("Invalid mime type specified for picture: %s", mimeType);
return;
}
@@ -1529,10 +1500,7 @@ void CJabberProto::OnIqResultSetBookmarks(const TiXmlElement *iqNode, CJabberIqI UI_SAFE_NOTIFY(m_pDlgBookmarks, WM_JABBER_REFRESH);
}
else if (!mir_strcmp(type, "error")) {
- auto *errorNode = iqNode->FirstChildElement("error");
- wchar_t *str = JabberErrorMsg(errorNode);
- MessageBox(nullptr, str, TranslateT("Jabber Bookmarks Error"), MB_OK | MB_SETFOREGROUND);
- mir_free(str);
+ MessageBox(nullptr, JabberErrorMsg(iqNode), TranslateT("Jabber Bookmarks Error"), MB_OK | MB_SETFOREGROUND);
UI_SAFE_NOTIFY(m_pDlgBookmarks, WM_JABBER_ACTIVATE);
}
}
@@ -1546,16 +1514,14 @@ void CJabberProto::OnIqResultLastActivity(const TiXmlElement *iqNode, CJabberIqI time_t lastActivity = -1;
if (pInfo->m_nIqType == JABBER_IQ_TYPE_RESULT) {
- const char *szSeconds = XPath(iqNode, "query[@xmlns='jabber:iq:last']/@seconds");
- if (szSeconds) {
- int nSeconds = atoi(szSeconds);
+ if (auto *xmlLast = XmlGetChildByTag(iqNode, "query", "xmlns", JABBER_FEAT_LAST_ACTIVITY)) {
+ int nSeconds = XmlGetChildInt(xmlLast, "seconds");
if (nSeconds > 0)
lastActivity = time(0) - nSeconds;
- }
- const char *szLastStatusMessage = XPath(iqNode, "query[@xmlns='jabber:iq:last']");
- if (szLastStatusMessage) // replace only if it exists
- r->m_szStatusMessage = mir_strdup(szLastStatusMessage);
+ if (const char *szLastStatusMessage = xmlLast->GetText())
+ r->m_szStatusMessage = mir_strdup(szLastStatusMessage);
+ }
}
r->m_dwIdleStartTime = lastActivity;
diff --git a/protocols/JabberG/src/jabber_iqid_muc.cpp b/protocols/JabberG/src/jabber_iqid_muc.cpp index ca638e28aa..2043ac4b45 100644 --- a/protocols/JabberG/src/jabber_iqid_muc.cpp +++ b/protocols/JabberG/src/jabber_iqid_muc.cpp @@ -122,9 +122,8 @@ class CJabberMucJidListDlg : public CJabberDlgBase lvi.pszText = (wchar_t*)jid;
if (m_info->type == MUC_BANLIST) {
- auto *reason = itemNode->FirstChildElement("reason");
- if (reason != nullptr) {
- mir_snwprintf(tszItemText, L"%s (%s)", Utf2T(jid).get(), Utf2T(reason->GetText()).get());
+ if (auto *reason = XmlGetChildText(itemNode, "reason")) {
+ mir_snwprintf(tszItemText, L"%s (%s)", Utf2T(jid).get(), Utf2T(reason).get());
lvi.pszText = tszItemText;
}
}
diff --git a/protocols/JabberG/src/jabber_list.cpp b/protocols/JabberG/src/jabber_list.cpp index 214250e1cc..08e7eb0cff 100644 --- a/protocols/JabberG/src/jabber_list.cpp +++ b/protocols/JabberG/src/jabber_list.cpp @@ -261,7 +261,7 @@ pResourceStatus CJabberProto::ListFindResource(JABBER_LIST list, const char *jid return (q == nullptr) ? nullptr : LI->findResource(q + 1);
}
-bool CJabberProto::ListAddResource(JABBER_LIST list, const char *jid, int status, const char *statusMessage, char priority, const char *nick)
+bool CJabberProto::ListAddResource(JABBER_LIST list, const char *jid, int status, const char *statusMessage, int priority, const char *nick)
{
mir_cslockfull lck(m_csLists);
JABBER_LIST_ITEM *LI = ListGetItemPtr(list, jid);
diff --git a/protocols/JabberG/src/jabber_message_handlers.cpp b/protocols/JabberG/src/jabber_message_handlers.cpp index 24b3fa5156..79bfd83f5c 100644 --- a/protocols/JabberG/src/jabber_message_handlers.cpp +++ b/protocols/JabberG/src/jabber_message_handlers.cpp @@ -34,16 +34,16 @@ BOOL CJabberProto::OnMessageError(const TiXmlElement *node, ThreadData*, CJabber if (item == nullptr)
item = ListGetItemPtr(LIST_CHATROOM, pInfo->GetFrom());
if (item != nullptr) { // yes, it is
- ptrW szErrText(JabberErrorMsg(pInfo->GetChildNode()));
+ CMStringW szErrText(JabberErrorMsg(pInfo->GetChildNode()));
if (id != -1)
- ProtoBroadcastAck(pInfo->GetHContact(), ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)id, szErrText);
+ ProtoBroadcastAck(pInfo->GetHContact(), ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)id, (LPARAM)szErrText.c_str());
else {
wchar_t buf[512];
- auto *bodyNode = node->FirstChildElement("body");
- if (bodyNode)
- mir_snwprintf(buf, L"%s:\n%s\n%s", pInfo->GetFrom(), bodyNode->GetText(), szErrText);
+ auto *body = XmlGetChildText(node, "body");
+ if (body)
+ mir_snwprintf(buf, L"%s:\n%s\n%s", pInfo->GetFrom(), body, szErrText.c_str());
else
- mir_snwprintf(buf, L"%s:\n%s", pInfo->GetFrom(), szErrText);
+ mir_snwprintf(buf, L"%s:\n%s", pInfo->GetFrom(), szErrText.c_str());
MsgPopup(0, buf, TranslateT("Jabber Error"));
}
diff --git a/protocols/JabberG/src/jabber_message_manager.cpp b/protocols/JabberG/src/jabber_message_manager.cpp index 78bba000a1..486a7b49d6 100644 --- a/protocols/JabberG/src/jabber_message_manager.cpp +++ b/protocols/JabberG/src/jabber_message_manager.cpp @@ -96,7 +96,7 @@ bool CJabberMessageManager::HandleMessagePermanent(const TiXmlElement *node, Thr messageInfo.m_hContact = ppro->HContactFromJID(messageInfo.m_szFrom);
if (messageInfo.m_szFrom)
- ppro->debugLogW(L"Handling message from %s", messageInfo.m_szFrom);
+ ppro->debugLogA("Handling message from %s", messageInfo.m_szFrom);
if ((ppro->*(it->m_pHandler))(node, pThreadData, &messageInfo))
return true;
}
diff --git a/protocols/JabberG/src/jabber_misc.cpp b/protocols/JabberG/src/jabber_misc.cpp index 490fbd7c35..423e65516b 100755 --- a/protocols/JabberG/src/jabber_misc.cpp +++ b/protocols/JabberG/src/jabber_misc.cpp @@ -93,7 +93,7 @@ MCONTACT CJabberProto::DBCreateContact(const char *jid, const char *nick, bool t if (JABBER_LIST_ITEM *pItem = ListAdd(LIST_ROSTER, jid, hNewContact))
pItem->bUseResource = strchr(szJid, '/') != nullptr;
- debugLogW(L"Create Jabber contact jid=%s, nick=%s", szJid, nick);
+ debugLogA("Create Jabber contact jid=%s, nick=%s", szJid, nick);
DBCheckIsTransportedContact(szJid, hNewContact);
return hNewContact;
}
@@ -276,7 +276,7 @@ void CJabberProto::UpdateMirVer(JABBER_LIST_ITEM *item) if (!hContact)
return;
- debugLogW(L"JabberUpdateMirVer: for jid %s", item->jid);
+ debugLogA("JabberUpdateMirVer: for jid %s", item->jid);
if (item->resourceMode == RSMODE_LASTSEEN)
UpdateMirVer(hContact, pResourceStatus(item->m_pLastSeenResource));
diff --git a/protocols/JabberG/src/jabber_omemo.cpp b/protocols/JabberG/src/jabber_omemo.cpp index 0b363fe938..61834f80e5 100755 --- a/protocols/JabberG/src/jabber_omemo.cpp +++ b/protocols/JabberG/src/jabber_omemo.cpp @@ -1496,8 +1496,8 @@ bool CJabberProto::OmemoHandleMessage(const TiXmlElement *node, const char *jid, 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
}
- const char *payload_base64w = payload_node->GetText();
- if (!payload_base64w) {
+ const char *payload_base64 = payload_node->GetText();
+ if (!payload_base64) {
debugLogA("Jabber OMEMO: error: failed to get payload data");
return true; //this should never happen
}
@@ -1640,7 +1640,7 @@ bool CJabberProto::OmemoHandleMessage(const TiXmlElement *node, const char *jid, int dec_success = 0;
size_t payload_len = 0;
int outl = 0, round_len = 0, tag_len = 0;
- unsigned char *payload = (unsigned char*)mir_base64_decode(payload_base64w, &payload_len);
+ unsigned char *payload = (unsigned char*)mir_base64_decode(payload_base64, &payload_len);
out = (char*)mir_alloc(payload_len + 32); //TODO: check this
unsigned char key[16], *tag;
{
diff --git a/protocols/JabberG/src/jabber_opt.cpp b/protocols/JabberG/src/jabber_opt.cpp index 05fddd6d2f..598f4c7867 100755 --- a/protocols/JabberG/src/jabber_opt.cpp +++ b/protocols/JabberG/src/jabber_opt.cpp @@ -1006,8 +1006,8 @@ void CJabberProto::_RosterHandleGetRequest(const TiXmlElement *node, CJabberIqIn const char *name = item->Attribute("name");
const char *subscription = item->Attribute("subscription");
- auto *group = item->FirstChildElement("group");
- _RosterInsertListItem(hList, jid, name, (group) ? group->GetText() : 0, subscription, TRUE);
+ const char *group = XmlGetChildText(item, "group");
+ _RosterInsertListItem(hList, jid, name, group, subscription, TRUE);
}
// now it is require to process whole contact list to add not in roster contacts
@@ -1080,8 +1080,8 @@ void CJabberProto::_RosterHandleGetRequest(const TiXmlElement *node, CJabberIqIn bPushed = TRUE;
}
if (!bPushed) {
- auto *rosterGroup = itemRoster->FirstChildElement("group");
- if ((rosterGroup != nullptr || group[0] != 0) && mir_strcmpi(rosterGroup->GetText(), szGroup))
+ auto *rosterGroup = XmlGetChildText(itemRoster, "group");
+ if (rosterGroup != nullptr && mir_strcmpi(rosterGroup, szGroup))
bPushed = TRUE;
}
}
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index b027388a67..7abe66e602 100755 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -356,7 +356,7 @@ void CJabberProto::OnShutdown() MCONTACT CJabberProto::AddToListByJID(const char *newJid, DWORD flags)
{
- debugLogW(L"AddToListByJID jid = %s", newJid);
+ debugLogA("AddToListByJID jid = %s", newJid);
MCONTACT hContact = DBCreateContact(newJid, nullptr, true, false);
if (flags & PALF_TEMPORARY)
@@ -422,7 +422,7 @@ int CJabberProto::Authorize(MEVENT hDbEvent) if (m_bAutoAdd) {
JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, blob.get_email());
if (item == nullptr || (item->subscription != SUB_BOTH && item->subscription != SUB_TO)) {
- debugLogW(L"Try adding contact automatically jid = %s", blob.get_email());
+ debugLogA("Try adding contact automatically jid = %s", blob.get_email());
if (MCONTACT hContact = AddToListByJID(blob.get_email(), 0)) {
// Trigger actual add by removing the "NotOnList" added by AddToListByJID()
// See AddToListByJID() and JabberDbSettingChanged().
@@ -698,7 +698,7 @@ void __cdecl CJabberProto::BasicSearchThread(JABBER_SEARCH_BASIC *jsb) HANDLE CJabberProto::SearchBasic(const wchar_t *szJid)
{
- debugLogW(L"JabberBasicSearch called with lParam = '%s'", szJid);
+ debugLogA("JabberBasicSearch called with lParam = '%s'", szJid);
JABBER_SEARCH_BASIC *jsb;
if (!m_bJabberOnline || (jsb = (JABBER_SEARCH_BASIC*)mir_alloc(sizeof(JABBER_SEARCH_BASIC))) == nullptr)
@@ -727,7 +727,7 @@ HANDLE CJabberProto::SearchBasic(const wchar_t *szJid) }
else wcsncpy_s(jsb->jid, szJid, _TRUNCATE);
- debugLogW(L"Adding '%s' without validation", jsb->jid);
+ debugLogA("Adding '%s' without validation", jsb->jid);
jsb->hSearch = SerialNext();
ForkThread((MyThreadFunc)&CJabberProto::BasicSearchThread, jsb);
return (HANDLE)jsb->hSearch;
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index 9860c6e580..cce4482df5 100755 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -516,7 +516,7 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface void OnIqResultGetVCardAvatar(const TiXmlElement *iqNode, CJabberIqInfo *pInfo);
void OnIqResultGetClientAvatar(const TiXmlElement *iqNode, CJabberIqInfo *pInfo);
void OnIqResultGetServerAvatar(const TiXmlElement *iqNode, CJabberIqInfo *pInfo);
- void OnIqResultGotAvatar(MCONTACT hContact, const TiXmlElement *n, const char *mimeType);
+ void OnIqResultGotAvatar(MCONTACT hContact, const char *pszText, const char *mimeType);
void OnIqResultGetMuc(const TiXmlElement *iqNode, CJabberIqInfo *pInfo);
void OnIqResultGetRegister(const TiXmlElement *iqNode, CJabberIqInfo *pInfo);
void OnIqResultGetRoster(const TiXmlElement *iqNode, CJabberIqInfo *pInfo);
@@ -606,9 +606,9 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface pResourceStatus ListFindResource(JABBER_LIST list, const char *jid);
- bool ListAddResource(JABBER_LIST list, const char *jid, int status, const char *statusMessage, char priority = 0, const char *nick = nullptr);
+ bool ListAddResource(JABBER_LIST list, const char *jid, int status, const char *statusMessage, int priority = 0, const char *nick = nullptr);
void ListRemoveResource(JABBER_LIST list, const char *jid);
- char* ListGetBestClientResourceNamePtr(const char *jid);
+ char* ListGetBestClientResourceNamePtr(const char *jid);
void OnIqResultServerDiscoInfo(const TiXmlElement *iqNode, CJabberIqInfo *pInfo);
void OnIqResultGetVcardPhoto(const TiXmlElement *n, MCONTACT hContact, bool &hasPhoto);
diff --git a/protocols/JabberG/src/jabber_rc.cpp b/protocols/JabberG/src/jabber_rc.cpp index 272f5b7c06..a3e1646f1c 100644 --- a/protocols/JabberG/src/jabber_rc.cpp +++ b/protocols/JabberG/src/jabber_rc.cpp @@ -360,9 +360,7 @@ int CJabberProto::AdhocSetStatusHandler(const TiXmlElement*, CJabberIqInfo *pInf int priority = -9999;
if (fieldNode = XmlGetChildByTag(xNode, "field", "var", "status-priority"))
- if (auto *valueNode = fieldNode->FirstChildElement("value"))
- if (pszValue = valueNode->GetText())
- priority = atoi(pszValue);
+ priority = XmlGetChildInt(fieldNode, "value");
if (priority >= -128 && priority <= 127)
setDword("Priority", priority);
@@ -378,12 +376,12 @@ int CJabberProto::AdhocSetStatusHandler(const TiXmlElement*, CJabberIqInfo *pInf db_set_utf(0, "SRAway", StatusModeToDbSetting(status, "Msg"), szStatusMessage ? szStatusMessage : "");
- if (fieldNode = XmlGetChildByTag(xNode, "field", "var", "status-global"))
- if (auto *valueNode = fieldNode->FirstChildElement("value"))
- if ((pszValue = valueNode->GetText()) != nullptr && atoi(pszValue))
- Clist_SetStatusMode(status);
- else
- CallProtoService(m_szModuleName, PS_SETSTATUS, status, 0);
+ if (fieldNode = XmlGetChildByTag(xNode, "field", "var", "status-global")) {
+ if (XmlGetChildInt(fieldNode, "value") > 0)
+ Clist_SetStatusMode(status);
+ else
+ CallProtoService(m_szModuleName, PS_SETSTATUS, status, 0);
+ }
SetAwayMsg(status, Utf2T(szStatusMessage));
@@ -441,21 +439,15 @@ int CJabberProto::AdhocOptionsHandler(const TiXmlElement*, CJabberIqInfo *pInfo, // Automatically Accept File Transfers
if (auto *fieldNode = XmlGetChildByTag(xNode, "field", "var", "auto-files"))
- if (auto *valueNode = fieldNode->FirstChildElement("value"))
- if (valueNode->GetText())
- db_set_b(0, "SRFile", "AutoAccept", (BYTE)atoi(valueNode->GetText()));
+ db_set_b(0, "SRFile", "AutoAccept", XmlGetChildInt(fieldNode, "value"));
// Use sounds
if (auto *fieldNode = XmlGetChildByTag(xNode, "field", "var", "sounds"))
- if (auto *valueNode = fieldNode->FirstChildElement("value"))
- if (valueNode->GetText())
- db_set_b(0, "Skin", "UseSound", (BYTE)atoi(valueNode->GetText()));
+ db_set_b(0, "Skin", "UseSound", XmlGetChildInt(fieldNode, "value"));
// Disable remote controlling
if (auto *fieldNode = XmlGetChildByTag(xNode, "field", "var", "enable-rc"))
- if (auto *valueNode = fieldNode->FirstChildElement("value"))
- if (valueNode->GetText() && atoi(valueNode->GetText()))
- m_bEnableRemoteControl = 0;
+ m_bEnableRemoteControl = XmlGetChildInt(fieldNode, "value");
return JABBER_ADHOC_HANDLER_STATUS_COMPLETED;
}
@@ -540,10 +532,8 @@ int CJabberProto::AdhocForwardHandler(const TiXmlElement*, CJabberIqInfo *pInfo, BOOL bRemoveCListEvents = TRUE;
// remove clist events
- auto *fieldNode = XmlGetChildByTag(xNode, "field", "var", "remove-clist-events");
- if (auto *valueNode = fieldNode->FirstChildElement("value"))
- if (valueNode->GetText() && !atoi(valueNode->GetText()))
- bRemoveCListEvents = FALSE;
+ if (auto *fieldNode = XmlGetChildByTag(xNode, "field", "var", "remove-clist-events"))
+ bRemoveCListEvents = XmlGetChildInt(fieldNode, "value");
m_bRcMarkMessagesAsRead = bRemoveCListEvents ? 1 : 0;
@@ -675,9 +665,8 @@ int CJabberProto::AdhocQuitMirandaHandler(const TiXmlElement*, CJabberIqInfo *pI return JABBER_ADHOC_HANDLER_STATUS_CANCEL;
// I Agree checkbox
- auto *fieldNode = XmlGetChildByTag(xNode, "field", "var", "allow-shutdown");
- if (auto *valueNode = fieldNode->FirstChildElement("value"))
- if (valueNode->GetText() && atoi(valueNode->GetText()))
+ if (auto *fieldNode = XmlGetChildByTag(xNode, "field", "var", "allow-shutdown"))
+ if (XmlGetChildInt(fieldNode, "value"))
CallFunctionAsync(JabberQuitMirandaIMThread, nullptr);
return JABBER_ADHOC_HANDLER_STATUS_COMPLETED;
diff --git a/protocols/JabberG/src/jabber_strm_mgmt.cpp b/protocols/JabberG/src/jabber_strm_mgmt.cpp index 0d75f9e8fd..9a61f66c63 100755 --- a/protocols/JabberG/src/jabber_strm_mgmt.cpp +++ b/protocols/JabberG/src/jabber_strm_mgmt.cpp @@ -50,11 +50,14 @@ void strm_mgmt::OnProcessResumed(const TiXmlElement *node, ThreadData * /*info*/ {
if (mir_strcmp(node->Attribute("xmlns"), "urn:xmpp:sm:3"))
return;
+
auto *var = node->Attribute("previd");
if (!var)
return;
+
if (m_sStrmMgmtResumeId != var)
return; //TODO: unknown session, what we should do ?
+
var = node->Attribute("h");
if (!var)
return;
@@ -145,7 +148,7 @@ void strm_mgmt::OnProcessFailed(const TiXmlElement *node, ThreadData * info) //u if (mir_strcmp(node->Attribute("xmlns"), "urn:xmpp:sm:3"))
return;
- proto->debugLogW(L"strm_mgmt: error: Failed to resume session %s", m_sStrmMgmtResumeId.c_str());
+ proto->debugLogA("strm_mgmt: error: Failed to resume session %s", m_sStrmMgmtResumeId.c_str());
m_bStrmMgmtEnabled = false;
bSessionResumed = false;
diff --git a/protocols/JabberG/src/jabber_svc.cpp b/protocols/JabberG/src/jabber_svc.cpp index b10b80159e..b6415a2c7e 100644 --- a/protocols/JabberG/src/jabber_svc.cpp +++ b/protocols/JabberG/src/jabber_svc.cpp @@ -154,7 +154,7 @@ INT_PTR __cdecl CJabberProto::JabberGetAvatarInfo(WPARAM wParam, LPARAM lParam) if (szJid[0] == 0)
strncpy_s(szJid, tszJid, _TRUNCATE);
- debugLogW(L"Rereading %s for %s", isXVcard ? JABBER_FEAT_VCARD_TEMP : JABBER_FEAT_AVATAR, szJid);
+ debugLogA("Rereading %s for %s", isXVcard ? JABBER_FEAT_VCARD_TEMP : JABBER_FEAT_AVATAR, szJid);
m_ThreadInfo->send((isXVcard) ?
XmlNodeIq(AddIQ(&CJabberProto::OnIqResultGetVCardAvatar, JABBER_IQ_TYPE_GET, szJid)) << XCHILDNS("vCard", JABBER_FEAT_VCARD_TEMP) :
diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index 14c000367e..c274eb8003 100755 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -833,13 +833,13 @@ void CJabberProto::OnProcessSuccess(const TiXmlElement *node, ThreadData *info) }
debugLogA("Success: Logged-in.");
- ptrA tszNick(getUStringA("Nick"));
- if (tszNick == nullptr)
+ ptrA szNick(getUStringA("Nick"));
+ if (szNick == nullptr)
setUString("Nick", info->conn.username);
xmlStreamInitialize("after successful sasl");
}
- else debugLogW(L"Success: unknown action %s.", type);
+ else debugLogA("Success: unknown action %s.", type);
}
void CJabberProto::OnProcessChallenge(const TiXmlElement *node, ThreadData *info)
@@ -982,19 +982,16 @@ void CJabberProto::OnProcessPubsubEvent(const TiXmlElement *node) return;
const char *szArtist = XPath(tuneNode, "artist");
- const char *szLength = XPath(tuneNode, "length");
const char *szSource = XPath(tuneNode, "source");
const char *szTitle = XPath(tuneNode, "title");
const char *szTrack = XPath(tuneNode, "track");
- wchar_t szLengthInTime[32];
- szLengthInTime[0] = 0;
- if (szLength) {
- int nLength = atoi(szLength);
+ wchar_t szLengthInTime[20];
+ int nLength = XmlGetChildInt(tuneNode, "length");
+ if (nLength > 0)
mir_snwprintf(szLengthInTime, L"%02d:%02d:%02d", nLength / 3600, (nLength / 60) % 60, nLength % 60);
- }
- SetContactTune(hContact, Utf2T(szArtist), szLength ? szLengthInTime : nullptr, Utf2T(szSource), Utf2T(szTitle), Utf2T(szTrack));
+ SetContactTune(hContact, Utf2T(szArtist), nLength ? szLengthInTime : nullptr, Utf2T(szSource), Utf2T(szTitle), Utf2T(szTrack));
}
}
@@ -1119,10 +1116,10 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) if (bodyNode == nullptr)
bodyNode = node->FirstChildElement("body");
- auto *subject = node->FirstChildElement("subject");
- if (subject && subject->GetText()) {
+ auto *subject = XmlGetChildText(node, "subject");
+ if (subject) {
szMessage.Append("Subject: ");
- szMessage.Append(subject->GetText());
+ szMessage.Append(subject);
szMessage.Append("\r\n");
}
@@ -1220,9 +1217,7 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) memset(pParams, 0, sizeof(CJabberHttpAuthParams));
pParams->m_nType = CJabberHttpAuthParams::MSG;
pParams->m_szFrom = mir_strdup(from);
- auto *threadNode = node->FirstChildElement("thread");
- if (threadNode)
- pParams->m_szThreadId = mir_strdup(threadNode->GetText());
+ pParams->m_szThreadId = mir_strdup(XmlGetChildText(node, "thread"));
pParams->m_szId = mir_strdup(szId);
pParams->m_szMethod = mir_strdup(szMethod);
pParams->m_szUrl = mir_strdup(szUrl);
@@ -1329,25 +1324,23 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) }
}
else if (!mir_strcmp(pszXmlns, JABBER_FEAT_OOB2)) {
- auto *url = xNode->FirstChildElement("url");
- if (url != nullptr && url->GetText()) {
+ auto *url = XmlGetChildText(xNode, "url");
+ if (url != nullptr) {
if (!szMessage.IsEmpty())
szMessage.Append("\r\n");
- szMessage.Append(url->GetText());
+ szMessage.Append(url);
}
}
else if (!mir_strcmp(pszXmlns, JABBER_FEAT_MUC_USER)) {
auto *inviteNode = xNode->FirstChildElement("invite");
if (inviteNode != nullptr) {
inviteFromJid = inviteNode->Attribute("from");
- if (auto *reasonNode = inviteNode->FirstChildElement("reason"))
- inviteReason = reasonNode->GetText();
+ inviteReason = XmlGetChildText(inviteNode, "reason");
inviteRoomJid = from;
if (inviteReason == nullptr)
inviteReason = szMessage;
isChatRoomInvitation = true;
- if (auto *n = xNode->FirstChildElement("password"))
- invitePassword = n->GetText();
+ invitePassword = XmlGetChildText(xNode, "password");
}
}
else if (!mir_strcmp(pszXmlns, JABBER_FEAT_ROSTER_EXCHANGE) && item != nullptr && (item->subscription == SUB_BOTH || item->subscription == SUB_TO)) {
@@ -1357,12 +1350,12 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) const char *action = iNode->Attribute("action");
const char *jid = iNode->Attribute("jid");
const char *nick = iNode->Attribute("name");
- auto *group = iNode->FirstChildElement("group");
+ auto *group = XmlGetChildText(iNode, "group");
if (action && jid && strstr(jid, chkJID)) {
if (!mir_strcmp(action, "add")) {
MCONTACT cc = DBCreateContact(jid, nick, false, false);
- if (group && group->GetText())
- db_set_utf(cc, "CList", "Group", group->GetText());
+ if (group)
+ db_set_utf(cc, "CList", "Group", group);
}
else if (!mir_strcmp(action, "delete")) {
MCONTACT cc = HContactFromJID(jid);
@@ -1539,7 +1532,7 @@ void CJabberProto::UpdateJidDbSettings(const char *jid) item->getTemp()->m_iStatus = status;
if (nSelectedResource != -1) {
pResourceStatus r(item->arResources[nSelectedResource]);
- debugLogW(L"JabberUpdateJidDbSettings: updating jid %s to rc %s", item->jid, r->m_szResourceName);
+ debugLogA("JabberUpdateJidDbSettings: updating jid %s to rc %s", item->jid, r->m_szResourceName);
if (r->m_szStatusMessage)
db_set_utf(hContact, "CList", "StatusMsg", r->m_szStatusMessage);
else
@@ -1597,35 +1590,26 @@ void CJabberProto::OnProcessPresence(const TiXmlElement *node, ThreadData *info) if ((hContact = HContactFromJID(from)) == 0) {
if (!mir_strcmpi(info->fullJID, from) || (!bSelfPresence && !ListGetItemPtr(LIST_ROSTER, from))) {
- debugLogW(L"SKIP Receive presence online from %s (who is not in my roster and not in list - skiping)", from);
+ debugLogA("SKIP Receive presence online from %s (who is not in my roster and not in list - skipping)", from);
return;
}
hContact = DBCreateContact(from, nick, true, true);
}
if (!ListGetItemPtr(LIST_ROSTER, from)) {
- debugLogW(L"Receive presence online from %s (who is not in my roster)", from);
+ debugLogA("Receive presence online from %s (who is not in my roster)", from);
ListAdd(LIST_ROSTER, from, hContact);
}
DBCheckIsTransportedContact(from, hContact);
int status = ID_STATUS_ONLINE;
- if (auto *showNode = node->FirstChildElement("show")) {
- if (const char *show = showNode->GetText()) {
- if (!mir_strcmp(show, "away")) status = ID_STATUS_AWAY;
- else if (!mir_strcmp(show, "xa")) status = ID_STATUS_NA;
- else if (!mir_strcmp(show, "dnd")) status = ID_STATUS_DND;
- else if (!mir_strcmp(show, "chat")) status = ID_STATUS_FREECHAT;
- }
+ if (auto *show = XmlGetChildText(node, "show")) {
+ if (!mir_strcmp(show, "away")) status = ID_STATUS_AWAY;
+ else if (!mir_strcmp(show, "xa")) status = ID_STATUS_NA;
+ else if (!mir_strcmp(show, "dnd")) status = ID_STATUS_DND;
+ else if (!mir_strcmp(show, "chat")) status = ID_STATUS_FREECHAT;
}
- int priority = 0;
- if (auto *n = node->FirstChildElement("priority"))
- if (n->GetText())
- priority = atoi(n->GetText());
-
- const char *pszStatus = nullptr;
- if (auto *n = node->FirstChildElement("status"))
- pszStatus = n->GetText();
-
+ int priority = XmlGetChildInt(node, "priority");
+ const char *pszStatus = XmlGetChildText(node, "status");
ListAddResource(LIST_ROSTER, from, status, pszStatus, priority);
// XEP-0115: Entity Capabilities
@@ -1638,7 +1622,7 @@ void CJabberProto::OnProcessPresence(const TiXmlElement *node, ThreadData *info) if (strchr(from, '@') == nullptr) {
UI_SAFE_NOTIFY(m_pDlgServiceDiscovery, WM_JABBER_TRANSPORT_REFRESH);
}
- debugLogW(L"%s (%s) online, set contact status to %s", nick, from, Clist_GetStatusModeDescription(status, 0));
+ debugLogA("%s (%s) online, set contact status to %S", nick, from, Clist_GetStatusModeDescription(status, 0));
if (m_bEnableAvatars) {
bool bHasAvatar = false, bRemovedAvatar = false;
@@ -1646,14 +1630,14 @@ 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")) {
- auto *xmlHash = xNode->FirstChildElement("hash");
- if (xmlHash != nullptr && xmlHash->GetText()) {
+ auto *szHash = XmlGetChildText(xNode, "hash");
+ if (szHash != nullptr) {
delSetting(hContact, "AvatarXVcard");
debugLogA("AvatarXVcard deleted");
- setString(hContact, "AvatarHash", xmlHash->GetText());
+ setString(hContact, "AvatarHash", szHash);
bHasAvatar = true;
ptrA saved(getStringA(hContact, "AvatarSaved"));
- if (saved == nullptr || mir_strcmp(saved, xmlHash->GetText())) {
+ if (saved == nullptr || mir_strcmp(saved, szHash)) {
debugLogA("Avatar was changed");
ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, nullptr, 0);
}
@@ -1661,16 +1645,15 @@ void CJabberProto::OnProcessPresence(const TiXmlElement *node, ThreadData *info) else bRemovedAvatar = true;
}
else if (!mir_strcmp(xNode->Attribute("xmlns"), "vcard-temp:x:update")) {
- auto *xPhoto = xNode->FirstChildElement("photo");
- if (xPhoto && !bHasAvatar) {
- const char *txt = xPhoto->GetText();
- if (mir_strlen(txt)) {
+ auto *szPhoto = XmlGetChildText(xNode, "photo");
+ if (szPhoto && !bHasAvatar) {
+ if (mir_strlen(szPhoto)) {
setByte(hContact, "AvatarXVcard", 1);
debugLogA("AvatarXVcard set");
- setString(hContact, "AvatarHash", txt);
+ setString(hContact, "AvatarHash", szPhoto);
bHasAvatar = true;
ptrA saved(getStringA(hContact, "AvatarSaved"));
- if (saved == nullptr || mir_strcmp(saved, txt)) {
+ if (saved == nullptr || mir_strcmp(saved, szPhoto)) {
debugLogA("Avatar was changed. Using vcard-temp:x:update");
ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, nullptr, 0);
}
@@ -1716,15 +1699,13 @@ void CJabberProto::OnProcessPresence(const TiXmlElement *node, ThreadData *info) ListRemoveResource(LIST_ROSTER, info->fullJID);
}
-
// set status only if no more available resources
if (!item->arResources.getCount()) {
item->getTemp()->m_iStatus = ID_STATUS_OFFLINE;
- if (auto *n = node->FirstChildElement("status"))
- item->getTemp()->m_szStatusMessage = mir_strdup(n->GetText());
+ item->getTemp()->m_szStatusMessage = mir_strdup(XmlGetChildText(node, "status"));
}
}
- else debugLogW(L"SKIP Receive presence offline from %s (who is not in my roster)", from);
+ else debugLogA("SKIP Receive presence offline from %s (who is not in my roster)", from);
UpdateJidDbSettings(from);
@@ -1739,13 +1720,13 @@ void CJabberProto::OnProcessPresence(const TiXmlElement *node, ThreadData *info) if (hContact = HContactFromJID(from))
AddDbPresenceEvent(hContact, JABBER_DB_EVENT_PRESENCE_SUBSCRIBE);
- ptrA tszNick(JabberNickFromJID(from));
+ ptrA szNick(JabberNickFromJID(from));
auto *xNick = XmlGetChildByTag(node, "nick", "xmlns", JABBER_FEAT_NICK);
if (xNick != nullptr) {
const char *xszNick = xNick->GetText();
if (xszNick != nullptr && *xszNick) {
debugLogA("Grabbed nick from presence: %s", xszNick);
- tszNick = mir_strdup(xszNick);
+ szNick = mir_strdup(xszNick);
}
}
@@ -1757,11 +1738,11 @@ void CJabberProto::OnProcessPresence(const TiXmlElement *node, ThreadData *info) if (m_bAutoAdd == TRUE) {
JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, from);
if (item == nullptr || (item->subscription != SUB_BOTH && item->subscription != SUB_TO)) {
- debugLogW(L"Try adding contact automatically jid = %s", from);
+ debugLogA("Try adding contact automatically jid = %s", from);
if ((hContact = AddToListByJID(from, 0)) != 0) {
if (item)
item->hContact = hContact;
- setUString(hContact, "Nick", tszNick);
+ setUString(hContact, "Nick", szNick);
db_unset(hContact, "CList", "NotOnList");
}
}
@@ -1769,8 +1750,8 @@ void CJabberProto::OnProcessPresence(const TiXmlElement *node, ThreadData *info) RebuildInfoFrame();
}
else {
- debugLogW(L"%s (%s) requests authorization", tszNick, from);
- DBAddAuthRequest(from, tszNick);
+ debugLogA("%s (%s) requests authorization", szNick, from);
+ DBAddAuthRequest(from, szNick);
}
return;
}
@@ -1964,9 +1945,7 @@ void CJabberProto::OnProcessRegIq(const TiXmlElement *node, ThreadData *info) }
}
else if (!mir_strcmp(type, "error")) {
- wchar_t *str = JabberErrorMsg(node->FirstChildElement("error"));
- SendMessage(info->conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)str);
- mir_free(str);
+ SendMessage(info->conn.reg_hwndDlg, WM_JABBER_REGDLG_UPDATE, 100, (LPARAM)JabberErrorMsg(node).c_str());
info->reg_done = TRUE;
info->send("</stream:stream>");
}
@@ -2100,7 +2079,7 @@ int ThreadData::send_no_strm_mgmt(TiXmlElement *node) // strip forbidden control characters from outgoing XML stream
char *q = buf.GetBuffer();
for (char *p = buf.GetBuffer(); *p; ++p) {
- int c = *p;
+ int c = *(BYTE*)p;
if (c < 32 && c != '\t' && c != '\n' && c != '\r')
continue;
diff --git a/protocols/JabberG/src/jabber_userinfo.cpp b/protocols/JabberG/src/jabber_userinfo.cpp index 42c1751921..6e024052b8 100755 --- a/protocols/JabberG/src/jabber_userinfo.cpp +++ b/protocols/JabberG/src/jabber_userinfo.cpp @@ -649,7 +649,7 @@ static INT_PTR CALLBACK JabberUserPhotoDlgProc(HWND hwndDlg, UINT msg, WPARAM wP item = photoInfo->ppro->ListGetItemPtr(LIST_ROSTER, jid); if (item != nullptr) { if (item->photoFileName) { - photoInfo->ppro->debugLogW(L"Showing picture from %s", item->photoFileName); + photoInfo->ppro->debugLogA("Showing picture from %s", item->photoFileName); photoInfo->hBitmap = Bitmap_Load(Utf2T(item->photoFileName)); FreeImage_Premultiply(photoInfo->hBitmap); ShowWindow(GetDlgItem(hwndDlg, IDC_SAVE), SW_SHOW); diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp index b19fe77437..dceac9a0db 100755 --- a/protocols/JabberG/src/jabber_util.cpp +++ b/protocols/JabberG/src/jabber_util.cpp @@ -244,22 +244,24 @@ wchar_t* JabberErrorStr(int errorCode) return JabberErrorCodeToStrMapping[i].str;
}
-wchar_t* JabberErrorMsg(const TiXmlElement *errorNode, int* pErrorCode)
+CMStringW JabberErrorMsg(const TiXmlElement *errorNode, int *pErrorCode)
{
- wchar_t *errorStr = (wchar_t*)mir_alloc(256 * sizeof(wchar_t));
+ CMStringW ret;
if (errorNode == nullptr) {
if (pErrorCode)
*pErrorCode = -1;
- mir_snwprintf(errorStr, 256, L"%s -1: %s", TranslateT("Error"), TranslateT("Unknown error message"));
- return errorStr;
+ ret.Format(L"%s -1: %s", TranslateT("Error"), TranslateT("Unknown error message"));
+ return ret;
}
+ if (auto *pChild = errorNode->FirstChildElement("error"))
+ errorNode = pChild;
+
int errorCode = errorNode->IntAttribute("code");
- auto *str = errorNode->GetText();
+ const char *str = errorNode->GetText();
if (str == nullptr)
- if (auto *n = errorNode->FirstChildElement("text"))
- str = n->GetText();
+ str = XmlGetChildText(errorNode, "text");
if (str == nullptr) {
for (auto *c : TiXmlEnum(errorNode)) {
@@ -272,13 +274,13 @@ wchar_t* JabberErrorMsg(const TiXmlElement *errorNode, int* pErrorCode) }
if (str != nullptr)
- mir_snwprintf(errorStr, 256, L"%s %d: %s\r\n%s", TranslateT("Error"), errorCode, TranslateW(JabberErrorStr(errorCode)), Utf2T(str).get());
+ ret.Format(L"%s %d: %s\r\n%s", TranslateT("Error"), errorCode, TranslateW(JabberErrorStr(errorCode)), Utf2T(str).get());
else
- mir_snwprintf(errorStr, 256, L"%s %d: %s", TranslateT("Error"), errorCode, TranslateW(JabberErrorStr(errorCode)));
+ ret.Format(L"%s %d: %s", TranslateT("Error"), errorCode, TranslateW(JabberErrorStr(errorCode)));
if (pErrorCode)
*pErrorCode = errorCode;
- return errorStr;
+ return ret;
}
void CJabberProto::SendVisibleInvisiblePresence(bool invisible)
@@ -930,6 +932,12 @@ void SetDlgItemTextUtf(HWND hwndDlg, int ctrlId, const char *szValue) SetDlgItemTextW(hwndDlg, ctrlId, Utf2T(szValue));
}
+void SetWindowTextUtf(HWND hwndDlg, const char *szValue)
+{
+ if (szValue)
+ SetWindowTextW(hwndDlg, Utf2T(szValue));
+}
+
int UIEmulateBtnClick(HWND hwndDlg, UINT idcButton)
{
if (IsWindowEnabled(GetDlgItem(hwndDlg, idcButton)))
diff --git a/protocols/JabberG/src/jabber_xml.cpp b/protocols/JabberG/src/jabber_xml.cpp index def4bf2463..89f39e567d 100644 --- a/protocols/JabberG/src/jabber_xml.cpp +++ b/protocols/JabberG/src/jabber_xml.cpp @@ -163,6 +163,24 @@ TiXmlElement* XmlAddChild(TiXmlElement *hXml, const char *name, int value) /////////////////////////////////////////////////////////////////////////////////////////
+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)
{
if (hXml == nullptr)
diff --git a/protocols/JabberG/src/jabber_xml.h b/protocols/JabberG/src/jabber_xml.h index c194307efd..60f4530f70 100644 --- a/protocols/JabberG/src/jabber_xml.h +++ b/protocols/JabberG/src/jabber_xml.h @@ -32,15 +32,13 @@ TiXmlElement* XmlAddChild(TiXmlElement*, const char *pszName); TiXmlElement* XmlAddChild(TiXmlElement*, const char *pszName, const char *ptszValue);
TiXmlElement* XmlAddChild(TiXmlElement*, const char *pszName, int iValue);
-const TiXmlElement* XmlGetChildByTag(const TiXmlElement*, const char *key, const char *attrName, const char *attrValue);
+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);
-int XmlGetAttrCount(TiXmlElement*);
-const char* XmlGetAttr(TiXmlElement*, int n);
-const char* XmlGetAttrName(TiXmlElement*, int n);
-
class XmlNode : public TiXmlDocument, private MNonCopyable
{
TiXmlElement *m_hXml;
@@ -228,11 +226,6 @@ public: }
return nullptr;
}
- operator int()
- {
- if (LPCSTR s = *this) return atoi(s);
- return 0;
- }
__forceinline bool operator== (char *str)
{
return !mir_strcmp(*this, str);
diff --git a/protocols/JabberG/src/stdafx.h b/protocols/JabberG/src/stdafx.h index dc50a93f52..ef24d224ae 100755 --- a/protocols/JabberG/src/stdafx.h +++ b/protocols/JabberG/src/stdafx.h @@ -739,7 +739,7 @@ time_t str2time(const char*); wchar_t* JabberStrFixLines(const wchar_t *str);
wchar_t* JabberErrorStr(int errorCode);
-wchar_t* JabberErrorMsg(const TiXmlElement *errorNode, int *errorCode = nullptr);
+CMStringW JabberErrorMsg(const TiXmlElement *errorNode, int *errorCode = nullptr);
const wchar_t *JabberStrIStr(const wchar_t *str, const wchar_t *substr);
void JabberCopyText(HWND hwnd, const wchar_t *text);
@@ -747,6 +747,7 @@ CJabberProto* JabberChooseInstance(bool bIsLink=false); bool JabberReadXep203delay(const TiXmlElement *node, time_t &msgTime);
+void SetWindowTextUtf(HWND hwndDlg, const char *szValue);
void SetDlgItemTextUtf(HWND hwndDlg, int ctrlId, const char *szValue);
int UIEmulateBtnClick(HWND hwndDlg, UINT idcButton);
|