diff options
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/JabberG/src/jabber_chat.cpp | 8 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_groupchat.cpp | 82 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_list.cpp | 60 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_list.h | 1 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_proto.cpp | 10 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_proto.h | 1 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_svc.cpp | 12 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_thread.cpp | 12 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_util.cpp | 18 |
9 files changed, 77 insertions, 127 deletions
diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp index d3315aff28..84cae898da 100644 --- a/protocols/JabberG/src/jabber_chat.cpp +++ b/protocols/JabberG/src/jabber_chat.cpp @@ -1453,11 +1453,9 @@ static void sttSendPrivateMessage(CJabberProto *ppro, JABBER_LIST_ITEM *item, co mir_sntprintf(szFullJid, SIZEOF(szFullJid), _T("%s/%s"), item->jid, nick);
HANDLE hContact = ppro->DBCreateContact(szFullJid, NULL, TRUE, FALSE);
if (hContact != NULL) {
- for (int i=0; i < item->resourceCount; i++) {
- if (_tcsicmp(item->pResources[i].resourceName, nick) == 0) {
- ppro->setWord(hContact, "Status", item->pResources[i].status);
- break;
- } }
+ JABBER_RESOURCE_STATUS *r = item->findResource(nick);
+ if (r)
+ ppro->setWord(hContact, "Status", r->status);
db_set_b(hContact, "CList", "Hidden", 1);
ppro->setTString(hContact, "Nick", nick);
diff --git a/protocols/JabberG/src/jabber_groupchat.cpp b/protocols/JabberG/src/jabber_groupchat.cpp index 03ccab63c9..a0655c0d27 100644 --- a/protocols/JabberG/src/jabber_groupchat.cpp +++ b/protocols/JabberG/src/jabber_groupchat.cpp @@ -200,17 +200,6 @@ private: }
};
-JABBER_RESOURCE_STATUS* CJabberProto::GcFindResource(JABBER_LIST_ITEM *item, const TCHAR *resource)
-{
- 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))
- return &r[i];
-
- return NULL;
-}
-
INT_PTR __cdecl CJabberProto::OnMenuHandleJoinGroupchat(WPARAM, LPARAM)
{
if (jabberChatDllPresent)
@@ -870,45 +859,45 @@ static int sttGetStatusCode(HXML node) void CJabberProto::RenameParticipantNick(JABBER_LIST_ITEM *item, const TCHAR *oldNick, HXML itemNode)
{
- const TCHAR *newNick = xmlGetAttrValue(itemNode, _T("nick"));
const TCHAR *jid = xmlGetAttrValue(itemNode, _T("jid"));
+ const TCHAR *newNick = xmlGetAttrValue(itemNode, _T("nick"));
if (newNick == NULL)
return;
- for (int i=0; i < item->resourceCount; i++) {
- JABBER_RESOURCE_STATUS& RS = item->pResources[i];
- if ( !lstrcmp(RS.resourceName, oldNick)) {
- replaceStrT(RS.resourceName, newNick);
+ JABBER_RESOURCE_STATUS *r = item->findResource(oldNick);
+ if (r == NULL)
+ return;
+
+ replaceStrT(r->resourceName, newNick);
- if ( !lstrcmp(item->nick, oldNick)) {
- replaceStrT(item->nick, newNick);
+ if ( !lstrcmp(item->nick, oldNick)) {
+ replaceStrT(item->nick, newNick);
- HANDLE hContact = HContactFromJID(item->jid);
- if (hContact != NULL)
- setTString(hContact, "MyNick", newNick);
- }
+ HANDLE hContact = HContactFromJID(item->jid);
+ if (hContact != NULL)
+ setTString(hContact, "MyNick", newNick);
+ }
- GCDEST gcd = { m_szModuleName, NULL, GC_EVENT_CHUID };
- gcd.ptszID = item->jid;
-
- GCEVENT gce = {0};
- gce.cbSize = sizeof(GCEVENT);
- gce.pDest = &gcd;
- gce.ptszNick = oldNick;
- gce.ptszText = newNick;
- if (jid != NULL)
- gce.ptszUserInfo = jid;
- gce.time = time(0);
- gce.dwFlags = GC_TCHAR;
- CallServiceSync(MS_GC_EVENT, NULL, (LPARAM)&gce);
-
- gcd.iType = GC_EVENT_NICK;
- gce.ptszNick = oldNick;
- gce.ptszUID = newNick;
- gce.ptszText = newNick;
- CallServiceSync(MS_GC_EVENT, NULL, (LPARAM)&gce);
- break;
-} } }
+ GCDEST gcd = { m_szModuleName, NULL, GC_EVENT_CHUID };
+ gcd.ptszID = item->jid;
+
+ GCEVENT gce = {0};
+ gce.cbSize = sizeof(GCEVENT);
+ gce.pDest = &gcd;
+ gce.ptszNick = oldNick;
+ gce.ptszText = newNick;
+ if (jid != NULL)
+ gce.ptszUserInfo = jid;
+ gce.time = time(0);
+ gce.dwFlags = GC_TCHAR;
+ CallServiceSync(MS_GC_EVENT, NULL, (LPARAM)&gce);
+
+ gcd.iType = GC_EVENT_NICK;
+ gce.ptszNick = oldNick;
+ gce.ptszUID = newNick;
+ gce.ptszText = newNick;
+ CallServiceSync(MS_GC_EVENT, NULL, (LPARAM)&gce);
+}
void CJabberProto::GroupchatProcessPresence(HXML node)
{
@@ -925,7 +914,7 @@ void CJabberProto::GroupchatProcessPresence(HXML node) if (item == NULL)
return;
- JABBER_RESOURCE_STATUS *r = GcFindResource(item, resource);
+ JABBER_RESOURCE_STATUS *r = item->findResource(resource);
HXML nNode = xmlGetChildByTag(node, "nick", "xmlns", JABBER_FEAT_NICK);
if (nNode == NULL)
@@ -940,7 +929,6 @@ void CJabberProto::GroupchatProcessPresence(HXML node) HXML xNode = xmlGetChildByTag(node, "x", "xmlns", JABBER_FEAT_MUC_USER);
HXML xUserNode = xmlGetChildByTag(node, "user:x", "xmlns:user", JABBER_FEAT_MUC_USER);
-
HXML itemNode = xmlGetChild(xNode , "item");
const TCHAR *type = xmlGetAttrValue(node, _T("type"));
@@ -980,7 +968,7 @@ void CJabberProto::GroupchatProcessPresence(HXML node) // Check additional MUC info for this user
if (itemNode != NULL) {
if (r == NULL)
- r = GcFindResource(item, resource);
+ r = item->findResource(resource);
if (r != NULL) {
JABBER_GC_AFFILIATION affiliation = r->affiliation;
JABBER_GC_ROLE role = r->role;
@@ -1210,7 +1198,7 @@ void CJabberProto::GroupchatProcessMessage(HXML node) msgTime = now;
if (resource != NULL) {
- JABBER_RESOURCE_STATUS *r = GcFindResource(item, resource);
+ JABBER_RESOURCE_STATUS *r = item->findResource(resource);
nick = r && r->nick ? r->nick : resource;
}
else nick = NULL;
diff --git a/protocols/JabberG/src/jabber_list.cpp b/protocols/JabberG/src/jabber_list.cpp index 67ab77fcf1..aaf41f912b 100644 --- a/protocols/JabberG/src/jabber_list.cpp +++ b/protocols/JabberG/src/jabber_list.cpp @@ -195,7 +195,7 @@ 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++)
+ for (; i < m_lstRoster.getCount(); i++)
if (m_lstRoster[i]->list == list)
return i;
@@ -205,6 +205,18 @@ int CJabberProto::ListFindNext(JABBER_LIST list, int fromOffset) /////////////////////////////////////////////////////////////////////////////////////////
// Resource related code
+JABBER_RESOURCE_STATUS* JABBER_LIST_ITEM::findResource(const TCHAR *resourceName) const
+{
+ if (pResources == NULL || resourceName == NULL || *resourceName == 0)
+ return NULL;
+
+ for (int i=0; i < resourceCount; i++)
+ if ( !_tcscmp(pResources[i].resourceName, resourceName))
+ return pResources + i;
+
+ return NULL;
+}
+
JABBER_RESOURCE_STATUS* CJabberProto::ListFindResource(JABBER_LIST list, const TCHAR *jid)
{
mir_cslock lck(m_csLists);
@@ -214,16 +226,7 @@ JABBER_RESOURCE_STATUS* CJabberProto::ListFindResource(JABBER_LIST list, const T const TCHAR *p = _tcschr(jid, '@');
const TCHAR *q = _tcschr((p == NULL) ? jid : p, '/');
- if (q == NULL)
- return NULL;
-
- const TCHAR *resource = q+1;
- if (*resource)
- for (int j=0; j < LI->resourceCount; j++)
- if ( !_tcscmp(LI->pResources[j].resourceName, resource))
- return LI->pResources + j;
-
- return NULL;
+ return (q == NULL) ? NULL : LI->findResource(q+1);
}
int CJabberProto::ListAddResource(JABBER_LIST list, const TCHAR *jid, int status, const TCHAR *statusMessage, char priority, const TCHAR *nick)
@@ -233,26 +236,21 @@ int CJabberProto::ListAddResource(JABBER_LIST list, const TCHAR *jid, int status if (LI == NULL)
return NULL;
- int bIsNewResource = false, j;
+ 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->pResources;
- for (j=0; j < LI->resourceCount; j++, r++) {
- if ( !_tcscmp(r->resourceName, resource)) {
- // Already exist, update status and statusMessage
- r->status = status;
- replaceStrT(r->statusMessage, statusMessage);
- r->priority = priority;
- break;
- } }
-
- if (j >= LI->resourceCount) {
- // Not already exist, add new resource
- LI->pResources = (JABBER_RESOURCE_STATUS *) mir_realloc(LI->pResources, (LI->resourceCount+1)*sizeof(JABBER_RESOURCE_STATUS));
+ 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));
@@ -290,16 +288,8 @@ void CJabberProto::ListRemoveResource(JABBER_LIST list, const TCHAR *jid) if (q == NULL)
return;
- const TCHAR *resource = q+1;
- if (resource[0] == 0)
- return;
-
- JABBER_RESOURCE_STATUS *r = LI->pResources;
- for (int j=0; j < LI->resourceCount; j++, r++)
- if ( !_tcsicmp(r->resourceName, resource))
- break;
-
- if (r >= LI->pResources + LI->resourceCount)
+ JABBER_RESOURCE_STATUS *r = LI->findResource(q+1);
+ if (r == NULL)
return;
// Found last seen resource ID to be removed
diff --git a/protocols/JabberG/src/jabber_list.h b/protocols/JabberG/src/jabber_list.h index fec42d8b01..798d0603ae 100644 --- a/protocols/JabberG/src/jabber_list.h +++ b/protocols/JabberG/src/jabber_list.h @@ -115,6 +115,7 @@ struct JABBER_LIST_ITEM : public MZeroedObject // jid = jid of the contact
TCHAR* nick;
+ JABBER_RESOURCE_STATUS* findResource(const TCHAR *resourceName) const;
JABBER_RESOURCE_STATUS* getBestResource() const;
JABBER_RESOURCE_MODE resourceMode;
int resourceCount;
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index 9df6932cf8..da49fcbf66 100644 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -728,19 +728,13 @@ int __cdecl CJabberProto::GetInfo(HANDLE hContact, int /*infoType*/) }
JABBER_LIST_ITEM *tmpItem = NULL;
if (pDelimiter && (tmpItem = ListGetItemPtr(LIST_CHATROOM, szBareJid))) {
- JABBER_RESOURCE_STATUS *him = NULL;
- for (int i=0; i < tmpItem->resourceCount; i++) {
- JABBER_RESOURCE_STATUS &p = tmpItem->pResources[i];
- if ( !lstrcmp(p.resourceName, pDelimiter))
- him = &p;
- }
+ JABBER_RESOURCE_STATUS *him = tmpItem->findResource(pDelimiter);
if (him) {
item = ListAdd(LIST_VCARD_TEMP, jid);
ListAddResource(LIST_VCARD_TEMP, jid, him->status, him->statusMessage, him->priority);
}
}
- else
- item = ListAdd(LIST_VCARD_TEMP, jid);
+ else item = ListAdd(LIST_VCARD_TEMP, jid);
}
if (item && item->pResources) {
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index 7d6ecbeeb6..7e0f47124a 100644 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -536,7 +536,6 @@ struct CJabberProto : public PROTO<CJabberProto> INT_PTR __cdecl OnJoinChat(WPARAM wParam, LPARAM lParam);
INT_PTR __cdecl OnLeaveChat(WPARAM wParam, LPARAM lParam);
- JABBER_RESOURCE_STATUS* GcFindResource(JABBER_LIST_ITEM *item, const TCHAR *resource);
void GroupchatJoinRoom(LPCTSTR server, LPCTSTR room, LPCTSTR nick, LPCTSTR password, bool autojoin = false);
void GroupchatProcessPresence(HXML node);
void GroupchatProcessMessage(HXML node);
diff --git a/protocols/JabberG/src/jabber_svc.cpp b/protocols/JabberG/src/jabber_svc.cpp index a162a5349c..c8a3bedb96 100644 --- a/protocols/JabberG/src/jabber_svc.cpp +++ b/protocols/JabberG/src/jabber_svc.cpp @@ -397,14 +397,7 @@ INT_PTR __cdecl CJabberProto::JabberGCGetToolTipText(WPARAM wParam, LPARAM lPara if (item == NULL)
return 0; //no room found
- JABBER_RESOURCE_STATUS * info = NULL;
- for (int i=0; i < item->resourceCount; i++) {
- JABBER_RESOURCE_STATUS& p = item->pResources[i];
- if ( !lstrcmp(p.resourceName, (TCHAR*)lParam)) {
- info = &p;
- break;
- } }
-
+ JABBER_RESOURCE_STATUS *info = item->findResource((TCHAR*)lParam);
if (info == NULL)
return 0; //no info found
@@ -423,9 +416,8 @@ INT_PTR __cdecl CJabberProto::JabberGCGetToolTipText(WPARAM wParam, LPARAM lPara //JID:
if (_tcschr(info->resourceName, _T('@')) != NULL)
appendString(bIsTipper, _T("JID:"), info->resourceName, outBuf, SIZEOF(outBuf));
- else if (lParam) { //or simple nick
+ else if (lParam) //or simple nick
appendString(bIsTipper, _T("Nick:"), (TCHAR*) lParam, outBuf, SIZEOF(outBuf));
- }
// status
if (info->status >= ID_STATUS_OFFLINE && info->status <= ID_STATUS_IDLE )
diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index f030609074..01d13405db 100644 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -1098,12 +1098,9 @@ HANDLE CJabberProto::CreateTemporaryContact(const TCHAR *szJid, JABBER_LIST_ITEM p = szJid;
hContact = DBCreateContact(szJid, p, TRUE, FALSE);
- for (int i=0; i < chatItem->resourceCount; i++) {
- if ( !lstrcmp(chatItem->pResources[i].resourceName, p)) {
- setWord(hContact, "Status", chatItem->pResources[i].status);
- break;
- }
- }
+ JABBER_RESOURCE_STATUS *r = chatItem->findResource(p);
+ if (r)
+ setWord(hContact, "Status", r->status);
}
else {
TCHAR *nick = JabberNickFromJID(szJid);
@@ -1544,8 +1541,7 @@ void CJabberProto::UpdateJidDbSettings(const TCHAR *jid) // Determine status to show for the contact based on the remaining resources
int nSelectedResource = -1, i = 0;
int nMaxPriority = -999; // -128...+127 valid range
- for (i = 0; i < item->resourceCount; i++)
- {
+ for (i = 0; i < item->resourceCount; i++) {
if (item->pResources[i].priority > nMaxPriority) {
nMaxPriority = item->pResources[i].priority;
status = item->pResources[i].status;
diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp index 69b2327e51..9814cd302c 100644 --- a/protocols/JabberG/src/jabber_util.cpp +++ b/protocols/JabberG/src/jabber_util.cpp @@ -153,25 +153,17 @@ JABBER_RESOURCE_STATUS* CJabberProto::ResourceInfoFromJID(const TCHAR *jid) if ( !jid)
return NULL;
- JABBER_LIST_ITEM *item = NULL;
- if ((item = ListGetItemPtr(LIST_VCARD_TEMP, jid)) == NULL)
+ JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_VCARD_TEMP, jid);
+ if (item == NULL)
item = ListGetItemPtr(LIST_ROSTER, jid);
- if (item == NULL) return NULL;
+ if (item == NULL)
+ return NULL;
const TCHAR *p = _tcschr(jid, '/');
if (p == NULL)
return &item->itemResource;
- if (*++p == '\0') return NULL;
-
- JABBER_RESOURCE_STATUS *r = item->pResources;
- if (r == NULL) return NULL;
-
- int i;
- for (i=0; i<item->resourceCount && _tcscmp(r->resourceName, p); i++, r++);
- if (i >= item->resourceCount)
- return NULL;
- return r;
+ return item->findResource(p+1);
}
JABBER_LIST_ITEM* CJabberProto::GetItemFromContact(HANDLE hContact)
|