summaryrefslogtreecommitdiff
path: root/protocols/IcqOscarJ/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-03-15 21:05:06 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-03-15 21:05:06 +0300
commit59e6b15f513cc998ce13e9e49e2a6a3ace445ebb (patch)
treeaf52b73a17039ed1fbe398ba9f488c26a7071257 /protocols/IcqOscarJ/src
parentbdaa5cf8b48515af2ac39f3f3245dd1183cbad52 (diff)
LIST<> iterators:
- new method LIST::removeItem added to save a pointer to removed record; - code cleaning related to the fact that LIST::remove() shall be the last operation inside an iterator, because otherwise the reference to it will point to a record next to deleted one; - a few remaining cycles converted to iterators
Diffstat (limited to 'protocols/IcqOscarJ/src')
-rw-r--r--protocols/IcqOscarJ/src/cookies.cpp2
-rw-r--r--protocols/IcqOscarJ/src/icq_avatar.cpp45
-rw-r--r--protocols/IcqOscarJ/src/icq_direct.cpp6
-rw-r--r--protocols/IcqOscarJ/src/icq_rates.cpp20
-rw-r--r--protocols/IcqOscarJ/src/utilities.cpp2
5 files changed, 34 insertions, 41 deletions
diff --git a/protocols/IcqOscarJ/src/cookies.cpp b/protocols/IcqOscarJ/src/cookies.cpp
index a517f93923..0eb4dcc2fd 100644
--- a/protocols/IcqOscarJ/src/cookies.cpp
+++ b/protocols/IcqOscarJ/src/cookies.cpp
@@ -182,7 +182,7 @@ void CIcqProto::FreeCookieByData(BYTE bType, void *pvExtra)
for (auto &it : cookies) {
if (bType == it->bType && pvExtra == it->pvExtra) {
// Cookie found, remove from list
- cookies.remove(it);
+ cookies.removeItem(&it);
break;
}
}
diff --git a/protocols/IcqOscarJ/src/icq_avatar.cpp b/protocols/IcqOscarJ/src/icq_avatar.cpp
index 28ef778680..c3d6b5792f 100644
--- a/protocols/IcqOscarJ/src/icq_avatar.cpp
+++ b/protocols/IcqOscarJ/src/icq_avatar.cpp
@@ -187,19 +187,18 @@ void CIcqProto::StartAvatarThread(HNETLIBCONN hConn, char *cookie, size_t cookie
// check if any upload request are waiting in the queue
int bYet = 0;
- for (int i = 0; i < m_arAvatars.getCount();) {
- avatars_request *ar = m_arAvatars[i];
- if (ar->type == ART_UPLOAD) { // we found it, return error
+ auto T = m_arAvatars.rev_iter();
+ for (auto &it : T) {
+ if (it->type == ART_UPLOAD) { // we found it, return error
if (!bYet) {
icq_LogMessage(LOG_WARNING, LPGEN("Error uploading avatar to server, server temporarily unavailable."));
bYet = 1;
}
// remove upload request from queue
- m_arAvatars.remove(i);
- delete ar;
+ delete it;
+ m_arAvatars.remove(T.indexOf(&it));
}
- else i++;
}
SAFE_FREE((void**)&cookie);
@@ -489,11 +488,10 @@ void CIcqProto::handleAvatarContactHash(DWORD dwUIN, char *szUID, MCONTACT hCont
if (bJob == TRUE) { // Remove possible block - hash changed, try again.
mir_cslock l(m_avatarsMutex);
- for (int i = 0; i < m_arAvatars.getCount(); i++) {
- avatars_request *ar = m_arAvatars[i];
- if (ar->hContact == hContact && ar->type == ART_BLOCK) { // found one, remove
- m_arAvatars.remove(i);
- delete ar;
+ for (auto &it : m_arAvatars) {
+ if (it->hContact == hContact && it->type == ART_BLOCK) { // found one, remove
+ delete it;
+ m_arAvatars.removeItem(&it);
break;
}
}
@@ -536,18 +534,17 @@ int CIcqProto::GetAvatarData(MCONTACT hContact, DWORD dwUin, const char *szUid,
if (m_avatarsConnection && m_avatarsConnection->isReady()) { // check if we are ready
// check if requests for this user are not blocked
- for (int i = 0; i < m_arAvatars.getCount();) {
- avatars_request *ar = m_arAvatars[i];
+ auto T = m_arAvatars.rev_iter();
+ for (auto &ar : T) {
if (ar->hContact == hContact && ar->type == ART_BLOCK) { // found a block item
if (GetTickCount() > ar->timeOut) { // remove timeouted block
- m_arAvatars.remove(i);
delete ar;
+ m_arAvatars.remove(T.indexOf(&ar));
continue;
}
debugLogA("Avatars: Requests for %s avatar are blocked.", strUID(dwUin, pszUid));
return 0;
}
- i++;
}
mir_cslock l(m_avatarsConnection->getLock());
@@ -562,12 +559,12 @@ int CIcqProto::GetAvatarData(MCONTACT hContact, DWORD dwUin, const char *szUid,
// we failed to send request, or avatar thread not ready
// check if any request for this user is not already in the queue
- for (int i = 0; i < m_arAvatars.getCount();) {
- avatars_request *ar = m_arAvatars[i];
+ auto T = m_arAvatars.rev_iter();
+ for (auto &ar : T) {
if (ar->hContact == hContact) { // we found it, return error
if (ar->type == ART_BLOCK && GetTickCount() > ar->timeOut) { // remove timeouted block
- m_arAvatars.remove(i);
delete ar;
+ m_arAvatars.remove(T.indexOf(&ar));
continue;
}
alck.unlock();
@@ -577,7 +574,6 @@ int CIcqProto::GetAvatarData(MCONTACT hContact, DWORD dwUin, const char *szUid,
requestAvatarConnection();
return 0;
}
- i++;
}
// add request to queue, processed after successful login
@@ -728,12 +724,11 @@ void avatars_server_connection::shutdownConnection()
DWORD avatars_server_connection::sendGetAvatarRequest(MCONTACT hContact, DWORD dwUin, char *szUid, const BYTE *hash, size_t hashlen, const wchar_t *file)
{
- int i;
DWORD dwNow = GetTickCount();
mir_cslockfull alck(ppro->m_avatarsMutex);
- for (i = 0; i < runCount;) { // look for timeouted requests
+ for (int i = 0; i < runCount;) { // look for timeouted requests
if (runTime[i] < dwNow) { // found outdated, remove
runContact[i] = runContact[runCount - 1];
runTime[i] = runTime[runCount - 1];
@@ -742,7 +737,7 @@ DWORD avatars_server_connection::sendGetAvatarRequest(MCONTACT hContact, DWORD d
else i++;
}
- for (i = 0; i < runCount; i++) {
+ for (int i = 0; i < runCount; i++) {
if (runContact[i] == hContact) {
ppro->debugLogA("Ignoring duplicate get %s image request.", strUID(dwUin, szUid));
return -1; // Success: request ignored
@@ -849,11 +844,11 @@ void avatars_server_connection::checkRequestQueue()
}
if (pRequest->type == ART_BLOCK) { // block contact processing
- for (int i = 0; i < ppro->m_arAvatars.getCount(); i++) {
- avatars_request *ar = ppro->m_arAvatars[i];
+ auto T = ppro->m_arAvatars.rev_iter();
+ for (auto &ar : T) {
if (GetTickCount() > ar->timeOut) { // expired contact block, remove
- ppro->m_arAvatars.remove(i);
delete ar;
+ ppro->m_arAvatars.remove(T.indexOf(&ar));
}
}
return; // end processing
diff --git a/protocols/IcqOscarJ/src/icq_direct.cpp b/protocols/IcqOscarJ/src/icq_direct.cpp
index 3ecbbe8d92..9872dbd9d6 100644
--- a/protocols/IcqOscarJ/src/icq_direct.cpp
+++ b/protocols/IcqOscarJ/src/icq_direct.cpp
@@ -76,10 +76,8 @@ filetransfer* CIcqProto::FindExpectedFileRecv(DWORD dwUin, DWORD dwTotalSize)
mir_cslock l(expectedFileRecvMutex);
for (auto &it : expectedFileRecvs)
- if (it->dwUin == dwUin && it->dwTotalSize == dwTotalSize) {
- expectedFileRecvs.remove(it);
- return it;
- }
+ if (it->dwUin == dwUin && it->dwTotalSize == dwTotalSize)
+ return expectedFileRecvs.removeItem(&it);
return nullptr;
}
diff --git a/protocols/IcqOscarJ/src/icq_rates.cpp b/protocols/IcqOscarJ/src/icq_rates.cpp
index b2d3ee2823..e2dc3d569f 100644
--- a/protocols/IcqOscarJ/src/icq_rates.cpp
+++ b/protocols/IcqOscarJ/src/icq_rates.cpp
@@ -386,16 +386,16 @@ void rates_queue::putItem(rates_queue_item *pItem, int nMinDelay)
ppro->debugLogA("Rates: Delaying %s.", szDescr);
{
mir_cslock l(csLists);
- if (lstPending.getCount()) {
- for (int i = 0; i < lstPending.getCount(); i++) {
- if (lstPending[i]->isEqual(pItem)) {
- if (duplicates == 1) // keep existing, ignore new
- return;
-
- if (duplicates == -1) { // discard existing, append new item
- delete lstPending[i];
- lstPending.remove(i);
- }
+
+ auto T = lstPending.rev_iter();
+ for (auto &it : T) {
+ if (it->isEqual(pItem)) {
+ if (duplicates == 1) // keep existing, ignore new
+ return;
+
+ if (duplicates == -1) { // discard existing, append new item
+ delete it;
+ lstPending.remove(T.indexOf(&it));
}
}
}
diff --git a/protocols/IcqOscarJ/src/utilities.cpp b/protocols/IcqOscarJ/src/utilities.cpp
index 97253e2cc1..e7af9c8a33 100644
--- a/protocols/IcqOscarJ/src/utilities.cpp
+++ b/protocols/IcqOscarJ/src/utilities.cpp
@@ -388,10 +388,10 @@ void CIcqProto::DeleteFromContactsCache(MCONTACT hContact)
for (auto &it : contactsCache) {
if (it->hContact == hContact) {
- contactsCache.remove(it);
// Release memory
SAFE_FREE((void**)&it->szUid);
SAFE_FREE((void**)&it);
+ contactsCache.removeItem(&it);
break;
}
}