summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-07-20 10:51:35 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-07-20 10:51:35 +0000
commit2fe00cdd66d4559cc43a5f27c19ddc79a43676eb (patch)
tree546def30affbabeaad425c9a25e2545e1e4096f5 /protocols
parentf946ebcb1ac09b7220f8547074496aa2d1b83768 (diff)
- all manual list locks removed;
- ListExists removed and replaced with ListGetItemPtr; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@5426 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/JabberG/src/jabber_bookmarks.cpp79
-rw-r--r--protocols/JabberG/src/jabber_events.cpp2
-rw-r--r--protocols/JabberG/src/jabber_groupchat.cpp16
-rw-r--r--protocols/JabberG/src/jabber_iqid.cpp2
-rw-r--r--protocols/JabberG/src/jabber_list.cpp245
-rw-r--r--protocols/JabberG/src/jabber_proto.cpp2
-rw-r--r--protocols/JabberG/src/jabber_proto.h4
-rw-r--r--protocols/JabberG/src/jabber_rc.cpp30
-rw-r--r--protocols/JabberG/src/jabber_svc.cpp142
-rw-r--r--protocols/JabberG/src/jabber_thread.cpp6
10 files changed, 233 insertions, 295 deletions
diff --git a/protocols/JabberG/src/jabber_bookmarks.cpp b/protocols/JabberG/src/jabber_bookmarks.cpp
index f2ceae6965..6fae8422bc 100644
--- a/protocols/JabberG/src/jabber_bookmarks.cpp
+++ b/protocols/JabberG/src/jabber_bookmarks.cpp
@@ -212,10 +212,10 @@ private:
if (iItem < 0) return;
TCHAR *address = (TCHAR *)m_lvBookmarks.GetItemData(iItem);
- if ( !address) return;
+ if (address == NULL) return;
JABBER_LIST_ITEM *item = m_proto->ListGetItemPtr(LIST_BOOKMARK, address);
- if ( !item) return;
+ if (item == NULL) return;
JabberAddBookmarkDlgParam param;
param.ppro = m_proto;
@@ -231,10 +231,10 @@ private:
if (iItem < 0) return;
TCHAR *address = (TCHAR *)m_lvBookmarks.GetItemData(iItem);
- if ( !address) return;
+ if (address == NULL) return;
JABBER_LIST_ITEM *item = m_proto->ListGetItemPtr(LIST_BOOKMARK, address);
- if ( !item) return;
+ if (item == NULL) return;
m_btnAdd.Disable();
m_btnEdit.Disable();
@@ -251,7 +251,6 @@ private:
m_proto->SetBookmarkRequest(iq);
m_proto->m_ThreadInfo->send(iq);
}
-
};
CJabberDlgBookmarks::CJabberDlgBookmarks(CJabberProto *proto) :
@@ -333,15 +332,13 @@ void CJabberDlgBookmarks::OpenBookmark()
if (iItem < 0) return;
TCHAR *address = (TCHAR *)m_lvBookmarks.GetItemData(iItem);
- if ( !address) return;
+ if (address == NULL) return;
JABBER_LIST_ITEM *item = m_proto->ListGetItemPtr(LIST_BOOKMARK, address);
- if ( !item) return;
+ if (item == NULL) return;
- if ( !lstrcmpi(item->type, _T("conference")))
- {
- if ( !jabberChatDllPresent)
- {
+ if ( !lstrcmpi(item->type, _T("conference"))) {
+ if ( !jabberChatDllPresent) {
JabberChatDllError();
return;
}
@@ -350,26 +347,23 @@ void CJabberDlgBookmarks::OpenBookmark()
/* some hack for using bookmark to transport not under XEP-0048 */
if ( !_tcschr(item->jid, _T('@')))
- { //the room name is not provided let consider that it is transport and send request to registration
+ //the room name is not provided let consider that it is transport and send request to registration
m_proto->RegisterAgent(NULL, item->jid);
- } else
- {
+ else {
TCHAR *room = NEWTSTR_ALLOCA(item->jid);
TCHAR *server = _tcschr(room, _T('@'));
*(server++) = 0;
if (item->nick && *item->nick)
- {
m_proto->GroupchatJoinRoom(server, room, item->nick, item->password);
- } else
- {
+ else {
TCHAR* nick = JabberNickFromJID(m_proto->m_szJabberJID);
m_proto->GroupchatJoinRoom(server, room, nick, item->password);
mir_free(nick);
}
}
- } else
- {
+ }
+ else {
char *szUrl = mir_t2a(item->jid);
CallService(MS_UTILS_OPENURL, 1, (LPARAM)szUrl);
mir_free(szUrl);
@@ -378,9 +372,8 @@ void CJabberDlgBookmarks::OpenBookmark()
INT_PTR CJabberDlgBookmarks::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch (msg)
- {
- case WM_GETMINMAXINFO:
+ switch (msg) {
+ case WM_GETMINMAXINFO:
{
LPMINMAXINFO lpmmi = (LPMINMAXINFO)lParam;
lpmmi->ptMinTrackSize.x = 451;
@@ -389,13 +382,10 @@ INT_PTR CJabberDlgBookmarks::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
}
case WM_COMMAND:
- switch (LOWORD(wParam))
- {
- case IDOK:
- {
- OpenBookmark();
- return TRUE;
- }
+ switch (LOWORD(wParam)) {
+ case IDOK:
+ OpenBookmark();
+ return TRUE;
}
break;
}
@@ -405,16 +395,12 @@ INT_PTR CJabberDlgBookmarks::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
void CJabberDlgBookmarks::OnProtoCheckOnline(WPARAM, LPARAM)
{
- if ( !m_proto->m_bJabberOnline)
- {
+ if ( !m_proto->m_bJabberOnline) {
m_btnAdd.Disable();
m_btnEdit.Disable();
m_btnRemove.Disable();
- } else
- {
- UpdateData();
}
-
+ else UpdateData();
}
void CJabberDlgBookmarks::OnProtoRefresh(WPARAM, LPARAM)
@@ -424,8 +410,7 @@ void CJabberDlgBookmarks::OnProtoRefresh(WPARAM, LPARAM)
JABBER_LIST_ITEM *item = NULL;
LISTFOREACH(i, m_proto, LIST_BOOKMARK)
{
- if (item = m_proto->ListGetItemPtrFromIndex(i))
- {
+ if (item = m_proto->ListGetItemPtrFromIndex(i)) {
int itemType = lstrcmpi(item->type, _T("conference")) ? 1 : 0;
int iItem = m_lvBookmarks.AddItem(item->name, itemType, (LPARAM)item->jid, itemType);
m_lvBookmarks.SetItem(iItem, 1, item->jid);
@@ -434,8 +419,7 @@ void CJabberDlgBookmarks::OnProtoRefresh(WPARAM, LPARAM)
}
}
- if (item)
- {
+ if (item) {
m_btnEdit.Enable();
m_btnRemove.Enable();
}
@@ -446,16 +430,16 @@ void CJabberDlgBookmarks::OnProtoRefresh(WPARAM, LPARAM)
int CJabberDlgBookmarks::Resizer(UTILRESIZECONTROL *urc)
{
switch (urc->wId) {
- case IDC_BM_LIST:
- return RD_ANCHORX_WIDTH|RD_ANCHORY_HEIGHT;
+ case IDC_BM_LIST:
+ return RD_ANCHORX_WIDTH|RD_ANCHORY_HEIGHT;
- case IDCANCEL:
- return RD_ANCHORX_RIGHT|RD_ANCHORY_BOTTOM;
+ case IDCANCEL:
+ return RD_ANCHORX_RIGHT|RD_ANCHORY_BOTTOM;
- case IDC_ADD:
- case IDC_EDIT:
- case IDC_REMOVE:
- return RD_ANCHORX_LEFT|RD_ANCHORY_BOTTOM;
+ case IDC_ADD:
+ case IDC_EDIT:
+ case IDC_REMOVE:
+ return RD_ANCHORX_LEFT|RD_ANCHORY_BOTTOM;
}
return CSuper::Resizer(urc);
}
@@ -472,6 +456,7 @@ INT_PTR __cdecl CJabberProto::OnMenuHandleBookmarks(WPARAM, LPARAM)
/////////////////////////////////////////////////////////////////////////////////////////
// Launches the Bookmark details window, lParam is JABBER_BOOKMARK_ITEM*
+
int CJabberProto::AddEditBookmark(JABBER_LIST_ITEM* item)
{
if (m_bJabberOnline) {
diff --git a/protocols/JabberG/src/jabber_events.cpp b/protocols/JabberG/src/jabber_events.cpp
index 59ac6e0228..b0484c638b 100644
--- a/protocols/JabberG/src/jabber_events.cpp
+++ b/protocols/JabberG/src/jabber_events.cpp
@@ -45,7 +45,7 @@ int CJabberProto::OnContactDeleted(WPARAM wParam, LPARAM)
DBVARIANT dbv;
if ( !getTString((HANDLE)wParam, getByte((HANDLE) wParam, "ChatRoom", 0)?(char*)"ChatRoomID":(char*)"jid", &dbv)) {
- if (ListExist(LIST_ROSTER, dbv.ptszVal)) {
+ if (ListGetItemPtr(LIST_ROSTER, dbv.ptszVal)) {
if ( !_tcschr(dbv.ptszVal, _T('@'))) {
TCHAR szStrippedJid[JABBER_MAX_JID_LEN];
JabberStripJid(m_ThreadInfo->fullJID, szStrippedJid, SIZEOF(szStrippedJid));
diff --git a/protocols/JabberG/src/jabber_groupchat.cpp b/protocols/JabberG/src/jabber_groupchat.cpp
index 25f0d1bb93..858535b3ab 100644
--- a/protocols/JabberG/src/jabber_groupchat.cpp
+++ b/protocols/JabberG/src/jabber_groupchat.cpp
@@ -202,19 +202,13 @@ private:
JABBER_RESOURCE_STATUS* CJabberProto::GcFindResource(JABBER_LIST_ITEM *item, const TCHAR *resource)
{
- JABBER_RESOURCE_STATUS *res = NULL;
-
- EnterCriticalSection(&m_csLists);
+ mir_cslock lck(m_csLists);
JABBER_RESOURCE_STATUS *r = item->pResources;
- for (int i=0; i<item->resourceCount; i++) {
- if ( !_tcscmp(r[i].resourceName, resource)) {
- res = &r[i];
- break;
- }
- }
- LeaveCriticalSection(&m_csLists);
+ for (int i=0; i < item->resourceCount; i++)
+ if ( !_tcscmp(r[i].resourceName, resource))
+ return &r[i];
- return res;
+ return NULL;
}
INT_PTR __cdecl CJabberProto::OnMenuHandleJoinGroupchat(WPARAM, LPARAM)
diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp
index 76ac8734e7..1bc26f178f 100644
--- a/protocols/JabberG/src/jabber_iqid.cpp
+++ b/protocols/JabberG/src/jabber_iqid.cpp
@@ -524,7 +524,7 @@ void CJabberProto::OnIqResultGetRoster(HXML iqNode, CJabberIqInfo* pInfo)
for (HANDLE hContact = db_find_first(m_szModuleName); hContact; ) {
HANDLE hNext = db_find_next(hContact, m_szModuleName);
ptrT jid( db_get_tsa(hContact, m_szModuleName, "jid"));
- if (jid != NULL && !ListExist(LIST_ROSTER, jid)) {
+ if (jid != NULL && !ListGetItemPtr(LIST_ROSTER, jid)) {
Log("Syncing roster: preparing to delete %S (hContact=0x%x)", jid, hContact);
CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0);
}
diff --git a/protocols/JabberG/src/jabber_list.cpp b/protocols/JabberG/src/jabber_list.cpp
index 49b0460365..4b21ffdd3f 100644
--- a/protocols/JabberG/src/jabber_list.cpp
+++ b/protocols/JabberG/src/jabber_list.cpp
@@ -32,17 +32,19 @@ void MenuUpdateSrmmIcon(JABBER_LIST_ITEM *item);
static void JabberListFreeResourceInternal(JABBER_RESOURCE_STATUS *r)
{
- if (r->resourceName) mir_free(r->resourceName);
- if (r->nick) mir_free(r->nick);
- if (r->statusMessage) mir_free(r->statusMessage);
- if (r->software) mir_free(r->software);
- if (r->version) mir_free(r->version);
- if (r->system) mir_free(r->system);
- if (r->szCapsNode) mir_free(r->szCapsNode);
- if (r->szCapsVer) mir_free(r->szCapsVer);
- if (r->szCapsExt) mir_free(r->szCapsExt);
- if (r->szRealJid) mir_free(r->szRealJid);
- if (r->pSoftwareInfo) delete r->pSoftwareInfo;
+ mir_free(r->resourceName);
+ mir_free(r->nick);
+ mir_free(r->statusMessage);
+ mir_free(r->software);
+ mir_free(r->version);
+ mir_free(r->system);
+ mir_free(r->szCapsNode);
+ mir_free(r->szCapsVer);
+ mir_free(r->szCapsExt);
+ mir_free(r->szRealJid);
+
+ if (r->pSoftwareInfo)
+ delete r->pSoftwareInfo;
}
static void JabberListFreeItemInternal(JABBER_LIST_ITEM *item)
@@ -50,9 +52,8 @@ static void JabberListFreeItemInternal(JABBER_LIST_ITEM *item)
if (item == NULL)
return;
- JABBER_RESOURCE_STATUS* r = item->pResources;
- for (int i=0; i < item->resourceCount; i++, r++)
- JabberListFreeResourceInternal(r);
+ for (int i=0; i < item->resourceCount; i++)
+ JabberListFreeResourceInternal(&item->pResources[i]);
JabberListFreeResourceInternal(&item->itemResource);
@@ -85,29 +86,12 @@ void CJabberProto::ListWipe(void)
m_lstRoster.destroy();
}
-int CJabberProto::ListExist(JABBER_LIST list, const TCHAR *jid)
-{
- JABBER_LIST_ITEM tmp;
- tmp.list = list;
- tmp.jid = (TCHAR*)jid;
- tmp.bUseResource = FALSE;
-
- mir_cslock lck(m_csLists);
- if (list == LIST_ROSTER) {
- tmp.list = LIST_CHATROOM;
- int id = m_lstRoster.getIndex(&tmp);
- if (id != -1)
- tmp.bUseResource = TRUE;
- tmp.list = list;
- }
-
- int idx = m_lstRoster.getIndex(&tmp);
- return (idx == -1) ? 0 : idx+1;
-}
+/////////////////////////////////////////////////////////////////////////////////////////
+// Adding & removing items
JABBER_LIST_ITEM *CJabberProto::ListAdd(JABBER_LIST list, const TCHAR *jid)
{
- BOOL bUseResource=FALSE;
+ bool bUseResource = FALSE;
mir_cslockfull lck(m_csLists);
JABBER_LIST_ITEM *item = ListGetItemPtr(list, jid);
@@ -118,7 +102,7 @@ JABBER_LIST_ITEM *CJabberProto::ListAdd(JABBER_LIST list, const TCHAR *jid)
TCHAR *q = NULL;
// strip resource name if any
//fyr
- if ( !((list== LIST_ROSTER) && ListExist(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,14 +110,14 @@ JABBER_LIST_ITEM *CJabberProto::ListAdd(JABBER_LIST list, const TCHAR *jid)
*q = '\0';
}
}
- else bUseResource = TRUE;
+ else bUseResource = true;
if ( !bUseResource && list == LIST_ROSTER) {
//if it is a chat room keep resource and made it resource sensitive
if (ChatRoomHContactFromJID(s)) {
if (q != NULL)
*q='/';
- bUseResource = TRUE;
+ bUseResource = true;
}
}
@@ -153,10 +137,10 @@ JABBER_LIST_ITEM *CJabberProto::ListAdd(JABBER_LIST list, const TCHAR *jid)
void CJabberProto::ListRemove(JABBER_LIST list, const TCHAR *jid)
{
mir_cslock lck(m_csLists);
- int i = ListExist(list, jid);
- if (i != 0) {
- JabberListFreeItemInternal(m_lstRoster[ --i ]);
- m_lstRoster.remove(i);
+ JABBER_LIST_ITEM* LI = ListGetItemPtr(list, jid);
+ if (LI != NULL) {
+ JabberListFreeItemInternal(LI);
+ m_lstRoster.remove(LI);
}
}
@@ -176,14 +160,57 @@ void CJabberProto::ListRemoveByIndex(int index)
}
}
-JABBER_RESOURCE_STATUS *CJabberProto::ListFindResource(JABBER_LIST list, const TCHAR *jid)
+/////////////////////////////////////////////////////////////////////////////////////////
+// Getting & finding items
+
+JABBER_LIST_ITEM* CJabberProto::ListGetItemPtr(JABBER_LIST list, const TCHAR *jid)
{
+ JABBER_LIST_ITEM tmp;
+ tmp.list = list;
+ tmp.jid = (TCHAR*)jid;
+ tmp.bUseResource = FALSE;
+
mir_cslock lck(m_csLists);
- int i = ListExist(list, jid);
- if (i == 0)
- return NULL;
+ if (list == LIST_ROSTER) {
+ tmp.list = LIST_CHATROOM;
+ int id = m_lstRoster.getIndex(&tmp);
+ if (id != -1)
+ tmp.bUseResource = TRUE;
+ tmp.list = list;
+ }
+
+ return m_lstRoster.find(&tmp);
+}
+
+JABBER_LIST_ITEM* CJabberProto::ListGetItemPtrFromIndex(int index)
+{
+ mir_cslock lck(m_csLists);
+ if (index >= 0 && index < m_lstRoster.getCount())
+ return m_lstRoster[index];
+
+ return NULL;
+}
+
+int CJabberProto::ListFindNext(JABBER_LIST list, int fromOffset)
+{
+ mir_cslock lck(m_csLists);
+ int i = (fromOffset >= 0) ? fromOffset : 0;
+ for (; i<m_lstRoster.getCount(); i++)
+ if (m_lstRoster[i]->list == list)
+ return i;
- JABBER_LIST_ITEM* LI = m_lstRoster[i-1];
+ return -1;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Resource related code
+
+JABBER_RESOURCE_STATUS* CJabberProto::ListFindResource(JABBER_LIST list, const TCHAR *jid)
+{
+ mir_cslock lck(m_csLists);
+ JABBER_LIST_ITEM* LI = ListGetItemPtr(list, jid);
+ if (LI == NULL)
+ return NULL;
const TCHAR *p = _tcschr(jid, '@');
const TCHAR *q = _tcschr((p == NULL) ? jid : p, '/');
@@ -202,11 +229,10 @@ JABBER_RESOURCE_STATUS *CJabberProto::ListFindResource(JABBER_LIST list, const T
int CJabberProto::ListAddResource(JABBER_LIST list, const TCHAR *jid, int status, const TCHAR *statusMessage, char priority, const TCHAR *nick)
{
mir_cslockfull lck(m_csLists);
- int i = ListExist(list, jid);
- if (!i)
- return 0;
+ JABBER_LIST_ITEM* LI = ListGetItemPtr(list, jid);
+ if (LI == NULL)
+ return NULL;
- JABBER_LIST_ITEM* LI = m_lstRoster[i-1];
int bIsNewResource = false, j;
const TCHAR *p = _tcschr(jid, '@');
@@ -255,9 +281,8 @@ int CJabberProto::ListAddResource(JABBER_LIST list, const TCHAR *jid, int status
void CJabberProto::ListRemoveResource(JABBER_LIST list, const TCHAR *jid)
{
mir_cslockfull lck(m_csLists);
- int i = ListExist(list, jid);
- JABBER_LIST_ITEM *LI = m_lstRoster[i-1];
- if (i == 0 || LI == NULL)
+ JABBER_LIST_ITEM* LI = ListGetItemPtr(list, jid);
+ if (LI == NULL)
return;
const TCHAR *p = _tcschr(jid, '@');
@@ -311,13 +336,12 @@ void CJabberProto::ListRemoveResource(JABBER_LIST list, const TCHAR *jid)
TCHAR* CJabberProto::ListGetBestResourceNamePtr(const TCHAR *jid)
{
mir_cslock lck(m_csLists);
- int i = ListExist(LIST_ROSTER, jid);
- if (i == 0)
+ JABBER_LIST_ITEM* LI = ListGetItemPtr(LIST_ROSTER, jid);
+ if (LI == NULL)
return NULL;
TCHAR* res = NULL;
- JABBER_LIST_ITEM* LI = m_lstRoster[i-1];
if (LI->resourceCount > 1) {
if (LI->resourceMode == RSMODE_LASTSEEN && LI->pLastSeenResource)
res = LI->pLastSeenResource->resourceName;
@@ -345,83 +369,44 @@ TCHAR* CJabberProto::ListGetBestResourceNamePtr(const TCHAR *jid)
TCHAR* CJabberProto::ListGetBestClientResourceNamePtr(const TCHAR *jid)
{
mir_cslock lck(m_csLists);
- int i = ListExist(LIST_ROSTER, jid);
- if (i == 0)
+ JABBER_LIST_ITEM* LI = ListGetItemPtr(LIST_ROSTER, jid);
+ if (LI == NULL)
return NULL;
- JABBER_LIST_ITEM* LI = m_lstRoster[i-1];
TCHAR* res = ListGetBestResourceNamePtr(jid);
- if (res == NULL) {
- JABBER_RESOURCE_STATUS* r = LI->pResources;
- int status = ID_STATUS_OFFLINE;
- res = NULL;
- for (i=0; i < LI->resourceCount; i++) {
- int s = r[i].status;
- BOOL foundBetter = FALSE;
- switch (s) {
- case ID_STATUS_FREECHAT:
- foundBetter = TRUE;
- break;
- case ID_STATUS_ONLINE:
- if (status != ID_STATUS_FREECHAT)
- foundBetter = TRUE;
- break;
- case ID_STATUS_DND:
- if (status != ID_STATUS_FREECHAT && status != ID_STATUS_ONLINE)
- foundBetter = TRUE;
- break;
- case ID_STATUS_AWAY:
- if (status != ID_STATUS_FREECHAT && status != ID_STATUS_ONLINE && status != ID_STATUS_DND)
- foundBetter = TRUE;
- break;
- case ID_STATUS_NA:
- if (status != ID_STATUS_FREECHAT && status != ID_STATUS_ONLINE && status != ID_STATUS_DND && status != ID_STATUS_AWAY)
- foundBetter = TRUE;
- break;
- }
- if (foundBetter) {
- res = r[i].resourceName;
- status = s;
- } } }
+ if (res != NULL)
+ return res;
- return res;
-}
-
-int CJabberProto::ListFindNext(JABBER_LIST list, int fromOffset)
-{
- mir_cslock lck(m_csLists);
- int i = (fromOffset >= 0) ? fromOffset : 0;
- for (; i<m_lstRoster.getCount(); i++)
- if (m_lstRoster[i]->list == list)
- return i;
-
- return -1;
-}
-
-JABBER_LIST_ITEM *CJabberProto::ListGetItemPtr(JABBER_LIST list, const TCHAR *jid)
-{
- mir_cslock lck(m_csLists);
- int i = ListExist(list, jid);
- return (i == 0) ? NULL : m_lstRoster[i-1];
-}
-
-JABBER_LIST_ITEM *CJabberProto::ListGetItemPtrFromIndex(int index)
-{
- mir_cslock lck(m_csLists);
- if (index >= 0 && index < m_lstRoster.getCount())
- return m_lstRoster[index];
-
- return NULL;
-}
-
-BOOL CJabberProto::ListLock()
-{
- EnterCriticalSection(&m_csLists);
- return TRUE;
-}
+ JABBER_RESOURCE_STATUS *r = LI->pResources;
+ int status = ID_STATUS_OFFLINE;
+ res = NULL;
+ for (int i=0; i < LI->resourceCount; i++) {
+ bool foundBetter = false;
+ switch (r[i].status) {
+ case ID_STATUS_FREECHAT:
+ foundBetter = true;
+ break;
+ case ID_STATUS_ONLINE:
+ if (status != ID_STATUS_FREECHAT)
+ foundBetter = true;
+ break;
+ case ID_STATUS_DND:
+ if (status != ID_STATUS_FREECHAT && status != ID_STATUS_ONLINE)
+ foundBetter = true;
+ break;
+ case ID_STATUS_AWAY:
+ if (status != ID_STATUS_FREECHAT && status != ID_STATUS_ONLINE && status != ID_STATUS_DND)
+ foundBetter = true;
+ break;
+ case ID_STATUS_NA:
+ if (status != ID_STATUS_FREECHAT && status != ID_STATUS_ONLINE && status != ID_STATUS_DND && status != ID_STATUS_AWAY)
+ foundBetter = true;
+ break;
+ }
+ if (foundBetter) {
+ res = r[i].resourceName;
+ status = r[i].status;
+ } }
-BOOL CJabberProto::ListUnlock()
-{
- LeaveCriticalSection(&m_csLists);
- return TRUE;
+ return res;
}
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp
index c8af871226..fa3434d260 100644
--- a/protocols/JabberG/src/jabber_proto.cpp
+++ b/protocols/JabberG/src/jabber_proto.cpp
@@ -1169,7 +1169,7 @@ int __cdecl CJabberProto::SendMsg(HANDLE hContact, int flags, const char* pszSrc
return 0;
TCHAR *msgType;
- if (ListExist(LIST_CHATROOM, ptszJid) && _tcschr(ptszJid, '/') == NULL)
+ if (ListGetItemPtr(LIST_CHATROOM, ptszJid) && _tcschr(ptszJid, '/') == NULL)
msgType = _T("groupchat");
else
msgType = _T("chat");
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h
index dbd9c13a20..92bf19327b 100644
--- a/protocols/JabberG/src/jabber_proto.h
+++ b/protocols/JabberG/src/jabber_proto.h
@@ -646,10 +646,6 @@ struct CJabberProto : public PROTO<CJabberProto>
JABBER_LIST_ITEM *ListGetItemPtrFromIndex(int index);
void ListWipe(void);
- int ListExist(JABBER_LIST list, const TCHAR *jid);
-
- BOOL ListLock();
- BOOL ListUnlock();
void ListRemove(JABBER_LIST list, const TCHAR *jid);
void ListRemoveList(JABBER_LIST list);
diff --git a/protocols/JabberG/src/jabber_rc.cpp b/protocols/JabberG/src/jabber_rc.cpp
index dbe490c9c1..eb01bc219a 100644
--- a/protocols/JabberG/src/jabber_rc.cpp
+++ b/protocols/JabberG/src/jabber_rc.cpp
@@ -723,19 +723,19 @@ int CJabberProto::AdhocLeaveGroupchatsHandler(HXML, CJabberIqInfo* pInfo, CJabbe
int i = 0;
if (pSession->GetStage() == 0) {
// first form
- TCHAR szMsg[ 1024 ];
-
- ListLock();
int nChatsCount = 0;
- LISTFOREACH_NODEF(i, this, LIST_CHATROOM)
{
- JABBER_LIST_ITEM *item = ListGetItemPtrFromIndex(i);
- if (item != NULL)
- nChatsCount++;
+ mir_cslock lck(m_csLists);
+ LISTFOREACH_NODEF(i, this, LIST_CHATROOM)
+ {
+ JABBER_LIST_ITEM *item = ListGetItemPtrFromIndex(i);
+ if (item != NULL)
+ nChatsCount++;
+ }
}
- ListUnlock();
if ( !nChatsCount) {
+ TCHAR szMsg[ 1024 ];
mir_sntprintf(szMsg, SIZEOF(szMsg), TranslateT("There is no groupchats to leave"));
m_ThreadInfo->send(
@@ -764,15 +764,15 @@ int CJabberProto::AdhocLeaveGroupchatsHandler(HXML, CJabberIqInfo* pInfo, CJabbe
// Groupchats
HXML fieldNode = xNode << XCHILD(_T("field")) << XATTR(_T("label"), NULL) << XATTR(_T("type"), _T("list-multi")) << XATTR(_T("var"), _T("groupchats"));
fieldNode << XCHILD(_T("required"));
-
- ListLock();
- LISTFOREACH_NODEF(i, this, LIST_CHATROOM)
{
- JABBER_LIST_ITEM *item = ListGetItemPtrFromIndex(i);
- if (item != NULL)
- fieldNode << XCHILD(_T("option")) << XATTR(_T("label"), item->jid) << XCHILD(_T("value"), item->jid);
+ mir_cslock lck(m_csLists);
+ LISTFOREACH_NODEF(i, this, LIST_CHATROOM)
+ {
+ JABBER_LIST_ITEM *item = ListGetItemPtrFromIndex(i);
+ if (item != NULL)
+ fieldNode << XCHILD(_T("option")) << XATTR(_T("label"), item->jid) << XCHILD(_T("value"), item->jid);
+ }
}
- ListUnlock();
m_ThreadInfo->send(iq);
return JABBER_ADHOC_HANDLER_STATUS_EXECUTING;
diff --git a/protocols/JabberG/src/jabber_svc.cpp b/protocols/JabberG/src/jabber_svc.cpp
index a6780f4f63..9d77a9addc 100644
--- a/protocols/JabberG/src/jabber_svc.cpp
+++ b/protocols/JabberG/src/jabber_svc.cpp
@@ -797,10 +797,8 @@ LPTSTR CJabberSysInterface::GetBestResourceName(LPCTSTR jid)
return NULL;
LPCTSTR p = _tcschr(jid, '/');
if (p == NULL) {
- m_psProto->ListLock(); // make sure we allow access to the list only after making mir_tstrdup() of resource name
- LPTSTR res = mir_tstrdup(m_psProto->ListGetBestClientResourceNamePtr(jid));
- m_psProto->ListUnlock();
- return res;
+ mir_cslock lck(m_psProto->m_csLists);
+ return mir_tstrdup(m_psProto->ListGetBestClientResourceNamePtr(jid));
}
return mir_tstrdup(jid);
}
@@ -810,19 +808,15 @@ LPTSTR CJabberSysInterface::GetResourceList(LPCTSTR jid)
if ( !jid)
return NULL;
- m_psProto->ListLock();
+ mir_cslock lck(m_psProto->m_csLists);
JABBER_LIST_ITEM *item = NULL;
if ((item = m_psProto->ListGetItemPtr(LIST_VCARD_TEMP, jid)) == NULL)
item = m_psProto->ListGetItemPtr(LIST_ROSTER, jid);
- if (item == NULL) {
- m_psProto->ListUnlock();
+ if (item == NULL)
return NULL;
- }
- if (item->pResources == NULL) {
- m_psProto->ListUnlock();
+ if (item->pResources == NULL)
return NULL;
- }
int i;
int iLen = 1; // 1 for extra zero terminator at the end of the string
@@ -839,7 +833,6 @@ LPTSTR CJabberSysInterface::GetResourceList(LPCTSTR jid)
}
*p = 0; // extra zero terminator
- m_psProto->ListUnlock();
return str;
}
@@ -978,10 +971,9 @@ int CJabberNetInterface::RegisterFeature(LPCTSTR szFeature, LPCTSTR szDescriptio
}
}
- m_psProto->ListLock();
+ mir_cslock lck(m_psProto->m_csLists);
JabberFeatCapPairDynamic *fcp = FindFeature(szFeature);
- if ( !fcp) {
- // if the feature is not registered yet, allocate new bit for it
+ if ( !fcp) { // if the feature is not registered yet, allocate new bit for it
JabberCapsBits jcb = JABBER_CAPS_OTHER_SPECIAL; // set all bits not included in g_JabberFeatCapPairs
// set all bits occupied by g_JabberFeatCapPairs
@@ -995,20 +987,16 @@ int CJabberNetInterface::RegisterFeature(LPCTSTR szFeature, LPCTSTR szDescriptio
// Now get first zero bit. The line below is a fast way to do it. If there are no zero bits, it returns 0.
jcb = (~jcb) & (JabberCapsBits)(-(__int64)(~jcb));
- if ( !jcb) {
// no more free bits
- m_psProto->ListUnlock();
+ if ( !jcb)
return false;
- }
+ // remove unnecessary symbols from szFeature to make the string shorter, and use it as szExt
LPTSTR szExt = mir_tstrdup(szFeature);
LPTSTR pSrc, pDst;
- for (pSrc = szExt, pDst = szExt; *pSrc; pSrc++) {
- // remove unnecessary symbols from szFeature to make the string shorter, and use it as szExt
- if (_tcschr(_T("bcdfghjklmnpqrstvwxz0123456789"), *pSrc)) {
+ for (pSrc = szExt, pDst = szExt; *pSrc; pSrc++)
+ if (_tcschr(_T("bcdfghjklmnpqrstvwxz0123456789"), *pSrc))
*pDst++ = *pSrc;
- }
- }
*pDst = 0;
m_psProto->m_clientCapsManager.SetClientCaps(_T(JABBER_CAPS_MIRANDA_NODE), szExt, jcb);
@@ -1018,116 +1006,106 @@ int CJabberNetInterface::RegisterFeature(LPCTSTR szFeature, LPCTSTR szDescriptio
fcp->szDescription = szDescription ? mir_tstrdup(szDescription) : NULL;
fcp->jcbCap = jcb;
m_psProto->m_lstJabberFeatCapPairsDynamic.insert(fcp);
- } else if (szDescription) {
- // update description
+ }
+ else if (szDescription) { // update description
if (fcp->szDescription)
mir_free(fcp->szDescription);
fcp->szDescription = mir_tstrdup(szDescription);
}
- m_psProto->ListUnlock();
return true;
}
int CJabberNetInterface::AddFeatures(LPCTSTR szFeatures)
{
- if ( !szFeatures) {
+ if ( !szFeatures)
return false;
- }
- m_psProto->ListLock();
+ mir_cslockfull lck(m_psProto->m_csLists);
BOOL ret = true;
LPCTSTR szFeat = szFeatures;
while (szFeat[0]) {
JabberFeatCapPairDynamic *fcp = FindFeature(szFeat);
// if someone is trying to add one of core features, RegisterFeature() will return false, so we don't have to perform this check here
- if ( !fcp) {
- // if the feature is not registered yet
- if ( !RegisterFeature(szFeat, NULL)) {
+ if ( !fcp) { // if the feature is not registered yet
+ if ( !RegisterFeature(szFeat, NULL))
ret = false;
- } else {
+ else
fcp = FindFeature(szFeat); // update fcp after RegisterFeature()
- }
}
- if (fcp) {
+ if (fcp)
m_psProto->m_uEnabledFeatCapsDynamic |= fcp->jcbCap;
- } else {
+ else
ret = false;
- }
szFeat += lstrlen(szFeat) + 1;
}
- m_psProto->ListUnlock();
+ lck.unlock();
- if (m_psProto->m_bJabberOnline) {
+ if (m_psProto->m_bJabberOnline)
m_psProto->SendPresence(m_psProto->m_iStatus, true);
- }
+
return ret;
}
int CJabberNetInterface::RemoveFeatures(LPCTSTR szFeatures)
{
- if ( !szFeatures) {
+ if ( !szFeatures)
return false;
- }
- m_psProto->ListLock();
+ mir_cslockfull lck(m_psProto->m_csLists);
BOOL ret = true;
LPCTSTR szFeat = szFeatures;
while (szFeat[0]) {
JabberFeatCapPairDynamic *fcp = FindFeature(szFeat);
- if (fcp) {
+ if (fcp)
m_psProto->m_uEnabledFeatCapsDynamic &= ~fcp->jcbCap;
- } else {
+ else
ret = false; // indicate that there was an error removing at least one of the specified features
- }
+
szFeat += lstrlen(szFeat) + 1;
}
- m_psProto->ListUnlock();
+ lck.unlock();
- if (m_psProto->m_bJabberOnline) {
+ if (m_psProto->m_bJabberOnline)
m_psProto->SendPresence(m_psProto->m_iStatus, true);
- }
+
return ret;
}
LPTSTR CJabberNetInterface::GetResourceFeatures(LPCTSTR jid)
{
JabberCapsBits jcb = m_psProto->GetResourceCapabilites(jid, true);
- if ( !(jcb & JABBER_RESOURCE_CAPS_ERROR)) {
- m_psProto->ListLock(); // contents of m_lstJabberFeatCapPairsDynamic must not change from the moment we calculate total length and to the moment when we fill the string
- int i;
- int iLen = 1; // 1 for extra zero terminator at the end of the string
- // calculate total necessary string length
- for (i = 0; g_JabberFeatCapPairs[i].szFeature; i++) {
- if (jcb & g_JabberFeatCapPairs[i].jcbCap) {
- iLen += lstrlen(g_JabberFeatCapPairs[i].szFeature) + 1;
- }
- }
- for (i = 0; i < m_psProto->m_lstJabberFeatCapPairsDynamic.getCount(); i++) {
- if (jcb & m_psProto->m_lstJabberFeatCapPairsDynamic[i]->jcbCap) {
- iLen += lstrlen(m_psProto->m_lstJabberFeatCapPairsDynamic[i]->szFeature) + 1;
- }
- }
+ if (jcb & JABBER_RESOURCE_CAPS_ERROR)
+ return NULL;
- // allocate memory and fill it
- LPTSTR str = (LPTSTR)mir_alloc(iLen * sizeof(TCHAR));
- LPTSTR p = str;
- for (i = 0; g_JabberFeatCapPairs[i].szFeature; i++) {
- if (jcb & g_JabberFeatCapPairs[i].jcbCap) {
- lstrcpy(p, g_JabberFeatCapPairs[i].szFeature);
- p += lstrlen(g_JabberFeatCapPairs[i].szFeature) + 1;
- }
+ mir_cslockfull lck(m_psProto->m_csLists);
+ int i;
+ int iLen = 1; // 1 for extra zero terminator at the end of the string
+ // calculate total necessary string length
+ for (i = 0; g_JabberFeatCapPairs[i].szFeature; i++)
+ if (jcb & g_JabberFeatCapPairs[i].jcbCap)
+ iLen += lstrlen(g_JabberFeatCapPairs[i].szFeature) + 1;
+
+ for (i = 0; i < m_psProto->m_lstJabberFeatCapPairsDynamic.getCount(); i++)
+ if (jcb & m_psProto->m_lstJabberFeatCapPairsDynamic[i]->jcbCap)
+ iLen += lstrlen(m_psProto->m_lstJabberFeatCapPairsDynamic[i]->szFeature) + 1;
+
+ // allocate memory and fill it
+ LPTSTR str = (LPTSTR)mir_alloc(iLen * sizeof(TCHAR));
+ LPTSTR p = str;
+ for (i = 0; g_JabberFeatCapPairs[i].szFeature; i++)
+ if (jcb & g_JabberFeatCapPairs[i].jcbCap) {
+ lstrcpy(p, g_JabberFeatCapPairs[i].szFeature);
+ p += lstrlen(g_JabberFeatCapPairs[i].szFeature) + 1;
}
- for (i = 0; i < m_psProto->m_lstJabberFeatCapPairsDynamic.getCount(); i++) {
- if (jcb & m_psProto->m_lstJabberFeatCapPairsDynamic[i]->jcbCap) {
- lstrcpy(p, m_psProto->m_lstJabberFeatCapPairsDynamic[i]->szFeature);
- p += lstrlen(m_psProto->m_lstJabberFeatCapPairsDynamic[i]->szFeature) + 1;
- }
+
+ for (i = 0; i < m_psProto->m_lstJabberFeatCapPairsDynamic.getCount(); i++)
+ if (jcb & m_psProto->m_lstJabberFeatCapPairsDynamic[i]->jcbCap) {
+ lstrcpy(p, m_psProto->m_lstJabberFeatCapPairsDynamic[i]->szFeature);
+ p += lstrlen(m_psProto->m_lstJabberFeatCapPairsDynamic[i]->szFeature) + 1;
}
- *p = 0; // extra zero terminator
- m_psProto->ListUnlock();
- return str;
- }
- return NULL;
+
+ *p = 0; // extra zero terminator
+ return str;
}
HANDLE CJabberNetInterface::GetHandle()
diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp
index a37074a14c..d16a5a1f15 100644
--- a/protocols/JabberG/src/jabber_thread.cpp
+++ b/protocols/JabberG/src/jabber_thread.cpp
@@ -1609,7 +1609,7 @@ void CJabberProto::OnProcessPresence(HXML node, ThreadData* info)
if (m_presenceManager.HandlePresencePermanent(node, info))
return;
- if (ListExist(LIST_CHATROOM, from)) {
+ if (ListGetItemPtr(LIST_CHATROOM, from)) {
GroupchatProcessPresence(node);
return;
}
@@ -1629,14 +1629,14 @@ void CJabberProto::OnProcessPresence(HXML node, ThreadData* info)
return;
if ((hContact = HContactFromJID(from)) == NULL) {
- if ( !_tcsicmp(info->fullJID, from) || (!bSelfPresence && !ListExist(LIST_ROSTER, from))) {
+ if ( !_tcsicmp(info->fullJID, from) || (!bSelfPresence && !ListGetItemPtr(LIST_ROSTER, from))) {
Log("SKIP Receive presence online from %S (who is not in my roster and not in list - skiping)", from);
mir_free(nick);
return;
}
hContact = DBCreateContact(from, nick, TRUE, TRUE);
}
- if ( !ListExist(LIST_ROSTER, from)) {
+ if ( !ListGetItemPtr(LIST_ROSTER, from)) {
Log("Receive presence online from %S (who is not in my roster)", from);
ListAdd(LIST_ROSTER, from);
}