summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xprotocols/JabberG/src/jabber_caps.cpp4
-rw-r--r--protocols/JabberG/src/jabber_chat.cpp30
-rw-r--r--protocols/JabberG/src/jabber_file.cpp2
-rw-r--r--protocols/JabberG/src/jabber_ft.cpp5
-rw-r--r--protocols/JabberG/src/jabber_groupchat.cpp6
-rw-r--r--protocols/JabberG/src/jabber_menu.cpp11
-rwxr-xr-xprotocols/JabberG/src/jabber_misc.cpp6
-rwxr-xr-xprotocols/JabberG/src/jabber_proto.cpp3
-rw-r--r--protocols/JabberG/src/jabber_rc.cpp15
-rw-r--r--protocols/JabberG/src/jabber_svc.cpp18
-rwxr-xr-xprotocols/JabberG/src/jabber_userinfo.cpp4
-rwxr-xr-xprotocols/JabberG/src/jabber_util.cpp20
-rwxr-xr-xprotocols/JabberG/src/stdafx.h2
13 files changed, 56 insertions, 70 deletions
diff --git a/protocols/JabberG/src/jabber_caps.cpp b/protocols/JabberG/src/jabber_caps.cpp
index 508b7126c1..50a94e6204 100755
--- a/protocols/JabberG/src/jabber_caps.cpp
+++ b/protocols/JabberG/src/jabber_caps.cpp
@@ -229,10 +229,8 @@ JabberCapsBits CJabberProto::GetTotalJidCapabilities(const char *jid)
if (item) {
for (auto &it : item->arResources) {
- char szFullJid[JABBER_MAX_JID_LEN];
- mir_snprintf(szFullJid, "%s/%s", szBareJid, it->m_szResourceName);
pResourceStatus r(it);
- JabberCapsBits jcb = GetResourceCapabilities(szFullJid, r);
+ JabberCapsBits jcb = GetResourceCapabilities(MakeJid(szBareJid, it->m_szResourceName), r);
if (!(jcb & JABBER_RESOURCE_CAPS_ERROR))
jcbToReturn |= jcb;
}
diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp
index c8d26b879d..39ad978519 100644
--- a/protocols/JabberG/src/jabber_chat.cpp
+++ b/protocols/JabberG/src/jabber_chat.cpp
@@ -334,11 +334,8 @@ void CJabberProto::GcQuit(JABBER_LIST_ITEM *item, int code, const TiXmlElement *
item->bChatActive = false;
if (m_bJabberOnline) {
- char szPresenceTo[JABBER_MAX_JID_LEN];
- mir_snprintf(szPresenceTo, "%s/%s", item->jid, item->nick);
-
m_ThreadInfo->send(
- XmlNode("presence") << XATTR("to", szPresenceTo) << XATTR("type", "unavailable")
+ XmlNode("presence") << XATTR("to", MakeJid(item->jid, item->nick)) << XATTR("type", "unavailable")
<< XCHILD("status", szMessage));
ListRemove(LIST_CHATROOM, item->jid);
@@ -1014,7 +1011,7 @@ static void sttNickListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK*
case IDM_VCARD:
{
- CMStringA jid(FORMAT, "%s/%s", item->jid, him->m_szResourceName);
+ CMStringA jid(MakeJid(item->jid, him->m_szResourceName));
MCONTACT hContact = ppro->AddToListByJID(jid, PALF_TEMPORARY);
ppro->setUString(hContact, "Nick", him->m_szResourceName);
@@ -1138,7 +1135,8 @@ static void sttNickListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK*
case IDM_LINK0: case IDM_LINK1: case IDM_LINK2: case IDM_LINK3: case IDM_LINK4:
case IDM_LINK5: case IDM_LINK6: case IDM_LINK7: case IDM_LINK8: case IDM_LINK9:
if ((GetTickCount() - dwLastBanKickTime) > BAN_KICK_INTERVAL) {
- Utf2T resourceName_copy(him->m_szResourceName); // copy resource name to prevent possible crash if user list rebuilds
+ // copy resource name to prevent possible crash if user list rebuilds
+ char *resourceName_copy(NEWSTR_ALLOCA(him->m_szResourceName));
char *szInviteTo = nullptr;
int idx = gch->dwData - IDM_LINK0;
@@ -1159,10 +1157,8 @@ static void sttNickListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK*
if (!ppro->EnterString(szBuffer, szTitle, ESF_MULTILINE))
break;
- szTitle.Format(L"%s/%s", item->jid, resourceName_copy);
-
XmlNode msg("message");
- msg << XATTR("to", T2Utf(szTitle)) << XATTRID(ppro->SerialNext())
+ msg << XATTR("to", MakeJid(item->jid, resourceName_copy)) << XATTRID(ppro->SerialNext())
<< XCHILD("x", T2Utf(szBuffer)) << XATTR("xmlns", JABBER_FEAT_DIRECT_MUC_INVITE) << XATTR("jid", szInviteTo)
<< XCHILD("invite") << XATTR("from", item->nick);
ppro->m_ThreadInfo->send(msg);
@@ -1180,7 +1176,7 @@ static void sttNickListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK*
break;
case IDM_CPY_INROOMJID:
- JabberCopyText(g_clistApi.hwndContactList, CMStringA(FORMAT, "%s/%s", item->jid, him->m_szResourceName));
+ JabberCopyText(g_clistApi.hwndContactList, MakeJid(item->jid, him->m_szResourceName));
break;
case IDM_RJID_VCARD:
@@ -1254,13 +1250,9 @@ static void sttLogListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK* g
szTitle.Format(TranslateT("Change nickname in %s"), gch->ptszID);
if (item->nick)
szBuffer = Utf2T(item->nick);
- if (ppro->EnterString(szBuffer, szTitle, ESF_COMBO, "gcNick_")) {
- if (ppro->ListGetItemPtr(LIST_CHATROOM, roomJid) != nullptr) {
- char text[1024];
- mir_snprintf(text, "%s/%s", roomJid.get(), T2Utf(szBuffer).get());
- ppro->SendPresenceTo(ppro->m_iStatus == ID_STATUS_INVISIBLE ? ID_STATUS_ONLINE : ppro->m_iStatus, text);
- }
- }
+ if (ppro->EnterString(szBuffer, szTitle, ESF_COMBO, "gcNick_"))
+ if (ppro->ListGetItemPtr(LIST_CHATROOM, roomJid) != nullptr)
+ ppro->SendPresenceTo(ppro->m_iStatus == ID_STATUS_INVISIBLE ? ID_STATUS_ONLINE : ppro->m_iStatus, MakeJid(roomJid, T2Utf(szBuffer)));
break;
case IDM_INVITE:
@@ -1341,9 +1333,7 @@ static void sttLogListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK* g
static void sttSendPrivateMessage(CJabberProto *ppro, JABBER_LIST_ITEM *item, const char *nick)
{
- char szFullJid[JABBER_MAX_JID_LEN];
- mir_snprintf(szFullJid, "%s/%s", item->jid, nick);
- MCONTACT hContact = ppro->DBCreateContact(szFullJid, nullptr, true, false);
+ MCONTACT hContact = ppro->DBCreateContact(MakeJid(item->jid, nick), nullptr, true, false);
if (hContact != 0) {
pResourceStatus r(item->findResource(nick));
if (r)
diff --git a/protocols/JabberG/src/jabber_file.cpp b/protocols/JabberG/src/jabber_file.cpp
index 69dc1778df..f9909972f0 100644
--- a/protocols/JabberG/src/jabber_file.cpp
+++ b/protocols/JabberG/src/jabber_file.cpp
@@ -295,7 +295,7 @@ void __cdecl CJabberProto::FileServerThread(filetransfer *ft)
char szAddr[256];
mir_snprintf(szAddr, "http://%s:%d/%s", myAddr, nlb.wPort, pFileName.c_str());
- XmlNodeIq iq("set", ft->szId, CMStringA(FORMAT, "%s/%s", ft->jid, ptszResource));
+ XmlNodeIq iq("set", ft->szId, MakeJid(ft->jid, ptszResource));
TiXmlElement *query = iq << XQUERY(JABBER_FEAT_OOB);
query << XCHILD("url", szAddr);
query << XCHILD("desc", T2Utf(ft->szDescription));
diff --git a/protocols/JabberG/src/jabber_ft.cpp b/protocols/JabberG/src/jabber_ft.cpp
index cd4884ebb1..c63f50aa96 100644
--- a/protocols/JabberG/src/jabber_ft.cpp
+++ b/protocols/JabberG/src/jabber_ft.cpp
@@ -97,10 +97,7 @@ void CJabberProto::FtInitiate(char* jid, filetransfer *ft)
if (wchar_t *p = wcsrchr(filename, '\\'))
filename = p + 1;
- char tszJid[512];
- mir_snprintf(tszJid, "%s/%s", jid, rs);
-
- XmlNodeIq iq(AddIQ(&CJabberProto::OnFtSiResult, JABBER_IQ_TYPE_SET, tszJid, JABBER_IQ_PARSE_FROM | JABBER_IQ_PARSE_TO, -1, ft));
+ XmlNodeIq iq(AddIQ(&CJabberProto::OnFtSiResult, JABBER_IQ_TYPE_SET, MakeJid(jid, rs), JABBER_IQ_PARSE_FROM | JABBER_IQ_PARSE_TO, -1, ft));
TiXmlElement *si = iq << XCHILDNS("si", JABBER_FEAT_SI) << XATTR("id", sid)
<< XATTR("mime-type", "binary/octet-stream") << XATTR("profile", JABBER_FEAT_SI_FT);
si << XCHILDNS("file", JABBER_FEAT_SI_FT) << XATTR("name", T2Utf(filename))
diff --git a/protocols/JabberG/src/jabber_groupchat.cpp b/protocols/JabberG/src/jabber_groupchat.cpp
index 42d968d7c5..06e538e573 100644
--- a/protocols/JabberG/src/jabber_groupchat.cpp
+++ b/protocols/JabberG/src/jabber_groupchat.cpp
@@ -744,7 +744,7 @@ static VOID CALLBACK JabberGroupchatChangeNickname(void* arg)
if (param->ppro->EnterString(szBuffer, szTitle, ESF_COMBO, "gcNick_")) {
T2Utf newNick(szBuffer);
replaceStr(item->nick, newNick);
- param->ppro->SendPresenceTo(param->ppro->m_iStatus, CMStringA(FORMAT, "%s/%s", item->jid, newNick.get()));
+ param->ppro->SendPresenceTo(param->ppro->m_iStatus, MakeJid(item->jid, newNick));
}
}
@@ -990,9 +990,7 @@ void CJabberProto::GroupchatProcessPresence(const TiXmlElement *node)
ptrA newNick(getUStringA("GcAltNick"));
if (++item->iChatState == 1 && newNick != nullptr && newNick[0] != 0) {
replaceStr(item->nick, newNick);
- char text[1024];
- mir_snprintf(text, "%s/%s", item->jid, newNick);
- SendPresenceTo(m_iStatus, text);
+ SendPresenceTo(m_iStatus, MakeJid(item->jid, newNick));
}
else {
CallFunctionAsync(JabberGroupchatChangeNickname, new JabberGroupchatChangeNicknameParam(this, from));
diff --git a/protocols/JabberG/src/jabber_menu.cpp b/protocols/JabberG/src/jabber_menu.cpp
index 640315f3bb..f1cbdcbae9 100644
--- a/protocols/JabberG/src/jabber_menu.cpp
+++ b/protocols/JabberG/src/jabber_menu.cpp
@@ -1021,9 +1021,9 @@ INT_PTR __cdecl CJabberProto::OnMenuHandleDirectPresence(WPARAM hContact, LPARAM
if (!m_bJabberOnline || !hContact)
return 0;
- char *jid, text[1024];
- ptrA tszJid(getUStringA(hContact, "jid"));
- if (tszJid == nullptr) {
+ CMStringA jid;
+ ptrA szJid(getUStringA(hContact, "jid"));
+ if (szJid == nullptr) {
ptrA roomid(getUStringA(hContact, "ChatRoomID"));
if (roomid == nullptr)
return 0;
@@ -1032,10 +1032,9 @@ INT_PTR __cdecl CJabberProto::OnMenuHandleDirectPresence(WPARAM hContact, LPARAM
if (item == nullptr)
return 0;
- mir_snprintf(text, "%s/%s", item->jid, item->nick);
- jid = text;
+ jid = MakeJid(item->jid, item->nick);
}
- else jid = tszJid;
+ else jid = szJid;
CMStringW szValue;
if (EnterString(szValue, TranslateT("Status Message"), ESF_MULTILINE))
diff --git a/protocols/JabberG/src/jabber_misc.cpp b/protocols/JabberG/src/jabber_misc.cpp
index 1366e7c81c..7f6ccc3d53 100755
--- a/protocols/JabberG/src/jabber_misc.cpp
+++ b/protocols/JabberG/src/jabber_misc.cpp
@@ -350,12 +350,10 @@ void CJabberProto::UpdateMirVer(MCONTACT hContact, const pResourceStatus &r)
if (jid == nullptr)
return;
- char szFullJid[JABBER_MAX_JID_LEN];
if (r->m_szResourceName && !strchr(jid, '/'))
- mir_snprintf(szFullJid, "%s/%s", jid, r->m_szResourceName);
+ setUString(hContact, DBSETTING_DISPLAY_UID, MakeJid(jid, r->m_szResourceName));
else
- mir_strncpy(szFullJid, jid, _countof(szFullJid));
- setUString(hContact, DBSETTING_DISPLAY_UID, szFullJid);
+ setUString(hContact, DBSETTING_DISPLAY_UID, jid);
}
void CJabberProto::UpdateSubscriptionInfo(MCONTACT hContact, JABBER_LIST_ITEM *item)
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp
index 6196fc0f13..005311104f 100755
--- a/protocols/JabberG/src/jabber_proto.cpp
+++ b/protocols/JabberG/src/jabber_proto.cpp
@@ -641,8 +641,7 @@ int CJabberProto::GetInfo(MCONTACT hContact, int /*infoType*/)
if (item->arResources.getCount()) {
for (auto &it : item->arResources) {
pResourceStatus r(it);
- char tmp[JABBER_MAX_JID_LEN];
- mir_snprintf(tmp, "%s/%s", szBareJid, r->m_szResourceName);
+ CMStringA tmp(MakeJid(szBareJid, r->m_szResourceName));
if (r->m_jcbCachedCaps & JABBER_CAPS_DISCO_INFO)
m_ThreadInfo->send(
diff --git a/protocols/JabberG/src/jabber_rc.cpp b/protocols/JabberG/src/jabber_rc.cpp
index 979d7b9a8d..1ea31f39a0 100644
--- a/protocols/JabberG/src/jabber_rc.cpp
+++ b/protocols/JabberG/src/jabber_rc.cpp
@@ -539,8 +539,8 @@ int CJabberProto::AdhocForwardHandler(const TiXmlElement*, CJabberIqInfo *pInfo,
int nEventsSent = 0;
for (auto &hContact : AccContacts()) {
- ptrA tszJid(getUStringA(hContact, "jid"));
- if (tszJid == nullptr)
+ ptrA szJid(getUStringA(hContact, "jid"));
+ if (szJid == nullptr)
continue;
for (MEVENT hDbEvent = db_event_firstUnread(hContact); hDbEvent; hDbEvent = db_event_next(hContact, hDbEvent)) {
@@ -567,13 +567,12 @@ int CJabberProto::AdhocForwardHandler(const TiXmlElement*, CJabberIqInfo *pInfo,
TiXmlElement *addressesNode = msg << XCHILDNS("addresses", JABBER_FEAT_EXT_ADDRESSING);
- char szOFrom[JABBER_MAX_JID_LEN];
+ CMStringA szOFrom;
size_t cbBlob = mir_strlen((LPSTR)dbei.pBlob) + 1;
- if (cbBlob < dbei.cbBlob) { // rest of message contains a sender's resource
- ptrW szOResource(mir_utf8decodeW((LPSTR)dbei.pBlob + cbBlob + 1));
- mir_snprintf(szOFrom, "%s/%s", tszJid, szOResource);
- }
- else strncpy_s(szOFrom, tszJid, _TRUNCATE);
+ if (cbBlob < dbei.cbBlob) // rest of message contains a sender's resource
+ szOFrom = MakeJid(szJid, (LPSTR)dbei.pBlob + cbBlob + 1);
+ else
+ szOFrom = szJid;
addressesNode << XCHILD("address") << XATTR("type", "ofrom") << XATTR("jid", szOFrom);
addressesNode << XCHILD("address") << XATTR("type", "oto") << XATTR("jid", m_ThreadInfo->fullJID);
diff --git a/protocols/JabberG/src/jabber_svc.cpp b/protocols/JabberG/src/jabber_svc.cpp
index b6415a2c7e..8ac857be1b 100644
--- a/protocols/JabberG/src/jabber_svc.cpp
+++ b/protocols/JabberG/src/jabber_svc.cpp
@@ -146,15 +146,15 @@ INT_PTR __cdecl CJabberProto::JabberGetAvatarInfo(WPARAM wParam, LPARAM lParam)
if (item != nullptr) {
BOOL isXVcard = getByte(pai->hContact, "AvatarXVcard", 0);
- char szJid[JABBER_MAX_JID_LEN]; szJid[0] = 0;
+ CMStringA szJid;
if (item->arResources.getCount() != 0 && !isXVcard)
if (char *bestResName = ListGetBestClientResourceNamePtr(tszJid))
- mir_snprintf(szJid, "%s/%s", tszJid, bestResName);
+ szJid = MakeJid(tszJid, bestResName);
- if (szJid[0] == 0)
- strncpy_s(szJid, tszJid, _TRUNCATE);
+ if (szJid.IsEmpty())
+ szJid = tszJid;
- debugLogA("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.c_str());
m_ThreadInfo->send((isXVcard) ?
XmlNodeIq(AddIQ(&CJabberProto::OnIqResultGetVCardAvatar, JABBER_IQ_TYPE_GET, szJid)) << XCHILDNS("vCard", JABBER_FEAT_VCARD_TEMP) :
@@ -511,15 +511,15 @@ INT_PTR __cdecl CJabberProto::JabberSendNudge(WPARAM hContact, LPARAM)
if (jid == nullptr)
return 0;
- char tszJid[JABBER_MAX_JID_LEN];
+ CMStringA szJid;
char *szResource = ListGetBestClientResourceNamePtr(jid);
if (szResource)
- mir_snprintf(tszJid, "%s/%s", jid, szResource);
+ szJid = MakeJid(jid, szResource);
else
- strncpy_s(tszJid, jid, _TRUNCATE);
+ szJid = jid;
m_ThreadInfo->send(
- XmlNode("message") << XATTR("type", "headline") << XATTR("to", tszJid)
+ XmlNode("message") << XATTR("type", "headline") << XATTR("to", szJid)
<< XCHILDNS("attention", JABBER_FEAT_ATTENTION));
return 0;
}
diff --git a/protocols/JabberG/src/jabber_userinfo.cpp b/protocols/JabberG/src/jabber_userinfo.cpp
index eb4a3638b3..16a0097a95 100755
--- a/protocols/JabberG/src/jabber_userinfo.cpp
+++ b/protocols/JabberG/src/jabber_userinfo.cpp
@@ -231,9 +231,7 @@ static void sttFillResourceInfo(CJabberProto *ppro, HWND hwndTree, HTREEITEM hti
}
// caps
- mir_snprintf(buf, "%s/%s", item->jid, r->m_szResourceName);
- JabberCapsBits jcb = ppro->GetResourceCapabilities(buf, r);
-
+ JabberCapsBits jcb = ppro->GetResourceCapabilities(MakeJid(item->jid, r->m_szResourceName), r);
if (!(jcb & JABBER_RESOURCE_CAPS_ERROR)) {
HTREEITEM htiCaps = sttFillInfoLine(hwndTree, htiResource, ppro->LoadIconEx("main"), nullptr, TranslateU("Client capabilities"), sttInfoLineId(resource, INFOLINE_CAPS));
int i;
diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp
index 1d946f6a90..981610f811 100755
--- a/protocols/JabberG/src/jabber_util.cpp
+++ b/protocols/JabberG/src/jabber_util.cpp
@@ -66,6 +66,17 @@ MCONTACT CJabberProto::HContactFromJID(const char *jid, bool bStripResource)
return 0;
}
+CMStringA MakeJid(const char *jid, const char *resource)
+{
+ CMStringA ret(jid);
+ if (resource != nullptr) {
+ ret.AppendChar('/');
+ ret.Append(resource);
+ }
+ return ret;
+}
+
+
char* JabberNickFromJID(const char *jid)
{
if (jid == nullptr)
@@ -494,11 +505,8 @@ void CJabberProto::SendPresence(int status, bool bSendToAll)
LISTFOREACH(i, this, LIST_CHATROOM)
{
JABBER_LIST_ITEM *item = ListGetItemPtrFromIndex(i);
- if (item != nullptr && item->nick != nullptr) {
- char text[1024];
- mir_snprintf(text, "%s/%s", item->jid, item->nick);
- SendPresenceTo(status == ID_STATUS_INVISIBLE ? ID_STATUS_ONLINE : status, text);
- }
+ if (item != nullptr && item->nick != nullptr)
+ SendPresenceTo(status == ID_STATUS_INVISIBLE ? ID_STATUS_ONLINE : status, MakeJid(item->jid, item->nick));
}
}
}
@@ -549,7 +557,7 @@ char* CJabberProto::GetClientJID(const char *jid, char *dest, size_t destLen)
if (p == nullptr) {
pResourceStatus r(LI->getBestResource());
if (r != nullptr)
- mir_snprintf(dest, destLen, "%s/%s", jid, r->m_szResourceName);
+ strncpy_s(dest, destLen, MakeJid(jid, r->m_szResourceName), _TRUNCATE);
}
}
diff --git a/protocols/JabberG/src/stdafx.h b/protocols/JabberG/src/stdafx.h
index 7eb48fb6b7..f319bb16d2 100755
--- a/protocols/JabberG/src/stdafx.h
+++ b/protocols/JabberG/src/stdafx.h
@@ -742,6 +742,8 @@ struct TStringPairs
typedef char JabberShaStrBuf[2*MIR_SHA1_HASH_SIZE + 1];
+CMStringA MakeJid(const char *jid, const char *resource);
+
char* JabberNickFromJID(const char *jid);
char* JabberPrepareJid(const char *jid);
char* JabberSha1(const char *str, JabberShaStrBuf buf);