diff options
author | George Hazan <george.hazan@gmail.com> | 2014-07-13 16:54:01 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-07-13 16:54:01 +0000 |
commit | 01112f344f8e764043a306bc641876cf4c13db38 (patch) | |
tree | 3624df97d6986433a142893809d52f8ae451aad4 /protocols/IcqOscarJ/src | |
parent | d80bdbbc068a75b592f48921414006d64d0d0268 (diff) |
code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@9788 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/IcqOscarJ/src')
-rw-r--r-- | protocols/IcqOscarJ/src/icq_infoupdate.cpp | 196 | ||||
-rw-r--r-- | protocols/IcqOscarJ/src/icq_proto.cpp | 62 | ||||
-rw-r--r-- | protocols/IcqOscarJ/src/icqosc_svcs.cpp | 17 |
3 files changed, 108 insertions, 167 deletions
diff --git a/protocols/IcqOscarJ/src/icq_infoupdate.cpp b/protocols/IcqOscarJ/src/icq_infoupdate.cpp index fcba9444f1..501adb6cc3 100644 --- a/protocols/IcqOscarJ/src/icq_infoupdate.cpp +++ b/protocols/IcqOscarJ/src/icq_infoupdate.cpp @@ -40,7 +40,7 @@ void CIcqProto::icq_InitInfoUpdate(void) infoUpdateMutex = new icq_critical_section();
// Init list
- for (int i = 0; i<LISTSIZE; i++) {
+ for (int i = 0; i < LISTSIZE; i++) {
m_infoUpdateList[i].dwUin = 0;
m_infoUpdateList[i].hContact = NULL;
m_infoUpdateList[i].queued = 0;
@@ -57,80 +57,64 @@ void CIcqProto::icq_InitInfoUpdate(void) // Returns FALSE if the list was full
BOOL CIcqProto::icq_QueueUser(MCONTACT hContact)
{
- if ( !infoUpdateMutex )
+ if (!infoUpdateMutex)
return FALSE;
- if (nInfoUserCount < LISTSIZE)
- {
- int i, nChecked = 0, nFirstFree = -1;
- BOOL bFound = FALSE;
+ if (nInfoUserCount >= LISTSIZE)
+ return FALSE;
- infoUpdateMutex->Enter();
+ int i, nChecked = 0, nFirstFree = -1;
+ BOOL bFound = FALSE;
- // Check if in list
- for (i = 0; (i<LISTSIZE && nChecked < nInfoUserCount); i++)
- {
- if (m_infoUpdateList[i].hContact)
- {
- nChecked++;
- if (m_infoUpdateList[i].hContact == hContact)
- {
- bFound = TRUE;
- break;
- }
- }
- else if (nFirstFree == -1)
- {
- nFirstFree = i;
+ infoUpdateMutex->Enter();
+
+ // Check if in list
+ for (i = 0; (i < LISTSIZE && nChecked < nInfoUserCount); i++) {
+ if (m_infoUpdateList[i].hContact) {
+ nChecked++;
+ if (m_infoUpdateList[i].hContact == hContact) {
+ bFound = TRUE;
+ break;
}
}
- if (nFirstFree == -1)
+ else if (nFirstFree == -1)
nFirstFree = i;
-
- // Add to list
- if (!bFound)
- {
- DWORD dwUin = getContactUin(hContact);
-
- if (dwUin)
- {
- m_infoUpdateList[nFirstFree].dwUin = dwUin;
- m_infoUpdateList[nFirstFree].hContact = hContact;
- m_infoUpdateList[nFirstFree].queued = time(NULL);
- nInfoUserCount++;
+ }
+ if (nFirstFree == -1)
+ nFirstFree = i;
+
+ // Add to list
+ if (!bFound) {
+ DWORD dwUin = getContactUin(hContact);
+ if (dwUin) {
+ m_infoUpdateList[nFirstFree].dwUin = dwUin;
+ m_infoUpdateList[nFirstFree].hContact = hContact;
+ m_infoUpdateList[nFirstFree].queued = time(NULL);
+ nInfoUserCount++;
#ifdef _DEBUG
- debugLogA("Queued user %u, place %u, count %u", dwUin, nFirstFree, nInfoUserCount);
+ debugLogA("Queued user %u, place %u, count %u", dwUin, nFirstFree, nInfoUserCount);
#endif
- // Notify worker thread
- if (hInfoQueueEvent && bInfoUpdateEnabled)
- SetEvent(hInfoQueueEvent);
- }
+ // Notify worker thread
+ if (hInfoQueueEvent && bInfoUpdateEnabled)
+ SetEvent(hInfoQueueEvent);
}
-
- infoUpdateMutex->Leave();
-
- return TRUE;
}
- return FALSE;
+ infoUpdateMutex->Leave();
+ return TRUE;
}
-
void CIcqProto::icq_DequeueUser(DWORD dwUin)
{
- if (nInfoUserCount > 0)
- {
+ if (nInfoUserCount > 0) {
int nChecked = 0;
// Check if in list
infoUpdateMutex->Enter();
- for (int i = 0; (i < LISTSIZE && nChecked < nInfoUserCount); i++)
- {
- if (m_infoUpdateList[i].dwUin)
- {
+ for (int i = 0; (i < LISTSIZE && nChecked < nInfoUserCount); i++) {
+ if (m_infoUpdateList[i].dwUin) {
nChecked++;
// Remove from list
- if (m_infoUpdateList[i].dwUin == dwUin)
- {
+ if (m_infoUpdateList[i].dwUin == dwUin) {
#ifdef _DEBUG
debugLogA("Dequeued user %u", m_infoUpdateList[i].dwUin);
#endif
@@ -146,7 +130,6 @@ void CIcqProto::icq_DequeueUser(DWORD dwUin) }
}
-
void CIcqProto::icq_RescanInfoUpdate()
{
bInfoPendingUsers = 0;
@@ -155,24 +138,16 @@ void CIcqProto::icq_RescanInfoUpdate() bInfoUpdateEnabled = 0; // freeze thread
// Queue all outdated users
- MCONTACT hContact = db_find_first(m_szModuleName);
- while (hContact != NULL)
- {
- if (IsMetaInfoChanged(hContact))
- { // Queue user
- if (!icq_QueueUser(hContact))
- { // The queue is full, pause queuing contacts
+ for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
+ if (IsMetaInfoChanged(hContact)) // Queue user
+ if (!icq_QueueUser(hContact)) { // The queue is full, pause queuing contacts
bInfoPendingUsers = 1;
- break;
+ break;
}
- }
- hContact = db_find_next(hContact, m_szModuleName);
- }
bInfoUpdateEnabled = TRUE;
}
-
void CIcqProto::icq_EnableUserLookup(BOOL bEnable)
{
bInfoUpdateEnabled = bEnable;
@@ -182,7 +157,6 @@ void CIcqProto::icq_EnableUserLookup(BOOL bEnable) SetEvent(hInfoQueueEvent);
}
-
void __cdecl CIcqProto::InfoUpdateThread( void* )
{
int i;
@@ -192,20 +166,17 @@ void __cdecl CIcqProto::InfoUpdateThread( void* ) bInfoUpdateRunning = TRUE;
- while (bInfoUpdateRunning)
- {
+ while (bInfoUpdateRunning) {
if (!nInfoUserCount && bInfoPendingUsers) // whole queue processed, check if more users needs updating
icq_RescanInfoUpdate();
- if (!nInfoUserCount || !bInfoUpdateEnabled || !icqOnline())
- {
+ if (!nInfoUserCount || !bInfoUpdateEnabled || !icqOnline()) {
dwWait = WAIT_TIMEOUT;
- while (bInfoUpdateRunning && dwWait == WAIT_TIMEOUT)
- { // wait for new work or until we should end
+ while (bInfoUpdateRunning && dwWait == WAIT_TIMEOUT) // wait for new work or until we should end
dwWait = ICQWaitForSingleObject(hInfoQueueEvent, 10000);
- }
}
- if (!bInfoUpdateRunning) break;
+ if (!bInfoUpdateRunning)
+ break;
switch (dwWait) {
case WAIT_IO_COMPLETION:
@@ -215,50 +186,44 @@ void __cdecl CIcqProto::InfoUpdateThread( void* ) case WAIT_OBJECT_0:
case WAIT_TIMEOUT:
// Time to check for new users
- if (!bInfoUpdateEnabled) continue; // we can't send requests now
+ if (!bInfoUpdateEnabled)
+ continue; // we can't send requests now
- if (nInfoUserCount && icqOnline())
- {
+ if (nInfoUserCount && icqOnline()) {
time_t now = time(NULL);
BOOL bNotReady = FALSE, bTimeOuted = FALSE;
// Check the list, take only users that were there for at least 5sec
// wait if any user is there shorter than 5sec and not a single user is there longer than 20sec
infoUpdateMutex->Enter();
- for (i = 0; i<LISTSIZE; i++)
- {
- if (m_infoUpdateList[i].hContact)
- {
- if (m_infoUpdateList[i].queued + 20 < now)
- {
+ for (i = 0; i < LISTSIZE; i++) {
+ if (m_infoUpdateList[i].hContact) {
+ if (m_infoUpdateList[i].queued + 20 < now) {
bTimeOuted = TRUE;
break;
}
- else if (m_infoUpdateList[i].queued + 5 >= now)
+ if (m_infoUpdateList[i].queued + 5 >= now)
bNotReady = TRUE;
}
}
infoUpdateMutex->Leave();
- if (!bTimeOuted && bNotReady)
- {
+ if (!bTimeOuted && bNotReady) {
SleepEx(1000, TRUE);
- if (!bInfoUpdateRunning)
- { // need to end as fast as possible
+ if (!bInfoUpdateRunning) { // need to end as fast as possible
debugLogA("%s thread ended.", "Info-Update");
goto LBL_Exit;
}
continue;
}
- if (FindCookie(dwInfoActiveRequest, NULL, NULL))
- { // only send another request, when the previous is completed
+ // only send another request, when the previous is completed
+ if (FindCookie(dwInfoActiveRequest, NULL, NULL)) {
#ifdef _DEBUG
debugLogA("Info-Update: Request 0x%x still in progress.", dwInfoActiveRequest);
#endif
SleepEx(1000, TRUE);
- if (!bInfoUpdateRunning)
- { // need to end as fast as possible
+ if (!bInfoUpdateRunning) { // need to end as fast as possible
debugLogA("%s thread ended.", "Info-Update");
goto LBL_Exit;
}
@@ -270,14 +235,13 @@ void __cdecl CIcqProto::InfoUpdateThread( void* ) #endif
// Either some user is waiting long enough, or all users are ready (waited at least the minimum time)
m_ratesMutex->Enter();
- if (!m_rates)
- { // we cannot send info request - icq is offline
+ if (!m_rates) { // we cannot send info request - icq is offline
m_ratesMutex->Leave();
break;
}
+
WORD wGroup = m_rates->getGroupFromSNAC(ICQ_EXTENSIONS_FAMILY, ICQ_META_CLI_REQUEST);
- while (m_rates->getNextRateLevel(wGroup) < m_rates->getLimitLevel(wGroup, RML_IDLE_30))
- { // we are over rate, need to wait before sending
+ while (m_rates->getNextRateLevel(wGroup) < m_rates->getLimitLevel(wGroup, RML_IDLE_30)) { // we are over rate, need to wait before sending
int nDelay = m_rates->getDelayToLimitLevel(wGroup, RML_IDLE_50);
m_ratesMutex->Leave();
@@ -285,8 +249,7 @@ void __cdecl CIcqProto::InfoUpdateThread( void* ) debugLogA("Rates: InfoUpdate delayed %dms", nDelay);
#endif
SleepEx(nDelay, TRUE); // do not keep things locked during sleep
- if (!bInfoUpdateRunning)
- { // need to end as fast as possible
+ if (!bInfoUpdateRunning) { // need to end as fast as possible
debugLogA("%s thread ended.", "Info-Update");
goto LBL_Exit;
}
@@ -294,8 +257,7 @@ void __cdecl CIcqProto::InfoUpdateThread( void* ) if (!m_rates) // we lost connection when we slept, go away
break;
}
- if (!m_rates)
- { // we cannot send info request - icq is offline
+ if (!m_rates) { // we cannot send info request - icq is offline
m_ratesMutex->Leave();
break;
}
@@ -307,21 +269,16 @@ void __cdecl CIcqProto::InfoUpdateThread( void* ) int nRequestSize = 0;
infoUpdateMutex->Enter();
- for (i = 0; i<LISTSIZE; i++)
- {
- if (m_infoUpdateList[i].hContact)
- {
+ for (i = 0; i < LISTSIZE; i++) {
+ if (m_infoUpdateList[i].hContact) {
// check TS again, maybe it has been updated while we slept
- if (IsMetaInfoChanged(m_infoUpdateList[i].hContact))
- {
- if (m_infoUpdateList[i].queued + 5 < now)
- {
+ if (IsMetaInfoChanged(m_infoUpdateList[i].hContact)) {
+ if (m_infoUpdateList[i].queued + 5 < now) {
BYTE *pItem = NULL;
int nItemSize = 0;
- DBVARIANT dbv = {DBVT_DELETED};
+ DBVARIANT dbv = { DBVT_DELETED };
- if (!getSetting(m_infoUpdateList[i].hContact, DBSETTING_METAINFO_TOKEN, &dbv))
- { // retrieve user details using privacy token
+ if (!getSetting(m_infoUpdateList[i].hContact, DBSETTING_METAINFO_TOKEN, &dbv)) { // retrieve user details using privacy token
ppackTLV(&pItem, &nItemSize, 0x96, dbv.cpbVal, dbv.pbVal);
db_free(&dbv);
}
@@ -336,8 +293,7 @@ void __cdecl CIcqProto::InfoUpdateThread( void* ) hContactList[nListIndex++] = &m_infoUpdateList[i];
}
}
- else
- {
+ else {
#ifdef _DEBUG
debugLogA("Dequeued absolete user %u", m_infoUpdateList[i].dwUin);
#endif
@@ -353,21 +309,19 @@ void __cdecl CIcqProto::InfoUpdateThread( void* ) #ifdef _DEBUG
debugLogA("Request info for %u user(s).", nListIndex);
#endif
- if (!nListIndex)
- { // no users to request info for
+ if (!nListIndex) { // no users to request info for
infoUpdateMutex->Leave();
break;
}
- if (!(dwInfoActiveRequest = sendUserInfoMultiRequest(pRequestData, nRequestSize, nListIndex)))
- { // sending data packet failed
+
+ if (!(dwInfoActiveRequest = sendUserInfoMultiRequest(pRequestData, nRequestSize, nListIndex))) { // sending data packet failed
SAFE_FREE((void**)&pRequestData);
infoUpdateMutex->Leave();
break;
}
SAFE_FREE((void**)&pRequestData);
- for (i = 0; i<nListIndex; i++)
- { // Dequeue users and go back to sleep
+ for (i = 0; i < nListIndex; i++) { // Dequeue users and go back to sleep
hContactList[i]->dwUin = 0;
hContactList[i]->hContact = NULL;
hContactList[i]->queued = 0;
diff --git a/protocols/IcqOscarJ/src/icq_proto.cpp b/protocols/IcqOscarJ/src/icq_proto.cpp index d19156bd12..6b870cfb76 100644 --- a/protocols/IcqOscarJ/src/icq_proto.cpp +++ b/protocols/IcqOscarJ/src/icq_proto.cpp @@ -290,13 +290,10 @@ int CIcqProto::OnModulesLoaded(WPARAM wParam, LPARAM lParam) ModuleLoad(0, 0);
InitXStatusItems(FALSE);
- MCONTACT hContact = db_find_first(m_szModuleName);
- while (hContact != NULL) {
+ for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
DWORD bXStatus = getContactXStatus(hContact);
if (bXStatus > 0)
setContactExtraIcon(hContact, bXStatus);
-
- hContact = db_find_next(hContact, m_szModuleName);
}
return 0;
@@ -315,42 +312,35 @@ int CIcqProto::OnPreShutdown(WPARAM wParam, LPARAM lParam) ////////////////////////////////////////////////////////////////////////////////////////
// PS_AddToList - adds a contact to the contact list
-MCONTACT CIcqProto::AddToList(int flags, PROTOSEARCHRESULT* psr)
+MCONTACT CIcqProto::AddToList(int flags, PROTOSEARCHRESULT *psr)
{
- if (psr) {
- if (psr->cbSize == sizeof(ICQSEARCHRESULT)) {
- ICQSEARCHRESULT *isr = (ICQSEARCHRESULT*)psr;
- if (isr->uin)
- return AddToListByUIN(isr->uin, flags);
- else { // aim contact
- char szUid[MAX_PATH];
-
- if (isr->hdr.flags & PSR_UNICODE)
- unicode_to_ansi_static((WCHAR*)isr->hdr.id, szUid, MAX_PATH);
- else
- null_strcpy(szUid, (char*)isr->hdr.id, MAX_PATH);
-
- if (szUid[0] == 0) return 0;
- return AddToListByUID(szUid, flags);
- }
- }
- else {
- char szUid[MAX_PATH];
-
- if (psr->flags & PSR_UNICODE)
- unicode_to_ansi_static((WCHAR*)psr->id, szUid, MAX_PATH);
- else
- null_strcpy(szUid, (char*)psr->id, MAX_PATH);
+ if (psr == NULL) return 0;
+
+ char szUid[MAX_PATH];
+ if (psr->cbSize == sizeof(ICQSEARCHRESULT)) {
+ ICQSEARCHRESULT *isr = (ICQSEARCHRESULT*)psr;
+ if (isr->uin)
+ return AddToListByUIN(isr->uin, flags);
+
+ // aim contact
+ if (isr->hdr.flags & PSR_UNICODE)
+ unicode_to_ansi_static((WCHAR*)isr->hdr.id, szUid, MAX_PATH);
+ else
+ null_strcpy(szUid, (char*)isr->hdr.id, MAX_PATH);
- if (szUid[0] == 0) return 0;
- if (IsStringUIN(szUid))
- return AddToListByUIN(atoi(szUid), flags);
- else
- return AddToListByUID(szUid, flags);
- }
+ return (szUid[0] == 0) ? 0 : AddToListByUID(szUid, flags);
}
- return 0; // Failure
+ if (psr->flags & PSR_UNICODE)
+ unicode_to_ansi_static((WCHAR*)psr->id, szUid, MAX_PATH);
+ else
+ null_strcpy(szUid, (char*)psr->id, MAX_PATH);
+
+ if (szUid[0] == 0)
+ return 0;
+ if (IsStringUIN(szUid))
+ return AddToListByUIN(atoi(szUid), flags);
+ return AddToListByUID(szUid, flags);
}
MCONTACT __cdecl CIcqProto::AddToListByEvent(int flags, int iContact, HANDLE hDbEvent)
diff --git a/protocols/IcqOscarJ/src/icqosc_svcs.cpp b/protocols/IcqOscarJ/src/icqosc_svcs.cpp index c5060ab1e4..df568a5b30 100644 --- a/protocols/IcqOscarJ/src/icqosc_svcs.cpp +++ b/protocols/IcqOscarJ/src/icqosc_svcs.cpp @@ -656,18 +656,15 @@ MCONTACT CIcqProto::AddToListByUID(const char *szUID, DWORD dwFlags) {
int bAdded;
MCONTACT hContact = HContactFromUID(0, szUID, &bAdded);
- if (hContact)
- {
- if (!(dwFlags & PALF_TEMPORARY) && db_get_b(hContact, "CList", "NotOnList", 0))
- {
- setContactHidden(hContact, 0);
- db_unset(hContact, "CList", "NotOnList");
- }
-
- return hContact; // Success
+ if (hContact == 0)
+ return 0; // Failure
+
+ if (!(dwFlags & PALF_TEMPORARY) && db_get_b(hContact, "CList", "NotOnList", 0)) {
+ setContactHidden(hContact, 0);
+ db_unset(hContact, "CList", "NotOnList");
}
- return NULL; // Failure
+ return hContact; // Success
}
|