From 14877a748010cf73448cc6892792120e4b191439 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 20 Sep 2013 19:31:57 +0000 Subject: Jabber: - JABBER_RESOURCE_STATUS became a class; - static item JABBER_LIST_ITEM::itemResource converted into a dynamically allocated structure for resourceless items only; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@6144 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/JabberG/src/jabber_chat.cpp | 18 +++++----- protocols/JabberG/src/jabber_disco.cpp | 4 +-- protocols/JabberG/src/jabber_groupchat.cpp | 2 +- protocols/JabberG/src/jabber_list.cpp | 58 +++++++++++++++--------------- protocols/JabberG/src/jabber_list.h | 6 ++-- protocols/JabberG/src/jabber_menu.cpp | 13 ++++--- protocols/JabberG/src/jabber_opt.cpp | 4 +-- protocols/JabberG/src/jabber_proto.cpp | 6 ++-- protocols/JabberG/src/jabber_thread.cpp | 23 ++++++------ protocols/JabberG/src/jabber_userinfo.cpp | 12 +++---- protocols/JabberG/src/jabber_util.cpp | 2 +- 11 files changed, 77 insertions(+), 71 deletions(-) (limited to 'protocols/JabberG/src') diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp index fddece3ed7..b1d4fe97d2 100644 --- a/protocols/JabberG/src/jabber_chat.cpp +++ b/protocols/JabberG/src/jabber_chat.cpp @@ -559,9 +559,9 @@ int CJabberProto::JabberGcMenuHook(WPARAM, LPARAM lParam) sttSetupGcMenuItem(gcmi, 0, FALSE); int idx = IDM_LINK0; - if (item->itemResource.statusMessage && *item->itemResource.statusMessage) { + if (item->m_pItemResource && item->m_pItemResource->statusMessage && *item->m_pItemResource->statusMessage) { TCHAR *bufPtr = url_buf; - for (TCHAR *p = _tcsstr(item->itemResource.statusMessage, _T("http://")); p && *p; p = _tcsstr(p+1, _T("http://"))) { + for (TCHAR *p = _tcsstr(item->m_pItemResource->statusMessage, _T("http://")); p && *p; p = _tcsstr(p+1, _T("http://"))) { lstrcpyn(bufPtr, p, SIZEOF(url_buf) - (bufPtr - url_buf)); gc_item *pItem = sttFindGcMenuItem(gcmi, idx); pItem->pszDesc = bufPtr; @@ -1312,18 +1312,18 @@ static void sttLogListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK* g case IDM_TOPIC: mir_sntprintf(szCaption, SIZEOF(szCaption), TranslateT("Set topic for %s"), gch->pDest->ptszID); { - size_t cbLen = 2048 + lstrlen(item->itemResource.statusMessage)*2; + size_t cbLen = 2048 + lstrlen(item->m_pItemResource->statusMessage)*2; ptrT ptszBuf((TCHAR*)mir_alloc( sizeof(TCHAR) * cbLen)); - if (item->itemResource.statusMessage) { + if (item->m_pItemResource->statusMessage) { TCHAR *d = ptszBuf; for (int i = 0; i < (int)cbLen; i++) { - if (item->itemResource.statusMessage[ i ] != _T('\n') || (i && item->itemResource.statusMessage[ i - 1 ] == _T('\r'))) - *d++ = item->itemResource.statusMessage[ i ]; + if (item->m_pItemResource->statusMessage[ i ] != _T('\n') || (i && item->m_pItemResource->statusMessage[ i - 1 ] == _T('\r'))) + *d++ = item->m_pItemResource->statusMessage[ i ]; else { *d++ = _T('\r'); *d++ = _T('\n'); } - if ( !item->itemResource.statusMessage[ i ]) + if ( !item->m_pItemResource->statusMessage[ i ]) break; } *d = 0; @@ -1410,7 +1410,7 @@ static void sttLogListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK* g case IDM_LINK5: case IDM_LINK6: case IDM_LINK7: case IDM_LINK8: case IDM_LINK9: { unsigned idx = IDM_LINK0; - for (TCHAR *p = _tcsstr(item->itemResource.statusMessage, _T("http://")); p && *p; p = _tcsstr(p+1, _T("http://"))) + for (TCHAR *p = _tcsstr(item->m_pItemResource->statusMessage, _T("http://")); p && *p; p = _tcsstr(p+1, _T("http://"))) { if (idx == gch->dwData) { @@ -1432,7 +1432,7 @@ static void sttLogListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK* g JabberCopyText((HWND)CallService(MS_CLUI_GETHWND, 0, 0), item->jid); break; case IDM_CPY_TOPIC: - JabberCopyText((HWND)CallService(MS_CLUI_GETHWND, 0, 0), item->itemResource.statusMessage); + JabberCopyText((HWND)CallService(MS_CLUI_GETHWND, 0, 0), item->m_pItemResource->statusMessage); break; } } diff --git a/protocols/JabberG/src/jabber_disco.cpp b/protocols/JabberG/src/jabber_disco.cpp index 41d4d20042..5f89785f31 100644 --- a/protocols/JabberG/src/jabber_disco.cpp +++ b/protocols/JabberG/src/jabber_disco.cpp @@ -1234,9 +1234,9 @@ void CJabberProto::ServiceDiscoveryShowMenu(CJabberSDNode *pNode, HTREELISTITEM continue; if ((items[i].flags&SD_FLG_NOTSUBSCRIBED) && (rosterItem && (rosterItem->subscription != SUB_NONE))) continue; - if ((items[i].flags&SD_FLG_ONLINE) && rosterItem && (rosterItem->itemResource.status != ID_STATUS_OFFLINE)) + if ((items[i].flags&SD_FLG_ONLINE) && rosterItem && (rosterItem->m_pItemResource->status != ID_STATUS_OFFLINE)) continue; - if ((items[i].flags&SD_FLG_NOTONLINE) && rosterItem && (rosterItem->itemResource.status == ID_STATUS_OFFLINE)) + if ((items[i].flags&SD_FLG_NOTONLINE) && rosterItem && (rosterItem->m_pItemResource->status == ID_STATUS_OFFLINE)) continue; if ((items[i].flags&SD_FLG_NORESOURCE) && _tcschr(pNode->GetJid(), _T('/'))) continue; diff --git a/protocols/JabberG/src/jabber_groupchat.cpp b/protocols/JabberG/src/jabber_groupchat.cpp index 1e15445539..8ad5307200 100644 --- a/protocols/JabberG/src/jabber_groupchat.cpp +++ b/protocols/JabberG/src/jabber_groupchat.cpp @@ -1163,7 +1163,7 @@ void CJabberProto::GroupchatProcessMessage(HXML node) *(TCHAR*)(--tmptr) = 0; resource = tmpnick; } } - replaceStrT(item->itemResource.statusMessage, msgText); + replaceStrT(item->m_pItemResource->statusMessage, msgText); } else { if ((n = xmlGetChildByTag(node , "body", "xml:lang", m_tszSelectedLang)) == NULL) diff --git a/protocols/JabberG/src/jabber_list.cpp b/protocols/JabberG/src/jabber_list.cpp index b1e7014a1e..d97d758055 100644 --- a/protocols/JabberG/src/jabber_list.cpp +++ b/protocols/JabberG/src/jabber_list.cpp @@ -37,33 +37,31 @@ JABBER_LIST_ITEM::JABBER_LIST_ITEM() : ///////////////////////////////////////////////////////////////////////////////////////// -static void JabberListFreeResourceInternal(JABBER_RESOURCE_STATUS *r) +JABBER_RESOURCE_STATUS::~JABBER_RESOURCE_STATUS() { - 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); + mir_free(resourceName); + mir_free(nick); + mir_free(statusMessage); + mir_free(software); + mir_free(version); + mir_free(system); + mir_free(szCapsNode); + mir_free(szCapsVer); + mir_free(szCapsExt); + mir_free(szRealJid); - if (r->pSoftwareInfo) - delete r->pSoftwareInfo; + if (pSoftwareInfo) + delete pSoftwareInfo; } JABBER_LIST_ITEM::~JABBER_LIST_ITEM() { - for (int i=0; i < arResources.getCount(); i++) { - JABBER_RESOURCE_STATUS *r = arResources[i]; - JabberListFreeResourceInternal(r); - mir_free(r); - } + for (int i=0; i < arResources.getCount(); i++) + delete arResources[i]; arResources.destroy(); - JabberListFreeResourceInternal(&itemResource); + if (m_pItemResource) + delete m_pItemResource; if (photoFileName) { if (list == LIST_VCARD_TEMP) @@ -130,9 +128,12 @@ JABBER_LIST_ITEM *CJabberProto::ListAdd(JABBER_LIST list, const TCHAR *jid) item = new JABBER_LIST_ITEM(); item->list = list; item->jid = s; - item->itemResource.status = ID_STATUS_OFFLINE; item->resourceMode = RSMODE_LASTSEEN; item->bUseResource = bUseResource; + if (!bUseResource) { + item->m_pItemResource = new JABBER_RESOURCE_STATUS(); + item->m_pItemResource->status = ID_STATUS_OFFLINE; + } m_lstRoster.insert(item); lck.unlock(); @@ -259,7 +260,7 @@ int CJabberProto::ListAddResource(JABBER_LIST list, const TCHAR *jid, int status } else { // Does not exist, add new resource bIsNewResource = true; - r = (JABBER_RESOURCE_STATUS*)mir_calloc( sizeof(JABBER_RESOURCE_STATUS)); + r = new JABBER_RESOURCE_STATUS(); r->status = status; r->affiliation = AFFILIATION_NONE; r->role = ROLE_NONE; @@ -273,8 +274,9 @@ int CJabberProto::ListAddResource(JABBER_LIST list, const TCHAR *jid, int status } // No resource, update the main statusMessage else { - LI->itemResource.status = status; - replaceStrT(LI->itemResource.statusMessage, statusMessage); + LI->m_pItemResource = new JABBER_RESOURCE_STATUS(); + LI->m_pItemResource->status = status; + replaceStrT(LI->m_pItemResource->statusMessage, statusMessage); } lck.unlock(); @@ -304,18 +306,16 @@ void CJabberProto::ListRemoveResource(JABBER_LIST list, const TCHAR *jid) LI->pLastSeenResource = NULL; // update manually selected resource ID - if (LI->resourceMode == RSMODE_MANUAL) { - if (LI->pManualResource == r) { - LI->resourceMode = RSMODE_LASTSEEN; - LI->pManualResource = NULL; - } + if (LI->resourceMode == RSMODE_MANUAL && LI->pManualResource == r) { + LI->resourceMode = RSMODE_LASTSEEN; + LI->pManualResource = NULL; } // Update MirVer due to possible resource changes UpdateMirVer(LI); LI->arResources.remove(r); - JabberListFreeResourceInternal(r); + delete r; lck.unlock(); MenuUpdateSrmmIcon(LI); diff --git a/protocols/JabberG/src/jabber_list.h b/protocols/JabberG/src/jabber_list.h index 9df9b7b710..16f1c8aad3 100644 --- a/protocols/JabberG/src/jabber_list.h +++ b/protocols/JabberG/src/jabber_list.h @@ -73,8 +73,10 @@ struct JABBER_XEP0232_SOFTWARE_INFO : public MZeroedObject ptrT tszOs, tszOsVersion, tszSoftware, tszSoftwareVersion, tszXMirandaCoreVersion; }; -struct JABBER_RESOURCE_STATUS +struct JABBER_RESOURCE_STATUS : public MZeroedObject { + ~JABBER_RESOURCE_STATUS(); + int status; TCHAR* resourceName; TCHAR* nick; @@ -122,7 +124,7 @@ struct JABBER_LIST_ITEM : public MZeroedObject JABBER_RESOURCE_STATUS *pLastSeenResource, // resource which was last seen active *pManualResource, // manually set resource - itemResource; // resource for jids without /resource node + *m_pItemResource; // resource for jids without /resource node JABBER_SUBSCRIPTION subscription; TCHAR* group; diff --git a/protocols/JabberG/src/jabber_menu.cpp b/protocols/JabberG/src/jabber_menu.cpp index 174e571571..7b47dcf4a3 100644 --- a/protocols/JabberG/src/jabber_menu.cpp +++ b/protocols/JabberG/src/jabber_menu.cpp @@ -587,7 +587,7 @@ INT_PTR __cdecl CJabberProto::OnMenuTransportLogin(WPARAM wParam, LPARAM) JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, jid.ptszVal); if (item != NULL) { XmlNode p(_T("presence")); xmlAddAttr(p, _T("to"), item->jid); - if (item->itemResource.status == ID_STATUS_ONLINE) + if (item->m_pItemResource->status == ID_STATUS_ONLINE) xmlAddAttr(p, _T("type"), _T("unavailable")); m_ThreadInfo->send(p); } @@ -1032,9 +1032,11 @@ int CJabberProto::OnProcessSrmmEvent(WPARAM, LPARAM lParam) WindowList_Add(hDialogsList, event->hwndWindow, event->hContact); ptrT jid( getTStringA(event->hContact, "jid")); - JABBER_LIST_ITEM *pItem = (jid == NULL) ? NULL : ListGetItemPtr(LIST_ROSTER, jid); - if (pItem && (m_ThreadInfo->jabberServerCaps & JABBER_CAPS_ARCHIVE_AUTO) && m_options.EnableMsgArchive) - RetrieveMessageArchive(event->hContact, pItem); + if (jid != NULL) { + JABBER_LIST_ITEM *pItem = ListGetItemPtr(LIST_ROSTER, jid); + if (pItem && (m_ThreadInfo->jabberServerCaps & JABBER_CAPS_ARCHIVE_AUTO) && m_options.EnableMsgArchive) + RetrieveMessageArchive(event->hContact, pItem); + } } else if (event->uType == MSG_WINDOW_EVT_CLOSING) { if (hDialogsList) @@ -1045,7 +1047,8 @@ int CJabberProto::OnProcessSrmmEvent(WPARAM, LPARAM lParam) if ( !db_get(event->hContact, "SRMsg", "SupportTyping", &dbv)) { bSupportTyping = dbv.bVal == 1; db_free(&dbv); - } else if ( !db_get(NULL, "SRMsg", "DefaultTyping", &dbv)) { + } + else if ( !db_get(NULL, "SRMsg", "DefaultTyping", &dbv)) { bSupportTyping = dbv.bVal == 1; db_free(&dbv); } diff --git a/protocols/JabberG/src/jabber_opt.cpp b/protocols/JabberG/src/jabber_opt.cpp index 7b350588cc..4c3e9a426b 100644 --- a/protocols/JabberG/src/jabber_opt.cpp +++ b/protocols/JabberG/src/jabber_opt.cpp @@ -872,8 +872,8 @@ public: HANDLE hContact = m_proto->HContactFromJID(item->jid); if (hContact != NULL) { if (bChecked) { - if (item->itemResource.status != m_proto->getWord(hContact, "Status", ID_STATUS_OFFLINE)) { - m_proto->setWord(hContact, "Status", (WORD)item->itemResource.status); + if (item->m_pItemResource->status != m_proto->getWord(hContact, "Status", ID_STATUS_OFFLINE)) { + m_proto->setWord(hContact, "Status", (WORD)item->m_pItemResource->status); } } else if (m_proto->getWord(hContact, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) m_proto->setWord(hContact, "Status", ID_STATUS_OFFLINE); diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index 047e8f3da6..784ce86e82 100644 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -761,7 +761,7 @@ int __cdecl CJabberProto::GetInfo(HANDLE hContact, int /*infoType*/) } } } - else if ( !item->itemResource.dwVersionRequestTime) { + else if ( !item->m_pItemResource->dwVersionRequestTime) { XmlNodeIq iq4(m_iqManager.AddHandler(&CJabberProto::OnIqResultVersion, JABBER_IQ_TYPE_GET, item->jid, JABBER_IQ_PARSE_FROM | JABBER_IQ_PARSE_HCONTACT | JABBER_IQ_PARSE_CHILD_TAG_NODE)); iq4 << XQUERY(JABBER_FEAT_VERSION); m_ThreadInfo->send(iq4); @@ -1337,8 +1337,8 @@ void __cdecl CJabberProto::GetAwayMsgThread(void* hContact) return; } - if (item->itemResource.statusMessage != NULL) { - ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, (LPARAM)item->itemResource.statusMessage); + if (item->m_pItemResource->statusMessage != NULL) { + ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, (LPARAM)item->m_pItemResource->statusMessage); return; } } diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index 7df6e3fc41..840b05bf59 100644 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -1523,17 +1523,19 @@ void CJabberProto::OnProcessPresenceCapabilites(HXML node) void CJabberProto::UpdateJidDbSettings(const TCHAR *jid) { JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, jid); - if ( !item) return; + if (item == NULL) + return; HANDLE hContact = HContactFromJID(jid); - if ( !hContact) return; + if (hContact == NULL) + return; int status = ID_STATUS_OFFLINE; if ( !item->arResources.getCount()) { // set offline only if jid has resources if (_tcschr(jid, '/') == NULL) - status = item->itemResource.status; - if (item->itemResource.statusMessage) - db_set_ts(hContact, "CList", "StatusMsg", item->itemResource.statusMessage); + status = item->m_pItemResource->status; + if (item->m_pItemResource->statusMessage) + db_set_ts(hContact, "CList", "StatusMsg", item->m_pItemResource->statusMessage); else db_unset(hContact, "CList", "StatusMsg"); } @@ -1553,7 +1555,7 @@ void CJabberProto::UpdateJidDbSettings(const TCHAR *jid) nSelectedResource = i; } } - item->itemResource.status = status; + item->m_pItemResource->status = status; if (nSelectedResource != -1) { JABBER_RESOURCE_STATUS *r = item->arResources[nSelectedResource]; Log("JabberUpdateJidDbSettings: updating jid %S to rc %S", item->jid, r->resourceName); @@ -1569,12 +1571,11 @@ void CJabberProto::UpdateJidDbSettings(const TCHAR *jid) if (getWord(hContact, "Status", ID_STATUS_OFFLINE) != status) setWord(hContact, "Status", (WORD)status); - if (status == ID_STATUS_OFFLINE) - { // remove x-status icon + // remove x-status icon + if (status == ID_STATUS_OFFLINE) { delSetting(hContact, DBSETTING_XSTATUSID); delSetting(hContact, DBSETTING_XSTATUSNAME); delSetting(hContact, DBSETTING_XSTATUSMSG); - //JabberUpdateContactExtraIcon(hContact); } MenuUpdateSrmmIcon(item); @@ -1723,8 +1724,8 @@ void CJabberProto::OnProcessPresence(HXML node, ThreadData* info) // set status only if no more available resources if ( !item->arResources.getCount()) { - item->itemResource.status = ID_STATUS_OFFLINE; - replaceStrT(item->itemResource.statusMessage, xmlGetText( xmlGetChild(node , "status"))); + item->m_pItemResource->status = ID_STATUS_OFFLINE; + replaceStrT(item->m_pItemResource->statusMessage, xmlGetText( xmlGetChild(node , "status"))); } } else Log("SKIP Receive presence offline from %S (who is not in my roster)", from); diff --git a/protocols/JabberG/src/jabber_userinfo.cpp b/protocols/JabberG/src/jabber_userinfo.cpp index c3adeebac6..a9c7455bcb 100644 --- a/protocols/JabberG/src/jabber_userinfo.cpp +++ b/protocols/JabberG/src/jabber_userinfo.cpp @@ -212,7 +212,7 @@ static void sttFillResourceInfo(CJabberProto *ppro, HWND hwndTree, HTREEITEM hti { TCHAR buf[256]; HTREEITEM htiResource = htiRoot; - JABBER_RESOURCE_STATUS *res = resource ? item->arResources[resource-1] : &item->itemResource; + JABBER_RESOURCE_STATUS *res = resource ? item->arResources[resource-1] : item->m_pItemResource; if (res->resourceName && *res->resourceName) htiResource = sttFillInfoLine(hwndTree, htiRoot, LoadSkinnedProtoIcon(ppro->m_szModuleName, res->status), @@ -365,12 +365,12 @@ static void sttFillUserInfo(CJabberProto *ppro, HWND hwndTree, JABBER_LIST_ITEM } // logoff - if (item->itemResource.idleStartTime > 0) { - lstrcpyn(buf, _tctime(&item->itemResource.idleStartTime), SIZEOF(buf)); + if (item->m_pItemResource->idleStartTime > 0) { + lstrcpyn(buf, _tctime(&item->m_pItemResource->idleStartTime), SIZEOF(buf)); int len = lstrlen(buf); if (len > 0) buf[len-1] = 0; } - else if ( !item->itemResource.idleStartTime) + else if ( !item->m_pItemResource->idleStartTime) lstrcpyn(buf, TranslateT("unknown"), SIZEOF(buf)); else lstrcpyn(buf, TranslateT(""), SIZEOF(buf)); @@ -381,7 +381,7 @@ static void sttFillUserInfo(CJabberProto *ppro, HWND hwndTree, JABBER_LIST_ITEM // logoff msg sttFillInfoLine(hwndTree, htiRoot, NULL, TranslateT("Logoff message"), - item->itemResource.statusMessage ? item->itemResource.statusMessage : TranslateT(""), sttInfoLineId(0, INFOLINE_LOGOFF_MSG)); + item->m_pItemResource->statusMessage ? item->m_pItemResource->statusMessage : TranslateT(""), sttInfoLineId(0, INFOLINE_LOGOFF_MSG)); // activity if (item->pLastSeenResource) @@ -397,7 +397,7 @@ static void sttFillUserInfo(CJabberProto *ppro, HWND hwndTree, JABBER_LIST_ITEM for (int i = 0; i < item->arResources.getCount(); i++) sttFillResourceInfo(ppro, hwndTree, htiRoot, item, i+1); } - else if ( !_tcschr(item->jid, _T('@')) || (item->itemResource.status != ID_STATUS_OFFLINE)) + else if ( !_tcschr(item->jid, _T('@')) || (item->m_pItemResource->status != ID_STATUS_OFFLINE)) sttFillResourceInfo(ppro, hwndTree, htiRoot, item, 0); sttCleanupInfo(hwndTree, 1); diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp index 53d7fc87f0..2d2102e6ba 100644 --- a/protocols/JabberG/src/jabber_util.cpp +++ b/protocols/JabberG/src/jabber_util.cpp @@ -161,7 +161,7 @@ JABBER_RESOURCE_STATUS* CJabberProto::ResourceInfoFromJID(const TCHAR *jid) const TCHAR *p = _tcschr(jid, '/'); if (p == NULL) - return &item->itemResource; + return item->m_pItemResource; return item->findResource(p+1); } -- cgit v1.2.3