summaryrefslogtreecommitdiff
path: root/protocols/IcqOscarJ/src/icq_servlist.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/IcqOscarJ/src/icq_servlist.cpp')
-rw-r--r--protocols/IcqOscarJ/src/icq_servlist.cpp1032
1 files changed, 356 insertions, 676 deletions
diff --git a/protocols/IcqOscarJ/src/icq_servlist.cpp b/protocols/IcqOscarJ/src/icq_servlist.cpp
index af0bd9a158..ecf67683ed 100644
--- a/protocols/IcqOscarJ/src/icq_servlist.cpp
+++ b/protocols/IcqOscarJ/src/icq_servlist.cpp
@@ -34,24 +34,21 @@
void CIcqProto::servlistBeginOperation(int operationCount, int bImport)
{
- if (operationCount)
- { // check if we should send operation begin packet
+ // check if we should send operation begin packet
+ if (operationCount) {
if (!servlistEditCount)
icq_sendServerBeginOperation(bImport);
+
// update count of active operations
servlistEditCount += operationCount;
-#ifdef _DEBUG
debugLogA("Server-List: Begin operation processed (%d operations active)", servlistEditCount);
-#endif
}
}
void CIcqProto::servlistEndOperation(int operationCount)
{
- if (operationCount)
- {
- if (operationCount > servlistEditCount)
- { // sanity check
+ if (operationCount) {
+ if (operationCount > servlistEditCount) { // sanity check
debugLogA("Error: Server-List End operation is not paired!");
operationCount = servlistEditCount;
}
@@ -60,65 +57,57 @@ void CIcqProto::servlistEndOperation(int operationCount)
// check if we should send operation end packet
if (!servlistEditCount)
icq_sendServerEndOperation();
-#ifdef _DEBUG
+
debugLogA("Server-List: End operation processed (%d operations active)", servlistEditCount);
-#endif
}
}
void __cdecl CIcqProto::servlistQueueThread(void *param)
{
- int* queueState = ( int* )param;
-
-#ifdef _DEBUG
debugLogA("Server-List: Starting Update board.");
-#endif
+ int *queueState = (int*)param;
SleepEx(50, FALSE);
+
// handle server-list requests queue
servlistQueueMutex->Enter();
- while (servlistQueueCount)
- {
+ while (servlistQueueCount) {
ssiqueueditems* pItem = NULL;
int bItemDouble;
WORD wItemAction;
- icq_packet groupPacket = {0};
- icq_packet groupPacket2 = {0};
+ icq_packet groupPacket = { 0 };
+ icq_packet groupPacket2 = { 0 };
cookie_servlist_action* pGroupCookie = NULL;
int nEndOperations;
// first check if the state is calm
- while (*queueState)
- {
+ while (*queueState) {
int i;
time_t tNow = time(NULL);
int bFound = FALSE;
- for (i = 0; i < servlistQueueCount; i++)
- { // check if we do not have some expired items to handle, otherwise keep sleeping
- if ((servlistQueueList[i]->tAdded + servlistQueueList[i]->dwTimeout) < tNow)
- { // got expired item, stop sleep even when changes goes on
+ for (i = 0; i < servlistQueueCount; i++) { // check if we do not have some expired items to handle, otherwise keep sleeping
+ if ((servlistQueueList[i]->tAdded + servlistQueueList[i]->dwTimeout) < tNow) { // got expired item, stop sleep even when changes goes on
bFound = TRUE;
break;
}
}
if (bFound) break;
// reset queue state, keep sleeping
- *queueState = FALSE;
+ *queueState = FALSE;
servlistQueueMutex->Leave();
SleepEx(100, TRUE);
servlistQueueMutex->Enter();
}
- if (!icqOnline())
- { // do not try to send packets if offline
+ if (!icqOnline()) { // do not try to send packets if offline
servlistQueueMutex->Leave();
SleepEx(100, TRUE);
servlistQueueMutex->Enter();
continue;
}
-#ifdef _DEBUG
+
debugLogA("Server-List: %d items in queue.", servlistQueueCount);
-#endif
+
// take the oldest item (keep the board FIFO)
pItem = servlistQueueList[0]; // take first (queue contains at least one item here)
wItemAction = (WORD)(pItem->pItems[0]->dwOperation & SSOF_ACTIONMASK);
@@ -129,31 +118,31 @@ void __cdecl CIcqProto::servlistQueueThread(void *param)
WORD wRateGroup = m_rates->getGroupFromSNAC(ICQ_LISTS_FAMILY, wItemAction);
int nRateLevel = bItemDouble ? RML_IDLE_30 : RML_IDLE_10;
- while (m_rates->getNextRateLevel(wRateGroup) < m_rates->getLimitLevel(wRateGroup, nRateLevel))
- { // the rate is higher, keep sleeping
+ while (m_rates->getNextRateLevel(wRateGroup) < m_rates->getLimitLevel(wRateGroup, nRateLevel)) { // the rate is higher, keep sleeping
int nDelay = m_rates->getDelayToLimitLevel(wRateGroup, nRateLevel);
m_ratesMutex->Leave();
// do not keep the queue frozen
servlistQueueMutex->Leave();
if (nDelay < 10) nDelay = 10;
-#ifdef _DEBUG
+
debugLogA("Server-List: Delaying %dms [Rates]", nDelay);
-#endif
+
SleepEx(nDelay, FALSE);
// check if the rate is now ok
servlistQueueMutex->Enter();
m_ratesMutex->Enter();
- }
+ }
}
m_ratesMutex->Leave();
- { // setup group packet(s) & cookie
+ {
+ // setup group packet(s) & cookie
int totalSize = 0;
int i;
cookie_servlist_action *pGroupCookie;
DWORD dwGroupCookie;
// determine the total size of the packet
- for(i = 0; i < pItem->nItems; i++)
+ for (i = 0; i < pItem->nItems; i++)
totalSize += pItem->pItems[i]->packet.wLen - 0x10;
// process begin & end operation flags
@@ -162,8 +151,7 @@ void __cdecl CIcqProto::servlistQueueThread(void *param)
int nBeginOperations = 0;
nEndOperations = 0;
- for(i = 0; i < pItem->nItems; i++)
- { // collect begin & end operation flags
+ for (i = 0; i < pItem->nItems; i++) { // collect begin & end operation flags
if (pItem->pItems[i]->dwOperation & SSOF_BEGIN_OPERATION)
nBeginOperations++;
if (pItem->pItems[i]->dwOperation & SSOF_END_OPERATION)
@@ -177,14 +165,12 @@ void __cdecl CIcqProto::servlistQueueThread(void *param)
servlistBeginOperation(nBeginOperations, bImportOperation);
}
- if (pItem->nItems > 1)
- { // pack all packet's data, create group cookie
+ if (pItem->nItems > 1) { // pack all packet's data, create group cookie
pGroupCookie = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action));
pGroupCookie->dwAction = SSA_ACTION_GROUP;
pGroupCookie->dwGroupCount = pItem->nItems;
pGroupCookie->pGroupItems = (cookie_servlist_action**)SAFE_MALLOC(pItem->nItems * sizeof(cookie_servlist_action*));
- for (i = 0; i < pItem->nItems; i++)
- { // build group cookie data - assign cookies datas
+ for (i = 0; i < pItem->nItems; i++) { // build group cookie data - assign cookies datas
pGroupCookie->pGroupItems[i] = pItem->pItems[i]->cookie;
// release the separate cookie id
FreeCookieByData(CKT_SERVERLIST, pItem->pItems[i]->cookie);
@@ -197,12 +183,11 @@ void __cdecl CIcqProto::servlistQueueThread(void *param)
for (i = 0; i < pItem->nItems; i++)
packBuffer(&groupPacket, pItem->pItems[i]->packet.pData + 0x10, (WORD)(pItem->pItems[i]->packet.wLen - 0x10));
- if (bItemDouble)
- { // prepare second packet
+ if (bItemDouble) { // prepare second packet
wItemAction = ((servlistgroupitemdouble*)(pItem->pItems[0]))->wAction2;
totalSize = 0;
// determine the total size of the packet
- for(i = 0; i < pItem->nItems; i++)
+ for (i = 0; i < pItem->nItems; i++)
totalSize += ((servlistgroupitemdouble*)(pItem->pItems[i]))->packet2.wLen - 0x10;
pGroupCookie = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action));
@@ -220,36 +205,31 @@ void __cdecl CIcqProto::servlistQueueThread(void *param)
packBuffer(&groupPacket2, ((servlistgroupitemdouble*)(pItem->pItems[i]))->packet2.pData + 0x10, (WORD)(((servlistgroupitemdouble*)(pItem->pItems[i]))->packet2.wLen - 0x10));
}
}
- else
- { // just send the one packet, do not create action group
+ else { // just send the one packet, do not create action group
pGroupCookie = pItem->pItems[0]->cookie;
memcpy(&groupPacket, &pItem->pItems[0]->packet, sizeof(icq_packet));
if (bItemDouble)
memcpy(&groupPacket2, &((servlistgroupitemdouble*)(pItem->pItems[0]))->packet2, sizeof(icq_packet));
}
- { // remove grouped item from queue & release grouped item
- servlistQueueCount--;
- servlistQueueList[0] = servlistQueueList[servlistQueueCount];
+ // remove grouped item from queue & release grouped item
+ servlistQueueCount--;
+ servlistQueueList[0] = servlistQueueList[servlistQueueCount];
- for (i = 0; i < pItem->nItems; i++)
- { // release memory
- if (pItem->nItems > 1)
- { // free the packet only if we created the group packet
- SAFE_FREE((void**)&pItem->pItems[i]->packet.pData);
- if (pItem->pItems[i]->dwOperation & SSOG_DOUBLE)
- SAFE_FREE((void**)&((servlistgroupitemdouble*)(pItem->pItems[i]))->packet2.pData);
- }
- SAFE_FREE((void**)&pItem->pItems[i]);
- break;
- }
- SAFE_FREE((void**)&pItem);
- // resize the queue
- if (servlistQueueSize > servlistQueueCount + 6)
- {
- servlistQueueSize -= 4;
- servlistQueueList = (ssiqueueditems**)SAFE_REALLOC(servlistQueueList, servlistQueueSize * sizeof(ssiqueueditems*));
+ for (i = 0; i < pItem->nItems; i++) { // release memory
+ if (pItem->nItems > 1) { // free the packet only if we created the group packet
+ SAFE_FREE((void**)&pItem->pItems[i]->packet.pData);
+ if (pItem->pItems[i]->dwOperation & SSOG_DOUBLE)
+ SAFE_FREE((void**)&((servlistgroupitemdouble*)(pItem->pItems[i]))->packet2.pData);
}
+ SAFE_FREE((void**)&pItem->pItems[i]);
+ break;
+ }
+ SAFE_FREE((void**)&pItem);
+ // resize the queue
+ if (servlistQueueSize > servlistQueueCount + 6) {
+ servlistQueueSize -= 4;
+ servlistQueueList = (ssiqueueditems**)SAFE_REALLOC(servlistQueueList, servlistQueueSize * sizeof(ssiqueueditems*));
}
}
servlistQueueMutex->Leave();
@@ -269,85 +249,73 @@ void __cdecl CIcqProto::servlistQueueThread(void *param)
CloseHandle(servlistQueueThreadHandle);
servlistQueueThreadHandle = NULL;
servlistQueueMutex->Leave();
-#ifdef _DEBUG
+
debugLogA("Server-List: Update Board ending.");
-#endif
}
void CIcqProto::servlistQueueAddGroupItem(servlistgroupitem* pGroupItem, int dwTimeout)
{
icq_lock l(servlistQueueMutex);
- { // add the packet to queue
- DWORD dwMark = pGroupItem->dwOperation & SSOF_GROUPINGMASK;
- ssiqueueditems* pItem = NULL;
+ // add the packet to queue
+ DWORD dwMark = pGroupItem->dwOperation & SSOF_GROUPINGMASK;
+ ssiqueueditems* pItem = NULL;
- // try to find compatible item
- for (int i = 0; i < servlistQueueCount; i++)
- {
- if ((servlistQueueList[i]->pItems[0]->dwOperation & SSOF_GROUPINGMASK) == dwMark && servlistQueueList[i]->nItems < MAX_SERVLIST_PACKET_ITEMS)
- { // found compatible item, check if it does not contain operation for the same server-list item
- pItem = servlistQueueList[i];
-
- for (int j = 0; j < pItem->nItems; j++)
- if (pItem->pItems[j]->cookie->wContactId == pGroupItem->cookie->wContactId &&
- pItem->pItems[j]->cookie->wGroupId == pGroupItem->cookie->wGroupId)
- {
- pItem = NULL;
- break;
- }
- // cannot send two operations for the same server-list record in one packet, look for another
- if (!pItem) continue;
-
-#ifdef _DEBUG
- debugLogA("Server-List: Adding packet to item #%d with operation %x.", i, servlistQueueList[i]->pItems[0]->dwOperation);
-#endif
+ // try to find compatible item
+ for (int i = 0; i < servlistQueueCount; i++) {
+ if ((servlistQueueList[i]->pItems[0]->dwOperation & SSOF_GROUPINGMASK) == dwMark && servlistQueueList[i]->nItems < MAX_SERVLIST_PACKET_ITEMS) { // found compatible item, check if it does not contain operation for the same server-list item
+ pItem = servlistQueueList[i];
+
+ for (int j = 0; j < pItem->nItems; j++)
+ if (pItem->pItems[j]->cookie->wContactId == pGroupItem->cookie->wContactId && pItem->pItems[j]->cookie->wGroupId == pGroupItem->cookie->wGroupId) {
+ pItem = NULL;
break;
- }
+ }
+
+ // cannot send two operations for the same server-list record in one packet, look for another
+ if (!pItem)
+ continue;
+
+ debugLogA("Server-List: Adding packet to item #%d with operation %x.", i, servlistQueueList[i]->pItems[0]->dwOperation);
+ break;
}
- if (!pItem)
- { // compatible item was not found, create new one, add to queue
- pItem = (ssiqueueditems*)SAFE_MALLOC(sizeof(ssiqueueditems));
- pItem->tAdded = time(NULL);
- pItem->dwTimeout = dwTimeout;
-
- if (servlistQueueCount == servlistQueueSize)
- { // resize the queue - it is too small
- servlistQueueSize += 4;
- servlistQueueList = (ssiqueueditems**)SAFE_REALLOC(servlistQueueList, servlistQueueSize * sizeof(ssiqueueditems*));
- }
- // really add to queue
- servlistQueueList[servlistQueueCount++] = pItem;
-#ifdef _DEBUG
- debugLogA("Server-List: Adding new item to queue.");
-#endif
- }
- else if (pItem->dwTimeout > dwTimeout)
- { // if the timeout of currently added packet is shorter, update the previous one
- pItem->dwTimeout = dwTimeout;
+ }
+ if (!pItem) { // compatible item was not found, create new one, add to queue
+ pItem = (ssiqueueditems*)SAFE_MALLOC(sizeof(ssiqueueditems));
+ pItem->tAdded = time(NULL);
+ pItem->dwTimeout = dwTimeout;
+
+ if (servlistQueueCount == servlistQueueSize) { // resize the queue - it is too small
+ servlistQueueSize += 4;
+ servlistQueueList = (ssiqueueditems**)SAFE_REALLOC(servlistQueueList, servlistQueueSize * sizeof(ssiqueueditems*));
}
- // add GroupItem to queueditems (pItem)
- pItem->pItems[pItem->nItems++] = pGroupItem;
+ // really add to queue
+ servlistQueueList[servlistQueueCount++] = pItem;
+
+ debugLogA("Server-List: Adding new item to queue.");
+ }
+ else if (pItem->dwTimeout > dwTimeout) {
+ // if the timeout of currently added packet is shorter, update the previous one
+ pItem->dwTimeout = dwTimeout;
}
+ // add GroupItem to queueditems (pItem)
+ pItem->pItems[pItem->nItems++] = pGroupItem;
+
// wake up board thread (keep sleeping or start new one)
if (!servlistQueueThreadHandle)
- {
// create new board thread
servlistQueueThreadHandle = ForkThreadEx(&CIcqProto::servlistQueueThread, &servlistQueueState, 0);
- }
else // signal thread, that queue was changed during sleep
servlistQueueState = TRUE;
}
int CIcqProto::servlistHandlePrimitives(DWORD dwOperation)
{
- if (dwOperation & SSO_BEGIN_OPERATION)
- { // operation starting, no action ready yet
+ if (dwOperation & SSO_BEGIN_OPERATION) { // operation starting, no action ready yet
servlistBeginOperation(1, dwOperation & SSOF_IMPORT_OPERATION);
return TRUE;
}
- else if (dwOperation & SSO_END_OPERATION)
- { // operation ending without action
+ if (dwOperation & SSO_END_OPERATION) { // operation ending without action
servlistEndOperation(1);
return TRUE;
}
@@ -365,8 +333,7 @@ void CIcqProto::servlistPostPacket(icq_packet* packet, DWORD dwCookie, DWORD dwO
if (!FindCookie(dwCookie, NULL, (void**)&pCookie))
return; // invalid cookie
- if (dwOperation & SSOF_SEND_DIRECTLY)
- { // send directly - this is for some special cases
+ if (dwOperation & SSOF_SEND_DIRECTLY) { // send directly - this is for some special cases
// begin operation if requested
if (dwOperation & SSOF_BEGIN_OPERATION)
servlistBeginOperation(1, dwOperation & SSOF_IMPORT_OPERATION);
@@ -378,12 +345,9 @@ void CIcqProto::servlistPostPacket(icq_packet* packet, DWORD dwCookie, DWORD dwO
if (dwOperation & SSOF_END_OPERATION)
servlistEndOperation(1);
}
- else
- { // add to server-list update board
- servlistgroupitem* pGroupItem;
-
+ else { // add to server-list update board
// prepare group item
- pGroupItem = (servlistgroupitem*)SAFE_MALLOC(sizeof(servlistgroupitem));
+ servlistgroupitem *pGroupItem = (servlistgroupitem*)SAFE_MALLOC(sizeof(servlistgroupitem));
pGroupItem->dwOperation = dwOperation;
pGroupItem->cookie = pCookie;
// packet data are alloced, keep them until they are sent
@@ -403,8 +367,7 @@ void CIcqProto::servlistPostPacketDouble(icq_packet* packet1, DWORD dwCookie, DW
if (!FindCookie(dwCookie, NULL, (void**)&pCookie))
return; // invalid cookie
- if (dwOperation & SSOF_SEND_DIRECTLY)
- { // send directly - this is for some special cases
+ if (dwOperation & SSOF_SEND_DIRECTLY) { // send directly - this is for some special cases
// begin operation if requested
if (dwOperation & SSOF_BEGIN_OPERATION)
servlistBeginOperation(1, dwOperation & SSOF_IMPORT_OPERATION);
@@ -417,8 +380,7 @@ void CIcqProto::servlistPostPacketDouble(icq_packet* packet1, DWORD dwCookie, DW
if (dwOperation & SSOF_END_OPERATION)
servlistEndOperation(1);
}
- else
- { // add to server-list update board
+ else { // add to server-list update board
servlistgroupitemdouble* pGroupItem;
// prepare group item
@@ -467,19 +429,16 @@ int CIcqProto::servlistPendingFindItem(int nType, MCONTACT hContact, const char
if (servlistPendingList)
for (int i = 0; i < servlistPendingCount; i++)
if (servlistPendingList[i]->nType == nType)
- {
if (((nType == ITEM_PENDING_CONTACT) && (servlistPendingList[i]->hContact == hContact)) ||
- ((nType == ITEM_PENDING_GROUP) && (!strcmpnull(servlistPendingList[i]->szGroup, pszGroup))))
+ ((nType == ITEM_PENDING_GROUP) && (!strcmpnull(servlistPendingList[i]->szGroup, pszGroup))))
return i;
- }
- return -1;
-}
+ return -1;
+}
void CIcqProto::servlistPendingAddItem(servlistpendingitem *pItem)
{
- if (servlistPendingCount >= servlistPendingSize) // add new
- {
+ if (servlistPendingCount >= servlistPendingSize) { // add new
servlistPendingSize += 10;
servlistPendingList = (servlistpendingitem**)SAFE_REALLOC(servlistPendingList, servlistPendingSize * sizeof(servlistpendingitem*));
}
@@ -487,38 +446,33 @@ void CIcqProto::servlistPendingAddItem(servlistpendingitem *pItem)
servlistPendingList[servlistPendingCount++] = pItem;
}
-
servlistpendingitem* CIcqProto::servlistPendingRemoveItem(int nType, MCONTACT hContact, const char *pszGroup)
-{ // unregister pending item, trigger pending operations
+{
+ // unregister pending item, trigger pending operations
int iItem;
servlistpendingitem *pItem = NULL;
icq_lock l(servlistMutex);
- if ((iItem = servlistPendingFindItem(nType, hContact, pszGroup)) != -1)
- { // found, remove from the pending list
+ if ((iItem = servlistPendingFindItem(nType, hContact, pszGroup)) != -1) { // found, remove from the pending list
pItem = servlistPendingList[iItem];
servlistPendingList[iItem] = servlistPendingList[--servlistPendingCount];
- if (servlistPendingCount + 10 < servlistPendingSize)
- {
+ if (servlistPendingCount + 10 < servlistPendingSize) {
servlistPendingSize -= 5;
servlistPendingList = (servlistpendingitem**)SAFE_REALLOC(servlistPendingList, servlistPendingSize * sizeof(servlistpendingitem*));
}
+
// was the first operation was created automatically to postpone ItemAdd?
- if (pItem->operations && pItem->operations[0].flags & SPOF_AUTO_CREATE_ITEM)
- { // yes, add new item
+ if (pItem->operations && pItem->operations[0].flags & SPOF_AUTO_CREATE_ITEM) { // yes, add new item
servlistpendingitem *pNewItem = (servlistpendingitem*)SAFE_MALLOC(sizeof(servlistpendingitem));
- if (pNewItem)
- { // move the remaining operations
-#ifdef _DEBUG
+ if (pNewItem) { // move the remaining operations
if (pItem->nType == ITEM_PENDING_CONTACT)
debugLogA("Server-List: Resuming contact %x operation.", pItem->hContact);
else
debugLogA("Server-List: Resuming group \"%s\" operation.", pItem->szGroup);
-#endif
pNewItem->nType = pItem->nType;
pNewItem->hContact = pItem->hContact;
@@ -536,17 +490,15 @@ servlistpendingitem* CIcqProto::servlistPendingRemoveItem(int nType, MCONTACT hC
}
}
}
-#ifdef _DEBUG
- else
- debugLogA("Server-List Error: Trying to remove non-existing pending %s.", nType == ITEM_PENDING_CONTACT ? "contact" : "group");
-#endif
+ else debugLogA("Server-List Error: Trying to remove non-existing pending %s.", nType == ITEM_PENDING_CONTACT ? "contact" : "group");
return pItem;
}
void CIcqProto::servlistPendingAddContactOperation(MCONTACT hContact, LPARAM param, PENDING_CONTACT_CALLBACK callback, DWORD flags)
-{ // add postponed operation (add contact, update contact, regroup resume, etc.)
+{
+ // add postponed operation (add contact, update contact, regroup resume, etc.)
// - after contact is added
int iItem;
servlistpendingitem *pItem = NULL;
@@ -556,8 +508,7 @@ void CIcqProto::servlistPendingAddContactOperation(MCONTACT hContact, LPARAM par
if ((iItem = servlistPendingFindItem(ITEM_PENDING_CONTACT, hContact, NULL)) != -1)
pItem = servlistPendingList[iItem];
- if (pItem)
- {
+ if (pItem) {
int iOperation = pItem->operationsCount++;
pItem->operations = (servlistpendingoperation*)SAFE_REALLOC(pItem->operations, pItem->operationsCount * sizeof(servlistpendingoperation));
@@ -565,15 +516,12 @@ void CIcqProto::servlistPendingAddContactOperation(MCONTACT hContact, LPARAM par
pItem->operations[iOperation].callback = (PENDING_GROUP_CALLBACK)callback;
pItem->operations[iOperation].flags = flags;
}
- else
- {
- debugLogA("Server-List Error: Trying to add pending operation to a non existing contact.");
- }
+ else debugLogA("Server-List Error: Trying to add pending operation to a non existing contact.");
}
-
void CIcqProto::servlistPendingAddGroupOperation(const char *pszGroup, LPARAM param, PENDING_GROUP_CALLBACK callback, DWORD flags)
-{ // add postponed operation - after group is added
+{
+ // add postponed operation - after group is added
int iItem;
servlistpendingitem *pItem = NULL;
@@ -582,8 +530,7 @@ void CIcqProto::servlistPendingAddGroupOperation(const char *pszGroup, LPARAM pa
if ((iItem = servlistPendingFindItem(ITEM_PENDING_GROUP, NULL, pszGroup)) != -1)
pItem = servlistPendingList[iItem];
- if (pItem)
- {
+ if (pItem) {
int iOperation = pItem->operationsCount++;
pItem->operations = (servlistpendingoperation*)SAFE_REALLOC(pItem->operations, pItem->operationsCount * sizeof(servlistpendingoperation));
@@ -591,13 +538,9 @@ void CIcqProto::servlistPendingAddGroupOperation(const char *pszGroup, LPARAM pa
pItem->operations[iOperation].callback = callback;
pItem->operations[iOperation].flags = flags;
}
- else
- {
- debugLogA("Server-List Error: Trying to add pending operation to a non existing group.");
- }
+ else debugLogA("Server-List Error: Trying to add pending operation to a non existing group.");
}
-
int CIcqProto::servlistPendingAddContact(MCONTACT hContact, WORD wContactID, WORD wGroupID, LPARAM param, PENDING_CONTACT_CALLBACK callback, int bDoInline, LPARAM operationParam, PENDING_CONTACT_CALLBACK operationCallback)
{
int iItem;
@@ -608,24 +551,19 @@ int CIcqProto::servlistPendingAddContact(MCONTACT hContact, WORD wContactID, WOR
if ((iItem = servlistPendingFindItem(ITEM_PENDING_CONTACT, hContact, NULL)) != -1)
pItem = servlistPendingList[iItem];
- if (pItem)
- {
-#ifdef _DEBUG
+ if (pItem) {
debugLogA("Server-List: Pending contact %x already in list; adding as operation.", hContact);
-#endif
+
servlistPendingAddContactOperation(hContact, param, callback, SPOF_AUTO_CREATE_ITEM);
if (operationCallback)
servlistPendingAddContactOperation(hContact, operationParam, operationCallback, 0);
servlistMutex->Leave();
-
return 0; // Pending
}
-#ifdef _DEBUG
debugLogA("Server-List: Starting contact %x operation.", hContact);
-#endif
pItem = (servlistpendingitem *)SAFE_MALLOC(sizeof(servlistpendingitem));
pItem->nType = ITEM_PENDING_CONTACT;
@@ -640,15 +578,12 @@ int CIcqProto::servlistPendingAddContact(MCONTACT hContact, WORD wContactID, WOR
servlistMutex->Leave();
- if (bDoInline)
- { // not postponed, called directly if requested
+ if (bDoInline) // not postponed, called directly if requested
(this->*callback)(hContact, wContactID, wGroupID, param, PENDING_RESULT_INLINE);
- }
return 1; // Ready
}
-
int CIcqProto::servlistPendingAddGroup(const char *pszGroup, WORD wGroupID, LPARAM param, PENDING_GROUP_CALLBACK callback, int bDoInline, LPARAM operationParam, PENDING_GROUP_CALLBACK operationCallback)
{
int iItem;
@@ -659,11 +594,9 @@ int CIcqProto::servlistPendingAddGroup(const char *pszGroup, WORD wGroupID, LPAR
if ((iItem = servlistPendingFindItem(ITEM_PENDING_GROUP, NULL, pszGroup)) != -1)
pItem = servlistPendingList[iItem];
- if (pItem)
- {
-#ifdef _DEBUG
+ if (pItem) {
debugLogA("Server-List: Pending group \"%s\" already in list; adding as operation.", pszGroup);
-#endif
+
servlistPendingAddGroupOperation(pszGroup, param, callback, SPOF_AUTO_CREATE_ITEM);
if (operationCallback)
@@ -674,9 +607,7 @@ int CIcqProto::servlistPendingAddGroup(const char *pszGroup, WORD wGroupID, LPAR
return 0; // Pending
}
-#ifdef _DEBUG
debugLogA("Server-List: Starting group \"%s\" operation.", pszGroup);
-#endif
pItem = (servlistpendingitem *)SAFE_MALLOC(sizeof(servlistpendingitem));
pItem->nType = ITEM_PENDING_GROUP;
@@ -690,76 +621,56 @@ int CIcqProto::servlistPendingAddGroup(const char *pszGroup, WORD wGroupID, LPAR
servlistMutex->Leave();
- if (bDoInline)
- { // not postponed, called directly if requested
+ if (bDoInline) // not postponed, called directly if requested
(this->*callback)(pszGroup, wGroupID, param, PENDING_RESULT_INLINE);
- }
return 1; // Ready
}
-
void CIcqProto::servlistPendingRemoveContact(MCONTACT hContact, WORD wContactID, WORD wGroupID, int nResult)
{
-#ifdef _DEBUG
debugLogA("Server-List: %s contact %x operation.", (nResult != PENDING_RESULT_PURGE) ? "Ending" : "Purging", hContact);
-#endif
servlistpendingitem *pItem = servlistPendingRemoveItem(ITEM_PENDING_CONTACT, hContact, NULL);
- if (pItem)
- { // process pending operations
- if (pItem->operations)
- {
- for (int i = 0; i < pItem->operationsCount; i++)
- {
+ if (pItem) { // process pending operations
+ if (pItem->operations) {
+ for (int i = 0; i < pItem->operationsCount; i++) {
int nCallbackState = (this->*(PENDING_CONTACT_CALLBACK)(pItem->operations[i].callback))(hContact, wContactID, wGroupID, pItem->operations[i].param, nResult);
- if (nResult != PENDING_RESULT_PURGE && nCallbackState == CALLBACK_RESULT_POSTPONE)
- { // any following pending operations cannot be processed now, move them to the new pending contact
+ if (nResult != PENDING_RESULT_PURGE && nCallbackState == CALLBACK_RESULT_POSTPONE) { // any following pending operations cannot be processed now, move them to the new pending contact
for (int j = i + 1; j < pItem->operationsCount; j++)
servlistPendingAddContactOperation(hContact, pItem->operations[j].param, (PENDING_CONTACT_CALLBACK)(pItem->operations[j].callback), pItem->operations[j].flags);
break;
}
- else if (nCallbackState == CALLBACK_RESULT_PURGE)
- { // purge all following operations - fatal failure occured
+ else if (nCallbackState == CALLBACK_RESULT_PURGE) // purge all following operations - fatal failure occured
nResult = PENDING_RESULT_PURGE;
- }
}
SAFE_FREE((void**)&pItem->operations);
}
// release item's memory
SAFE_FREE((void**)&pItem);
}
- else
- debugLogA("Server-List Error: Trying to remove a non existing pending contact.");
+ else debugLogA("Server-List Error: Trying to remove a non existing pending contact.");
}
-
void CIcqProto::servlistPendingRemoveGroup(const char *pszGroup, WORD wGroupID, int nResult)
{
-#ifdef _DEBUG
debugLogA("Server-List: %s group \"%s\" operation.", (nResult != PENDING_RESULT_PURGE) ? "Ending" : "Purging", pszGroup);
-#endif
servlistpendingitem *pItem = servlistPendingRemoveItem(ITEM_PENDING_GROUP, NULL, pszGroup);
- if (pItem)
- { // process pending operations
- if (pItem->operations)
- {
- for (int i = 0; i < pItem->operationsCount; i++)
- {
+ if (pItem) { // process pending operations
+ if (pItem->operations) {
+ for (int i = 0; i < pItem->operationsCount; i++) {
int nCallbackState = (this->*pItem->operations[i].callback)(pItem->szGroup, wGroupID, pItem->operations[i].param, nResult);
- if (nResult != PENDING_RESULT_PURGE && nCallbackState == CALLBACK_RESULT_POSTPONE)
- { // any following pending operations cannot be processed now, move them to the new pending group
+ if (nResult != PENDING_RESULT_PURGE && nCallbackState == CALLBACK_RESULT_POSTPONE) { // any following pending operations cannot be processed now, move them to the new pending group
for (int j = i + 1; j < pItem->operationsCount; j++)
servlistPendingAddGroupOperation(pItem->szGroup, pItem->operations[j].param, pItem->operations[j].callback, pItem->operations[j].flags);
break;
}
- else if (nCallbackState == CALLBACK_RESULT_PURGE)
- { // purge all following operations - fatal failure occured
+ else if (nCallbackState == CALLBACK_RESULT_PURGE) { // purge all following operations - fatal failure occured
nResult = PENDING_RESULT_PURGE;
}
}
@@ -769,18 +680,15 @@ void CIcqProto::servlistPendingRemoveGroup(const char *pszGroup, WORD wGroupID,
SAFE_FREE((void**)&pItem->szGroup);
SAFE_FREE((void**)&pItem);
}
- else
- debugLogA("Server-List Error: Trying to remove a non existing pending group.");
+ else debugLogA("Server-List Error: Trying to remove a non existing pending group.");
}
-
// Remove All pending operations
void CIcqProto::servlistPendingFlushOperations()
{
icq_lock l(servlistMutex);
- for (int i = servlistPendingCount; i; i--)
- { // purge all items
+ for (int i = servlistPendingCount; i; i--) { // purge all items
servlistpendingitem *pItem = servlistPendingList[i - 1];
if (pItem->nType == ITEM_PENDING_CONTACT)
@@ -797,36 +705,29 @@ void CIcqProto::servlistPendingFlushOperations()
// END OF SERVER-LIST PENDING OPERATIONS
////
-
// used for adding new contacts to list - sync with visible items
void CIcqProto::AddJustAddedContact(MCONTACT hContact)
{
icq_lock l(servlistMutex);
- if (nJustAddedCount >= nJustAddedSize)
- {
+ if (nJustAddedCount >= nJustAddedSize) {
nJustAddedSize += 10;
pdwJustAddedList = (MCONTACT*)SAFE_REALLOC(pdwJustAddedList, nJustAddedSize * sizeof(MCONTACT));
}
pdwJustAddedList[nJustAddedCount] = hContact;
- nJustAddedCount++;
+ nJustAddedCount++;
}
-
// was the contact added during this serv-list load
BOOL CIcqProto::IsContactJustAdded(MCONTACT hContact)
{
icq_lock l(servlistMutex);
if (pdwJustAddedList)
- {
- for (int i = 0; i<nJustAddedCount; i++)
- {
+ for (int i = 0; i < nJustAddedCount; i++)
if (pdwJustAddedList[i] == hContact)
return TRUE;
- }
- }
return FALSE;
}
@@ -841,7 +742,6 @@ void CIcqProto::FlushJustAddedContacts()
nJustAddedCount = 0;
}
-
// Add a server ID to the list of reserved IDs.
// To speed up the process, no checks is done, if
// you try to reserve an ID twice, it will be added again.
@@ -849,8 +749,7 @@ void CIcqProto::FlushJustAddedContacts()
void CIcqProto::ReserveServerID(WORD wID, int bGroupType, int bFlags)
{
servlistMutex->Enter();
- if (nServerIDListCount >= nServerIDListSize)
- {
+ if (nServerIDListCount >= nServerIDListSize) {
nServerIDListSize += 100;
pdwServerIDList = (DWORD*)SAFE_REALLOC(pdwServerIDList, nServerIDListSize * sizeof(DWORD));
}
@@ -863,7 +762,6 @@ void CIcqProto::ReserveServerID(WORD wID, int bGroupType, int bFlags)
StoreServerIDs();
}
-
// Remove a server ID from the list of reserved IDs.
// Used for deleting contacts and other modifications.
void CIcqProto::FreeServerID(WORD wID, int bGroupType)
@@ -872,14 +770,11 @@ void CIcqProto::FreeServerID(WORD wID, int bGroupType)
icq_lock l(servlistMutex);
- if (pdwServerIDList)
- {
- for (int i = 0; i<nServerIDListCount; i++)
- {
- if ((pdwServerIDList[i] & 0x00FFFFFF) == dwId)
- { // we found it, so remove
- for (int j = i+1; j<nServerIDListCount; j++)
- pdwServerIDList[j-1] = pdwServerIDList[j];
+ if (pdwServerIDList) {
+ for (int i = 0; i < nServerIDListCount; i++) {
+ if ((pdwServerIDList[i] & 0x00FFFFFF) == dwId) { // we found it, so remove
+ for (int j = i + 1; j < nServerIDListCount; j++)
+ pdwServerIDList[j - 1] = pdwServerIDList[j];
nServerIDListCount--;
}
@@ -887,16 +782,13 @@ void CIcqProto::FreeServerID(WORD wID, int bGroupType)
}
}
-
// Returns true if dwID is reserved
BOOL CIcqProto::CheckServerID(WORD wID, unsigned int wCount)
{
icq_lock l(servlistMutex);
- if (pdwServerIDList)
- {
- for (int i = 0; i<nServerIDListCount; i++)
- {
+ if (pdwServerIDList) {
+ for (int i = 0; i < nServerIDListCount; i++) {
if (((pdwServerIDList[i] & 0xFFFF) >= wID) && ((pdwServerIDList[i] & 0xFFFF) <= wID + wCount))
return TRUE;
}
@@ -922,27 +814,25 @@ struct GroupReserveIdsEnumParam
char *szModule;
};
-static int GroupReserveIdsEnumProc(const char *szSetting,LPARAM lParam)
-{
- if (szSetting && strlennull(szSetting)<5)
- {
+static int GroupReserveIdsEnumProc(const char *szSetting, LPARAM lParam)
+{
+ if (szSetting && strlennull(szSetting) < 5) {
// it is probably server group
GroupReserveIdsEnumParam *param = (GroupReserveIdsEnumParam*)lParam;
- char val[MAX_PATH+2]; // dummy
+ char val[MAX_PATH + 2]; // dummy
if (db_get_static(0, param->szModule, szSetting, val, MAX_PATH))
if (db_get_static_utf(0, param->szModule, szSetting, val, MAX_PATH))
return 0; // we failed also, invalid setting
param->ppro->ReserveServerID((WORD)strtoul(szSetting, NULL, 0x10), SSIT_GROUP, 0);
-#ifdef _DEBUG
param->ppro->debugLogA("Loaded group %u:'%s'", strtoul(szSetting, NULL, 0x10), val);
-#endif
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
// Load all known server IDs from DB to list
+
void CIcqProto::LoadServerIDs()
{
WORD wSrvID;
@@ -976,25 +866,20 @@ void CIcqProto::LoadServerIDs()
MCONTACT hContact = db_find_first(m_szModuleName);
- while (hContact)
- { // search all our contacts, reserve their server IDs
- if (wSrvID = getWord(hContact, DBSETTING_SERVLIST_ID, 0))
- {
+ while (hContact) { // search all our contacts, reserve their server IDs
+ if (wSrvID = getWord(hContact, DBSETTING_SERVLIST_ID, 0)) {
ReserveServerID(wSrvID, SSIT_ITEM, 0);
nContacts++;
}
- if (wSrvID = getWord(hContact, DBSETTING_SERVLIST_DENY, 0))
- {
+ if (wSrvID = getWord(hContact, DBSETTING_SERVLIST_DENY, 0)) {
ReserveServerID(wSrvID, SSIT_ITEM, 0);
nDenys++;
}
- if (wSrvID = getWord(hContact, DBSETTING_SERVLIST_PERMIT, 0))
- {
+ if (wSrvID = getWord(hContact, DBSETTING_SERVLIST_PERMIT, 0)) {
ReserveServerID(wSrvID, SSIT_ITEM, 0);
nPermits++;
}
- if (wSrvID = getWord(hContact, DBSETTING_SERVLIST_IGNORE, 0))
- {
+ if (wSrvID = getWord(hContact, DBSETTING_SERVLIST_IGNORE, 0)) {
ReserveServerID(wSrvID, SSIT_ITEM, 0);
nIgnores++;
}
@@ -1003,14 +888,12 @@ void CIcqProto::LoadServerIDs()
}
servlistMutex->Leave();
- DBVARIANT dbv = {0};
- if (!getSetting(NULL, DBSETTING_SERVLIST_UNHANDLED, &dbv))
- {
+ DBVARIANT dbv = { 0 };
+ if (!getSetting(NULL, DBSETTING_SERVLIST_UNHANDLED, &dbv)) {
int dataLen = dbv.cpbVal;
BYTE *pData = dbv.pbVal;
- while (dataLen >= 4)
- {
+ while (dataLen >= 4) {
BYTE bGroupType;
BYTE bFlags;
@@ -1018,7 +901,7 @@ void CIcqProto::LoadServerIDs()
unpackByte(&pData, &bGroupType);
unpackByte(&pData, &bFlags);
- ReserveServerID(wSrvID, bGroupType, bFlags);
+ ReserveServerID(wSrvID, bGroupType, bFlags);
dataLen -= 4;
nUnhandled++;
}
@@ -1029,7 +912,6 @@ void CIcqProto::LoadServerIDs()
debugLogA("Loaded SSI: %d contacts, %d groups, %d permit, %d deny, %d ignore, %d unknown items.", nContacts, nGroups, nPermits, nDenys, nIgnores, nUnhandled);
}
-
void CIcqProto::StoreServerIDs() /// TODO: allow delayed
{
BYTE *pUnhandled = NULL;
@@ -1037,31 +919,29 @@ void CIcqProto::StoreServerIDs() /// TODO: allow delayed
servlistMutex->Enter();
if (pdwServerIDList)
- for (int i = 0; i<nServerIDListCount; i++)
- if ((pdwServerIDList[i] & 0xFF000000) == SSIF_UNHANDLED)
- {
+ for (int i = 0; i < nServerIDListCount; i++)
+ if ((pdwServerIDList[i] & 0xFF000000) == SSIF_UNHANDLED) {
ppackLEWord(&pUnhandled, &cbUnhandled, pdwServerIDList[i] & 0xFFFF);
ppackByte(&pUnhandled, &cbUnhandled, (pdwServerIDList[i] & 0x00FF0000) >> 0x10);
ppackByte(&pUnhandled, &cbUnhandled, (pdwServerIDList[i] & 0xFF000000) >> 0x18);
}
- servlistMutex->Leave();
- if (pUnhandled)
- setSettingBlob(NULL, DBSETTING_SERVLIST_UNHANDLED, pUnhandled, cbUnhandled);
- else
- delSetting(DBSETTING_SERVLIST_UNHANDLED);
+ servlistMutex->Leave();
- SAFE_FREE((void**)&pUnhandled);
-}
+ if (pUnhandled)
+ setSettingBlob(NULL, DBSETTING_SERVLIST_UNHANDLED, pUnhandled, cbUnhandled);
+ else
+ delSetting(DBSETTING_SERVLIST_UNHANDLED);
+ SAFE_FREE((void**)&pUnhandled);
+}
// Generate server ID with wCount IDs free after it, for sub-groups.
WORD CIcqProto::GenerateServerID(int bGroupType, int bFlags, int wCount)
{
WORD wId;
- while (TRUE)
- {
+ while (TRUE) {
// Randomize a new ID
// Max value is probably 0x7FFF, lowest value is probably 0x0001 (generated by Icq2Go)
// We use range 0x1000-0x7FFF.
@@ -1072,11 +952,9 @@ WORD CIcqProto::GenerateServerID(int bGroupType, int bFlags, int wCount)
}
ReserveServerID(wId, bGroupType, bFlags);
-
return wId;
}
-
/***********************************************
*
* --- Low-level packet sending functions ---
@@ -1090,7 +968,8 @@ struct doubleServerItemObject
};
DWORD CIcqProto::icq_sendServerItem(DWORD dwCookie, WORD wAction, WORD wGroupId, WORD wItemId, const char *szName, BYTE *pTLVs, int nTlvLength, WORD wItemType, DWORD dwOperation, DWORD dwTimeout, void **doubleObject)
-{ // generic packet
+{
+ // generic packet
icq_packet packet;
int nNameLen;
WORD wTLVlen = (WORD)nTlvLength;
@@ -1102,34 +981,28 @@ DWORD CIcqProto::icq_sendServerItem(DWORD dwCookie, WORD wAction, WORD wGroupId,
serverPacketInit(&packet, (WORD)(nNameLen + 20 + wTLVlen));
packFNACHeader(&packet, ICQ_LISTS_FAMILY, wAction, 0, dwCookie);
packWord(&packet, (WORD)nNameLen);
- if (nNameLen)
+ if (nNameLen)
packBuffer(&packet, (LPBYTE)szName, (WORD)nNameLen);
packWord(&packet, wGroupId);
- packWord(&packet, wItemId);
- packWord(&packet, wItemType);
+ packWord(&packet, wItemId);
+ packWord(&packet, wItemType);
packWord(&packet, wTLVlen);
if (wTLVlen)
packBuffer(&packet, pTLVs, wTLVlen);
- if (!doubleObject)
- { // Send the packet and return the cookie
+ if (!doubleObject) // Send the packet and return the cookie
servlistPostPacket(&packet, dwCookie, dwOperation | wAction, dwTimeout);
- }
- else
- {
- if (*doubleObject)
- { // Send both packets and return the cookie
+ else {
+ if (*doubleObject) { // Send both packets and return the cookie
doubleServerItemObject* helper = (doubleServerItemObject*)*doubleObject;
servlistPostPacketDouble(&helper->packet, dwCookie, dwOperation | helper->wAction, dwTimeout, &packet, wAction);
SAFE_FREE(doubleObject);
}
- else
- { // Create helper object, return the cookie
+ else { // Create helper object, return the cookie
doubleServerItemObject* helper = (doubleServerItemObject*)SAFE_MALLOC(sizeof(doubleServerItemObject));
- if (helper)
- {
+ if (helper) {
helper->wAction = wAction;
memcpy(&helper->packet, &packet, sizeof(icq_packet));
*doubleObject = helper;
@@ -1145,7 +1018,6 @@ DWORD CIcqProto::icq_sendServerItem(DWORD dwCookie, WORD wAction, WORD wGroupId,
return dwCookie;
}
-
DWORD CIcqProto::icq_sendServerContact(MCONTACT hContact, DWORD dwCookie, WORD wAction, WORD wGroupId, WORD wContactId, DWORD dwOperation, DWORD dwTimeout, void **doubleObject)
{
DWORD dwUin;
@@ -1159,8 +1031,7 @@ DWORD CIcqProto::icq_sendServerContact(MCONTACT hContact, DWORD dwCookie, WORD w
int bDataTooLong = FALSE;
// Prepare UID
- if (getContactUid(hContact, &dwUin, &szUid))
- {
+ if (getContactUid(hContact, &dwUin, &szUid)) {
debugLogA("Buddy upload failed (UID missing).");
return 0;
}
@@ -1171,16 +1042,14 @@ DWORD CIcqProto::icq_sendServerContact(MCONTACT hContact, DWORD dwCookie, WORD w
DBVARIANT dbv;
- if (!getSetting(hContact, DBSETTING_METAINFO_TOKEN, &dbv))
- {
+ if (!getSetting(hContact, DBSETTING_METAINFO_TOKEN, &dbv)) {
nMetaTokenLen = dbv.cpbVal;
pMetaToken = (BYTE*)_alloca(dbv.cpbVal);
memcpy(pMetaToken, dbv.pbVal, dbv.cpbVal);
db_free(&dbv);
}
- if (!getSetting(hContact, DBSETTING_METAINFO_TIME, &dbv))
- {
+ if (!getSetting(hContact, DBSETTING_METAINFO_TIME, &dbv)) {
nMetaTimeLen = dbv.cpbVal;
pMetaTime = (BYTE*)_alloca(dbv.cpbVal);
for (int i = 0; i < dbv.cpbVal; i++)
@@ -1189,8 +1058,7 @@ DWORD CIcqProto::icq_sendServerContact(MCONTACT hContact, DWORD dwCookie, WORD w
db_free(&dbv);
}
- if (!getSetting(hContact, DBSETTING_SERVLIST_DATA, &dbv))
- { // read additional server item data
+ if (!getSetting(hContact, DBSETTING_SERVLIST_DATA, &dbv)) { // read additional server item data
nDataLen = dbv.cpbVal;
pData = (BYTE*)_alloca(nDataLen);
memcpy(pData, dbv.pbVal, nDataLen);
@@ -1202,25 +1070,22 @@ DWORD CIcqProto::icq_sendServerContact(MCONTACT hContact, DWORD dwCookie, WORD w
nNoteLen = strlennull(szNote);
// Limit the strings
- if (nNickLen > MAX_SSI_TLV_NAME_SIZE)
- {
+ if (nNickLen > MAX_SSI_TLV_NAME_SIZE) {
bDataTooLong = TRUE;
nNickLen = null_strcut(szNick, MAX_SSI_TLV_NAME_SIZE);
}
- if (nNoteLen > MAX_SSI_TLV_COMMENT_SIZE)
- {
+ if (nNoteLen > MAX_SSI_TLV_COMMENT_SIZE) {
bDataTooLong = TRUE;
nNoteLen = null_strcut(szNote, MAX_SSI_TLV_COMMENT_SIZE);
}
- if (bDataTooLong)
- { // Inform the user
+ if (bDataTooLong) { // Inform the user
/// TODO: do something with this for Manage Server-List dialog.
if (wAction != ICQ_LISTS_REMOVEFROMLIST) // do not report this when removing from list
icq_LogMessage(LOG_WARNING, LPGEN("The contact's information was too big and was truncated."));
}
// Build the packet
- wTLVlen = (nNickLen?4+nNickLen:0) + (nNoteLen?4+nNoteLen:0) + (bAuth?4:0) + nDataLen + (nMetaTokenLen?4+nMetaTokenLen:0) + (nMetaTimeLen?4+nMetaTimeLen:0);
+ wTLVlen = (nNickLen ? 4 + nNickLen : 0) + (nNoteLen ? 4 + nNoteLen : 0) + (bAuth ? 4 : 0) + nDataLen + (nMetaTokenLen ? 4 + nMetaTokenLen : 0) + (nMetaTimeLen ? 4 + nMetaTimeLen : 0);
// Initialize our handy data buffer
pBuffer.wPlace = 0;
@@ -1251,27 +1116,24 @@ DWORD CIcqProto::icq_sendServerContact(MCONTACT hContact, DWORD dwCookie, WORD w
return icq_sendServerItem(dwCookie, wAction, wGroupId, wContactId, strUID(dwUin, szUid), pBuffer.pData, wTLVlen, SSI_ITEM_BUDDY, dwOperation, dwTimeout, doubleObject);
}
-
DWORD CIcqProto::icq_sendSimpleItem(DWORD dwCookie, WORD wAction, DWORD dwUin, char* szUID, WORD wGroupId, WORD wItemId, WORD wItemType, DWORD dwOperation, DWORD dwTimeout)
{ // for privacy items
return icq_sendServerItem(dwCookie, wAction, wGroupId, wItemId, strUID(dwUin, szUID), NULL, 0, wItemType, dwOperation, dwTimeout, NULL);
}
-
DWORD CIcqProto::icq_sendServerGroup(DWORD dwCookie, WORD wAction, WORD wGroupId, const char *szName, void *pContent, int cbContent, DWORD dwOperationFlags)
{
WORD wTLVlen;
icq_packet pBuffer; // I reuse the ICQ packet type as a generic buffer
// I should be ashamed! ;)
- if (strlennull(szName) == 0 && wGroupId != 0)
- {
+ if (strlennull(szName) == 0 && wGroupId != 0) {
debugLogA("Group upload failed (GroupName missing).");
return 0; // without name we could not change the group
}
// Calculate buffer size
- wTLVlen = (cbContent?4+cbContent:0);
+ wTLVlen = (cbContent ? 4 + cbContent : 0);
// Initialize our handy data buffer
pBuffer.wPlace = 0;
@@ -1284,14 +1146,12 @@ DWORD CIcqProto::icq_sendServerGroup(DWORD dwCookie, WORD wAction, WORD wGroupId
return icq_sendServerItem(dwCookie, wAction, wGroupId, 0, szName, pBuffer.pData, wTLVlen, SSI_ITEM_GROUP, SSOP_GROUP_ACTION | dwOperationFlags, 400, NULL);
}
-
DWORD CIcqProto::icq_modifyServerPrivacyItem(MCONTACT hContact, DWORD dwUin, char *szUid, WORD wAction, DWORD dwOperation, WORD wItemId, WORD wType)
{
cookie_servlist_action *ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action));
DWORD dwCookie;
- if (ack)
- {
+ if (ack) {
ack->dwAction = dwOperation; // remove privacy item
ack->hContact = hContact;
ack->wContactId = wItemId;
@@ -1304,13 +1164,11 @@ DWORD CIcqProto::icq_modifyServerPrivacyItem(MCONTACT hContact, DWORD dwUin, cha
return icq_sendSimpleItem(dwCookie, wAction, dwUin, szUid, 0, wItemId, wType, SSOP_ITEM_ACTION, 400);
}
-
DWORD CIcqProto::icq_removeServerPrivacyItem(MCONTACT hContact, DWORD dwUin, char *szUid, WORD wItemId, WORD wType)
{
return icq_modifyServerPrivacyItem(hContact, dwUin, szUid, ICQ_LISTS_REMOVEFROMLIST, SSA_PRIVACY_REMOVE, wItemId, wType);
}
-
DWORD CIcqProto::icq_addServerPrivacyItem(MCONTACT hContact, DWORD dwUin, char *szUid, WORD wItemId, WORD wType)
{
return icq_modifyServerPrivacyItem(hContact, dwUin, szUid, ICQ_LISTS_ADDTOLIST, SSA_PRIVACY_ADD, wItemId, wType);
@@ -1322,14 +1180,12 @@ DWORD CIcqProto::icq_addServerPrivacyItem(MCONTACT hContact, DWORD dwUin, char *
*
*/
-
/// TODO: do not check by plugin version, check by ServListStructures version!
int CIcqProto::IsServerGroupsDefined()
{
int iRes = 1;
- if (getDword("Version", 0) < 0x00030608)
- { // group cache & linking data too old, flush, reload from server
+ if (getDword("Version", 0) < 0x00030608) { // group cache & linking data too old, flush, reload from server
char szModule[MAX_PATH];
// flush obsolete linking data
@@ -1344,7 +1200,6 @@ int CIcqProto::IsServerGroupsDefined()
return iRes;
}
-
void CIcqProto::FlushSrvGroupsCache()
{
char szModule[MAX_PATH];
@@ -1353,7 +1208,6 @@ void CIcqProto::FlushSrvGroupsCache()
CallService(MS_DB_MODULE_DELETE, 0, (LPARAM)szModule);
}
-
// Look thru DB and collect all ContactIDs from a group
void* CIcqProto::collectBuddyGroup(WORD wGroupID, int *count)
{
@@ -1364,17 +1218,14 @@ void* CIcqProto::collectBuddyGroup(WORD wGroupID, int *count)
hContact = db_find_first(m_szModuleName);
- while (hContact)
- { // search all contacts
- if (wGroupID == getWord(hContact, DBSETTING_SERVLIST_GROUP, 0))
- { // add only buddys from specified group
+ while (hContact) { // search all contacts
+ if (wGroupID == getWord(hContact, DBSETTING_SERVLIST_GROUP, 0)) { // add only buddys from specified group
wItemID = getWord(hContact, DBSETTING_SERVLIST_ID, 0);
- if (wItemID)
- { // valid ID, add
+ if (wItemID) { // valid ID, add
cnt++;
buf = (WORD*)SAFE_REALLOC(buf, cnt*sizeof(WORD));
- buf[cnt-1] = wItemID;
+ buf[cnt - 1] = wItemID;
if (!count) break;
}
}
@@ -1383,33 +1234,26 @@ void* CIcqProto::collectBuddyGroup(WORD wGroupID, int *count)
}
if (count)
- *count = cnt<<1; // we return size in bytes
+ *count = cnt << 1; // we return size in bytes
return buf;
}
-
// Look thru DB and collect all GroupIDs
void* CIcqProto::collectGroups(int *count)
{
WORD* buf = NULL;
int cnt = 0;
int i;
- MCONTACT hContact;
WORD wGroupID;
- hContact = db_find_first(m_szModuleName);
-
- while (hContact)
- { // search all contacts
- if (wGroupID = getWord(hContact, DBSETTING_SERVLIST_GROUP, 0))
- { // add only valid IDs
- for (i = 0; i<cnt; i++)
- { // check for already added ids
- if (buf[i] == wGroupID) break;
- }
+ MCONTACT hContact = db_find_first(m_szModuleName);
+ while (hContact) { // search all contacts
+ if (wGroupID = getWord(hContact, DBSETTING_SERVLIST_GROUP, 0)) { // add only valid IDs
+ for (i = 0; i < cnt; i++) // check for already added ids
+ if (buf[i] == wGroupID)
+ break;
- if (i == cnt)
- { // not preset, add
+ if (i == cnt) { // not preset, add
cnt++;
buf = (WORD*)SAFE_REALLOC(buf, cnt*sizeof(WORD));
buf[i] = wGroupID;
@@ -1419,17 +1263,15 @@ void* CIcqProto::collectGroups(int *count)
hContact = db_find_next(hContact, m_szModuleName);
}
- *count = cnt<<1;
+ *count = cnt << 1;
return buf;
}
-
-static int GroupLinksEnumProc(const char *szSetting,LPARAM lParam)
+static int GroupLinksEnumProc(const char *szSetting, LPARAM lParam)
{
// check link target, add if match
- if (db_get_w(NULL, ((char**)lParam)[2], szSetting, 0) == (WORD)((char**)lParam)[1])
- {
- char** block = (char**)SAFE_MALLOC(2*sizeof(char*));
+ if (db_get_w(NULL, ((char**)lParam)[2], szSetting, 0) == (WORD)((char**)lParam)[1]) {
+ char** block = (char**)SAFE_MALLOC(2 * sizeof(char*));
block[1] = null_strdup(szSetting);
block[0] = ((char**)lParam)[0];
((char**)lParam)[0] = (char*)block;
@@ -1453,11 +1295,9 @@ void CIcqProto::removeGroupPathLinks(WORD wGroupID)
dbces.szModule = szModule;
dbces.lParam = (LPARAM)pars;
- if (!CallService(MS_DB_CONTACT_ENUMSETTINGS, 0, (LPARAM)&dbces))
- { // we found some links, remove them
+ if (!CallService(MS_DB_CONTACT_ENUMSETTINGS, 0, (LPARAM)&dbces)) { // we found some links, remove them
char** list = (char**)pars[0];
- while (list)
- {
+ while (list) {
void* bet;
db_unset(NULL, szModule, list[1]);
@@ -1469,14 +1309,12 @@ void CIcqProto::removeGroupPathLinks(WORD wGroupID)
}
}
-
-char *CIcqProto::getServListGroupName(WORD wGroupID)
+char* CIcqProto::getServListGroupName(WORD wGroupID)
{
char szModule[MAX_PATH];
char szGroup[16];
- if (!wGroupID)
- {
+ if (!wGroupID) {
debugLogA("Warning: Cannot get group name (Group ID missing)!");
return NULL;
}
@@ -1484,8 +1322,7 @@ char *CIcqProto::getServListGroupName(WORD wGroupID)
mir_snprintf(szModule, SIZEOF(szModule), "%sSrvGroups", m_szModuleName);
_itoa(wGroupID, szGroup, 0x10);
- if (!CheckServerID(wGroupID, 0))
- { // check if valid id, if not give empty and remove
+ if (!CheckServerID(wGroupID, 0)) { // check if valid id, if not give empty and remove
debugLogA("Removing group %u from cache...", wGroupID);
db_unset(NULL, szModule, szGroup);
return NULL;
@@ -1494,14 +1331,12 @@ char *CIcqProto::getServListGroupName(WORD wGroupID)
return getSettingStringUtf(NULL, szModule, szGroup, NULL);
}
-
void CIcqProto::setServListGroupName(WORD wGroupID, const char *szGroupName)
{
char szModule[MAX_PATH];
char szGroup[16];
- if (!wGroupID)
- {
+ if (!wGroupID) {
debugLogA("Warning: Cannot set group name (Group ID missing)!");
return;
}
@@ -1511,26 +1346,20 @@ void CIcqProto::setServListGroupName(WORD wGroupID, const char *szGroupName)
if (szGroupName)
db_set_utf(NULL, szModule, szGroup, szGroupName);
- else
- {
+ else {
db_unset(NULL, szModule, szGroup);
removeGroupPathLinks(wGroupID);
}
- return;
}
-
WORD CIcqProto::getServListGroupLinkID(const char *szPath)
{
char szModule[MAX_PATH];
- WORD wGroupId;
-
mir_snprintf(szModule, SIZEOF(szModule), "%sGroups", m_szModuleName);
- wGroupId = db_get_w(NULL, szModule, szPath, 0);
+ WORD wGroupId = db_get_w(NULL, szModule, szPath, 0);
- if (wGroupId && !CheckServerID(wGroupId, 0))
- { // known, check if still valid, if not remove
+ if (wGroupId && !CheckServerID(wGroupId, 0)) { // known, check if still valid, if not remove
debugLogA("Removing group \"%s\" from cache...", szPath);
db_unset(NULL, szModule, szPath);
wGroupId = 0;
@@ -1539,11 +1368,9 @@ WORD CIcqProto::getServListGroupLinkID(const char *szPath)
return wGroupId;
}
-
void CIcqProto::setServListGroupLinkID(const char *szPath, WORD wGroupID)
{
char szModule[MAX_PATH];
-
mir_snprintf(szModule, SIZEOF(szModule), "%sGroups", m_szModuleName);
if (wGroupID)
@@ -1579,7 +1406,7 @@ int CIcqProto::getCListGroupExists(const char *szGroup)
int CIcqProto::moveContactToCListGroup(MCONTACT hContact, const char *szGroup)
{
- HANDLE hGroup = Clist_CreateGroup(0, ptrT( mir_utf8decodeT(szGroup)));
+ HANDLE hGroup = Clist_CreateGroup(0, ptrT(mir_utf8decodeT(szGroup)));
if (ServiceExists(MS_CLIST_CONTACTCHANGEGROUP))
return CallService(MS_CLIST_CONTACTCHANGEGROUP, hContact, (LPARAM)hGroup);
@@ -1594,8 +1421,7 @@ static int countGroupNameLevel(const char *szGroupName)
int nNameLen = strlennull(szGroupName);
int i = 0;
- while (i<nNameLen)
- {
+ while (i < nNameLen) {
if (szGroupName[i] != '>')
return i;
@@ -1620,8 +1446,7 @@ int CIcqProto::getServListGroupLevel(WORD wGroupId)
char *szGroupName = getServListGroupName(wGroupId);
int cnt = -1;
- if (szGroupName)
- { // groupid is valid count group name level
+ if (szGroupName) { // groupid is valid count group name level
if (m_bSsiSimpleGroups)
cnt = countCListGroupLevel(szGroupName);
else
@@ -1639,77 +1464,52 @@ char *CIcqProto::getServListGroupCListPath(WORD wGroupId)
{
char *szGroup = NULL;
- if (szGroup = getServListGroupName(wGroupId))
- { // this groupid is valid
+ if (szGroup = getServListGroupName(wGroupId)) { // this groupid is valid
if (!m_bSsiSimpleGroups)
while (strstrnull(szGroup, "\\")) *strstrnull(szGroup, "\\") = '_'; // remove invalid char
- if (getServListGroupLinkID(szGroup) == wGroupId)
- { // this grouppath is known and is for this group, set user group
+ if (getServListGroupLinkID(szGroup) == wGroupId) { // this grouppath is known and is for this group, set user group
return szGroup;
}
- else if (m_bSsiSimpleGroups)
- { // with simple groups it is mapped 1:1, give real serv-list group name
+ else if (m_bSsiSimpleGroups) { // with simple groups it is mapped 1:1, give real serv-list group name
setServListGroupLinkID(szGroup, wGroupId);
return szGroup;
}
- else
- { // advanced groups, determine group level
+ else { // advanced groups, determine group level
int nGroupLevel = getServListGroupLevel(wGroupId);
- if (nGroupLevel > 0)
- { // it is probably a sub-group locate parent group
+ if (nGroupLevel > 0) { // it is probably a sub-group locate parent group
WORD wParentGroupId = wGroupId;
int nParentGroupLevel;
- do
- { // we look for parent group at the correct level
+ do { // we look for parent group at the correct level
wParentGroupId--;
nParentGroupLevel = getServListGroupLevel(wParentGroupId);
- } while ((nParentGroupLevel >= nGroupLevel) && (nParentGroupLevel != -1));
+ }
+ while ((nParentGroupLevel >= nGroupLevel) && (nParentGroupLevel != -1));
- if (nParentGroupLevel == -1)
- { // that was not a sub-group, it was just a group starting with >
+ if (nParentGroupLevel == -1) { // that was not a sub-group, it was just a group starting with >
setServListGroupLinkID(szGroup, wGroupId);
return szGroup;
}
- { // recursively determine parent group clist path
- char *szParentGroup = getServListGroupCListPath(wParentGroupId);
-
- /// FIXME: properly handle ~N suffixes
- szParentGroup = (char*)SAFE_REALLOC(szParentGroup, strlennull(szGroup) + strlennull(szParentGroup) + 2);
- strcat(szParentGroup, "\\");
- strcat(szParentGroup, (char*)szGroup + nGroupLevel);
- /* if (strstrnull(szGroup, "~"))
- { // check if the ~ was not added to obtain unique servlist item name
- char *szUniqueMark = strrchr(szParentGroup, '~');
-
- *szUniqueMark = '\0';
- // not the same group without ~, return it
- if (getServListGroupLinkID(szParentGroup) != wGroupId)
- *szUniqueMark = '~';
- } */ /// FIXME: this is necessary, but needs group loading changes
- SAFE_FREE((void**)&szGroup);
- szGroup = szParentGroup;
-
-
- if (getServListGroupLinkID(szGroup) == wGroupId)
- { // known path, give
- return szGroup;
- }
- else
- { // unknown path, setup a link
- setServListGroupLinkID(szGroup, wGroupId);
- return szGroup;
- }
- }
- }
- else
- { // normal group, setup a link
- setServListGroupLinkID(szGroup, wGroupId);
- return szGroup;
+ // recursively determine parent group clist path
+ char *szParentGroup = getServListGroupCListPath(wParentGroupId);
+
+ /// FIXME: properly handle ~N suffixes
+ szParentGroup = (char*)SAFE_REALLOC(szParentGroup, strlennull(szGroup) + strlennull(szParentGroup) + 2);
+ strcat(szParentGroup, "\\");
+ strcat(szParentGroup, (char*)szGroup + nGroupLevel);
+
+ SAFE_FREE((void**)&szGroup);
+ szGroup = szParentGroup;
+
+ if (getServListGroupLinkID(szGroup) == wGroupId) // known path, give
+ return szGroup;
}
+
+ setServListGroupLinkID(szGroup, wGroupId);
+ return szGroup;
}
}
return NULL;
@@ -1717,7 +1517,8 @@ char *CIcqProto::getServListGroupCListPath(WORD wGroupId)
static int SrvGroupNamesEnumProc(const char *szSetting, LPARAM lParam)
-{ // check server-group cache item
+{
+ // check server-group cache item
const char **params = (const char**)lParam;
CIcqProto *ppro = (CIcqProto*)params[0];
char *szGroupName = ppro->getSettingStringUtf(NULL, params[3], szSetting, NULL);
@@ -1730,7 +1531,8 @@ static int SrvGroupNamesEnumProc(const char *szSetting, LPARAM lParam)
}
char* CIcqProto::getServListUniqueGroupName(const char *szGroupName, int bAlloced)
-{ // enum ICQSrvGroups and create unique name if neccessary
+{
+ // enum ICQSrvGroups and create unique name if neccessary
DBCONTACTENUMSETTINGS dbces;
char szModule[MAX_PATH];
char *pars[4];
@@ -1755,38 +1557,33 @@ char* CIcqProto::getServListUniqueGroupName(const char *szGroupName, int bAlloce
dbces.lParam = (LPARAM)pars;
CallService(MS_DB_CONTACT_ENUMSETTINGS, 0, (LPARAM)&dbces);
- if (pars[1])
- { // the groupname already exists, create another
+ if (pars[1]) { // the groupname already exists, create another
SAFE_FREE((void**)&szNewGroupName);
char szUnique[10];
_itoa(uniqueID++, szUnique, 10);
null_strcut(szGroupNameBase, m_wServerListRecordNameMaxLength - strlennull(szUnique) - 1);
szNewGroupName = (char*)SAFE_MALLOC(strlennull(szUnique) + strlennull(szGroupNameBase) + 2);
- if (szNewGroupName)
- {
+ if (szNewGroupName) {
strcpy(szNewGroupName, szGroupNameBase);
strcat(szNewGroupName, "~");
strcat(szNewGroupName, szUnique);
}
}
- } while (pars[1] && szNewGroupName);
+ }
+ while (pars[1] && szNewGroupName);
- if (szNewGroupName)
- {
+ if (szNewGroupName) {
SAFE_FREE(&szGroupNameBase);
return szNewGroupName;
}
- if (szGroupName != szGroupNameBase)
- {
+ if (szGroupName != szGroupNameBase) {
SAFE_FREE(&szGroupNameBase);
return (char*)szGroupName;
}
- else
- return szGroupNameBase;
+ return szGroupNameBase;
}
-
// this is the second part of recursive event-driven procedure
int CIcqProto::servlistCreateGroup_gotParentGroup(const char *szGroup, WORD wGroupID, LPARAM param, int nResult)
{
@@ -1798,14 +1595,11 @@ int CIcqProto::servlistCreateGroup_gotParentGroup(const char *szGroup, WORD wGro
SAFE_FREE((void**)&clue);
- if (nResult == PENDING_RESULT_PURGE)
- { // only cleanup
+ if (nResult == PENDING_RESULT_PURGE) // only cleanup
return CALLBACK_RESULT_CONTINUE;
- }
szSubGroup = (char*)SAFE_MALLOC(strlennull(szGroup) + strlennull(szSubGroupName) + 2);
- if (szSubGroup)
- {
+ if (szSubGroup) {
strcpy(szSubGroup, szGroup);
strcat(szSubGroup, "\\");
strcat(szSubGroup, szSubGroupName);
@@ -1814,8 +1608,7 @@ int CIcqProto::servlistCreateGroup_gotParentGroup(const char *szGroup, WORD wGro
if (nResult == PENDING_RESULT_SUCCESS) // if we got an id count level
wSubGroupLevel = getServListGroupLevel(wGroupID);
- if (wSubGroupLevel == -1)
- { // something went wrong, give the id and go away
+ if (wSubGroupLevel == -1) { // something went wrong, give the id and go away
servlistPendingRemoveGroup(szSubGroup, wGroupID, PENDING_RESULT_FAILED);
SAFE_FREE((void**)&szSubGroupName);
@@ -1827,21 +1620,17 @@ int CIcqProto::servlistCreateGroup_gotParentGroup(const char *szGroup, WORD wGro
// check if on that id is not group of the same or greater level, if yes, try next
while (CheckServerID(wSubGroupID, 0) && (getServListGroupLevel(wSubGroupID) >= wSubGroupLevel))
- {
wSubGroupID++;
- }
- if (!CheckServerID(wSubGroupID, 0))
- { // the next id is free, so create our group with that id
+ if (!CheckServerID(wSubGroupID, 0)) { // the next id is free, so create our group with that id
cookie_servlist_action *ack;
DWORD dwCookie;
char *szSubGroupItem = (char*)SAFE_MALLOC(strlennull(szSubGroupName) + wSubGroupLevel + 1);
- if (szSubGroupItem)
- {
+ if (szSubGroupItem) {
int i;
- for (i=0; i < wSubGroupLevel; i++)
+ for (i = 0; i < wSubGroupLevel; i++)
szSubGroupItem[i] = '>';
strcpy(szSubGroupItem + wSubGroupLevel, szSubGroupName);
@@ -1850,11 +1639,9 @@ int CIcqProto::servlistCreateGroup_gotParentGroup(const char *szGroup, WORD wGro
// check and create unique group name (Miranda does allow more subgroups with the same name!)
szSubGroupItem = getServListUniqueGroupName(szSubGroupItem, TRUE);
- if (ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action)))
- { // we have cookie good, go on
-#ifdef _DEBUG
+ if (ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action))) { // we have cookie good, go on
debugLogA("Server-List: Creating sub-group \"%s\", parent group \"%s\".", szSubGroupItem, szGroup);
-#endif
+
ReserveServerID(wSubGroupID, SSIT_GROUP, 0);
ack->wGroupId = wSubGroupID;
@@ -1887,22 +1674,18 @@ int CIcqProto::servlistCreateGroup_Ready(const char *szGroup, WORD groupID, LPAR
if (nResult == PENDING_RESULT_PURGE)
return CALLBACK_RESULT_CONTINUE;
- if (wGroupID = getServListGroupLinkID(szGroup))
- { // the path is known, continue the process
+ if (wGroupID = getServListGroupLinkID(szGroup)) { // the path is known, continue the process
servlistPendingRemoveGroup(szGroup, wGroupID, PENDING_RESULT_SUCCESS);
return CALLBACK_RESULT_CONTINUE;
}
- if (!strstrnull(szGroup, "\\") || m_bSsiSimpleGroups)
- { // a root group can be simply created without problems; simple groups are mapped directly
+ if (!strstrnull(szGroup, "\\") || m_bSsiSimpleGroups) { // a root group can be simply created without problems; simple groups are mapped directly
cookie_servlist_action* ack;
DWORD dwCookie;
- if (ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action)))
- { // we have cookie good, go on
-#ifdef _DEBUG
+ if (ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action))) { // we have cookie good, go on
debugLogA("Server-List: Creating root group \"%s\".", szGroup);
-#endif
+
ack->wGroupId = GenerateServerID(SSIT_GROUP, 0);
ack->szGroup = null_strdup(szGroup); // we need that name
// check if the groupname is unique - just to be sure, Miranda should handle that!
@@ -1915,22 +1698,19 @@ int CIcqProto::servlistCreateGroup_Ready(const char *szGroup, WORD groupID, LPAR
return CALLBACK_RESULT_POSTPONE;
}
}
- else
- { // this is a sub-group
+ else { // this is a sub-group
char* szSub = null_strdup(szGroup); // create subgroup, recursive, event-driven, possibly relocate
cookie_servlist_action* ack;
char *szLast;
- if (strstrnull(szSub, "\\"))
- { // determine parent group
+ if (strstrnull(szSub, "\\")) { // determine parent group
szLast = strrchr(szSub, '\\') + 1;
- szLast[-1] = '\0';
+ szLast[-1] = '\0';
}
// make parent group id
ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action));
- if (ack)
- {
+ if (ack) {
ack->szGroupName = null_strdup(szLast); // groupname
servlistCreateGroup(szSub, (LPARAM)ack, &CIcqProto::servlistCreateGroup_gotParentGroup);
SAFE_FREE((void**)&szSub);
@@ -1938,14 +1718,13 @@ int CIcqProto::servlistCreateGroup_Ready(const char *szGroup, WORD groupID, LPAR
return CALLBACK_RESULT_POSTPONE;
}
- SAFE_FREE((void**)&szSub);
+ SAFE_FREE((void**)&szSub);
}
- servlistPendingRemoveGroup(szGroup, groupID, PENDING_RESULT_FAILED);
+ servlistPendingRemoveGroup(szGroup, groupID, PENDING_RESULT_FAILED);
return CALLBACK_RESULT_CONTINUE;
}
-
// create group with this path, a bit complex task
// this supposes that all server groups are known
void CIcqProto::servlistCreateGroup(const char *szGroupPath, LPARAM param, PENDING_GROUP_CALLBACK callback)
@@ -1957,7 +1736,6 @@ void CIcqProto::servlistCreateGroup(const char *szGroupPath, LPARAM param, PENDI
servlistPendingAddGroup(szGroup, 0, 0, &CIcqProto::servlistCreateGroup_Ready, TRUE, param, callback);
}
-
/*****************************************
*
* --- Server-List Operations ---
@@ -1967,26 +1745,24 @@ void CIcqProto::servlistCreateGroup(const char *szGroupPath, LPARAM param, PENDI
int CIcqProto::servlistAddContact_gotGroup(const char *szGroup, WORD wGroupID, LPARAM lParam, int nResult)
{
cookie_servlist_action* ack = (cookie_servlist_action*)lParam;
+ if (ack)
+ SAFE_FREE(&ack->szGroup);
- if (ack) SAFE_FREE(&ack->szGroup);
-
- if (nResult == PENDING_RESULT_PURGE)
- { // only cleanup
+ if (nResult == PENDING_RESULT_PURGE) { // only cleanup
SAFE_FREE((void**)&ack);
return CALLBACK_RESULT_CONTINUE;
}
- if (!ack || !wGroupID) // something went wrong
- {
- if (ack) servlistPendingRemoveContact(ack->hContact, 0, wGroupID, PENDING_RESULT_FAILED);
+ if (!ack || !wGroupID) { // something went wrong
+ if (ack)
+ servlistPendingRemoveContact(ack->hContact, 0, wGroupID, PENDING_RESULT_FAILED);
SAFE_FREE((void**)&ack);
return CALLBACK_RESULT_CONTINUE;
}
WORD wItemID = getWord(ack->hContact, DBSETTING_SERVLIST_ID, 0);
-
- if (wItemID) /// TODO: redundant ???
- { // Only add the contact if it doesnt already have an ID
+ if (wItemID) {
+ // Only add the contact if it doesnt already have an ID
servlistPendingRemoveContact(ack->hContact, wItemID, wGroupID, PENDING_RESULT_SUCCESS);
debugLogA("Failed to add contact to server side list (%s)", "already there");
SAFE_FREE((void**)&ack);
@@ -2006,14 +1782,12 @@ int CIcqProto::servlistAddContact_gotGroup(const char *szGroup, WORD wGroupID, L
return CALLBACK_RESULT_CONTINUE;
}
-
// Need to be called when Pending Contact is active
int CIcqProto::servlistAddContact_Ready(MCONTACT hContact, WORD wContactID, WORD wGroupID, LPARAM lParam, int nResult)
{
cookie_servlist_action* ack = (cookie_servlist_action*)lParam;
- if (nResult == PENDING_RESULT_PURGE)
- { // removing obsolete items, just free the memory
+ if (nResult == PENDING_RESULT_PURGE) { // removing obsolete items, just free the memory
SAFE_FREE((void**)&ack->szGroup);
SAFE_FREE((void**)&ack);
return CALLBACK_RESULT_CONTINUE;
@@ -2021,8 +1795,7 @@ int CIcqProto::servlistAddContact_Ready(MCONTACT hContact, WORD wContactID, WORD
WORD wItemID = getWord(ack->hContact, DBSETTING_SERVLIST_ID, 0);
- if (wItemID)
- { // Only add the contact if it doesn't already have an ID
+ if (wItemID) { // Only add the contact if it doesn't already have an ID
servlistPendingRemoveContact(ack->hContact, wItemID, getWord(hContact, DBSETTING_SERVLIST_GROUP, 0), PENDING_RESULT_SUCCESS);
debugLogA("Failed to add contact to server side list (%s)", "already there");
SAFE_FREE((void**)&ack->szGroup);
@@ -2036,7 +1809,6 @@ int CIcqProto::servlistAddContact_Ready(MCONTACT hContact, WORD wContactID, WORD
return CALLBACK_RESULT_POSTPONE;
}
-
// Called when contact should be added to server list, if group does not exist, create one
void CIcqProto::servlistAddContact(MCONTACT hContact, const char *pszGroup)
{
@@ -2045,27 +1817,21 @@ void CIcqProto::servlistAddContact(MCONTACT hContact, const char *pszGroup)
cookie_servlist_action* ack;
// Get UID
- if (getContactUid(hContact, &dwUin, &szUid))
- { // Could not do anything without uid
+ if (getContactUid(hContact, &dwUin, &szUid)) { // Could not do anything without uid
debugLogA("Failed to add contact to server side list (%s)", "no UID");
return;
}
- if (!(ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action))))
- { // Could not do anything without cookie
+ if (!(ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action)))) { // Could not do anything without cookie
debugLogA("Failed to add contact to server side list (%s)", "malloc failed");
return;
}
- else
- {
- ack->hContact = hContact;
- ack->szGroup = null_strdup(pszGroup);
- // call thru pending operations - makes sure the contact is ready to be added
- servlistPendingAddContact(hContact, 0, 0, (LPARAM)ack, &CIcqProto::servlistAddContact_Ready, TRUE);
- return;
- }
-}
+ ack->hContact = hContact;
+ ack->szGroup = null_strdup(pszGroup);
+ // call thru pending operations - makes sure the contact is ready to be added
+ servlistPendingAddContact(hContact, 0, 0, (LPARAM)ack, &CIcqProto::servlistAddContact_Ready, TRUE);
+}
int CIcqProto::servlistRemoveContact_Ready(MCONTACT hContact, WORD contactID, WORD groupID, LPARAM lParam, int nResult)
{
@@ -2074,15 +1840,13 @@ int CIcqProto::servlistRemoveContact_Ready(MCONTACT hContact, WORD contactID, WO
cookie_servlist_action* ack = (cookie_servlist_action*)lParam;
DWORD dwCookie;
- if (nResult == PENDING_RESULT_PURGE)
- {
+ if (nResult == PENDING_RESULT_PURGE) {
SAFE_FREE((void**)&ack);
return CALLBACK_RESULT_CONTINUE;
}
// Get the contact's group ID
- if (!(wGroupID = getWord(hContact, DBSETTING_SERVLIST_GROUP, 0)))
- { // Could not find a usable group ID
+ if (!(wGroupID = getWord(hContact, DBSETTING_SERVLIST_GROUP, 0))) { // Could not find a usable group ID
servlistPendingRemoveContact(hContact, contactID, groupID, PENDING_RESULT_FAILED);
debugLogA("Failed to remove contact from server side list (%s)", "no group ID");
@@ -2091,8 +1855,7 @@ int CIcqProto::servlistRemoveContact_Ready(MCONTACT hContact, WORD contactID, WO
}
// Get the contact's item ID
- if (!(wItemID = getWord(hContact, DBSETTING_SERVLIST_ID, 0)))
- { // Could not find usable item ID
+ if (!(wItemID = getWord(hContact, DBSETTING_SERVLIST_ID, 0))) { // Could not find usable item ID
servlistPendingRemoveContact(hContact, contactID, wGroupID, PENDING_RESULT_FAILED);
debugLogA("Failed to remove contact from server side list (%s)", "no item ID");
@@ -2112,7 +1875,6 @@ int CIcqProto::servlistRemoveContact_Ready(MCONTACT hContact, WORD contactID, WO
return CALLBACK_RESULT_POSTPONE;
}
-
// Called when contact should be removed from server list, remove group if it remain empty
void CIcqProto::servlistRemoveContact(MCONTACT hContact)
{
@@ -2121,43 +1883,37 @@ void CIcqProto::servlistRemoveContact(MCONTACT hContact)
cookie_servlist_action* ack;
// Get UID
- if (getContactUid(hContact, &dwUin, &szUid))
- {
+ if (getContactUid(hContact, &dwUin, &szUid)) {
// Could not do anything without uid
debugLogA("Failed to remove contact from server side list (%s)", "no UID");
return;
}
- if (!(ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action))))
- { // Could not do anything without cookie
+ if (!(ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action)))) { // Could not do anything without cookie
debugLogA("Failed to remove contact from server side list (%s)", "malloc failed");
return;
}
- else
- {
- ack->hContact = hContact;
- // call thru pending operations - makes sure the contact is ready to be removed
- servlistPendingAddContact(hContact, 0, 0, (LPARAM)ack, &CIcqProto::servlistRemoveContact_Ready, TRUE);
- return;
- }
+
+ ack->hContact = hContact;
+ // call thru pending operations - makes sure the contact is ready to be removed
+ servlistPendingAddContact(hContact, 0, 0, (LPARAM)ack, &CIcqProto::servlistRemoveContact_Ready, TRUE);
}
int CIcqProto::servlistMoveContact_gotTargetGroup(const char *szGroup, WORD wNewGroupID, LPARAM lParam, int nResult)
{
cookie_servlist_action *ack = (cookie_servlist_action*)lParam;
+ if (ack)
+ SAFE_FREE(&ack->szGroup);
- if (ack) SAFE_FREE(&ack->szGroup);
-
- if (nResult == PENDING_RESULT_PURGE)
- { // removing obsolete items, just free the memory
+ if (nResult == PENDING_RESULT_PURGE) { // removing obsolete items, just free the memory
SAFE_FREE((void**)&ack);
return CALLBACK_RESULT_CONTINUE;
}
- if (!ack || !wNewGroupID || !ack->hContact) // something went wrong
- {
- if (ack) servlistPendingRemoveContact(ack->hContact, 0, 0, PENDING_RESULT_FAILED);
+ if (!ack || !wNewGroupID || !ack->hContact) { // something went wrong
+ if (ack)
+ servlistPendingRemoveContact(ack->hContact, 0, 0, PENDING_RESULT_FAILED);
SAFE_FREE((void**)&ack);
return CALLBACK_RESULT_CONTINUE;
}
@@ -2165,15 +1921,13 @@ int CIcqProto::servlistMoveContact_gotTargetGroup(const char *szGroup, WORD wNew
WORD wItemID = getWord(ack->hContact, DBSETTING_SERVLIST_ID, 0);
WORD wGroupID = getWord(ack->hContact, DBSETTING_SERVLIST_GROUP, 0);
- if (!wItemID)
- { // We have no ID, so try to simply add the contact to serv-list
+ if (!wItemID) { // We have no ID, so try to simply add the contact to serv-list
debugLogA("Unable to move contact (no ItemID) -> trying to add");
// we know the GroupID, so directly call add
return servlistAddContact_gotGroup(szGroup, wNewGroupID, lParam, nResult);
}
- if (wGroupID == wNewGroupID)
- { // Only move the contact if it had different GroupID
+ if (wGroupID == wNewGroupID) { // Only move the contact if it had different GroupID
servlistPendingRemoveContact(ack->hContact, wItemID, wNewGroupID, PENDING_RESULT_SUCCESS);
debugLogA("Contact not moved to group on server side list (same Group)");
return CALLBACK_RESULT_CONTINUE;
@@ -2189,8 +1943,8 @@ int CIcqProto::servlistMoveContact_gotTargetGroup(const char *szGroup, WORD wNew
DWORD dwCookie = AllocateCookie(CKT_SERVERLIST, ICQ_LISTS_REMOVEFROMLIST, ack->hContact, ack);
DWORD dwCookie2 = AllocateCookie(CKT_SERVERLIST, ICQ_LISTS_ADDTOLIST, ack->hContact, ack);
-
- { // imitate icq5, previously here was different order, but AOL changed and it ceased to work
+ {
+ // imitate icq5, previously here was different order, but AOL changed and it ceased to work
void *doubleObject = NULL;
icq_sendServerContact(ack->hContact, dwCookie2, ICQ_LISTS_ADDTOLIST, wNewGroupID, ack->wNewContactId, SSO_CONTACT_SETGROUP | SSOF_BEGIN_OPERATION, 500, &doubleObject);
@@ -2199,13 +1953,11 @@ int CIcqProto::servlistMoveContact_gotTargetGroup(const char *szGroup, WORD wNew
return CALLBACK_RESULT_CONTINUE;
}
-
int CIcqProto::servlistMoveContact_Ready(MCONTACT hContact, WORD contactID, WORD groupID, LPARAM lParam, int nResult)
{
cookie_servlist_action *ack = (cookie_servlist_action*)lParam;
- if (nResult == PENDING_RESULT_PURGE)
- { // removing obsolete items, just free the memory
+ if (nResult == PENDING_RESULT_PURGE) { // removing obsolete items, just free the memory
SAFE_FREE(&ack->szGroup);
SAFE_FREE((void**)&ack);
return CALLBACK_RESULT_CONTINUE;
@@ -2214,8 +1966,7 @@ int CIcqProto::servlistMoveContact_Ready(MCONTACT hContact, WORD contactID, WORD
WORD wItemID = getWord(ack->hContact, DBSETTING_SERVLIST_ID, 0);
WORD wGroupID = getWord(ack->hContact, DBSETTING_SERVLIST_GROUP, 0);
- if (!wGroupID && wItemID)
- { // Only move the contact if it had an GroupID
+ if (!wGroupID && wItemID) { // Only move the contact if it had an GroupID
servlistPendingRemoveContact(ack->hContact, contactID, groupID, PENDING_RESULT_FAILED);
debugLogA("Failed to move contact to group on server side list (%s)", "no Group");
@@ -2226,11 +1977,9 @@ int CIcqProto::servlistMoveContact_Ready(MCONTACT hContact, WORD contactID, WORD
// obtain a correct target groupid first
servlistCreateGroup(ack->szGroup, lParam, &CIcqProto::servlistMoveContact_gotTargetGroup);
-
return CALLBACK_RESULT_POSTPONE;
}
-
// Called when contact should be moved from one group to another, create new, remove empty
void CIcqProto::servlistMoveContact(MCONTACT hContact, const char *pszNewGroup)
{
@@ -2240,14 +1989,12 @@ void CIcqProto::servlistMoveContact(MCONTACT hContact, const char *pszNewGroup)
if (!hContact) return; // we do not move us, caused our uin was wrongly added to list
// Get UID
- if (getContactUid(hContact, &dwUin, &szUid))
- { // Could not do anything without uin
+ if (getContactUid(hContact, &dwUin, &szUid)) { // Could not do anything without uin
debugLogA("Failed to move contact to group on server side list (%s)", "no UID");
return;
}
- if ((pszNewGroup != NULL) && (pszNewGroup[0]!='\0') && !getCListGroupExists(pszNewGroup))
- { // the contact moved to non existing group, do not do anything: MetaContact hack
+ if ((pszNewGroup != NULL) && (pszNewGroup[0] != '\0') && !getCListGroupExists(pszNewGroup)) { // the contact moved to non existing group, do not do anything: MetaContact hack
debugLogA("Contact not moved - probably hiding by MetaContacts.");
return;
}
@@ -2255,18 +2002,16 @@ void CIcqProto::servlistMoveContact(MCONTACT hContact, const char *pszNewGroup)
if (!getWord(hContact, DBSETTING_SERVLIST_ID, 0)) /// FIXME:::: this should be in _ready
{ // the contact is not stored on the server, check if we should try to add
if (!getByte("ServerAddRemove", DEFAULT_SS_ADDSERVER) ||
- db_get_b(hContact, "CList", "Hidden", 0))
- return;
+ db_get_b(hContact, "CList", "Hidden", 0))
+ return;
}
cookie_servlist_action *ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action));
- if (!ack)
- { // Could not do anything without cookie
+ if (!ack) { // Could not do anything without cookie
debugLogA("Failed to add contact to server side list (%s)", "malloc failed");
return;
}
- else
- {
+ else {
ack->hContact = hContact;
ack->szGroup = null_strdup(pszNewGroup);
// call thru pending operations - makes sure the contact is ready to be moved
@@ -2280,8 +2025,7 @@ int CIcqProto::servlistUpdateContact_Ready(MCONTACT hContact, WORD contactID, WO
{
cookie_servlist_action *ack = (cookie_servlist_action*)lParam;
- if (nResult == PENDING_RESULT_PURGE)
- { // removing obsolete items, just free the memory
+ if (nResult == PENDING_RESULT_PURGE) { // removing obsolete items, just free the memory
SAFE_FREE((void**)&ack);
return CALLBACK_RESULT_CONTINUE;
}
@@ -2289,8 +2033,7 @@ int CIcqProto::servlistUpdateContact_Ready(MCONTACT hContact, WORD contactID, WO
WORD wGroupID;
// Get the contact's group ID
- if (!(wGroupID = getWord(hContact, DBSETTING_SERVLIST_GROUP, 0)))
- {
+ if (!(wGroupID = getWord(hContact, DBSETTING_SERVLIST_GROUP, 0))) {
servlistPendingRemoveContact(hContact, contactID, groupID, PENDING_RESULT_FAILED);
// Could not find a usable group ID
debugLogA("Failed to update contact's details on server side list (%s)", "no group ID");
@@ -2299,8 +2042,7 @@ int CIcqProto::servlistUpdateContact_Ready(MCONTACT hContact, WORD contactID, WO
}
// Get the contact's item ID
- if (!(wItemID = getWord(hContact, DBSETTING_SERVLIST_ID, 0)))
- {
+ if (!(wItemID = getWord(hContact, DBSETTING_SERVLIST_ID, 0))) {
servlistPendingRemoveContact(hContact, contactID, wGroupID, PENDING_RESULT_FAILED);
// Could not find usable item ID
debugLogA("Failed to update contact's details on server side list (%s)", "no item ID");
@@ -2327,58 +2069,49 @@ int CIcqProto::servlistUpdateContact_Ready(MCONTACT hContact, WORD contactID, WO
// the server side details.
void CIcqProto::servlistUpdateContact(MCONTACT hContact)
{
+ // Get UID
DWORD dwUin;
uid_str szUid;
-
- // Get UID
- if (getContactUid(hContact, &dwUin, &szUid))
- {
+ if (getContactUid(hContact, &dwUin, &szUid)) {
// Could not set nickname on server without uid
debugLogA("Failed to update contact's details on server side list (%s)", "no UID");
return;
}
- cookie_servlist_action *ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action));
- if (!ack)
- {
+ cookie_servlist_action *ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action));
+ if (!ack) {
// Could not allocate cookie - use old fake
debugLogA("Failed to update contact's details on server side list (%s)", "malloc failed");
return;
}
- else
- {
- ack->hContact = hContact;
- // call thru pending operations - makes sure the contact is ready to be updated
- servlistPendingAddContact(hContact, 0, 0, (LPARAM)ack, &CIcqProto::servlistUpdateContact_Ready, TRUE);
- return;
- }
-}
+ ack->hContact = hContact;
+ // call thru pending operations - makes sure the contact is ready to be updated
+ servlistPendingAddContact(hContact, 0, 0, (LPARAM)ack, &CIcqProto::servlistUpdateContact_Ready, TRUE);
+}
int CIcqProto::servlistRenameGroup_Ready(const char *szGroup, WORD wGroupID, LPARAM lParam, int nResult)
{
cookie_servlist_action *ack = (cookie_servlist_action*)lParam;
- if (nResult == PENDING_RESULT_PURGE)
- { // only cleanup
- if (ack) SAFE_FREE(&ack->szGroupName);
+ if (nResult == PENDING_RESULT_PURGE) { // only cleanup
+ if (ack)
+ SAFE_FREE(&ack->szGroupName);
SAFE_FREE((void**)&ack);
return CALLBACK_RESULT_CONTINUE;
}
- if (!ack || !wGroupID) // something went wrong
- {
+ if (!ack || !wGroupID) { // something went wrong
servlistPendingRemoveGroup(szGroup, wGroupID, PENDING_RESULT_FAILED);
if (ack) SAFE_FREE(&ack->szGroupName);
SAFE_FREE((void**)&ack);
return CALLBACK_RESULT_CONTINUE;
}
+
void *groupData;
int groupSize;
-
- if (groupData = collectBuddyGroup(wGroupID, &groupSize))
- {
+ if (groupData = collectBuddyGroup(wGroupID, &groupSize)) {
ack->dwAction = SSA_GROUP_RENAME;
ack->wGroupId = wGroupID;
ack->szGroup = null_strdup(szGroup); // we need this name
@@ -2401,12 +2134,10 @@ void CIcqProto::servlistRenameGroup(char *szGroup, WORD wGroupId, char *szNewGro
if (nGroupLevel == -1) return; // we failed to prepare group
- if (!m_bSsiSimpleGroups)
- {
+ if (!m_bSsiSimpleGroups) {
char *szGroupName = szGroup;
int i = nGroupLevel;
- while (i)
- { // find correct part of grouppath
+ while (i) { // find correct part of grouppath
szGroupName = strstrnull(szGroupName, "\\");
if (!szGroupName) return; // failed to get correct part of the grouppath
szGroupName++;
@@ -2414,8 +2145,7 @@ void CIcqProto::servlistRenameGroup(char *szGroup, WORD wGroupId, char *szNewGro
}
szNewGroupName = szNewGroup;
i = nGroupLevel;
- while (i)
- { // find correct part of new grouppath
+ while (i) { // find correct part of new grouppath
szNewGroupName = strstrnull(szNewGroupName, "\\");
if (!szNewGroupName) return; // failed to get correct part of the new grouppath
szNewGroupName++;
@@ -2436,8 +2166,7 @@ void CIcqProto::servlistRenameGroup(char *szGroup, WORD wGroupId, char *szNewGro
szNewGroupName = (char*)SAFE_MALLOC(strlennull(szGroupName) + 1 + nGroupLevel);
if (!szNewGroupName) return; // Failure
- for (i = 0; i < nGroupLevel; i++)
- { // create level prefix
+ for (i = 0; i < nGroupLevel; i++) { // create level prefix
szNewGroupName[i] = '>';
}
strcat(szNewGroupName, szGroupName);
@@ -2446,8 +2175,7 @@ void CIcqProto::servlistRenameGroup(char *szGroup, WORD wGroupId, char *szNewGro
szNewGroupName = null_strdup(szNewGroup);
cookie_servlist_action* ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action));
- if (!ack)
- { // cookie failed
+ if (!ack) { // cookie failed
debugLogA("Error: Failed to allocate cookie");
SAFE_FREE(&szNewGroupName);
@@ -2459,25 +2187,21 @@ void CIcqProto::servlistRenameGroup(char *szGroup, WORD wGroupId, char *szNewGro
servlistPendingAddGroup(szGroup, wGroupId, (LPARAM)ack, &CIcqProto::servlistRenameGroup_Ready, TRUE);
}
-
int CIcqProto::servlistRemoveGroup_Ready(const char *szGroup, WORD groupID, LPARAM lParam, int nResult)
{
cookie_servlist_action *ack = (cookie_servlist_action*)lParam;
- if (nResult == PENDING_RESULT_PURGE)
- { // only cleanup
+ if (nResult == PENDING_RESULT_PURGE) { // only cleanup
SAFE_FREE((void**)&ack);
return CALLBACK_RESULT_CONTINUE;
}
WORD wGroupID = getServListGroupLinkID(szGroup);
char *szGroupName;
- if (wGroupID && (szGroupName = getServListGroupName(wGroupID)))
- { // the group is valid, check if it is empty
+ if (wGroupID && (szGroupName = getServListGroupName(wGroupID))) { // the group is valid, check if it is empty
void *groupData = collectBuddyGroup(wGroupID, NULL);
- if (groupData)
- { // the group is not empty, cannot delete
+ if (groupData) { // the group is not empty, cannot delete
SAFE_FREE(&groupData);
SAFE_FREE(&szGroupName);
// end operation
@@ -2487,8 +2211,7 @@ int CIcqProto::servlistRemoveGroup_Ready(const char *szGroup, WORD groupID, LPAR
return CALLBACK_RESULT_CONTINUE;
}
- if (!CheckServerID((WORD)(wGroupID+1), 0) || getServListGroupLevel((WORD)(wGroupID+1)) == 0)
- { // is next id an sub-group, if yes, we cannot delete this group
+ if (!CheckServerID((WORD)(wGroupID + 1), 0) || getServListGroupLevel((WORD)(wGroupID + 1)) == 0) { // is next id an sub-group, if yes, we cannot delete this group
ack->dwAction = SSA_GROUP_REMOVE;
ack->wContactId = 0;
ack->wGroupId = wGroupID;
@@ -2514,9 +2237,7 @@ void CIcqProto::servlistRemoveGroup(const char *szGroup, WORD wGroupId)
if (!szGroup) return;
cookie_servlist_action *ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action));
-
- if (!ack)
- { // cookie failed
+ if (!ack) { // cookie failed
debugLogA("Error: Failed to allocate cookie");
return;
}
@@ -2525,24 +2246,14 @@ void CIcqProto::servlistRemoveGroup(const char *szGroup, WORD wGroupId)
servlistPendingAddGroup(szGroup, wGroupId, (LPARAM)ack, &CIcqProto::servlistRemoveGroup_Ready, TRUE);
}
-
-/*void CIcqProto::servlistMoveGroup(const char *szGroup, WORD wNewGroupId)
-{
-// relocate the group
-}*/
-
-
void CIcqProto::resetServContactAuthState(MCONTACT hContact, DWORD dwUin)
{
WORD wContactId = getWord(hContact, DBSETTING_SERVLIST_ID, 0);
WORD wGroupId = getWord(hContact, DBSETTING_SERVLIST_GROUP, 0);
- if (wContactId && wGroupId)
- {
+ if (wContactId && wGroupId) {
cookie_servlist_action *ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action));
-
- if (ack)
- { // we have cookie good, go on
+ if (ack) { // we have cookie good, go on
ack->hContact = hContact;
ack->wContactId = wContactId;
ack->wGroupId = wGroupId;
@@ -2560,8 +2271,7 @@ void CIcqProto::resetServContactAuthState(MCONTACT hContact, DWORD dwUin)
icq_sendServerContact(hContact, dwCookie, ICQ_LISTS_ADDTOLIST, wGroupId, wContactId, SSO_CONTACT_FIXAUTH | SSOF_BEGIN_OPERATION | SSOF_END_OPERATION, 200, &doubleObject);
}
}
- else
- debugLogA("Error: Failed to allocate cookie");
+ else debugLogA("Error: Failed to allocate cookie");
}
}
@@ -2579,15 +2289,7 @@ int CIcqProto::ServListDbSettingChanged(WPARAM hContact, LPARAM lParam)
if (!icqOnline() || !m_bSsiEnabled || bIsSyncingCL)
return 0;
-#ifdef _DEBUG
- if (cws->value.type == DBVT_DELETED)
- debugLogA("DB-Events: Module \"%s\", setting \"%s\" deleted.", cws->szModule, cws->szSetting);
- else
- debugLogA("DB-Events: Module \"%s\", setting \"%s\" changed, data type %x.", cws->szModule, cws->szSetting, cws->value.type);
-#endif
-
- if (!strcmpnull(cws->szModule, "CList"))
- {
+ if (!strcmpnull(cws->szModule, "CList")) {
// Has contact been renamed?
if (!strcmpnull(cws->szSetting, "MyHandle") && getByte("StoreServerDetails", DEFAULT_SS_STORE))
servlistUpdateContact(hContact); // Update contact's details in server-list
@@ -2610,17 +2312,13 @@ int CIcqProto::ServListDbSettingChanged(WPARAM hContact, LPARAM lParam)
int CIcqProto::ServListDbContactDeleted(WPARAM hContact, LPARAM lParam)
{
-#ifdef _DEBUG
- debugLogA("DB-Events: Contact %x deleted.", hContact);
-#endif
-
DeleteFromContactsCache(hContact);
- if ( !icqOnline() && m_bSsiEnabled)
+ if (!icqOnline() && m_bSsiEnabled)
// contact was deleted only locally - retrieve full list on next connect
setWord(hContact, "SrvRecordCount", 0);
- if ( !icqOnline() || !m_bSsiEnabled)
+ if (!icqOnline() || !m_bSsiEnabled)
return 0;
// we need all server contacts on local buddy list
@@ -2670,50 +2368,32 @@ int CIcqProto::ServListCListGroupChange(WPARAM hContact, LPARAM lParam)
if (!getByte("StoreServerDetails", DEFAULT_SS_STORE))
return 0;
-
- if (hContact == NULL)
- { // change made to group
- if (grpchg->pszNewName == NULL && grpchg->pszOldName != NULL)
- { // group removed
+ if (hContact == NULL) { // change made to group
+ if (grpchg->pszNewName == NULL && grpchg->pszOldName != NULL) { // group removed
char *szOldName = tchar_to_utf8(grpchg->pszOldName);
WORD wGroupId = getServListGroupLinkID(szOldName);
-#ifdef _DEBUG
- debugLogA("CList-Events: Group %x:\"%s\" deleted.", wGroupId, szOldName);
-#endif
- if (wGroupId)
- { // the group is known, remove from server
+ if (wGroupId) { // the group is known, remove from server
servlistPostPacket(NULL, 0, SSO_BEGIN_OPERATION, 100); // start server modifications here
servlistRemoveGroup(szOldName, wGroupId);
}
SAFE_FREE(&szOldName);
}
- else if (grpchg->pszNewName != NULL && grpchg->pszOldName != NULL)
- { // group renamed
+ else if (grpchg->pszNewName != NULL && grpchg->pszOldName != NULL) { // group renamed
char *szNewName = tchar_to_utf8(grpchg->pszNewName);
char *szOldName = tchar_to_utf8(grpchg->pszOldName);
WORD wGroupId = getServListGroupLinkID(szOldName);
-#ifdef _DEBUG
- debugLogA("CList-Events: Group %x:\"%s\" changed to \"%s\".", wGroupId, szOldName, szNewName);
-#endif
- if (wGroupId)
- { // group is known, rename on server
+ if (wGroupId) { // group is known, rename on server
servlistRenameGroup(szOldName, wGroupId, szNewName);
}
SAFE_FREE(&szOldName);
SAFE_FREE(&szNewName);
}
}
- else
- { // change to contact
- if (IsICQContact(hContact))
- { // our contact, fine move on the server as well
+ else { // change to contact
+ if (IsICQContact(hContact)) { // our contact, fine move on the server as well
char *szNewName = grpchg->pszNewName ? tchar_to_utf8(grpchg->pszNewName) : NULL;
-
-#ifdef _DEBUG
- debugLogA("CList-Events: Contact %x moved to group \"%s\".", hContact, szNewName);
-#endif
servlistMoveContact(hContact, szNewName);
SAFE_FREE(&szNewName);
}