diff options
-rw-r--r-- | protocols/JabberG/src/jabber_list.cpp | 229 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_svc.cpp | 58 |
2 files changed, 142 insertions, 145 deletions
diff --git a/protocols/JabberG/src/jabber_list.cpp b/protocols/JabberG/src/jabber_list.cpp index 836580ffcf..c33d83140c 100644 --- a/protocols/JabberG/src/jabber_list.cpp +++ b/protocols/JabberG/src/jabber_list.cpp @@ -91,47 +91,45 @@ void CJabberProto::ListWipe(void) JABBER_LIST_ITEM *CJabberProto::ListAdd(JABBER_LIST list, const TCHAR *jid)
{
- JABBER_LIST_ITEM *item;
bool bUseResource = false;
- {
- mir_cslock lck(m_csLists);
-
- item = ListGetItemPtr(list, jid);
- if (item != NULL)
- 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_VCARD_TEMP) {
- TCHAR *p;
- if ((p = _tcschr(s, '@')) != NULL)
- if ((q = _tcschr(p, '/')) != NULL)
- *q = '\0';
- }
+ mir_cslockfull lck(m_csLists);
+
+ JABBER_LIST_ITEM *item = ListGetItemPtr(list, jid);
+ if (item != NULL)
+ 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_VCARD_TEMP) {
+ TCHAR *p;
+ if ((p = _tcschr(s, '@')) != NULL)
+ if ((q = _tcschr(p, '/')) != NULL)
+ *q = '\0';
}
- 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;
- }
+ }
+ 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;
}
-
- item = (JABBER_LIST_ITEM*)mir_calloc(sizeof(JABBER_LIST_ITEM));
- item->list = list;
- item->jid = s;
- item->itemResource.status = ID_STATUS_OFFLINE;
- item->resourceMode = RSMODE_LASTSEEN;
- item->bUseResource = bUseResource;
- m_lstRoster.insert(item);
}
+ item = (JABBER_LIST_ITEM*)mir_calloc(sizeof(JABBER_LIST_ITEM));
+ item->list = list;
+ item->jid = s;
+ item->itemResource.status = ID_STATUS_OFFLINE;
+ item->resourceMode = RSMODE_LASTSEEN;
+ item->bUseResource = bUseResource;
+ m_lstRoster.insert(item);
+ lck.unlock();
+
MenuUpdateSrmmIcon(item);
return item;
}
@@ -233,96 +231,95 @@ 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);
+ JABBER_LIST_ITEM *LI = ListGetItemPtr(list, jid);
+ if (LI == NULL)
+ return NULL;
+
bool bIsNewResource = false;
- JABBER_LIST_ITEM *LI;
- {
- mir_cslock lck(m_csLists);
- LI = ListGetItemPtr(list, jid);
- if (LI == NULL)
- return NULL;
-
- const TCHAR *p = _tcschr(jid, '@');
- const TCHAR *q = _tcschr((p == NULL) ? jid : p, '/');
- if (q) {
- const TCHAR *resource = q+1;
- if (resource[0]) {
- JABBER_RESOURCE_STATUS *r = LI->findResource(resource);
- if (r != NULL) { // Already exists, update status and statusMessage
- r->status = status;
- replaceStrT(r->statusMessage, statusMessage);
- r->priority = priority;
- }
- else { // Does not exist, add new resource
- LI->pResources = (JABBER_RESOURCE_STATUS *)mir_realloc(LI->pResources, (LI->resourceCount+1)*sizeof(JABBER_RESOURCE_STATUS));
- bIsNewResource = true;
- r = LI->pResources + LI->resourceCount++;
- memset(r, 0, sizeof(JABBER_RESOURCE_STATUS));
- r->status = status;
- r->affiliation = AFFILIATION_NONE;
- r->role = ROLE_NONE;
- r->resourceName = mir_tstrdup(resource);
- r->nick = mir_tstrdup(nick);
- if (statusMessage)
- r->statusMessage = mir_tstrdup(statusMessage);
- r->priority = priority;
- } }
- }
- // No resource, update the main statusMessage
- else {
- LI->itemResource.status = status;
- replaceStrT(LI->itemResource.statusMessage, statusMessage);
- }
+
+ const TCHAR *p = _tcschr(jid, '@');
+ const TCHAR *q = _tcschr((p == NULL) ? jid : p, '/');
+ if (q) {
+ const TCHAR *resource = q+1;
+ if (resource[0]) {
+ JABBER_RESOURCE_STATUS *r = LI->findResource(resource);
+ if (r != NULL) { // Already exists, update status and statusMessage
+ r->status = status;
+ replaceStrT(r->statusMessage, statusMessage);
+ r->priority = priority;
+ }
+ else { // Does not exist, add new resource
+ LI->pResources = (JABBER_RESOURCE_STATUS *)mir_realloc(LI->pResources, (LI->resourceCount+1)*sizeof(JABBER_RESOURCE_STATUS));
+ bIsNewResource = true;
+ r = LI->pResources + LI->resourceCount++;
+ memset(r, 0, sizeof(JABBER_RESOURCE_STATUS));
+ r->status = status;
+ r->affiliation = AFFILIATION_NONE;
+ r->role = ROLE_NONE;
+ r->resourceName = mir_tstrdup(resource);
+ r->nick = mir_tstrdup(nick);
+ if (statusMessage)
+ r->statusMessage = mir_tstrdup(statusMessage);
+ r->priority = priority;
+ } }
+ }
+ // No resource, update the main statusMessage
+ else {
+ LI->itemResource.status = status;
+ replaceStrT(LI->itemResource.statusMessage, statusMessage);
}
+ lck.unlock();
+
MenuUpdateSrmmIcon(LI);
return bIsNewResource;
}
void CJabberProto::ListRemoveResource(JABBER_LIST list, const TCHAR *jid)
{
- JABBER_LIST_ITEM *LI;
- {
- mir_cslock lck(m_csLists);
- LI = ListGetItemPtr(list, jid);
- if (LI == NULL)
- return;
-
- const TCHAR *p = _tcschr(jid, '@');
- const TCHAR *q = _tcschr((p == NULL) ? jid : p, '/');
- if (q == NULL)
- return;
-
- JABBER_RESOURCE_STATUS *r = LI->findResource(q+1);
- if (r == NULL)
- return;
-
- // Found last seen resource ID to be removed
- if (LI->pLastSeenResource == r)
- LI->pLastSeenResource = NULL;
-
- // update manually selected resource ID
- if (LI->resourceMode == RSMODE_MANUAL) {
- if (LI->pManualResource == r) {
- LI->resourceMode = RSMODE_LASTSEEN;
- LI->pManualResource = NULL;
- }
- }
+ mir_cslockfull lck(m_csLists);
+ JABBER_LIST_ITEM *LI = ListGetItemPtr(list, jid);
+ if (LI == NULL)
+ return;
- // Update MirVer due to possible resource changes
- UpdateMirVer(LI);
+ const TCHAR *p = _tcschr(jid, '@');
+ const TCHAR *q = _tcschr((p == NULL) ? jid : p, '/');
+ if (q == NULL)
+ return;
- JabberListFreeResourceInternal(r);
+ JABBER_RESOURCE_STATUS *r = LI->findResource(q+1);
+ if (r == NULL)
+ return;
- if (LI->resourceCount-- == 1) {
- mir_free(r);
- LI->pResources = NULL;
- }
- else {
- memmove(r, r+1, (LI->resourceCount - (r-LI->pResources))*sizeof(JABBER_RESOURCE_STATUS));
- LI->pResources = (JABBER_RESOURCE_STATUS*)mir_realloc(LI->pResources, LI->resourceCount*sizeof(JABBER_RESOURCE_STATUS));
+ // Found last seen resource ID to be removed
+ if (LI->pLastSeenResource == r)
+ LI->pLastSeenResource = NULL;
+
+ // update manually selected resource ID
+ if (LI->resourceMode == RSMODE_MANUAL) {
+ if (LI->pManualResource == r) {
+ LI->resourceMode = RSMODE_LASTSEEN;
+ LI->pManualResource = NULL;
}
}
+ // Update MirVer due to possible resource changes
+ UpdateMirVer(LI);
+
+ JabberListFreeResourceInternal(r);
+
+ if (LI->resourceCount-- == 1) {
+ mir_free(r);
+ LI->pResources = NULL;
+ }
+ else {
+ memmove(r, r+1, (LI->resourceCount - (r-LI->pResources))*sizeof(JABBER_RESOURCE_STATUS));
+ LI->pResources = (JABBER_RESOURCE_STATUS*)mir_realloc(LI->pResources, LI->resourceCount*sizeof(JABBER_RESOURCE_STATUS));
+ }
+
+ lck.unlock();
+
MenuUpdateSrmmIcon(LI);
}
@@ -365,8 +362,9 @@ TCHAR* CJabberProto::ListGetBestClientResourceNamePtr(const TCHAR *jid) int status = ID_STATUS_OFFLINE;
TCHAR *res = NULL;
for (int i=0; i < LI->resourceCount; i++) {
+ r = &LI->pResources[i];
bool foundBetter = false;
- switch (r[i].status) {
+ switch (r->status) {
case ID_STATUS_FREECHAT:
foundBetter = true;
break;
@@ -388,9 +386,10 @@ TCHAR* CJabberProto::ListGetBestClientResourceNamePtr(const TCHAR *jid) break;
}
if (foundBetter) {
- res = LI->pResources[i].resourceName;
- status = LI->pResources[i].status;
- } }
+ res = r->resourceName;
+ status = r->status;
+ }
+ }
return res;
}
diff --git a/protocols/JabberG/src/jabber_svc.cpp b/protocols/JabberG/src/jabber_svc.cpp index d65d9687bf..c8a3bedb96 100644 --- a/protocols/JabberG/src/jabber_svc.cpp +++ b/protocols/JabberG/src/jabber_svc.cpp @@ -1011,26 +1011,25 @@ int CJabberNetInterface::AddFeatures(LPCTSTR szFeatures) if ( !szFeatures)
return false;
- bool ret = true;
- {
- mir_cslock lck(m_psProto->m_csLists);
- 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))
- ret = false;
- else
- fcp = FindFeature(szFeat); // update fcp after RegisterFeature()
- }
- if (fcp)
- m_psProto->m_uEnabledFeatCapsDynamic |= fcp->jcbCap;
- else
+ 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))
ret = false;
- szFeat += lstrlen(szFeat) + 1;
+ else
+ fcp = FindFeature(szFeat); // update fcp after RegisterFeature()
}
+ if (fcp)
+ m_psProto->m_uEnabledFeatCapsDynamic |= fcp->jcbCap;
+ else
+ ret = false;
+ szFeat += lstrlen(szFeat) + 1;
}
+ lck.unlock();
if (m_psProto->m_bJabberOnline)
m_psProto->SendPresence(m_psProto->m_iStatus, true);
@@ -1043,20 +1042,19 @@ int CJabberNetInterface::RemoveFeatures(LPCTSTR szFeatures) if ( !szFeatures)
return false;
- bool ret = true;
- {
- mir_cslock lck(m_psProto->m_csLists);
- LPCTSTR szFeat = szFeatures;
- while (szFeat[0]) {
- JabberFeatCapPairDynamic *fcp = FindFeature(szFeat);
- if (fcp)
- m_psProto->m_uEnabledFeatCapsDynamic &= ~fcp->jcbCap;
- else
- ret = false; // indicate that there was an error removing at least one of the specified features
+ mir_cslockfull lck(m_psProto->m_csLists);
+ BOOL ret = true;
+ LPCTSTR szFeat = szFeatures;
+ while (szFeat[0]) {
+ JabberFeatCapPairDynamic *fcp = FindFeature(szFeat);
+ if (fcp)
+ m_psProto->m_uEnabledFeatCapsDynamic &= ~fcp->jcbCap;
+ else
+ ret = false; // indicate that there was an error removing at least one of the specified features
- szFeat += lstrlen(szFeat) + 1;
- }
+ szFeat += lstrlen(szFeat) + 1;
}
+ lck.unlock();
if (m_psProto->m_bJabberOnline)
m_psProto->SendPresence(m_psProto->m_iStatus, true);
@@ -1070,7 +1068,7 @@ LPTSTR CJabberNetInterface::GetResourceFeatures(LPCTSTR jid) if (jcb & JABBER_RESOURCE_CAPS_ERROR)
return NULL;
- mir_cslock lck(m_psProto->m_csLists);
+ 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
|