summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2016-06-28 11:04:48 +0000
committerGeorge Hazan <george.hazan@gmail.com>2016-06-28 11:04:48 +0000
commita743c7d531c07c1fc2a778d7e15189f124aa6e48 (patch)
tree1c0d4a35b23a6e7c52eafdbba5675f9202d59f41
parent7256e8b5c3967e231627ce8056fa7c44aceb3dca (diff)
Jabber:
- newly added contacts could be doubled; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@17041 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--protocols/JabberG/src/jabber_list.cpp2
-rw-r--r--protocols/JabberG/src/jabber_misc.cpp34
-rwxr-xr-xprotocols/JabberG/src/jabber_proto.cpp33
3 files changed, 18 insertions, 51 deletions
diff --git a/protocols/JabberG/src/jabber_list.cpp b/protocols/JabberG/src/jabber_list.cpp
index e73e485194..b12aeef4d4 100644
--- a/protocols/JabberG/src/jabber_list.cpp
+++ b/protocols/JabberG/src/jabber_list.cpp
@@ -200,7 +200,7 @@ JABBER_LIST_ITEM* CJabberProto::ListGetItemPtr(JABBER_LIST list, const TCHAR *ji
JABBER_LIST_ITEM *tmp = (JABBER_LIST_ITEM*)_alloca(sizeof(JABBER_LIST_ITEM));
tmp->list = list;
tmp->jid = (TCHAR*)jid;
- tmp->bUseResource = FALSE;
+ tmp->bUseResource = false;
mir_cslock lck(m_csLists);
if (list == LIST_ROSTER) {
diff --git a/protocols/JabberG/src/jabber_misc.cpp b/protocols/JabberG/src/jabber_misc.cpp
index a7a1c46562..0d9b4a7c01 100644
--- a/protocols/JabberG/src/jabber_misc.cpp
+++ b/protocols/JabberG/src/jabber_misc.cpp
@@ -90,40 +90,32 @@ MCONTACT CJabberProto::DBCreateContact(const TCHAR *jid, const TCHAR *nick, bool
if (jid == NULL || jid[0] == '\0')
return NULL;
+ MCONTACT hContact = HContactFromJID(jid, stripResource);
+ if (hContact != NULL)
+ return hContact;
+
// strip resource if present
- TCHAR *s = NEWTSTR_ALLOCA(jid), *pResource = NULL;
+ TCHAR szJid[JABBER_MAX_JID_LEN];
if (stripResource)
- if (TCHAR *p = _tcschr(s, '@'))
- if (pResource = _tcschr(p, '/'))
- *pResource = '\0';
-
- // We can't use JabberHContactFromJID() here because of the stripResource option
- size_t len = mir_tstrlen(s);
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
- ptrT dbJid(getTStringA(hContact, "jid"));
- if (dbJid == NULL)
- continue;
-
- TCHAR *p = dbJid; // not null
- if (_tcslen(p) >= len && (p[len] == '\0' || p[len] == '/') && !_tcsnicmp(p, s, len))
- return hContact;
- }
+ JabberStripJid(jid, szJid, _countof(szJid));
+ else
+ _tcsncpy_s(szJid, jid, _TRUNCATE);
MCONTACT hNewContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
Proto_AddToContact(hNewContact, m_szModuleName);
- setTString(hNewContact, "jid", s);
+ setTString(hNewContact, "jid", szJid);
if (nick != NULL && *nick != '\0')
setTString(hNewContact, "Nick", nick);
if (temporary)
db_set_b(hNewContact, "CList", "NotOnList", 1);
else
- SendGetVcard(s);
+ SendGetVcard(szJid);
if (JABBER_LIST_ITEM *pItem = ListAdd(LIST_ROSTER, jid, hNewContact))
- pItem->bUseResource = pResource != NULL;
+ pItem->bUseResource = _tcschr(szJid, '/') != 0;
- debugLog(_T("Create Jabber contact jid=%s, nick=%s"), s, nick);
- DBCheckIsTransportedContact(s, hNewContact);
+ debugLog(_T("Create Jabber contact jid=%s, nick=%s"), szJid, nick);
+ DBCheckIsTransportedContact(szJid, hNewContact);
return hNewContact;
}
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp
index 327415dab4..b64ac73c55 100755
--- a/protocols/JabberG/src/jabber_proto.cpp
+++ b/protocols/JabberG/src/jabber_proto.cpp
@@ -42,7 +42,7 @@ static int compareListItems(const JABBER_LIST_ITEM *p1, const JABBER_LIST_ITEM *
// for bookmarks, temporary contacts & groupchat members
// resource must be used in the comparison
- if ((p1->list == LIST_ROSTER && (p1->bUseResource == TRUE || p2->bUseResource == TRUE))
+ if ((p1->list == LIST_ROSTER && (p1->bUseResource == true || p2->bUseResource == true))
|| (p1->list == LIST_BOOKMARK) || (p1->list == LIST_VCARD_TEMP))
return mir_tstrcmpi(p1->jid, p2->jid);
@@ -299,35 +299,10 @@ MCONTACT CJabberProto::AddToListByJID(const TCHAR *newJid, DWORD flags)
{
debugLog(_T("AddToListByJID jid = %s"), newJid);
- MCONTACT hContact = HContactFromJID(newJid);
- if (hContact == NULL) {
- // not already there: add
- debugLog(_T("Add new jid to contact jid = %s"), newJid);
- hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
- Proto_AddToContact(hContact, m_szModuleName);
- setTString(hContact, "jid", newJid);
-
- // Note that by removing or disable the "NotOnList" will trigger
- // the plugin to add a particular contact to the roster list.
- // See DBSettingChanged hook at the bottom part of this source file.
- // But the add module will delete "NotOnList". So we will not do it here.
- // Also because we need "MyHandle" and "Group" info, which are set after
- // PS_ADDTOLIST is called but before the add dialog issue deletion of
- // "NotOnList".
- // If temporary add, "NotOnList" won't be deleted, and that's expected.
- db_set_b(hContact, "CList", "NotOnList", 1);
- if (flags & PALF_TEMPORARY)
- db_set_b(hContact, "CList", "Hidden", 1);
- }
- else {
- // already exist
- // Set up a dummy "NotOnList" when adding permanently only
- if (!(flags & PALF_TEMPORARY))
- db_set_b(hContact, "CList", "NotOnList", 1);
- }
+ MCONTACT hContact = DBCreateContact(newJid, NULL, true, false);
+ if (flags & PALF_TEMPORARY)
+ db_set_b(hContact, "CList", "Hidden", 1);
- if (hContact && newJid)
- DBCheckIsTransportedContact(newJid, hContact);
return hContact;
}