summaryrefslogtreecommitdiff
path: root/protocols/JabberG/src
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/JabberG/src')
-rw-r--r--protocols/JabberG/src/jabber_archive.cpp2
-rw-r--r--protocols/JabberG/src/jabber_bookmarks.cpp2
-rw-r--r--protocols/JabberG/src/jabber_chat.cpp12
-rw-r--r--protocols/JabberG/src/jabber_disco.cpp16
-rw-r--r--protocols/JabberG/src/jabber_iq_handlers.cpp67
-rw-r--r--protocols/JabberG/src/jabber_iqid.cpp24
-rw-r--r--protocols/JabberG/src/jabber_list.cpp45
-rw-r--r--protocols/JabberG/src/jabber_list.h32
-rw-r--r--protocols/JabberG/src/jabber_menu.cpp2
-rw-r--r--protocols/JabberG/src/jabber_misc.cpp4
-rw-r--r--protocols/JabberG/src/jabber_proto.cpp6
-rw-r--r--protocols/JabberG/src/jabber_proto.h8
-rw-r--r--protocols/JabberG/src/jabber_svc.cpp4
-rwxr-xr-xprotocols/JabberG/src/jabber_thread.cpp14
-rw-r--r--protocols/JabberG/src/jabber_util.cpp53
15 files changed, 140 insertions, 151 deletions
diff --git a/protocols/JabberG/src/jabber_archive.cpp b/protocols/JabberG/src/jabber_archive.cpp
index 0b8d4e0b64..cd568f5f0f 100644
--- a/protocols/JabberG/src/jabber_archive.cpp
+++ b/protocols/JabberG/src/jabber_archive.cpp
@@ -37,7 +37,7 @@ void CJabberProto::RetrieveMessageArchive(MCONTACT hContact, JABBER_LIST_ITEM *p
if (pItem->bHistoryRead)
return;
- pItem->bHistoryRead = TRUE;
+ pItem->bHistoryRead = true;
XmlNodeIq iq( AddIQ(&CJabberProto::OnIqResultGetCollectionList, JABBER_IQ_TYPE_GET));
HXML list = iq << XCHILDNS( _T("list"), JABBER_FEAT_ARCHIVE) << XATTR(_T("with"), pItem->jid);
diff --git a/protocols/JabberG/src/jabber_bookmarks.cpp b/protocols/JabberG/src/jabber_bookmarks.cpp
index 6d22b5172c..11a136cd86 100644
--- a/protocols/JabberG/src/jabber_bookmarks.cpp
+++ b/protocols/JabberG/src/jabber_bookmarks.cpp
@@ -131,7 +131,7 @@ static INT_PTR CALLBACK JabberAddBookmarkDlgProc(HWND hwndDlg, UINT msg, WPARAM
GetDlgItemText(hwndDlg, IDC_NAME, text, _countof(text));
replaceStrT(item->name, (text[0] == 0) ? roomJID : text);
- item->bAutoJoin = (IsDlgButtonChecked(hwndDlg, IDC_CHECK_BM_AUTOJOIN) == BST_CHECKED);
+ item->bAutoJoin = IsDlgButtonChecked(hwndDlg, IDC_CHECK_BM_AUTOJOIN) == BST_CHECKED;
XmlNodeIq iq( param->ppro->AddIQ(&CJabberProto::OnIqResultSetBookmarks, JABBER_IQ_TYPE_SET));
param->ppro->SetBookmarkRequest(iq);
diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp
index 5038fd7160..3617dd6c5b 100644
--- a/protocols/JabberG/src/jabber_chat.cpp
+++ b/protocols/JabberG/src/jabber_chat.cpp
@@ -1031,10 +1031,11 @@ static void sttNickListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK*
{
CMString jid(FORMAT, _T("%s/%s"), item->jid, him->m_tszResourceName);
- ppro->ListAdd(LIST_VCARD_TEMP, jid);
+ MCONTACT hContact = ppro->AddToListByJID(jid, PALF_TEMPORARY);
+ ppro->ListAdd(LIST_VCARD_TEMP, jid, hContact);
ppro->ListAddResource(LIST_VCARD_TEMP, jid, him->m_iStatus, him->m_tszStatusMessage, him->m_iPriority);
- CallService(MS_USERINFO_SHOWDIALOG, ppro->AddToListByJID(jid, PALF_TEMPORARY), 0);
+ CallService(MS_USERINFO_SHOWDIALOG, hContact, 0);
}
break;
@@ -1199,10 +1200,11 @@ static void sttNickListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK*
if (TCHAR *tmp = _tcschr(jid, _T('/')))
*tmp = 0;
- ppro->ListAdd(LIST_VCARD_TEMP, jid);
+ MCONTACT hContact = ppro->AddToListByJID(jid, PALF_TEMPORARY);
+ ppro->ListAdd(LIST_VCARD_TEMP, jid, hContact);
ppro->ListAddResource(LIST_VCARD_TEMP, jid, him->m_iStatus, him->m_tszStatusMessage, him->m_iPriority);
- CallService(MS_USERINFO_SHOWDIALOG, ppro->AddToListByJID(jid, PALF_TEMPORARY), 0);
+ CallService(MS_USERINFO_SHOWDIALOG, hContact, 0);
}
break;
@@ -1358,7 +1360,7 @@ static void sttSendPrivateMessage(CJabberProto *ppro, JABBER_LIST_ITEM *item, co
{
TCHAR szFullJid[JABBER_MAX_JID_LEN];
mir_sntprintf(szFullJid, _T("%s/%s"), item->jid, nick);
- MCONTACT hContact = ppro->DBCreateContact(szFullJid, NULL, TRUE, FALSE);
+ MCONTACT hContact = ppro->DBCreateContact(szFullJid, NULL, true, false);
if (hContact != NULL) {
pResourceStatus r(item->findResource(nick));
if (r)
diff --git a/protocols/JabberG/src/jabber_disco.cpp b/protocols/JabberG/src/jabber_disco.cpp
index 50b6e873d7..d11f05d097 100644
--- a/protocols/JabberG/src/jabber_disco.cpp
+++ b/protocols/JabberG/src/jabber_disco.cpp
@@ -1394,9 +1394,9 @@ void CJabberProto::ServiceDiscoveryShowMenu(CJabberSDNode *pNode, HTREELISTITEM
{
MCONTACT hContact = HContactFromJID(pNode->GetJid());
if (!hContact) {
- hContact = DBCreateContact(pNode->GetJid(), pNode->GetName(), TRUE, FALSE);
- JABBER_LIST_ITEM *item = ListAdd(LIST_VCARD_TEMP, pNode->GetJid());
- item->bUseResource = TRUE;
+ hContact = DBCreateContact(pNode->GetJid(), pNode->GetName(), true, false);
+ JABBER_LIST_ITEM *item = ListAdd(LIST_VCARD_TEMP, pNode->GetJid(), hContact);
+ item->bUseResource = true;
}
HMENU hContactMenu = Menu_BuildContactMenu(hContact);
GetCursorPos(&pt);
@@ -1413,8 +1413,8 @@ void CJabberProto::ServiceDiscoveryShowMenu(CJabberSDNode *pNode, HTREELISTITEM
hContact = AddToListByJID(jid, PALF_TEMPORARY);
if (ListGetItemPtr(LIST_VCARD_TEMP, pNode->GetJid()) == NULL) {
- JABBER_LIST_ITEM *item = ListAdd(LIST_VCARD_TEMP, pNode->GetJid());
- item->bUseResource = TRUE;
+ JABBER_LIST_ITEM *item = ListAdd(LIST_VCARD_TEMP, pNode->GetJid(), hContact);
+ item->bUseResource = true;
if (item->arResources.getCount() == 0)
ListAddResource(LIST_VCARD_TEMP, jid, ID_STATUS_OFFLINE, NULL, 0);
}
@@ -1424,10 +1424,10 @@ void CJabberProto::ServiceDiscoveryShowMenu(CJabberSDNode *pNode, HTREELISTITEM
case SD_ACT_ROSTER:
{
- MCONTACT hContact = DBCreateContact(pNode->GetJid(), pNode->GetName(), FALSE, FALSE);
+ MCONTACT hContact = DBCreateContact(pNode->GetJid(), pNode->GetName(), false, false);
db_unset(hContact, "CList", "NotOnList");
- JABBER_LIST_ITEM *item = ListAdd(LIST_VCARD_TEMP, pNode->GetJid());
- item->bUseResource = TRUE;
+ JABBER_LIST_ITEM *item = ListAdd(LIST_VCARD_TEMP, pNode->GetJid(), hContact);
+ item->bUseResource = true;
}
break;
diff --git a/protocols/JabberG/src/jabber_iq_handlers.cpp b/protocols/JabberG/src/jabber_iq_handlers.cpp
index b64cbfb12a..9d0bfde672 100644
--- a/protocols/JabberG/src/jabber_iq_handlers.cpp
+++ b/protocols/JabberG/src/jabber_iq_handlers.cpp
@@ -232,8 +232,6 @@ BOOL CJabberProto::OnRosterPushRequest(HXML, CJabberIqInfo *pInfo)
}
}
- JABBER_LIST_ITEM *item;
- MCONTACT hContact = NULL;
const TCHAR *jid, *str;
debugLogA("<iq/> Got roster push, query has %d children", XmlGetChildCount(queryNode));
@@ -254,53 +252,54 @@ BOOL CJabberProto::OnRosterPushRequest(HXML, CJabberIqInfo *pInfo)
const TCHAR *name = XmlGetAttrValue(itemNode, _T("name"));
ptrT nick((name != NULL) ? mir_tstrdup(name) : JabberNickFromJID(jid));
if (nick != NULL) {
- if ((item = ListAdd(LIST_ROSTER, jid)) != NULL) {
- replaceStrT(item->nick, nick);
-
- HXML groupNode = XmlGetChild(itemNode, "group");
- replaceStrT(item->group, XmlGetText(groupNode));
-
- if ((hContact = HContactFromJID(jid, false)) == NULL) {
- // Received roster has a new JID.
- // Add the jid (with empty resource) to Miranda contact list.
- hContact = DBCreateContact(jid, nick, FALSE, FALSE);
+ MCONTACT hContact = HContactFromJID(jid, false);
+ if (hContact == NULL)
+ hContact = DBCreateContact(jid, nick, false, false);
+ else
+ setTString(hContact, "jid", jid);
+
+ JABBER_LIST_ITEM *item = ListAdd(LIST_ROSTER, jid, hContact);
+ replaceStrT(item->nick, nick);
+
+ HXML groupNode = XmlGetChild(itemNode, "group");
+ replaceStrT(item->group, XmlGetText(groupNode));
+
+ if (name != NULL) {
+ ptrT tszNick(getTStringA(hContact, "Nick"));
+ if (tszNick != NULL) {
+ if (mir_tstrcmp(nick, tszNick) != 0)
+ db_set_ts(hContact, "CList", "MyHandle", nick);
+ else
+ db_unset(hContact, "CList", "MyHandle");
}
- else setTString(hContact, "jid", jid);
-
- if (name != NULL) {
- ptrT tszNick(getTStringA(hContact, "Nick"));
- if (tszNick != NULL) {
- if (mir_tstrcmp(nick, tszNick) != 0)
- db_set_ts(hContact, "CList", "MyHandle", nick);
- else
- db_unset(hContact, "CList", "MyHandle");
- }
- else db_set_ts(hContact, "CList", "MyHandle", nick);
- }
- else db_unset(hContact, "CList", "MyHandle");
-
- if (!m_options.IgnoreRosterGroups) {
- if (item->group != NULL) {
- Clist_CreateGroup(0, item->group);
- db_set_ts(hContact, "CList", "Group", item->group);
- }
- else db_unset(hContact, "CList", "Group");
+ else db_set_ts(hContact, "CList", "MyHandle", nick);
+ }
+ else db_unset(hContact, "CList", "MyHandle");
+
+ if (!m_options.IgnoreRosterGroups) {
+ if (item->group != NULL) {
+ Clist_CreateGroup(0, item->group);
+ db_set_ts(hContact, "CList", "Group", item->group);
}
+ else db_unset(hContact, "CList", "Group");
}
}
}
- if ((item = ListGetItemPtr(LIST_ROSTER, jid)) != NULL) {
+ if (JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, jid)) {
if (!mir_tstrcmp(str, _T("both"))) item->subscription = SUB_BOTH;
else if (!mir_tstrcmp(str, _T("to"))) item->subscription = SUB_TO;
else if (!mir_tstrcmp(str, _T("from"))) item->subscription = SUB_FROM;
else item->subscription = SUB_NONE;
debugLog(_T("Roster push for jid=%s, set subscription to %s"), jid, str);
+
+ MCONTACT hContact = HContactFromJID(jid);
+
// subscription = remove is to remove from roster list
// but we will just set the contact to offline and not actually
// remove, so that history will be retained.
if (!mir_tstrcmp(str, _T("remove"))) {
- if ((hContact = HContactFromJID(jid)) != NULL) {
+ if (hContact) {
SetContactOfflineStatus(hContact);
ListRemove(LIST_ROSTER, jid);
}
diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp
index ad3f91ece9..71ac576a3b 100644
--- a/protocols/JabberG/src/jabber_iqid.cpp
+++ b/protocols/JabberG/src/jabber_iqid.cpp
@@ -390,7 +390,11 @@ void CJabberProto::OnIqResultGetRoster(HXML iqNode, CJabberIqInfo *pInfo)
if (nick == NULL)
continue;
- JABBER_LIST_ITEM *item = ListAdd(LIST_ROSTER, jid);
+ MCONTACT hContact = HContactFromJID(jid);
+ if (hContact == NULL) // Received roster has a new JID.
+ hContact = DBCreateContact(jid, nick, false, false); // Add the jid (with empty resource) to Miranda contact list.
+
+ JABBER_LIST_ITEM *item = ListAdd(LIST_ROSTER, jid, hContact);
item->subscription = sub;
mir_free(item->nick); item->nick = nick;
@@ -400,8 +404,7 @@ void CJabberProto::OnIqResultGetRoster(HXML iqNode, CJabberIqInfo *pInfo)
// check group delimiters:
if (item->group && szGroupDelimeter) {
- TCHAR *szPos = NULL;
- while (szPos = _tcsstr(item->group, szGroupDelimeter)) {
+ while (TCHAR *szPos = _tcsstr(item->group, szGroupDelimeter)) {
*szPos = 0;
szPos += mir_tstrlen(szGroupDelimeter);
TCHAR *szNewGroup = (TCHAR *)mir_alloc(sizeof(TCHAR) * (mir_tstrlen(item->group) + mir_tstrlen(szPos) + 2));
@@ -413,13 +416,6 @@ void CJabberProto::OnIqResultGetRoster(HXML iqNode, CJabberIqInfo *pInfo)
}
}
- MCONTACT hContact = HContactFromJID(jid);
- if (hContact == NULL) {
- // Received roster has a new JID.
- // Add the jid (with empty resource) to Miranda contact list.
- hContact = DBCreateContact(jid, nick, FALSE, FALSE);
- }
-
if (name != NULL) {
ptrT tszNick( getTStringA("Nick"));
if (tszNick != NULL) {
@@ -617,7 +613,7 @@ void CJabberProto::OnIqResultGetVcardPhoto(HXML n, MCONTACT hContact, bool &hasP
if (item == NULL) {
item = ListAdd(LIST_VCARD_TEMP, jid); // adding to the temp list to store information about photo
if (item != NULL)
- item->bUseResource = TRUE;
+ item->bUseResource = true;
}
if (item != NULL) {
hasPhoto = TRUE;
@@ -1465,17 +1461,17 @@ void CJabberProto::OnIqResultDiscoBookmarks(HXML iqNode, CJabberIqInfo*)
JABBER_LIST_ITEM *item = ListAdd(LIST_BOOKMARK, jid);
item->name = mir_tstrdup(XmlGetAttrValue(itemNode, _T("name")));
item->type = mir_tstrdup(_T("conference"));
- item->bUseResource = TRUE;
+ item->bUseResource = true;
item->nick = mir_tstrdup(XPathT(itemNode, "nick"));
item->password = mir_tstrdup(XPathT(itemNode, "password"));
const TCHAR *autoJ = XmlGetAttrValue(itemNode, _T("autojoin"));
if (autoJ != NULL)
- item->bAutoJoin = (!mir_tstrcmp(autoJ, _T("true")) || !mir_tstrcmp(autoJ, _T("1"))) ? true : false;
+ item->bAutoJoin = !mir_tstrcmp(autoJ, _T("true")) || !mir_tstrcmp(autoJ, _T("1"));
}
else if (!mir_tstrcmp(name, _T("url")) && (jid = XmlGetAttrValue(itemNode, _T("url")))) {
JABBER_LIST_ITEM *item = ListAdd(LIST_BOOKMARK, jid);
- item->bUseResource = TRUE;
+ item->bUseResource = true;
item->name = mir_tstrdup(XmlGetAttrValue(itemNode, _T("name")));
item->type = mir_tstrdup(_T("url"));
}
diff --git a/protocols/JabberG/src/jabber_list.cpp b/protocols/JabberG/src/jabber_list.cpp
index de054a23ad..25db1afe3e 100644
--- a/protocols/JabberG/src/jabber_list.cpp
+++ b/protocols/JabberG/src/jabber_list.cpp
@@ -38,7 +38,7 @@ JABBER_LIST_ITEM::JABBER_LIST_ITEM() :
JABBER_LIST_ITEM::~JABBER_LIST_ITEM()
{
- for (int i=0; i < arResources.getCount(); i++)
+ for (int i = 0; i < arResources.getCount(); i++)
delete arResources[i];
if (m_pItemResource)
@@ -84,13 +84,13 @@ void JABBER_RESOURCE_STATUS::Release()
{
if (this != NULL)
if (::InterlockedDecrement(&m_refCount) == 0)
- delete this;
+ delete this;
}
void CJabberProto::ListWipe(void)
{
mir_cslock lck(m_csLists);
- for (int i=0; i < m_lstRoster.getCount(); i++)
+ for (int i = 0; i < m_lstRoster.getCount(); i++)
delete m_lstRoster[i];
m_lstRoster.destroy();
@@ -99,20 +99,23 @@ void CJabberProto::ListWipe(void)
/////////////////////////////////////////////////////////////////////////////////////////
// Adding & removing items
-JABBER_LIST_ITEM *CJabberProto::ListAdd(JABBER_LIST list, const TCHAR *jid)
+JABBER_LIST_ITEM* CJabberProto::ListAdd(JABBER_LIST list, const TCHAR *jid, MCONTACT hContact)
{
bool bUseResource = false;
mir_cslockfull lck(m_csLists);
JABBER_LIST_ITEM *item = ListGetItemPtr(list, jid);
- if (item != NULL)
+ if (item != NULL) {
+ if (hContact)
+ item->hContact = hContact;
return item;
+ }
TCHAR *s = mir_tstrdup(jid);
TCHAR *q = NULL;
// strip resource name if any
//fyr
- if (!((list== LIST_ROSTER) && ListGetItemPtr(LIST_CHATROOM, jid))) { // but only if it is not chat room contact
+ if (!((list == LIST_ROSTER) && ListGetItemPtr(LIST_CHATROOM, jid))) { // but only if it is not chat room contact
if (list != LIST_VCARD_TEMP) {
TCHAR *p;
if ((p = _tcschr(s, '@')) != NULL)
@@ -126,7 +129,7 @@ JABBER_LIST_ITEM *CJabberProto::ListAdd(JABBER_LIST list, const TCHAR *jid)
//if it is a chat room keep resource and made it resource sensitive
if (ChatRoomHContactFromJID(s)) {
if (q != NULL)
- *q='/';
+ *q = '/';
bUseResource = true;
}
}
@@ -134,6 +137,7 @@ JABBER_LIST_ITEM *CJabberProto::ListAdd(JABBER_LIST list, const TCHAR *jid)
item = new JABBER_LIST_ITEM();
item->list = list;
item->jid = s;
+ item->hContact = hContact;
item->resourceMode = RSMODE_LASTSEEN;
item->bUseResource = bUseResource;
m_lstRoster.insert(item);
@@ -156,7 +160,7 @@ void CJabberProto::ListRemove(JABBER_LIST list, const TCHAR *jid)
void CJabberProto::ListRemoveList(JABBER_LIST list)
{
int i = 0;
- while ((i=ListFindNext(list, i)) >= 0)
+ while ((i = ListFindNext(list, i)) >= 0)
ListRemoveByIndex(i);
}
@@ -174,9 +178,12 @@ void CJabberProto::ListRemoveByIndex(int index)
JABBER_LIST_ITEM* CJabberProto::ListGetItemPtr(JABBER_LIST list, const TCHAR *jid)
{
- JABBER_LIST_ITEM *tmp = (JABBER_LIST_ITEM*)_alloca( sizeof(JABBER_LIST_ITEM));
+ if (jid == NULL)
+ return NULL;
+
+ JABBER_LIST_ITEM *tmp = (JABBER_LIST_ITEM*)_alloca(sizeof(JABBER_LIST_ITEM));
tmp->list = list;
- tmp->jid = (TCHAR*)jid;
+ tmp->jid = (TCHAR*)jid;
tmp->bUseResource = FALSE;
mir_cslock lck(m_csLists);
@@ -184,7 +191,7 @@ JABBER_LIST_ITEM* CJabberProto::ListGetItemPtr(JABBER_LIST list, const TCHAR *ji
tmp->list = LIST_CHATROOM;
int id = m_lstRoster.getIndex(tmp);
if (id != -1)
- tmp->bUseResource = TRUE;
+ tmp->bUseResource = true;
tmp->list = list;
}
@@ -219,7 +226,7 @@ pResourceStatus JABBER_LIST_ITEM::findResource(const TCHAR *resourceName) const
if (arResources.getCount() == 0 || resourceName == NULL || *resourceName == 0)
return NULL;
- for (int i=0; i < arResources.getCount(); i++) {
+ for (int i = 0; i < arResources.getCount(); i++) {
JABBER_RESOURCE_STATUS *r = arResources[i];
if (!mir_tstrcmp(r->m_tszResourceName, resourceName))
return r;
@@ -237,7 +244,7 @@ pResourceStatus CJabberProto::ListFindResource(JABBER_LIST list, const TCHAR *ji
const TCHAR *p = _tcschr(jid, '@');
const TCHAR *q = _tcschr((p == NULL) ? jid : p, '/');
- return (q == NULL) ? NULL : LI->findResource(q+1);
+ return (q == NULL) ? NULL : LI->findResource(q + 1);
}
bool CJabberProto::ListAddResource(JABBER_LIST list, const TCHAR *jid, int status, const TCHAR *statusMessage, char priority, const TCHAR *nick)
@@ -252,7 +259,7 @@ bool CJabberProto::ListAddResource(JABBER_LIST list, const TCHAR *jid, int statu
const TCHAR *p = _tcschr(jid, '@');
const TCHAR *q = _tcschr((p == NULL) ? jid : p, '/');
if (q) {
- const TCHAR *resource = q+1;
+ const TCHAR *resource = q + 1;
if (*resource == 0)
return 0;
@@ -301,7 +308,7 @@ void CJabberProto::ListRemoveResource(JABBER_LIST list, const TCHAR *jid)
if (q == NULL)
return;
- pResourceStatus r( LI->findResource(q+1));
+ pResourceStatus r(LI->findResource(q + 1));
if (r == NULL)
return;
@@ -340,14 +347,14 @@ pResourceStatus JABBER_LIST_ITEM::getBestResource() const
return m_pManualResource;
int nBestPos = -1, nBestPri = -200;
- for (int i=0; i < arResources.getCount(); i++) {
+ for (int i = 0; i < arResources.getCount(); i++) {
JABBER_RESOURCE_STATUS *r = arResources[i];
if (r->m_iPriority > nBestPri) {
nBestPri = r->m_iPriority;
nBestPos = i;
}
}
-
+
return (nBestPos != -1) ? arResources[nBestPos] : NULL;
}
@@ -366,13 +373,13 @@ TCHAR* CJabberProto::ListGetBestClientResourceNamePtr(const TCHAR *jid)
if (LI == NULL)
return NULL;
- pResourceStatus r( LI->getBestResource());
+ pResourceStatus r(LI->getBestResource());
if (r != NULL)
return r->m_tszResourceName;
int status = ID_STATUS_OFFLINE;
TCHAR *res = NULL;
- for (int i=0; i < LI->arResources.getCount(); i++) {
+ for (int i = 0; i < LI->arResources.getCount(); i++) {
r = LI->arResources[i];
bool foundBetter = false;
switch (r->m_iStatus) {
diff --git a/protocols/JabberG/src/jabber_list.h b/protocols/JabberG/src/jabber_list.h
index 6d8352ac95..6537179c50 100644
--- a/protocols/JabberG/src/jabber_list.h
+++ b/protocols/JabberG/src/jabber_list.h
@@ -28,7 +28,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "jabber_caps.h"
-typedef enum {
+enum JABBER_LIST
+{
LIST_ROSTER, // Roster list
LIST_CHATROOM, // Groupchat room currently joined
LIST_ROOM, // Groupchat room list to show on the Jabber groupchat dialog
@@ -38,35 +39,39 @@ typedef enum {
LIST_BOOKMARK,
LIST_VCARD_TEMP,
LIST_FTIQID
-} JABBER_LIST;
+};
-typedef enum {
+enum JABBER_SUBSCRIPTION
+{
SUB_NONE,
SUB_TO,
SUB_FROM,
SUB_BOTH
-} JABBER_SUBSCRIPTION;
+};
-typedef enum {
+enum JABBER_GC_AFFILIATION
+{
AFFILIATION_NONE,
AFFILIATION_OUTCAST,
AFFILIATION_MEMBER,
AFFILIATION_ADMIN,
AFFILIATION_OWNER
-} JABBER_GC_AFFILIATION;
+};
-typedef enum {
+enum JABBER_GC_ROLE
+{
ROLE_NONE,
ROLE_VISITOR,
ROLE_PARTICIPANT,
ROLE_MODERATOR
-} JABBER_GC_ROLE;
+};
-typedef enum { // initial default to RSMODE_LASTSEEN
+enum JABBER_RESOURCE_MODE // initial default to RSMODE_LASTSEEN
+{
RSMODE_SERVER, // always let server decide (always send correspondence without resouce name)
RSMODE_LASTSEEN, // use the last seen resource (or let server decide if haven't seen anything yet)
RSMODE_MANUAL // specify resource manually (see the defaultResource field - must not be NULL)
-} JABBER_RESOURCE_MODE;
+};
class JABBER_RESOURCE_STATUS : public MZeroedObject
{
@@ -146,6 +151,7 @@ struct JABBER_LIST_ITEM : public MZeroedObject
JABBER_LIST list;
TCHAR* jid;
+ MCONTACT hContact;
// LIST_ROSTER
// jid = jid of the contact
@@ -201,10 +207,10 @@ struct JABBER_LIST_ITEM : public MZeroedObject
//LIST_BOOKMARK
// jid = room JID
TCHAR* password; // password for room
- BOOL bAutoJoin;
+ bool bAutoJoin;
- BOOL bUseResource;
- BOOL bHistoryRead;
+ bool bUseResource;
+ bool bHistoryRead;
};
/////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/JabberG/src/jabber_menu.cpp b/protocols/JabberG/src/jabber_menu.cpp
index 2a015df7d9..6f5be21d83 100644
--- a/protocols/JabberG/src/jabber_menu.cpp
+++ b/protocols/JabberG/src/jabber_menu.cpp
@@ -944,7 +944,7 @@ int CJabberProto::OnProcessSrmmEvent(WPARAM, LPARAM lParam)
ptrT jid(getTStringA(event->hContact, "jid"));
if (jid != NULL) {
JABBER_LIST_ITEM *pItem = ListGetItemPtr(LIST_ROSTER, jid);
- if (pItem && (m_ThreadInfo->jabberServerCaps & JABBER_CAPS_ARCHIVE_AUTO) && m_options.EnableMsgArchive)
+ if (pItem && m_ThreadInfo && (m_ThreadInfo->jabberServerCaps & JABBER_CAPS_ARCHIVE_AUTO) && m_options.EnableMsgArchive)
RetrieveMessageArchive(event->hContact, pItem);
}
}
diff --git a/protocols/JabberG/src/jabber_misc.cpp b/protocols/JabberG/src/jabber_misc.cpp
index 44e491f1fd..e0ed5736e2 100644
--- a/protocols/JabberG/src/jabber_misc.cpp
+++ b/protocols/JabberG/src/jabber_misc.cpp
@@ -55,7 +55,7 @@ void JabberChatDllError()
void CJabberProto::DBAddAuthRequest(const TCHAR *jid, const TCHAR *nick)
{
- MCONTACT hContact = DBCreateContact(jid, nick, TRUE, TRUE);
+ MCONTACT hContact = DBCreateContact(jid, nick, true, true);
delSetting(hContact, "Hidden");
T2Utf szJid(jid);
@@ -85,7 +85,7 @@ void CJabberProto::DBAddAuthRequest(const TCHAR *jid, const TCHAR *nick)
///////////////////////////////////////////////////////////////////////////////
// JabberDBCreateContact()
-MCONTACT CJabberProto::DBCreateContact(const TCHAR *jid, const TCHAR *nick, BOOL temporary, BOOL stripResource)
+MCONTACT CJabberProto::DBCreateContact(const TCHAR *jid, const TCHAR *nick, bool temporary, bool stripResource)
{
if (jid == NULL || jid[0] == '\0')
return NULL;
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp
index d9fca6c2d4..57025c09b5 100644
--- a/protocols/JabberG/src/jabber_proto.cpp
+++ b/protocols/JabberG/src/jabber_proto.cpp
@@ -245,6 +245,8 @@ int CJabberProto::OnModulesLoadedEx(WPARAM, LPARAM)
if (jid == NULL)
continue;
+ ListAdd(isChatRoom(hContact) ? LIST_CHATROOM : LIST_ROSTER, jid, hContact);
+
TCHAR *resourcepos = _tcschr(jid, '/');
if (resourcepos != NULL)
*resourcepos = '\0';
@@ -622,11 +624,11 @@ int __cdecl CJabberProto::GetInfo(MCONTACT hContact, int /*infoType*/)
if (bHasResource && (tmpItem = ListGetItemPtr(LIST_CHATROOM, szBareJid))) {
pResourceStatus him(tmpItem->findResource(szBareJid+mir_tstrlen(szBareJid)+1));
if (him) {
- item = ListAdd(LIST_VCARD_TEMP, jid);
+ item = ListAdd(LIST_VCARD_TEMP, jid, hContact);
ListAddResource(LIST_VCARD_TEMP, jid, him->m_iStatus, him->m_tszStatusMessage, him->m_iPriority);
}
}
- else item = ListAdd(LIST_VCARD_TEMP, jid);
+ else item = ListAdd(LIST_VCARD_TEMP, jid, hContact);
}
if (item != NULL) {
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h
index 5bb94655b7..cf496ba308 100644
--- a/protocols/JabberG/src/jabber_proto.h
+++ b/protocols/JabberG/src/jabber_proto.h
@@ -526,9 +526,9 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
//---- jabber_list.cpp ---------------------------------------------------------------
- JABBER_LIST_ITEM *ListAdd(JABBER_LIST list, const TCHAR *jid);
- JABBER_LIST_ITEM *ListGetItemPtr(JABBER_LIST list, const TCHAR *jid);
- JABBER_LIST_ITEM *ListGetItemPtrFromIndex(int index);
+ JABBER_LIST_ITEM* ListAdd(JABBER_LIST list, const TCHAR *jid, MCONTACT hContact = 0);
+ JABBER_LIST_ITEM* ListGetItemPtr(JABBER_LIST list, const TCHAR *jid);
+ JABBER_LIST_ITEM* ListGetItemPtrFromIndex(int index);
void ListWipe(void);
@@ -587,7 +587,7 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
void AddContactToRoster(const TCHAR *jid, const TCHAR *nick, const TCHAR *grpName);
void DBAddAuthRequest(const TCHAR *jid, const TCHAR *nick);
BOOL AddDbPresenceEvent(MCONTACT hContact, BYTE btEventType);
- MCONTACT DBCreateContact(const TCHAR *jid, const TCHAR *nick, BOOL temporary, BOOL stripResource);
+ MCONTACT DBCreateContact(const TCHAR *jid, const TCHAR *nick, bool temporary, bool stripResource);
void GetAvatarFileName(MCONTACT hContact, TCHAR* pszDest, size_t cbLen);
void ResolveTransportNicks(const TCHAR *jid);
void SetServerStatus(int iNewStatus);
diff --git a/protocols/JabberG/src/jabber_svc.cpp b/protocols/JabberG/src/jabber_svc.cpp
index 317687a073..9b6ecf86a6 100644
--- a/protocols/JabberG/src/jabber_svc.cpp
+++ b/protocols/JabberG/src/jabber_svc.cpp
@@ -442,7 +442,7 @@ INT_PTR __cdecl CJabberProto::JabberServiceParseXmppURI(WPARAM, LPARAM lParam)
TCHAR *szMsgBody = NULL;
MCONTACT hContact = HContactFromJID(szJid, false);
if (hContact == NULL)
- hContact = DBCreateContact(szJid, szJid, TRUE, TRUE);
+ hContact = DBCreateContact(szJid, szJid, true, true);
if (hContact == NULL)
return 1;
@@ -509,7 +509,7 @@ INT_PTR __cdecl CJabberProto::JabberServiceParseXmppURI(WPARAM, LPARAM lParam)
if (!mir_tstrcmpi(szCommand, _T("sendfile"))) {
MCONTACT hContact = HContactFromJID(szJid, false);
if (hContact == NULL)
- hContact = DBCreateContact(szJid, szJid, TRUE, TRUE);
+ hContact = DBCreateContact(szJid, szJid, true, true);
if (hContact == NULL)
return 1;
CallService(MS_FILE_SENDFILE, hContact, NULL);
diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp
index 296a427470..8fba12715f 100755
--- a/protocols/JabberG/src/jabber_thread.cpp
+++ b/protocols/JabberG/src/jabber_thread.cpp
@@ -1005,14 +1005,14 @@ DWORD JabberGetLastContactMessageTime(MCONTACT hContact)
MCONTACT CJabberProto::CreateTemporaryContact(const TCHAR *szJid, JABBER_LIST_ITEM* chatItem)
{
if (chatItem == NULL)
- return DBCreateContact(szJid, ptrT(JabberNickFromJID(szJid)), TRUE, TRUE);
+ return DBCreateContact(szJid, ptrT(JabberNickFromJID(szJid)), true, true);
const TCHAR *p = _tcschr(szJid, '/');
if (p != NULL && p[1] != '\0')
p++;
else
p = szJid;
- MCONTACT hContact = DBCreateContact(szJid, p, TRUE, FALSE);
+ MCONTACT hContact = DBCreateContact(szJid, p, true, false);
pResourceStatus r(chatItem->findResource(p));
if (r)
@@ -1318,7 +1318,7 @@ void CJabberProto::OnProcessMessage(HXML node, ThreadData *info)
const TCHAR *group = XmlGetText(XmlGetChild(iNode, _T("group")));
if (action && jid && _tcsstr(jid, chkJID)) {
if (!mir_tstrcmp(action, _T("add"))) {
- MCONTACT cc = DBCreateContact(jid, nick, FALSE, FALSE);
+ MCONTACT cc = DBCreateContact(jid, nick, false, false);
if (group)
db_set_ts(cc, "CList", "Group", group);
}
@@ -1531,11 +1531,11 @@ void CJabberProto::OnProcessPresence(HXML node, ThreadData *info)
debugLog(_T("SKIP Receive presence online from %s (who is not in my roster and not in list - skiping)"), from);
return;
}
- hContact = DBCreateContact(from, nick, TRUE, TRUE);
+ hContact = DBCreateContact(from, nick, true, true);
}
if (!ListGetItemPtr(LIST_ROSTER, from)) {
debugLog(_T("Receive presence online from %s (who is not in my roster)"), from);
- ListAdd(LIST_ROSTER, from);
+ ListAdd(LIST_ROSTER, from, hContact);
}
DBCheckIsTransportedContact(from, hContact);
int status = ID_STATUS_ONLINE;
@@ -1664,7 +1664,7 @@ void CJabberProto::OnProcessPresence(HXML node, ThreadData *info)
// automatically send authorization allowed to agent/transport
if (_tcschr(from, '@') == NULL || m_options.AutoAcceptAuthorization) {
- ListAdd(LIST_ROSTER, from);
+ ListAdd(LIST_ROSTER, from, hContact);
info->send(XmlNode(_T("presence")) << XATTR(_T("to"), from) << XATTR(_T("type"), _T("subscribed")));
if (m_options.AutoAdd == TRUE) {
@@ -1672,6 +1672,8 @@ void CJabberProto::OnProcessPresence(HXML node, ThreadData *info)
if (item == NULL || (item->subscription != SUB_BOTH && item->subscription != SUB_TO)) {
debugLog(_T("Try adding contact automatically jid = %s"), from);
if ((hContact = AddToListByJID(from, 0)) != NULL) {
+ if (item)
+ item->hContact = hContact;
setTString(hContact, "Nick", tszNick);
db_unset(hContact, "CList", "NotOnList");
}
diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp
index 8d1d1e7c72..5691dc81eb 100644
--- a/protocols/JabberG/src/jabber_util.cpp
+++ b/protocols/JabberG/src/jabber_util.cpp
@@ -36,18 +36,9 @@ int CJabberProto::SerialNext(void)
MCONTACT CJabberProto::ChatRoomHContactFromJID(const TCHAR *jid)
{
- if (jid == NULL)
- return NULL;
-
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
- ptrT dbJid(getTStringA(hContact, "ChatRoomID"));
- if (dbJid == NULL)
- if ((dbJid = getTStringA(hContact, "jid")) == NULL)
- continue;
-
- if (!mir_tstrcmpi(jid, dbJid) && isChatRoom(hContact))
- return hContact;
- }
+ JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_CHATROOM, jid);
+ if (item != NULL && item->hContact)
+ return item->hContact;
return NULL;
}
@@ -60,31 +51,15 @@ MCONTACT CJabberProto::HContactFromJID(const TCHAR *jid, bool bStripResource)
if (jid == NULL)
return NULL;
- JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_CHATROOM, jid);
-
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
- bool bIsChat = isChatRoom(hContact);
-
- ptrT dbJid(getTStringA(hContact, bIsChat ? "ChatRoomID" : "jid"));
- if (dbJid != NULL) {
- int result;
- if (item != NULL)
- result = mir_tstrcmpi(jid, dbJid);
- else {
- if (bStripResource) {
- if (bIsChat)
- result = mir_tstrcmpi(jid, dbJid); // for chat room we have to have full contact matched
- else
- result = _tcsnicmp(jid, dbJid, mir_tstrlen(dbJid));
- }
- // most probably it should just look full matching contact
- else result = mir_tstrcmpi(jid, dbJid);
- }
-
- if (result == 0)
- return hContact;
- }
- }
+ TCHAR szJid[JABBER_MAX_JID_LEN];
+ if (bStripResource)
+ JabberStripJid(jid, szJid, _countof(szJid));
+ else
+ _tcsncpy_s(szJid, jid, _TRUNCATE);
+
+ JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, szJid);
+ if (item != NULL && item->hContact)
+ return item->hContact;
return NULL;
}
@@ -94,8 +69,8 @@ TCHAR* __stdcall JabberNickFromJID(const TCHAR *jid)
if (jid == NULL)
return mir_tstrdup(_T(""));
- const TCHAR *p;
- if ((p = _tcschr(jid, '@')) == NULL)
+ const TCHAR *p = _tcschr(jid, '@');
+ if (p == NULL)
p = _tcschr(jid, '/');
return (p != NULL) ? mir_tstrndup(jid, p - jid) : mir_tstrdup(jid);