diff options
author | George Hazan <george.hazan@gmail.com> | 2013-07-25 06:36:29 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-07-25 06:36:29 +0000 |
commit | 1662307100ce7cd803321f5dd9052ce67d037279 (patch) | |
tree | 8c9990338f1e1bbda2909f16c902537e4f400968 /protocols | |
parent | d12d5e2d51b892e5c65168643e63723e8a9739f8 (diff) |
attemt to fix hangup in Jabber
git-svn-id: http://svn.miranda-ng.org/main/trunk@5479 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/JabberG/src/jabber_list.cpp | 219 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_svc.cpp | 58 |
2 files changed, 141 insertions, 136 deletions
diff --git a/protocols/JabberG/src/jabber_list.cpp b/protocols/JabberG/src/jabber_list.cpp index aaf41f912b..836580ffcf 100644 --- a/protocols/JabberG/src/jabber_list.cpp +++ b/protocols/JabberG/src/jabber_list.cpp @@ -91,44 +91,46 @@ void CJabberProto::ListWipe(void) JABBER_LIST_ITEM *CJabberProto::ListAdd(JABBER_LIST list, const TCHAR *jid)
{
+ JABBER_LIST_ITEM *item;
bool bUseResource = false;
- 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';
+ {
+ 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';
+ }
}
- }
- 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);
- lck.unlock();
+ 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);
+ }
MenuUpdateSrmmIcon(item);
return item;
@@ -231,95 +233,96 @@ 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;
-
- 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);
+ 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);
+ }
}
- lck.unlock();
-
MenuUpdateSrmmIcon(LI);
return bIsNewResource;
}
void CJabberProto::ListRemoveResource(JABBER_LIST list, const TCHAR *jid)
{
- mir_cslockfull lck(m_csLists);
- JABBER_LIST_ITEM *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;
+ 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;
+ }
}
- }
- // Update MirVer due to possible resource changes
- UpdateMirVer(LI);
+ // Update MirVer due to possible resource changes
+ UpdateMirVer(LI);
- JabberListFreeResourceInternal(r);
+ 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));
+ 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);
}
diff --git a/protocols/JabberG/src/jabber_svc.cpp b/protocols/JabberG/src/jabber_svc.cpp index c8a3bedb96..d65d9687bf 100644 --- a/protocols/JabberG/src/jabber_svc.cpp +++ b/protocols/JabberG/src/jabber_svc.cpp @@ -1011,25 +1011,26 @@ int CJabberNetInterface::AddFeatures(LPCTSTR szFeatures) if ( !szFeatures)
return false;
- 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;
+ 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
- fcp = FindFeature(szFeat); // update fcp after RegisterFeature()
+ ret = false;
+ szFeat += lstrlen(szFeat) + 1;
}
- 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);
@@ -1042,19 +1043,20 @@ int CJabberNetInterface::RemoveFeatures(LPCTSTR szFeatures) if ( !szFeatures)
return false;
- 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
+ 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
- szFeat += lstrlen(szFeat) + 1;
+ szFeat += lstrlen(szFeat) + 1;
+ }
}
- lck.unlock();
if (m_psProto->m_bJabberOnline)
m_psProto->SendPresence(m_psProto->m_iStatus, true);
@@ -1068,7 +1070,7 @@ LPTSTR CJabberNetInterface::GetResourceFeatures(LPCTSTR jid) if (jcb & JABBER_RESOURCE_CAPS_ERROR)
return NULL;
- mir_cslockfull lck(m_psProto->m_csLists);
+ mir_cslock 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
|