diff options
25 files changed, 2440 insertions, 4116 deletions
diff --git a/protocols/IcqOscarJ/src/chan_01login.cpp b/protocols/IcqOscarJ/src/chan_01login.cpp index c1c6cfd9f3..48fc85dfcc 100644 --- a/protocols/IcqOscarJ/src/chan_01login.cpp +++ b/protocols/IcqOscarJ/src/chan_01login.cpp @@ -29,16 +29,13 @@ void CIcqProto::handleLoginChannel(BYTE *buf, WORD datalen, serverthread_info *i {
icq_packet packet;
-#ifdef _DEBUG
debugLogA("Received SRV_HELLO from %s", info->isLoginServer ? "login server" : "communication server");
-#endif
// isLoginServer is "1" if we just received SRV_HELLO
if (info->isLoginServer) {
if (m_bSecureLogin) {
-#ifdef _DEBUG
debugLogA("Sending %s to %s", "CLI_HELLO", "login server");
-#endif
+
packet.wLen = 12;
write_flap(&packet, ICQ_LOGIN_CHAN);
packDWord(&packet, 0x00000001);
@@ -48,9 +45,8 @@ void CIcqProto::handleLoginChannel(BYTE *buf, WORD datalen, serverthread_info *i char szUin[UINMAXLEN];
WORD wUinLen = strlennull(strUID(m_dwLocalUIN, szUin));
-#ifdef _DEBUG
debugLogA("Sending %s to %s", "ICQ_SIGNON_AUTH_REQUEST", "login server");
-#endif
+
serverPacketInit(&packet, (WORD)(14 + wUinLen));
packFNACHeader(&packet, ICQ_AUTHORIZATION_FAMILY, ICQ_SIGNON_AUTH_REQUEST, 0, 0);
packTLV(&packet, 0x0001, wUinLen, (LPBYTE)szUin);
@@ -58,9 +54,7 @@ void CIcqProto::handleLoginChannel(BYTE *buf, WORD datalen, serverthread_info *i }
else {
sendClientAuth((char*)info->szAuthKey, info->wAuthKeyLen, FALSE);
-#ifdef _DEBUG
debugLogA("Sent CLI_IDENT to %s", "login server");
-#endif
}
info->isLoginServer = false;
@@ -76,9 +70,7 @@ void CIcqProto::handleLoginChannel(BYTE *buf, WORD datalen, serverthread_info *i serverCookieInit(&packet, info->cookieData, (WORD)info->cookieDataLen);
sendServPacket(&packet);
-#ifdef _DEBUG
debugLogA("Sent CLI_IDENT to %s", "communication server");
-#endif
SAFE_FREE((void**)&info->cookieData);
info->cookieDataLen = 0;
diff --git a/protocols/IcqOscarJ/src/chan_02data.cpp b/protocols/IcqOscarJ/src/chan_02data.cpp index d9a827c359..37b8617465 100644 --- a/protocols/IcqOscarJ/src/chan_02data.cpp +++ b/protocols/IcqOscarJ/src/chan_02data.cpp @@ -34,17 +34,12 @@ void CIcqProto::handleDataChannel(BYTE *pBuffer, WORD wBufferLength, serverthrea snac_header snacHeader = {0};
if (!unpackSnacHeader(&snacHeader, &pBuffer, &wBufferLength) || !snacHeader.bValid)
- {
debugLogA("Error: Failed to parse SNAC header");
- }
- else
- {
-#ifdef _DEBUG
+ else {
if (snacHeader.wFlags & 0x8000)
debugLogA(" Received SNAC(x%02X,x%02X), version %u", snacHeader.wFamily, snacHeader.wSubtype, snacHeader.wVersion);
else
debugLogA(" Received SNAC(x%02X,x%02X)", snacHeader.wFamily, snacHeader.wSubtype);
-#endif
switch (snacHeader.wFamily) {
@@ -91,7 +86,6 @@ void CIcqProto::handleDataChannel(BYTE *pBuffer, WORD wBufferLength, serverthrea default:
debugLogA("Ignoring SNAC(x%02X,x%02X) - FAMILYx%02X not implemented", snacHeader.wFamily, snacHeader.wSubtype, snacHeader.wFamily);
break;
-
}
}
}
@@ -102,77 +96,62 @@ int unpackSnacHeader(snac_header *pSnacHeader, BYTE **pBuffer, WORD *pwBufferLen WORD wRef1, wRef2;
// Check header
- if (!pSnacHeader) return 0;
+ if (!pSnacHeader)
+ return 0;
// 10 bytes is the minimum size of a header
- if (*pwBufferLength < 10)
- {
+ if (*pwBufferLength < 10) {
// Buffer overflow
pSnacHeader->bValid = FALSE;
return 1;
}
// Unpack all the standard data
- unpackWord(pBuffer, &(pSnacHeader->wFamily));
- unpackWord(pBuffer, &(pSnacHeader->wSubtype));
- unpackWord(pBuffer, &(pSnacHeader->wFlags));
- unpackWord(pBuffer, &wRef1); // unpack reference id (sequence)
- unpackWord(pBuffer, &wRef2); // command
- pSnacHeader->dwRef = wRef1 | (wRef2<<0x10);
+ unpackWord(pBuffer, &(pSnacHeader->wFamily));
+ unpackWord(pBuffer, &(pSnacHeader->wSubtype));
+ unpackWord(pBuffer, &(pSnacHeader->wFlags));
+ unpackWord(pBuffer, &wRef1); // unpack reference id (sequence)
+ unpackWord(pBuffer, &wRef2); // command
+ pSnacHeader->dwRef = wRef1 | (wRef2 << 0x10);
*pwBufferLength -= 10;
// If flag bit 15 is set, we also have a version tag
// (...at least that is what I think it is)
- if (pSnacHeader->wFlags & 0x8000)
- {
- if (*pwBufferLength >= 2)
- {
+ if (pSnacHeader->wFlags & 0x8000) {
+ if (*pwBufferLength >= 2) {
WORD wExtraBytes = 0;
unpackWord(pBuffer, &wExtraBytes);
*pwBufferLength -= 2;
- if (*pwBufferLength >= wExtraBytes)
- {
- if (wExtraBytes == 6)
- {
+ if (*pwBufferLength >= wExtraBytes) {
+ if (wExtraBytes == 6) {
*pBuffer += 4; // TLV type and length?
unpackWord(pBuffer, &(pSnacHeader->wVersion));
*pwBufferLength -= wExtraBytes;
pSnacHeader->bValid = TRUE;
}
- else if (wExtraBytes == 0x0E)
- {
+ else if (wExtraBytes == 0x0E) {
*pBuffer += 8; // TLV(2) - unknown
*pBuffer += 4;
unpackWord(pBuffer, &(pSnacHeader->wVersion));
*pwBufferLength -= wExtraBytes;
pSnacHeader->bValid = TRUE;
}
- else
- {
+ else {
*pBuffer += wExtraBytes;
*pwBufferLength -= wExtraBytes;
pSnacHeader->bValid = TRUE;
}
}
- else
- {
- // Buffer overflow
+ else // Buffer overflow
pSnacHeader->bValid = FALSE;
- }
}
- else
- {
- // Buffer overflow
+ else // Buffer overflow
pSnacHeader->bValid = FALSE;
- }
- }
- else
- {
- pSnacHeader->bValid = TRUE;
}
+ else pSnacHeader->bValid = TRUE;
return 1;
}
@@ -182,7 +161,7 @@ void CIcqProto::LogFamilyError(WORD wFamily, WORD wError) {
char *msg;
- switch(wError) {
+ switch (wError) {
case 0x01: msg = "Invalid SNAC header"; break;
case 0x02: msg = "Server rate limit exceeded"; break;
case 0x03: msg = "Client rate limit exceeded"; break;
diff --git a/protocols/IcqOscarJ/src/fam_01service.cpp b/protocols/IcqOscarJ/src/fam_01service.cpp index e86882e802..57247e33d3 100644 --- a/protocols/IcqOscarJ/src/fam_01service.cpp +++ b/protocols/IcqOscarJ/src/fam_01service.cpp @@ -38,10 +38,8 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header switch (pSnacHeader->wSubtype) {
case ICQ_SERVER_READY:
-#ifdef _DEBUG
debugLogA("Server is ready and is requesting my Family versions");
debugLogA("Sending my Families");
-#endif
// This packet is a response to SRV_FAMILIES SNAC(1,3).
// This tells the server which SNAC families and their corresponding
@@ -67,38 +65,34 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header case ICQ_SERVER_FAMILIES2:
/* This is a reply to CLI_FAMILIES and it tells the client which families and their versions that this server understands.
* We send a rate request packet */
-#ifdef _DEBUG
debugLogA("Server told me his Family versions");
debugLogA("Requesting Rate Information");
-#endif
+
serverPacketInit(&packet, 10);
packFNACHeader(&packet, ICQ_SERVICE_FAMILY, ICQ_CLIENT_REQ_RATE_INFO);
sendServPacket(&packet);
break;
case ICQ_SERVER_RATE_INFO:
-#ifdef _DEBUG
debugLogA("Server sent Rate Info");
-#endif
+
/* init rates management */
m_rates = new rates(this, pBuffer, wBufferLength);
+
/* ack rate levels */
-#ifdef _DEBUG
debugLogA("Sending Rate Info Ack");
-#endif
+
m_rates->initAckPacket(&packet);
sendServPacket(&packet);
/* CLI_REQINFO - This command requests from the server certain information about the client that is stored on the server. */
-#ifdef _DEBUG
debugLogA("Sending CLI_REQINFO");
-#endif
+
serverPacketInit(&packet, 10);
packFNACHeader(&packet, ICQ_SERVICE_FAMILY, ICQ_CLIENT_REQINFO);
sendServPacket(&packet);
- if (m_bSsiEnabled)
- {
+ if (m_bSsiEnabled) {
cookie_servlist_action* ack;
DWORD dwCookie;
@@ -106,56 +100,49 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header WORD wRecordCount = getWord("SrvRecordCount", 0);
// CLI_REQLISTS - we want to use SSI
-#ifdef _DEBUG
debugLogA("Requesting roster rights");
-#endif
+
serverPacketInit(&packet, 16);
packFNACHeader(&packet, ICQ_LISTS_FAMILY, ICQ_LISTS_CLI_REQLISTS);
packTLVWord(&packet, 0x0B, 0x000F); // mimic ICQ 6
sendServPacket(&packet);
- if (!wRecordCount) // CLI_REQROSTER
- { // we do not have any data - request full list
-#ifdef _DEBUG
+ if (!wRecordCount) { // CLI_REQROSTER
+ // we do not have any data - request full list
debugLogA("Requesting full roster");
-#endif
+
serverPacketInit(&packet, 10);
ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action));
- if (ack)
- { // we try to use standalone cookie if available
+ if (ack) { // we try to use standalone cookie if available
ack->dwAction = SSA_CHECK_ROSTER; // loading list
dwCookie = AllocateCookie(CKT_SERVERLIST, ICQ_LISTS_CLI_REQUEST, 0, ack);
}
else // if not use that old fake
- dwCookie = ICQ_LISTS_CLI_REQUEST<<0x10;
+ dwCookie = ICQ_LISTS_CLI_REQUEST << 0x10;
packFNACHeader(&packet, ICQ_LISTS_FAMILY, ICQ_LISTS_CLI_REQUEST, 0, dwCookie);
sendServPacket(&packet);
}
- else // CLI_CHECKROSTER
- {
-#ifdef _DEBUG
+ else { // CLI_CHECKROSTER
debugLogA("Requesting roster check");
-#endif
+
serverPacketInit(&packet, 16);
ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action));
- if (ack) // TODO: rewrite - use get list service for empty list
- { // we try to use standalone cookie if available
+ if (ack) { // TODO: rewrite - use get list service for empty list
+ // we try to use standalone cookie if available
ack->dwAction = SSA_CHECK_ROSTER; // loading list
dwCookie = AllocateCookie(CKT_SERVERLIST, ICQ_LISTS_CLI_CHECK, 0, ack);
}
else // if not use that old fake
- dwCookie = ICQ_LISTS_CLI_CHECK<<0x10;
+ dwCookie = ICQ_LISTS_CLI_CHECK << 0x10;
packFNACHeader(&packet, ICQ_LISTS_FAMILY, ICQ_LISTS_CLI_CHECK, 0, dwCookie);
// check if it was not changed elsewhere (force reload, set that setting to zero)
- if (IsServerGroupsDefined())
- {
+ if (IsServerGroupsDefined()) {
packDWord(&packet, dwLastUpdate); // last saved time
packWord(&packet, wRecordCount); // number of records saved
}
- else
- { // we need to get groups info into DB, force receive list
+ else { // we need to get groups info into DB, force receive list
packDWord(&packet, 0); // last saved time
packWord(&packet, 0); // number of records saved
}
@@ -164,38 +151,34 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header }
// CLI_REQLOCATION
-#ifdef _DEBUG
debugLogA("Requesting Location rights");
-#endif
+
serverPacketInit(&packet, 10);
packFNACHeader(&packet, ICQ_LOCATION_FAMILY, ICQ_LOCATION_CLI_REQ_RIGHTS);
sendServPacket(&packet);
// CLI_REQBUDDY
-#ifdef _DEBUG
debugLogA("Requesting Client-side contactlist rights");
-#endif
+
serverPacketInit(&packet, 16);
packFNACHeader(&packet, ICQ_BUDDY_FAMILY, ICQ_USER_CLI_REQBUDDY);
// Query flags: 1 = Enable Avatars
// 2 = Enable offline status message notification
// 4 = Enable Avatars for offline contacts
- // 8 = Use reject for not authorized contacts
+ // 8 = Use reject for not authorized contacts
packTLVWord(&packet, 0x05, 0x0007);
sendServPacket(&packet);
// CLI_REQICBM
-#ifdef _DEBUG
debugLogA("Sending CLI_REQICBM");
-#endif
+
serverPacketInit(&packet, 10);
packFNACHeader(&packet, ICQ_MSG_FAMILY, ICQ_MSG_CLI_REQICBM);
sendServPacket(&packet);
// CLI_REQBOS
-#ifdef _DEBUG
debugLogA("Sending CLI_REQBOS");
-#endif
+
serverPacketInit(&packet, 10);
packFNACHeader(&packet, ICQ_BOS_FAMILY, ICQ_PRIVACY_REQ_RIGHTS);
sendServPacket(&packet);
@@ -206,26 +189,24 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header // This is the list of groups that we want to have on the next server
serverPacketInit(&packet, 30);
packFNACHeader(&packet, ICQ_SERVICE_FAMILY, ICQ_CLIENT_PAUSE_ACK);
- packWord(&packet,ICQ_SERVICE_FAMILY);
- packWord(&packet,ICQ_LISTS_FAMILY);
- packWord(&packet,ICQ_LOCATION_FAMILY);
- packWord(&packet,ICQ_BUDDY_FAMILY);
- packWord(&packet,ICQ_EXTENSIONS_FAMILY);
- packWord(&packet,ICQ_MSG_FAMILY);
- packWord(&packet,0x06);
- packWord(&packet,ICQ_BOS_FAMILY);
- packWord(&packet,ICQ_LOOKUP_FAMILY);
- packWord(&packet,ICQ_STATS_FAMILY);
+ packWord(&packet, ICQ_SERVICE_FAMILY);
+ packWord(&packet, ICQ_LISTS_FAMILY);
+ packWord(&packet, ICQ_LOCATION_FAMILY);
+ packWord(&packet, ICQ_BUDDY_FAMILY);
+ packWord(&packet, ICQ_EXTENSIONS_FAMILY);
+ packWord(&packet, ICQ_MSG_FAMILY);
+ packWord(&packet, 0x06);
+ packWord(&packet, ICQ_BOS_FAMILY);
+ packWord(&packet, ICQ_LOOKUP_FAMILY);
+ packWord(&packet, ICQ_STATS_FAMILY);
sendServPacket(&packet);
-#ifdef _DEBUG
+
debugLogA("Sent server pause ack");
-#endif
break;
case ICQ_SERVER_MIGRATIONREQ:
-#ifdef _DEBUG
debugLogA("Server migration requested (Flags: %u)", pSnacHeader->wFlags);
-#endif
+
pBuffer += 2; // Unknown, seen: 0
wBufferLength -= 2;
{
@@ -260,9 +241,7 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header break;
case ICQ_SERVER_NAME_INFO: // This is the reply to CLI_REQINFO
-#ifdef _DEBUG
debugLogA("Received self info");
-#endif
{
BYTE bUinLen;
unpackByte(&pBuffer, &bUinLen);
@@ -289,7 +268,7 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header setDword("IP", dwValue);
// Save member since timestamp
- dwValue = chain->getDWord(0x05, 1);
+ dwValue = chain->getDWord(0x05, 1);
if (dwValue) setDword("MemberTS", dwValue);
dwValue = chain->getDWord(0x03, 1);
@@ -338,81 +317,79 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header break;
case ICQ_SERVER_REDIRECT_SERVICE: // reply to family request, got new connection point
- {
- oscar_tlv_chain *pChain = NULL;
- cookie_family_request *pCookieData;
-
- if (!(pChain = readIntoTLVChain(&pBuffer, wBufferLength, 0))) {
- debugLogA("Received Broken Redirect Service SNAC(1,5).");
- break;
- }
-
- // pick request data
- WORD wFamily = pChain->getWord(0x0D, 1);
- if ((!FindCookie(pSnacHeader->dwRef, NULL, (void**)&pCookieData)) || (pCookieData->wFamily != wFamily)) {
- disposeChain(&pChain);
- debugLogA("Received unexpected SNAC(1,5), skipping.");
- break;
- }
-
- FreeCookie(pSnacHeader->dwRef);
+ {
+ oscar_tlv_chain *pChain = NULL;
+ cookie_family_request *pCookieData;
- // new family entry point received
- char *pServer = pChain->getString(0x05, 1);
- BYTE bServerSSL = pChain->getNumber(0x8E, 1);
- char *pCookie = pChain->getString(0x06, 1);
- WORD wCookieLen = pChain->getLength(0x06, 1);
+ if (!(pChain = readIntoTLVChain(&pBuffer, wBufferLength, 0))) {
+ debugLogA("Received Broken Redirect Service SNAC(1,5).");
+ break;
+ }
- if (!pServer || !pCookie) {
- debugLogA("Server returned invalid data, family unavailable.");
+ // pick request data
+ WORD wFamily = pChain->getWord(0x0D, 1);
+ if ((!FindCookie(pSnacHeader->dwRef, NULL, (void**)&pCookieData)) || (pCookieData->wFamily != wFamily)) {
+ disposeChain(&pChain);
+ debugLogA("Received unexpected SNAC(1,5), skipping.");
+ break;
+ }
- SAFE_FREE(&pServer);
- SAFE_FREE(&pCookie);
- SAFE_FREE((void**)&pCookieData);
- disposeChain(&pChain);
- break;
- }
+ FreeCookie(pSnacHeader->dwRef);
- // Get new family server ip and port
- WORD wPort = info->wServerPort; // get default port
- parseServerAddress(pServer, &wPort);
-
- // establish connection
- NETLIBOPENCONNECTION nloc = { 0 };
- if (m_bGatewayMode)
- nloc.flags |= NLOCF_HTTPGATEWAY;
- nloc.szHost = pServer;
- nloc.wPort = wPort;
-
- HANDLE hConnection = NetLib_OpenConnection(m_hNetlibUser, wFamily == ICQ_AVATAR_FAMILY ? "Avatar " : NULL, &nloc);
-
- if (hConnection == NULL)
- debugLogA("Unable to connect to ICQ new family server.");
- // we want the handler to be called even if the connecting failed
- else if (bServerSSL) { /* Start SSL session if requested */
-#ifdef _DEBUG
- debugLogA("(%d) Starting SSL negotiation", CallService(MS_NETLIB_GETSOCKET, (WPARAM)hConnection, 0));
-#endif
- if (!CallService(MS_NETLIB_STARTSSL, (WPARAM)hConnection, 0)) {
- debugLogA("Unable to connect to ICQ new family server, SSL could not be negotiated");
- NetLib_CloseConnection(&hConnection, FALSE);
- }
- }
+ // new family entry point received
+ char *pServer = pChain->getString(0x05, 1);
+ BYTE bServerSSL = pChain->getNumber(0x8E, 1);
+ char *pCookie = pChain->getString(0x06, 1);
+ WORD wCookieLen = pChain->getLength(0x06, 1);
- (this->*pCookieData->familyHandler)(hConnection, pCookie, wCookieLen);
+ if (!pServer || !pCookie) {
+ debugLogA("Server returned invalid data, family unavailable.");
- // Free allocated memory
- // NOTE: "cookie" will get freed when we have connected to the avatar server.
- disposeChain(&pChain);
SAFE_FREE(&pServer);
+ SAFE_FREE(&pCookie);
SAFE_FREE((void**)&pCookieData);
+ disposeChain(&pChain);
break;
}
+ // Get new family server ip and port
+ WORD wPort = info->wServerPort; // get default port
+ parseServerAddress(pServer, &wPort);
+
+ // establish connection
+ NETLIBOPENCONNECTION nloc = { 0 };
+ if (m_bGatewayMode)
+ nloc.flags |= NLOCF_HTTPGATEWAY;
+ nloc.szHost = pServer;
+ nloc.wPort = wPort;
+
+ HANDLE hConnection = NetLib_OpenConnection(m_hNetlibUser, wFamily == ICQ_AVATAR_FAMILY ? "Avatar " : NULL, &nloc);
+
+ if (hConnection == NULL)
+ debugLogA("Unable to connect to ICQ new family server.");
+ // we want the handler to be called even if the connecting failed
+ else if (bServerSSL) { /* Start SSL session if requested */
+ debugLogA("(%p) Starting SSL negotiation", CallService(MS_NETLIB_GETSOCKET, (WPARAM)hConnection, 0));
+
+ if (!CallService(MS_NETLIB_STARTSSL, (WPARAM)hConnection, 0)) {
+ debugLogA("Unable to connect to ICQ new family server, SSL could not be negotiated");
+ NetLib_CloseConnection(&hConnection, FALSE);
+ }
+ }
+
+ (this->*pCookieData->familyHandler)(hConnection, pCookie, wCookieLen);
+
+ // Free allocated memory
+ // NOTE: "cookie" will get freed when we have connected to the avatar server.
+ disposeChain(&pChain);
+ SAFE_FREE(&pServer);
+ SAFE_FREE((void**)&pCookieData);
+ break;
+ }
+
case ICQ_SERVER_EXTSTATUS: // our session data
-#ifdef _DEBUG
debugLogA("Received owner session data.");
-#endif
+
while (wBufferLength > 4) { // loop thru all items
WORD itemType = pBuffer[0] * 0x10 | pBuffer[1];
BYTE itemFlags = pBuffer[2];
@@ -420,14 +397,11 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header if (itemType == AVATAR_HASH_PHOTO) { /// TODO: handle photo item
// skip photo item
-#ifdef _DEBUG
debugLogA("Photo item recognized");
-#endif
}
else if ((itemType == AVATAR_HASH_STATIC || itemType == AVATAR_HASH_FLASH) && (itemLen >= 0x10)) {
-#ifdef _DEBUG
debugLogA("Avatar item recognized");
-#endif
+
if (m_bAvatarsEnabled && !info->bMyAvatarInited) { // signal the server after login
// this refreshes avatar state - it used to work automatically, but now it does not
if (getByte("ForceOurAvatar", 0)) { // keep our avatar
@@ -448,14 +422,10 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header handleAvatarOwnerHash(itemType, itemFlags, pBuffer, itemLen + 4);
}
else if (itemType == 0x02) {
-#ifdef _DEBUG
debugLogA("Status message item recognized");
-#endif
}
else if (itemType == 0x0E) {
-#ifdef _DEBUG
debugLogA("Status mood item recognized");
-#endif
}
// move to next item
@@ -471,22 +441,20 @@ void CIcqProto::handleServiceFam(BYTE *pBuffer, WORD wBufferLength, snac_header break;
case ICQ_ERROR: // Something went wrong, probably the request for avatar family failed
- {
- WORD wError;
- if (wBufferLength >= 2)
- unpackWord(&pBuffer, &wError);
- else
- wError = 0;
+ {
+ WORD wError;
+ if (wBufferLength >= 2)
+ unpackWord(&pBuffer, &wError);
+ else
+ wError = 0;
- LogFamilyError(ICQ_SERVICE_FAMILY, wError);
- }
+ LogFamilyError(ICQ_SERVICE_FAMILY, wError);
+ }
break;
// Stuff we don't care about
case ICQ_SERVER_MOTD:
-#ifdef _DEBUG
debugLogA("Server message of the day");
-#endif
break;
default:
@@ -541,8 +509,8 @@ char* CIcqProto::buildUinList(int subtype, WORD wMaxLen, MCONTACT *hContactResum // not in our SS list, or are awaiting authorization, to our
// client side list
if (m_bSsiEnabled && getWord(hContact, DBSETTING_SERVLIST_ID, 0) &&
- !getByte(hContact, "Auth", 0))
- add = 0;
+ !getByte(hContact, "Auth", 0))
+ add = 0;
// Never add hidden contacts to CS list
if (db_get_b(hContact, "CList", "Hidden", 0))
@@ -589,7 +557,7 @@ void CIcqProto::sendEntireListServ(WORD wFamily, WORD wSubtype, int listType) SAFE_FREE((void**)&szList);
}
- while (hResumeContact);
+ while (hResumeContact);
}
@@ -606,7 +574,7 @@ static void packShortCapability(icq_packet *packet, WORD wCapability) // CLI_SETUSERINFO
void CIcqProto::setUserInfo()
-{
+{
icq_packet packet;
WORD wAdditionalData = 0;
BYTE bXStatus = getContactXStatus(NULL);
@@ -692,7 +660,7 @@ void CIcqProto::setUserInfo() // Tells the server we can speak to AIM
if (m_bAimEnabled)
packShortCapability(&packet, 0x134D); // CAP_AIM_COMPATIBLE
-
+
#ifdef DBG_AIMCONTACTSEND
packShortCapability(&packet, 0x134B); // CAP_SENDBUDDYLIST
#endif
diff --git a/protocols/IcqOscarJ/src/fam_02location.cpp b/protocols/IcqOscarJ/src/fam_02location.cpp index 202f063854..73c8923288 100644 --- a/protocols/IcqOscarJ/src/fam_02location.cpp +++ b/protocols/IcqOscarJ/src/fam_02location.cpp @@ -34,7 +34,6 @@ extern const char* cliSpamBot; void CIcqProto::handleLocationFam(BYTE *pBuffer, WORD wBufferLength, snac_header *pSnacHeader)
{
switch (pSnacHeader->wSubtype) {
-
case ICQ_LOCATION_RIGHTS_REPLY: // Reply to CLI_REQLOCATION
debugLogA("Server sent SNAC(x02,x03) - SRV_LOCATION_RIGHTS_REPLY");
break;
@@ -46,21 +45,16 @@ void CIcqProto::handleLocationFam(BYTE *pBuffer, WORD wBufferLength, snac_header case ICQ_ERROR:
{
WORD wError;
- MCONTACT hCookieContact;
- cookie_fam15_data *pCookieData;
-
-
if (wBufferLength >= 2)
unpackWord(&pBuffer, &wError);
else
wError = 0;
- if (wError == 4)
- {
- if (FindCookie(pSnacHeader->dwRef, &hCookieContact, (void**)&pCookieData) && !getContactUin(hCookieContact) && pCookieData->bRequestType == REQUESTTYPE_PROFILE)
- {
- ProtoBroadcastAck(hCookieContact, ACKTYPE_GETINFO, ACKRESULT_FAILED, (HANDLE)1 ,0);
-
+ if (wError == 4) {
+ MCONTACT hCookieContact;
+ cookie_fam15_data *pCookieData;
+ if (FindCookie(pSnacHeader->dwRef, &hCookieContact, (void**)&pCookieData) && !getContactUin(hCookieContact) && pCookieData->bRequestType == REQUESTTYPE_PROFILE) {
+ ProtoBroadcastAck(hCookieContact, ACKTYPE_GETINFO, ACKRESULT_FAILED, (HANDLE)1, 0);
ReleaseCookie(pSnacHeader->dwRef);
}
}
@@ -76,13 +70,11 @@ void CIcqProto::handleLocationFam(BYTE *pBuffer, WORD wBufferLength, snac_header }
static char* AimApplyEncoding(char* pszStr, const char* pszEncoding)
-{ // decode encoding to ANSI only
- if (pszStr && pszEncoding)
- {
+{
+ // decode encoding to ANSI only
+ if (pszStr && pszEncoding) {
const char *szEnc = strstrnull(pszEncoding, "charset=");
-
- if (szEnc)
- { // decode custom encoding to Utf-8
+ if (szEnc) { // decode custom encoding to Utf-8
char *szStr = ApplyEncoding(pszStr, szEnc + 9);
// decode utf-8 to ansi
char *szRes = NULL;
@@ -127,9 +119,7 @@ void CIcqProto::handleLocationUserInfoReply(BYTE* buf, WORD wLen, DWORD dwCookie // Ignore away status if the user is not already on our list
if (hContact == INVALID_CONTACT_ID) {
-#ifdef _DEBUG
debugLogA("Ignoring away reply (%s)", strUID(dwUIN, szUID));
-#endif
return;
}
@@ -148,139 +138,120 @@ void CIcqProto::handleLocationUserInfoReply(BYTE* buf, WORD wLen, DWORD dwCookie switch (GetCookieType(dwCookie)) {
case CKT_FAMILYSPECIAL:
+ ReleaseCookie(dwCookie);
{
- ReleaseCookie(dwCookie);
+ // Syntax check
+ if (wLen < 4)
+ return;
- // Read user info TLVs
- {
- oscar_tlv_chain* pChain;
- BYTE *tmp;
- char *szMsg = NULL;
+ char *szMsg = NULL;
+ BYTE *tmp = buf;
- // Syntax check
- if (wLen < 4)
- return;
+ // Get general chain
+ oscar_tlv_chain* pChain;
+ if (!(pChain = readIntoTLVChain(&buf, wLen, wTLVCount)))
+ return;
- tmp = buf;
- // Get general chain
- if (!(pChain = readIntoTLVChain(&buf, wLen, wTLVCount)))
- return;
+ disposeChain(&pChain);
- disposeChain(&pChain);
+ wLen -= (buf - tmp);
- wLen -= (buf - tmp);
-
- // Get extra chain
- if (pChain = readIntoTLVChain(&buf, wLen, 2))
- {
- oscar_tlv *pTLV;
- char *szEncoding = NULL;
-
- // Get Profile encoding TLV
-
- pTLV = pChain->getTLV(0x05, 1);
- if (pTLV && pTLV->wLen > 0) // store client capabilities
- db_set_blob(hContact, m_szModuleName, "CapBuf", pTLV->pData, pTLV->wLen);
- else
- delSetting(hContact, "CapBuf");
-
- pTLV = pChain->getTLV(0x01, 1);
- if (pTLV && (pTLV->wLen >= 1))
- {
- szEncoding = (char*)_alloca(pTLV->wLen + 1);
- memcpy(szEncoding, pTLV->pData, pTLV->wLen);
- szEncoding[pTLV->wLen] = '\0';
- }
- // Get Profile info TLV
- pTLV = pChain->getTLV(0x02, 1);
- if (pTLV && (pTLV->wLen >= 1))
- {
- szMsg = (char*)SAFE_MALLOC(pTLV->wLen + 2);
- memcpy(szMsg, pTLV->pData, pTLV->wLen);
- szMsg[pTLV->wLen] = '\0';
- szMsg[pTLV->wLen + 1] = '\0';
- szMsg = AimApplyEncoding(szMsg, szEncoding);
- szMsg = EliminateHtml(szMsg, pTLV->wLen);
- }
- // Free TLV chain
- disposeChain(&pChain);
- }
+ // Get extra chain
+ if (pChain = readIntoTLVChain(&buf, wLen, 2)) {
+ char *szEncoding = NULL;
- setString(hContact, "About", szMsg);
- ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, (HANDLE)1 ,0);
+ // Get Profile encoding TLV
+ oscar_tlv *pTLV = pChain->getTLV(0x05, 1);
+ if (pTLV && pTLV->wLen > 0) // store client capabilities
+ db_set_blob(hContact, m_szModuleName, "CapBuf", pTLV->pData, pTLV->wLen);
+ else
+ delSetting(hContact, "CapBuf");
- SAFE_FREE((void**)&szMsg);
+ pTLV = pChain->getTLV(0x01, 1);
+ if (pTLV && (pTLV->wLen >= 1)) {
+ szEncoding = (char*)_alloca(pTLV->wLen + 1);
+ memcpy(szEncoding, pTLV->pData, pTLV->wLen);
+ szEncoding[pTLV->wLen] = '\0';
+ }
+ // Get Profile info TLV
+ pTLV = pChain->getTLV(0x02, 1);
+ if (pTLV && (pTLV->wLen >= 1)) {
+ szMsg = (char*)SAFE_MALLOC(pTLV->wLen + 2);
+ memcpy(szMsg, pTLV->pData, pTLV->wLen);
+ szMsg[pTLV->wLen] = '\0';
+ szMsg[pTLV->wLen + 1] = '\0';
+ szMsg = AimApplyEncoding(szMsg, szEncoding);
+ szMsg = EliminateHtml(szMsg, pTLV->wLen);
+ }
+ // Free TLV chain
+ disposeChain(&pChain);
}
- break;
+
+ setString(hContact, "About", szMsg);
+ ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, (HANDLE)1 ,0);
+
+ SAFE_FREE((void**)&szMsg);
}
+ break;
default: // away message
- {
- status = AwayMsgTypeToStatus(pCookieData->nAckType);
- if (status == ID_STATUS_OFFLINE)
- {
- debugLogA("SNAC(2.6) Ignoring unknown status message from %s", strUID(dwUIN, szUID));
-
- ReleaseCookie(dwCookie);
- return;
- }
+ status = AwayMsgTypeToStatus(pCookieData->nAckType);
+ if (status == ID_STATUS_OFFLINE) {
+ debugLogA("SNAC(2.6) Ignoring unknown status message from %s", strUID(dwUIN, szUID));
ReleaseCookie(dwCookie);
+ return;
+ }
- // Read user info TLVs
- {
- oscar_tlv_chain* pChain;
- oscar_tlv* pTLV;
- BYTE *tmp;
- char *szMsg = NULL;
+ ReleaseCookie(dwCookie);
- // Syntax check
- if (wLen < 4)
- return;
+ // Syntax check
+ if (wLen < 4)
+ return;
- tmp = buf;
- // Get general chain
- if (!(pChain = readIntoTLVChain(&buf, wLen, wTLVCount)))
- return;
+ BYTE *tmp = buf;
- disposeChain(&pChain);
+ // Get general chain
+ oscar_tlv_chain* pChain;
+ if (!(pChain = readIntoTLVChain(&buf, wLen, wTLVCount)))
+ return;
- wLen -= (buf - tmp);
-
- // Get extra chain
- if (pChain = readIntoTLVChain(&buf, wLen, 2)) {
- char* szEncoding = NULL;
-
- // Get Away encoding TLV
- pTLV = pChain->getTLV(0x03, 1);
- if (pTLV && (pTLV->wLen >= 1)) {
- szEncoding = (char*)_alloca(pTLV->wLen + 1);
- memcpy(szEncoding, pTLV->pData, pTLV->wLen);
- szEncoding[pTLV->wLen] = '\0';
- }
- // Get Away info TLV
- pTLV = pChain->getTLV(0x04, 1);
- if (pTLV && (pTLV->wLen >= 1)) {
- szMsg = (char*)SAFE_MALLOC(pTLV->wLen + 2);
- memcpy(szMsg, pTLV->pData, pTLV->wLen);
- szMsg[pTLV->wLen] = '\0';
- szMsg[pTLV->wLen + 1] = '\0';
- szMsg = AimApplyEncoding(szMsg, szEncoding);
- szMsg = EliminateHtml(szMsg, pTLV->wLen);
- }
- // Free TLV chain
- disposeChain(&pChain);
- }
+ disposeChain(&pChain);
- PROTORECVEVENT pre = { 0 };
- pre.szMessage = szMsg ? szMsg : (char *)"";
- pre.timestamp = time(NULL);
- pre.lParam = dwCookie;
- ProtoChainRecv(hContact, PSR_AWAYMSG, status, (LPARAM)&pre);
+ wLen -= (buf - tmp);
- SAFE_FREE((void**)&szMsg);
+ // Get extra chain
+ char *szMsg = NULL;
+ if (pChain = readIntoTLVChain(&buf, wLen, 2)) {
+ char *szEncoding = NULL;
+
+ // Get Away encoding TLV
+ oscar_tlv *pTLV = pChain->getTLV(0x03, 1);
+ if (pTLV && (pTLV->wLen >= 1)) {
+ szEncoding = (char*)_alloca(pTLV->wLen + 1);
+ memcpy(szEncoding, pTLV->pData, pTLV->wLen);
+ szEncoding[pTLV->wLen] = '\0';
}
- break;
+ // Get Away info TLV
+ pTLV = pChain->getTLV(0x04, 1);
+ if (pTLV && (pTLV->wLen >= 1)) {
+ szMsg = (char*)SAFE_MALLOC(pTLV->wLen + 2);
+ memcpy(szMsg, pTLV->pData, pTLV->wLen);
+ szMsg[pTLV->wLen] = '\0';
+ szMsg[pTLV->wLen + 1] = '\0';
+ szMsg = AimApplyEncoding(szMsg, szEncoding);
+ szMsg = EliminateHtml(szMsg, pTLV->wLen);
+ }
+ // Free TLV chain
+ disposeChain(&pChain);
}
+
+ PROTORECVEVENT pre = { 0 };
+ pre.szMessage = szMsg ? szMsg : (char *)"";
+ pre.timestamp = time(NULL);
+ pre.lParam = dwCookie;
+ ProtoChainRecv(hContact, PSR_AWAYMSG, status, (LPARAM)&pre);
+
+ SAFE_FREE((void**)&szMsg);
}
}
diff --git a/protocols/IcqOscarJ/src/fam_03buddy.cpp b/protocols/IcqOscarJ/src/fam_03buddy.cpp index 495eb9774b..4679ca82c5 100644 --- a/protocols/IcqOscarJ/src/fam_03buddy.cpp +++ b/protocols/IcqOscarJ/src/fam_03buddy.cpp @@ -69,7 +69,6 @@ void CIcqProto::handleBuddyFam(BYTE *pBuffer, WORD wBufferLength, snac_header *p }
}
-
void CIcqProto::handleReplyBuddy(BYTE *buf, WORD wPackLen)
{
oscar_tlv_chain *pChain = readIntoTLVChain(&buf, wPackLen, 0);
@@ -87,7 +86,6 @@ void CIcqProto::handleReplyBuddy(BYTE *buf, WORD wPackLen) else debugLogA("Error: Malformed BuddyReply");
}
-
int unpackSessionDataItem(oscar_tlv_chain *pChain, WORD wItemType, BYTE **ppItemData, WORD *pwItemSize, BYTE *pbItemFlags)
{
int len = 0;
@@ -190,9 +188,7 @@ void CIcqProto::handleUserOnline(BYTE *buf, WORD wLen, serverthread_info *info) // Ignore status notification if the user is not already on our list
MCONTACT hContact = HContactFromUID(dwUIN, szUID, NULL);
if (hContact == INVALID_CONTACT_ID) {
-#ifdef _DEBUG
debugLogA("Ignoring user online (%s)", strUID(dwUIN, szUID));
-#endif
return;
}
@@ -273,10 +269,8 @@ void CIcqProto::handleUserOnline(BYTE *buf, WORD wLen, serverthread_info *info) wStatusFlags = 0;
}
-#ifdef _DEBUG
debugLogA("Flags are %x", wStatusFlags);
debugLogA("Status is %x", wStatus);
-#endif
// Get IP TLV
DWORD dwIP = pChain->getDWord(0x0A, 1);
@@ -298,13 +292,11 @@ void CIcqProto::handleUserOnline(BYTE *buf, WORD wLen, serverthread_info *info) tIdleTS -= (wIdleTimer*60);
}
-#ifdef _DEBUG
if (wIdleTimer)
debugLogA("Idle timer is %u.", wIdleTimer);
debugLogA("Online since %s", time2text(dwOnlineSince));
if (dwAwaySince)
debugLogA("Status was set on %s", time2text(dwAwaySince));
-#endif
// Check client capabilities
if (hContact != NULL) {
@@ -371,9 +363,7 @@ void CIcqProto::handleUserOnline(BYTE *buf, WORD wLen, serverthread_info *info) cLen -= 2;
}
}
-#ifdef _DEBUG
debugLogA("Detected %d capability items.", capLen / BINARY_CAP_SIZE);
-#endif
}
if (capLen) {
@@ -416,14 +406,12 @@ void CIcqProto::handleUserOnline(BYTE *buf, WORD wLen, serverthread_info *info) else if (wOldStatus == ID_STATUS_OFFLINE)
ClearContactCapabilities(hContact, CAPF_STATUS_MESSAGES);
-#ifdef _DEBUG
if (wOldStatus == ID_STATUS_OFFLINE) {
if (CheckContactCapabilities(hContact, CAPF_SRV_RELAY))
debugLogA("Supports advanced messages");
else
debugLogA("Does NOT support advanced messages");
}
-#endif
if (!nIsICQ) {
// AIM clients does not advertise these, but do support them
@@ -515,14 +503,6 @@ void CIcqProto::handleUserOnline(BYTE *buf, WORD wLen, serverthread_info *info) else
debugLogA("%s changed status to %S.", strUID(dwUIN, szUID), ptszStatus);
}
-#ifdef _DEBUG
- else {
- if (nIsICQ)
- debugLogA("%u has status %s (v%d).", dwUIN, ptszStatus, wVersion);
- else
- debugLogA("%s has status %s.", strUID(dwUIN, szUID), ptszStatus);
- }
-#endif
if (szClient == cliSpamBot) {
if (getByte("KillSpambots", DEFAULT_KILLSPAM_ENABLED) && db_get_b(hContact, "CList", "NotOnList", 0)) {
@@ -625,10 +605,7 @@ void CIcqProto::handleUserOffline(BYTE *buf, WORD wLen) // Reset DC status
setByte(hContact, "DCStatus", 0);
}
-#ifdef _DEBUG
- else
- debugLogA("%s is offline.", strUID(dwUIN, szUID));
-#endif
+ else debugLogA("%s is offline.", strUID(dwUIN, szUID));
}
// Release memory
diff --git a/protocols/IcqOscarJ/src/fam_04message.cpp b/protocols/IcqOscarJ/src/fam_04message.cpp index 538ce9741e..203ac55b95 100644 --- a/protocols/IcqOscarJ/src/fam_04message.cpp +++ b/protocols/IcqOscarJ/src/fam_04message.cpp @@ -32,7 +32,6 @@ void CIcqProto::handleMsgFam(BYTE *pBuffer, WORD wBufferLength, snac_header *pSnacHeader)
{
switch (pSnacHeader->wSubtype) {
-
case ICQ_MSG_SRV_ERROR: // SNAC(4, 0x01)
handleRecvServMsgError(pBuffer, wBufferLength, pSnacHeader->wFlags, pSnacHeader->dwRef);
break;
@@ -71,7 +70,6 @@ void CIcqProto::handleMsgFam(BYTE *pBuffer, WORD wBufferLength, snac_header *pSn }
}
-
static void setMsgChannelParams(CIcqProto *ppro, WORD wChan, DWORD dwFlags)
{
icq_packet packet;
@@ -89,7 +87,6 @@ static void setMsgChannelParams(CIcqProto *ppro, WORD wChan, DWORD dwFlags) ppro->sendServPacket(&packet);
}
-
void CIcqProto::handleReplyICBM(BYTE *buf, WORD wLen, WORD wFlags, DWORD dwRef)
{ // we don't care about the stuff, just change the params
DWORD dwFlags = 0x00000303;
@@ -104,7 +101,6 @@ void CIcqProto::handleReplyICBM(BYTE *buf, WORD wLen, WORD wFlags, DWORD dwRef) setMsgChannelParams(this, 0x0000, dwFlags);
}
-
void CIcqProto::handleRecvServMsg(BYTE *buf, WORD wLen, WORD wFlags, DWORD dwRef)
{
DWORD dwUin;
@@ -114,8 +110,7 @@ void CIcqProto::handleRecvServMsg(BYTE *buf, WORD wLen, WORD wFlags, DWORD dwRef WORD wMessageFormat;
uid_str szUID;
- if (wLen < 11)
- { // just do some basic packet checking
+ if (wLen < 11) { // just do some basic packet checking
debugLogA("Error: Malformed message thru server");
return;
}
@@ -134,14 +129,12 @@ void CIcqProto::handleRecvServMsg(BYTE *buf, WORD wLen, WORD wFlags, DWORD dwRef // Sender UIN
if (!unpackUID(&buf, &wLen, &dwUin, &szUID)) return;
- if (dwUin && IsOnSpammerList(dwUin))
- {
+ if (dwUin && IsOnSpammerList(dwUin)) {
debugLogA("Ignored Message from known Spammer");
return;
}
- if (wLen < 4)
- { // just do some basic packet checking
+ if (wLen < 4) { // just do some basic packet checking
debugLogA("Error: Malformed message thru server");
return;
}
@@ -153,8 +146,7 @@ void CIcqProto::handleRecvServMsg(BYTE *buf, WORD wLen, WORD wFlags, DWORD dwRef // Number of following TLVs, until msg-format dependant TLVs
unpackWord(&buf, &wTLVCount);
wLen -= 2;
- if (wTLVCount > 0)
- {
+ if (wTLVCount > 0) {
// Save current buffer pointer so we can calculate
// how much data we have left after the chain read.
BYTE *pBufStart = buf;
@@ -194,11 +186,9 @@ void CIcqProto::handleRecvServMsg(BYTE *buf, WORD wLen, WORD wFlags, DWORD dwRef default:
debugLogA("Unknown format message thru server - Ref %u, Type: %u, UID: %s", dwRef, wMessageFormat, strUID(dwUin, szUID));
break;
-
}
}
-
char* CIcqProto::convertMsgToUserSpecificUtf(MCONTACT hContact, const char *szMsg)
{
WORD wCP = getWord(hContact, "CodePage", m_wAnsiCodepage);
@@ -210,15 +200,13 @@ char* CIcqProto::convertMsgToUserSpecificUtf(MCONTACT hContact, const char *szMs return usMsg;
}
-
void CIcqProto::handleRecvServMsgType1(BYTE *buf, WORD wLen, DWORD dwUin, char *szUID, DWORD dwMsgID1, DWORD dwMsgID2, DWORD dwRef)
{
WORD wTLVType;
WORD wTLVLen;
BYTE* pMsgTLV;
- if (wLen < 4)
- { // just perform basic structure check
+ if (wLen < 4) { // just perform basic structure check
debugLogA("Message (format %u) - Ignoring empty message", 1);
return;
}
@@ -228,8 +216,7 @@ void CIcqProto::handleRecvServMsgType1(BYTE *buf, WORD wLen, DWORD dwUin, char * debugLogA("Message (format %u) - UID: %s", 1, strUID(dwUin, szUID));
// It must be TLV(2)
- if (wTLVType == 2)
- {
+ if (wTLVType == 2) {
BYTE *pDataBuf = pMsgTLV;
oscar_tlv_chain *pChain = readIntoTLVChain(&pDataBuf, wTLVLen, 0);
@@ -237,42 +224,31 @@ void CIcqProto::handleRecvServMsgType1(BYTE *buf, WORD wLen, DWORD dwUin, char * // TLV(1281): Capability
// TLV(257): This TLV contains the actual message (can be fragmented)
- if (pChain)
- {
- oscar_tlv* pMessageTLV;
- oscar_tlv* pCapabilityTLV;
- WORD wMsgPart = 1;
-
+ if (pChain) {
// Find the capability TLV
- pCapabilityTLV = pChain->getTLV(0x0501, 1);
- if (pCapabilityTLV && (pCapabilityTLV->wLen > 0))
- {
- WORD wDataLen;
- BYTE *pDataBuf;
-
- wDataLen = pCapabilityTLV->wLen;
- pDataBuf = pCapabilityTLV->pData;
-
+ oscar_tlv *pCapabilityTLV = pChain->getTLV(0x0501, 1);
+ if (pCapabilityTLV && (pCapabilityTLV->wLen > 0)) {
+ WORD wDataLen = pCapabilityTLV->wLen;
+ BYTE *pDataBuf = pCapabilityTLV->pData;
if (wDataLen > 0)
debugLogA("Message (format 1) - Message has %d caps.", wDataLen);
}
- else
- debugLogA("Message (format 1) - No message cap.");
+ else debugLogA("Message (format 1) - No message cap.");
- { // Parse the message parts, usually only one 0x0101 TLV containing the message,
+ {
+ // Parse the message parts, usually only one 0x0101 TLV containing the message,
// but in some cases there can be more 0x0101 TLVs containing message parts in
// different encodings (just like the new format of Offline Messages).
DWORD dwRecvTime;
char* szMsg = NULL;
- PROTORECVEVENT pre = {0};
- int bAdded;
+ PROTORECVEVENT pre = { 0 };
+ int bAdded;
MCONTACT hContact = HContactFromUID(dwUin, szUID, &bAdded);
- while (pMessageTLV = pChain->getTLV(0x0101, wMsgPart))
- { // Loop thru all message parts
- if (pMessageTLV->wLen > 4)
- {
+ WORD wMsgPart = 1;
+ while (oscar_tlv *pMessageTLV = pChain->getTLV(0x0101, wMsgPart)) { // Loop thru all message parts
+ if (pMessageTLV->wLen > 4) {
WORD wMsgLen;
BYTE *pMsgBuf;
WORD wEncoding;
@@ -296,36 +272,31 @@ void CIcqProto::handleRecvServMsgType1(BYTE *buf, WORD wLen, DWORD dwUin, char * case 2: // UCS-2
{
- WCHAR* usMsgPart = (WCHAR*)SAFE_MALLOC(wMsgLen + 2);
+ WCHAR *usMsgPart = (WCHAR*)SAFE_MALLOC(wMsgLen + 2);
unpackWideString(&pMsgBuf, usMsgPart, wMsgLen);
- usMsgPart[wMsgLen/sizeof(WCHAR)] = 0;
+ usMsgPart[wMsgLen / sizeof(WCHAR)] = 0;
szMsgPart = make_utf8_string(usMsgPart);
if (!IsUSASCII(szMsgPart, strlennull(szMsgPart)))
bMsgPartUnicode = TRUE;
SAFE_FREE(&usMsgPart);
-
- break;
}
+ break;
case 0: // us-ascii
case 3: // ANSI
default:
- {
- // Copy the message text into a new proper string.
- szMsgPart = (char*)SAFE_MALLOC(wMsgLen + 1);
- memcpy(szMsgPart, pMsgBuf, wMsgLen);
- szMsgPart[wMsgLen] = '\0';
+ // Copy the message text into a new proper string.
+ szMsgPart = (char*)SAFE_MALLOC(wMsgLen + 1);
+ memcpy(szMsgPart, pMsgBuf, wMsgLen);
+ szMsgPart[wMsgLen] = '\0';
- break;
- }
+ break;
}
// Check if the new part is compatible with the message
- if (!pre.flags && bMsgPartUnicode)
- { // make the resulting message utf-8 encoded - need to append utf-8 encoded part
- if (szMsg)
- { // not necessary to convert - appending first part, only set flags
+ if (!pre.flags && bMsgPartUnicode) { // make the resulting message utf-8 encoded - need to append utf-8 encoded part
+ if (szMsg) { // not necessary to convert - appending first part, only set flags
char *szUtfMsg = ansi_to_utf8_codepage(szMsg, getWord(hContact, "CodePage", m_wAnsiCodepage));
SAFE_FREE(&szMsg);
@@ -333,8 +304,7 @@ void CIcqProto::handleRecvServMsgType1(BYTE *buf, WORD wLen, DWORD dwUin, char * }
pre.flags = PREF_UTF;
}
- if (!bMsgPartUnicode && pre.flags == PREF_UTF)
- { // convert message part to utf-8 and append
+ if (!bMsgPartUnicode && pre.flags == PREF_UTF) { // convert message part to utf-8 and append
char *szUtfPart = ansi_to_utf8_codepage((char*)szMsgPart, getWord(hContact, "CodePage", m_wAnsiCodepage));
SAFE_FREE(&szMsgPart);
@@ -348,18 +318,13 @@ void CIcqProto::handleRecvServMsgType1(BYTE *buf, WORD wLen, DWORD dwUin, char * }
wMsgPart++;
}
- if (strlennull(szMsg))
- {
- if (_strnicmp(szMsg, "<html>", 6) == 0)
- { // strip HTML formating from AIM message
+ if (strlennull(szMsg)) {
+ if (_strnicmp(szMsg, "<html>", 6) == 0) // strip HTML formating from AIM message
szMsg = EliminateHtml(szMsg, strlennull(szMsg));
- }
- if (!pre.flags && !IsUSASCII(szMsg, strlennull(szMsg)))
- { // message is Ansi and contains national characters, create Unicode part by codepage
+ if (!pre.flags && !IsUSASCII(szMsg, strlennull(szMsg))) { // message is Ansi and contains national characters, create Unicode part by codepage
char *usMsg = convertMsgToUserSpecificUtf(hContact, szMsg);
- if (usMsg)
- {
+ if (usMsg) {
SAFE_FREE(&szMsg);
szMsg = usMsg;
pre.flags = PREF_UTF;
@@ -370,17 +335,13 @@ void CIcqProto::handleRecvServMsgType1(BYTE *buf, WORD wLen, DWORD dwUin, char * { // Check if the message was received as offline
cookie_offline_messages *cookie;
+ if (!(dwRef & 0x80000000) && FindCookie(dwRef, NULL, (void**)&cookie)) {
+ cookie->nMessages++;
- if (!(dwRef & 0x80000000) && FindCookie(dwRef, NULL, (void**)&cookie))
- {
WORD wTimeTLVType, wTimeTLVLen;
BYTE *pTimeTLV;
-
- cookie->nMessages++;
-
unpackTypedTLV(buf, wLen, 0x16, &wTimeTLVType, &wTimeTLVLen, &pTimeTLV);
- if (pTimeTLV && wTimeTLVType == 0x16 && wTimeTLVLen == 4)
- { // found Offline timestamp
+ if (pTimeTLV && wTimeTLVType == 0x16 && wTimeTLVLen == 4) { // found Offline timestamp
BYTE *pBuf = pTimeTLV;
unpackDWord(&pBuf, &dwRecvTime);
@@ -397,7 +358,7 @@ void CIcqProto::handleRecvServMsgType1(BYTE *buf, WORD wLen, DWORD dwUin, char * debugLogA("Message (format 1) received");
// Save tick value
- setDword(hContact, "TickTS", time(NULL) - (dwMsgID1/1000));
+ setDword(hContact, "TickTS", time(NULL) - (dwMsgID1 / 1000));
}
else debugLogA("Message (format %u) - Ignoring empty message", 1);
@@ -407,25 +368,20 @@ void CIcqProto::handleRecvServMsgType1(BYTE *buf, WORD wLen, DWORD dwUin, char * // Free the chain memory
disposeChain(&pChain);
}
- else
- debugLogA("Failed to read TLV chain in message (format 1)");
+ else debugLogA("Failed to read TLV chain in message (format 1)");
}
- else
- debugLogA("Unsupported TLV (%u) in message (format %u)", wTLVType, 1);
+ else debugLogA("Unsupported TLV (%u) in message (format %u)", wTLVType, 1);
SAFE_FREE((void**)&pMsgTLV);
}
-
void CIcqProto::handleRecvServMsgType2(BYTE *buf, WORD wLen, DWORD dwUin, char *szUID, DWORD dwMsgID1, DWORD dwMsgID2, DWORD dwRef)
{
WORD wTLVType;
WORD wTLVLen;
BYTE *pDataBuf = NULL;
- BYTE *pBuf;
- if (wLen < 4)
- {
+ if (wLen < 4) {
debugLogA("Message (format %u) - Ignoring empty message", 2);
return;
}
@@ -433,28 +389,28 @@ void CIcqProto::handleRecvServMsgType2(BYTE *buf, WORD wLen, DWORD dwUin, char * // Unpack the first TLV(5)
unpackTypedTLV(buf, wLen, 5, &wTLVType, &wTLVLen, &pDataBuf);
debugLogA("Message (format %u) - UID: %s", 2, strUID(dwUin, szUID));
- pBuf = pDataBuf;
+ BYTE *pBuf = pDataBuf;
// It must be TLV(5)
- if (wTLVType == 5)
- {
+ if (wTLVType == 5) {
WORD wCommand;
oscar_tlv_chain* chain;
oscar_tlv* tlv;
- DWORD q1,q2,q3,q4;
+ DWORD q1, q2, q3, q4;
- if (wTLVLen < 26)
- { // just check if all basic data is there
+ if (wTLVLen < 26) { // just check if all basic data is there
debugLogA("Message (format %u) - Ignoring empty message", 2);
SAFE_FREE((void**)&pBuf);
return;
}
unpackWord(&pDataBuf, &wCommand);
- wTLVLen -= 2; // Command 0x0000 - Normal message/file send request
-#ifdef _DEBUG // 0x0001 - Abort request
- debugLogA("Command is %u", wCommand); // 0x0002 - Acknowledge request
-#endif
+ wTLVLen -= 2;
+
+ // Command 0x0000 - Normal message/file send request
+ // 0x0001 - Abort request
+ // 0x0002 - Acknowledge request
+ debugLogA("Command is %u", wCommand);
// Some stuff we don't use
pDataBuf += 8; // dwID1 and dwID2 again
@@ -465,19 +421,16 @@ void CIcqProto::handleRecvServMsgType2(BYTE *buf, WORD wLen, DWORD dwUin, char * unpackDWord(&pDataBuf, &q4); // Message Capability
wTLVLen -= 16;
- if (CompareGUIDs(q1,q2,q3,q4, MCAP_SRV_RELAY_FMT))
- { // we surely have at least 4 bytes for TLV chain
+ if (CompareGUIDs(q1, q2, q3, q4, MCAP_SRV_RELAY_FMT)) { // we surely have at least 4 bytes for TLV chain
MCONTACT hContact = HContactFromUID(dwUin, szUID, NULL);
- if (wCommand == 1)
- {
+ if (wCommand == 1) {
debugLogA("Cannot handle abort messages yet... :(");
SAFE_FREE((void**)&pBuf);
return;
}
- if (wTLVLen < 4)
- { // just check if at least one tlv is there
+ if (wTLVLen < 4) { // just check if at least one tlv is there
debugLogA("Message (format %u) - Ignoring empty message", 2);
SAFE_FREE((void**)&pBuf);
return;
@@ -493,8 +446,7 @@ void CIcqProto::handleRecvServMsgType2(BYTE *buf, WORD wLen, DWORD dwUin, char * // TLV(0x2711): The next message level
chain = readIntoTLVChain(&pDataBuf, wTLVLen, 0);
- if (!chain)
- { // sanity check
+ if (!chain) { // sanity check
debugLogA("Message (format %u) - Invalid data", 2);
SAFE_FREE((void**)&pBuf);
return;
@@ -503,8 +455,7 @@ void CIcqProto::handleRecvServMsgType2(BYTE *buf, WORD wLen, DWORD dwUin, char * WORD wAckType = chain->getWord(0x0A, 1);
// Update the saved DC info (if contact already exists)
- if (hContact != INVALID_CONTACT_ID)
- {
+ if (hContact != INVALID_CONTACT_ID) {
DWORD dwIP, dwExternalIP;
WORD wPort;
@@ -518,46 +469,38 @@ void CIcqProto::handleRecvServMsgType2(BYTE *buf, WORD wLen, DWORD dwUin, char * // Save tick value
BYTE bClientID = getByte(hContact, "ClientID", 0);
if (bClientID == CLID_GENERIC || bClientID == CLID_ICQ6)
- setDword(hContact, "TickTS", time(NULL) - (dwMsgID1/1000));
+ setDword(hContact, "TickTS", time(NULL) - (dwMsgID1 / 1000));
else
setDword(hContact, "TickTS", 0);
}
// Parse the next message level
if (tlv = chain->getTLV(0x2711, 1))
- {
parseServRelayData(tlv->pData, tlv->wLen, hContact, dwUin, szUID, dwMsgID1, dwMsgID2, wAckType);
- }
else
- {
debugLogA("Warning, no 0x2711 TLV in message (format 2)");
- }
+
// Clean up
disposeChain(&chain);
}
- else if (CompareGUIDs(q1,q2,q3,q4, MCAP_REVERSE_DC_REQ))
- { // Handle reverse DC request
- if (wCommand == 1)
- {
+ else if (CompareGUIDs(q1, q2, q3, q4, MCAP_REVERSE_DC_REQ)) { // Handle reverse DC request
+ if (wCommand == 1) {
debugLogA("Cannot handle abort messages yet... :(");
SAFE_FREE((void**)&pBuf);
return;
}
- if (wTLVLen < 4)
- { // just check if at least one tlv is there
+ if (wTLVLen < 4) { // just check if at least one tlv is there
debugLogA("Message (format %u) - Ignoring empty message", 2);
SAFE_FREE((void**)&pBuf);
return;
}
- if (!dwUin)
- { // AIM cannot send this, just sanity
+ if (!dwUin) { // AIM cannot send this, just sanity
debugLogA("Error: Malformed UIN in packet");
SAFE_FREE((void**)&pBuf);
return;
}
chain = readIntoTLVChain(&pDataBuf, wTLVLen, 0);
- if (!chain)
- { // Malformed packet
+ if (!chain) { // Malformed packet
debugLogA("Error: Malformed data in packet");
SAFE_FREE((void**)&pBuf);
return;
@@ -565,10 +508,8 @@ void CIcqProto::handleRecvServMsgType2(BYTE *buf, WORD wLen, DWORD dwUin, char * WORD wAckType = chain->getWord(0x0A, 1);
// Parse the next message level
- if (tlv = chain->getTLV(0x2711, 1))
- {
- if (tlv->wLen == 0x1B)
- {
+ if (tlv = chain->getTLV(0x2711, 1)) {
+ if (tlv->wLen == 0x1B) {
BYTE *buf = tlv->pData;
DWORD dwUin;
@@ -576,11 +517,8 @@ void CIcqProto::handleRecvServMsgType2(BYTE *buf, WORD wLen, DWORD dwUin, char * MCONTACT hContact = HContactFromUIN(dwUin, NULL);
if (hContact == INVALID_CONTACT_ID)
- {
debugLogA("Error: %s from unknown contact %u", "Reverse Connect Request", dwUin);
- }
- else
- {
+ else {
DWORD dwIp, dwPort;
WORD wVersion;
BYTE bMode;
@@ -596,11 +534,10 @@ void CIcqProto::handleRecvServMsgType2(BYTE *buf, WORD wLen, DWORD dwUin, char * unpackLEWord(&buf, &wVersion);
setDword(hContact, "IP", dwIp);
- setWord(hContact, "UserPort", (WORD)dwPort);
- setByte(hContact, "DCType", bMode);
- setWord(hContact, "Version", wVersion);
- if (wVersion > 6)
- {
+ setWord(hContact, "UserPort", (WORD)dwPort);
+ setByte(hContact, "DCType", bMode);
+ setWord(hContact, "Version", wVersion);
+ if (wVersion > 6) {
cookie_reverse_connect *pCookie = (cookie_reverse_connect*)SAFE_MALLOC(sizeof(cookie_reverse_connect));
unpackLEDWord(&buf, (DWORD*)&pCookie->ft);
@@ -609,39 +546,26 @@ void CIcqProto::handleRecvServMsgType2(BYTE *buf, WORD wLen, DWORD dwUin, char * OpenDirectConnection(hContact, DIRECTCONN_REVERSE, (void*)pCookie);
}
- else
- debugLogA("Warning: Unsupported direct protocol version in %s", "Reverse Connect Request");
+ else debugLogA("Warning: Unsupported direct protocol version in %s", "Reverse Connect Request");
}
}
- else
- {
- debugLogA("Malformed %s", "Reverse Connect Request");
- }
- }
- else
- {
- debugLogA("Warning, no 0x2711 TLV in message (format 2)");
+ else debugLogA("Malformed %s", "Reverse Connect Request");
}
+ else debugLogA("Warning, no 0x2711 TLV in message (format 2)");
+
// Clean up
disposeChain(&chain);
}
- else if (CompareGUIDs(q1,q2,q3,q4, MCAP_FILE_TRANSFER))
- { // this is an OFT packet
+ else if (CompareGUIDs(q1, q2, q3, q4, MCAP_FILE_TRANSFER)) // this is an OFT packet
handleRecvServMsgOFT(pDataBuf, wTLVLen, dwUin, szUID, dwMsgID1, dwMsgID2, wCommand);
- }
- else if (CompareGUIDs(q1,q2,q3,q4, MCAP_CONTACTS))
- { // this is Contacts Transfer
+
+ else if (CompareGUIDs(q1, q2, q3, q4, MCAP_CONTACTS)) // this is Contacts Transfer
handleRecvServMsgContacts(pDataBuf, wTLVLen, dwUin, szUID, dwMsgID1, dwMsgID2, wCommand);
- }
+
else // here should be detection of extra data streams (Xtraz)
- {
debugLogA("Unknown Message Format Capability");
- }
- }
- else
- {
- debugLogA("Unsupported TLV (%u) in message (format %u)", wTLVType, 2);
}
+ else debugLogA("Unsupported TLV (%u) in message (format %u)", wTLVType, 2);
SAFE_FREE((void**)&pBuf);
}
@@ -651,8 +575,7 @@ void CIcqProto::parseServRelayData(BYTE *pDataBuf, WORD wLen, MCONTACT hContact, {
WORD wId;
- if (wLen < 2)
- {
+ if (wLen < 2) {
debugLogA("Message (format %u) - Ignoring empty message", 2);
return;
}
@@ -661,14 +584,12 @@ void CIcqProto::parseServRelayData(BYTE *pDataBuf, WORD wLen, MCONTACT hContact, wLen -= 2;
// Only 0x1B are real messages
- if (wId == 0x001B)
- {
+ if (wId == 0x001B) {
WORD wVersion;
WORD wCookie;
- DWORD dwGuid1,dwGuid2,dwGuid3,dwGuid4;
+ DWORD dwGuid1, dwGuid2, dwGuid3, dwGuid4;
- if (wLen < 31)
- { // just check if we have data to work with
+ if (wLen < 31) { // just check if we have data to work with
debugLogA("Message (format %u) - Ignoring empty message", 2);
return;
}
@@ -695,15 +616,13 @@ void CIcqProto::parseServRelayData(BYTE *pDataBuf, WORD wLen, MCONTACT hContact, unpackLEWord(&pDataBuf, &wCookie);
wLen -= 2;
- if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, PSIG_MESSAGE))
- { // is this a normal message ?
+ if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, PSIG_MESSAGE)) { // is this a normal message ?
BYTE bMsgType;
BYTE bFlags;
WORD wStatus, wPritority;
WORD wMsgLen;
- if (wLen < 20)
- { // check if there is everything that should be there
+ if (wLen < 20) { // check if there is everything that should be there
debugLogA("Message (format %u) - Ignoring empty message", 2);
return;
}
@@ -729,17 +648,13 @@ void CIcqProto::parseServRelayData(BYTE *pDataBuf, WORD wLen, MCONTACT hContact, wLen -= 2;
// HANDLERS
- switch (bMsgType)
- {
- // File messages, handled by the file module
+ switch (bMsgType) { // File messages, handled by the file module
case MTYPE_FILEREQ:
+ if (!dwUin) { // AIM cannot send this, just sanity
+ debugLogA("Error: Malformed UIN in packet");
+ return;
+ }
{
- if (!dwUin)
- { // AIM cannot send this, just sanity
- debugLogA("Error: Malformed UIN in packet");
- return;
- }
-
char* szMsg = (char *)_alloca(wMsgLen + 1);
memcpy(szMsg, pDataBuf, wMsgLen);
szMsg[wMsgLen] = '\0';
@@ -747,68 +662,52 @@ void CIcqProto::parseServRelayData(BYTE *pDataBuf, WORD wLen, MCONTACT hContact, wLen -= wMsgLen;
if (wAckType == 0 || wAckType == 1)
- {
// File requests 7
handleFileRequest(pDataBuf, wLen, dwUin, wCookie, dwMsgID1, dwMsgID2, szMsg, 7, FALSE);
- }
else if (wAckType == 2)
- {
// File reply 7
handleFileAck(pDataBuf, wLen, dwUin, wCookie, wStatus, szMsg);
- }
else
- {
debugLogA("Ignored strange file message");
- }
-
- break;
}
+ break;
- // Chat messages, handled by the chat module
+ // Chat messages, handled by the chat module
case MTYPE_CHAT:
- { // TODO: this type is deprecated
- break;
- }
+ // TODO: this type is deprecated
+ break;
- // Plugin messages, need further parsing
+ // Plugin messages, need further parsing
case MTYPE_PLUGIN:
- {
- if (wLen < wMsgLen)
- { // sanity check
- debugLogA("Error: Malformed server Greeting message");
- return;
- }
-
- parseServRelayPluginData(pDataBuf + wMsgLen, wLen - wMsgLen, hContact, dwUin, szUID, dwMsgID1, dwMsgID2, wAckType, bFlags, wStatus, wCookie, wVersion);
- break;
+ if (wLen < wMsgLen) { // sanity check
+ debugLogA("Error: Malformed server Greeting message");
+ return;
}
- // Everything else
+ parseServRelayPluginData(pDataBuf + wMsgLen, wLen - wMsgLen, hContact, dwUin, szUID, dwMsgID1, dwMsgID2, wAckType, bFlags, wStatus, wCookie, wVersion);
+ break;
+
+ // Everything else
default:
- {
- if (!dwUin)
- { // AIM cannot send this, just sanity
- debugLogA("Error: Malformed UIN in packet");
- return;
- }
- message_ack_params pMsgAck = {0};
-
- pMsgAck.bType = MAT_SERVER_ADVANCED;
- pMsgAck.dwUin = dwUin;
- pMsgAck.dwMsgID1 = dwMsgID1;
- pMsgAck.dwMsgID2 = dwMsgID2;
- pMsgAck.wCookie = wCookie;
- pMsgAck.msgType = bMsgType;
- pMsgAck.bFlags = bFlags;
- handleMessageTypes(dwUin, szUID, time(NULL), dwMsgID1, dwMsgID2, wCookie, wVersion, bMsgType, bFlags, wAckType, wLen, wMsgLen, (char*)pDataBuf, 0, &pMsgAck);
- break;
+ if (!dwUin) { // AIM cannot send this, just sanity
+ debugLogA("Error: Malformed UIN in packet");
+ return;
}
+
+ message_ack_params pMsgAck = { 0 };
+ pMsgAck.bType = MAT_SERVER_ADVANCED;
+ pMsgAck.dwUin = dwUin;
+ pMsgAck.dwMsgID1 = dwMsgID1;
+ pMsgAck.dwMsgID2 = dwMsgID2;
+ pMsgAck.wCookie = wCookie;
+ pMsgAck.msgType = bMsgType;
+ pMsgAck.bFlags = bFlags;
+ handleMessageTypes(dwUin, szUID, time(NULL), dwMsgID1, dwMsgID2, wCookie, wVersion, bMsgType, bFlags, wAckType, wLen, wMsgLen, (char*)pDataBuf, 0, &pMsgAck);
+ break;
}
}
- else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, PSIG_INFO_PLUGIN))
- { // info manager plugin - obsolete
- if (!dwUin)
- { // AIM cannot send this, just sanity
+ else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, PSIG_INFO_PLUGIN)) { // info manager plugin - obsolete
+ if (!dwUin) { // AIM cannot send this, just sanity
debugLogA("Error: Malformed UIN in packet");
return;
}
@@ -824,8 +723,7 @@ void CIcqProto::parseServRelayData(BYTE *pDataBuf, WORD wLen, MCONTACT hContact, pDataBuf += 3; // unknown
wLen -= 3;
unpackByte(&pDataBuf, &bLevel);
- if (bLevel != 0 || wLen < 16)
- {
+ if (bLevel != 0 || wLen < 16) {
debugLogA("Invalid %s Manager Plugin message from %u", "Info", dwUin);
return;
}
@@ -836,16 +734,12 @@ void CIcqProto::parseServRelayData(BYTE *pDataBuf, WORD wLen, MCONTACT hContact, wLen -= 16;
if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, PMSG_QUERY_INFO))
- {
debugLogA("User %u requests our %s plugin list. NOT SUPPORTED", dwUin, "info");
- }
else
debugLogA("Unknown %s Manager message from %u", "Info", dwUin);
}
- else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, PSIG_STATUS_PLUGIN))
- { // status manager plugin - obsolete
- if (!dwUin)
- { // AIM cannot send this, just sanity
+ else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, PSIG_STATUS_PLUGIN)) { // status manager plugin - obsolete
+ if (!dwUin) { // AIM cannot send this, just sanity
debugLogA("Error: Malformed UIN in packet");
return;
}
@@ -861,8 +755,7 @@ void CIcqProto::parseServRelayData(BYTE *pDataBuf, WORD wLen, MCONTACT hContact, pDataBuf += 3; // unknown
wLen -= 3;
unpackByte(&pDataBuf, &bLevel);
- if (bLevel != 0 || wLen < 16)
- {
+ if (bLevel != 0 || wLen < 16) {
debugLogA("Invalid %s Manager Plugin message from %u", "Status", dwUin);
return;
}
@@ -877,14 +770,11 @@ void CIcqProto::parseServRelayData(BYTE *pDataBuf, WORD wLen, MCONTACT hContact, else
debugLogA("Unknown %s Manager message from %u", "Status", dwUin);
}
- else
- debugLogA("Unknown signature (%08x-%08x-%08x-%08x) in message (format 2)", dwGuid1, dwGuid2, dwGuid3, dwGuid4);
+ else debugLogA("Unknown signature (%08x-%08x-%08x-%08x) in message (format 2)", dwGuid1, dwGuid2, dwGuid3, dwGuid4);
}
- else
- debugLogA("Unknown wId1 (%u) in message (format 2)", wId);
+ else debugLogA("Unknown wId1 (%u) in message (format 2)", wId);
}
-
void CIcqProto::parseServRelayPluginData(BYTE *pDataBuf, WORD wLen, MCONTACT hContact, DWORD dwUin, char *szUID, DWORD dwMsgID1, DWORD dwMsgID2, WORD wAckType, BYTE bFlags, WORD wStatus, WORD wCookie, WORD wVersion)
{
int nTypeId;
@@ -895,8 +785,7 @@ void CIcqProto::parseServRelayPluginData(BYTE *pDataBuf, WORD wLen, MCONTACT hCo // Message plugin identification
if (!unpackPluginTypeId(&pDataBuf, &wLen, &nTypeId, &wFunction, FALSE)) return;
- if (wLen > 8)
- {
+ if (wLen > 8) {
DWORD dwLengthToEnd;
DWORD dwDataLen;
@@ -910,10 +799,8 @@ void CIcqProto::parseServRelayPluginData(BYTE *pDataBuf, WORD wLen, MCONTACT hCo if (dwDataLen > wLen)
dwDataLen = wLen;
- if (nTypeId == MTYPE_FILEREQ && wAckType == 2)
- {
- if (!dwUin)
- { // AIM cannot send this, just sanity
+ if (nTypeId == MTYPE_FILEREQ && wAckType == 2) {
+ if (!dwUin) { // AIM cannot send this, just sanity
debugLogA("Error: Malformed UIN in packet");
return;
}
@@ -927,10 +814,8 @@ void CIcqProto::parseServRelayPluginData(BYTE *pDataBuf, WORD wLen, MCONTACT hCo handleFileAck(pDataBuf, wLen, dwUin, wCookie, wStatus, szMsg);
}
- else if (nTypeId == MTYPE_FILEREQ && wAckType == 1)
- {
- if (!dwUin)
- { // AIM cannot send this, just sanity
+ else if (nTypeId == MTYPE_FILEREQ && wAckType == 1) {
+ if (!dwUin) { // AIM cannot send this, just sanity
debugLogA("Error: Malformed UIN in packet");
return;
}
@@ -944,10 +829,8 @@ void CIcqProto::parseServRelayPluginData(BYTE *pDataBuf, WORD wLen, MCONTACT hCo handleFileRequest(pDataBuf, wLen, dwUin, wCookie, dwMsgID1, dwMsgID2, szMsg, 8, FALSE);
}
- else if (nTypeId == MTYPE_CHAT && wAckType == 1)
- { // TODO: this is deprecated
- if (!dwUin)
- { // AIM cannot send this, just sanity
+ else if (nTypeId == MTYPE_CHAT && wAckType == 1) { // TODO: this is deprecated
+ if (!dwUin) { // AIM cannot send this, just sanity
debugLogA("Error: Malformed UIN in packet");
return;
}
@@ -961,12 +844,10 @@ void CIcqProto::parseServRelayPluginData(BYTE *pDataBuf, WORD wLen, MCONTACT hCo // handleChatRequest(pDataBuf, wLen, dwUin, wCookie, dwMsgID1, dwMsgID2, szMsg, 8);
}
- else if (nTypeId == MTYPE_STATUSMSGEXT && wFunction >= 1 && wFunction <= 3)
- { // handle extended status message request
+ else if (nTypeId == MTYPE_STATUSMSGEXT && wFunction >= 1 && wFunction <= 3) { // handle extended status message request
int nMsgType = 0;
- switch (wFunction)
- {
+ switch (wFunction) {
case 1: // Away
if (m_iStatus == ID_STATUS_ONLINE || m_iStatus == ID_STATUS_INVISIBLE)
nMsgType = MTYPE_AUTOONLINE;
@@ -989,14 +870,12 @@ void CIcqProto::parseServRelayPluginData(BYTE *pDataBuf, WORD wLen, MCONTACT hCo }
handleMessageTypes(dwUin, szUID, time(NULL), dwMsgID1, dwMsgID2, wCookie, wVersion, nMsgType, bFlags, wAckType, dwLengthToEnd, 0, (char*)pDataBuf, MTF_PLUGIN | MTF_STATUS_EXTENDED, NULL);
}
- else if (nTypeId)
- {
- if (!dwUin)
- { // AIM cannot send this, just sanity
+ else if (nTypeId) {
+ if (!dwUin) { // AIM cannot send this, just sanity
debugLogA("Error: Malformed UIN in packet");
return;
}
- message_ack_params pMsgAck = {0};
+ message_ack_params pMsgAck = { 0 };
pMsgAck.bType = MAT_SERVER_ADVANCED;
pMsgAck.dwUin = dwUin;
@@ -1007,43 +886,33 @@ void CIcqProto::parseServRelayPluginData(BYTE *pDataBuf, WORD wLen, MCONTACT hCo pMsgAck.bFlags = bFlags;
handleMessageTypes(dwUin, szUID, time(NULL), dwMsgID1, dwMsgID2, wCookie, wVersion, nTypeId, bFlags, wAckType, dwLengthToEnd, (WORD)dwDataLen, (char*)pDataBuf, MTF_PLUGIN, &pMsgAck);
}
- else
- {
- debugLogA("Unsupported plugin message type %d", nTypeId);
- }
+ else debugLogA("Unsupported plugin message type %d", nTypeId);
}
- else
- debugLogA("Error: Malformed server plugin message");
+ else debugLogA("Error: Malformed server plugin message");
}
-
void CIcqProto::handleRecvServMsgContacts(BYTE *buf, WORD wLen, DWORD dwUin, char *szUID, DWORD dwID1, DWORD dwID2, WORD wCommand)
{
MCONTACT hContact = HContactFromUID(dwUin, szUID, NULL);
- if (wCommand == 0)
- { // received contacts
- if (wLen < 4)
- { // just check if at least one tlv is there
+ if (wCommand == 0) { // received contacts
+ if (wLen < 4) { // just check if at least one tlv is there
debugLogA("Message (format %u) - Ignoring empty contacts message", 2);
return;
}
oscar_tlv_chain *chain = readIntoTLVChain(&buf, wLen, 0);
- if (!chain)
- { // sanity check
+ if (!chain) { // sanity check
debugLogA("Message (format %u) - Invalid data", 2);
return;
}
WORD wAckType = chain->getWord(0x0A, 1);
- if (wAckType == 1)
- { // it is really message containing contacts, parse them
+ if (wAckType == 1) { // it is really message containing contacts, parse them
oscar_tlv *tlvUins = chain->getTLV(0x2711, 1);
oscar_tlv *tlvNames = chain->getTLV(0x2712, 1);
- if (!tlvUins || tlvUins->wLen < 4)
- {
+ if (!tlvUins || tlvUins->wLen < 4) {
debugLogA("Malformed '%s' message", "contacts");
disposeChain(&chain);
return;
@@ -1055,16 +924,13 @@ void CIcqProto::handleRecvServMsgContacts(BYTE *buf, WORD wLen, DWORD dwUin, cha BYTE *pBuffer = tlvUins->pData;
int nLen = tlvUins->wLen;
- while (nLen > 2)
- { // parse UIDs
- if (!wContactsGroup)
- {
+ while (nLen > 2) { // parse UIDs
+ if (!wContactsGroup) {
WORD wGroupLen;
unpackWord(&pBuffer, &wGroupLen);
nLen -= 2;
- if (nLen >= wGroupLen + 2)
- {
+ if (nLen >= wGroupLen + 2) {
pBuffer += wGroupLen;
unpackWord(&pBuffer, &wContactsGroup);
nLen -= wGroupLen + 2;
@@ -1072,20 +938,17 @@ void CIcqProto::handleRecvServMsgContacts(BYTE *buf, WORD wLen, DWORD dwUin, cha else
break;
}
- else
- { // group parsed, UIDs waiting
+ else { // group parsed, UIDs waiting
WORD wUidLen;
unpackWord(&pBuffer, &wUidLen);
nLen -= 2;
- if (nLen >= wUidLen)
- {
+ if (nLen >= wUidLen) {
char *szUid = (char*)SAFE_MALLOC(wUidLen + 1);
unpackString(&pBuffer, szUid, wUidLen);
nLen -= wUidLen;
- if (iContact >= nContacts)
- { // the list is too small, resize it
+ if (iContact >= nContacts) { // the list is too small, resize it
nContacts += 0x10;
contacts = (ICQSEARCHRESULT**)SAFE_REALLOC(contacts, nContacts * sizeof(ICQSEARCHRESULT*));
}
@@ -1095,14 +958,12 @@ void CIcqProto::handleRecvServMsgContacts(BYTE *buf, WORD wLen, DWORD dwUin, cha contacts[iContact]->hdr.nick = null_strdup(_T(""));
contacts[iContact]->hdr.id = ansi_to_tchar(szUid);
- if (IsStringUIN(szUid))
- { // icq contact
+ if (IsStringUIN(szUid)) { // icq contact
contacts[iContact]->uin = atoi(szUid);
if (contacts[iContact]->uin == 0)
valid = 0;
}
- else
- { // aim contact
+ else { // aim contact
if (!strlennull(szUid))
valid = 0;
}
@@ -1110,8 +971,7 @@ void CIcqProto::handleRecvServMsgContacts(BYTE *buf, WORD wLen, DWORD dwUin, cha SAFE_FREE(&szUid);
}
- else
- {
+ else {
if (wContactsGroup) valid = 0;
break;
}
@@ -1119,12 +979,10 @@ void CIcqProto::handleRecvServMsgContacts(BYTE *buf, WORD wLen, DWORD dwUin, cha wContactsGroup--;
}
}
- if (!iContact || !valid)
- {
+ if (!iContact || !valid) {
debugLogA("Malformed '%s' message", "contacts");
disposeChain(&chain);
- for (int i = 0; i < iContact; i++)
- {
+ for (int i = 0; i < iContact; i++) {
SAFE_FREE(&contacts[i]->hdr.id);
SAFE_FREE(&contacts[i]->hdr.nick);
SAFE_FREE((void**)&contacts[i]);
@@ -1133,22 +991,18 @@ void CIcqProto::handleRecvServMsgContacts(BYTE *buf, WORD wLen, DWORD dwUin, cha return;
}
nContacts = iContact;
- if (tlvNames && tlvNames->wLen >= 4)
- { // parse names, if available
+ if (tlvNames && tlvNames->wLen >= 4) { // parse names, if available
pBuffer = tlvNames->pData;
nLen = tlvNames->wLen;
iContact = 0;
- while (nLen > 2)
- { // parse Names
- if (!wContactsGroup)
- {
+ while (nLen > 2) { // parse Names
+ if (!wContactsGroup) {
WORD wGroupLen;
unpackWord(&pBuffer, &wGroupLen);
nLen -= 2;
- if (nLen >= wGroupLen + 2)
- {
+ if (nLen >= wGroupLen + 2) {
pBuffer += wGroupLen;
unpackWord(&pBuffer, &wContactsGroup);
nLen -= wGroupLen + 2;
@@ -1156,20 +1010,17 @@ void CIcqProto::handleRecvServMsgContacts(BYTE *buf, WORD wLen, DWORD dwUin, cha else
break;
}
- else
- { // group parsed, Names waiting
+ else { // group parsed, Names waiting
WORD wNickLen;
unpackWord(&pBuffer, &wNickLen);
nLen -= 2;
- if (nLen >= wNickLen)
- {
+ if (nLen >= wNickLen) {
WORD wNickTLV, wNickTLVLen;
char *pNick = NULL;
unpackTypedTLV(pBuffer, wNickLen, 0x01, &wNickTLV, &wNickTLVLen, (LPBYTE*)&pNick);
- if (wNickTLV == 0x01)
- {
+ if (wNickTLV == 0x01) {
SAFE_FREE(&contacts[iContact]->hdr.nick);
contacts[iContact]->hdr.nick = utf8_to_tchar(pNick);
}
@@ -1190,18 +1041,15 @@ void CIcqProto::handleRecvServMsgContacts(BYTE *buf, WORD wLen, DWORD dwUin, cha }
if (!valid)
- {
debugLogA("Malformed '%s' message", "contacts");
- }
- else
- {
+ else {
int bAdded;
hContact = HContactFromUID(dwUin, szUID, &bAdded);
// ack the message
icq_sendContactsAck(dwUin, szUID, dwID1, dwID2);
- PROTORECVEVENT pre = {0};
+ PROTORECVEVENT pre = { 0 };
pre.timestamp = (DWORD)time(NULL);
pre.szMessage = (char *)contacts;
pre.lParam = nContacts;
@@ -1209,8 +1057,7 @@ void CIcqProto::handleRecvServMsgContacts(BYTE *buf, WORD wLen, DWORD dwUin, cha ProtoChainRecv(hContact, PSR_CONTACTS, 0, (LPARAM)&pre);
}
- for (int i = 0; i < iContact; i++)
- {
+ for (int i = 0; i < iContact; i++) {
SAFE_FREE(&contacts[i]->hdr.id);
SAFE_FREE(&contacts[i]->hdr.nick);
SAFE_FREE((void**)&contacts[i]);
@@ -1222,13 +1069,10 @@ void CIcqProto::handleRecvServMsgContacts(BYTE *buf, WORD wLen, DWORD dwUin, cha // Clean up
disposeChain(&chain);
}
- else if (wCommand == 1)
- {
+ else if (wCommand == 1) {
debugLogA("Cannot handle abort messages yet... :(");
- return;
}
- else if (wCommand == 2)
- { // acknowledgement
+ else if (wCommand == 2) { // acknowledgement
DWORD dwCookie;
MCONTACT hCookieContact;
if (FindMessageCookie(dwID1, dwID2, &dwCookie, &hCookieContact, NULL)) {
@@ -1243,7 +1087,6 @@ void CIcqProto::handleRecvServMsgContacts(BYTE *buf, WORD wLen, DWORD dwUin, cha }
}
-
void CIcqProto::handleRecvServMsgType4(BYTE *buf, WORD wLen, DWORD dwUin, char *szUID, DWORD dwMsgID1, DWORD dwMsgID2, DWORD dwRef)
{
WORD wTLVType;
@@ -1251,8 +1094,7 @@ void CIcqProto::handleRecvServMsgType4(BYTE *buf, WORD wLen, DWORD dwUin, char * BYTE* pDataBuf;
DWORD dwUin2;
- if (wLen < 2)
- {
+ if (wLen < 2) {
debugLogA("Message (format %u) - Ignoring empty message", 4);
return;
}
@@ -1262,8 +1104,7 @@ void CIcqProto::handleRecvServMsgType4(BYTE *buf, WORD wLen, DWORD dwUin, char * debugLogA("Message (format %u) - UID: %s", 4, strUID(dwUin, szUID));
// It must be TLV(5)
- if (wTLVType == 5)
- {
+ if (wTLVType == 5) {
BYTE bMsgType;
BYTE bFlags;
BYTE* pmsg = pDataBuf;
@@ -1272,41 +1113,33 @@ void CIcqProto::handleRecvServMsgType4(BYTE *buf, WORD wLen, DWORD dwUin, char * unpackLEDWord(&pmsg, &dwUin2);
- if (dwUin2 == dwUin)
- {
+ if (dwUin2 == dwUin) {
unpackByte(&pmsg, &bMsgType);
unpackByte(&pmsg, &bFlags);
unpackLEWord(&pmsg, &wMsgLen);
if (bMsgType == 0 && wMsgLen == 1)
- {
debugLogA("User %u probably checks his ignore state.", dwUin);
- }
- else
- {
+ else {
cookie_offline_messages *cookie;
DWORD dwRecvTime = (DWORD)time(NULL);
- if (!(dwRef & 0x80000000) && FindCookie(dwRef, NULL, (void**)&cookie))
- {
+ if (!(dwRef & 0x80000000) && FindCookie(dwRef, NULL, (void**)&cookie)) {
WORD wTimeTLVType, wTimeTLVLen;
BYTE *pTimeTLV = NULL;
cookie->nMessages++;
unpackTypedTLV(buf, wLen, 0x16, &wTimeTLVType, &wTimeTLVLen, &pTimeTLV);
- if (pTimeTLV && wTimeTLVType == 0x16 && wTimeTLVLen == 4)
- { // found Offline timestamp
+ if (pTimeTLV && wTimeTLVType == 0x16 && wTimeTLVLen == 4) { // found Offline timestamp
BYTE *pBuf = pTimeTLV;
-
unpackDWord(&pBuf, &dwRecvTime);
debugLogA("Message (format %u) - Offline timestamp is %s", 4, time2text(dwRecvTime));
}
SAFE_FREE((void**)&pTimeTLV);
}
- if (bMsgType == MTYPE_PLUGIN)
- {
+ if (bMsgType == MTYPE_PLUGIN) {
WORD wLen = wTLVLen - 8;
int typeId;
@@ -1315,8 +1148,7 @@ void CIcqProto::handleRecvServMsgType4(BYTE *buf, WORD wLen, DWORD dwUin, char * pmsg += wMsgLen;
wLen -= wMsgLen;
- if (unpackPluginTypeId(&pmsg, &wLen, &typeId, NULL, FALSE) && wLen > 8)
- {
+ if (unpackPluginTypeId(&pmsg, &wLen, &typeId, NULL, FALSE) && wLen > 8) {
DWORD dwLengthToEnd;
DWORD dwDataLen;
@@ -1330,33 +1162,22 @@ void CIcqProto::handleRecvServMsgType4(BYTE *buf, WORD wLen, DWORD dwUin, char * if (dwDataLen > wLen)
dwDataLen = wLen;
- if (typeId)
- {
+ if (typeId) {
uid_str szUID;
handleMessageTypes(dwUin, szUID, dwRecvTime, dwMsgID1, dwMsgID2, 0, 0, typeId, bFlags, 0, dwLengthToEnd, (WORD)dwDataLen, (char*)pmsg, MTF_PLUGIN, NULL);
}
- else
- {
- debugLogA("Unsupported plugin message type %d", typeId);
- }
+ else debugLogA("Unsupported plugin message type %d", typeId);
}
}
- else
- {
+ else {
uid_str szUID;
handleMessageTypes(dwUin, szUID, dwRecvTime, dwMsgID1, dwMsgID2, 0, 0, bMsgType, bFlags, 0, wTLVLen - 8, wMsgLen, (char*)pmsg, 0, NULL);
}
}
}
- else
- {
- debugLogA("Ignoring spoofed TYPE4 message thru server from %d", dwUin);
- }
- }
- else
- {
- debugLogA("Unsupported TLV (%u) in message (format %u)", wTLVType, 4);
+ else debugLogA("Ignoring spoofed TYPE4 message thru server from %d", dwUin);
}
+ else debugLogA("Unsupported TLV (%u) in message (format %u)", wTLVType, 4);
SAFE_FREE((void**)&pDataBuf);
}
@@ -1370,67 +1191,50 @@ static int TypeGUIDToTypeId(DWORD dwGuid1, DWORD dwGuid2, DWORD dwGuid3, DWORD d {
int nTypeID = MTYPE_UNKNOWN;
- if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_STATUSMSGEXT))
- {
+ if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_STATUSMSGEXT)) {
nTypeID = MTYPE_STATUSMSGEXT;
}
- else if (wType==MGTYPE_UNDEFINED)
- {
- if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, PSIG_MESSAGE))
- { // icq6 message ack
+ else if (wType == MGTYPE_UNDEFINED) {
+ if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, PSIG_MESSAGE)) { // icq6 message ack
nTypeID = MTYPE_PLAIN;
}
}
- else if (wType==MGTYPE_STANDARD_SEND)
- {
- if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_WEBURL))
- {
+ else if (wType == MGTYPE_STANDARD_SEND) {
+ if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_WEBURL)) {
nTypeID = MTYPE_URL;
}
- else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_CONTACTS))
- {
+ else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_CONTACTS)) {
nTypeID = MTYPE_CONTACTS;
}
- else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_CHAT))
- {
+ else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_CHAT)) {
nTypeID = MTYPE_CHAT;
}
- else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_FILE))
- {
+ else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_FILE)) {
nTypeID = MTYPE_FILEREQ;
}
- else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_GREETING_CARD))
- {
+ else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_GREETING_CARD)) {
nTypeID = MTYPE_GREETINGCARD;
}
- else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_MESSAGE))
- {
+ else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_MESSAGE)) {
nTypeID = MTYPE_MESSAGE;
}
- else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_SMS_MESSAGE))
- {
+ else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_SMS_MESSAGE)) {
nTypeID = MTYPE_SMS_MESSAGE;
}
}
- else if (wType==MGTYPE_CONTACTS_REQUEST)
- {
- if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_CONTACTS))
- {
+ else if (wType == MGTYPE_CONTACTS_REQUEST) {
+ if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_CONTACTS)) {
nTypeID = MTYPE_REQUESTCONTACTS;
}
- else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_XTRAZ_SCRIPT))
- {
+ else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_XTRAZ_SCRIPT)) {
nTypeID = MTYPE_SCRIPT_DATA;
}
}
- else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_XTRAZ_SCRIPT))
- {
- if (wType==MGTYPE_SCRIPT_INVITATION)
- {
+ else if (CompareGUIDs(dwGuid1, dwGuid2, dwGuid3, dwGuid4, MGTYPE_XTRAZ_SCRIPT)) {
+ if (wType == MGTYPE_SCRIPT_INVITATION) {
nTypeID = MTYPE_SCRIPT_INVITATION;
}
- else if (wType==MGTYPE_SCRIPT_NOTIFY)
- {
+ else if (wType == MGTYPE_SCRIPT_NOTIFY) {
nTypeID = MTYPE_SCRIPT_NOTIFY;
}
}
@@ -1444,7 +1248,7 @@ int CIcqProto::unpackPluginTypeId(BYTE **pBuffer, WORD *pwLen, int *pTypeId, WOR WORD wLen = *pwLen;
WORD wInfoLen;
DWORD dwPluginNameLen;
- DWORD q1,q2,q3,q4;
+ DWORD q1, q2, q3, q4;
WORD qt;
if (wLen < 24)
@@ -1464,8 +1268,7 @@ int CIcqProto::unpackPluginTypeId(BYTE **pBuffer, WORD *pwLen, int *pTypeId, WOR unpackLEDWord(pBuffer, &dwPluginNameLen);
wLen -= 4;
- if (dwPluginNameLen > wLen)
- { // check for malformed plugin name
+ if (dwPluginNameLen > wLen) { // check for malformed plugin name
dwPluginNameLen = wLen;
NetLog_Uni(bThruDC, "Warning: malformed size of plugin name.");
}
@@ -1478,15 +1281,13 @@ int CIcqProto::unpackPluginTypeId(BYTE **pBuffer, WORD *pwLen, int *pTypeId, WOR int typeId = TypeGUIDToTypeId(q1, q2, q3, q4, qt);
if (!typeId)
- NetLog_Uni(bThruDC, "Error: Unknown type {%08x-%08x-%08x-%08x:%04x}: %s", q1,q2,q3,q4,qt, szPluginName);
+ NetLog_Uni(bThruDC, "Error: Unknown type {%08x-%08x-%08x-%08x:%04x}: %s", q1, q2, q3, q4, qt, szPluginName);
- if (wInfoLen >= 22 + dwPluginNameLen)
- { // sanity checking
+ if (wInfoLen >= 22 + dwPluginNameLen) { // sanity checking
wInfoLen -= (WORD)(22 + dwPluginNameLen);
// check if enough data is available - skip remaining bytes of info block
- if (wLen >= wInfoLen)
- {
+ if (wLen >= wInfoLen) {
*pBuffer += wInfoLen;
wLen -= wInfoLen;
}
@@ -1501,8 +1302,7 @@ int CIcqProto::unpackPluginTypeId(BYTE **pBuffer, WORD *pwLen, int *pTypeId, WOR int getPluginTypeIdLen(int nTypeID)
{
- switch (nTypeID)
- {
+ switch (nTypeID) {
case MTYPE_SCRIPT_NOTIFY:
return 0x51;
@@ -1527,8 +1327,7 @@ int getPluginTypeIdLen(int nTypeID) void packPluginTypeId(icq_packet *packet, int nTypeID)
{
- switch (nTypeID)
- {
+ switch (nTypeID) {
case MTYPE_SCRIPT_NOTIFY:
packLEWord(packet, 0x04f); // Length
@@ -1632,7 +1431,7 @@ void CIcqProto::handleStatusMsgReply(const char *szPrefix, MCONTACT hContact, DW }
// it is probably UTF-8 status reply
- PROTORECVEVENT pre = {0};
+ PROTORECVEVENT pre = { 0 };
if (wVersion >= 9)
if (UTF8_IsValid(szMsg))
pre.flags |= PREF_UTF;
@@ -1646,23 +1445,20 @@ void CIcqProto::handleStatusMsgReply(const char *szPrefix, MCONTACT hContact, DW HANDLE CIcqProto::handleMessageAck(DWORD dwUin, char *szUID, WORD wCookie, WORD wVersion, int type, WORD wMsgLen, PBYTE buf, BYTE bFlags, int nMsgFlags)
{
- if (bFlags == 3)
- {
+ if (bFlags == 3) {
MCONTACT hCookieContact;
cookie_message_data *pCookieData = NULL;
MCONTACT hContact = HContactFromUID(dwUin, szUID, NULL);
- if (!FindCookie(wCookie, &hCookieContact, (void**)&pCookieData))
- {
+ if (!FindCookie(wCookie, &hCookieContact, (void**)&pCookieData)) {
debugLogA("%sIgnoring unrequested status message from %u", "handleMessageAck: ", dwUin);
ReleaseCookie(wCookie);
return INVALID_HANDLE_VALUE;
}
- if (hContact != hCookieContact)
- {
+ if (hContact != hCookieContact) {
debugLogA("%sAck Contact does not match Cookie Contact(0x%x != 0x%x)", "handleMessageAck: ", hContact, hCookieContact);
ReleaseCookie(wCookie);
@@ -1672,11 +1468,8 @@ HANDLE CIcqProto::handleMessageAck(DWORD dwUin, char *szUID, WORD wCookie, WORD handleStatusMsgReply("handleMessageAck: ", hContact, dwUin, wVersion, type, wCookie, (char*)buf, nMsgFlags);
}
- else
- {
- // Should not happen
+ else // Should not happen
debugLogA("%sIgnored type %u ack message (this should not happen)", "handleMessageAck: ", type);
- }
return INVALID_HANDLE_VALUE;
}
@@ -1685,18 +1478,14 @@ HANDLE CIcqProto::handleMessageAck(DWORD dwUin, char *szUID, WORD wCookie, WORD /* this function send all acks from handleMessageTypes */
void CIcqProto::sendMessageTypesAck(MCONTACT hContact, int bUnicode, message_ack_params *pArgs)
{
- if (pArgs)
- {
+ if (pArgs) {
if ((pArgs->msgType == MTYPE_PLAIN && !CallService(MS_IGNORE_ISIGNORED, hContact, IGNOREEVENT_MESSAGE))
- || (pArgs->msgType == MTYPE_URL && !CallService(MS_IGNORE_ISIGNORED, hContact, IGNOREEVENT_URL))
- || pArgs->msgType == MTYPE_CONTACTS)
- {
- if (pArgs->bType == MAT_SERVER_ADVANCED)
- { // Only ack message packets
+ || (pArgs->msgType == MTYPE_URL && !CallService(MS_IGNORE_ISIGNORED, hContact, IGNOREEVENT_URL))
+ || pArgs->msgType == MTYPE_CONTACTS) {
+ if (pArgs->bType == MAT_SERVER_ADVANCED) { // Only ack message packets
icq_sendAdvancedMsgAck(pArgs->dwUin, pArgs->dwMsgID1, pArgs->dwMsgID2, pArgs->wCookie, (BYTE)pArgs->msgType, pArgs->bFlags);
}
- else if (pArgs->bType == MAT_DIRECT)
- { // Send acknowledgement
+ else if (pArgs->bType == MAT_DIRECT) { // Send acknowledgement
icq_sendDirectMsgAck(pArgs->pDC, pArgs->wCookie, (BYTE)pArgs->msgType, pArgs->bFlags, bUnicode ? (char *)CAP_UTF8MSGS : NULL);
}
}
@@ -1712,22 +1501,18 @@ void CIcqProto::handleMessageTypes(DWORD dwUin, char *szUID, DWORD dwTimestamp, BOOL bThruDC = (nMsgFlags & MTF_DIRECT) == MTF_DIRECT;
int bAdded;
-
- if (dwDataLen < wMsgLen)
- {
+ if (dwDataLen < wMsgLen) {
NetLog_Uni(bThruDC, "Ignoring overflowed message");
return;
}
- if (wAckType == 2)
- {
+ if (wAckType == 2) {
handleMessageAck(dwUin, szUID, wCookie, wVersion, type, wMsgLen, (LPBYTE)pMsg, (BYTE)flags, nMsgFlags);
return;
}
char *szMsg = (char *)SAFE_MALLOC(wMsgLen + 1);
- if (wMsgLen > 0)
- {
+ if (wMsgLen > 0) {
memcpy(szMsg, pMsg, wMsgLen);
pMsg += wMsgLen;
dwDataLen -= wMsgLen;
@@ -1735,16 +1520,13 @@ void CIcqProto::handleMessageTypes(DWORD dwUin, char *szUID, DWORD dwTimestamp, szMsg[wMsgLen] = '\0';
- char* pszMsgField[2*MAX_CONTACTSSEND+1];
+ char *pszMsgField[2 * MAX_CONTACTSSEND + 1];
int nMsgFields = 0;
pszMsgField[0] = szMsg;
- if (type == MTYPE_URL || type == MTYPE_AUTHREQ || type == MTYPE_ADDED || type == MTYPE_CONTACTS || type == MTYPE_EEXPRESS || type == MTYPE_WWP)
- {
- for (char *pszMsg=szMsg, nMsgFields=1; *pszMsg; pszMsg++)
- {
- if ((BYTE)*pszMsg == 0xFE)
- {
+ if (type == MTYPE_URL || type == MTYPE_AUTHREQ || type == MTYPE_ADDED || type == MTYPE_CONTACTS || type == MTYPE_EEXPRESS || type == MTYPE_WWP) {
+ for (char *pszMsg = szMsg, nMsgFields = 1; *pszMsg; pszMsg++) {
+ if ((BYTE)*pszMsg == 0xFE) {
*pszMsg = '\0';
pszMsgField[nMsgFields++] = pszMsg + 1;
if (nMsgFields >= SIZEOF(pszMsgField))
@@ -1754,23 +1536,19 @@ void CIcqProto::handleMessageTypes(DWORD dwUin, char *szUID, DWORD dwTimestamp, }
switch (type) {
-
case MTYPE_PLAIN: /* plain message */
{
- PROTORECVEVENT pre = {0};
+ PROTORECVEVENT pre = { 0 };
// Check if this message is marked as UTF8 encoded
- if (dwDataLen > 12)
- {
+ if (dwDataLen > 12) {
DWORD dwGuidLen = 0;
int bDoubleMsg = 0;
- if (bThruDC)
- {
+ if (bThruDC) {
DWORD dwExtraLen = *(DWORD*)pMsg;
- if (dwExtraLen < dwDataLen && !strncmp(szMsg, "{\\rtf", 5))
- { // it is icq5 sending us crap, get real message from it
+ if (dwExtraLen < dwDataLen && !strncmp(szMsg, "{\\rtf", 5)) { // it is icq5 sending us crap, get real message from it
WCHAR* usMsg = (WCHAR*)_alloca((dwExtraLen + 1)*sizeof(WCHAR));
// make sure it is null-terminated
wcsncpy(usMsg, (WCHAR*)(pMsg + 4), dwExtraLen);
@@ -1785,22 +1563,18 @@ void CIcqProto::handleMessageTypes(DWORD dwUin, char *szUID, DWORD dwTimestamp, }
}
- if (!bDoubleMsg)
- {
- dwGuidLen = *(DWORD*)(pMsg+8);
+ if (!bDoubleMsg) {
+ dwGuidLen = *(DWORD*)(pMsg + 8);
dwDataLen -= 12;
pMsg += 12;
}
- while ((dwGuidLen >= 38) && (dwDataLen >= dwGuidLen))
- {
- if (!strncmp(pMsg, CAP_UTF8MSGS, 38))
- { // Found UTF8 cap, convert message to ansi
+ while ((dwGuidLen >= 38) && (dwDataLen >= dwGuidLen)) {
+ if (!strncmp(pMsg, CAP_UTF8MSGS, 38)) { // Found UTF8 cap, convert message to ansi
pre.flags = PREF_UTF;
break;
}
- else if (!strncmp(pMsg, CAP_RTFMSGS, 38))
- { // Found RichText cap
+ else if (!strncmp(pMsg, CAP_RTFMSGS, 38)) { // Found RichText cap
NetLog_Uni(bThruDC, "Warning: User %u sends us RichText.", dwUin);
break;
}
@@ -1814,11 +1588,9 @@ void CIcqProto::handleMessageTypes(DWORD dwUin, char *szUID, DWORD dwTimestamp, hContact = HContactFromUIN(dwUin, &bAdded);
sendMessageTypesAck(hContact, pre.flags & PREF_UTF, pAckParams);
- if (!pre.flags && !IsUSASCII(szMsg, strlennull(szMsg)))
- { // message is Ansi and contains national characters, create Unicode part by codepage
+ if (!pre.flags && !IsUSASCII(szMsg, strlennull(szMsg))) { // message is Ansi and contains national characters, create Unicode part by codepage
char *usMsg = convertMsgToUserSpecificUtf(hContact, szMsg);
- if (usMsg)
- {
+ if (usMsg) {
SAFE_FREE(&szMsg);
szMsg = (char*)usMsg;
pre.flags = PREF_UTF;
@@ -1832,18 +1604,14 @@ void CIcqProto::handleMessageTypes(DWORD dwUin, char *szUID, DWORD dwTimestamp, break;
case MTYPE_URL:
- {
- PROTORECVEVENT pre = {0};
-
- if (nMsgFields < 2)
- {
- NetLog_Uni(bThruDC, "Malformed '%s' message", "URL");
- break;
- }
-
- hContact = HContactFromUIN(dwUin, &bAdded);
- sendMessageTypesAck(hContact, 0, pAckParams);
+ if (nMsgFields < 2) {
+ NetLog_Uni(bThruDC, "Malformed '%s' message", "URL");
+ break;
+ }
+ hContact = HContactFromUIN(dwUin, &bAdded);
+ sendMessageTypesAck(hContact, 0, pAckParams);
+ {
char *szTitle = ICQTranslateUtf(LPGEN("Incoming URL:"));
char *szDataDescr = ansi_to_utf8(pszMsgField[0]);
char *szDataUrl = ansi_to_utf8(pszMsgField[1]);
@@ -1857,6 +1625,7 @@ void CIcqProto::handleMessageTypes(DWORD dwUin, char *szUID, DWORD dwTimestamp, SAFE_FREE(&szDataDescr);
SAFE_FREE(&szDataUrl);
+ PROTORECVEVENT pre = { 0 };
pre.timestamp = dwTimestamp;
pre.szMessage = (char *)szBlob;
pre.flags = PREF_UTF;
@@ -1873,9 +1642,9 @@ void CIcqProto::handleMessageTypes(DWORD dwUin, char *szUID, DWORD dwTimestamp, break;
}
{
- PROTORECVEVENT pre = {0};
- pre.timestamp=dwTimestamp;
- pre.lParam=sizeof(DWORD)*2+strlennull(pszMsgField[0])+strlennull(pszMsgField[1])+strlennull(pszMsgField[2])+strlennull(pszMsgField[3])+strlennull(pszMsgField[5])+5;
+ PROTORECVEVENT pre = { 0 };
+ pre.timestamp = dwTimestamp;
+ pre.lParam = sizeof(DWORD) * 2 + strlennull(pszMsgField[0]) + strlennull(pszMsgField[1]) + strlennull(pszMsgField[2]) + strlennull(pszMsgField[3]) + strlennull(pszMsgField[5]) + 5;
// blob is: uin(DWORD), hcontact(HANDLE), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ), reason(ASCIIZ)
char *szBlob, *pCurBlob = szBlob = (char *)_alloca(pre.lParam);
@@ -1916,61 +1685,52 @@ void CIcqProto::handleMessageTypes(DWORD dwUin, char *szUID, DWORD dwTimestamp, {
char* pszNContactsEnd;
int nContacts;
- int i;
-
- if (nMsgFields < 3
- || (nContacts = strtol(pszMsgField[0], &pszNContactsEnd, 10)) == 0
- || pszNContactsEnd - pszMsgField[0] != (int)strlennull(pszMsgField[0])
- || nMsgFields < nContacts * 2 + 1)
+ if (nMsgFields < 3 ||
+ (nContacts = strtol(pszMsgField[0], &pszNContactsEnd, 10)) == 0 ||
+ pszNContactsEnd - pszMsgField[0] != (int)strlennull(pszMsgField[0]) ||
+ nMsgFields < nContacts * 2 + 1)
{
NetLog_Uni(bThruDC, "Malformed '%s' message", "contacts");
- break;
}
-
- int valid = 1;
- ICQSEARCHRESULT** isrList = (ICQSEARCHRESULT**)_alloca(nContacts * sizeof(ICQSEARCHRESULT*));
- for (i = 0; i < nContacts; i++)
- {
- isrList[i] = (ICQSEARCHRESULT*)SAFE_MALLOC(sizeof(ICQSEARCHRESULT));
- isrList[i]->hdr.cbSize = sizeof(ICQSEARCHRESULT);
- isrList[i]->hdr.flags = PSR_TCHAR;
- if (IsStringUIN(pszMsgField[1 + i * 2]))
- { // icq contact
- isrList[i]->uin = atoi(pszMsgField[1 + i * 2]);
- if (isrList[i]->uin == 0)
- valid = 0;
- }
- else
- { // aim contact
- if (!strlennull(pszMsgField[1 + i * 2]))
- valid = 0;
+ else {
+ int valid = 1;
+ ICQSEARCHRESULT** isrList = (ICQSEARCHRESULT**)_alloca(nContacts * sizeof(ICQSEARCHRESULT*));
+ for (int i = 0; i < nContacts; i++) {
+ isrList[i] = (ICQSEARCHRESULT*)SAFE_MALLOC(sizeof(ICQSEARCHRESULT));
+ isrList[i]->hdr.cbSize = sizeof(ICQSEARCHRESULT);
+ isrList[i]->hdr.flags = PSR_TCHAR;
+ if (IsStringUIN(pszMsgField[1 + i * 2])) { // icq contact
+ isrList[i]->uin = atoi(pszMsgField[1 + i * 2]);
+ if (isrList[i]->uin == 0)
+ valid = 0;
+ }
+ else { // aim contact
+ if (!strlennull(pszMsgField[1 + i * 2]))
+ valid = 0;
+ }
+ isrList[i]->hdr.id = ansi_to_tchar(pszMsgField[1 + i * 2]);
+ isrList[i]->hdr.nick = ansi_to_tchar(pszMsgField[2 + i * 2]);
}
- isrList[i]->hdr.id = ansi_to_tchar(pszMsgField[1 + i * 2]);
- isrList[i]->hdr.nick = ansi_to_tchar(pszMsgField[2 + i * 2]);
- }
-
- if (!valid)
- {
- NetLog_Uni(bThruDC, "Malformed '%s' message", "contacts");
- }
- else
- {
- hContact = HContactFromUIN(dwUin, &bAdded);
- sendMessageTypesAck(hContact, 0, pAckParams);
- PROTORECVEVENT pre = {0};
- pre.timestamp = dwTimestamp;
- pre.szMessage = (char *)isrList;
- pre.lParam = nContacts;
- pre.flags = PREF_TCHAR;
- ProtoChainRecv(hContact, PSR_CONTACTS, 0, (LPARAM)&pre);
- }
+ if (!valid)
+ NetLog_Uni(bThruDC, "Malformed '%s' message", "contacts");
+ else {
+ hContact = HContactFromUIN(dwUin, &bAdded);
+ sendMessageTypesAck(hContact, 0, pAckParams);
+
+ PROTORECVEVENT pre = { 0 };
+ pre.timestamp = dwTimestamp;
+ pre.szMessage = (char *)isrList;
+ pre.lParam = nContacts;
+ pre.flags = PREF_TCHAR;
+ ProtoChainRecv(hContact, PSR_CONTACTS, 0, (LPARAM)&pre);
+ }
- for (i = 0; i < nContacts; i++)
- {
- SAFE_FREE(&isrList[i]->hdr.id);
- SAFE_FREE(&isrList[i]->hdr.nick);
- SAFE_FREE((void**)&isrList[i]);
+ for (int i = 0; i < nContacts; i++) {
+ SAFE_FREE(&isrList[i]->hdr.id);
+ SAFE_FREE(&isrList[i]->hdr.nick);
+ SAFE_FREE((void**)&isrList[i]);
+ }
}
}
break;
@@ -1978,17 +1738,15 @@ void CIcqProto::handleMessageTypes(DWORD dwUin, char *szUID, DWORD dwTimestamp, case MTYPE_PLUGIN: // FIXME: this should be removed - it is never called
hContact = NULL;
- switch(dwUin)
- {
+ switch (dwUin) {
case 1111: /* icqmail 'you've got mail' - not processed */
break;
}
break;
case MTYPE_SMS_MESSAGE:
- /* it's a SMS message from a mobile - broadcast to SMS plugin */
- if (dwUin != 1002)
- {
+ // it's a SMS message from a mobile - broadcast to SMS plugin
+ if (dwUin != 1002) {
NetLog_Uni(bThruDC, "Malformed '%s' message", "SMS Mobile");
break;
}
@@ -1998,54 +1756,38 @@ void CIcqProto::handleMessageTypes(DWORD dwUin, char *szUID, DWORD dwTimestamp, break;
case MTYPE_STATUSMSGEXT:
- /* it's either extended StatusMsg reply from icq2003b or a IcqWebMessage */
+ // it's either extended StatusMsg reply from icq2003b or a IcqWebMessage
if (dwUin == 1003)
- {
debugLogA("Received ICQWebMessage - NOT SUPPORTED");
- }
break;
case MTYPE_WWP:
- /* format: fromname FE FE FE fromemail FE unknownbyte FE 'Sender IP: xxx.xxx.xxx.xxx' 0D 0A body */
- {
- DWORD cbBlob;
- PBYTE pBlob, pCurBlob;
-
- if (nMsgFields < 6)
- {
- debugLogA("Malformed '%s' message", "web pager");
- break;
- }
-
- /*blob is: body(ASCIIZ), name(ASCIIZ), email(ASCIIZ) */
- cbBlob=strlennull(pszMsgField[0])+strlennull(pszMsgField[3])+strlennull(pszMsgField[5])+3;
- pCurBlob=pBlob=(PBYTE)_alloca(cbBlob);
- strcpy((char *)pCurBlob,pszMsgField[5]); pCurBlob+=strlennull((char *)pCurBlob)+1;
- strcpy((char *)pCurBlob,pszMsgField[0]); pCurBlob+=strlennull((char *)pCurBlob)+1;
- strcpy((char *)pCurBlob,pszMsgField[3]);
+ // format: fromname FE FE FE fromemail FE unknownbyte FE 'Sender IP: xxx.xxx.xxx.xxx' 0D 0A body
+ if (nMsgFields < 6)
+ debugLogA("Malformed '%s' message", "web pager");
+ else {
+ // blob is: body(ASCIIZ), name(ASCIIZ), email(ASCIIZ)
+ DWORD cbBlob = strlennull(pszMsgField[0]) + strlennull(pszMsgField[3]) + strlennull(pszMsgField[5]) + 3;
+ PBYTE pBlob, pCurBlob = pBlob = (PBYTE)_alloca(cbBlob);
+ strcpy((char *)pCurBlob, pszMsgField[5]); pCurBlob += strlennull((char *)pCurBlob) + 1;
+ strcpy((char *)pCurBlob, pszMsgField[0]); pCurBlob += strlennull((char *)pCurBlob) + 1;
+ strcpy((char *)pCurBlob, pszMsgField[3]);
AddEvent(NULL, ICQEVENTTYPE_WEBPAGER, dwTimestamp, 0, cbBlob, pBlob);
}
break;
case MTYPE_EEXPRESS:
- /* format: fromname FE FE FE fromemail FE unknownbyte FE body */
- {
- DWORD cbBlob;
- PBYTE pBlob, pCurBlob;
-
- if (nMsgFields < 6)
- {
- debugLogA("Malformed '%s' message", "e-mail express");
- break;
- }
-
- /*blob is: body(ASCIIZ), name(ASCIIZ), email(ASCIIZ) */
- cbBlob=strlennull(pszMsgField[0])+strlennull(pszMsgField[3])+strlennull(pszMsgField[5])+3;
- pCurBlob=pBlob=(PBYTE)_alloca(cbBlob);
- strcpy((char *)pCurBlob,pszMsgField[5]); pCurBlob+=strlennull((char *)pCurBlob)+1;
- strcpy((char *)pCurBlob,pszMsgField[0]); pCurBlob+=strlennull((char *)pCurBlob)+1;
- strcpy((char *)pCurBlob,pszMsgField[3]);
+ // format: fromname FE FE FE fromemail FE unknownbyte FE body
+ if (nMsgFields < 6)
+ debugLogA("Malformed '%s' message", "e-mail express");
+ else {
+ // blob is: body(ASCIIZ), name(ASCIIZ), email(ASCIIZ)
+ DWORD cbBlob = strlennull(pszMsgField[0]) + strlennull(pszMsgField[3]) + strlennull(pszMsgField[5]) + 3;
+ PBYTE pBlob, pCurBlob = pBlob = (PBYTE)_alloca(cbBlob);
+ strcpy((char *)pCurBlob, pszMsgField[5]); pCurBlob += strlennull((char *)pCurBlob) + 1;
+ strcpy((char *)pCurBlob, pszMsgField[0]); pCurBlob += strlennull((char *)pCurBlob) + 1;
+ strcpy((char *)pCurBlob, pszMsgField[3]);
AddEvent(NULL, ICQEVENTTYPE_EMAILEXPRESS, dwTimestamp, 0, cbBlob, pBlob);
}
@@ -2085,72 +1827,71 @@ void CIcqProto::handleMessageTypes(DWORD dwUin, char *szUID, DWORD dwTimestamp, case MTYPE_AUTONA:
case MTYPE_AUTODND:
case MTYPE_AUTOFFC:
- {
- char **szMsg = MirandaStatusToAwayMsg(AwayMsgTypeToStatus(type));
- if (szMsg)
+ {
+ char **szMsg = MirandaStatusToAwayMsg(AwayMsgTypeToStatus(type));
+ if (szMsg) {
+ struct rates_status_message_response : public rates_queue_item
{
- struct rates_status_message_response: public rates_queue_item
+ protected:
+ virtual rates_queue_item* copyItem(rates_queue_item *aDest = NULL)
{
- protected:
- virtual rates_queue_item* copyItem(rates_queue_item *aDest = NULL)
- {
- rates_status_message_response *pDest = (rates_status_message_response*)aDest;
- if (!pDest)
- pDest = new rates_status_message_response(ppro, wGroup);
-
- pDest->bExtended = bExtended;
- pDest->dwMsgID1 = dwMsgID1;
- pDest->dwMsgID2 = dwMsgID2;
- pDest->wCookie = wCookie;
- pDest->wVersion = wVersion;
- pDest->nMsgType = nMsgType;
-
- return rates_queue_item::copyItem(pDest);
- };
- public:
- rates_status_message_response(CIcqProto *ppro, WORD wGroup): rates_queue_item(ppro, wGroup) { };
- virtual ~rates_status_message_response() { };
-
- virtual void execute()
- {
- char **pszMsg = ppro->MirandaStatusToAwayMsg(AwayMsgTypeToStatus(nMsgType));
- if (bExtended)
- ppro->icq_sendAwayMsgReplyServExt(dwUin, szUid, dwMsgID1, dwMsgID2, wCookie, wVersion, nMsgType, pszMsg);
- else if (dwUin)
- ppro->icq_sendAwayMsgReplyServ(dwUin, dwMsgID1, dwMsgID2, wCookie, wVersion, (BYTE)nMsgType, pszMsg);
- else
- ppro->debugLogA("Error: Malformed UIN in packet");
- };
-
- BOOL bExtended;
- DWORD dwMsgID1;
- DWORD dwMsgID2;
- WORD wCookie;
- WORD wVersion;
- int nMsgType;
+ rates_status_message_response *pDest = (rates_status_message_response*)aDest;
+ if (!pDest)
+ pDest = new rates_status_message_response(ppro, wGroup);
+
+ pDest->bExtended = bExtended;
+ pDest->dwMsgID1 = dwMsgID1;
+ pDest->dwMsgID2 = dwMsgID2;
+ pDest->wCookie = wCookie;
+ pDest->wVersion = wVersion;
+ pDest->nMsgType = nMsgType;
+
+ return rates_queue_item::copyItem(pDest);
};
+ public:
+ rates_status_message_response(CIcqProto *ppro, WORD wGroup) : rates_queue_item(ppro, wGroup) {};
+ virtual ~rates_status_message_response() {};
- m_ratesMutex->Enter();
- WORD wGroup = m_rates->getGroupFromSNAC(ICQ_MSG_FAMILY, ICQ_MSG_RESPONSE);
- m_ratesMutex->Leave();
-
- rates_status_message_response rr(this, wGroup);
- rr.bExtended = (nMsgFlags & MTF_STATUS_EXTENDED) == MTF_STATUS_EXTENDED;
- rr.hContact = hContact;
- rr.dwUin = dwUin;
- rr.szUid = szUID;
- rr.dwMsgID1 = dwMsgID;
- rr.dwMsgID2 = dwMsgID2;
- rr.wCookie = wCookie;
- rr.wVersion = wVersion;
- rr.nMsgType = type;
-
- handleRateItem(&rr, RQT_RESPONSE);
- }
+ virtual void execute()
+ {
+ char **pszMsg = ppro->MirandaStatusToAwayMsg(AwayMsgTypeToStatus(nMsgType));
+ if (bExtended)
+ ppro->icq_sendAwayMsgReplyServExt(dwUin, szUid, dwMsgID1, dwMsgID2, wCookie, wVersion, nMsgType, pszMsg);
+ else if (dwUin)
+ ppro->icq_sendAwayMsgReplyServ(dwUin, dwMsgID1, dwMsgID2, wCookie, wVersion, (BYTE)nMsgType, pszMsg);
+ else
+ ppro->debugLogA("Error: Malformed UIN in packet");
+ };
- break;
+ BOOL bExtended;
+ DWORD dwMsgID1;
+ DWORD dwMsgID2;
+ WORD wCookie;
+ WORD wVersion;
+ int nMsgType;
+ };
+
+ m_ratesMutex->Enter();
+ WORD wGroup = m_rates->getGroupFromSNAC(ICQ_MSG_FAMILY, ICQ_MSG_RESPONSE);
+ m_ratesMutex->Leave();
+
+ rates_status_message_response rr(this, wGroup);
+ rr.bExtended = (nMsgFlags & MTF_STATUS_EXTENDED) == MTF_STATUS_EXTENDED;
+ rr.hContact = hContact;
+ rr.dwUin = dwUin;
+ rr.szUid = szUID;
+ rr.dwMsgID1 = dwMsgID;
+ rr.dwMsgID2 = dwMsgID2;
+ rr.wCookie = wCookie;
+ rr.wVersion = wVersion;
+ rr.nMsgType = type;
+
+ handleRateItem(&rr, RQT_RESPONSE);
}
+ break;
+ }
+
case MTYPE_FILEREQ: // Never happens
default:
NetLog_Uni(bThruDC, "Unprocessed message type %d", type);
@@ -2183,8 +1924,7 @@ void CIcqProto::handleRecvMsgResponse(BYTE *buf, WORD wLen, WORD wFlags, DWORD d unpackWord(&buf, &wMessageFormat);
wLen -= 2;
- if (wMessageFormat != 2)
- {
+ if (wMessageFormat != 2) {
debugLogA("SNAC(4.B) Unknown type");
return;
}
@@ -2254,8 +1994,7 @@ void CIcqProto::handleRecvMsgResponse(BYTE *buf, WORD wLen, WORD wFlags, DWORD d // use old reliable method
debugLogA("Warning: Invalid cookie in %s from (%u)", "message response", dwUin);
- if (pCookieData->bMessageType != MTYPE_AUTOAWAY && bFlags == 3)
- { // most probably a broken ack of some kind (e.g. from R&Q), try to fix that
+ if (pCookieData->bMessageType != MTYPE_AUTOAWAY && bFlags == 3) { // most probably a broken ack of some kind (e.g. from R&Q), try to fix that
bMsgType = pCookieData->bMessageType;
bFlags = 0;
@@ -2301,154 +2040,154 @@ void CIcqProto::handleRecvMsgResponse(BYTE *buf, WORD wLen, WORD wFlags, DWORD d switch (bMsgType) {
case MTYPE_FILEREQ:
- {
- char* szMsg;
- WORD wMsgLen;
-
- // Message length
- unpackLEWord(&buf, &wMsgLen);
- wLen -= 2;
- szMsg = (char *)_alloca(wMsgLen + 1);
- szMsg[wMsgLen] = '\0';
- if (wMsgLen > 0) {
- memcpy(szMsg, buf, wMsgLen);
- buf += wMsgLen;
- wLen -= wMsgLen;
- }
- handleFileAck(buf, wLen, dwUin, dwCookie, wStatus, szMsg);
- // No success protoack will be sent here, since all file requests
- // will have been 'sent' when the server returns its ack
- return;
+ {
+ char* szMsg;
+ WORD wMsgLen;
+
+ // Message length
+ unpackLEWord(&buf, &wMsgLen);
+ wLen -= 2;
+ szMsg = (char *)_alloca(wMsgLen + 1);
+ szMsg[wMsgLen] = '\0';
+ if (wMsgLen > 0) {
+ memcpy(szMsg, buf, wMsgLen);
+ buf += wMsgLen;
+ wLen -= wMsgLen;
}
+ handleFileAck(buf, wLen, dwUin, dwCookie, wStatus, szMsg);
+ // No success protoack will be sent here, since all file requests
+ // will have been 'sent' when the server returns its ack
+ return;
+ }
case MTYPE_PLUGIN:
- {
- WORD wMsgLen;
- DWORD dwLengthToEnd;
- DWORD dwDataLen;
- int typeId;
- WORD wFunctionId;
+ {
+ WORD wMsgLen;
+ DWORD dwLengthToEnd;
+ DWORD dwDataLen;
+ int typeId;
+ WORD wFunctionId;
- if (wLength != 0x1B) {
- debugLogA("Invalid Greeting %s", "message response");
+ if (wLength != 0x1B) {
+ debugLogA("Invalid Greeting %s", "message response");
- ReleaseCookie(dwCookie);
- return;
- }
+ ReleaseCookie(dwCookie);
+ return;
+ }
- debugLogA("Parsing Greeting %s", "message response");
+ debugLogA("Parsing Greeting %s", "message response");
- // Message
- unpackLEWord(&buf, &wMsgLen);
- wLen -= 2;
- buf += wMsgLen;
- wLen -= wMsgLen;
+ // Message
+ unpackLEWord(&buf, &wMsgLen);
+ wLen -= 2;
+ buf += wMsgLen;
+ wLen -= wMsgLen;
- // This packet is malformed. Possibly a file accept from Miranda IM 0.1.2.1
- if (wLen < 20) {
- ReleaseCookie(dwCookie);
- return;
- }
+ // This packet is malformed. Possibly a file accept from Miranda IM 0.1.2.1
+ if (wLen < 20) {
+ ReleaseCookie(dwCookie);
+ return;
+ }
- if (!unpackPluginTypeId(&buf, &wLen, &typeId, &wFunctionId, FALSE)) {
- ReleaseCookie(dwCookie);
- return;
- }
+ if (!unpackPluginTypeId(&buf, &wLen, &typeId, &wFunctionId, FALSE)) {
+ ReleaseCookie(dwCookie);
+ return;
+ }
- if (wLen < 4) {
- debugLogA("Error: Invalid greeting %s", "message response");
- ReleaseCookie(dwCookie);
- return;
- }
+ if (wLen < 4) {
+ debugLogA("Error: Invalid greeting %s", "message response");
+ ReleaseCookie(dwCookie);
+ return;
+ }
- // Length of remaining data
- unpackLEDWord(&buf, &dwLengthToEnd);
- wLen -= 4;
+ // Length of remaining data
+ unpackLEDWord(&buf, &dwLengthToEnd);
+ wLen -= 4;
- if (wLen >= 4 && dwLengthToEnd > 0)
- unpackLEDWord(&buf, &dwDataLen); // Length of message
- else
- dwDataLen = 0;
+ if (wLen >= 4 && dwLengthToEnd > 0)
+ unpackLEDWord(&buf, &dwDataLen); // Length of message
+ else
+ dwDataLen = 0;
- switch (typeId) {
- case MTYPE_PLAIN:
- if (pCookieData && pCookieData->bMessageType == MTYPE_AUTOAWAY && dwLengthToEnd >= 4) {
- // ICQ 6 invented this
- char *szMsg = (char*)_alloca(dwDataLen + 1);
+ switch (typeId) {
+ case MTYPE_PLAIN:
+ if (pCookieData && pCookieData->bMessageType == MTYPE_AUTOAWAY && dwLengthToEnd >= 4) {
+ // ICQ 6 invented this
+ char *szMsg = (char*)_alloca(dwDataLen + 1);
- if (dwDataLen > 0)
- memcpy(szMsg, buf, dwDataLen);
- szMsg[dwDataLen] = '\0';
- handleStatusMsgReply("SNAC(4.B) ", hContact, dwUin, wVersion, pCookieData->nAckType, (WORD)dwCookie, szMsg, 0);
+ if (dwDataLen > 0)
+ memcpy(szMsg, buf, dwDataLen);
+ szMsg[dwDataLen] = '\0';
+ handleStatusMsgReply("SNAC(4.B) ", hContact, dwUin, wVersion, pCookieData->nAckType, (WORD)dwCookie, szMsg, 0);
- ReleaseCookie(dwCookie);
- return;
- }
- ackType = ACKTYPE_MESSAGE;
- break;
+ ReleaseCookie(dwCookie);
+ return;
+ }
+ ackType = ACKTYPE_MESSAGE;
+ break;
- case MTYPE_URL:
- ackType = ACKTYPE_URL;
- break;
+ case MTYPE_URL:
+ ackType = ACKTYPE_URL;
+ break;
- case MTYPE_CONTACTS:
- ackType = ACKTYPE_CONTACTS;
- break;
+ case MTYPE_CONTACTS:
+ ackType = ACKTYPE_CONTACTS;
+ break;
- case MTYPE_FILEREQ:
- debugLogA("This is file ack");
- {
- char *szMsg = (char *)_alloca(dwDataLen + 1);
-
- if (dwDataLen > 0)
- memcpy(szMsg, buf, dwDataLen);
- szMsg[dwDataLen] = '\0';
- buf += dwDataLen;
- wLen -= (WORD)dwDataLen;
-
- handleFileAck(buf, wLen, dwUin, dwCookie, wStatus, szMsg);
- // No success protoack will be sent here, since all file requests
- // will have been 'sent' when the server returns its ack
- }
- return;
+ case MTYPE_FILEREQ:
+ debugLogA("This is file ack");
+ {
+ char *szMsg = (char *)_alloca(dwDataLen + 1);
- case MTYPE_SCRIPT_NOTIFY:
- {
- char *szMsg = (char*)_alloca(dwDataLen + 1);
+ if (dwDataLen > 0)
+ memcpy(szMsg, buf, dwDataLen);
+ szMsg[dwDataLen] = '\0';
+ buf += dwDataLen;
+ wLen -= (WORD)dwDataLen;
- if (dwDataLen > 0)
- memcpy(szMsg, buf, dwDataLen);
- szMsg[dwDataLen] = '\0';
+ handleFileAck(buf, wLen, dwUin, dwCookie, wStatus, szMsg);
+ // No success protoack will be sent here, since all file requests
+ // will have been 'sent' when the server returns its ack
+ }
+ return;
- handleXtrazNotifyResponse(dwUin, hContact, (WORD)dwCookie, szMsg, dwDataLen);
+ case MTYPE_SCRIPT_NOTIFY:
+ {
+ char *szMsg = (char*)_alloca(dwDataLen + 1);
- ReleaseCookie(dwCookie);
- }
- return;
+ if (dwDataLen > 0)
+ memcpy(szMsg, buf, dwDataLen);
+ szMsg[dwDataLen] = '\0';
- case MTYPE_STATUSMSGEXT:
- { // handle Away Message response (ICQ 6)
- char *szMsg = (char*)SAFE_MALLOC(dwDataLen + 1);
+ handleXtrazNotifyResponse(dwUin, hContact, (WORD)dwCookie, szMsg, dwDataLen);
- if (dwDataLen > 0)
- memcpy(szMsg, buf, dwDataLen);
- szMsg[dwDataLen] = '\0';
- szMsg = EliminateHtml(szMsg, dwDataLen);
+ ReleaseCookie(dwCookie);
+ }
+ return;
- handleStatusMsgReply("SNAC(4.B) ", hContact, dwUin, wVersion, pCookieData->nAckType, (WORD)dwCookie, szMsg, MTF_PLUGIN | MTF_STATUS_EXTENDED);
+ case MTYPE_STATUSMSGEXT:
+ { // handle Away Message response (ICQ 6)
+ char *szMsg = (char*)SAFE_MALLOC(dwDataLen + 1);
- SAFE_FREE(&szMsg);
+ if (dwDataLen > 0)
+ memcpy(szMsg, buf, dwDataLen);
+ szMsg[dwDataLen] = '\0';
+ szMsg = EliminateHtml(szMsg, dwDataLen);
- ReleaseCookie(dwCookie);
- }
- return;
+ handleStatusMsgReply("SNAC(4.B) ", hContact, dwUin, wVersion, pCookieData->nAckType, (WORD)dwCookie, szMsg, MTF_PLUGIN | MTF_STATUS_EXTENDED);
- default:
- debugLogA("Error: Unknown plugin message response, type %d.", typeId);
- return;
- }
+ SAFE_FREE(&szMsg);
+
+ ReleaseCookie(dwCookie);
+ }
+ return;
+
+ default:
+ debugLogA("Error: Unknown plugin message response, type %d.", typeId);
+ return;
}
+ }
break;
case MTYPE_PLAIN:
@@ -2473,21 +2212,20 @@ void CIcqProto::handleRecvMsgResponse(BYTE *buf, WORD wLen, WORD wFlags, DWORD d break;
case MTYPE_REVERSE_REQUEST:
- {
- cookie_reverse_connect *pReverse = (cookie_reverse_connect*)pCookieData;
-
- if (pReverse->ft)
- {
- filetransfer *ft = (filetransfer*)pReverse->ft;
+ {
+ cookie_reverse_connect *pReverse = (cookie_reverse_connect*)pCookieData;
- ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0);
- }
- debugLogA("Reverse Connect request failed");
- // Set DC status to failed
- setByte(hContact, "DCStatus", 2);
+ if (pReverse->ft) {
+ filetransfer *ft = (filetransfer*)pReverse->ft;
- ReleaseCookie(dwCookie);
+ ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0);
}
+ debugLogA("Reverse Connect request failed");
+ // Set DC status to failed
+ setByte(hContact, "DCStatus", 2);
+
+ ReleaseCookie(dwCookie);
+ }
return;
case MTYPE_CHAT:
@@ -2647,7 +2385,7 @@ void CIcqProto::handleRecvServMsgError(BYTE *buf, WORD wLen, WORD wFlags, DWORD if (pCookieData->bMessageType != MTYPE_FILEREQ)
SAFE_FREE((void**)&pCookieData);
}
- else {
+ else {
unpackWord(&buf, &wError);
LogFamilyError(ICQ_MSG_FAMILY, wError);
}
@@ -2678,14 +2416,11 @@ void CIcqProto::handleServerAck(BYTE *buf, WORD wLen, WORD wFlags, DWORD dwSeque MCONTACT hContact = HContactFromUID(dwUin, szUID, NULL);
- if (FindCookie((WORD)dwSequence, NULL, (void**)&pCookieData))
- {
+ if (FindCookie((WORD)dwSequence, NULL, (void**)&pCookieData)) {
// If the user requested a full ack, the
// server ack should be ignored here.
- if (pCookieData && (pCookieData->nAckType == ACKTYPE_SERVER))
- {
- if ((hContact != NULL) && (hContact != INVALID_CONTACT_ID))
- {
+ if (pCookieData && (pCookieData->nAckType == ACKTYPE_SERVER)) {
+ if ((hContact != NULL) && (hContact != INVALID_CONTACT_ID)) {
int ackType;
int ackRes = ACKRESULT_SUCCESS;
@@ -2764,7 +2499,7 @@ void CIcqProto::handleMissedMsg(BYTE *buf, WORD wLen, WORD wFlags, DWORD dwRef) wLen -= 2;
// Read past user info TLVs
- oscar_tlv_chain *pChain = readIntoTLVChain(&buf, (WORD)(wLen-4), wTLVCount);
+ oscar_tlv_chain *pChain = readIntoTLVChain(&buf, (WORD)(wLen - 4), wTLVCount);
if (pChain)
disposeChain(&pChain);
@@ -2811,11 +2546,9 @@ void CIcqProto::handleOffineMessagesReply(BYTE *buf, WORD wLen, WORD wFlags, DWO {
cookie_offline_messages *cookie;
- if (FindCookie(dwRef, NULL, (void**)&cookie))
- {
+ if (FindCookie(dwRef, NULL, (void**)&cookie)) {
debugLogA("End of offline msgs, %u received", cookie->nMessages);
- if (cookie->nMissed)
- { // NASTY WORKAROUND!!
+ if (cookie->nMissed) { // NASTY WORKAROUND!!
// The ICQ server has a bug that causes offline messages to be received again and again when some
// missed message notification is present (most probably it is not processed correctly and causes
// the server to fail the purging process); try to purge them using the old offline messages
@@ -2839,8 +2572,7 @@ void CIcqProto::handleOffineMessagesReply(BYTE *buf, WORD wLen, WORD wFlags, DWO ReleaseCookie(dwRef);
}
- else
- debugLogA("Error: Received unexpected end of offline msgs.");
+ else debugLogA("Error: Received unexpected end of offline msgs.");
}
@@ -2851,19 +2583,11 @@ void CIcqProto::handleTypingNotification(BYTE *buf, WORD wLen, WORD wFlags, DWOR WORD wChannel;
WORD wNotification;
- if (wLen < 14)
- {
+ if (wLen < 14) {
debugLogA("Ignoring SNAC(4.x11) Packet to short");
return;
}
-#ifndef DBG_CAPMTN
- {
- debugLogA("Ignoring unexpected typing notification");
- return;
- }
-#endif
-
// The message ID, unused?
buf += 8;
wLen -= 8;
diff --git a/protocols/IcqOscarJ/src/fam_09bos.cpp b/protocols/IcqOscarJ/src/fam_09bos.cpp index 280e457972..9b486ff60b 100644 --- a/protocols/IcqOscarJ/src/fam_09bos.cpp +++ b/protocols/IcqOscarJ/src/fam_09bos.cpp @@ -28,7 +28,6 @@ void CIcqProto::handleBosFam(unsigned char *pBuffer, WORD wBufferLength, snac_header* pSnacHeader)
{
switch (pSnacHeader->wSubtype) {
-
case ICQ_PRIVACY_RIGHTS_REPLY: // Reply to CLI_REQBOS
handlePrivacyRightsReply(pBuffer, wBufferLength);
break;
@@ -49,24 +48,17 @@ void CIcqProto::handleBosFam(unsigned char *pBuffer, WORD wBufferLength, snac_he default:
debugLogA("Warning: Ignoring SNAC(x%02x,x%02x) - Unknown SNAC (Flags: %u, Ref: %u)", ICQ_BOS_FAMILY, pSnacHeader->wSubtype, pSnacHeader->wFlags, pSnacHeader->dwRef);
break;
-
}
}
void CIcqProto::handlePrivacyRightsReply(unsigned char *pBuffer, WORD wBufferLength)
{
- if (wBufferLength >= 12)
- {
+ if (wBufferLength >= 12) {
oscar_tlv_chain* pChain = readIntoTLVChain(&pBuffer, wBufferLength, 0);
- if (pChain)
- {
- WORD wMaxVisibleContacts;
- WORD wMaxInvisibleContacts;
- WORD wMaxTemporaryVisibleContacts;
-
- wMaxVisibleContacts = pChain->getWord(0x0001, 1);
- wMaxInvisibleContacts = pChain->getWord(0x0002, 1);
- wMaxTemporaryVisibleContacts = pChain->getWord(0x0003, 1);
+ if (pChain) {
+ WORD wMaxVisibleContacts = pChain->getWord(0x0001, 1);
+ WORD wMaxInvisibleContacts = pChain->getWord(0x0002, 1);
+ WORD wMaxTemporaryVisibleContacts = pChain->getWord(0x0003, 1);
disposeChain(&pChain);
@@ -83,12 +75,11 @@ void CIcqProto::handlePrivacyRightsReply(unsigned char *pBuffer, WORD wBufferLen void CIcqProto::makeContactTemporaryVisible(MCONTACT hContact)
{
- DWORD dwUin;
- uid_str szUid;
-
if (getByte(hContact, "TemporaryVisible", 0))
return; // already there
+ DWORD dwUin;
+ uid_str szUid;
if (getContactUid(hContact, &dwUin, &szUid))
return; // Invalid contact
@@ -96,7 +87,5 @@ void CIcqProto::makeContactTemporaryVisible(MCONTACT hContact) setByte(hContact, "TemporaryVisible", 1);
-#ifdef _DEBUG
debugLogA("Added contact %s to temporary visible list", strUID(dwUin, szUid));
-#endif
}
diff --git a/protocols/IcqOscarJ/src/fam_0alookup.cpp b/protocols/IcqOscarJ/src/fam_0alookup.cpp index 9fc4ee1d49..0f25e47b06 100644 --- a/protocols/IcqOscarJ/src/fam_0alookup.cpp +++ b/protocols/IcqOscarJ/src/fam_0alookup.cpp @@ -34,17 +34,15 @@ void CIcqProto::handleLookupFam(BYTE *pBuffer, WORD wBufferLength, snac_header* break;
case ICQ_ERROR:
- {
+ {
WORD wError;
- cookie_search *pCookie;
-
if (wBufferLength >= 2)
unpackWord(&pBuffer, &wError);
- else
+ else
wError = 0;
- if (FindCookie(pSnacHeader->dwRef, NULL, (void**)&pCookie))
- {
+ cookie_search *pCookie;
+ if (FindCookie(pSnacHeader->dwRef, NULL, (void**)&pCookie)) {
if (wError == 0x14)
debugLogA("Lookup: No results");
@@ -54,8 +52,8 @@ void CIcqProto::handleLookupFam(BYTE *pBuffer, WORD wBufferLength, snac_header* }
LogFamilyError(ICQ_LOOKUP_FAMILY, wError);
- break;
}
+ break;
default:
debugLogA("Warning: Ignoring SNAC(x%02x,x%02x) - Unknown SNAC (Flags: %u, Ref: %u)", ICQ_LOOKUP_FAMILY, pSnacHeader->wSubtype, pSnacHeader->wFlags, pSnacHeader->dwRef);
@@ -68,12 +66,9 @@ void CIcqProto::ReleaseLookupCookie(DWORD dwCookie, cookie_search *pCookie) FreeCookie(dwCookie);
SAFE_FREE(&pCookie->szObject);
- if (pCookie->dwMainId && !pCookie->dwStatus)
- { // we need to wait for main search
+ if (pCookie->dwMainId && !pCookie->dwStatus) // we need to wait for main search
pCookie->dwStatus = 1;
- }
- else
- { // finish everything
+ else { // finish everything
if (pCookie->dwMainId)
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)pCookie->dwMainId, 0);
else // we are single
@@ -85,12 +80,11 @@ void CIcqProto::ReleaseLookupCookie(DWORD dwCookie, cookie_search *pCookie) void CIcqProto::handleLookupEmailReply(BYTE* buf, WORD wLen, DWORD dwCookie)
{
- ICQSEARCHRESULT sr = {0};
+ ICQSEARCHRESULT sr = { 0 };
oscar_tlv_chain *pChain;
cookie_search *pCookie;
- if (!FindCookie(dwCookie, NULL, (void**)&pCookie))
- {
+ if (!FindCookie(dwCookie, NULL, (void**)&pCookie)) {
debugLogA("Error: Received unexpected lookup reply");
return;
}
@@ -102,10 +96,8 @@ void CIcqProto::handleLookupEmailReply(BYTE* buf, WORD wLen, DWORD dwCookie) sr.hdr.email = ansi_to_tchar(pCookie->szObject);
// Syntax check, read chain
- if (wLen >= 4 && (pChain = readIntoTLVChain(&buf, wLen, 0)))
- {
- for (WORD i = 1; TRUE; i++)
- { // collect the results
+ if (wLen >= 4 && (pChain = readIntoTLVChain(&buf, wLen, 0))) {
+ for (WORD i = 1; TRUE; i++) { // collect the results
char *szUid = pChain->getString(0x01, i);
if (!szUid) break;
sr.hdr.id = ansi_to_tchar(szUid);
diff --git a/protocols/IcqOscarJ/src/fam_13servclist.cpp b/protocols/IcqOscarJ/src/fam_13servclist.cpp index 5bf83423f9..050aea947a 100644 --- a/protocols/IcqOscarJ/src/fam_13servclist.cpp +++ b/protocols/IcqOscarJ/src/fam_13servclist.cpp @@ -31,46 +31,36 @@ static int unpackServerListItem(BYTE **pbuf, WORD *pwLen, char *pszRecordName, W void CIcqProto::handleServCListFam(BYTE *pBuffer, WORD wBufferLength, snac_header* pSnacHeader, serverthread_info *info)
{
switch (pSnacHeader->wSubtype) {
-
case ICQ_LISTS_ACK: // UPDATE_ACK
- if (wBufferLength >= 2)
- {
+ if (wBufferLength >= 2) {
WORD wError;
cookie_servlist_action* sc;
unpackWord(&pBuffer, &wError);
- if (FindCookie(pSnacHeader->dwRef, NULL, (void**)&sc))
- { // look for action cookie
-#ifdef _DEBUG
+ if (FindCookie(pSnacHeader->dwRef, NULL, (void**)&sc)) { // look for action cookie
debugLogA("Received expected server list ack, action: %d, result: %d", sc->dwAction, wError);
-#endif
FreeCookie(pSnacHeader->dwRef); // release cookie
- if (sc->dwAction == SSA_ACTION_GROUP)
- { // group cookie, handle sub-items
+ if (sc->dwAction == SSA_ACTION_GROUP) { // group cookie, handle sub-items
int i;
-#ifdef _DEBUG
debugLogA("Server-List: Grouped action contains %d actions.", sc->dwGroupCount);
-#endif
+
pBuffer -= 2; // revoke unpack
- if (wBufferLength != 2*sc->dwGroupCount)
- debugLogA("Error: Server list ack does not contain expected amount of result codes (%u != %u)", wBufferLength/2, sc->dwGroupCount);
+ if (wBufferLength != 2 * sc->dwGroupCount)
+ debugLogA("Error: Server list ack does not contain expected amount of result codes (%u != %u)", wBufferLength / 2, sc->dwGroupCount);
- for (i = 0; i < sc->dwGroupCount; i++)
- {
- if (wBufferLength >= 2)
- { // get proper result code
+ for (i = 0; i < sc->dwGroupCount; i++) {
+ if (wBufferLength >= 2) { // get proper result code
unpackWord(&pBuffer, &wError);
wBufferLength -= 2;
}
else // missing result code, give some special
wError = -1;
-#ifdef _DEBUG
debugLogA("Action: %d, ack result: %d", sc->pGroupItems[i]->dwAction, wError);
-#endif
+
// call normal ack handler
handleServerCListAck(sc->pGroupItems[i], wError);
}
@@ -81,77 +71,56 @@ void CIcqProto::handleServCListFam(BYTE *pBuffer, WORD wBufferLength, snac_heade else // single ack
handleServerCListAck(sc, wError);
}
- else
- {
- debugLogA("Received unexpected server list ack %u", wError);
- }
+ else debugLogA("Received unexpected server list ack %u", wError);
}
break;
case ICQ_LISTS_SRV_REPLYLISTS:
- { /* received server-list rights */
- handleServerCListRightsReply(pBuffer, wBufferLength);
-
-#ifdef _DEBUG
- debugLogA("Server sent SNAC(x13,x03) - SRV_REPLYLISTS");
-#endif
- }
+ /* received server-list rights */
+ handleServerCListRightsReply(pBuffer, wBufferLength);
+ debugLogA("Server sent SNAC(x13,x03) - SRV_REPLYLISTS");
break;
case ICQ_LISTS_LIST: // SRV_REPLYROSTER
{
cookie_servlist_action* sc;
- BOOL blWork;
-
- blWork = bIsSyncingCL;
+ BOOL blWork = bIsSyncingCL;
bIsSyncingCL = TRUE; // this is not used if cookie takes place
- if (FindCookie(pSnacHeader->dwRef, NULL, (void**)&sc))
- { // we do it by reliable cookie
- if (!sc->lParam)
- { // is this first packet ?
+ if (FindCookie(pSnacHeader->dwRef, NULL, (void**)&sc)) { // we do it by reliable cookie
+ if (!sc->lParam) { // is this first packet ?
ResetSettingsOnListReload();
sc->lParam = 1;
}
handleServerCListReply(pBuffer, wBufferLength, pSnacHeader->wFlags, info);
- if (!(pSnacHeader->wFlags & 0x0001))
- { // was that last packet ?
+ if (!(pSnacHeader->wFlags & 0x0001)) // was that last packet ?
ReleaseCookie(pSnacHeader->dwRef); // yes, release cookie
- }
}
- else
- { // use old fake
- if (!blWork)
- { // this can fail on some crazy situations
+ else { // use old fake
+ if (!blWork) // this can fail on some crazy situations
ResetSettingsOnListReload();
- }
+
handleServerCListReply(pBuffer, wBufferLength, pSnacHeader->wFlags, info);
}
- break;
}
+ break;
case ICQ_LISTS_UPTODATE: // SRV_REPLYROSTEROK
+ bIsSyncingCL = FALSE;
{
cookie_servlist_action* sc;
-
- bIsSyncingCL = FALSE;
-
- if (FindCookie(pSnacHeader->dwRef, NULL, (void**)&sc))
- { // we requested servlist check
-#ifdef _DEBUG
+ if (FindCookie(pSnacHeader->dwRef, NULL, (void**)&sc)) { // we requested servlist check
debugLogA("Server stated roster is ok.");
-#endif
ReleaseCookie(pSnacHeader->dwRef);
LoadServerIDs();
}
- else
- debugLogA("Server sent unexpected SNAC(x13,x0F) - SRV_REPLYROSTEROK");
+ else debugLogA("Server sent unexpected SNAC(x13,x0F) - SRV_REPLYROSTEROK");
// This will activate the server side list
sendRosterAck(); // this must be here, cause of failures during cookie alloc
handleServUINSettings(wListenPort, info);
- break;
}
+ break;
case ICQ_LISTS_CLI_MODIFYSTART:
debugLogA("Server sent SNAC(x13,x%02x) - %s", ICQ_LISTS_CLI_MODIFYSTART, "Server is modifying contact list");
@@ -167,21 +136,18 @@ void CIcqProto::handleServCListFam(BYTE *pBuffer, WORD wBufferLength, snac_heade {
int nItems = 0;
- while (wBufferLength >= 10)
- {
+ while (wBufferLength >= 10) {
WORD wGroupId, wItemId, wItemType, wTlvLen;
uid_str szRecordName;
- if (unpackServerListItem(&pBuffer, &wBufferLength, szRecordName, &wGroupId, &wItemId, &wItemType, &wTlvLen))
- {
+ if (unpackServerListItem(&pBuffer, &wBufferLength, szRecordName, &wGroupId, &wItemId, &wItemType, &wTlvLen)) {
BYTE *buf = pBuffer;
oscar_tlv_chain *pChain = NULL;
nItems++;
// parse possible item's data
- if (wBufferLength >= wTlvLen && wTlvLen > 0)
- {
+ if (wBufferLength >= wTlvLen && wTlvLen > 0) {
pChain = readIntoTLVChain(&buf, wTlvLen, 0);
pBuffer += wTlvLen;
wBufferLength -= wTlvLen;
@@ -201,9 +167,9 @@ void CIcqProto::handleServCListFam(BYTE *pBuffer, WORD wBufferLength, snac_heade disposeChain(&pChain);
}
}
- { // log packet basics
+ {
+ // log packet basics
char *szChange;
- char szLogText[MAX_PATH];
if (pSnacHeader->wSubtype == ICQ_LISTS_ADDTOLIST)
szChange = "Server added %u item(s) to list";
@@ -212,6 +178,7 @@ void CIcqProto::handleServCListFam(BYTE *pBuffer, WORD wBufferLength, snac_heade else if (pSnacHeader->wSubtype == ICQ_LISTS_REMOVEFROMLIST)
szChange = "Server removed %u item(s) from list";
+ char szLogText[MAX_PATH];
mir_snprintf(szLogText, MAX_PATH, szChange, nItems);
debugLogA("Server sent SNAC(x13,x%02x) - %s", pSnacHeader->wSubtype, szLogText);
}
@@ -235,22 +202,17 @@ void CIcqProto::handleServCListFam(BYTE *pBuffer, WORD wBufferLength, snac_heade break;
case ICQ_LISTS_ERROR:
- if (wBufferLength >= 2)
- {
+ if (wBufferLength >= 2) {
WORD wError;
cookie_servlist_action* sc;
unpackWord(&pBuffer, &wError);
- if (FindCookie(pSnacHeader->dwRef, NULL, (void**)&sc))
- { // look for action cookie
-#ifdef _DEBUG
+ if (FindCookie(pSnacHeader->dwRef, NULL, (void**)&sc)) { // look for action cookie
debugLogA("Received server list error, action: %d, result: %d", sc->dwAction, wError);
-#endif
FreeCookie(pSnacHeader->dwRef); // release cookie
- if (sc->dwAction==SSA_CHECK_ROSTER)
- { // the serv-list is unavailable turn it off
+ if (sc->dwAction == SSA_CHECK_ROSTER) { // the serv-list is unavailable turn it off
icq_LogMessage(LOG_ERROR, LPGEN("Server contact list is unavailable, Miranda will use local contact list."));
m_bSsiEnabled = 0;
handleServUINSettings(wListenPort, info);
@@ -258,10 +220,7 @@ void CIcqProto::handleServCListFam(BYTE *pBuffer, WORD wBufferLength, snac_heade /// FIXME: properly release pending operations & cookie memory
SAFE_FREE((void**)&sc);
}
- else
- {
- LogFamilyError(ICQ_LISTS_FAMILY, wError);
- }
+ else LogFamilyError(ICQ_LISTS_FAMILY, wError);
}
break;
@@ -309,32 +268,27 @@ static int unpackServerListItem(BYTE **pbuf, WORD *pwLen, char *pszRecordName, W void CIcqProto::handleServerCListRightsReply(BYTE *buf, WORD wLen)
-{ /* received list rights, store the item limits for future use */
+{
+ /* received list rights, store the item limits for future use */
oscar_tlv_chain* chain;
memset(m_wServerListLimits, -1, sizeof(m_wServerListLimits));
m_wServerListGroupMaxContacts = 0;
m_wServerListRecordNameMaxLength = 0xFFFF;
- if (chain = readIntoTLVChain(&buf, wLen, 0))
- {
- oscar_tlv* pTLV;
-
+ if (chain = readIntoTLVChain(&buf, wLen, 0)) {
// determine max number of contacts in a group
m_wServerListGroupMaxContacts = chain->getWord(0x0C, 1);
// determine length limit for server-list item's name
m_wServerListRecordNameMaxLength = chain->getWord(0x06, 1);
- if (pTLV = chain->getTLV(0x04, 1))
- { // limits for item types
- int i;
+ if (oscar_tlv *pTLV = chain->getTLV(0x04, 1)) { // limits for item types
WORD *pLimits = (WORD*)pTLV->pData;
-
- for (i = 0; i < pTLV->wLen / 2; i++)
- {
+ for (int i = 0; i < pTLV->wLen / 2; i++) {
m_wServerListLimits[i] = (pLimits[i] & 0xFF) << 8 | (pLimits[i] >> 8);
- if (i + 1 >= SIZEOF(m_wServerListLimits)) break;
+ if (i + 1 >= SIZEOF(m_wServerListLimits))
+ break;
}
debugLogA("SSI: Max %d contacts (%d per group), %d groups, %d permit, %d deny, %d ignore items.", m_wServerListLimits[SSI_ITEM_BUDDY], m_wServerListGroupMaxContacts, m_wServerListLimits[SSI_ITEM_GROUP], m_wServerListLimits[SSI_ITEM_PERMIT], m_wServerListLimits[SSI_ITEM_DENY], m_wServerListLimits[SSI_ITEM_IGNORE]);
@@ -344,449 +298,379 @@ void CIcqProto::handleServerCListRightsReply(BYTE *buf, WORD wLen) }
}
-
DWORD CIcqProto::updateServerGroupData(WORD wGroupId, void *groupData, int groupSize, DWORD dwOperationFlags)
{
- DWORD dwCookie;
- cookie_servlist_action* ack;
-
- 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) {
debugLogA("Updating of group on server list failed (malloc error)");
return 0;
}
ack->dwAction = SSA_GROUP_UPDATE;
ack->szGroupName = getServListGroupName(wGroupId);
ack->wGroupId = wGroupId;
- dwCookie = AllocateCookie(CKT_SERVERLIST, ICQ_LISTS_UPDATEGROUP, 0, ack);
-
+
+ DWORD dwCookie = AllocateCookie(CKT_SERVERLIST, ICQ_LISTS_UPDATEGROUP, 0, ack);
return icq_sendServerGroup(dwCookie, ICQ_LISTS_UPDATEGROUP, ack->wGroupId, ack->szGroupName, groupData, groupSize, dwOperationFlags);
}
-
void CIcqProto::handleServerCListAck(cookie_servlist_action* sc, WORD wError)
{
- switch (sc->dwAction)
- {
+ switch (sc->dwAction) {
case SSA_VISIBILITY:
- {
- if (wError)
- debugLogA("Server visibility update failed, error %d", wError);
- break;
- }
+ if (wError)
+ debugLogA("Server visibility update failed, error %d", wError);
+ break;
+
case SSA_CONTACT_UPDATE:
- {
- servlistPendingRemoveContact(sc->hContact, sc->wContactId, sc->wGroupId, wError ? PENDING_RESULT_FAILED : PENDING_RESULT_SUCCESS);
- if (wError)
- {
- debugLogA("Updating of server contact failed, error %d", wError);
- icq_LogMessage(LOG_WARNING, LPGEN("Updating of server contact failed."));
- }
- break;
+ servlistPendingRemoveContact(sc->hContact, sc->wContactId, sc->wGroupId, wError ? PENDING_RESULT_FAILED : PENDING_RESULT_SUCCESS);
+ if (wError) {
+ debugLogA("Updating of server contact failed, error %d", wError);
+ icq_LogMessage(LOG_WARNING, LPGEN("Updating of server contact failed."));
}
+ break;
+
case SSA_PRIVACY_ADD:
- {
- if (wError)
- {
- debugLogA("Adding of privacy item to server list failed, error %d", wError);
- icq_LogMessage(LOG_WARNING, LPGEN("Adding of privacy item to server list failed."));
- }
- break;
+ if (wError) {
+ debugLogA("Adding of privacy item to server list failed, error %d", wError);
+ icq_LogMessage(LOG_WARNING, LPGEN("Adding of privacy item to server list failed."));
}
+ break;
+
case SSA_PRIVACY_REMOVE:
- {
- if (wError)
- {
- debugLogA("Removing of privacy item from server list failed, error %d", wError);
- icq_LogMessage(LOG_WARNING, LPGEN("Removing of privacy item from server list failed."));
- }
- FreeServerID(sc->wContactId, SSIT_ITEM); // release server id
- break;
+ if (wError) {
+ debugLogA("Removing of privacy item from server list failed, error %d", wError);
+ icq_LogMessage(LOG_WARNING, LPGEN("Removing of privacy item from server list failed."));
}
- case SSA_CONTACT_ADD:
- {
- if (wError)
- {
- if (wError == 0xE) // server refused to add contact w/o auth, add with
- {
- DWORD dwCookie;
+ FreeServerID(sc->wContactId, SSIT_ITEM); // release server id
+ break;
- debugLogA("Contact could not be added without authorization, add with await auth flag.");
+ case SSA_CONTACT_ADD:
+ if (wError) {
+ if (wError == 0xE) { // server refused to add contact w/o auth, add with
+ debugLogA("Contact could not be added without authorization, add with await auth flag.");
- setByte(sc->hContact, "Auth", 1); // we need auth
- dwCookie = AllocateCookie(CKT_SERVERLIST, ICQ_LISTS_ADDTOLIST, sc->hContact, sc);
- icq_sendServerContact(sc->hContact, dwCookie, ICQ_LISTS_ADDTOLIST, sc->wGroupId, sc->wContactId, SSOP_ITEM_ACTION | SSOF_CONTACT, 500, NULL);
+ setByte(sc->hContact, "Auth", 1); // we need auth
+ DWORD dwCookie = AllocateCookie(CKT_SERVERLIST, ICQ_LISTS_ADDTOLIST, sc->hContact, sc);
+ icq_sendServerContact(sc->hContact, dwCookie, ICQ_LISTS_ADDTOLIST, sc->wGroupId, sc->wContactId, SSOP_ITEM_ACTION | SSOF_CONTACT, 500, NULL);
- sc = NULL; // we do not want it to be freed now
- break;
- }
- FreeServerID(sc->wContactId, SSIT_ITEM);
+ sc = NULL; // we do not want it to be freed now
+ break;
+ }
+ FreeServerID(sc->wContactId, SSIT_ITEM);
- debugLogA("Adding of contact to server list failed, error %d", wError);
- icq_LogMessage(LOG_WARNING, LPGEN("Adding of contact to server list failed."));
+ debugLogA("Adding of contact to server list failed, error %d", wError);
+ icq_LogMessage(LOG_WARNING, LPGEN("Adding of contact to server list failed."));
- servlistPendingRemoveContact(sc->hContact, 0, sc->wGroupId, PENDING_RESULT_FAILED);
+ servlistPendingRemoveContact(sc->hContact, 0, sc->wGroupId, PENDING_RESULT_FAILED);
- servlistPostPacket(NULL, 0, SSO_END_OPERATION, 100); // end server modifications here
- }
- else
- {
- void* groupData;
- int groupSize;
+ servlistPostPacket(NULL, 0, SSO_END_OPERATION, 100); // end server modifications here
+ }
+ else {
+ void* groupData;
+ int groupSize;
- setWord(sc->hContact, DBSETTING_SERVLIST_ID, sc->wContactId);
- setWord(sc->hContact, DBSETTING_SERVLIST_GROUP, sc->wGroupId);
+ setWord(sc->hContact, DBSETTING_SERVLIST_ID, sc->wContactId);
+ setWord(sc->hContact, DBSETTING_SERVLIST_GROUP, sc->wGroupId);
- servlistPendingRemoveContact(sc->hContact, sc->wContactId, sc->wGroupId, PENDING_RESULT_SUCCESS);
+ servlistPendingRemoveContact(sc->hContact, sc->wContactId, sc->wGroupId, PENDING_RESULT_SUCCESS);
- if (groupData = collectBuddyGroup(sc->wGroupId, &groupSize))
- { // the group is not empty, just update it
- updateServerGroupData(sc->wGroupId, groupData, groupSize, SSOF_END_OPERATION);
- SAFE_FREE((void**)&groupData);
- }
- else
- { // this should never happen
- debugLogA("Group update failed.");
- servlistPostPacket(NULL, 0, SSO_END_OPERATION, 100); // end server modifications here
- }
+ if (groupData = collectBuddyGroup(sc->wGroupId, &groupSize)) { // the group is not empty, just update it
+ updateServerGroupData(sc->wGroupId, groupData, groupSize, SSOF_END_OPERATION);
+ SAFE_FREE((void**)&groupData);
+ }
+ else { // this should never happen
+ debugLogA("Group update failed.");
+ servlistPostPacket(NULL, 0, SSO_END_OPERATION, 100); // end server modifications here
}
- break;
}
- case SSA_GROUP_ADD:
- {
- if (wError)
- {
- FreeServerID(sc->wGroupId, SSIT_GROUP);
- debugLogA("Adding of group to server list failed, error %d", wError);
- icq_LogMessage(LOG_WARNING, LPGEN("Adding of group to server list failed."));
+ break;
- servlistPendingRemoveGroup(sc->szGroup, 0, PENDING_RESULT_FAILED);
- }
- else // group added, we need to update master group
- {
- void* groupData;
- int groupSize;
- cookie_servlist_action* ack;
- DWORD dwCookie;
+ case SSA_GROUP_ADD:
+ if (wError) {
+ FreeServerID(sc->wGroupId, SSIT_GROUP);
+ debugLogA("Adding of group to server list failed, error %d", wError);
+ icq_LogMessage(LOG_WARNING, LPGEN("Adding of group to server list failed."));
- setServListGroupName(sc->wGroupId, sc->szGroupName); // add group to namelist
- { // add group to known
- char *szCListGroup = getServListGroupCListPath(sc->wGroupId);
+ servlistPendingRemoveGroup(sc->szGroup, 0, PENDING_RESULT_FAILED);
+ }
+ else { // group added, we need to update master group
+ void* groupData;
+ int groupSize;
- // create link to the original CList group
- setServListGroupLinkID(sc->szGroup, sc->wGroupId);
+ setServListGroupName(sc->wGroupId, sc->szGroupName); // add group to namelist
+ { // add group to known
+ char *szCListGroup = getServListGroupCListPath(sc->wGroupId);
- servlistPendingRemoveGroup(sc->szGroup, sc->wGroupId, PENDING_RESULT_SUCCESS);
- SAFE_FREE((void**)&szCListGroup);
- }
+ // create link to the original CList group
+ setServListGroupLinkID(sc->szGroup, sc->wGroupId);
- groupData = collectGroups(&groupSize);
- groupData = SAFE_REALLOC(groupData, groupSize+2);
- *(((WORD*)groupData)+(groupSize>>1)) = sc->wGroupId; // add this new group id
- groupSize += 2;
+ servlistPendingRemoveGroup(sc->szGroup, sc->wGroupId, PENDING_RESULT_SUCCESS);
+ SAFE_FREE((void**)&szCListGroup);
+ }
- ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action));
- if (ack)
- {
- ack->dwAction = SSA_GROUP_UPDATE;
- dwCookie = AllocateCookie(CKT_SERVERLIST, ICQ_LISTS_UPDATEGROUP, 0, ack);
+ groupData = collectGroups(&groupSize);
+ groupData = SAFE_REALLOC(groupData, groupSize + 2);
+ *(((WORD*)groupData) + (groupSize >> 1)) = sc->wGroupId; // add this new group id
+ groupSize += 2;
- icq_sendServerGroup(dwCookie, ICQ_LISTS_UPDATEGROUP, 0, ack->szGroupName, groupData, groupSize, SSOF_END_OPERATION);
- }
- else // end server modifications here
- servlistPostPacket(NULL, 0, SSO_END_OPERATION, 100);
+ cookie_servlist_action *ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action));
+ if (ack) {
+ ack->dwAction = SSA_GROUP_UPDATE;
- SAFE_FREE((void**)&groupData);
+ DWORD dwCookie = AllocateCookie(CKT_SERVERLIST, ICQ_LISTS_UPDATEGROUP, 0, ack);
+ icq_sendServerGroup(dwCookie, ICQ_LISTS_UPDATEGROUP, 0, ack->szGroupName, groupData, groupSize, SSOF_END_OPERATION);
}
- if (sc->szGroup != sc->szGroupName)
- SAFE_FREE((void**)&sc->szGroup);
+ else // end server modifications here
+ servlistPostPacket(NULL, 0, SSO_END_OPERATION, 100);
- SAFE_FREE((void**)&sc->szGroupName);
- break;
+ SAFE_FREE((void**)&groupData);
}
- case SSA_CONTACT_REMOVE:
- {
- if (!wError)
- {
- void* groupData;
- int groupSize;
+ if (sc->szGroup != sc->szGroupName)
+ SAFE_FREE((void**)&sc->szGroup);
- setWord(sc->hContact, DBSETTING_SERVLIST_ID, 0); // clear the values
- setWord(sc->hContact, DBSETTING_SERVLIST_GROUP, 0);
+ SAFE_FREE((void**)&sc->szGroupName);
+ break;
- FreeServerID(sc->wContactId, SSIT_ITEM);
+ case SSA_CONTACT_REMOVE:
+ if (!wError) {
+ void* groupData;
+ int groupSize;
- servlistPendingRemoveContact(sc->hContact, 0, sc->wGroupId, PENDING_RESULT_SUCCESS);
+ setWord(sc->hContact, DBSETTING_SERVLIST_ID, 0); // clear the values
+ setWord(sc->hContact, DBSETTING_SERVLIST_GROUP, 0);
- if (groupData = collectBuddyGroup(sc->wGroupId, &groupSize))
- { // the group is still not empty, just update it
- updateServerGroupData(sc->wGroupId, groupData, groupSize, SSOF_END_OPERATION);
- }
- else // the group is empty, delete it
- {
- char *szGroup = getServListGroupCListPath(sc->wGroupId);
+ FreeServerID(sc->wContactId, SSIT_ITEM);
- servlistRemoveGroup(szGroup, sc->wGroupId);
- SAFE_FREE((void**)&szGroup);
- }
- SAFE_FREE((void**)&groupData); // free the memory
+ servlistPendingRemoveContact(sc->hContact, 0, sc->wGroupId, PENDING_RESULT_SUCCESS);
+
+ if (groupData = collectBuddyGroup(sc->wGroupId, &groupSize)) { // the group is still not empty, just update it
+ updateServerGroupData(sc->wGroupId, groupData, groupSize, SSOF_END_OPERATION);
}
- else
+ else // the group is empty, delete it
{
- debugLogA("Removing of contact from server list failed, error %d", wError);
- icq_LogMessage(LOG_WARNING, LPGEN("Removing of contact from server list failed."));
+ char *szGroup = getServListGroupCListPath(sc->wGroupId);
- servlistPendingRemoveContact(sc->hContact, sc->wContactId, sc->wGroupId, PENDING_RESULT_FAILED);
-
- servlistPostPacket(NULL, 0, SSO_END_OPERATION, 100); // end server modifications here
+ servlistRemoveGroup(szGroup, sc->wGroupId);
+ SAFE_FREE((void**)&szGroup);
}
- break;
+ SAFE_FREE((void**)&groupData); // free the memory
+ }
+ else {
+ debugLogA("Removing of contact from server list failed, error %d", wError);
+ icq_LogMessage(LOG_WARNING, LPGEN("Removing of contact from server list failed."));
+
+ servlistPendingRemoveContact(sc->hContact, sc->wContactId, sc->wGroupId, PENDING_RESULT_FAILED);
+
+ servlistPostPacket(NULL, 0, SSO_END_OPERATION, 100); // end server modifications here
}
+ break;
+
case SSA_GROUP_UPDATE:
- {
- if (wError)
- {
- debugLogA("Updating of group on server list failed, error %d", wError);
- icq_LogMessage(LOG_WARNING, LPGEN("Updating of group on server list failed."));
- }
- SAFE_FREE((void**)&sc->szGroupName);
- break;
+ if (wError) {
+ debugLogA("Updating of group on server list failed, error %d", wError);
+ icq_LogMessage(LOG_WARNING, LPGEN("Updating of group on server list failed."));
}
+ SAFE_FREE((void**)&sc->szGroupName);
+ break;
+
case SSA_GROUP_REMOVE:
- {
- SAFE_FREE((void**)&sc->szGroupName);
- if (wError)
- {
- debugLogA("Removing of group from server list failed, error %d", wError);
- icq_LogMessage(LOG_WARNING, LPGEN("Removing of group from server list failed."));
+ SAFE_FREE((void**)&sc->szGroupName);
+ if (wError) {
+ debugLogA("Removing of group from server list failed, error %d", wError);
+ icq_LogMessage(LOG_WARNING, LPGEN("Removing of group from server list failed."));
- servlistPendingRemoveGroup(sc->szGroup, 0, PENDING_RESULT_FAILED);
+ servlistPendingRemoveGroup(sc->szGroup, 0, PENDING_RESULT_FAILED);
- servlistPostPacket(NULL, 0, SSO_END_OPERATION, 100); // end server modifications here
- SAFE_FREE((void**)&sc->szGroup);
- }
- else // group removed, we need to update master group
- {
- void* groupData;
- int groupSize;
- DWORD dwCookie;
+ servlistPostPacket(NULL, 0, SSO_END_OPERATION, 100); // end server modifications here
+ SAFE_FREE((void**)&sc->szGroup);
+ }
+ else { // group removed, we need to update master group
+ void* groupData;
+ int groupSize;
- setServListGroupName(sc->wGroupId, NULL); // clear group from namelist
- FreeServerID(sc->wGroupId, SSIT_GROUP);
- removeGroupPathLinks(sc->wGroupId);
+ setServListGroupName(sc->wGroupId, NULL); // clear group from namelist
+ FreeServerID(sc->wGroupId, SSIT_GROUP);
+ removeGroupPathLinks(sc->wGroupId);
- servlistPendingRemoveGroup(sc->szGroup, 0, PENDING_RESULT_SUCCESS);
- SAFE_FREE((void**)&sc->szGroup);
+ servlistPendingRemoveGroup(sc->szGroup, 0, PENDING_RESULT_SUCCESS);
+ SAFE_FREE((void**)&sc->szGroup);
- groupData = collectGroups(&groupSize);
- sc->wGroupId = 0;
- sc->dwAction = SSA_GROUP_UPDATE;
- sc->szGroupName = NULL;
- dwCookie = AllocateCookie(CKT_SERVERLIST, ICQ_LISTS_UPDATEGROUP, 0, sc);
+ groupData = collectGroups(&groupSize);
+ sc->wGroupId = 0;
+ sc->dwAction = SSA_GROUP_UPDATE;
+ sc->szGroupName = NULL;
+ DWORD dwCookie = AllocateCookie(CKT_SERVERLIST, ICQ_LISTS_UPDATEGROUP, 0, sc);
- icq_sendServerGroup(dwCookie, ICQ_LISTS_UPDATEGROUP, 0, sc->szGroupName, groupData, groupSize, SSOF_END_OPERATION);
- // end server modifications here
+ icq_sendServerGroup(dwCookie, ICQ_LISTS_UPDATEGROUP, 0, sc->szGroupName, groupData, groupSize, SSOF_END_OPERATION);
+ // end server modifications here
- sc = NULL; // we do not want to be freed here
+ sc = NULL; // we do not want to be freed here
- SAFE_FREE((void**)&groupData);
- }
- break;
+ SAFE_FREE((void**)&groupData);
}
- case SSA_CONTACT_SET_GROUP:
- { // we moved contact to another group
- if (sc->lParam == -1)
- { // the first was an error
- break;
- }
- if (wError)
- {
- if (wError == 0x0E && sc->lParam == 1)
- { // second ack - adding failed with error 0x0E, try to add with AVAIT_AUTH flag
- DWORD dwCookie;
-
- if (!getByte(sc->hContact, "Auth", 0))
- { // we tried without AWAIT_AUTH, try again with it
- debugLogA("Contact could not be added without authorization, add with await auth flag.");
-
- setByte(sc->hContact, "Auth", 1); // we need auth
- }
- else
- { // we tried with AWAIT_AUTH, try again without
- debugLogA("Contact count not be added awaiting authorization, try authorized.");
+ break;
- setByte(sc->hContact, "Auth", 0);
- }
- dwCookie = AllocateCookie(CKT_SERVERLIST, ICQ_LISTS_ADDTOLIST, sc->hContact, sc);
- icq_sendServerContact(sc->hContact, dwCookie, ICQ_LISTS_ADDTOLIST, sc->wNewGroupId, sc->wNewContactId, SSOP_ITEM_ACTION | SSOF_CONTACT, 400, NULL);
+ case SSA_CONTACT_SET_GROUP:
+ // we moved contact to another group
+ if (sc->lParam == -1) // the first was an error
+ break;
- sc->lParam = 2; // do not cycle
- sc = NULL; // we do not want to be freed here
- break;
+ if (wError) {
+ if (wError == 0x0E && sc->lParam == 1) { // second ack - adding failed with error 0x0E, try to add with AVAIT_AUTH flag
+ if (!getByte(sc->hContact, "Auth", 0)) { // we tried without AWAIT_AUTH, try again with it
+ debugLogA("Contact could not be added without authorization, add with await auth flag.");
+ setByte(sc->hContact, "Auth", 1); // we need auth
}
- FreeServerID(sc->wNewContactId, SSIT_ITEM);
- debugLogA("Moving of user to another group on server list failed, error %d", wError);
- icq_LogMessage(LOG_ERROR, LPGEN("Moving of user to another group on server list failed."));
-
- servlistPendingRemoveContact(sc->hContact, 0, (WORD)(sc->lParam ? sc->wGroupId : sc->wNewGroupId), PENDING_RESULT_FAILED);
-
- servlistPostPacket(NULL, 0, SSO_END_OPERATION, 100); // end server modifications here
-
- if (!sc->lParam) // is this first ack ?
- {
- sc->lParam = -1;
- sc = NULL; // this can't be freed here
+ else { // we tried with AWAIT_AUTH, try again without
+ debugLogA("Contact count not be added awaiting authorization, try authorized.");
+ setByte(sc->hContact, "Auth", 0);
}
+ DWORD dwCookie = AllocateCookie(CKT_SERVERLIST, ICQ_LISTS_ADDTOLIST, sc->hContact, sc);
+ icq_sendServerContact(sc->hContact, dwCookie, ICQ_LISTS_ADDTOLIST, sc->wNewGroupId, sc->wNewContactId, SSOP_ITEM_ACTION | SSOF_CONTACT, 400, NULL);
+
+ sc->lParam = 2; // do not cycle
+ sc = NULL; // we do not want to be freed here
break;
}
- if (sc->lParam) // is this the second ack ?
- {
- void* groupData;
- int groupSize;
- int bEnd = 1; // shall we end the sever modifications
+ FreeServerID(sc->wNewContactId, SSIT_ITEM);
+ debugLogA("Moving of user to another group on server list failed, error %d", wError);
+ icq_LogMessage(LOG_ERROR, LPGEN("Moving of user to another group on server list failed."));
- setWord(sc->hContact, DBSETTING_SERVLIST_ID, sc->wNewContactId);
- setWord(sc->hContact, DBSETTING_SERVLIST_GROUP, sc->wNewGroupId);
+ servlistPendingRemoveContact(sc->hContact, 0, (WORD)(sc->lParam ? sc->wGroupId : sc->wNewGroupId), PENDING_RESULT_FAILED);
- servlistPendingRemoveContact(sc->hContact, sc->wNewContactId, sc->wNewGroupId, PENDING_RESULT_SUCCESS);
+ servlistPostPacket(NULL, 0, SSO_END_OPERATION, 100); // end server modifications here
- if (groupData = collectBuddyGroup(sc->wGroupId, &groupSize)) // update the group we moved from
- { // the group is still not empty, just update it
- updateServerGroupData(sc->wGroupId, groupData, groupSize, 0);
- SAFE_FREE((void**)&groupData); // free the memory
- }
- else
- { // the group is empty, delete it
- char* szGroup = getServListGroupCListPath(sc->wGroupId);
+ if (!sc->lParam) { // is this first ack ?
+ sc->lParam = -1;
+ sc = NULL; // this can't be freed here
+ }
+ break;
+ }
- servlistRemoveGroup(szGroup, sc->wGroupId);
- SAFE_FREE((void**)&szGroup);
- bEnd = 0; // here the modifications go on
- }
+ if (sc->lParam) { // is this the second ack ?
+ void* groupData;
+ int groupSize;
+ int bEnd = 1; // shall we end the sever modifications
- groupData = collectBuddyGroup(sc->wNewGroupId, &groupSize); // update the group we moved to
- updateServerGroupData(sc->wNewGroupId, groupData, groupSize, bEnd ? SSOF_END_OPERATION : 0);
- // end server modifications here
- SAFE_FREE((void**)&groupData);
+ setWord(sc->hContact, DBSETTING_SERVLIST_ID, sc->wNewContactId);
+ setWord(sc->hContact, DBSETTING_SERVLIST_GROUP, sc->wNewGroupId);
+
+ servlistPendingRemoveContact(sc->hContact, sc->wNewContactId, sc->wNewGroupId, PENDING_RESULT_SUCCESS);
+ if (groupData = collectBuddyGroup(sc->wGroupId, &groupSize)) // update the group we moved from
+ { // the group is still not empty, just update it
+ updateServerGroupData(sc->wGroupId, groupData, groupSize, 0);
+ SAFE_FREE((void**)&groupData); // free the memory
}
- else // contact was deleted from server-list
- {
- delSetting(sc->hContact, DBSETTING_SERVLIST_ID);
- delSetting(sc->hContact, DBSETTING_SERVLIST_GROUP);
- FreeServerID(sc->wContactId, SSIT_ITEM); // release old contact id
- sc->lParam = 1;
- sc = NULL; // wait for second ack
+ else { // the group is empty, delete it
+ char* szGroup = getServListGroupCListPath(sc->wGroupId);
+
+ servlistRemoveGroup(szGroup, sc->wGroupId);
+ SAFE_FREE((void**)&szGroup);
+ bEnd = 0; // here the modifications go on
}
- break;
+
+ groupData = collectBuddyGroup(sc->wNewGroupId, &groupSize); // update the group we moved to
+ updateServerGroupData(sc->wNewGroupId, groupData, groupSize, bEnd ? SSOF_END_OPERATION : 0);
+ // end server modifications here
+ SAFE_FREE((void**)&groupData);
+
}
- case SSA_CONTACT_FIX_AUTH:
+ else // contact was deleted from server-list
{
- if (wError)
- { // FIXME: something failed, we should handle it properly
- }
- break;
+ delSetting(sc->hContact, DBSETTING_SERVLIST_ID);
+ delSetting(sc->hContact, DBSETTING_SERVLIST_GROUP);
+ FreeServerID(sc->wContactId, SSIT_ITEM); // release old contact id
+ sc->lParam = 1;
+ sc = NULL; // wait for second ack
+ }
+ break;
+
+ case SSA_CONTACT_FIX_AUTH:
+ if (wError) { // FIXME: something failed, we should handle it properly
}
+ break;
+
case SSA_GROUP_RENAME:
- {
- if (wError)
- {
- debugLogA("Renaming of server group failed, error %d", wError);
- icq_LogMessage(LOG_WARNING, LPGEN("Renaming of server group failed."));
+ if (wError) {
+ debugLogA("Renaming of server group failed, error %d", wError);
+ icq_LogMessage(LOG_WARNING, LPGEN("Renaming of server group failed."));
- servlistPendingRemoveGroup(sc->szGroup, sc->wGroupId, PENDING_RESULT_FAILED);
- }
- else
- {
- setServListGroupName(sc->wGroupId, sc->szGroupName);
- removeGroupPathLinks(sc->wGroupId);
- { // add group to known
- char *szCListGroup = getServListGroupCListPath(sc->wGroupId);
-
- /// FIXME: need to create link to the new group name before unique item name correction as well
- setServListGroupLinkID(szCListGroup, sc->wGroupId);
- SAFE_FREE((void**)&szCListGroup);
- }
- servlistPendingRemoveGroup(sc->szGroup, sc->wGroupId, PENDING_RESULT_SUCCESS);
+ servlistPendingRemoveGroup(sc->szGroup, sc->wGroupId, PENDING_RESULT_FAILED);
+ }
+ else {
+ setServListGroupName(sc->wGroupId, sc->szGroupName);
+ removeGroupPathLinks(sc->wGroupId);
+ { // add group to known
+ char *szCListGroup = getServListGroupCListPath(sc->wGroupId);
+
+ /// FIXME: need to create link to the new group name before unique item name correction as well
+ setServListGroupLinkID(szCListGroup, sc->wGroupId);
+ SAFE_FREE((void**)&szCListGroup);
}
- SAFE_FREE((void**)&sc->szGroupName);
- SAFE_FREE((void**)&sc->szGroup);
- break;
+ servlistPendingRemoveGroup(sc->szGroup, sc->wGroupId, PENDING_RESULT_SUCCESS);
}
+ SAFE_FREE((void**)&sc->szGroupName);
+ SAFE_FREE((void**)&sc->szGroup);
+ break;
+
case SSA_SETAVATAR:
- {
- if (wError)
- {
- debugLogA("Uploading of avatar hash failed.");
- if (sc->wGroupId) // is avatar added or updated?
- {
- FreeServerID(sc->wContactId, SSIT_ITEM);
- delSetting(DBSETTING_SERVLIST_AVATAR); // to fix old versions
- }
- }
- else
- {
- setWord(DBSETTING_SERVLIST_AVATAR, sc->wContactId);
+ if (wError) {
+ debugLogA("Uploading of avatar hash failed.");
+ if (sc->wGroupId) { // is avatar added or updated?
+ FreeServerID(sc->wContactId, SSIT_ITEM);
+ delSetting(DBSETTING_SERVLIST_AVATAR); // to fix old versions
}
- break;
}
+ else setWord(DBSETTING_SERVLIST_AVATAR, sc->wContactId);
+ break;
+
case SSA_REMOVEAVATAR:
- {
- if (wError)
- debugLogA("Removing of avatar hash failed.");
- else
- {
- FreeServerID(sc->wContactId, SSIT_ITEM);
- delSetting(DBSETTING_SERVLIST_AVATAR);
- }
- break;
+ if (wError)
+ debugLogA("Removing of avatar hash failed.");
+ else {
+ FreeServerID(sc->wContactId, SSIT_ITEM);
+ delSetting(DBSETTING_SERVLIST_AVATAR);
}
+ break;
+
case SSA_SERVLIST_ACK:
- {
- ProtoBroadcastAck(sc->hContact, ICQACKTYPE_SERVERCLIST, wError?ACKRESULT_FAILED:ACKRESULT_SUCCESS, (HANDLE)sc->lParam, wError);
- break;
- }
+ ProtoBroadcastAck(sc->hContact, ICQACKTYPE_SERVERCLIST, wError ? ACKRESULT_FAILED : ACKRESULT_SUCCESS, (HANDLE)sc->lParam, wError);
+ break;
+
case SSA_IMPORT:
- {
- if (wError)
- debugLogA("Re-starting import sequence failed, error %d", wError);
- else
- {
- setWord("SrvImportID", 0);
- delSetting("ImportTS");
- }
- break;
+ if (wError)
+ debugLogA("Re-starting import sequence failed, error %d", wError);
+ else {
+ setWord("SrvImportID", 0);
+ delSetting("ImportTS");
}
+ break;
+
default:
debugLogA("Server ack cookie type (%d) not recognized.", sc->dwAction);
}
- SAFE_FREE((void**)&sc); // free the memory
+ SAFE_FREE((void**)&sc); // free the memory
return;
}
-
MCONTACT CIcqProto::HContactFromRecordName(const char* szRecordName, int *bAdded)
{
MCONTACT hContact = INVALID_CONTACT_ID;
- if (!IsStringUIN(szRecordName))
- { // probably AIM contact
+ if (!IsStringUIN(szRecordName)) // probably AIM contact
hContact = HContactFromUID(0, szRecordName, bAdded);
- }
- else
- { // this should be ICQ number
+ else { // this should be ICQ number
DWORD dwUin = atoi(szRecordName);
-
hContact = HContactFromUIN(dwUin, bAdded);
}
return hContact;
}
-
int CIcqProto::getServerDataFromItemTLV(oscar_tlv_chain* pChain, unsigned char *buf) /// FIXME: need to keep original order
-{ // get server-list item's TLV data
+{
+ // get server-list item's TLV data
oscar_tlv_chain* list = pChain;
int datalen = 0;
icq_packet pBuf;
@@ -795,14 +679,12 @@ int CIcqProto::getServerDataFromItemTLV(oscar_tlv_chain* pChain, unsigned char * pBuf.wPlace = 0;
pBuf.pData = buf;
- while (list)
- { // collect non-standard TLVs and save them to DB
+ while (list) { // collect non-standard TLVs and save them to DB
if (list->tlv.wType != SSI_TLV_AWAITING_AUTH &&
- list->tlv.wType != SSI_TLV_NAME &&
- list->tlv.wType != SSI_TLV_COMMENT &&
- list->tlv.wType != SSI_TLV_METAINFO_TOKEN &&
- list->tlv.wType != SSI_TLV_METAINFO_TIME)
- { // only TLVs which we do not handle on our own
+ list->tlv.wType != SSI_TLV_NAME &&
+ list->tlv.wType != SSI_TLV_COMMENT &&
+ list->tlv.wType != SSI_TLV_METAINFO_TOKEN &&
+ list->tlv.wType != SSI_TLV_METAINFO_TIME) { // only TLVs which we do not handle on our own
packTLV(&pBuf, list->tlv.wType, list->tlv.wLen, list->tlv.pData);
datalen += list->tlv.wLen + 4;
@@ -812,7 +694,6 @@ int CIcqProto::getServerDataFromItemTLV(oscar_tlv_chain* pChain, unsigned char * return datalen;
}
-
void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, serverthread_info *info)
{
BYTE bySSIVersion;
@@ -854,76 +735,58 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server wLen -= 2;
debugLogA("SSI: number of entries is %u, version is %u", wRecordCount, bySSIVersion);
-
// Loop over all items in the packet
- for (wRecord = 0; wRecord < wRecordCount; wRecord++)
- {
+ for (wRecord = 0; wRecord < wRecordCount; wRecord++) {
debugLogA("SSI: parsing record %u", wRecord + 1);
- if (wLen < 10)
- { // minimum: name length (zero), group ID, item ID, empty TLV
+ if (wLen < 10) { // minimum: name length (zero), group ID, item ID, empty TLV
debugLogA("Warning: SSI parsing error (%d)", 0);
break;
}
- if (!unpackServerListItem(&buf, &wLen, szRecordName, &wGroupId, &wItemId, &wTlvType, &wTlvLength))
- { // unpack basic structure
+ if (!unpackServerListItem(&buf, &wLen, szRecordName, &wGroupId, &wItemId, &wTlvType, &wTlvLength)) { // unpack basic structure
debugLogA("Warning: SSI parsing error (%d)", 1);
break;
}
debugLogA("Name: '%s', GroupID: %u, EntryID: %u, EntryType: %u, TLVlength: %u",
- szRecordName, wGroupId, wItemId, wTlvType, wTlvLength);
+ szRecordName, wGroupId, wItemId, wTlvType, wTlvLength);
- if (wLen < wTlvLength)
- {
+ if (wLen < wTlvLength) {
debugLogA("Warning: SSI parsing error (%d)", 2);
break;
}
// Initialize the tlv chain
- if (wTlvLength > 0)
- {
+ if (wTlvLength > 0) {
pChain = readIntoTLVChain(&buf, wTlvLength, 0);
wLen -= wTlvLength;
}
- else
- {
- pChain = NULL;
- }
-
-
- switch (wTlvType)
- {
+ else pChain = NULL;
+ switch (wTlvType) {
case SSI_ITEM_BUDDY:
{
/* this is a contact */
- MCONTACT hContact;
int bAdded;
+ MCONTACT hContact = HContactFromRecordName(szRecordName, &bAdded);
- hContact = HContactFromRecordName(szRecordName, &bAdded);
-
- if (hContact != INVALID_CONTACT_ID)
- {
+ if (hContact != INVALID_CONTACT_ID) {
int bRegroup = 0;
int bNicked = 0;
- if (bAdded)
- { // Not already on list: added
+ if (bAdded) { // Not already on list: added
debugLogA("SSI added new %s contact '%s'", "ICQ", szRecordName);
AddJustAddedContact(hContact);
}
- else
- { // we should add new contacts and this contact was just added, show it
- if (IsContactJustAdded(hContact))
- {
+ else { // we should add new contacts and this contact was just added, show it
+ if (IsContactJustAdded(hContact)) {
setContactHidden(hContact, 0);
bAdded = 1; // we want details for new contacts
}
- else
- debugLogA("SSI ignoring existing contact '%s'", szRecordName);
+ else debugLogA("SSI ignoring existing contact '%s'", szRecordName);
+
// Contact on server is always on list
db_set_b(hContact, "CList", "NotOnList", 0);
}
@@ -933,26 +796,22 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server setWord(hContact, DBSETTING_SERVLIST_GROUP, wGroupId);
ReserveServerID(wItemId, SSIT_ITEM, 0);
- if (!bAdded && getByte("LoadServerDetails", DEFAULT_SS_LOAD))
- { // check if the contact has been moved on the server
- if (wActiveSrvGroupId != wGroupId || !szActiveSrvGroup)
- {
+ if (!bAdded && getByte("LoadServerDetails", DEFAULT_SS_LOAD)) { // check if the contact has been moved on the server
+ if (wActiveSrvGroupId != wGroupId || !szActiveSrvGroup) {
SAFE_FREE(&szActiveSrvGroup);
szActiveSrvGroup = getServListGroupCListPath(wGroupId);
wActiveSrvGroupId = wGroupId;
}
char *szLocalGroup = getContactCListGroup(hContact);
- if (!strlennull(szLocalGroup))
- { // no CListGroup
+ if (!strlennull(szLocalGroup)) { // no CListGroup
SAFE_FREE(&szLocalGroup);
szLocalGroup = null_strdup(DEFAULT_SS_GROUP);
}
if (strcmpnull(szActiveSrvGroup, szLocalGroup) &&
- (strlennull(szActiveSrvGroup) >= strlennull(szLocalGroup) || (szActiveSrvGroup && _strnicmp(szActiveSrvGroup, szLocalGroup, strlennull(szLocalGroup)))))
- { // contact moved to new group or sub-group or not to master group
+ (strlennull(szActiveSrvGroup) >= strlennull(szLocalGroup) || (szActiveSrvGroup && _strnicmp(szActiveSrvGroup, szLocalGroup, strlennull(szLocalGroup))))) { // contact moved to new group or sub-group or not to master group
bRegroup = 1;
}
if (bRegroup && !stricmpnull(DEFAULT_SS_GROUP, szActiveSrvGroup)) /// TODO: invent something more clever for "root" group
@@ -962,27 +821,21 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server SAFE_FREE(&szLocalGroup);
}
- if (bRegroup || bAdded)
- { // if we should load server details or contact was just added, update its group
- if (wActiveSrvGroupId != wGroupId || !szActiveSrvGroup)
- {
+ if (bRegroup || bAdded) { // if we should load server details or contact was just added, update its group
+ if (wActiveSrvGroupId != wGroupId || !szActiveSrvGroup) {
SAFE_FREE(&szActiveSrvGroup);
szActiveSrvGroup = getServListGroupCListPath(wGroupId);
wActiveSrvGroupId = wGroupId;
}
- if (szActiveSrvGroup)
- { // try to get Miranda Group path from groupid, if succeeded save to db
+ if (szActiveSrvGroup) { // try to get Miranda Group path from groupid, if succeeded save to db
moveContactToCListGroup(hContact, szActiveSrvGroup);
}
}
- if (pChain)
- { // Look for nickname TLV and copy it to the db if necessary
- if (pTLV = pChain->getTLV(SSI_TLV_NAME, 1))
- {
- if (pTLV->pData && (pTLV->wLen > 0))
- {
+ if (pChain) { // Look for nickname TLV and copy it to the db if necessary
+ if (pTLV = pChain->getTLV(SSI_TLV_NAME, 1)) {
+ if (pTLV->pData && (pTLV->wLen > 0)) {
char *pszNick;
WORD wNickLength;
@@ -998,45 +851,35 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server bNicked = 1;
// Write nickname to database
- if (getByte("LoadServerDetails", DEFAULT_SS_LOAD) || bAdded)
- { // if just added contact, save details always - does no harm
+ if (getByte("LoadServerDetails", DEFAULT_SS_LOAD) || bAdded) { // if just added contact, save details always - does no harm
char *szOldNick;
- if (szOldNick = getSettingStringUtf(hContact, "CList", "MyHandle", NULL))
- {
- if ((strcmpnull(szOldNick, pszNick)) && (strlennull(pszNick) > 0))
- { // check if the truncated nick changed, i.e. do not overwrite locally stored longer nick
- if (strlennull(szOldNick) <= strlennull(pszNick) || strncmp(szOldNick, pszNick, null_strcut(szOldNick, MAX_SSI_TLV_NAME_SIZE)))
- {
+ if (szOldNick = getSettingStringUtf(hContact, "CList", "MyHandle", NULL)) {
+ if ((strcmpnull(szOldNick, pszNick)) && (strlennull(pszNick) > 0)) { // check if the truncated nick changed, i.e. do not overwrite locally stored longer nick
+ if (strlennull(szOldNick) <= strlennull(pszNick) || strncmp(szOldNick, pszNick, null_strcut(szOldNick, MAX_SSI_TLV_NAME_SIZE))) {
// Yes, we really do need to delete it first. Otherwise the CLUI nick
// cache isn't updated (I'll look into it)
- db_unset(hContact,"CList","MyHandle");
+ db_unset(hContact, "CList", "MyHandle");
db_set_utf(hContact, "CList", "MyHandle", pszNick);
}
}
SAFE_FREE(&szOldNick);
}
- else if (strlennull(pszNick) > 0)
- {
- db_unset(hContact,"CList","MyHandle");
+ else if (strlennull(pszNick) > 0) {
+ db_unset(hContact, "CList", "MyHandle");
db_set_utf(hContact, "CList", "MyHandle", pszNick);
}
}
SAFE_FREE(&pszNick);
}
- else
- {
- debugLogA("Invalid nickname");
- }
+ else debugLogA("Invalid nickname");
}
if (bAdded && !bNicked)
icq_QueueUser(hContact); // queue user without nick for fast auto info update
// Look for comment TLV and copy it to the db if necessary
- if (pTLV = pChain->getTLV(SSI_TLV_COMMENT, 1))
- {
- if (pTLV->pData && (pTLV->wLen > 0))
- {
+ if (pTLV = pChain->getTLV(SSI_TLV_COMMENT, 1)) {
+ if (pTLV->pData && (pTLV->wLen > 0)) {
char *pszComment;
WORD wCommentLength;
@@ -1051,91 +894,70 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server debugLogA("Comment is '%s'", pszComment);
// Write comment to database
- if (getByte("LoadServerDetails", DEFAULT_SS_LOAD) || bAdded)
- { // if just added contact, save details always - does no harm
+ if (getByte("LoadServerDetails", DEFAULT_SS_LOAD) || bAdded) { // if just added contact, save details always - does no harm
char *szOldComment;
- if (szOldComment = getSettingStringUtf(hContact, "UserInfo", "MyNotes", NULL))
- {
- if ((strcmpnull(szOldComment, pszComment)) && (strlennull(pszComment) > 0))
- { // check if the truncated comment changed, i.e. do not overwrite locally stored longer comment
+ if (szOldComment = getSettingStringUtf(hContact, "UserInfo", "MyNotes", NULL)) {
+ if ((strcmpnull(szOldComment, pszComment)) && (strlennull(pszComment) > 0)) // check if the truncated comment changed, i.e. do not overwrite locally stored longer comment
if (strlennull(szOldComment) <= strlennull(pszComment) || strncmp((char*)szOldComment, (char*)pszComment, null_strcut(szOldComment, MAX_SSI_TLV_COMMENT_SIZE)))
- {
db_set_utf(hContact, "UserInfo", "MyNotes", pszComment);
- }
- }
+
SAFE_FREE((void**)&szOldComment);
}
else if (strlennull(pszComment) > 0)
- {
db_set_utf(hContact, "UserInfo", "MyNotes", pszComment);
- }
}
SAFE_FREE((void**)&pszComment);
}
- else
- {
- debugLogA("Invalid comment");
- }
+ else debugLogA("Invalid comment");
}
// Look for need-authorization TLV
- if (pChain->getTLV(SSI_TLV_AWAITING_AUTH, 1))
- {
+ if (pChain->getTLV(SSI_TLV_AWAITING_AUTH, 1)) {
setByte(hContact, "Auth", 1);
debugLogA("SSI contact need authorization");
}
- else
- {
- setByte(hContact, "Auth", 0);
- }
+ else setByte(hContact, "Auth", 0);
- if (pTLV = pChain->getTLV(SSI_TLV_METAINFO_TOKEN, 1))
- {
+ if (pTLV = pChain->getTLV(SSI_TLV_METAINFO_TOKEN, 1)) {
setSettingBlob(hContact, DBSETTING_METAINFO_TOKEN, pTLV->pData, pTLV->wLen);
if (pChain->getTLV(SSI_TLV_METAINFO_TIME, 1))
setSettingDouble(hContact, DBSETTING_METAINFO_TIME, pChain->getDouble(SSI_TLV_METAINFO_TIME, 1));
debugLogA("SSI contact has meta info token");
}
- else
- {
+ else {
delSetting(hContact, DBSETTING_METAINFO_TOKEN);
delSetting(hContact, DBSETTING_METAINFO_TIME);
}
- { // store server-list item's TLV data
- BYTE* data = (BYTE*)SAFE_MALLOC(wTlvLength);
- int datalen = getServerDataFromItemTLV(pChain, data);
+ { // store server-list item's TLV data
+ BYTE* data = (BYTE*)SAFE_MALLOC(wTlvLength);
+ int datalen = getServerDataFromItemTLV(pChain, data);
- if (datalen > 0)
- setSettingBlob(hContact, DBSETTING_SERVLIST_DATA, data, datalen);
- else
- delSetting(hContact, DBSETTING_SERVLIST_DATA);
+ if (datalen > 0)
+ setSettingBlob(hContact, DBSETTING_SERVLIST_DATA, data, datalen);
+ else
+ delSetting(hContact, DBSETTING_SERVLIST_DATA);
- SAFE_FREE((void**)&data);
- }
+ SAFE_FREE((void**)&data);
+ }
}
}
- else
- { // failed to add or other error
+ else // failed to add or other error
debugLogA("SSI failed to handle %s Item '%s'", "Buddy", szRecordName);
- }
}
break;
case SSI_ITEM_GROUP:
- if ((wGroupId == 0) && (wItemId == 0))
- {
+ if ((wGroupId == 0) && (wItemId == 0)) {
/* list of groups. wTlvType=1, data is TLV(C8) containing list of WORDs which */
/* is the group ids
/* we don't need to use this. Our processing is on-the-fly */
/* this record is always sent first in the first packet only, */
}
- else if (wGroupId != 0)
- {
+ else if (wGroupId != 0) {
/* wGroupId != 0: a group record */
- if (wItemId == 0)
- { /* no item ID: this is a group */
+ if (wItemId == 0) { /* no item ID: this is a group */
/* pszRecordName is the name of the group */
ReserveServerID(wGroupId, SSIT_GROUP, 0);
@@ -1151,15 +973,9 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server /* TLV contains a TLV(C8) with a list of WORDs of contained contact IDs */
/* our processing is good enough that we don't need this duplication */
}
- else
- {
- debugLogA("Unhandled type 0x01, wItemID != 0");
- }
- }
- else
- {
- debugLogA("Unhandled type 0x01");
+ else debugLogA("Unhandled type 0x01, wItemID != 0");
}
+ else debugLogA("Unhandled type 0x01");
break;
case SSI_ITEM_PERMIT:
@@ -1167,23 +983,18 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server /* item on visible list */
/* wItemId not related to contact ID */
/* pszRecordName is the UIN */
- MCONTACT hContact;
int bAdded;
+ MCONTACT hContact = HContactFromRecordName(szRecordName, &bAdded);
- hContact = HContactFromRecordName(szRecordName, &bAdded);
-
- if (hContact != INVALID_CONTACT_ID)
- {
- if (bAdded)
- {
+ if (hContact != INVALID_CONTACT_ID) {
+ if (bAdded) {
debugLogA("SSI added new %s contact '%s'", "Permit", szRecordName);
// It wasn't previously in the list, we hide it so it only appears in the visible list
setContactHidden(hContact, 1);
// Add it to the list, so it can be added properly if proper contact
AddJustAddedContact(hContact);
}
- else
- debugLogA("SSI %s contact already exists '%s'", "Permit", szRecordName);
+ else debugLogA("SSI %s contact already exists '%s'", "Permit", szRecordName);
// Save permit ID
setWord(hContact, DBSETTING_SERVLIST_PERMIT, wItemId);
@@ -1192,10 +1003,8 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server setWord(hContact, "ApparentMode", ID_STATUS_ONLINE);
debugLogA("Visible-contact (%s)", szRecordName);
}
- else
- { // failed to add or other error
+ else { // failed to add or other error
debugLogA("SSI failed to handle %s Item '%s'", "Permit", szRecordName);
-
ReserveServerID(wItemId, SSIT_ITEM, SSIF_UNHANDLED);
}
}
@@ -1206,15 +1015,11 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server /* Item on invisible list */
/* wItemId not related to contact ID */
/* pszRecordName is the UIN */
- MCONTACT hContact;
int bAdded;
+ MCONTACT hContact = HContactFromRecordName(szRecordName, &bAdded);
- hContact = HContactFromRecordName(szRecordName, &bAdded);
-
- if (hContact != INVALID_CONTACT_ID)
- {
- if (bAdded)
- {
+ if (hContact != INVALID_CONTACT_ID) {
+ if (bAdded) {
/* not already on list: added */
debugLogA("SSI added new %s contact '%s'", "Deny", szRecordName);
// It wasn't previously in the list, we hide it so it only appears in the visible list
@@ -1222,8 +1027,7 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server // Add it to the list, so it can be added properly if proper contact
AddJustAddedContact(hContact);
}
- else
- debugLogA("SSI %s contact already exists '%s'", "Deny", szRecordName);
+ else debugLogA("SSI %s contact already exists '%s'", "Deny", szRecordName);
// Save Deny ID
setWord(hContact, DBSETTING_SERVLIST_DENY, wItemId);
@@ -1233,30 +1037,22 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server setWord(hContact, "ApparentMode", ID_STATUS_OFFLINE);
debugLogA("Invisible-contact (%s)", szRecordName);
}
- else
- { // failed to add or other error
+ else { // failed to add or other error
debugLogA("SSI failed to handle %s Item '%s'", "Deny", szRecordName);
-
ReserveServerID(wItemId, SSIT_ITEM, SSIF_UNHANDLED);
}
}
break;
case SSI_ITEM_VISIBILITY: /* My visibility settings */
- {
- BYTE bVisibility;
-
- // Look for visibility TLV
- if (bVisibility = pChain->getByte(SSI_TLV_VISIBILITY, 1))
- { // found it, store the id, we do not need current visibility - we do not rely on it
- setWord(DBSETTING_SERVLIST_PRIVACY, wItemId);
- ReserveServerID(wItemId, SSIT_ITEM, 0);
+ // Look for visibility TLV
+ if (BYTE bVisibility = pChain->getByte(SSI_TLV_VISIBILITY, 1)) { // found it, store the id, we do not need current visibility - we do not rely on it
+ setWord(DBSETTING_SERVLIST_PRIVACY, wItemId);
+ ReserveServerID(wItemId, SSIT_ITEM, 0);
- debugLogA("Visibility is %u", bVisibility);
- }
- else
- ReserveServerID(wItemId, SSIT_ITEM, SSIF_UNHANDLED);
+ debugLogA("Visibility is %u", bVisibility);
}
+ else ReserveServerID(wItemId, SSIT_ITEM, SSIF_UNHANDLED);
break;
case SSI_ITEM_IGNORE:
@@ -1264,15 +1060,11 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server /* item on ignore list */
/* wItemId not related to contact ID */
/* pszRecordName is the UIN */
- MCONTACT hContact;
int bAdded;
+ MCONTACT hContact = HContactFromRecordName(szRecordName, &bAdded);
- hContact = HContactFromRecordName(szRecordName, &bAdded);
-
- if (hContact != INVALID_CONTACT_ID)
- {
- if (bAdded)
- {
+ if (hContact != INVALID_CONTACT_ID) {
+ if (bAdded) {
/* not already on list: add */
debugLogA("SSI added new %s contact '%s'", "Ignore", szRecordName);
// It wasn't previously in the list, we hide it
@@ -1280,8 +1072,7 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server // Add it to the list, so it can be added properly if proper contact
AddJustAddedContact(hContact);
}
- else
- debugLogA("SSI %s contact already exists '%s'", "Ignore", szRecordName);
+ else debugLogA("SSI %s contact already exists '%s'", "Ignore", szRecordName);
// Save Ignore ID
setWord(hContact, DBSETTING_SERVLIST_IGNORE, wItemId);
@@ -1293,10 +1084,8 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server CallService(MS_IGNORE_IGNORE, hContact, IGNOREEVENT_ALL);
debugLogA("Ignore-contact (%s)", szRecordName);
}
- else
- { // failed to add or other error
+ else { // failed to add or other error
debugLogA("SSI failed to handle %s Item '%s'", "Ignore", szRecordName);
-
ReserveServerID(wItemId, SSIT_ITEM, SSIF_UNHANDLED);
}
}
@@ -1309,8 +1098,7 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server break;
case SSI_ITEM_IMPORTTIME:
- if (wGroupId == 0)
- {
+ if (wGroupId == 0) {
/* time our list was first imported */
/* pszRecordName is "Import Time" */
/* data is TLV(13) {TLV(D4) {time_t importTime}} */
@@ -1322,20 +1110,17 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server break;
case SSI_ITEM_BUDDYICON:
- if (wGroupId == 0)
- {
+ if (wGroupId == 0) {
/* our avatar MD5-hash */
/* pszRecordName is "1" */
/* data is TLV(D5) hash */
/* we ignore this, just save the id */
/* cause we get the hash again after login */
- if (!strcmpnull(szRecordName, "12"))
- { // need to handle Photo Item separately
+ if (!strcmpnull(szRecordName, "12")) { // need to handle Photo Item separately
setWord(DBSETTING_SERVLIST_PHOTO, wItemId);
debugLogA("SSI %s item recognized", "Photo");
}
- else
- {
+ else {
setWord(DBSETTING_SERVLIST_AVATAR, wItemId);
debugLogA("SSI %s item recognized", "Avatar");
}
@@ -1344,8 +1129,7 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server break;
case SSI_ITEM_METAINFO:
- if (wGroupId == 0)
- {
+ if (wGroupId == 0) {
/* our meta info token & last update time */
/* pszRecordName is "ICQ-MDIR" */
/* data is TLV(15C) and TLV(15D) */
@@ -1364,8 +1148,7 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server break;
case SSI_ITEM_CLIENTDATA:
- if (wGroupId == 0)
- {
+ if (wGroupId == 0) {
/* ICQ2k ShortcutBar Items */
/* data is TLV(CD) text */
if (wItemId)
@@ -1394,8 +1177,7 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server setWord("SrvRecordCount", (WORD)(wRecord + getWord("SrvRecordCount", 0)));
- if (bIsLastPacket)
- {
+ if (bIsLastPacket) {
// No contacts left to sync
bIsSyncingCL = FALSE;
@@ -1403,8 +1185,7 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server icq_RescanInfoUpdate();
- if (wLen >= 4)
- {
+ if (wLen >= 4) {
DWORD dwLastUpdateTime;
/* finally we get a time_t of the last update time */
@@ -1417,15 +1198,11 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server servlistProcessLogin();
}
- else
- {
- debugLogA("Last packet missed update time...");
- }
- if (getWord("SrvRecordCount", 0) == 0)
- { // we got empty serv-list, create master group
+ else debugLogA("Last packet missed update time...");
+
+ if (getWord("SrvRecordCount", 0) == 0) { // we got empty serv-list, create master group
cookie_servlist_action* ack = (cookie_servlist_action*)SAFE_MALLOC(sizeof(cookie_servlist_action));
- if (ack)
- {
+ if (ack) {
DWORD dwCookie;
ack->dwAction = SSA_GROUP_UPDATE;
@@ -1437,25 +1214,18 @@ void CIcqProto::handleServerCListReply(BYTE *buf, WORD wLen, WORD wFlags, server // serv-list sync finished, clear just added contacts
FlushJustAddedContacts();
}
- else
- {
- debugLogA("Waiting for more packets");
- }
+ else debugLogA("Waiting for more packets");
}
-
void CIcqProto::handleServerCListItemAdd(const char *szRecordName, WORD wGroupId, WORD wItemId, WORD wItemType, oscar_tlv_chain *pItemData)
{
- if (wItemType == SSI_ITEM_IMPORTTIME)
- {
- if (pItemData)
- {
+ if (wItemType == SSI_ITEM_IMPORTTIME) {
+ if (pItemData) {
setDword("ImportTS", pItemData->getDWord(SSI_TLV_TIMESTAMP, 1));
setWord("SrvImportID", wItemId);
ReserveServerID(wItemId, SSIT_ITEM, 0);
debugLogA("Server added Import timestamp to list");
-
return;
}
}
@@ -1463,20 +1233,16 @@ void CIcqProto::handleServerCListItemAdd(const char *szRecordName, WORD wGroupId ReserveServerID(wItemId, wItemType == SSI_ITEM_GROUP ? SSIT_GROUP : SSIT_ITEM, SSIF_UNHANDLED);
}
-
void CIcqProto::handleServerCListItemUpdate(const char *szRecordName, WORD wGroupId, WORD wItemId, WORD wItemType, oscar_tlv_chain *pItemData)
{
MCONTACT hContact = (wItemType == SSI_ITEM_BUDDY || wItemType == SSI_ITEM_DENY || wItemType == SSI_ITEM_PERMIT || wItemType == SSI_ITEM_IGNORE) ? HContactFromRecordName(szRecordName, NULL) : NULL;
- if (hContact != INVALID_CONTACT_ID && wItemType == SSI_ITEM_BUDDY)
- { // a contact was updated on server
- if (pItemData)
- {
- oscar_tlv* pAuth = pItemData->getTLV(SSI_TLV_AWAITING_AUTH, 1);
+ if (hContact != INVALID_CONTACT_ID && wItemType == SSI_ITEM_BUDDY) { // a contact was updated on server
+ if (pItemData) {
+ oscar_tlv *pAuth = pItemData->getTLV(SSI_TLV_AWAITING_AUTH, 1);
BYTE bAuth = getByte(hContact, "Auth", 0);
- if (bAuth && !pAuth)
- { // server authorized our contact
+ if (bAuth && !pAuth) { // server authorized our contact
char str[MAX_PATH];
char msg[MAX_PATH];
char *nick = NickFromHandleUtf(hContact);
@@ -1486,8 +1252,7 @@ void CIcqProto::handleServerCListItemUpdate(const char *szRecordName, WORD wGrou icq_LogMessage(LOG_WARNING, str);
SAFE_FREE(&nick);
}
- else if (!bAuth && pAuth)
- { // server took away authorization of our contact
+ else if (!bAuth && pAuth) { // server took away authorization of our contact
char str[MAX_PATH];
char msg[MAX_PATH];
char *nick = NickFromHandleUtf(hContact);
@@ -1497,16 +1262,14 @@ void CIcqProto::handleServerCListItemUpdate(const char *szRecordName, WORD wGrou icq_LogMessage(LOG_WARNING, str);
SAFE_FREE(&nick);
}
-
- { // update metainfo data
- DBVARIANT dbv = {0};
+ {
+ // update metainfo data
+ DBVARIANT dbv = { 0 };
oscar_tlv *pToken = pItemData->getTLV(SSI_TLV_METAINFO_TOKEN, 1);
oscar_tlv *pTime = pItemData->getTLV(SSI_TLV_METAINFO_TIME, 1);
- if (!getSetting(hContact, DBSETTING_METAINFO_TOKEN, &dbv))
- {
- if (!pToken || dbv.cpbVal != pToken->wLen || memcmp(dbv.pbVal, pToken->pData, dbv.cpbVal))
- {
+ if (!getSetting(hContact, DBSETTING_METAINFO_TOKEN, &dbv)) {
+ if (!pToken || dbv.cpbVal != pToken->wLen || memcmp(dbv.pbVal, pToken->pData, dbv.cpbVal)) {
if (!pToken)
debugLogA("Contact %s, meta info token removed", szRecordName);
else
@@ -1519,8 +1282,7 @@ void CIcqProto::handleServerCListItemUpdate(const char *szRecordName, WORD wGrou db_free(&dbv);
}
- else if (pToken)
- {
+ else if (pToken) {
debugLogA("Contact %s, meta info token added", szRecordName);
// user info was changed, refresh
@@ -1533,8 +1295,8 @@ void CIcqProto::handleServerCListItemUpdate(const char *szRecordName, WORD wGrou if (pTime)
setSettingDouble(hContact, DBSETTING_METAINFO_TIME, pItemData->getDouble(SSI_TLV_METAINFO_TIME, 1));
}
-
- { // update server's data - otherwise consequent operations can fail with 0x0E
+ {
+ // update server's data - otherwise consequent operations can fail with 0x0E
BYTE *data = (BYTE*)_alloca(pItemData->getChainLength());
int datalen = getServerDataFromItemTLV(pItemData, data);
@@ -1545,18 +1307,14 @@ void CIcqProto::handleServerCListItemUpdate(const char *szRecordName, WORD wGrou }
}
}
- else if (wItemType == SSI_ITEM_METAINFO)
- { // owner MetaInfo data updated
- if (pItemData)
- {
- DBVARIANT dbv = {0};
+ else if (wItemType == SSI_ITEM_METAINFO) { // owner MetaInfo data updated
+ if (pItemData) {
+ DBVARIANT dbv = { 0 };
oscar_tlv *pToken = pItemData->getTLV(SSI_TLV_METAINFO_TOKEN, 1);
oscar_tlv *pTime = pItemData->getTLV(SSI_TLV_METAINFO_TIME, 1);
- if (!getSetting(hContact, DBSETTING_METAINFO_TOKEN, &dbv))
- {
- if (!pToken || dbv.cpbVal != pToken->wLen || memcmp(dbv.pbVal, pToken->pData, dbv.cpbVal))
- {
+ if (!getSetting(hContact, DBSETTING_METAINFO_TOKEN, &dbv)) {
+ if (!pToken || dbv.cpbVal != pToken->wLen || memcmp(dbv.pbVal, pToken->pData, dbv.cpbVal)) {
if (!pToken)
debugLogA("Owner meta info token removed");
else
@@ -1572,41 +1330,33 @@ void CIcqProto::handleServerCListItemUpdate(const char *szRecordName, WORD wGrou setSettingDouble(hContact, DBSETTING_METAINFO_TIME, pItemData->getDouble(SSI_TLV_METAINFO_TIME, 1));
}
}
- else if (wItemType == SSI_ITEM_GROUP)
- { // group updated
+ else if (wItemType == SSI_ITEM_GROUP) // group updated
debugLogA("Server updated our group \"%s\" on list", szRecordName);
- }
}
-
void CIcqProto::handleServerCListItemDelete(const char *szRecordName, WORD wGroupId, WORD wItemId, WORD wItemType, oscar_tlv_chain *pItemData)
{
MCONTACT hContact = (wItemType == SSI_ITEM_BUDDY || wItemType == SSI_ITEM_DENY || wItemType == SSI_ITEM_PERMIT || wItemType == SSI_ITEM_IGNORE) ? HContactFromRecordName(szRecordName, NULL) : NULL;
- if (hContact != INVALID_CONTACT_ID && wItemType == SSI_ITEM_BUDDY)
- { // a contact was removed from our list
- if (getWord(hContact, DBSETTING_SERVLIST_ID, 0) == wItemId)
- {
+ if (hContact != INVALID_CONTACT_ID && wItemType == SSI_ITEM_BUDDY) { // a contact was removed from our list
+ if (getWord(hContact, DBSETTING_SERVLIST_ID, 0) == wItemId) {
delSetting(hContact, DBSETTING_SERVLIST_ID);
delSetting(hContact, DBSETTING_SERVLIST_GROUP);
delSetting(hContact, "Auth");
- {
- char str[MAX_PATH];
- char msg[MAX_PATH];
- char *nick = NickFromHandleUtf(hContact);
+ char str[MAX_PATH];
+ char msg[MAX_PATH];
+ char *nick = NickFromHandleUtf(hContact);
- mir_snprintf(str, MAX_PATH, ICQTranslateUtfStatic(LPGEN("User \"%s\" was removed from server list."), msg, MAX_PATH), nick);
- icq_LogMessage(LOG_WARNING, str);
- SAFE_FREE(&nick);
- }
+ mir_snprintf(str, MAX_PATH, ICQTranslateUtfStatic(LPGEN("User \"%s\" was removed from server list."), msg, MAX_PATH), nick);
+ icq_LogMessage(LOG_WARNING, str);
+ SAFE_FREE(&nick);
}
}
// Release server-list ID
FreeServerID(wItemId, wItemType == SSI_ITEM_GROUP ? SSIT_GROUP : SSIT_ITEM);
}
-
void CIcqProto::handleRecvAuthRequest(unsigned char *buf, WORD wLen)
{
DWORD dwUin;
@@ -1630,7 +1380,7 @@ void CIcqProto::handleRecvAuthRequest(unsigned char *buf, WORD wLen) PROTORECVEVENT pre = { 0 };
pre.timestamp = time(NULL);
- pre.lParam = sizeof(DWORD)*2 + 5;
+ pre.lParam = sizeof(DWORD) * 2 + 5;
// Prepare reason
char *szReason = (char*)SAFE_MALLOC(wReasonLen + 1);
int nReasonLen = 0;
@@ -1721,8 +1471,7 @@ void CIcqProto::handleRecvAdded(unsigned char *buf, WORD wLen) nNickLen = strlennull(szNick);
}
}
- else
- nNickLen = strlennull(szUid);
+ else nNickLen = strlennull(szUid);
cbBlob += nNickLen;
@@ -1747,7 +1496,6 @@ void CIcqProto::handleRecvAdded(unsigned char *buf, WORD wLen) AddEvent(NULL, EVENTTYPE_ADDED, time(NULL), 0, cbBlob, pBlob);
}
-
void CIcqProto::handleRecvAuthResponse(unsigned char *buf, WORD wLen)
{
DWORD dwUin;
@@ -1785,7 +1533,6 @@ void CIcqProto::handleRecvAuthResponse(unsigned char *buf, WORD wLen) }
switch (bResponse) {
-
case 0:
debugLogA("Authorization request %s by %s", "denied", strUID(dwUin, szUid));
// TODO: Add to system history as soon as new auth system is ready
@@ -1805,7 +1552,6 @@ void CIcqProto::handleRecvAuthResponse(unsigned char *buf, WORD wLen) SAFE_FREE(&szNick);
}
-
// Updates the visibility code used while in SSI mode. If a server ID is
// not stored in the local DB, a new ID will be added to the server list.
//
@@ -1837,14 +1583,11 @@ void CIcqProto::updateServVisibilityCode(BYTE bCode) wVisibilityID = GenerateServerID(SSIT_ITEM, 0);
setWord(DBSETTING_SERVLIST_PRIVACY, wVisibilityID);
wCommand = ICQ_LISTS_ADDTOLIST;
-#ifdef _DEBUG
+
debugLogA("Made new srvVisibilityID, id is %u, code is %u", wVisibilityID, bCode);
-#endif
}
else {
-#ifdef _DEBUG
debugLogA("Reused srvVisibilityID, id is %u, code is %u", wVisibilityID, bCode);
-#endif
wCommand = ICQ_LISTS_UPDATEGROUP;
}
@@ -1853,6 +1596,7 @@ void CIcqProto::updateServVisibilityCode(BYTE bCode) debugLogA("Cookie alloc failure.");
return; // out of memory, go away
}
+
ack->dwAction = SSA_VISIBILITY; // update visibility
dwCookie = AllocateCookie(CKT_SERVERLIST, wCommand, 0, ack); // take cookie
@@ -1924,14 +1668,10 @@ void CIcqProto::updateServAvatarHash(BYTE *pHash, int size) // No, create a new random ID
wAvatarID = GenerateServerID(SSIT_ITEM, 0);
wCommand = ICQ_LISTS_ADDTOLIST;
-#ifdef _DEBUG
debugLogA("Made new srvAvatarID, id is %u", wAvatarID);
-#endif
}
else {
-#ifdef _DEBUG
debugLogA("Reused srvAvatarID, id is %u", wAvatarID);
-#endif
wCommand = ICQ_LISTS_UPDATEGROUP;
}
@@ -2011,7 +1751,5 @@ void CIcqProto::sendRosterAck(void) packFNACHeader(&packet, ICQ_LISTS_FAMILY, ICQ_LISTS_GOTLIST);
sendServPacket(&packet);
-#ifdef _DEBUG
debugLogA("Sent SNAC(x13,x07) - CLI_ROSTERACK");
-#endif
}
diff --git a/protocols/IcqOscarJ/src/fam_15icqserver.cpp b/protocols/IcqOscarJ/src/fam_15icqserver.cpp index 49de606e3c..eb33033129 100644 --- a/protocols/IcqOscarJ/src/fam_15icqserver.cpp +++ b/protocols/IcqOscarJ/src/fam_15icqserver.cpp @@ -28,7 +28,6 @@ void CIcqProto::handleIcqExtensionsFam(BYTE *pBuffer, WORD wBufferLength, snac_header* pSnacHeader)
{
switch (pSnacHeader->wSubtype) {
-
case ICQ_META_ERROR:
handleExtensionError(pBuffer, wBufferLength);
break;
@@ -53,63 +52,52 @@ void CIcqProto::handleExtensionError(BYTE *buf, WORD wPackLen) if (wPackLen >= 2 && wPackLen <= 6)
unpackWord(&buf, &wErrorCode);
- else
- { // TODO: cookies need to be handled and freed here on error
- oscar_tlv_chain *chain = NULL;
-
+ else {
+ // TODO: cookies need to be handled and freed here on error
unpackWord(&buf, &wErrorCode);
wPackLen -= 2;
- chain = readIntoTLVChain(&buf, wPackLen, 0);
- if (chain)
- {
+
+ oscar_tlv_chain *chain = readIntoTLVChain(&buf, wPackLen, 0);
+ if (chain) {
oscar_tlv* pTLV;
pTLV = chain->getTLV(0x21, 1); // get meta error data
- if (pTLV && pTLV->wLen >= 8)
- {
+ if (pTLV && pTLV->wLen >= 8) {
BYTE *pBuffer = pTLV->pData;
WORD wData;
pBuffer += 6;
unpackLEWord(&pBuffer, &wData); // get request type
- switch (wData)
- {
+ switch (wData) {
case CLI_META_INFO_REQ:
- if (pTLV->wLen >= 12)
- {
+ if (pTLV->wLen >= 12) {
WORD wSubType;
WORD wCookie;
unpackWord(&pBuffer, &wCookie);
unpackLEWord(&pBuffer, &wSubType);
// more sofisticated detection, send ack
- if (wSubType == META_REQUEST_FULL_INFO)
- {
+ if (wSubType == META_REQUEST_FULL_INFO) {
MCONTACT hContact;
cookie_fam15_data *pCookieData = NULL;
int foundCookie = FindCookie(wCookie, &hContact, (void**)&pCookieData);
- if (foundCookie && pCookieData)
- {
- ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_FAILED, (HANDLE)1 ,0);
+ if (foundCookie && pCookieData) {
+ ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_FAILED, (HANDLE)1, 0);
ReleaseCookie(wCookie); // we do not leak cookie and memory
}
debugLogA("Full info request error 0x%02x received", wErrorCode);
}
- else if (wSubType == META_SET_PASSWORD_REQ)
- {
+ else if (wSubType == META_SET_PASSWORD_REQ) {
// failed to change user password, report to UI
ProtoBroadcastAck(NULL, ACKTYPE_SETINFO, ACKRESULT_FAILED, (HANDLE)wCookie, 0);
debugLogA("Meta change password request failed, error 0x%02x", wErrorCode);
}
- else
- debugLogA("Meta request error 0x%02x received", wErrorCode);
+ else debugLogA("Meta request error 0x%02x received", wErrorCode);
}
- else
- debugLogA("Meta request error 0x%02x received", wErrorCode);
-
+ else debugLogA("Meta request error 0x%02x received", wErrorCode);
break;
default:
@@ -124,51 +112,40 @@ void CIcqProto::handleExtensionError(BYTE *buf, WORD wPackLen) LogFamilyError(ICQ_EXTENSIONS_FAMILY, wErrorCode);
}
-
void CIcqProto::handleExtensionServerInfo(BYTE *buf, WORD wPackLen, WORD wFlags)
{
- oscar_tlv_chain *chain;
- oscar_tlv *dataTlv;
-
// The entire packet is encapsulated in a TLV type 1
- chain = readIntoTLVChain(&buf, wPackLen, 0);
- if (chain == NULL)
- {
+ oscar_tlv_chain *chain = readIntoTLVChain(&buf, wPackLen, 0);
+ if (chain == NULL) {
debugLogA("Error: Broken snac 15/3 %d", 1);
return;
}
- dataTlv = chain->getTLV(0x0001, 1);
- if (dataTlv == NULL)
- {
+ oscar_tlv *dataTlv = chain->getTLV(0x0001, 1);
+ if (dataTlv == NULL) {
disposeChain(&chain);
debugLogA("Error: Broken snac 15/3 %d", 2);
return;
}
+
BYTE *databuf = dataTlv->pData;
wPackLen -= 4;
_ASSERTE(dataTlv->wLen == wPackLen);
_ASSERTE(wPackLen >= 10);
- if ((dataTlv->wLen == wPackLen) && (wPackLen >= 10))
- {
- WORD wBytesRemaining;
- WORD wRequestType;
- WORD wCookie;
+ if ((dataTlv->wLen == wPackLen) && (wPackLen >= 10)) {
DWORD dwMyUin;
-
+ WORD wBytesRemaining, wCookie, wRequestType;
unpackLEWord(&databuf, &wBytesRemaining);
unpackLEDWord(&databuf, &dwMyUin);
unpackLEWord(&databuf, &wRequestType);
unpackWord(&databuf, &wCookie);
_ASSERTE(wBytesRemaining == (wPackLen - 2));
- if (wBytesRemaining == (wPackLen - 2))
- {
- wPackLen -= 10;
- switch (wRequestType)
- {
+ if (wBytesRemaining == (wPackLen - 2)) {
+ wPackLen -= 10;
+ switch (wRequestType) {
case SRV_META_INFO_REPLY: // SRV_META request replies
handleExtensionMetaResponse(databuf, wPackLen, wCookie, wFlags);
break;
@@ -179,8 +156,7 @@ void CIcqProto::handleExtensionServerInfo(BYTE *buf, WORD wPackLen, WORD wFlags) }
}
}
- else
- debugLogA("Error: Broken snac 15/3 %d", 3);
+ else debugLogA("Error: Broken snac 15/3 %d", 3);
if (chain)
disposeChain(&chain);
@@ -193,8 +169,7 @@ void CIcqProto::handleExtensionMetaResponse(BYTE *databuf, WORD wPacketLen, WORD BYTE bResultCode;
_ASSERTE(wPacketLen >= 3);
- if (wPacketLen >= 3)
- {
+ if (wPacketLen >= 3) {
// Reply subtype
unpackLEWord(&databuf, &wReplySubtype);
wPacketLen -= 2;
@@ -203,8 +178,7 @@ void CIcqProto::handleExtensionMetaResponse(BYTE *databuf, WORD wPacketLen, WORD unpackByte(&databuf, &bResultCode);
wPacketLen -= 1;
- switch (wReplySubtype)
- {
+ switch (wReplySubtype) {
case META_SET_PASSWORD_ACK:
parseUserInfoUpdateAck(databuf, wPacketLen, wCookie, wReplySubtype, bResultCode);
break;
@@ -226,32 +200,27 @@ void CIcqProto::handleExtensionMetaResponse(BYTE *databuf, WORD wPacketLen, WORD ProtoBroadcastAck(NULL, ICQACKTYPE_SMS, ACKRESULT_FAILED, (HANDLE)wCookie, (LPARAM)pszInfo);
FreeCookie(wCookie);
- break;
}
break;
case META_SMS_DELIVERY_RECEIPT:
// Todo: This overlaps with META_SET_AFFINFO_ACK.
// Todo: Check what happens if result != A
- if (wPacketLen > 8)
- {
+ if (wPacketLen > 8) {
WORD wNetworkNameLen;
WORD wAckLen;
char *pszInfo;
-
databuf += 6; // Some unknowns
wPacketLen -= 6;
unpackWord(&databuf, &wNetworkNameLen);
- if (wPacketLen >= (wNetworkNameLen + 2))
- {
+ if (wPacketLen >= (wNetworkNameLen + 2)) {
databuf += wNetworkNameLen;
wPacketLen -= wNetworkNameLen;
unpackWord(&databuf, &wAckLen);
- if (pszInfo = (char *)_alloca(wAckLen + 1))
- {
+ if (pszInfo = (char *)_alloca(wAckLen + 1)) {
// Terminate buffer
if (wAckLen > 0)
memcpy(pszInfo, databuf, wAckLen);
@@ -261,7 +230,7 @@ void CIcqProto::handleExtensionMetaResponse(BYTE *databuf, WORD wPacketLen, WORD FreeCookie(wCookie);
// Parsing success
- break;
+ break;
}
}
}
@@ -299,7 +268,6 @@ void CIcqProto::handleExtensionMetaResponse(BYTE *databuf, WORD wPacketLen, WORD default:
debugLogA("Warning: Ignored 15/03 replysubtype x%x", wReplySubtype);
- // _ASSERTE(0);
break;
}
@@ -311,48 +279,37 @@ void CIcqProto::handleExtensionMetaResponse(BYTE *databuf, WORD wPacketLen, WORD debugLogA("Warning: Broken 15/03 ExtensionMetaResponse");
}
-
void CIcqProto::ReleaseSearchCookie(DWORD dwCookie, cookie_search *pCookie)
{
- if (pCookie)
- {
+ if (pCookie) {
FreeCookie(dwCookie);
- if (pCookie->dwMainId)
- {
- if (pCookie->dwStatus)
- {
+ if (pCookie->dwMainId) {
+ if (pCookie->dwStatus) {
SAFE_FREE((void**)&pCookie);
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)dwCookie, 0);
}
- else
- pCookie->dwStatus = 1;
+ else pCookie->dwStatus = 1;
}
- else
- {
+ else {
SAFE_FREE((void**)&pCookie);
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)dwCookie, 0);
}
}
- else
- ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)dwCookie, 0);
+ else ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)dwCookie, 0);
}
-
void CIcqProto::parseSearchReplies(unsigned char *databuf, WORD wPacketLen, WORD wCookie, WORD wReplySubtype, BYTE bResultCode)
{
BYTE bParsingOK = FALSE; // For debugging purposes only
BOOL bLastUser = FALSE;
- cookie_search *pCookie;
- if (!FindCookie(wCookie, NULL, (void**)&pCookie))
- {
+ cookie_search *pCookie;
+ if (!FindCookie(wCookie, NULL, (void**)&pCookie)) {
debugLogA("Warning: Received unexpected search reply");
pCookie = NULL;
}
- switch (wReplySubtype)
- {
-
+ switch (wReplySubtype) {
case SRV_LAST_USER_FOUND: // Search: last user found reply
bLastUser = TRUE;
@@ -362,9 +319,8 @@ void CIcqProto::parseSearchReplies(unsigned char *databuf, WORD wPacketLen, WORD else
debugLogA("SNAC(0x15,0x3): Search reply");
- if (bResultCode == 0xA)
- {
- ICQSEARCHRESULT sr = {0};
+ if (bResultCode == 0xA) {
+ ICQSEARCHRESULT sr = { 0 };
DWORD dwUin;
char szUin[UINMAXLEN];
WORD wLen;
@@ -395,15 +351,13 @@ void CIcqProto::parseSearchReplies(unsigned char *databuf, WORD wPacketLen, WORD break;
unpackLEWord(&databuf, &wLen);
wPacketLen -= 2;
- if (wLen > 0)
- {
- if (wPacketLen < wLen || (databuf[wLen-1] != 0))
+ if (wLen > 0) {
+ if (wPacketLen < wLen || (databuf[wLen - 1] != 0))
break;
sr.hdr.nick = (FNAMECHAR*)databuf;
databuf += wLen;
}
- else
- {
+ else {
sr.hdr.nick = NULL;
}
@@ -412,51 +366,39 @@ void CIcqProto::parseSearchReplies(unsigned char *databuf, WORD wPacketLen, WORD break;
unpackLEWord(&databuf, &wLen);
wPacketLen -= 2;
- if (wLen > 0)
- {
- if (wPacketLen < wLen || (databuf[wLen-1] != 0))
+ if (wLen > 0) {
+ if (wPacketLen < wLen || (databuf[wLen - 1] != 0))
break;
sr.hdr.firstName = (FNAMECHAR*)databuf;
databuf += wLen;
}
- else
- {
- sr.hdr.firstName = NULL;
- }
+ else sr.hdr.firstName = NULL;
// Last name
if (wPacketLen < 2)
break;
unpackLEWord(&databuf, &wLen);
wPacketLen -= 2;
- if (wLen > 0)
- {
- if (wPacketLen < wLen || (databuf[wLen-1] != 0))
+ if (wLen > 0) {
+ if (wPacketLen < wLen || (databuf[wLen - 1] != 0))
break;
sr.hdr.lastName = (FNAMECHAR*)databuf;
databuf += wLen;
}
- else
- {
- sr.hdr.lastName = NULL;
- }
+ else sr.hdr.lastName = NULL;
// E-mail name
if (wPacketLen < 2)
break;
unpackLEWord(&databuf, &wLen);
wPacketLen -= 2;
- if (wLen > 0)
- {
- if (wPacketLen < wLen || (databuf[wLen-1] != 0))
+ if (wLen > 0) {
+ if (wPacketLen < wLen || (databuf[wLen - 1] != 0))
break;
sr.hdr.email = (FNAMECHAR*)databuf;
databuf += wLen;
}
- else
- {
- sr.hdr.email = NULL;
- }
+ else sr.hdr.email = NULL;
// Authentication needed flag
if (wPacketLen < 1)
@@ -467,10 +409,8 @@ void CIcqProto::parseSearchReplies(unsigned char *databuf, WORD wPacketLen, WORD ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)wCookie, (LPARAM)&sr);
// Broadcast "Last result" ack if this was the last user found
- if (wReplySubtype == SRV_LAST_USER_FOUND)
- {
- if (wPacketLen>=10)
- {
+ if (wReplySubtype == SRV_LAST_USER_FOUND) {
+ if (wPacketLen >= 10) {
DWORD dwLeft;
databuf += 5;
@@ -482,8 +422,7 @@ void CIcqProto::parseSearchReplies(unsigned char *databuf, WORD wPacketLen, WORD }
bParsingOK = TRUE;
}
- else
- {
+ else {
// Failed search
debugLogA("SNAC(0x15,0x3): Search error %u", bResultCode);
@@ -501,19 +440,16 @@ void CIcqProto::parseSearchReplies(unsigned char *databuf, WORD wPacketLen, WORD }
// For debugging purposes only
- if (!bParsingOK)
- {
+ if (!bParsingOK) {
debugLogA("Warning: Parsing error in 15/03 search reply type x%x", wReplySubtype);
_ASSERTE(!bParsingOK);
}
}
-
void CIcqProto::parseUserInfoUpdateAck(unsigned char *databuf, WORD wPacketLen, WORD wCookie, WORD wReplySubtype, BYTE bResultCode)
{
switch (wReplySubtype) {
case META_SET_PASSWORD_ACK: // Set user password server ack
-
if (bResultCode == 0xA)
ProtoBroadcastAck(NULL, ACKTYPE_SETINFO, ACKRESULT_SUCCESS, (HANDLE)wCookie, 0);
else
@@ -528,52 +464,56 @@ void CIcqProto::parseUserInfoUpdateAck(unsigned char *databuf, WORD wPacketLen, }
}
-
-UserInfoRecordItem rEmail[] = {
- {0x64, DBVT_UTF8, "e-mail%u"}
+UserInfoRecordItem rEmail[] =
+{
+ { 0x64, DBVT_UTF8, "e-mail%u" }
};
-UserInfoRecordItem rAddress[] = {
- {0x64, DBVT_UTF8, "Street"},
- {0x6E, DBVT_UTF8, "City"},
- {0x78, DBVT_UTF8, "State"},
- {0x82, DBVT_UTF8, "ZIP"},
- {0x8C, DBVT_WORD, "Country"}
+UserInfoRecordItem rAddress[] =
+{
+ { 0x64, DBVT_UTF8, "Street" },
+ { 0x6E, DBVT_UTF8, "City" },
+ { 0x78, DBVT_UTF8, "State" },
+ { 0x82, DBVT_UTF8, "ZIP" },
+ { 0x8C, DBVT_WORD, "Country" }
};
-UserInfoRecordItem rOriginAddress[] = {
- {0x64, DBVT_UTF8, "OriginStreet"},
- {0x6E, DBVT_UTF8, "OriginCity"},
- {0x78, DBVT_UTF8, "OriginState"},
- {0x8C, DBVT_WORD, "OriginCountry"}
+UserInfoRecordItem rOriginAddress[] =
+{
+ { 0x64, DBVT_UTF8, "OriginStreet" },
+ { 0x6E, DBVT_UTF8, "OriginCity" },
+ { 0x78, DBVT_UTF8, "OriginState" },
+ { 0x8C, DBVT_WORD, "OriginCountry" }
};
-UserInfoRecordItem rCompany[] = {
- {0x64, DBVT_UTF8, "CompanyPosition"},
- {0x6E, DBVT_UTF8, "Company"},
- {0x7D, DBVT_UTF8, "CompanyDepartment"},
- {0x78, DBVT_UTF8, "CompanyHomepage"},
- {0x82, DBVT_WORD, "CompanyIndustry"},
- {0xAA, DBVT_UTF8, "CompanyStreet"},
- {0xB4, DBVT_UTF8, "CompanyCity"},
- {0xBE, DBVT_UTF8, "CompanyState"},
- {0xC8, DBVT_UTF8, "CompanyZIP"},
- {0xD2, DBVT_WORD, "CompanyCountry"}
+UserInfoRecordItem rCompany[] =
+{
+ { 0x64, DBVT_UTF8, "CompanyPosition" },
+ { 0x6E, DBVT_UTF8, "Company" },
+ { 0x7D, DBVT_UTF8, "CompanyDepartment" },
+ { 0x78, DBVT_UTF8, "CompanyHomepage" },
+ { 0x82, DBVT_WORD, "CompanyIndustry" },
+ { 0xAA, DBVT_UTF8, "CompanyStreet" },
+ { 0xB4, DBVT_UTF8, "CompanyCity" },
+ { 0xBE, DBVT_UTF8, "CompanyState" },
+ { 0xC8, DBVT_UTF8, "CompanyZIP" },
+ { 0xD2, DBVT_WORD, "CompanyCountry" }
};
-UserInfoRecordItem rEducation[] = {
- {0x64, DBVT_WORD, "StudyLevel"},
- {0x6E, DBVT_UTF8, "StudyInstitute"},
- {0x78, DBVT_UTF8, "StudyDegree"},
- {0x8C, DBVT_WORD, "StudyYear"}
+UserInfoRecordItem rEducation[] =
+{
+ { 0x64, DBVT_WORD, "StudyLevel" },
+ { 0x6E, DBVT_UTF8, "StudyInstitute" },
+ { 0x78, DBVT_UTF8, "StudyDegree" },
+ { 0x8C, DBVT_WORD, "StudyYear" }
};
-UserInfoRecordItem rInterest[] = {
- {0x64, DBVT_UTF8, "Interest%uText"},
- {0x6E, DBVT_WORD, "Interest%uCat"}
+UserInfoRecordItem rInterest[] =
+{
+ { 0x64, DBVT_UTF8, "Interest%uText" },
+ { 0x6E, DBVT_WORD, "Interest%uCat" }
};
-
int CIcqProto::parseUserInfoRecord(MCONTACT hContact, oscar_tlv *pData, UserInfoRecordItem pRecordDef[], int nRecordDef, int nMaxRecords)
{
int nRecords = 0;
@@ -589,7 +529,6 @@ int CIcqProto::parseUserInfoRecord(MCONTACT hContact, oscar_tlv *pData, UserInfo for (int i = 0; i < nRecordDef; i++) {
char szItemKey[MAX_PATH];
-
mir_snprintf(szItemKey, MAX_PATH, pRecordDef[i].szDbSetting, nRecords);
switch (pRecordDef[i].dbType) {
@@ -626,19 +565,17 @@ int CIcqProto::parseUserInfoRecord(MCONTACT hContact, oscar_tlv *pData, UserInfo void CIcqProto::handleDirectoryQueryResponse(BYTE *databuf, WORD wPacketLen, WORD wCookie, WORD wReplySubtype, WORD wFlags)
{
WORD wBytesRemaining = 0;
- snac_header requestSnac = {0};
+ snac_header requestSnac = { 0 };
BYTE requestResult;
-#ifdef _DEBUG
debugLogA("Received directory query response");
-#endif
+
if (wPacketLen >= 2)
unpackLEWord(&databuf, &wBytesRemaining);
wPacketLen -= 2;
_ASSERTE(wPacketLen == wBytesRemaining);
- if (!unpackSnacHeader(&requestSnac, &databuf, &wPacketLen) || !requestSnac.bValid)
- {
+ if (!unpackSnacHeader(&requestSnac, &databuf, &wPacketLen) || !requestSnac.bValid) {
debugLogA("Error: Failed to parse directory response");
return;
}
@@ -646,54 +583,49 @@ void CIcqProto::handleDirectoryQueryResponse(BYTE *databuf, WORD wPacketLen, WOR cookie_directory_data *pCookieData;
MCONTACT hContact;
// check request cookie
- if (!FindCookie(wCookie, &hContact, (void**)&pCookieData) || !pCookieData)
- {
+ if (!FindCookie(wCookie, &hContact, (void**)&pCookieData) || !pCookieData) {
debugLogA("Warning: Ignoring unrequested directory reply type (x%x, x%x)", requestSnac.wFamily, requestSnac.wSubtype);
return;
}
/// FIXME: we should really check the snac contents according to cookie data here ??
// Check if this is the last packet for this request
- BOOL bMoreDataFollows = wFlags&0x0001 && requestSnac.wFlags&0x0001;
+ BOOL bMoreDataFollows = wFlags & 0x0001 && requestSnac.wFlags & 0x0001;
- if (wPacketLen >= 3)
+ if (wPacketLen >= 3)
unpackByte(&databuf, &requestResult);
- else
- {
+ else {
debugLogA("Error: Malformed directory response");
if (!bMoreDataFollows)
ReleaseCookie(wCookie);
return;
}
- if (requestResult != 1 && requestResult != 4)
- {
+
+ if (requestResult != 1 && requestResult != 4) {
debugLogA("Error: Directory request failed, status %u", requestResult);
- if (!bMoreDataFollows)
- {
+ if (!bMoreDataFollows) {
if (pCookieData->bRequestType == DIRECTORYREQUEST_INFOUSER)
- ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_FAILED, (HANDLE)1 ,0);
+ ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_FAILED, (HANDLE)1, 0);
else if (pCookieData->bRequestType == DIRECTORYREQUEST_SEARCH)
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)wCookie, 0); // should report error here, but Find/Add module does not support that
ReleaseCookie(wCookie);
}
return;
}
- WORD wLen;
+ WORD wLen;
unpackWord(&databuf, &wLen);
wPacketLen -= 3;
if (wLen)
debugLogA("Warning: Data in error message present!");
- if (wPacketLen <= 0x16)
- { // sanity check
+ if (wPacketLen <= 0x16) { // sanity check
debugLogA("Error: Malformed directory response");
- if (!bMoreDataFollows)
- {
+ if (!bMoreDataFollows) {
if (pCookieData->bRequestType == DIRECTORYREQUEST_INFOUSER)
- ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_FAILED, (HANDLE)1 ,0);
+ ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_FAILED, (HANDLE)1, 0);
else if (pCookieData->bRequestType == DIRECTORYREQUEST_SEARCH)
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)wCookie, 0); // should report error here, but Find/Add module does not support that
ReleaseCookie(wCookie);
@@ -715,32 +647,28 @@ void CIcqProto::handleDirectoryQueryResponse(BYTE *databuf, WORD wPacketLen, WOR if (pCookieData->bRequestType == DIRECTORYREQUEST_SEARCH && !bMoreDataFollows)
debugLogA("Directory Search: %d contacts found (%u pages)", dwItemCount, wPageCount);
- if (wPacketLen <= 2)
- { // sanity check, block expected
+ if (wPacketLen <= 2) { // sanity check, block expected
debugLogA("Error: Malformed directory response");
- if (!bMoreDataFollows)
- {
+ if (!bMoreDataFollows) {
if (pCookieData->bRequestType == DIRECTORYREQUEST_INFOUSER)
- ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_FAILED, (HANDLE)1 ,0);
+ ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_FAILED, (HANDLE)1, 0);
else if (pCookieData->bRequestType == DIRECTORYREQUEST_SEARCH)
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)wCookie, 0); // should report error here, but Find/Add module does not support that
ReleaseCookie(wCookie);
}
return;
}
- WORD wData;
+ WORD wData;
unpackWord(&databuf, &wData); // This probably the count of items following (a block)
wPacketLen -= 2;
- if (wPacketLen >= 2 && wData >= 1)
- {
+ if (wPacketLen >= 2 && wData >= 1) {
unpackWord(&databuf, &wLen); // This is the size of the first item
wPacketLen -= 2;
}
- if (wData == 0 && pCookieData->bRequestType == DIRECTORYREQUEST_SEARCH)
- {
+ if (wData == 0 && pCookieData->bRequestType == DIRECTORYREQUEST_SEARCH) {
debugLogA("Directory Search: No contacts found");
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)wCookie, 0);
ReleaseCookie(wCookie);
@@ -748,52 +676,46 @@ void CIcqProto::handleDirectoryQueryResponse(BYTE *databuf, WORD wPacketLen, WOR }
_ASSERTE(wData == 1 && wPacketLen == wLen);
- if (wData != 1 || wPacketLen != wLen)
- {
+ if (wData != 1 || wPacketLen != wLen) {
debugLogA("Error: Malformed directory response (missing data)");
- if (!bMoreDataFollows)
- {
+ if (!bMoreDataFollows) {
if (pCookieData->bRequestType == DIRECTORYREQUEST_INFOUSER)
- ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_FAILED, (HANDLE)1 ,0);
+ ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_FAILED, (HANDLE)1, 0);
else if (pCookieData->bRequestType == DIRECTORYREQUEST_SEARCH)
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)wCookie, 0); // should report error here, but Find/Add module does not support that
ReleaseCookie(wCookie);
}
return;
}
+
oscar_tlv_chain *pDirectoryData = readIntoTLVChain(&databuf, wLen, -1);
- if (pDirectoryData)
- {
- switch (pCookieData->bRequestType)
- {
+ if (pDirectoryData) {
+ switch (pCookieData->bRequestType) {
case DIRECTORYREQUEST_INFOOWNER:
parseDirectoryUserDetailsData(NULL, pDirectoryData, wCookie, pCookieData, wReplySubtype);
break;
case DIRECTORYREQUEST_INFOUSER:
- {
- DWORD dwUin = 0;
- char *szUid = pDirectoryData->getString(0x32, 1);
- if (!szUid)
- {
- debugLogA("Error: Received unrecognized data from the directory");
- break;
- }
-
- if (IsStringUIN(szUid))
- dwUin = atoi(szUid);
-
- if (hContact != HContactFromUID(dwUin, szUid, NULL))
- {
- debugLogA("Error: Received data does not match cookie contact, ignoring.");
- SAFE_FREE(&szUid);
- break;
- }
- else
- SAFE_FREE(&szUid);
- }
-
+ {
+ DWORD dwUin = 0;
+ char *szUid = pDirectoryData->getString(0x32, 1);
+ if (!szUid) {
+ debugLogA("Error: Received unrecognized data from the directory");
+ break;
+ }
+
+ if (IsStringUIN(szUid))
+ dwUin = atoi(szUid);
+
+ if (hContact != HContactFromUID(dwUin, szUid, NULL)) {
+ debugLogA("Error: Received data does not match cookie contact, ignoring.");
+ SAFE_FREE(&szUid);
+ break;
+ }
+ else SAFE_FREE(&szUid);
+ }
+
case DIRECTORYREQUEST_INFOMULTI:
parseDirectoryUserDetailsData(hContact, pDirectoryData, wCookie, pCookieData, wReplySubtype);
break;
@@ -807,28 +729,22 @@ void CIcqProto::handleDirectoryQueryResponse(BYTE *databuf, WORD wPacketLen, WOR }
disposeChain(&pDirectoryData);
}
- else
- debugLogA("Error: Failed parsing directory response");
+ else debugLogA("Error: Failed parsing directory response");
// Release Memory
if (!bMoreDataFollows)
ReleaseCookie(wCookie);
}
-
static int calcAgeFromBirthDate(double dDate)
{
- if (dDate > 0)
- { // date is stored as double with unit equal to a day, incrementing since 1/1/1900 0:00 GMT
- SYSTEMTIME sDate = {0};
- if (VariantTimeToSystemTime(dDate + 2, &sDate))
- {
- SYSTEMTIME sToday = {0};
-
+ if (dDate > 0) { // date is stored as double with unit equal to a day, incrementing since 1/1/1900 0:00 GMT
+ SYSTEMTIME sDate = { 0 };
+ if (VariantTimeToSystemTime(dDate + 2, &sDate)) {
+ SYSTEMTIME sToday = { 0 };
GetLocalTime(&sToday);
int nAge = sToday.wYear - sDate.wYear;
-
if (sToday.wMonth < sDate.wMonth || (sToday.wMonth == sDate.wMonth && sToday.wDay < sDate.wDay))
nAge--;
@@ -838,18 +754,12 @@ static int calcAgeFromBirthDate(double dDate) return 0;
}
-
void CIcqProto::parseDirectoryUserDetailsData(MCONTACT hContact, oscar_tlv_chain *cDetails, DWORD dwCookie, cookie_directory_data *pCookieData, WORD wReplySubType)
{
- oscar_tlv *pTLV;
- WORD wRecordCount;
-
- if (pCookieData->bRequestType == DIRECTORYREQUEST_INFOMULTI && !hContact)
- {
+ if (pCookieData->bRequestType == DIRECTORYREQUEST_INFOMULTI && !hContact) {
DWORD dwUin = 0;
char *szUid = cDetails->getString(0x32, 1);
- if (!szUid)
- {
+ if (!szUid) {
debugLogA("Error: Received unrecognized data from the directory");
return;
}
@@ -858,53 +768,37 @@ void CIcqProto::parseDirectoryUserDetailsData(MCONTACT hContact, oscar_tlv_chain dwUin = atoi(szUid);
hContact = HContactFromUID(dwUin, szUid, NULL);
- if (hContact == INVALID_CONTACT_ID)
- {
+ if (hContact == INVALID_CONTACT_ID) {
debugLogA("Error: Received details for unknown contact \"%s\"", szUid);
SAFE_FREE(&szUid);
return;
}
-#ifdef _DEBUG
- else
- debugLogA("Received user info for %s from directory", szUid);
-#endif
+
+ debugLogA("Received user info for %s from directory", szUid);
SAFE_FREE(&szUid);
}
-#ifdef _DEBUG
- else
- {
- char *szUid = cDetails->getString(0x32, 1);
-
- if (!hContact)
- debugLogA("Received owner user info from directory");
- else
- debugLogA("Received user info for %s from directory", szUid);
- SAFE_FREE(&szUid);
- }
-#endif
- pTLV = cDetails->getTLV(0x50, 1);
+ oscar_tlv *pTLV = cDetails->getTLV(0x50, 1);
if (pTLV && pTLV->wLen > 0)
- writeDbInfoSettingTLVStringUtf(hContact, "e-mail", cDetails, 0x50); // Verified e-mail
+ writeDbInfoSettingTLVStringUtf(hContact, "e-mail", cDetails, 0x50); // Verified e-mail
else
- writeDbInfoSettingTLVStringUtf(hContact, "e-mail", cDetails, 0x55); // Pending e-mail
+ writeDbInfoSettingTLVStringUtf(hContact, "e-mail", cDetails, 0x55); // Pending e-mail
writeDbInfoSettingTLVStringUtf(hContact, "FirstName", cDetails, 0x64);
- writeDbInfoSettingTLVStringUtf(hContact, "LastName", cDetails, 0x6E);
- writeDbInfoSettingTLVStringUtf(hContact, "Nick", cDetails, 0x78);
+ writeDbInfoSettingTLVStringUtf(hContact, "LastName", cDetails, 0x6E);
+ writeDbInfoSettingTLVStringUtf(hContact, "Nick", cDetails, 0x78);
// Home Address
parseUserInfoRecord(hContact, cDetails->getTLV(0x96, 1), rAddress, SIZEOF(rAddress), 1);
// Origin Address
parseUserInfoRecord(hContact, cDetails->getTLV(0xA0, 1), rOriginAddress, SIZEOF(rOriginAddress), 1);
// Phones
pTLV = cDetails->getTLV(0xC8, 1);
- if (pTLV && pTLV->wLen >= 2)
- {
+ if (pTLV && pTLV->wLen >= 2) {
BYTE *pRecords = pTLV->pData;
+ WORD wRecordCount;
unpackWord(&pRecords, &wRecordCount);
oscar_tlv_record_list *cPhones = readIntoTLVRecordList(&pRecords, pTLV->wLen - 2, wRecordCount);
- if (cPhones)
- {
+ if (cPhones) {
oscar_tlv_chain *cPhone;
cPhone = cPhones->getRecordByTLV(0x6E, 1);
writeDbInfoSettingTLVStringUtf(hContact, "Phone", cPhone, 0x64);
@@ -919,8 +813,7 @@ void CIcqProto::parseDirectoryUserDetailsData(MCONTACT hContact, oscar_tlv_chain disposeRecordList(&cPhones);
}
- else
- { // Remove old data when phones not available
+ else { // Remove old data when phones not available
delSetting(hContact, "Phone");
delSetting(hContact, "CompanyPhone");
delSetting(hContact, "Cellular");
@@ -928,8 +821,7 @@ void CIcqProto::parseDirectoryUserDetailsData(MCONTACT hContact, oscar_tlv_chain delSetting(hContact, "CompanyFax");
}
}
- else
- { // Remove old data when phones not available
+ else { // Remove old data when phones not available
delSetting(hContact, "Phone");
delSetting(hContact, "CompanyPhone");
delSetting(hContact, "Cellular");
@@ -945,9 +837,8 @@ void CIcqProto::parseDirectoryUserDetailsData(MCONTACT hContact, oscar_tlv_chain // Education
parseUserInfoRecord(hContact, cDetails->getTLV(0x10E, 1), rEducation, SIZEOF(rEducation), 1);
- switch (cDetails->getNumber(0x82, 1))
- {
- case 1:
+ switch (cDetails->getNumber(0x82, 1)) {
+ case 1:
setByte(hContact, "Gender", 'F');
break;
case 2:
@@ -970,11 +861,10 @@ void CIcqProto::parseDirectoryUserDetailsData(MCONTACT hContact, oscar_tlv_chain writeDbInfoSettingTLVStringUtf(hContact, "About", cDetails, 0x186);
-// if (hContact)
-// writeDbInfoSettingTLVStringUtf(hContact, DBSETTING_STATUS_NOTE, cDetails, 0x226);
-// else
- if (!hContact)
- { // Owner contact needs special processing, in the database is current status note for the client
+ // if (hContact)
+ // writeDbInfoSettingTLVStringUtf(hContact, DBSETTING_STATUS_NOTE, cDetails, 0x226);
+ // else
+ if (!hContact) { // Owner contact needs special processing, in the database is current status note for the client
// We just received the last status note set on directory, if it differs call SetStatusNote() to
// ensure the directory will be updated (it should be in process anyway)
char *szClientStatusNote = getSettingStringUtf(hContact, DBSETTING_STATUS_NOTE, NULL);
@@ -990,8 +880,7 @@ void CIcqProto::parseDirectoryUserDetailsData(MCONTACT hContact, oscar_tlv_chain writeDbInfoSettingTLVByte(hContact, "PrivacyLevel", cDetails, 0x1F9);
- if (!hContact)
- {
+ if (!hContact) {
setByte(hContact, "Auth", !cDetails->getByte(0x19A, 1));
writeDbInfoSettingTLVByte(hContact, "WebAware", cDetails, 0x212);
writeDbInfoSettingTLVByte(hContact, "AllowSpam", cDetails, 0x1EA);
@@ -999,8 +888,7 @@ void CIcqProto::parseDirectoryUserDetailsData(MCONTACT hContact, oscar_tlv_chain writeDbInfoSettingTLVWord(hContact, "InfoCP", cDetails, 0x1C2);
- if (hContact)
- { // Handle deprecated setting (Age & Birthdate are not separate fields anymore)
+ if (hContact) { // Handle deprecated setting (Age & Birthdate are not separate fields anymore)
int nAge = calcAgeFromBirthDate(cDetails->getDouble(0x1A4, 1));
if (nAge)
@@ -1013,7 +901,7 @@ void CIcqProto::parseDirectoryUserDetailsData(MCONTACT hContact, oscar_tlv_chain { // Save user info last update time and privacy token
double dInfoTime;
- BYTE pbEmptyMetaToken[0x10] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+ BYTE pbEmptyMetaToken[0x10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int bHasMetaToken = FALSE;
// Check if the details arrived with privacy token!
@@ -1031,7 +919,7 @@ void CIcqProto::parseDirectoryUserDetailsData(MCONTACT hContact, oscar_tlv_chain if (wReplySubType == META_DIRECTORY_RESPONSE)
if (pCookieData->bRequestType == DIRECTORYREQUEST_INFOUSER)
- ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, (HANDLE)1 ,0);
+ ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, (HANDLE)1, 0);
// Remove user from info update queue. Removing is fast so we always call this
// even if it is likely that the user is not queued at all.
@@ -1042,12 +930,11 @@ void CIcqProto::parseDirectoryUserDetailsData(MCONTACT hContact, oscar_tlv_chain void CIcqProto::parseDirectorySearchData(oscar_tlv_chain *cDetails, DWORD dwCookie, cookie_directory_data *pCookieData, WORD wReplySubType)
{
- ICQSEARCHRESULT isr = {0};
char *szUid = cDetails->getString(0x32, 1); // User ID
-#ifdef _DEBUG
debugLogA("Directory Search: Found user %s", szUid);
-#endif
+
+ ICQSEARCHRESULT isr = { 0 };
isr.hdr.cbSize = sizeof(ICQSEARCHRESULT);
isr.hdr.flags = PSR_TCHAR;
isr.hdr.id = ansi_to_tchar(szUid);
@@ -1067,7 +954,7 @@ void CIcqProto::parseDirectorySearchData(oscar_tlv_chain *cDetails, DWORD dwCook else
szData = cDetails->getString(0x55, 1); // Pending e-mail
if (strlennull(szData))
- isr.hdr.email = ansi_to_tchar(szData);
+ isr.hdr.email = ansi_to_tchar(szData);
SAFE_FREE(&szData);
szData = cDetails->getString(0x64, 1); // First Name
@@ -1082,12 +969,12 @@ void CIcqProto::parseDirectorySearchData(oscar_tlv_chain *cDetails, DWORD dwCook szData = cDetails->getString(0x78, 1); // Nick
if (strlennull(szData))
- isr.hdr.nick = utf8_to_tchar(szData);
+ isr.hdr.nick = utf8_to_tchar(szData);
SAFE_FREE(&szData);
switch (cDetails->getNumber(0x82, 1)) // Gender
{
- case 1:
+ case 1:
isr.gender = 'F';
break;
case 2:
@@ -1096,8 +983,7 @@ void CIcqProto::parseDirectorySearchData(oscar_tlv_chain *cDetails, DWORD dwCook }
pTLV = cDetails->getTLV(0x96, 1);
- if (pTLV && pTLV->wLen >= 4)
- {
+ if (pTLV && pTLV->wLen >= 4) {
BYTE *buf = pTLV->pData;
oscar_tlv_chain *chain = readIntoTLVChain(&buf, pTLV->wLen, 0);
if (chain)
@@ -1130,19 +1016,17 @@ void CIcqProto::parseDirectorySearchData(oscar_tlv_chain *cDetails, DWORD dwCook void CIcqProto::handleDirectoryUpdateResponse(BYTE *databuf, WORD wPacketLen, WORD wCookie, WORD wReplySubtype)
{
WORD wBytesRemaining = 0;
- snac_header requestSnac = {0};
+ snac_header requestSnac = { 0 };
BYTE requestResult;
-#ifdef _DEBUG
debugLogA("Received directory update response");
-#endif
+
if (wPacketLen >= 2)
unpackLEWord(&databuf, &wBytesRemaining);
wPacketLen -= 2;
_ASSERTE(wPacketLen == wBytesRemaining);
- if (!unpackSnacHeader(&requestSnac, &databuf, &wPacketLen) || !requestSnac.bValid)
- {
+ if (!unpackSnacHeader(&requestSnac, &databuf, &wPacketLen) || !requestSnac.bValid) {
debugLogA("Error: Failed to parse directory response");
return;
}
@@ -1150,8 +1034,7 @@ void CIcqProto::handleDirectoryUpdateResponse(BYTE *databuf, WORD wPacketLen, WO cookie_directory_data *pCookieData;
MCONTACT hContact;
// check request cookie
- if (!FindCookie(wCookie, &hContact, (void**)&pCookieData) || !pCookieData)
- {
+ if (!FindCookie(wCookie, &hContact, (void**)&pCookieData) || !pCookieData) {
debugLogA("Warning: Ignoring unrequested directory reply type (x%x, x%x)", requestSnac.wFamily, requestSnac.wSubtype);
return;
}
@@ -1159,14 +1042,12 @@ void CIcqProto::handleDirectoryUpdateResponse(BYTE *databuf, WORD wPacketLen, WO if (wPacketLen >= 3)
unpackByte(&databuf, &requestResult);
- else
- {
+ else {
debugLogA("Error: Malformed directory response");
ReleaseCookie(wCookie);
return;
}
- if (requestResult != 1 && requestResult != 4)
- {
+ if (requestResult != 1 && requestResult != 4) {
debugLogA("Error: Directory request failed, status %u", requestResult);
if (pCookieData->bRequestType == DIRECTORYREQUEST_UPDATEOWNER)
@@ -1184,10 +1065,9 @@ void CIcqProto::handleDirectoryUpdateResponse(BYTE *databuf, WORD wPacketLen, WO if (pCookieData->bRequestType == DIRECTORYREQUEST_UPDATEOWNER)
ProtoBroadcastAck(NULL, ACKTYPE_SETINFO, ACKRESULT_SUCCESS, (HANDLE)wCookie, 0);
- if (wPacketLen == 0x18)
- {
+ if (wPacketLen == 0x18) {
DWORD64 qwMetaTime;
- BYTE pbEmptyMetaToken[0x10] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+ BYTE pbEmptyMetaToken[0x10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
unpackQWord(&databuf, &qwMetaTime);
setSettingBlob(NULL, DBSETTING_METAINFO_TIME, (BYTE*)&qwMetaTime, 8);
diff --git a/protocols/IcqOscarJ/src/fam_17signon.cpp b/protocols/IcqOscarJ/src/fam_17signon.cpp index 9561df17b1..d5251199d7 100644 --- a/protocols/IcqOscarJ/src/fam_17signon.cpp +++ b/protocols/IcqOscarJ/src/fam_17signon.cpp @@ -130,12 +130,9 @@ void CIcqProto::handleAuthKeyResponse(BYTE *buf, WORD wPacketLen, serverthread_i mir_md5_state_t state;
BYTE digest[16];
-#ifdef _DEBUG
debugLogA("Received %s", "ICQ_SIGNON_AUTH_KEY");
-#endif
- if (wPacketLen < 2)
- {
+ if (wPacketLen < 2) {
debugLogA("Malformed %s", "ICQ_SIGNON_AUTH_KEY");
icq_LogMessage(LOG_FATAL, LPGEN("Secure login failed.\nInvalid server response."));
SetCurrentStatus(ID_STATUS_OFFLINE);
@@ -145,8 +142,7 @@ void CIcqProto::handleAuthKeyResponse(BYTE *buf, WORD wPacketLen, serverthread_i unpackWord(&buf, &wKeyLen);
wPacketLen -= 2;
- if (!wKeyLen || wKeyLen > wPacketLen || wKeyLen > sizeof(szKey))
- {
+ if (!wKeyLen || wKeyLen > wPacketLen || wKeyLen > sizeof(szKey)) {
debugLogA("Invalid length in %s: %u", "ICQ_SIGNON_AUTH_KEY", wKeyLen);
icq_LogMessage(LOG_FATAL, LPGEN("Secure login failed.\nInvalid key length."));
SetCurrentStatus(ID_STATUS_OFFLINE);
@@ -165,8 +161,6 @@ void CIcqProto::handleAuthKeyResponse(BYTE *buf, WORD wPacketLen, serverthread_i mir_md5_append(&state, (LPBYTE)CLIENT_MD5_STRING, sizeof(CLIENT_MD5_STRING)-1);
mir_md5_finish(&state, digest);
-#ifdef _DEBUG
debugLogA("Sending ICQ_SIGNON_LOGIN_REQUEST to login server");
-#endif
sendClientAuth((char*)digest, 0x10, TRUE);
}
diff --git a/protocols/IcqOscarJ/src/icq_avatar.cpp b/protocols/IcqOscarJ/src/icq_avatar.cpp index c8ec527825..f71b32ede0 100644 --- a/protocols/IcqOscarJ/src/icq_avatar.cpp +++ b/protocols/IcqOscarJ/src/icq_avatar.cpp @@ -249,19 +249,6 @@ void CIcqProto::StopAvatarThread() m_avatarsConnection->shutdownConnection(); // make the thread stop
}
-#ifdef _DEBUG
-static void NetLog_Hash(CIcqProto *ppro, const char *pszIdent, const BYTE *pHash, int nHashLen)
-{
- if (nHashLen == 0x14)
- ppro->debugLogA("Avatars: %s hash: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", pszIdent, pHash[0], pHash[1], pHash[2], pHash[3], pHash[4], pHash[5], pHash[6], pHash[7], pHash[8], pHash[9], pHash[10], pHash[11], pHash[12], pHash[13], pHash[14], pHash[15], pHash[16], pHash[17], pHash[18], pHash[19]);
- else if (nHashLen == 0x09)
- ppro->debugLogA("Avatars: %s hash: %02X%02X%02X%02X%02X%02X%02X%02X%02X", pszIdent, pHash[0], pHash[1], pHash[2], pHash[3], pHash[4], pHash[5], pHash[6], pHash[7], pHash[8]);
- else
- ppro->debugLogA("Avatars: %s hash: Unknown hash format.", pszIdent);
-}
-#endif
-
-
// handle Owner's avatar hash changes
void CIcqProto::handleAvatarOwnerHash(WORD wItemID, BYTE bFlags, BYTE *pData, BYTE nDataLen)
{
@@ -276,10 +263,9 @@ void CIcqProto::handleAvatarOwnerHash(WORD wItemID, BYTE bFlags, BYTE *pData, BY // here we need to find a file, check its hash, if invalid get avatar from server
TCHAR *file = GetOwnAvatarFileName();
if (!file) { // we have no avatar file, download from server
- TCHAR szFile[MAX_PATH * 2 + 4];
-#ifdef _DEBUG
debugLogA("We have no avatar, requesting from server.");
-#endif
+
+ TCHAR szFile[MAX_PATH * 2 + 4];
GetAvatarFileName(0, NULL, szFile, MAX_PATH * 2);
GetAvatarData(NULL, m_dwLocalUIN, NULL, pData, 0x14, szFile);
}
@@ -287,10 +273,9 @@ void CIcqProto::handleAvatarOwnerHash(WORD wItemID, BYTE bFlags, BYTE *pData, BY BYTE *hash = calcMD5HashOfFile(file);
if (!hash) { // hash could not be calculated - probably missing file, get avatar from server
- TCHAR szFile[MAX_PATH * 2 + 4];
-#ifdef _DEBUG
debugLogA("We have no avatar, requesting from server.");
-#endif
+
+ TCHAR szFile[MAX_PATH * 2 + 4];
GetAvatarFileName(0, NULL, szFile, MAX_PATH * 2);
GetAvatarData(NULL, m_dwLocalUIN, NULL, pData, 0x14, szFile);
}
@@ -310,10 +295,9 @@ void CIcqProto::handleAvatarOwnerHash(WORD wItemID, BYTE bFlags, BYTE *pData, BY updateServAvatarHash(pHash, 0x14);
}
else { // get avatar from server
- TCHAR tszFile[MAX_PATH * 2 + 4];
-#ifdef _DEBUG
debugLogA("We have different avatar, requesting new from server.");
-#endif
+
+ TCHAR tszFile[MAX_PATH * 2 + 4];
GetAvatarFileName(0, NULL, tszFile, MAX_PATH * 2);
GetAvatarData(NULL, m_dwLocalUIN, NULL, pData, 0x14, tszFile);
}
@@ -453,18 +437,13 @@ void CIcqProto::handleAvatarContactHash(DWORD dwUIN, char *szUID, MCONTACT hCont if ((avatarType == AVATAR_HASH_STATIC || avatarType == AVATAR_HASH_MINI) && cbAvatarHash == 0x09 && !memcmp(pAvatarHash + 4, hashEmptyAvatar + 4, 0x05)) { // empty avatar - unlink image, clear hash
if (!getSetting(hContact, "AvatarHash", &dbv)) { // contact had avatar, clear hash, notify UI
-#ifdef _DEBUG
- NetLog_Hash(this, "old", dbv.pbVal, dbv.cpbVal);
-#endif
db_free(&dbv);
debugLogA("%s has removed Avatar.", strUID(dwUIN, szUID));
delSetting(hContact, "AvatarHash");
ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, NULL, 0);
}
-#ifdef _DEBUG
else debugLogA("%s has empty Avatar.", strUID(dwUIN, szUID));
-#endif
return;
}
@@ -478,37 +457,23 @@ void CIcqProto::handleAvatarContactHash(DWORD dwUIN, char *szUID, MCONTACT hCont GetFullAvatarFileName(dwUIN, szUID, dwPaFormat, tszAvatar, MAX_PATH * 2);
if (_taccess(tszAvatar, 0) == 0) { // the file is there, link to contactphoto, save hash
debugLogA("%s has published Avatar. Image was found in the cache.", strUID(dwUIN, szUID));
-#ifdef _DEBUG
- NetLog_Hash(this, "new", pAvatarHash, cbAvatarHash);
-#endif
+
setSettingBlob(hContact, "AvatarHash", pAvatarHash, cbAvatarHash);
ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, NULL, 0);
}
else { // the file was lost, request avatar again
debugLogA("%s has published Avatar.", strUID(dwUIN, szUID));
-#ifdef _DEBUG
- NetLog_Hash(this, "new", pAvatarHash, cbAvatarHash);
-#endif
bJob = TRUE;
}
}
else { // the hash is not the one we want, request avatar
debugLogA("%s has published a new Avatar.", strUID(dwUIN, szUID));
-#ifdef _DEBUG
- NetLog_Hash(this, "new", pAvatarHash, cbAvatarHash);
-#endif
bJob = TRUE;
}
}
else { // we found hash check if it changed or not
if ((dbv.cpbVal != cbAvatarHash) || memcmp(dbv.pbVal, pAvatarHash, cbAvatarHash)) { // the hash is different, request new avatar
-#ifdef _DEBUG
- NetLog_Hash(this, "old", dbv.pbVal, dbv.cpbVal);
-#endif
debugLogA("%s has changed Avatar.", strUID(dwUIN, szUID));
-#ifdef _DEBUG
- NetLog_Hash(this, "new", pAvatarHash, cbAvatarHash);
-#endif
bJob = TRUE;
}
else { // the hash was not changed, check if we have the correct file
@@ -518,34 +483,19 @@ void CIcqProto::handleAvatarContactHash(DWORD dwUIN, char *szUID, MCONTACT hCont if (!avatarState) {
int dwPaFormat = getByte(hContact, "AvatarType", PA_FORMAT_UNKNOWN);
if (dwPaFormat == PA_FORMAT_UNKNOWN) { // we do not know the format, get avatar again
-#ifdef _DEBUG
- NetLog_Hash(this, "current", dbv.pbVal, dbv.cpbVal);
-#endif
debugLogA("%s has Avatar. Image is missing.", strUID(dwUIN, szUID));
bJob = 2;
}
else {
GetFullAvatarFileName(dwUIN, szUID, dwPaFormat, tszAvatar, MAX_PATH * 2);
if (_taccess(tszAvatar, 0) != 0) { // the file was lost, get it again
-#ifdef _DEBUG
- NetLog_Hash(this, "current", dbv.pbVal, dbv.cpbVal);
-#endif
debugLogA("%s has Avatar. Image is missing.", strUID(dwUIN, szUID));
bJob = 2;
}
-#ifdef _DEBUG
- else {
- NetLog_Hash(this, "current", dbv.pbVal, dbv.cpbVal);
-
- debugLogA("%s has Avatar. Image was found in the cache.", strUID(dwUIN, szUID));
- }
-#endif
+ else debugLogA("%s has Avatar. Image was found in the cache.", strUID(dwUIN, szUID));
}
}
else { // the hash is not the one we want, request avatar
-#ifdef _DEBUG
- NetLog_Hash(this, "current", dbv.pbVal, dbv.cpbVal);
-#endif
debugLogA("%s has Avatar. Image was not retrieved yet.", strUID(dwUIN, szUID));
bJob = 2;
}
@@ -577,20 +527,14 @@ void CIcqProto::handleAvatarContactHash(DWORD dwUIN, char *szUID, MCONTACT hCont }
else if (avatarInfoPresent) { // hash was not found, clear the hash
DBVARIANT dbv = { DBVT_DELETED };
-
if (!getSetting(hContact, "AvatarHash", &dbv)) { // contact had avatar, clear hash, notify UI
-#ifdef _DEBUG
- NetLog_Hash(this, "old", dbv.pbVal, dbv.cpbVal);
-#endif
db_free(&dbv);
debugLogA("%s has removed Avatar.", strUID(dwUIN, szUID));
delSetting(hContact, "AvatarHash");
ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, NULL, 0);
}
-#ifdef _DEBUG
else debugLogA("%s has no Avatar.", strUID(dwUIN, szUID));
-#endif
}
}
@@ -865,9 +809,7 @@ DWORD avatars_server_connection::sendGetAvatarRequest(MCONTACT hContact, DWORD d if (m_rates->getNextRateLevel(wGroup) < m_rates->getLimitLevel(wGroup, RML_ALERT)) { // we will be over quota if we send the request now, add to queue instead
bSendNow = FALSE;
-#ifdef _DEBUG
ppro->debugLogA("Rates: Delay avatar request.");
-#endif
}
}
@@ -902,7 +844,6 @@ DWORD avatars_server_connection::sendGetAvatarRequest(MCONTACT hContact, DWORD d if (sendServerPacket(&packet)) {
ppro->debugLogA("Request to get %s image sent.", strUID(dwUin, szUid));
-
return dwCookie;
}
ppro->FreeCookie(dwCookie); // sending failed, free resources
@@ -945,10 +886,6 @@ DWORD avatars_server_connection::sendUploadAvatarRequest(MCONTACT hContact, WORD void avatars_server_connection::checkRequestQueue()
{
-#ifdef _DEBUG
- ppro->debugLogA("Checking request queue...");
-#endif
-
ppro->m_avatarsMutex->Enter();
while (ppro->m_avatarsQueue && runCount < 3) { // pick up an request and send it - happens immediatelly after login
@@ -959,12 +896,9 @@ void avatars_server_connection::checkRequestQueue() icq_lock l(m_ratesMutex);
WORD wGroup = m_rates->getGroupFromSNAC(ICQ_AVATAR_FAMILY, (WORD)(pRequest->type == ART_UPLOAD ? ICQ_AVATAR_GET_REQUEST : ICQ_AVATAR_UPLOAD_REQUEST));
- if (m_rates->getNextRateLevel(wGroup) < m_rates->getLimitLevel(wGroup, RML_ALERT)) { // we are over rate, leave queue and wait
-#ifdef _DEBUG
- ppro->debugLogA("Rates: Leaving avatar queue processing");
-#endif
+ // we are over rate, leave queue and wait
+ if (m_rates->getNextRateLevel(wGroup) < m_rates->getLimitLevel(wGroup, RML_ALERT))
break;
- }
}
if (pRequest->type == ART_BLOCK) { // block contact processing
@@ -986,9 +920,6 @@ void avatars_server_connection::checkRequestQueue() ppro->m_avatarsMutex->Leave();
-#ifdef _DEBUG
- ppro->debugLogA("Picked up the %s request from queue.", strUID(pRequest->dwUin, pRequest->szUid));
-#endif
switch (pRequest->type) {
case ART_GET: // get avatar
sendGetAvatarRequest(pRequest->hContact, pRequest->dwUin, pRequest->szUid, pRequest->hash, pRequest->hashlen, pRequest->szFile);
@@ -1147,9 +1078,7 @@ int avatars_server_connection::handleServerPackets(BYTE *buf, int buflen) if (buflen < 6 + datalen)
break;
-#ifdef _DEBUG
ppro->debugLogA("Server FLAP: Channel %u, Seq %u, Length %u bytes", channel, sequence, datalen);
-#endif
switch (channel) {
case ICQ_LOGIN_CHAN:
@@ -1183,9 +1112,7 @@ void avatars_server_connection::handleLoginChannel(BYTE *buf, WORD datalen) serverCookieInit(&packet, (LPBYTE)pCookie, wCookieLen);
sendServerPacket(&packet);
-#ifdef _DEBUG
ppro->debugLogA("Sent CLI_IDENT to %s", "avatar server");
-#endif
SAFE_FREE((void**)&pCookie);
wCookieLen = 0;
@@ -1199,12 +1126,10 @@ void avatars_server_connection::handleDataChannel(BYTE *buf, WORD datalen) if (!unpackSnacHeader(&snacHeader, &buf, &datalen) || !snacHeader.bValid)
ppro->debugLogA("Error: Failed to parse SNAC header");
else {
-#ifdef _DEBUG
if (snacHeader.wFlags & 0x8000)
ppro->debugLogA(" Received SNAC(x%02X,x%02X), version %u", snacHeader.wFamily, snacHeader.wSubtype, snacHeader.wVersion);
else
ppro->debugLogA(" Received SNAC(x%02X,x%02X)", snacHeader.wFamily, snacHeader.wSubtype);
-#endif
switch (snacHeader.wFamily) {
case ICQ_SERVICE_FAMILY:
@@ -1228,10 +1153,8 @@ void avatars_server_connection::handleServiceFam(BYTE *pBuffer, WORD wBufferLeng switch (pSnacHeader->wSubtype) {
case ICQ_SERVER_READY:
-#ifdef _DEBUG
ppro->debugLogA("Server is ready and is requesting my Family versions");
ppro->debugLogA("Sending my Families");
-#endif
// Miranda mimics the behaviour of Icq5
serverPacketInit(&packet, 18);
@@ -1244,25 +1167,23 @@ void avatars_server_connection::handleServiceFam(BYTE *pBuffer, WORD wBufferLeng case ICQ_SERVER_FAMILIES2:
/* This is a reply to CLI_FAMILIES and it tells the client which families and their versions that this server understands.
* We send a rate request packet */
-#ifdef _DEBUG
ppro->debugLogA("Server told me his Family versions");
ppro->debugLogA("Requesting Rate Information");
-#endif
+
serverPacketInit(&packet, 10);
packFNACHeader(&packet, ICQ_SERVICE_FAMILY, ICQ_CLIENT_REQ_RATE_INFO);
sendServerPacket(&packet);
break;
case ICQ_SERVER_RATE_INFO:
-#ifdef _DEBUG
ppro->debugLogA("Server sent Rate Info");
-#endif
+
/* init rates management */
m_rates = new rates(ppro, pBuffer, wBufferLength);
+
/* ack rate levels */
-#ifdef _DEBUG
ppro->debugLogA("Sending Rate Info Ack");
-#endif
+
m_rates->initAckPacket(&packet);
sendServerPacket(&packet);
diff --git a/protocols/IcqOscarJ/src/icq_direct.cpp b/protocols/IcqOscarJ/src/icq_direct.cpp index 2e5666973c..391ccf16dd 100644 --- a/protocols/IcqOscarJ/src/icq_direct.cpp +++ b/protocols/IcqOscarJ/src/icq_direct.cpp @@ -181,10 +181,9 @@ void CIcqProto::CloseDirectConnection(directconnect *dc) icq_lock l(directConnListMutex);
NetLib_CloseConnection(&dc->hConnection, FALSE);
-#ifdef _DEBUG
+
if (dc->hConnection)
NetLog_Direct("Direct conn closed (%p)", dc->hConnection);
-#endif
}
// Called from icq_newConnectionReceived when a new incomming dc is done
@@ -410,9 +409,7 @@ void __cdecl CIcqProto::icq_directThread(directthreadstartinfo *dtsi) continue;
}
}
-#ifdef _DEBUG
- NetLog_Direct("New direct package");
-#endif
+
if (dc.type == DIRECTCONN_FILE && dc.initialised)
handleFileTransferPacket(&dc, packetRecv.buffer + i + 2, wLen);
else
@@ -453,9 +450,8 @@ void CIcqProto::handleDirectPacket(directconnect* dc, PBYTE buf, WORD wLen) switch (buf[0]) {
case PEER_FILE_INIT: // first packet of a file transfer
-#ifdef _DEBUG
NetLog_Direct("Received PEER_FILE_INIT from %u", dc->dwRemoteUin);
-#endif
+
if (dc->handshake)
handleFileTransferPacket(dc, buf, wLen);
else
@@ -468,9 +464,9 @@ void CIcqProto::handleDirectPacket(directconnect* dc, PBYTE buf, WORD wLen) NetLog_Direct("Error: Received malformed PEER_INITACK from %u", dc->dwRemoteUin);
break;
}
-#ifdef _DEBUG
+
NetLog_Direct("Received PEER_INITACK from %u on %s DC", dc->dwRemoteUin, dc->incoming ? "incoming" : "outgoing");
-#endif
+
if (dc->incoming) dc->handshake = 1;
if (dc->incoming && dc->type == DIRECTCONN_REVERSE) {
@@ -509,9 +505,8 @@ void CIcqProto::handleDirectPacket(directconnect* dc, PBYTE buf, WORD wLen) break;
case PEER_INIT: /* connect packet */
-#ifdef _DEBUG
NetLog_Direct("Received PEER_INIT");
-#endif
+
buf++;
if (wLen < 3)
@@ -635,9 +630,8 @@ void CIcqProto::handleDirectPacket(directconnect* dc, PBYTE buf, WORD wLen) break;
case PEER_MSG: /* messaging packets */
-#ifdef _DEBUG
NetLog_Direct("Received PEER_MSG from %u", dc->dwRemoteUin);
-#endif
+
if (dc->initialised)
handleDirectMessage(dc, buf + 1, (WORD)(wLen - 1));
else
@@ -653,9 +647,8 @@ void CIcqProto::handleDirectPacket(directconnect* dc, PBYTE buf, WORD wLen) break;
}
-#ifdef _DEBUG
NetLog_Direct("Received PEER_MSG_INIT from %u", dc->dwRemoteUin);
-#endif
+
buf++;
if (wLen != 0x21)
break;
@@ -895,9 +888,8 @@ void CIcqProto::sendPeerInit_v78(directconnect* dc) packDWord(&packet, 0); // Unknown
sendDirectPacket(dc, &packet);
-#ifdef _DEBUG
+
NetLog_Direct("Sent PEER_INIT to %u on %s DC", dc->dwRemoteUin, dc->incoming ? "incoming" : "outgoing");
-#endif
}
// Sends a PEER_INIT packet through a DC
@@ -911,9 +903,8 @@ void CIcqProto::sendPeerInitAck(directconnect* dc) packLEDWord(&packet, PEER_INIT_ACK); //
sendDirectPacket(dc, &packet);
-#ifdef _DEBUG
+
NetLog_Direct("Sent PEER_INIT_ACK to %u on %s DC", dc->dwRemoteUin, dc->incoming ? "incoming" : "outgoing");
-#endif
}
// Sends a PEER_MSG_INIT packet through a DC
@@ -943,9 +934,8 @@ void CIcqProto::sendPeerMsgInit(directconnect* dc, DWORD dwSeq) packDWord(&packet, 0);
}
sendDirectPacket(dc, &packet);
-#ifdef _DEBUG
+
NetLog_Direct("Sent PEER_MSG_INIT to %u on %s DC", dc->dwRemoteUin, dc->incoming ? "incoming" : "outgoing");
-#endif
}
// Sends a PEER_FILE_INIT packet through a DC
@@ -975,8 +965,7 @@ void CIcqProto::sendPeerFileInit(directconnect* dc) packLEWord(&packet, (WORD)(nNickLen + 1));
packBuffer(&packet, (LPBYTE)szNick, (WORD)(nNickLen + 1));
sendDirectPacket(dc, &packet);
-#ifdef _DEBUG
- NetLog_Direct("Sent PEER_FILE_INIT to %u on %s DC", dc->dwRemoteUin, dc->incoming ? "incoming" : "outgoing");
-#endif
db_free(&dbv);
+
+ NetLog_Direct("Sent PEER_FILE_INIT to %u on %s DC", dc->dwRemoteUin, dc->incoming ? "incoming" : "outgoing");
}
diff --git a/protocols/IcqOscarJ/src/icq_directmsg.cpp b/protocols/IcqOscarJ/src/icq_directmsg.cpp index a85d355c0d..8010f31870 100644 --- a/protocols/IcqOscarJ/src/icq_directmsg.cpp +++ b/protocols/IcqOscarJ/src/icq_directmsg.cpp @@ -35,10 +35,8 @@ void CIcqProto::handleDirectMessage(directconnect* dc, PBYTE buf, WORD wLen) WORD wTextLen;
char* pszText = NULL;
-
// The first part of the packet should always be at least 31 bytes
- if (wLen < 31)
- {
+ if (wLen < 31) {
NetLog_Direct("Error during parsing of DC packet 2 PEER_MSG (too short)");
return;
}
@@ -100,17 +98,12 @@ void CIcqProto::handleDirectMessage(directconnect* dc, PBYTE buf, WORD wLen) }
wLen = (wLen - 2) - wTextLen;
-#ifdef _DEBUG
NetLog_Direct("Handling PEER_MSG '%s', command %u, cookie %u, messagetype %u, messageflags %u, status %u, flags %u", pszText, wCommand, wCookie, bMsgType, bMsgFlags, wStatus, wFlags);
-#else
- NetLog_Direct("Message through direct - UID: %u", dc->dwRemoteUin);
-#endif
// The remaining actual message is handled either as a status message request,
// a greeting message, a acknowledge or a normal (text, url, file) message
- if (wCommand == DIRECT_MESSAGE)
- switch (bMsgType)
- {
+ if (wCommand == DIRECT_MESSAGE) {
+ switch (bMsgType) {
case MTYPE_FILEREQ: // File inits
handleFileRequest(buf, wLen, dc->dwRemoteUin, wCookie, 0, 0, pszText, 7, TRUE);
break;
@@ -123,7 +116,7 @@ void CIcqProto::handleDirectMessage(directconnect* dc, PBYTE buf, WORD wLen) {
char **szMsg = MirandaStatusToAwayMsg(AwayMsgTypeToStatus(bMsgType));
if (szMsg)
- icq_sendAwayMsgReplyDirect(dc, wCookie, bMsgType, ( const char** )szMsg);
+ icq_sendAwayMsgReplyDirect(dc, wCookie, bMsgType, (const char**)szMsg);
}
break;
@@ -131,54 +124,45 @@ void CIcqProto::handleDirectMessage(directconnect* dc, PBYTE buf, WORD wLen) handleDirectGreetingMessage(dc, buf, wLen, wCommand, wCookie, bMsgType, bMsgFlags, wStatus, wFlags, pszText);
break;
- default:
- {
- message_ack_params pMsgAck = {0};
- uid_str szUID;
-
- buf -= wTextLen;
- wLen += wTextLen;
-
- pMsgAck.bType = MAT_DIRECT;
- pMsgAck.pDC = dc;
- pMsgAck.wCookie = wCookie;
- pMsgAck.msgType = bMsgType;
- pMsgAck.bFlags = bMsgFlags;
- handleMessageTypes(dc->dwRemoteUin, szUID, time(NULL), 0, 0, wCookie, dc->wVersion, (int)bMsgType, (int)bMsgFlags, 0, (DWORD)wLen, wTextLen, (char*)buf, MTF_DIRECT, &pMsgAck);
- break;
- }
+ default:
+ message_ack_params pMsgAck = { 0 };
+ uid_str szUID;
+
+ buf -= wTextLen;
+ wLen += wTextLen;
+
+ pMsgAck.bType = MAT_DIRECT;
+ pMsgAck.pDC = dc;
+ pMsgAck.wCookie = wCookie;
+ pMsgAck.msgType = bMsgType;
+ pMsgAck.bFlags = bMsgFlags;
+ handleMessageTypes(dc->dwRemoteUin, szUID, time(NULL), 0, 0, wCookie, dc->wVersion, (int)bMsgType, (int)bMsgFlags, 0, (DWORD)wLen, wTextLen, (char*)buf, MTF_DIRECT, &pMsgAck);
+ break;
+ }
}
- else if (wCommand == DIRECT_ACK)
- {
- if (bMsgFlags == 3)
- { // this is status reply
- uid_str szUID;
+ else if (wCommand == DIRECT_ACK) {
+ if (bMsgFlags == 3) {
+ // this is status reply
+ uid_str szUID;
buf -= wTextLen;
wLen += wTextLen;
handleMessageTypes(dc->dwRemoteUin, szUID, time(NULL), 0, 0, wCookie, dc->wVersion, (int)bMsgType, (int)bMsgFlags, 2, (DWORD)wLen, wTextLen, (char*)buf, MTF_DIRECT, NULL);
}
- else
- {
+ else {
MCONTACT hCookieContact;
cookie_message_data *pCookieData = NULL;
-
if (!FindCookie(wCookie, &hCookieContact, (void**)&pCookieData))
- {
NetLog_Direct("Received an unexpected direct ack");
- }
- else if (hCookieContact != dc->hContact)
- {
+ else if (hCookieContact != dc->hContact) {
NetLog_Direct("Direct Contact does not match Cookie Contact(0x%x != 0x%x)", dc->hContact, hCookieContact);
ReleaseCookie(wCookie); // This could be a bad idea, but I think it is safe
}
- else
- { // the ack is correct
+ else { // the ack is correct
int ackType = -1;
- switch (bMsgType)
- {
+ switch (bMsgType) {
case MTYPE_PLAIN:
ackType = ACKTYPE_MESSAGE;
break;
@@ -197,22 +181,19 @@ void CIcqProto::handleDirectMessage(directconnect* dc, PBYTE buf, WORD wLen) handleDirectGreetingMessage(dc, buf, wLen, wCommand, wCookie, bMsgType, bMsgFlags, wStatus, wFlags, pszText);
break;
- default:
+ default:
NetLog_Direct("Skipped packet from direct connection");
break;
}
- if (ackType != -1)
- { // was a good ack to broadcast ?
+ if (ackType != -1) { // was a good ack to broadcast ?
ProtoBroadcastAck(dc->hContact, ackType, ACKRESULT_SUCCESS, (HANDLE)wCookie, 0);
ReleaseCookie(wCookie);
}
}
}
}
- else if (wCommand == DIRECT_CANCEL)
- {
+ else if (wCommand == DIRECT_CANCEL)
NetLog_Direct("Cannot handle abort messages yet... :(");
- }
else
NetLog_Direct("Unknown wCommand, packet skipped");
}
@@ -225,18 +206,14 @@ void CIcqProto::handleDirectGreetingMessage(directconnect* dc, PBYTE buf, WORD w int typeId;
WORD qt;
-#ifdef _DEBUG
NetLog_Direct("Handling PEER_MSG_GREETING, command %u, cookie %u, messagetype %u, messageflags %u, status %u, flags %u", wCommand, wCookie, bMsgType, bMsgFlags, wStatus, wFlags);
-#endif
-
- NetLog_Direct("Parsing Greeting message through direct");
- if (!unpackPluginTypeId(&buf, &wLen, &typeId, &qt, TRUE)) return;
+ if (!unpackPluginTypeId(&buf, &wLen, &typeId, &qt, TRUE))
+ return;
// Length of remaining data
unpackLEDWord(&buf, &dwLengthToEnd);
- if (dwLengthToEnd < 4 || dwLengthToEnd > wLen)
- {
+ if (dwLengthToEnd < 4 || dwLengthToEnd > wLen) {
NetLog_Direct("Error: Sanity checking failed (%d) in handleDirectGreetingMessage, datalen %u wLen %u", 2, dwLengthToEnd, wLen);
return;
}
@@ -244,30 +221,23 @@ void CIcqProto::handleDirectGreetingMessage(directconnect* dc, PBYTE buf, WORD w // Length of message/reason
unpackLEDWord(&buf, &dwDataLength);
wLen -= 4;
- if (dwDataLength > wLen)
- {
+ if (dwDataLength > wLen) {
NetLog_Direct("Error: Sanity checking failed (%d) in handleDirectGreetingMessage, datalen %u wLen %u", 3, dwDataLength, wLen);
return;
}
- if (typeId == MTYPE_FILEREQ && wCommand == DIRECT_MESSAGE)
- {
- char* szMsg;
-
+ if (typeId == MTYPE_FILEREQ && wCommand == DIRECT_MESSAGE) {
NetLog_Direct("This is file request");
- szMsg = (char*)_alloca(dwDataLength+1);
+ char *szMsg = (char*)_alloca(dwDataLength + 1);
unpackString(&buf, szMsg, (WORD)dwDataLength);
szMsg[dwDataLength] = '\0';
wLen = wLen - (WORD)dwDataLength;
handleFileRequest(buf, wLen, dc->dwRemoteUin, wCookie, 0, 0, szMsg, 8, TRUE);
}
- else if (typeId == MTYPE_FILEREQ && wCommand == DIRECT_ACK)
- {
- char* szMsg;
-
+ else if (typeId == MTYPE_FILEREQ && wCommand == DIRECT_ACK) {
NetLog_Direct("This is file ack");
- szMsg = (char*)_alloca(dwDataLength+1);
+ char *szMsg = (char*)_alloca(dwDataLength + 1);
unpackString(&buf, szMsg, (WORD)dwDataLength);
szMsg[dwDataLength] = '\0';
wLen = wLen - (WORD)dwDataLength;
@@ -275,10 +245,9 @@ void CIcqProto::handleDirectGreetingMessage(directconnect* dc, PBYTE buf, WORD w // 50 - file request granted/refused
handleFileAck(buf, wLen, dc->dwRemoteUin, wCookie, wStatus, szMsg);
}
- else if (typeId && wCommand == DIRECT_MESSAGE)
- {
- uid_str szUID;
- message_ack_params pMsgAck = {0};
+ else if (typeId && wCommand == DIRECT_MESSAGE) {
+ uid_str szUID;
+ message_ack_params pMsgAck = { 0 };
pMsgAck.bType = MAT_DIRECT;
pMsgAck.pDC = dc;
@@ -286,37 +255,31 @@ void CIcqProto::handleDirectGreetingMessage(directconnect* dc, PBYTE buf, WORD w pMsgAck.msgType = typeId;
handleMessageTypes(dc->dwRemoteUin, szUID, time(NULL), 0, 0, wCookie, dc->wVersion, typeId, 0, 0, dwLengthToEnd, (WORD)dwDataLength, (char*)buf, MTF_PLUGIN | MTF_DIRECT, &pMsgAck);
}
- else if (typeId == MTYPE_STATUSMSGEXT && wCommand == DIRECT_ACK)
- { // especially for icq2003b
+ else if (typeId == MTYPE_STATUSMSGEXT && wCommand == DIRECT_ACK) { // especially for icq2003b
NetLog_Direct("This is extended status reply");
- char *szMsg = (char*)_alloca(dwDataLength+1);
- uid_str szUID;
+ char *szMsg = (char*)_alloca(dwDataLength + 1);
+ uid_str szUID;
unpackString(&buf, szMsg, (WORD)dwDataLength);
szMsg[dwDataLength] = '\0';
handleMessageTypes(dc->dwRemoteUin, szUID, time(NULL), 0, 0, wCookie, dc->wVersion, (int)(qt + 0xE7), 3, 2, (DWORD)wLen, (WORD)dwDataLength, szMsg, MTF_PLUGIN | MTF_DIRECT, NULL);
}
- else if (typeId && wCommand == DIRECT_ACK)
- {
+ else if (typeId && wCommand == DIRECT_ACK) {
MCONTACT hCookieContact;
cookie_message_data *pCookieData = NULL;
- if (!FindCookie(wCookie, &hCookieContact, (void**)&pCookieData))
- {
+ if (!FindCookie(wCookie, &hCookieContact, (void**)&pCookieData)) {
NetLog_Direct("Received an unexpected direct ack");
}
- else if (hCookieContact != dc->hContact)
- {
+ else if (hCookieContact != dc->hContact) {
NetLog_Direct("Direct Contact does not match Cookie Contact(0x%x != 0x%x)", dc->hContact, hCookieContact);
ReleaseCookie(wCookie); // This could be a bad idea, but I think it is safe
}
- else
- {
+ else {
int ackType = -1;
- switch (typeId)
- {
+ switch (typeId) {
case MTYPE_MESSAGE:
ackType = ACKTYPE_MESSAGE;
break;
@@ -328,9 +291,7 @@ void CIcqProto::handleDirectGreetingMessage(directconnect* dc, PBYTE buf, WORD w break;
case MTYPE_SCRIPT_NOTIFY:
{
- char *szMsg;
-
- szMsg = (char*)_alloca(dwDataLength + 1);
+ char *szMsg = (char*)_alloca(dwDataLength + 1);
if (dwDataLength > 0)
memcpy(szMsg, buf, dwDataLength);
szMsg[dwDataLength] = '\0';
@@ -344,14 +305,12 @@ void CIcqProto::handleDirectGreetingMessage(directconnect* dc, PBYTE buf, WORD w break;
}
- if (ackType != -1)
- { // was a good ack to broadcast ?
+ if (ackType != -1) { // was a good ack to broadcast ?
ProtoBroadcastAck(dc->hContact, ackType, ACKRESULT_SUCCESS, (HANDLE)wCookie, 0);
}
// Release cookie
ReleaseCookie(wCookie);
}
}
- else
- NetLog_Direct("Unsupported plugin message type %s", typeId);
+ else NetLog_Direct("Unsupported plugin message type %s", typeId);
}
diff --git a/protocols/IcqOscarJ/src/icq_filerequests.cpp b/protocols/IcqOscarJ/src/icq_filerequests.cpp index fec6fe6e0a..afb4d94bcc 100644 --- a/protocols/IcqOscarJ/src/icq_filerequests.cpp +++ b/protocols/IcqOscarJ/src/icq_filerequests.cpp @@ -34,25 +34,21 @@ void CIcqProto::handleFileAck(PBYTE buf, WORD wLen, DWORD dwUin, DWORD dwCookie, WORD wFilenameLength;
filetransfer* ft;
-
// Find the filetransfer that belongs to this response
- if (!FindCookie(dwCookie, &hCookieContact, (void**)&ft))
- {
+ if (!FindCookie(dwCookie, &hCookieContact, (void**)&ft)) {
NetLog_Direct("Error: Received unexpected file transfer request response");
return;
}
FreeCookie(dwCookie);
- if (hCookieContact != HContactFromUIN(dwUin, NULL))
- {
+ if (hCookieContact != HContactFromUIN(dwUin, NULL)) {
NetLog_Direct("Error: UINs do not match in file transfer request response");
return;
}
// If status != 0, a request has been denied
- if (wStatus != 0)
- {
+ if (wStatus != 0) {
NetLog_Direct("File transfer denied by %u.", dwUin);
ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_DENIED, (HANDLE)ft, 0);
@@ -61,8 +57,7 @@ void CIcqProto::handleFileAck(PBYTE buf, WORD wLen, DWORD dwUin, DWORD dwCookie, return;
}
- if (wLen < 6)
- { // sanity check
+ if (wLen < 6) { // sanity check
NetLog_Direct("Ignoring malformed file transfer request response");
return;
}
@@ -78,18 +73,16 @@ void CIcqProto::handleFileAck(PBYTE buf, WORD wLen, DWORD dwUin, DWORD dwCookie, // Filename
unpackLEWord(&buf, &wFilenameLength);
- if (wFilenameLength > 0)
- {
+ if (wFilenameLength > 0) {
if (wFilenameLength > wLen - 2)
wFilenameLength = wLen - 2;
- pszFileName = (char*)_alloca(wFilenameLength+1);
+ pszFileName = (char*)_alloca(wFilenameLength + 1);
unpackString(&buf, pszFileName, wFilenameLength);
pszFileName[wFilenameLength] = '\0';
}
wLen = wLen - 2 - wFilenameLength;
- if (wLen >= 4)
- { // Total filesize
+ if (wLen >= 4) { // Total filesize
unpackLEDWord(&buf, &dwFileSize);
wLen -= 4;
}
@@ -167,7 +160,7 @@ void CIcqProto::handleFileRequest(PBYTE buf, WORD wLen, DWORD dwUin, DWORD dwCoo // Send chain event
TCHAR* ptszFileName = mir_utf8decodeT(pszFileName);
- PROTORECVFILET pre = {0};
+ PROTORECVFILET pre = { 0 };
pre.flags = PREF_TCHAR;
pre.fileCount = 1;
pre.timestamp = time(NULL);
@@ -194,14 +187,12 @@ void CIcqProto::icq_CancelFileTransfer(MCONTACT hContact, filetransfer* ft) if (FindCookieByData(ft, &dwCookie, NULL))
FreeCookie(dwCookie); /* this bit stops a send that's waiting for acceptance */
- if (IsValidFileTransfer(ft))
- { // Transfer still out there, end it
+ if (IsValidFileTransfer(ft)) { // Transfer still out there, end it
NetLib_CloseConnection(&ft->hConnection, FALSE);
ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0);
- if (!FindFileTransferDC(ft))
- { // Release orphan structure only
+ if (!FindFileTransferDC(ft)) { // Release orphan structure only
SafeReleaseFileTransfer((void**)&ft);
}
}
diff --git a/protocols/IcqOscarJ/src/icq_filetransfer.cpp b/protocols/IcqOscarJ/src/icq_filetransfer.cpp index ebdcaa4a9e..b1cc948705 100644 --- a/protocols/IcqOscarJ/src/icq_filetransfer.cpp +++ b/protocols/IcqOscarJ/src/icq_filetransfer.cpp @@ -63,7 +63,7 @@ static void file_sendNick(CIcqProto* ppro, directconnect* dc) icq_packet packet;
char* szNick;
WORD wNickLen;
- DBVARIANT dbv = {DBVT_DELETED};
+ DBVARIANT dbv = { DBVT_DELETED };
if (ppro->getString("Nick", &dbv))
szNick = "";
@@ -88,8 +88,7 @@ static void file_sendNextFile(CIcqProto* ppro, directconnect* dc) struct _stati64 statbuf;
char szThisSubDir[MAX_PATH];
- if (dc->ft->iCurrentFile >= (int)dc->ft->dwFileCount)
- {
+ if (dc->ft->iCurrentFile >= (int)dc->ft->dwFileCount) {
ppro->ProtoBroadcastAck(dc->ft->hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, dc->ft, 0);
ppro->CloseDirectConnection(dc);
dc->ft->hConnection = NULL;
@@ -97,8 +96,7 @@ static void file_sendNextFile(CIcqProto* ppro, directconnect* dc) }
dc->ft->szThisFile = dc->ft->pszFiles[dc->ft->iCurrentFile];
- if (FileStatUtf(dc->ft->szThisFile, &statbuf))
- {
+ if (FileStatUtf(dc->ft->szThisFile, &statbuf)) {
ppro->icq_LogMessage(LOG_ERROR, LPGEN("Your file transfer has been aborted because one of the files that you selected to send is no longer readable from the disk. You may have deleted or moved it."));
ppro->CloseDirectConnection(dc);
dc->ft->hConnection = NULL;
@@ -107,16 +105,13 @@ static void file_sendNextFile(CIcqProto* ppro, directconnect* dc) char *pszThisFileName = FindFilePathContainer((LPCSTR*)dc->ft->pszFiles, dc->ft->iCurrentFile, szThisSubDir);
- if (statbuf.st_mode&_S_IFDIR)
- {
+ if (statbuf.st_mode&_S_IFDIR) {
dc->ft->currentIsDir = 1;
}
- else
- {
+ else {
dc->ft->currentIsDir = 0;
dc->ft->fileId = OpenFileUtf(dc->ft->szThisFile, _O_BINARY | _O_RDONLY, _S_IREAD);
- if (dc->ft->fileId == -1)
- {
+ if (dc->ft->fileId == -1) {
ppro->icq_LogMessage(LOG_ERROR, LPGEN("Your file transfer has been aborted because one of the files that you selected to send is no longer readable from the disk. You may have deleted or moved it."));
ppro->CloseDirectConnection(dc);
dc->ft->hConnection = NULL;
@@ -173,8 +168,7 @@ static void file_sendData(CIcqProto* ppro, directconnect* dc) BYTE buf[2048];
int bytesRead = 0;
- if (!dc->ft->currentIsDir)
- {
+ if (!dc->ft->currentIsDir) {
icq_packet packet;
if (dc->ft->fileId == -1)
@@ -192,8 +186,7 @@ static void file_sendData(CIcqProto* ppro, directconnect* dc) dc->ft->dwBytesDone += bytesRead;
dc->ft->dwFileBytesDone += bytesRead;
- if (GetTickCount() > dc->ft->dwLastNotify + 500 || bytesRead == 0)
- {
+ if (GetTickCount() > dc->ft->dwLastNotify + 500 || bytesRead == 0) {
PROTOFILETRANSFERSTATUS pfts;
file_buildProtoFileTransferStatus(dc->ft, &pfts);
@@ -202,8 +195,7 @@ static void file_sendData(CIcqProto* ppro, directconnect* dc) dc->ft->dwLastNotify = GetTickCount();
}
- if (bytesRead == 0)
- {
+ if (bytesRead == 0) {
if (!dc->ft->currentIsDir) _close(dc->ft->fileId);
dc->ft->fileId = -1;
dc->wantIdleTime = 0;
@@ -229,8 +221,7 @@ void CIcqProto::icq_sendFileResume(filetransfer *ft, int action, const char *szF int openFlags;
- switch (action)
- {
+ switch (action) {
case FILERESUME_RESUME:
openFlags = _O_BINARY | _O_WRONLY;
break;
@@ -254,8 +245,7 @@ void CIcqProto::icq_sendFileResume(filetransfer *ft, int action, const char *szF }
ft->fileId = OpenFileUtf(ft->szThisFile, openFlags, _S_IREAD | _S_IWRITE);
- if (ft->fileId == -1)
- {
+ if (ft->fileId == -1) {
icq_LogMessage(LOG_ERROR, LPGEN("Your file receive has been aborted because Miranda could not open the destination file in order to write to it. You may be trying to save to a read-only folder."));
NetLib_CloseConnection(&ft->hConnection, FALSE);
return;
@@ -279,7 +269,7 @@ void NormalizeBackslash(char* path) {
int len = strlennull(path);
- if (len && path[len-1] != '\\') strcat(path, "\\");
+ if (len && path[len - 1] != '\\') strcat(path, "\\");
}
/* a file transfer looks like this:
@@ -299,8 +289,7 @@ void CIcqProto::handleFileTransferPacket(directconnect* dc, PBYTE buf, WORD wLen NetLog_Direct("Handling file packet");
- switch (buf[0])
- {
+ switch (buf[0]) {
case PEER_FILE_INIT: /* first packet of a file transfer */
if (dc->initialised)
return;
@@ -321,8 +310,7 @@ void CIcqProto::handleFileTransferPacket(directconnect* dc, PBYTE buf, WORD wLen unpackLEWord(&buf, &wNickLength);
dc->ft = FindExpectedFileRecv(dc->dwRemoteUin, dwTotalSize);
- if (dc->ft == NULL)
- {
+ if (dc->ft == NULL) {
NetLog_Direct("Unexpected file receive");
CloseDirectConnection(dc);
return;
@@ -358,7 +346,7 @@ void CIcqProto::handleFileTransferPacket(directconnect* dc, PBYTE buf, WORD wLen return;
buf++; /* id */
{
- char *szAnsi;
+ char *szAnsi;
WORD wThisFilenameLen, wSubdirLen;
BYTE isDirectory;
@@ -367,39 +355,38 @@ void CIcqProto::handleFileTransferPacket(directconnect* dc, PBYTE buf, WORD wLen if (wLen < 19 + wThisFilenameLen)
return;
SAFE_FREE(&dc->ft->szThisFile);
- szAnsi = (char *)_alloca(wThisFilenameLen + 1);
+ szAnsi = (char *)_alloca(wThisFilenameLen + 1);
memcpy(szAnsi, buf, wThisFilenameLen);
szAnsi[wThisFilenameLen] = '\0';
- dc->ft->szThisFile = ansi_to_utf8(szAnsi);
+ dc->ft->szThisFile = ansi_to_utf8(szAnsi);
buf += wThisFilenameLen;
unpackLEWord(&buf, &wSubdirLen);
if (wLen < 18 + wThisFilenameLen + wSubdirLen)
return;
SAFE_FREE(&dc->ft->szThisSubdir);
- szAnsi = (char *)_alloca(wSubdirLen + 1);
+ szAnsi = (char *)_alloca(wSubdirLen + 1);
memcpy(szAnsi, buf, wSubdirLen);
szAnsi[wSubdirLen] = '\0';
dc->ft->szThisSubdir = ansi_to_utf8(szAnsi);
buf += wSubdirLen;
unpackLEDWord(&buf, &dc->ft->dwThisFileSize);
- unpackLEDWord(&buf, &dc->ft->dwThisFileDate);
- unpackLEDWord(&buf, &dc->ft->dwTransferSpeed);
+ unpackLEDWord(&buf, &dc->ft->dwThisFileDate);
+ unpackLEDWord(&buf, &dc->ft->dwTransferSpeed);
/* no cheating with paths */
- if (!IsValidRelativePath(dc->ft->szThisFile) || !IsValidRelativePath(dc->ft->szThisSubdir))
- {
+ if (!IsValidRelativePath(dc->ft->szThisFile) || !IsValidRelativePath(dc->ft->szThisSubdir)) {
NetLog_Direct("Invalid path information");
break;
}
- char *szFullPath = (char*)SAFE_MALLOC(strlennull(dc->ft->szSavePath)+strlennull(dc->ft->szThisSubdir)+strlennull(dc->ft->szThisFile)+3);
+ char *szFullPath = (char*)SAFE_MALLOC(strlennull(dc->ft->szSavePath) + strlennull(dc->ft->szThisSubdir) + strlennull(dc->ft->szThisFile) + 3);
strcpy(szFullPath, dc->ft->szSavePath);
NormalizeBackslash(szFullPath);
strcat(szFullPath, dc->ft->szThisSubdir);
NormalizeBackslash(szFullPath);
-// _chdir(szFullPath); // set current dir - not very useful
+ // _chdir(szFullPath); // set current dir - not very useful
strcat(szFullPath, dc->ft->szThisFile);
// we joined the full path to dest file
SAFE_FREE(&dc->ft->szThisFile);
@@ -408,23 +395,20 @@ void CIcqProto::handleFileTransferPacket(directconnect* dc, PBYTE buf, WORD wLen dc->ft->dwFileBytesDone = 0;
dc->ft->iCurrentFile++;
- if (isDirectory)
- {
+ if (isDirectory) {
MakeDirUtf(dc->ft->szThisFile);
dc->ft->fileId = -1;
}
- else
- {
+ else {
/* file resume */
- PROTOFILETRANSFERSTATUS pfts = {0};
+ PROTOFILETRANSFERSTATUS pfts = { 0 };
file_buildProtoFileTransferStatus(dc->ft, &pfts);
if (ProtoBroadcastAck(dc->ft->hContact, ACKTYPE_FILE, ACKRESULT_FILERESUME, dc->ft, (LPARAM)&pfts))
break; /* UI supports resume: it will call PS_FILERESUME */
dc->ft->fileId = OpenFileUtf(dc->ft->szThisFile, _O_BINARY | _O_CREAT | _O_TRUNC | _O_WRONLY, _S_IREAD | _S_IWRITE);
- if (dc->ft->fileId == -1)
- {
+ if (dc->ft->fileId == -1) {
icq_LogMessage(LOG_ERROR, LPGEN("Your file receive has been aborted because Miranda could not open the destination file in order to write to it. You may be trying to save to a read-only folder."));
CloseDirectConnection(dc);
dc->ft->hConnection = NULL;
@@ -470,8 +454,7 @@ void CIcqProto::handleFileTransferPacket(directconnect* dc, PBYTE buf, WORD wLen break;
case PEER_FILE_DATA:
- if (!dc->ft->currentIsDir)
- {
+ if (!dc->ft->currentIsDir) {
if (dc->ft->fileId == -1)
break;
buf++; wLen--;
@@ -481,22 +464,19 @@ void CIcqProto::handleFileTransferPacket(directconnect* dc, PBYTE buf, WORD wLen wLen = 0;
dc->ft->dwBytesDone += wLen;
dc->ft->dwFileBytesDone += wLen;
- if (GetTickCount() > dc->ft->dwLastNotify + 500 || wLen < 2048)
- {
+ if (GetTickCount() > dc->ft->dwLastNotify + 500 || wLen < 2048) {
PROTOFILETRANSFERSTATUS pfts;
file_buildProtoFileTransferStatus(dc->ft, &pfts);
ProtoBroadcastAck(dc->ft->hContact, ACKTYPE_FILE, ACKRESULT_DATA, dc->ft, (LPARAM)&pfts);
dc->ft->dwLastNotify = GetTickCount();
}
- if (wLen < 2048)
- {
+ if (wLen < 2048) {
/* EOF */
if (!dc->ft->currentIsDir)
_close(dc->ft->fileId);
dc->ft->fileId = -1;
- if ((DWORD)dc->ft->iCurrentFile == dc->ft->dwFileCount - 1)
- {
+ if ((DWORD)dc->ft->iCurrentFile == dc->ft->dwFileCount - 1) {
dc->type = DIRECTCONN_CLOSING; /* this guarantees that we won't accept any more data but that the sender is still free to closesocket() neatly */
ProtoBroadcastAck(dc->ft->hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, dc->ft, 0);
}
diff --git a/protocols/IcqOscarJ/src/icq_infoupdate.cpp b/protocols/IcqOscarJ/src/icq_infoupdate.cpp index e50a6fa6ce..7d1bfba072 100644 --- a/protocols/IcqOscarJ/src/icq_infoupdate.cpp +++ b/protocols/IcqOscarJ/src/icq_infoupdate.cpp @@ -90,9 +90,9 @@ BOOL CIcqProto::icq_QueueUser(MCONTACT hContact) 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);
-#endif
+
// Notify worker thread
if (hInfoQueueEvent && bInfoUpdateEnabled)
SetEvent(hInfoQueueEvent);
@@ -114,9 +114,8 @@ void CIcqProto::icq_DequeueUser(DWORD dwUin) nChecked++;
// Remove from list
if (m_infoUpdateList[i].dwUin == dwUin) {
-#ifdef _DEBUG
debugLogA("Dequeued user %u", m_infoUpdateList[i].dwUin);
-#endif
+
m_infoUpdateList[i].dwUin = 0;
m_infoUpdateList[i].hContact = NULL;
m_infoUpdateList[i].queued = 0;
@@ -218,9 +217,8 @@ void __cdecl CIcqProto::InfoUpdateThread( void* ) // 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
debugLogA("%s thread ended.", "Info-Update");
@@ -229,9 +227,8 @@ void __cdecl CIcqProto::InfoUpdateThread( void* ) continue;
}
-#ifdef _DEBUG
debugLogA("Info-Update: Users %u in queue.", nInfoUserCount);
-#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
@@ -244,9 +241,9 @@ void __cdecl CIcqProto::InfoUpdateThread( void* ) int nDelay = m_rates->getDelayToLimitLevel(wGroup, RML_IDLE_50);
m_ratesMutex->Leave();
-#ifdef _DEBUG
+
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
debugLogA("%s thread ended.", "Info-Update");
@@ -293,9 +290,8 @@ void __cdecl CIcqProto::InfoUpdateThread( void* ) }
}
else {
-#ifdef _DEBUG
debugLogA("Dequeued absolete user %u", m_infoUpdateList[i].dwUin);
-#endif
+
// Dequeue user and find another one
m_infoUpdateList[i].dwUin = 0;
m_infoUpdateList[i].hContact = NULL;
@@ -305,9 +301,8 @@ void __cdecl CIcqProto::InfoUpdateThread( void* ) }
}
-#ifdef _DEBUG
debugLogA("Request info for %u user(s).", nListIndex);
-#endif
+
if (!nListIndex) { // no users to request info for
infoUpdateMutex->Leave();
break;
diff --git a/protocols/IcqOscarJ/src/icq_proto.cpp b/protocols/IcqOscarJ/src/icq_proto.cpp index 4f5e5c3b49..1b639c526f 100644 --- a/protocols/IcqOscarJ/src/icq_proto.cpp +++ b/protocols/IcqOscarJ/src/icq_proto.cpp @@ -1041,11 +1041,8 @@ int __cdecl CIcqProto::SendContacts(MCONTACT hContact, int flags, int nContacts, }
if (i == nContacts) {
- icq_packet mData, mNames;
-
-#ifdef _DEBUG
debugLogA("Sending contacts to %s.", strUID(dwUin, szUid));
-#endif
+
// Do not calculate the exact size of the data packet - only the maximal size (easier)
// Sumarize size of group information
// - we do not utilize the full power of the protocol and send all contacts with group "General"
@@ -1054,6 +1051,7 @@ int __cdecl CIcqProto::SendContacts(MCONTACT hContact, int flags, int nContacts, nNamesLen += 9;
// Create data structures
+ icq_packet mData, mNames;
mData.wPlace = 0;
mData.pData = (LPBYTE)SAFE_MALLOC(nDataLen);
mData.wLen = nDataLen;
@@ -1161,18 +1159,14 @@ int __cdecl CIcqProto::SendContacts(MCONTACT hContact, int flags, int nContacts, }
if (i == nContacts) {
- char* pBody;
- char* pBuffer;
-
-#ifdef _DEBUG
debugLogA("Sending contacts to %d.", dwUin);
-#endif
+
// Compute count record's length
_itoa(nContacts, szCount, 10);
nBodyLength += strlennull(szCount) + 1;
// Finally we need to copy the contact data into the packet body
- pBuffer = pBody = (char *)SAFE_MALLOC(nBodyLength);
+ char *pBody, *pBuffer = pBody = (char *)SAFE_MALLOC(nBodyLength);
null_strcpy(pBuffer, szCount, nBodyLength - 1);
pBuffer += strlennull(pBuffer);
*pBuffer++ = (char)0xFE;
@@ -1312,44 +1306,39 @@ HANDLE __cdecl CIcqProto::SendFile(MCONTACT hContact, const TCHAR* szDescription ft->hConnection = NULL;
// Send file transfer request
- {
- char szFiles[64], tmp[64];
- char *pszFiles;
-
+ debugLogA("Init file send");
- debugLogA("Init file send");
+ char *pszFiles;
+ if (ft->dwFileCount == 1) {
+ pszFiles = strchr(ft->pszFiles[0], '\\');
+ if (pszFiles)
+ pszFiles++;
+ else
+ pszFiles = ft->pszFiles[0];
+ }
+ else {
+ char szFiles[64], tmp[64];
+ mir_snprintf(szFiles, SIZEOF(szFiles), ICQTranslateUtfStatic("%d Files", tmp, SIZEOF(tmp)), ft->dwFileCount);
+ pszFiles = szFiles;
+ }
- if (ft->dwFileCount == 1) {
- pszFiles = strchr(ft->pszFiles[0], '\\');
- if (pszFiles)
- pszFiles++;
- else
- pszFiles = ft->pszFiles[0];
- }
- else {
- mir_snprintf(szFiles, SIZEOF(szFiles), ICQTranslateUtfStatic("%d Files", tmp, SIZEOF(tmp)), ft->dwFileCount);
- pszFiles = szFiles;
+ // Send packet
+ if (ft->nVersion == 7) {
+ if (m_bDCMsgEnabled && IsDirectConnectionOpen(hContact, DIRECTCONN_STANDARD, 0)) {
+ int iRes = icq_sendFileSendDirectv7(ft, pszFiles);
+ if (iRes) return ft; // Success
}
-
- // Send packet
- {
- if (ft->nVersion == 7) {
- if (m_bDCMsgEnabled && IsDirectConnectionOpen(hContact, DIRECTCONN_STANDARD, 0)) {
- int iRes = icq_sendFileSendDirectv7(ft, pszFiles);
- if (iRes) return ft; // Success
- }
- debugLogA("Sending v%u file transfer request through server", 7);
- icq_sendFileSendServv7(ft, pszFiles);
- }
- else {
- if (m_bDCMsgEnabled && IsDirectConnectionOpen(hContact, DIRECTCONN_STANDARD, 0)) {
- int iRes = icq_sendFileSendDirectv8(ft, pszFiles);
- if (iRes) return ft; // Success
- }
- debugLogA("Sending v%u file transfer request through server", 8);
- icq_sendFileSendServv8(ft, pszFiles, ACKTYPE_NONE);
- }
+ debugLogA("Sending v%u file transfer request through server", 7);
+ icq_sendFileSendServv7(ft, pszFiles);
+ }
+ else {
+ if (m_bDCMsgEnabled && IsDirectConnectionOpen(hContact, DIRECTCONN_STANDARD, 0)) {
+ int iRes = icq_sendFileSendDirectv8(ft, pszFiles);
+ if (iRes)
+ return ft; // Success
}
+ debugLogA("Sending v%u file transfer request through server", 8);
+ icq_sendFileSendServv8(ft, pszFiles, ACKTYPE_NONE);
}
return ft; // Success
@@ -1405,18 +1394,15 @@ int __cdecl CIcqProto::SendMsg(MCONTACT hContact, int flags, const char* pszSrc) makeContactTemporaryVisible(hContact); // make us temporarily visible to contact
// Failure scenarios
- if (!icqOnline()) {
+ if (!icqOnline())
dwCookie = ReportGenericSendError(hContact, ACKTYPE_MESSAGE, "You cannot send messages when you are offline.");
- }
- else if ((wRecipientStatus == ID_STATUS_OFFLINE) && (strlennull(puszText) > 4096)) {
+ else if ((wRecipientStatus == ID_STATUS_OFFLINE) && (strlennull(puszText) > 4096))
dwCookie = ReportGenericSendError(hContact, ACKTYPE_MESSAGE, "Messages to offline contacts must be shorter than 4096 characters.");
- }
// Looks OK
else {
-#ifdef _DEBUG
debugLogA("Send %smessage - Message cap is %u", puszText ? "unicode " : "", CheckContactCapabilities(hContact, CAPF_SRV_RELAY));
debugLogA("Send %smessage - Contact status is %u", puszText ? "unicode " : "", wRecipientStatus);
-#endif
+
if (dwUin && m_bDCMsgEnabled && IsDirectConnectionOpen(hContact, DIRECTCONN_STANDARD, 0)) { // send thru direct
char *dc_msg = puszText;
char *dc_cap = plain_ascii ? NULL : CAP_UTF8MSGS;
diff --git a/protocols/IcqOscarJ/src/icq_rates.cpp b/protocols/IcqOscarJ/src/icq_rates.cpp index fb8962f4e0..a77f49c90b 100644 --- a/protocols/IcqOscarJ/src/icq_rates.cpp +++ b/protocols/IcqOscarJ/src/icq_rates.cpp @@ -44,8 +44,8 @@ rates::rates(CIcqProto *ppro, BYTE *pBuffer, WORD wLen) unpackWord(&pBuffer, &wCount);
wLen -= 2;
- if (wCount > MAX_RATES_GROUP_COUNT)
- { // just sanity check
+ if (wCount > MAX_RATES_GROUP_COUNT) {
+ // just sanity check
ppro->debugLogA("Rates: Error: Data packet contains too many rate groups!");
wCount = MAX_RATES_GROUP_COUNT;
}
@@ -53,12 +53,10 @@ rates::rates(CIcqProto *ppro, BYTE *pBuffer, WORD wLen) nGroups = wCount;
// Parse Group details
int i;
- for (i=0; i<wCount; i++)
- {
+ for (i = 0; i < wCount; i++) {
rates_group *pGroup = &groups[i];
- if (wLen >= 35)
- {
+ if (wLen >= 35) {
pBuffer += 2; // Group ID
unpackDWord(&pBuffer, &pGroup->dwWindowSize);
unpackDWord(&pBuffer, &pGroup->dwClearLevel);
@@ -69,41 +67,35 @@ rates::rates(CIcqProto *ppro, BYTE *pBuffer, WORD wLen) pBuffer += 5;
wLen -= 35;
}
- else
- { // packet broken, put some basic defaults
+ else { // packet broken, put some basic defaults
pGroup->dwWindowSize = 10;
pGroup->dwMaxLevel = 5000;
}
pGroup->rCurrentLevel = pGroup->dwMaxLevel;
}
// Parse Group associated pairs
- for (i=0; i<wCount; i++)
- {
+ for (i = 0; i < wCount; i++) {
rates_group *pGroup = &groups[i];
WORD wNum;
- if (wLen<4) break;
+ if (wLen < 4) break;
pBuffer += 2; // Group ID
unpackWord(&pBuffer, &wNum);
wLen -= 4;
- if (wLen < wNum*4) break;
+ if (wLen < wNum * 4) break;
pGroup->nPairs = wNum;
- pGroup->pPairs = (WORD*)SAFE_MALLOC(wNum*4);
- for (int n=0; n<wNum*2; n++)
- {
+ pGroup->pPairs = (WORD*)SAFE_MALLOC(wNum * 4);
+ for (int n = 0; n < wNum * 2; n++) {
WORD wItem;
unpackWord(&pBuffer, &wItem);
pGroup->pPairs[n] = wItem;
}
-#ifdef _DEBUG
- ppro->debugLogA("Rates: %d# %d pairs.", i+1, wNum);
-#endif
- wLen -= wNum*4;
+
+ wLen -= wNum * 4;
}
}
-
rates::~rates()
{
for (int i = 0; i < nGroups; i++)
@@ -112,19 +104,14 @@ rates::~rates() nGroups = 0;
}
-
WORD rates::getGroupFromSNAC(WORD wFamily, WORD wCommand)
{
- if (this)
- {
- for (int i = 0; i < nGroups; i++)
- {
+ if (this) {
+ for (int i = 0; i < nGroups; i++) {
rates_group* pGroup = &groups[i];
- for (int j = 0; j < 2 * pGroup->nPairs; j += 2)
- {
- if (pGroup->pPairs[j] == wFamily && pGroup->pPairs[j + 1] == wCommand)
- { // we found the group
+ for (int j = 0; j < 2 * pGroup->nPairs; j += 2) {
+ if (pGroup->pPairs[j] == wFamily && pGroup->pPairs[j + 1] == wCommand) { // we found the group
return (WORD)(i + 1);
}
}
@@ -135,13 +122,10 @@ WORD rates::getGroupFromSNAC(WORD wFamily, WORD wCommand) return 0; // Failure
}
-
WORD rates::getGroupFromPacket(icq_packet *pPacket)
{
- if (this)
- {
- if (pPacket->nChannel == ICQ_DATA_CHAN && pPacket->wLen >= 0x10)
- {
+ if (this) {
+ if (pPacket->nChannel == ICQ_DATA_CHAN && pPacket->wLen >= 0x10) {
WORD wFamily, wCommand;
BYTE *pBuf = pPacket->pData + 6;
@@ -154,7 +138,6 @@ WORD rates::getGroupFromPacket(icq_packet *pPacket) return 0;
}
-
rates_group* rates::getGroup(WORD wGroup)
{
if (this && wGroup && wGroup <= nGroups)
@@ -163,21 +146,18 @@ rates_group* rates::getGroup(WORD wGroup) return NULL;
}
-
int rates::getNextRateLevel(WORD wGroup)
{
rates_group *pGroup = getGroup(wGroup);
- if (pGroup)
- {
- int nLevel = pGroup->rCurrentLevel*(pGroup->dwWindowSize-1)/pGroup->dwWindowSize + (GetTickCount() - pGroup->tCurrentLevel)/pGroup->dwWindowSize;
+ if (pGroup) {
+ int nLevel = pGroup->rCurrentLevel*(pGroup->dwWindowSize - 1) / pGroup->dwWindowSize + (GetTickCount() - pGroup->tCurrentLevel) / pGroup->dwWindowSize;
return nLevel < (int)pGroup->dwMaxLevel ? nLevel : pGroup->dwMaxLevel;
}
return -1; // Failure
}
-
int rates::getDelayToLimitLevel(WORD wGroup, int nLevel)
{
rates_group *pGroup = getGroup(wGroup);
@@ -188,11 +168,9 @@ int rates::getDelayToLimitLevel(WORD wGroup, int nLevel) return 0; // Failure
}
-
void rates::packetSent(icq_packet *pPacket)
{
- if (this)
- {
+ if (this) {
WORD wGroup = getGroupFromPacket(pPacket);
if (wGroup)
@@ -200,30 +178,24 @@ void rates::packetSent(icq_packet *pPacket) }
}
-
void rates::updateLevel(WORD wGroup, int nLevel)
{
rates_group *pGroup = getGroup(wGroup);
- if (pGroup)
- {
+ if (pGroup) {
pGroup->rCurrentLevel = nLevel;
pGroup->tCurrentLevel = GetTickCount();
-#ifdef _DEBUG
+
ppro->debugLogA("Rates: New level %d for #%d", nLevel, wGroup);
-#endif
}
}
-
int rates::getLimitLevel(WORD wGroup, int nLevel)
{
rates_group *pGroup = getGroup(wGroup);
- if (pGroup)
- {
- switch(nLevel)
- {
+ if (pGroup) {
+ switch (nLevel) {
case RML_CLEAR:
return pGroup->dwClearLevel;
@@ -234,37 +206,33 @@ int rates::getLimitLevel(WORD wGroup, int nLevel) return pGroup->dwLimitLevel;
case RML_IDLE_10:
- return pGroup->dwClearLevel + ((pGroup->dwMaxLevel - pGroup->dwClearLevel)/10);
+ return pGroup->dwClearLevel + ((pGroup->dwMaxLevel - pGroup->dwClearLevel) / 10);
case RML_IDLE_30:
- return pGroup->dwClearLevel + (3*(pGroup->dwMaxLevel - pGroup->dwClearLevel)/10);
+ return pGroup->dwClearLevel + (3 * (pGroup->dwMaxLevel - pGroup->dwClearLevel) / 10);
case RML_IDLE_50:
- return pGroup->dwClearLevel + ((pGroup->dwMaxLevel - pGroup->dwClearLevel)/2);
+ return pGroup->dwClearLevel + ((pGroup->dwMaxLevel - pGroup->dwClearLevel) / 2);
case RML_IDLE_70:
- return pGroup->dwClearLevel + (7*(pGroup->dwMaxLevel - pGroup->dwClearLevel)/10);
+ return pGroup->dwClearLevel + (7 * (pGroup->dwMaxLevel - pGroup->dwClearLevel) / 10);
}
}
return 9999; // some high number - without rates we allow anything
}
-
void rates::initAckPacket(icq_packet *pPacket)
{
- serverPacketInit(pPacket, 10 + nGroups * (int)sizeof(WORD));
+ serverPacketInit(pPacket, 10 + nGroups * (int)sizeof(WORD));
packFNACHeader(pPacket, ICQ_SERVICE_FAMILY, ICQ_CLIENT_RATE_ACK);
for (WORD wGroup = 1; wGroup <= nGroups; wGroup++)
packWord(pPacket, wGroup);
}
-
-
//
// Rate Level 2 Management
/////////////////////////////
-
rates_queue_item::rates_queue_item(CIcqProto *ppro, WORD wGroup) : bCreated(FALSE), dwUin(0), szUid(NULL)
{
this->ppro = ppro;
@@ -273,20 +241,18 @@ rates_queue_item::rates_queue_item(CIcqProto *ppro, WORD wGroup) : bCreated(FALS rates_queue_item::~rates_queue_item()
{
- if (bCreated)
- {
+ if (bCreated) {
SAFE_FREE(&szUid);
bCreated = FALSE;
}
}
-
BOOL rates_queue_item::isEqual(rates_queue_item *pItem)
-{ // the same event (equal address of _vftable) for the same contact
+{
+ // the same event (equal address of _vftable) for the same contact
return (pItem->hContact == this->hContact) && (*(void**)pItem == *(void**)this);
}
-
rates_queue_item* rates_queue_item::copyItem(rates_queue_item *pDest)
{
if (!pDest)
@@ -300,15 +266,11 @@ rates_queue_item* rates_queue_item::copyItem(rates_queue_item *pDest) return pDest;
}
-
void rates_queue_item::execute()
{
-#ifdef _DEBUG
ppro->debugLogA("Rates: Error executing abstract event.");
-#endif
}
-
BOOL rates_queue_item::isOverRate(int nLevel)
{
icq_lock l(ppro->m_ratesMutex);
@@ -319,7 +281,6 @@ BOOL rates_queue_item::isOverRate(int nLevel) return FALSE;
}
-
rates_queue::rates_queue(CIcqProto *ppro, const char *szDescr, int nLimitLevel, int nWaitLevel, int nDuplicates)
{
this->listsMutex = new icq_critical_section();
@@ -330,7 +291,6 @@ rates_queue::rates_queue(CIcqProto *ppro, const char *szDescr, int nLimitLevel, duplicates = nDuplicates;
}
-
rates_queue::~rates_queue()
{
cleanup();
@@ -356,9 +316,7 @@ void __cdecl CIcqProto::rateDelayThread(rate_delay_args *pArgs) void rates_queue::initDelay(int nDelay, IcqRateFunc delaycode)
{
-#ifdef _DEBUG
ppro->debugLogA("Rates: Delay %dms", nDelay);
-#endif
rate_delay_args *pArgs = (rate_delay_args*)SAFE_MALLOC(sizeof(rate_delay_args)); // This will be freed in the new thread
pArgs->queue = this;
@@ -376,7 +334,7 @@ void rates_queue::cleanup() if (pendingListSize)
ppro->debugLogA("Rates: Purging %d %s(s).", pendingListSize, szDescr);
- for (int i=0; i < pendingListSize; i++)
+ for (int i = 0; i < pendingListSize; i++)
delete pendingList[i];
SAFE_FREE((void**)&pendingList);
pendingListSize = 0;
@@ -388,8 +346,7 @@ void rates_queue::processQueue() if (!pendingList)
return;
- if (!ppro->icqOnline())
- {
+ if (!ppro->icqOnline()) {
cleanup();
return;
}
@@ -398,8 +355,7 @@ void rates_queue::processQueue() ppro->m_ratesMutex->Enter();
listsMutex->Enter();
- if (item->isOverRate(limitLevel))
- { // the rate is higher, keep sleeping
+ if (item->isOverRate(limitLevel)) { // the rate is higher, keep sleeping
int nDelay = ppro->m_rates->getDelayToLimitLevel(item->wGroup, ppro->m_rates->getLimitLevel(item->wGroup, waitLevel));
listsMutex->Leave();
@@ -410,8 +366,7 @@ void rates_queue::processQueue() }
ppro->m_ratesMutex->Leave();
- if (pendingListSize > 1)
- { // we need to keep order
+ if (pendingListSize > 1) { // we need to keep order
memmove(&pendingList[0], &pendingList[1], (pendingListSize - 1) * sizeof(rates_queue_item*));
}
else
@@ -421,16 +376,13 @@ void rates_queue::processQueue() listsMutex->Leave();
- if (ppro->icqOnline())
- {
+ if (ppro->icqOnline()) {
ppro->debugLogA("Rates: Resuming %s.", szDescr);
item->execute();
}
- else
- ppro->debugLogA("Rates: Discarding %s.", szDescr);
+ else ppro->debugLogA("Rates: Discarding %s.", szDescr);
- if (bSetupTimer)
- {
+ if (bSetupTimer) {
// in queue remained some items, setup timer
ppro->m_ratesMutex->Enter();
int nDelay = ppro->m_rates->getDelayToLimitLevel(item->wGroup, waitLevel);
@@ -453,20 +405,15 @@ void rates_queue::putItem(rates_queue_item *pItem, int nMinDelay) ppro->debugLogA("Rates: Delaying %s.", szDescr);
listsMutex->Enter();
- if (pendingListSize)
- {
- for (int i = 0; i < pendingListSize; i++)
- {
- if (pendingList[i]->isEqual(pItem))
- {
- if (duplicates == -1)
- { // discard existing, append new item
+ if (pendingListSize) {
+ for (int i = 0; i < pendingListSize; i++) {
+ if (pendingList[i]->isEqual(pItem)) {
+ if (duplicates == -1) { // discard existing, append new item
delete pendingList[i];
memcpy(&pendingList[i], &pendingList[i + 1], (pendingListSize - i - 1) * sizeof(rates_queue_item*));
bFound = TRUE;
}
- else if (duplicates == 1)
- { // keep existing, ignore new
+ else if (duplicates == 1) { // keep existing, ignore new
listsMutex->Leave();
return;
}
@@ -474,15 +421,13 @@ void rates_queue::putItem(rates_queue_item *pItem, int nMinDelay) }
}
}
- if (!bFound)
- { // not found, enlarge the queue
+ if (!bFound) { // not found, enlarge the queue
pendingListSize++;
pendingList = (rates_queue_item**)SAFE_REALLOC(pendingList, pendingListSize * sizeof(rates_queue_item*));
}
pendingList[pendingListSize - 1] = pItem->copyItem();
- if (pendingListSize == 1)
- { // queue was empty setup timer
+ if (pendingListSize == 1) { // queue was empty setup timer
listsMutex->Leave();
ppro->m_ratesMutex->Enter();
int nDelay = ppro->m_rates->getDelayToLimitLevel(pItem->wGroup, waitLevel);
@@ -502,7 +447,7 @@ int CIcqProto::handleRateItem(rates_queue_item *item, int nQueueType, int nMinDe m_ratesMutex->Enter();
switch (nQueueType) {
- case RQT_REQUEST:
+ case RQT_REQUEST:
pQueue = m_ratesQueue_Request;
break;
case RQT_RESPONSE:
diff --git a/protocols/IcqOscarJ/src/icq_server.cpp b/protocols/IcqOscarJ/src/icq_server.cpp index be134164ff..5c7d5368ef 100644 --- a/protocols/IcqOscarJ/src/icq_server.cpp +++ b/protocols/IcqOscarJ/src/icq_server.cpp @@ -248,10 +248,7 @@ int CIcqProto::handleServerPackets(BYTE *buf, int len, serverthread_info *info) if (len < 6 + datalen)
break;
-
-#ifdef _DEBUG
debugLogA("Server FLAP: Channel %u, Seq %u, Length %u bytes", channel, sequence, datalen);
-#endif
switch (channel) {
case ICQ_LOGIN_CHAN:
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);
}
diff --git a/protocols/IcqOscarJ/src/icq_xtraz.cpp b/protocols/IcqOscarJ/src/icq_xtraz.cpp index a210a58037..ef7f84a154 100644 --- a/protocols/IcqOscarJ/src/icq_xtraz.cpp +++ b/protocols/IcqOscarJ/src/icq_xtraz.cpp @@ -54,10 +54,10 @@ void CIcqProto::handleXtrazNotify(DWORD dwUin, DWORD dwMID, DWORD dwMID2, WORD w szQuery = DemangleXml(szQuery, nQueryLen);
szWork = strstrnull(szQuery, "<PluginID>");
szEnd = strstrnull(szQuery, "</PluginID>");
-#ifdef _DEBUG
+
debugLogA("Query: %s", szQuery);
debugLogA("Notify: %s", szNotify);
-#endif
+
if (szWork && szEnd) { // this is our plugin
szWork += 10;
*szEnd = '\0';
@@ -153,34 +153,26 @@ void CIcqProto::handleXtrazNotify(DWORD dwUin, DWORD dwMID, DWORD dwMID2, WORD w else
debugLogA("Error: We are not in XStatus, skipping");
}
- else
- debugLogA("Error: Invalid sender information");
+ else debugLogA("Error: Invalid sender information");
}
- else
- debugLogA("Error: Missing sender information");
+ else debugLogA("Error: Missing sender information");
}
- else
- debugLogA("Error: Unknown plugin \"%s\" in Xtraz message", szWork);
+ else debugLogA("Error: Unknown plugin \"%s\" in Xtraz message", szWork);
}
- else
- debugLogA("Error: Missing PluginID in Xtraz message");
+ else debugLogA("Error: Missing PluginID in Xtraz message");
SAFE_FREE(&szNotify);
SAFE_FREE(&szQuery);
}
- else
- debugLogA("Error: Invalid Xtraz Notify message");
+ else debugLogA("Error: Invalid Xtraz Notify message");
}
-
void CIcqProto::handleXtrazNotifyResponse(DWORD dwUin, MCONTACT hContact, WORD wCookie, char* szMsg, int nMsgLen)
{
char *szMem, *szRes, *szEnd;
int nResLen;
-#ifdef _DEBUG
debugLogA("Received Xtraz Notify Response");
-#endif
szRes = strstrnull(szMsg, "<RES>");
szEnd = strstrnull(szMsg, "</RES>");
@@ -193,9 +185,7 @@ void CIcqProto::handleXtrazNotifyResponse(DWORD dwUin, MCONTACT hContact, WORD w szMem = szRes = DemangleXml(szRes, nResLen);
-#ifdef _DEBUG
debugLogA("Response: %s", szRes);
-#endif
ProtoBroadcastAck(hContact, ICQACKTYPE_XTRAZNOTIFY_RESPONSE, ACKRESULT_SUCCESS, (HANDLE)wCookie, (LPARAM)szRes);
@@ -266,16 +256,13 @@ void CIcqProto::handleXtrazNotifyResponse(DWORD dwUin, MCONTACT hContact, WORD w debugLogA("Error: Unknown serverId \"%s\" in Xtraz response", szNode);
}
}
- else
- debugLogA("Error: Missing serverId in Xtraz response");
+ else debugLogA("Error: Missing serverId in Xtraz response");
SAFE_FREE(&szMem);
}
- else
- debugLogA("Error: Invalid Xtraz Notify response");
+ else debugLogA("Error: Invalid Xtraz Notify response");
}
-
static char* getXmlPidItem(const char* szData, int nLen)
{
const char *szPid, *szEnd;
diff --git a/protocols/IcqOscarJ/src/log.cpp b/protocols/IcqOscarJ/src/log.cpp index 5d3a47bd9d..52d53a85c4 100644 --- a/protocols/IcqOscarJ/src/log.cpp +++ b/protocols/IcqOscarJ/src/log.cpp @@ -27,12 +27,13 @@ extern BOOL bPopupService;
-static const char *szLevelDescr[] = {LPGEN("ICQ Note"), LPGEN("ICQ Warning"), LPGEN("ICQ Error"), LPGEN("ICQ Fatal")};
+static const char *szLevelDescr[] = { LPGEN("ICQ Note"), LPGEN("ICQ Warning"), LPGEN("ICQ Error"), LPGEN("ICQ Fatal") };
-struct LogMessageInfo {
+struct LogMessageInfo
+{
const char *szMsg;
const char *szTitle;
- BYTE bLevel;
+ BYTE bLevel;
};
@@ -42,8 +43,7 @@ void __cdecl CIcqProto::icq_LogMessageThread(void* arg) if (!err)
return;
- if (bPopupService && getByte("PopupsLogEnabled", DEFAULT_LOG_POPUPS_ENABLED))
- {
+ if (bPopupService && getByte("PopupsLogEnabled", DEFAULT_LOG_POPUPS_ENABLED)) {
ShowPopupMsg(NULL, err->szTitle, err->szMsg, err->bLevel);
SAFE_FREE((void**)&err->szMsg);
@@ -66,16 +66,14 @@ void CIcqProto::icq_LogMessage(int level, const char *szMsg) debugLogA("%s", szMsg);
int displayLevel = getByte("ShowLogLevel", LOG_WARNING);
- if (level >= displayLevel)
- {
- if (!bErrorBoxVisible || !getByte("IgnoreMultiErrorBox", 0))
- {
+ if (level >= displayLevel) {
+ if (!bErrorBoxVisible || !getByte("IgnoreMultiErrorBox", 0)) {
// error not shown or allowed multi - show messagebox
LogMessageInfo *lmi = (LogMessageInfo*)SAFE_MALLOC(sizeof(LogMessageInfo));
lmi->bLevel = (BYTE)level;
lmi->szMsg = null_strdup(szMsg);
lmi->szTitle = szLevelDescr[level];
- ForkThread( &CIcqProto::icq_LogMessageThread, lmi);
+ ForkThread(&CIcqProto::icq_LogMessageThread, lmi);
}
}
}
@@ -89,7 +87,7 @@ void CIcqProto::icq_LogUsingErrorCode(int level, DWORD dwError, const char *szMs char *pszErrorMsg = NULL;
int bNeedFree = FALSE;
- switch(dwError) {
+ switch (dwError) {
case ERROR_TIMEOUT:
case WSAETIMEDOUT:
pszErrorMsg = LPGEN("The server did not respond to the connection attempt within a reasonable time, it may be temporarily down. Try again later.");
@@ -120,26 +118,20 @@ void CIcqProto::icq_LogUsingErrorCode(int level, DWORD dwError, const char *szMs break;
default:
- {
- TCHAR err[512];
-
- if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, 0, err, SIZEOF(err), NULL))
- {
-
- pszErrorMsg = make_utf8_string(err);
-
- bNeedFree = TRUE;
- }
- break;
+ TCHAR err[512];
+ if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, 0, err, SIZEOF(err), NULL)) {
+ pszErrorMsg = make_utf8_string(err);
+ bNeedFree = TRUE;
}
+ break;
}
mir_snprintf(szBuf, sizeof(szBuf), "%s%s%s (%s %d)",
- szMsg ? ICQTranslateUtfStatic(szMsg, str, 1024) : "",
- szMsg ? "\r\n\r\n" : "",
- ICQTranslateUtfStatic(pszErrorMsg, szErrorMsg, 512),
- ICQTranslateUtfStatic(LPGEN("error"), str2, 64),
- dwError);
+ szMsg ? ICQTranslateUtfStatic(szMsg, str, 1024) : "",
+ szMsg ? "\r\n\r\n" : "",
+ ICQTranslateUtfStatic(pszErrorMsg, szErrorMsg, 512),
+ ICQTranslateUtfStatic(LPGEN("error"), str2, 64),
+ dwError);
if (bNeedFree)
SAFE_FREE(&pszErrorMsg);
diff --git a/protocols/IcqOscarJ/src/oscar_filetransfer.cpp b/protocols/IcqOscarJ/src/oscar_filetransfer.cpp index 1e244e0f42..97ba1155ea 100644 --- a/protocols/IcqOscarJ/src/oscar_filetransfer.cpp +++ b/protocols/IcqOscarJ/src/oscar_filetransfer.cpp @@ -40,7 +40,6 @@ struct oscarthreadstartinfo oscar_listener *listener;
};
-
// small utility function
extern void NormalizeBackslash(char* path);
@@ -48,32 +47,27 @@ extern void NormalizeBackslash(char* path); // Common functions
/////////////////////////////
-char *FindFilePathContainer(const char **files, int iFile, char *szContainer)
+char* FindFilePathContainer(const char **files, int iFile, char *szContainer)
{
const char *szThisFile = files[iFile];
char *szFileName = (char*)ExtractFileName(szThisFile);
szContainer[0] = '\0';
- if (szThisFile != szFileName)
- { // find an earlier subdirectory to be used as a container
- for (int i = iFile - 1; i >= 0; i--)
- {
+ if (szThisFile != szFileName) { // find an earlier subdirectory to be used as a container
+ for (int i = iFile - 1; i >= 0; i--) {
int len = strlennull(files[i]);
- if (!_strnicmp(files[i], szThisFile, len) && (szThisFile[len] == '\\' || szThisFile[len] == '/'))
- {
+ if (!_strnicmp(files[i], szThisFile, len) && (szThisFile[len] == '\\' || szThisFile[len] == '/')) {
const char *pszLastBackslash;
if (((pszLastBackslash = strrchr(files[i], '\\')) == NULL) &&
- ((pszLastBackslash = strrchr(files[i], '/')) == NULL))
- {
+ ((pszLastBackslash = strrchr(files[i], '/')) == NULL)) {
strcpy(szContainer, files[i]);
}
- else
- {
+ else {
len = pszLastBackslash - files[i] + 1;
- null_strcpy(szContainer, szThisFile + len, szFileName - szThisFile - len);
+ null_strcpy(szContainer, szThisFile + len, szFileName - szThisFile - len);
}
}
}
@@ -81,15 +75,13 @@ char *FindFilePathContainer(const char **files, int iFile, char *szContainer) return szFileName;
}
-
//
// Utility functions
/////////////////////////////
oscar_filetransfer* CIcqProto::CreateOscarTransfer()
{
- oscar_filetransfer* ft = (oscar_filetransfer*)SAFE_MALLOC(sizeof(oscar_filetransfer));
-
+ oscar_filetransfer *ft = (oscar_filetransfer*)SAFE_MALLOC(sizeof(oscar_filetransfer));
ft->ft_magic = FT_MAGIC_OSCAR; // Setup signature
// Init members
ft->fileId = -1;
@@ -99,14 +91,11 @@ oscar_filetransfer* CIcqProto::CreateOscarTransfer() fileTransferList = (basic_filetransfer**)SAFE_REALLOC(fileTransferList, sizeof(basic_filetransfer*)*(fileTransferCount + 1));
fileTransferList[fileTransferCount++] = ft;
-#ifdef _DEBUG
- NetLog_Direct("OFT: FT struct 0x%x created", ft);
-#endif
+ NetLog_Direct("OFT: FT struct %p created", ft);
return ft;
}
-
filetransfer *CIcqProto::CreateIcqFileTransfer()
{
filetransfer *ft = (filetransfer*)SAFE_MALLOC(sizeof(filetransfer));
@@ -118,69 +107,49 @@ filetransfer *CIcqProto::CreateIcqFileTransfer() fileTransferList = (basic_filetransfer**)SAFE_REALLOC(fileTransferList, sizeof(basic_filetransfer*)*(fileTransferCount + 1));
fileTransferList[fileTransferCount++] = (basic_filetransfer*)ft;
-#ifdef _DEBUG
- NetLog_Direct("FT struct 0x%x created", ft);
-#endif
+ NetLog_Direct("FT struct %p created", ft);
return ft;
}
-
int CIcqProto::getFileTransferIndex(void *ft)
{
for (int i = 0; i < fileTransferCount; i++)
- {
if (fileTransferList[i] == ft)
return i;
- }
+
return -1;
}
-
void CIcqProto::ReleaseFileTransfer(void *ft)
{
int i = getFileTransferIndex(ft);
-
- if (i != -1)
- {
+ if (i != -1) {
fileTransferCount--;
fileTransferList[i] = fileTransferList[fileTransferCount];
fileTransferList = (basic_filetransfer**)SAFE_REALLOC(fileTransferList, sizeof(basic_filetransfer*)*fileTransferCount);
}
}
-
int CIcqProto::IsValidFileTransfer(void *ft)
{
icq_lock l(oftMutex);
-
- if (getFileTransferIndex(ft) != -1) return 1;
-
- return 0;
+ return getFileTransferIndex(ft) != -1;
}
-
int CIcqProto::IsValidOscarTransfer(void *ft)
{
icq_lock l(oftMutex);
-
- if (getFileTransferIndex(ft) != -1 && ((basic_filetransfer*)ft)->ft_magic == FT_MAGIC_OSCAR)
- return 1;
-
- return 0;
+ return getFileTransferIndex(ft) != -1 && ((basic_filetransfer*)ft)->ft_magic == FT_MAGIC_OSCAR;
}
-
oscar_filetransfer* CIcqProto::FindOscarTransfer(MCONTACT hContact, DWORD dwID1, DWORD dwID2)
{
icq_lock l(oftMutex);
- for (int i = 0; i < fileTransferCount; i++)
- {
- if (fileTransferList[i]->ft_magic == FT_MAGIC_OSCAR)
- {
+ for (int i = 0; i < fileTransferCount; i++) {
+ if (fileTransferList[i]->ft_magic == FT_MAGIC_OSCAR) {
oscar_filetransfer *oft = (oscar_filetransfer*)fileTransferList[i];
-
if (oft->hContact == hContact && oft->pMessage.dwMsgID1 == dwID1 && oft->pMessage.dwMsgID2 == dwID2)
return oft;
}
@@ -189,7 +158,6 @@ oscar_filetransfer* CIcqProto::FindOscarTransfer(MCONTACT hContact, DWORD dwID1, return NULL;
}
-
// Release file transfer structure
void CIcqProto::SafeReleaseFileTransfer(void **ft)
{
@@ -201,20 +169,16 @@ void CIcqProto::SafeReleaseFileTransfer(void **ft) if (getFileTransferIndex(*ft) == -1)
return;
- if (*bft)
- {
- if ((*bft)->ft_magic == FT_MAGIC_ICQ)
- { // release ICQ filetransfer structure and its contents
+ if (*bft) {
+ if ((*bft)->ft_magic == FT_MAGIC_ICQ) { // release ICQ filetransfer structure and its contents
filetransfer *ift = (filetransfer*)(*bft);
SAFE_FREE(&ift->szFilename);
SAFE_FREE(&ift->szDescription);
SAFE_FREE(&ift->szSavePath);
SAFE_FREE(&ift->szThisSubdir);
- if (ift->pszFiles)
- {
- for (int i = 0; i < (int)ift->dwFileCount; i++)
- {
+ if (ift->pszFiles) {
+ for (int i = 0; i < (int)ift->dwFileCount; i++) {
// szThisFile can be a duplicate of pszFiles[i]
if (ift->szThisFile == ift->pszFiles[i])
ift->szThisFile = NULL;
@@ -225,14 +189,13 @@ void CIcqProto::SafeReleaseFileTransfer(void **ft) SAFE_FREE(&ift->szThisFile);
// Invalidate transfer
ReleaseFileTransfer(ift);
-#ifdef _DEBUG
- NetLog_Direct("FT struct 0x%x released", ft);
-#endif
+
+ NetLog_Direct("FT struct %p released", ft);
+
// Release memory
SAFE_FREE((void**)ft);
}
- else if ((*bft)->ft_magic == FT_MAGIC_OSCAR)
- { // release oscar filetransfer structure and its contents
+ else if ((*bft)->ft_magic == FT_MAGIC_OSCAR) { // release oscar filetransfer structure and its contents
oscar_filetransfer *oft = (oscar_filetransfer*)(*bft);
// If connected, close connection
if (oft->connection)
@@ -249,43 +212,36 @@ void CIcqProto::SafeReleaseFileTransfer(void **ft) SAFE_FREE(&oft->szThisFile);
SAFE_FREE(&oft->szThisPath);
SAFE_FREE(&oft->szDescription);
- if (oft->files)
- {
+
+ if (oft->files) {
for (int i = 0; i < oft->wFilesCount; i++)
SAFE_FREE(&oft->files[i].szFile);
SAFE_FREE((void**)&oft->files);
}
+
if (oft->files_list)
- {
-/* for (int i = 0; i < oft->wFilesCount; i++)
- SAFE_FREE(&oft->files_list[i]);*/
SAFE_FREE((void**)&oft->files_list);
- }
- if (oft->file_containers)
- {
+
+ if (oft->file_containers) {
for (int i = 0; i < oft->containerCount; i++)
SAFE_FREE(&oft->file_containers[i]);
SAFE_FREE((void**)&oft->file_containers);
}
+
if (oft->fileId != -1)
- {
-#ifdef _DEBUG
- NetLog_Direct("OFT: _close(%u)", oft->fileId);
-#endif
_close(oft->fileId);
- }
+
// Invalidate transfer
ReleaseFileTransfer(oft);
-#ifdef _DEBUG
- NetLog_Direct("OFT: FT struct 0x%x released", ft);
-#endif
+
+ NetLog_Direct("OFT: FT struct %p released", ft);
+
// Release memory
SAFE_FREE((void**)ft);
}
}
}
-
// Calculate oft checksum of buffer
// --------------------------------
// Information was gathered from Gaim's sources, thanks
@@ -294,8 +250,7 @@ DWORD oft_calc_checksum(int offset, const BYTE *buffer, int len, DWORD dwChecksu {
DWORD checksum = (dwChecksum >> 16) & 0xffff;
- for (int i = 0; i < len; i++)
- {
+ for (int i = 0; i < len; i++) {
WORD val = buffer[i];
DWORD oldchecksum = checksum;
@@ -312,7 +267,6 @@ DWORD oft_calc_checksum(int offset, const BYTE *buffer, int len, DWORD dwChecksu return checksum << 16;
}
-
DWORD oft_calc_file_checksum(int hFile, __int64 maxSize)
{
BYTE buf[OFT_BUFFER_SIZE];
@@ -325,8 +279,7 @@ DWORD oft_calc_file_checksum(int hFile, __int64 maxSize) if (bytesRead == -1)
return dwCheck;
- while(bytesRead)
- {
+ while (bytesRead) {
dwCheck = oft_calc_checksum((int)offset, buf, bytesRead, dwCheck);
offset += bytesRead;
bytesRead = _read(hFile, buf, sizeof(buf));
@@ -337,13 +290,10 @@ DWORD oft_calc_file_checksum(int hFile, __int64 maxSize) return dwCheck;
}
-
oscar_listener* CIcqProto::CreateOscarListener(oscar_filetransfer *ft, NETLIBNEWCONNECTIONPROC_V2 handler)
{
oscar_listener *listener = (oscar_listener*)SAFE_MALLOC(sizeof(oscar_listener));
-
- if (listener)
- {
+ if (listener) {
listener->ppro = this;
listener->ft = ft;
if (listener->hBoundPort = NetLib_BindPort(handler, listener, &listener->wPort, NULL))
@@ -359,9 +309,7 @@ oscar_listener* CIcqProto::CreateOscarListener(oscar_filetransfer *ft, NETLIBNEW void CIcqProto::ReleaseOscarListener(oscar_listener **pListener)
{
oscar_listener *listener = *pListener;
-
- if (listener)
- { // Close listening port
+ if (listener) { // Close listening port
if (listener->hBoundPort)
NetLib_SafeCloseHandle(&listener->hBoundPort);
@@ -379,16 +327,13 @@ void CIcqProto::handleRecvServMsgOFT(BYTE *buf, WORD wLen, DWORD dwUin, char *sz {
MCONTACT hContact = HContactFromUID(dwUin, szUID, NULL);
- if (wCommand == 0)
- { // this is OFT request
+ if (wCommand == 0) { // this is OFT request
oscar_tlv_chain* chain = readIntoTLVChain(&buf, wLen, 0);
- if (chain)
- {
+ if (chain) {
WORD wAckType = chain->getWord(0x0A, 1);
- if (wAckType == 1)
- { // This is first request in this OFT
+ if (wAckType == 1) { // This is first request in this OFT
oscar_filetransfer *ft = CreateOscarTransfer();
char *pszFileName = NULL;
char *pszDescription = NULL;
@@ -426,51 +371,44 @@ void CIcqProto::handleRecvServMsgOFT(BYTE *buf, WORD wLen, DWORD dwUin, char *sz { // User Message
oscar_tlv* tlv = chain->getTLV(0x0C, 1);
- if (tlv)
- { // parse User Message
+ if (tlv) { // parse User Message
BYTE* tBuf = tlv->pData;
pszDescription = (char*)_alloca(tlv->wLen + 2);
unpackString(&tBuf, (char*)pszDescription, tlv->wLen);
pszDescription[tlv->wLen] = '\0';
- pszDescription[tlv->wLen+1] = '\0';
+ pszDescription[tlv->wLen + 1] = '\0';
{ // apply User Message encoding
oscar_tlv *charset = chain->getTLV(0x0D, 1);
char *str = pszDescription;
- char *bTag,*eTag;
+ char *bTag, *eTag;
- if (charset)
- { // decode charset
+ if (charset) { // decode charset
char *szEnc = (char*)_alloca(charset->wLen + 1);
null_strcpy(szEnc, (char*)charset->pData, charset->wLen);
str = ApplyEncoding((char*)pszDescription, szEnc);
}
- else
+ else
str = null_strdup(str);
// eliminate HTML tags
pszDescription = EliminateHtml(str, strlennull(str));
bTag = strstrnull(pszDescription, "<DESC>");
- if (bTag)
- { // take special Description - ICQJ's extension
+ if (bTag) { // take special Description - ICQJ's extension
eTag = strstrnull(bTag, "</DESC>");
- if (eTag)
- {
+ if (eTag) {
*eTag = '\0';
str = null_strdup(bTag + 6);
SAFE_FREE(&pszDescription);
pszDescription = str;
}
}
- else
- {
+ else {
bTag = strstrnull(pszDescription, "<FS>");
- if (bTag)
- { // take only <FS> - Description tag if present
+ if (bTag) { // take only <FS> - Description tag if present
eTag = strstrnull(bTag, "</FS>");
- if (eTag)
- {
+ if (eTag) {
*eTag = '\0';
str = null_strdup(bTag + 4);
SAFE_FREE(&pszDescription);
@@ -480,8 +418,7 @@ void CIcqProto::handleRecvServMsgOFT(BYTE *buf, WORD wLen, DWORD dwUin, char *sz }
}
}
- if (!strlennull(pszDescription))
- {
+ if (!strlennull(pszDescription)) {
SAFE_FREE(&pszDescription);
pszDescription = ICQTranslateUtf(LPGEN("No description given"));
}
@@ -490,8 +427,7 @@ void CIcqProto::handleRecvServMsgOFT(BYTE *buf, WORD wLen, DWORD dwUin, char *sz oscar_tlv* tlv = chain->getTLV(0x2711, 1);
// sanity check
- if (!tlv || tlv->wLen < 8)
- {
+ if (!tlv || tlv->wLen < 8) {
debugLogA("Error: Malformed file request");
// release structures
SafeReleaseFileTransfer((void**)&ft);
@@ -508,8 +444,7 @@ void CIcqProto::handleRecvServMsgOFT(BYTE *buf, WORD wLen, DWORD dwUin, char *sz unpackDWord(&tBuf, (DWORD*)&ft->qwTotalSize);
tLen -= 8;
// Filename / Directory Name
- if (tLen)
- { // some filename specified, unpack
+ if (tLen) { // some filename specified, unpack
wFilenameLength = tLen - 1;
pszFileName = (char*)_alloca(tLen);
unpackString(&tBuf, (char*)pszFileName, wFilenameLength);
@@ -529,16 +464,14 @@ void CIcqProto::handleRecvServMsgOFT(BYTE *buf, WORD wLen, DWORD dwUin, char *sz }
else pszFileName = ansi_to_utf8(pszFileName);
- if (ft->wFilesCount == 1)
- { // Filename - use for DB event
+ if (ft->wFilesCount == 1) { // Filename - use for DB event
char *szFileName = (char*)_alloca(strlennull(pszFileName) + 1);
strcpy(szFileName, pszFileName);
SAFE_FREE(&pszFileName);
pszFileName = szFileName;
}
- else
- { // Save Directory name for future use
+ else { // Save Directory name for future use
ft->szThisPath = pszFileName;
// for multi-file transfer we do not display "folder" name, but create only a simple notice
pszFileName = (char*)_alloca(64);
@@ -548,11 +481,10 @@ void CIcqProto::handleRecvServMsgOFT(BYTE *buf, WORD wLen, DWORD dwUin, char *sz }
}
// Total Size TLV (ICQ 6 and AIM 6)
- {
+ {
oscar_tlv *tlv = chain->getTLV(0x2713, 1);
- if (tlv && tlv->wLen >= 8)
- {
+ if (tlv && tlv->wLen >= 8) {
BYTE *tBuf = tlv->pData;
unpackQWord(&tBuf, &ft->qwTotalSize);
@@ -572,7 +504,7 @@ void CIcqProto::handleRecvServMsgOFT(BYTE *buf, WORD wLen, DWORD dwUin, char *sz TCHAR* ptszFileName = mir_utf8decodeT(pszFileName);
- PROTORECVFILET pre = {0};
+ PROTORECVFILET pre = { 0 };
pre.flags = PREF_TCHAR;
pre.fileCount = 1;
pre.timestamp = time(NULL);
@@ -584,18 +516,14 @@ void CIcqProto::handleRecvServMsgOFT(BYTE *buf, WORD wLen, DWORD dwUin, char *sz mir_free(pre.tszDescription);
mir_free(ptszFileName);
}
- else if (wAckType == 2)
- { // First attempt failed, reverse requested
+ else if (wAckType == 2) { // First attempt failed, reverse requested
oscar_filetransfer *ft = FindOscarTransfer(hContact, dwID1, dwID2);
-
- if (ft)
- {
+ if (ft) {
NetLog_Direct("OFT: Redirect received (%d)", wAckType);
ft->wReqNum = wAckType;
- if (ft->flags & OFTF_SENDING)
- {
+ if (ft->flags & OFTF_SENDING) {
ReleaseOscarListener((oscar_listener**)&ft->listener);
ft->bUseProxy = chain->getTLV(0x10, 1) ? 1 : 0;
@@ -604,24 +532,19 @@ void CIcqProto::handleRecvServMsgOFT(BYTE *buf, WORD wLen, DWORD dwUin, char *sz ft->dwRemoteExternalIP = chain->getDWord(0x04, 1);
ft->wRemotePort = chain->getWord(0x05, 1);
- OpenOscarConnection(hContact, ft, ft->bUseProxy ? OCT_PROXY_RECV: OCT_REVERSE);
+ OpenOscarConnection(hContact, ft, ft->bUseProxy ? OCT_PROXY_RECV : OCT_REVERSE);
}
- else
- { // Just sanity
+ else { // Just sanity
ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)ft, 0);
// Release transfer
SafeReleaseFileTransfer((void**)&ft);
}
}
- else
- debugLogA("Error: Invalid request, no such transfer");
+ else debugLogA("Error: Invalid request, no such transfer");
}
- else if (wAckType == 3)
- { // Transfering thru proxy, join tunnel
+ else if (wAckType == 3) { // Transfering thru proxy, join tunnel
oscar_filetransfer *ft = FindOscarTransfer(hContact, dwID1, dwID2);
-
- if (ft)
- { // release possible previous listener
+ if (ft) { // release possible previous listener
NetLog_Direct("OFT: Redirect received (%d)", wAckType);
ft->wReqNum = wAckType;
@@ -632,24 +555,16 @@ void CIcqProto::handleRecvServMsgOFT(BYTE *buf, WORD wLen, DWORD dwUin, char *sz ft->dwProxyIP = chain->getDWord(0x02, 1);
ft->wRemotePort = chain->getWord(0x05, 1);
- if (ft->bUseProxy && ft->dwProxyIP)
- { // Init proxy connection
+ if (ft->bUseProxy && ft->dwProxyIP) // Init proxy connection
OpenOscarConnection(hContact, ft, OCT_PROXY_RECV);
- }
- else
- { // try Stage 4
+ else // try Stage 4
OpenOscarConnection(hContact, ft, OCT_PROXY);
- }
}
- else
- debugLogA("Error: Invalid request, no such transfer");
+ else debugLogA("Error: Invalid request, no such transfer");
}
- else if (wAckType == 4)
- {
+ else if (wAckType == 4) {
oscar_filetransfer *ft = FindOscarTransfer(hContact, dwID1, dwID2);
-
- if (ft)
- {
+ if (ft) {
NetLog_Direct("OFT: Redirect received (%d)", wAckType);
ft->wReqNum = wAckType;
@@ -657,30 +572,22 @@ void CIcqProto::handleRecvServMsgOFT(BYTE *buf, WORD wLen, DWORD dwUin, char *sz ft->dwProxyIP = chain->getDWord(0x02, 1);
ft->wRemotePort = chain->getWord(0x05, 1);
- if (ft->bUseProxy && ft->dwProxyIP)
- { // Init proxy connection
+ if (ft->bUseProxy && ft->dwProxyIP) // Init proxy connection
OpenOscarConnection(hContact, ft, OCT_PROXY_RECV);
- }
else
debugLogA("Error: Invalid request, IP missing.");
}
- else
- debugLogA("Error: Invalid request, no such transfer");
+ else debugLogA("Error: Invalid request, no such transfer");
}
- else
- debugLogA("Error: Uknown Stage %d request", wAckType);
+ else debugLogA("Error: Uknown Stage %d request", wAckType);
disposeChain(&chain);
}
- else
- debugLogA("Error: Missing TLV chain in OFT request");
+ else debugLogA("Error: Missing TLV chain in OFT request");
}
- else if (wCommand == 1)
- { // transfer cancelled/aborted
+ else if (wCommand == 1) { // transfer cancelled/aborted
oscar_filetransfer *ft = FindOscarTransfer(hContact, dwID1, dwID2);
-
- if (ft)
- {
+ if (ft) {
debugLogA("OFT: File transfer cancelled by %s", strUID(dwUin, szUID));
ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)ft, 0);
@@ -689,23 +596,17 @@ void CIcqProto::handleRecvServMsgOFT(BYTE *buf, WORD wLen, DWORD dwUin, char *sz // Release transfer
SafeReleaseFileTransfer((void**)&ft);
}
- else
- debugLogA("Error: Invalid request, no such transfer");
+ else debugLogA("Error: Invalid request, no such transfer");
}
- else if (wCommand == 2)
- { // transfer accepted - connection established
+ else if (wCommand == 2) { // transfer accepted - connection established
oscar_filetransfer *ft = FindOscarTransfer(hContact, dwID1, dwID2);
- if (ft)
- {
+ if (ft) {
NetLog_Direct("OFT: Session established.");
// Init connection
- if (ft->flags & OFTF_SENDING)
- {
- if (ft->connection && ft->connection->status == OCS_CONNECTED)
- {
- if (!(ft->flags & OFTF_FILE_REQUEST_SENT))
- {
+ if (ft->flags & OFTF_SENDING) {
+ if (ft->connection && ft->connection->status == OCS_CONNECTED) {
+ if (!(ft->flags & OFTF_FILE_REQUEST_SENT)) {
ft->flags |= OFTF_FILE_REQUEST_SENT;
// proceed with first file
oft_sendPeerInit(ft->connection);
@@ -713,19 +614,13 @@ void CIcqProto::handleRecvServMsgOFT(BYTE *buf, WORD wLen, DWORD dwUin, char *sz }
ft->flags |= OFTF_INITIALIZED; // accept was received
}
- else
- debugLogA("Warning: Received invalid rendezvous accept");
+ else debugLogA("Warning: Received invalid rendezvous accept");
}
- else
- debugLogA("Error: Invalid request, no such transfer");
- }
- else
- {
- debugLogA("Error: Unknown wCommand=0x%x in OFT request", wCommand);
+ else debugLogA("Error: Invalid request, no such transfer");
}
+ else debugLogA("Error: Unknown wCommand=0x%x in OFT request", wCommand);
}
-
void CIcqProto::handleRecvServResponseOFT(BYTE *buf, WORD wLen, DWORD dwUin, char *szUID, void* ft)
{
WORD wDataLen;
@@ -734,68 +629,56 @@ void CIcqProto::handleRecvServResponseOFT(BYTE *buf, WORD wLen, DWORD dwUin, cha unpackWord(&buf, &wDataLen);
- if (wDataLen == 2)
- {
+ if (wDataLen == 2) {
oscar_filetransfer *oft = (oscar_filetransfer*)ft;
- WORD wStatus;
+ WORD wStatus;
unpackWord(&buf, &wStatus);
- switch (wStatus)
- {
+ switch (wStatus) {
case 1:
- { // FT denied (icq5)
- debugLogA("OFT: File transfer denied by %s", strUID(dwUin, szUID));
+ // FT denied (icq5)
+ debugLogA("OFT: File transfer denied by %s", strUID(dwUin, szUID));
- ProtoBroadcastAck(oft->hContact, ACKTYPE_FILE, ACKRESULT_DENIED, (HANDLE)oft, 0);
- // Release transfer
- SafeReleaseFileTransfer((void**)&oft);
- }
+ ProtoBroadcastAck(oft->hContact, ACKTYPE_FILE, ACKRESULT_DENIED, (HANDLE)oft, 0);
+ // Release transfer
+ SafeReleaseFileTransfer((void**)&oft);
break;
case 4: // Proxy error
- {
- icq_LogMessage(LOG_ERROR, LPGEN("The file transfer failed: Proxy error"));
+ icq_LogMessage(LOG_ERROR, LPGEN("The file transfer failed: Proxy error"));
- ProtoBroadcastAck(oft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)oft, 0);
- // Release transfer
- SafeReleaseFileTransfer((void**)&oft);
- }
+ ProtoBroadcastAck(oft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)oft, 0);
+ // Release transfer
+ SafeReleaseFileTransfer((void**)&oft);
break;
case 5: // Invalid request
- {
- icq_LogMessage(LOG_ERROR, LPGEN("The file transfer failed: Invalid request"));
+ icq_LogMessage(LOG_ERROR, LPGEN("The file transfer failed: Invalid request"));
- ProtoBroadcastAck(oft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)oft, 0);
- // Release transfer
- SafeReleaseFileTransfer((void**)&oft);
- }
+ ProtoBroadcastAck(oft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)oft, 0);
+ // Release transfer
+ SafeReleaseFileTransfer((void**)&oft);
break;
case 6: // Proxy Failed (IP = 0)
- {
- icq_LogMessage(LOG_ERROR, LPGEN("The file transfer failed: Proxy unavailable"));
+ icq_LogMessage(LOG_ERROR, LPGEN("The file transfer failed: Proxy unavailable"));
- ProtoBroadcastAck(oft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)oft, 0);
- // Release transfer
- SafeReleaseFileTransfer((void**)&oft);
- }
+ ProtoBroadcastAck(oft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)oft, 0);
+ // Release transfer
+ SafeReleaseFileTransfer((void**)&oft);
break;
default:
- {
- debugLogA("OFT: Uknown request response code 0x%x", wStatus);
+ debugLogA("OFT: Uknown request response code 0x%x", wStatus);
- ProtoBroadcastAck(oft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)oft, 0);
- // Release transfer
- SafeReleaseFileTransfer((void**)&oft);
- }
+ ProtoBroadcastAck(oft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)oft, 0);
+ // Release transfer
+ SafeReleaseFileTransfer((void**)&oft);
}
}
}
-
// This function is called from the Netlib when someone is connecting to our oscar_listener
static void oft_newConnectionReceived(HANDLE hNewConnection, DWORD dwRemoteIP, void *pExtra)
{
@@ -809,11 +692,10 @@ static void oft_newConnectionReceived(HANDLE hNewConnection, DWORD dwRemoteIP, v otsi->listener = listener;
// Start a new thread for the incomming connection
- listener->ppro->ForkThread((CIcqProto::MyThreadFunc)&CIcqProto::oft_connectionThread, otsi );
+ listener->ppro->ForkThread((CIcqProto::MyThreadFunc)&CIcqProto::oft_connectionThread, otsi);
}
-
-static char *oftGetFileContainer(oscar_filetransfer* oft, const char** files, int iFile)
+static char* oftGetFileContainer(oscar_filetransfer* oft, const char** files, int iFile)
{
char szPath[MAX_PATH];
char* szFileName = FindFilePathContainer(files, iFile, szPath);
@@ -822,19 +704,17 @@ static char *oftGetFileContainer(oscar_filetransfer* oft, const char** files, in // try to find existing container
for (i = 0; i < oft->containerCount; i++)
- if (!strcmpnull(szPathUtf, oft->file_containers[i]))
- {
- SAFE_FREE((void**)&szPathUtf);
-
- return oft->file_containers[i];
+ if (!strcmpnull(szPathUtf, oft->file_containers[i])) {
+ SAFE_FREE((void**)&szPathUtf);
+ return oft->file_containers[i];
}
- // create new container
- i = oft->containerCount++;
- oft->file_containers = (char**)SAFE_REALLOC(oft->file_containers, (sizeof(char*) * oft->containerCount));
- oft->file_containers[i] = szPathUtf;
+ // create new container
+ i = oft->containerCount++;
+ oft->file_containers = (char**)SAFE_REALLOC(oft->file_containers, (sizeof(char*) * oft->containerCount));
+ oft->file_containers[i] = szPathUtf;
- return oft->file_containers[i];
+ return oft->file_containers[i];
}
@@ -857,19 +737,16 @@ HANDLE CIcqProto::oftInitTransfer(MCONTACT hContact, DWORD dwUin, char* szUid, c ft->qwTotalSize = 0;
char **filesUtf = (char**)SAFE_MALLOC(sizeof(char *) * filesCount);
- for(i = 0; i < filesCount; i++) filesUtf[i] = FileNameToUtf(files[i]);
+ for (i = 0; i < filesCount; i++) filesUtf[i] = FileNameToUtf(files[i]);
// Prepare files arrays
- for (i = 0; i < filesCount; i++)
- {
+ for (i = 0; i < filesCount; i++) {
if (_tstati64(files[i], &statbuf))
debugLogA("IcqSendFile() was passed invalid filename \"%s\"", files[i]);
- else
- {
- if (!(statbuf.st_mode&_S_IFDIR))
- { // take only files
+ else {
+ if (!(statbuf.st_mode & _S_IFDIR)) { // take only files
ft->files[ft->wFilesCount].szFile = ft->files_list[ft->wFilesCount] = null_strdup(filesUtf[i]);
- ft->files[ft->wFilesCount].szContainer = oftGetFileContainer(ft, (LPCSTR*) filesUtf, i);
+ ft->files[ft->wFilesCount].szContainer = oftGetFileContainer(ft, (LPCSTR*)filesUtf, i);
ft->wFilesCount++;
ft->qwTotalSize += statbuf.st_size;
@@ -881,8 +758,7 @@ HANDLE CIcqProto::oftInitTransfer(MCONTACT hContact, DWORD dwUin, char* szUid, c SAFE_FREE(&filesUtf[i]);
SAFE_FREE((void**)&filesUtf);
- if (!ft->wFilesCount)
- { // found no valid files to send
+ if (!ft->wFilesCount) { // found no valid files to send
icq_LogMessage(LOG_ERROR, LPGEN("Failed to Initialize File Transfer. No valid files were specified."));
// Notify UI
ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)ft, 0);
@@ -896,8 +772,7 @@ HANDLE CIcqProto::oftInitTransfer(MCONTACT hContact, DWORD dwUin, char* szUid, c #else
#define OSCAR_MAX_SIZE 0x100000000
#endif
- if (ft->qwTotalSize >= OSCAR_MAX_SIZE && ft->wFilesCount > 1)
- { // file larger than 4GB can be send only as single
+ if (ft->qwTotalSize >= OSCAR_MAX_SIZE && ft->wFilesCount > 1) { // file larger than 4GB can be send only as single
icq_LogMessage(LOG_ERROR, LPGEN("The files are too big to be sent at once. Files bigger than 4 GB can be sent only separately."));
// Notify UI
ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, (HANDLE)ft, 0);
@@ -934,12 +809,10 @@ HANDLE CIcqProto::oftInitTransfer(MCONTACT hContact, DWORD dwUin, char* szUid, c {
char *pszFiles;
- if (ft->wFilesCount == 1)
- { // transfering single file, give filename
+ if (ft->wFilesCount == 1) { // transfering single file, give filename
pszFiles = (char*)ExtractFileName(ft->files[0].szFile);
}
- else
- { // check if transfering one directory
+ else { // check if transfering one directory
char *szFirstDiv, *szFirstDir = ft->file_containers[0];
int nFirstDirLen;
@@ -951,18 +824,14 @@ HANDLE CIcqProto::oftInitTransfer(MCONTACT hContact, DWORD dwUin, char* szUid, c else
nFirstDirLen = strlennull(szFirstDir);
- if (nFirstDirLen)
- { // got root dir from first container, check if others are only sub-dirs
- for (i = 0; i < ft->containerCount; i++)
- {
- if (_strnicmp((char*)ft->file_containers[i], (char*)szFirstDir, nFirstDirLen))
- {
+ if (nFirstDirLen) { // got root dir from first container, check if others are only sub-dirs
+ for (i = 0; i < ft->containerCount; i++) {
+ if (_strnicmp((char*)ft->file_containers[i], (char*)szFirstDir, nFirstDirLen)) {
szFirstDir = NULL;
break;
}
}
- if (szFirstDir)
- { // fine, we are sending only one directory
+ if (szFirstDir) { // fine, we are sending only one directory
pszFiles = szFirstDir;
if (szFirstDiv) szFirstDiv[0] = '\0';
nFirstDirLen++; // include backslash
@@ -977,12 +846,10 @@ HANDLE CIcqProto::oftInitTransfer(MCONTACT hContact, DWORD dwUin, char* szUid, c ft->listener = CreateOscarListener(ft, oft_newConnectionReceived);
// Send packet
- if (ft->listener)
- {
+ if (ft->listener) {
oft_sendFileRequest(dwUin, szUid, ft, pszFiles, getDword("RealIP", 0));
}
- else
- { // try stage 1 proxy
+ else { // try stage 1 proxy
ft->szThisFile = null_strdup(pszFiles);
OpenOscarConnection(hContact, ft, OCT_PROXY_INIT);
}
@@ -1006,25 +873,22 @@ HANDLE CIcqProto::oftFileAllow(MCONTACT hContact, HANDLE hTransfer, const TCHAR ft->szSavePath = tchar_to_utf8(szPath);
- if (ft->szThisPath)
- { // Append Directory name to the save path, when transfering a directory
+ if (ft->szThisPath) { // Append Directory name to the save path, when transfering a directory
ft->szSavePath = (char*)SAFE_REALLOC(ft->szSavePath, strlennull(ft->szSavePath) + strlennull(ft->szThisPath) + 4);
NormalizeBackslash(ft->szSavePath);
strcat(ft->szSavePath, ft->szThisPath);
NormalizeBackslash(ft->szSavePath);
}
-#ifdef _DEBUG
+
NetLog_Direct("OFT: Request accepted, saving to '%s'.", ft->szSavePath);
-#endif
// Create cookie
ft->dwCookie = AllocateCookie(CKT_FILE, ICQ_MSG_SRV_SEND, hContact, ft);
- OpenOscarConnection(hContact, ft, ft->bUseProxy ? OCT_PROXY_RECV: OCT_NORMAL);
+ OpenOscarConnection(hContact, ft, ft->bUseProxy ? OCT_PROXY_RECV : OCT_NORMAL);
return hTransfer; // Success
}
-
DWORD CIcqProto::oftFileDeny(MCONTACT hContact, HANDLE hTransfer, const TCHAR *szReason)
{
oscar_filetransfer *ft = (oscar_filetransfer*)hTransfer;
@@ -1034,26 +898,21 @@ DWORD CIcqProto::oftFileDeny(MCONTACT hContact, HANDLE hTransfer, const TCHAR *s if (getContactUid(hContact, &dwUin, &szUid))
return 1; // Invalid contact
- if (IsValidOscarTransfer(ft))
- {
- if (ft->hContact != hContact)
- return 1; // Bad contact or hTransfer
+ if (!IsValidOscarTransfer(ft))
+ return 1; // Invalid transfer
+
+ if (ft->hContact != hContact)
+ return 1; // Bad contact or hTransfer
-#ifdef _DEBUG
- NetLog_Direct("OFT: Request denied.");
-#endif
+ NetLog_Direct("OFT: Request denied.");
- oft_sendFileDeny(dwUin, szUid, ft);
+ oft_sendFileDeny(dwUin, szUid, ft);
- // Release structure
- SafeReleaseFileTransfer((void**)&ft);
-
- return 0; // Success
- }
- return 1; // Invalid transfer
+ // Release structure
+ SafeReleaseFileTransfer((void**)&ft);
+ return 0; // Success
}
-
DWORD CIcqProto::oftFileCancel(MCONTACT hContact, HANDLE hTransfer)
{
oscar_filetransfer* ft = (oscar_filetransfer*)hTransfer;
@@ -1063,28 +922,24 @@ DWORD CIcqProto::oftFileCancel(MCONTACT hContact, HANDLE hTransfer) if (getContactUid(hContact, &dwUin, &szUid))
return 1; // Invalid contact
- if (IsValidOscarTransfer(ft))
- {
- if (ft->hContact != hContact)
- return 1; // Bad contact or hTransfer
+ if (!IsValidOscarTransfer(ft))
+ return 1; // Invalid transfer
+
+ if (ft->hContact != hContact)
+ return 1; // Bad contact or hTransfer
-#ifdef _DEBUG
- NetLog_Direct("OFT: Transfer cancelled.");
-#endif
+ NetLog_Direct("OFT: Transfer cancelled.");
- oft_sendFileCancel(dwUin, szUid, ft);
+ oft_sendFileCancel(dwUin, szUid, ft);
- ProtoBroadcastAck(hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0);
+ ProtoBroadcastAck(hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0);
- // Release structure
- SafeReleaseFileTransfer((void**)&ft);
+ // Release structure
+ SafeReleaseFileTransfer((void**)&ft);
- return 0; // Success
- }
- return 1; // Invalid transfer
+ return 0; // Success
}
-
void CIcqProto::oftFileResume(oscar_filetransfer *ft, int action, const TCHAR *szFilename)
{
int openFlags;
@@ -1094,12 +949,9 @@ void CIcqProto::oftFileResume(oscar_filetransfer *ft, int action, const TCHAR *s oscar_connection *oc = ft->connection;
-#ifdef _DEBUG
NetLog_Direct("OFT: Resume Transfer, Action: %d, FileName: '%s'", action, szFilename);
-#endif
- switch (action)
- {
+ switch (action) {
case FILERESUME_RESUME:
openFlags = _O_BINARY | _O_RDWR;
break;
@@ -1124,8 +976,7 @@ void CIcqProto::oftFileResume(oscar_filetransfer *ft, int action, const TCHAR *s default: // workaround for bug in Miranda Core
if (ft->resumeAction == FILERESUME_RESUME)
openFlags = _O_BINARY | _O_RDWR;
- else
- { // default to overwrite
+ else { // default to overwrite
openFlags = _O_BINARY | _O_CREAT | _O_TRUNC | _O_WRONLY;
ft->qwFileBytesDone = 0;
}
@@ -1133,14 +984,9 @@ void CIcqProto::oftFileResume(oscar_filetransfer *ft, int action, const TCHAR *s ft->resumeAction = action;
ft->fileId = OpenFileUtf(ft->szThisFile, openFlags, _S_IREAD | _S_IWRITE);
-#ifdef _DEBUG
- NetLog_Direct("OFT: OpenFileUtf(%s, %u) returned %u", ft->szThisFile, openFlags, ft->fileId);
-#endif
- if (ft->fileId == -1)
- {
-#ifdef _DEBUG
+ if (ft->fileId == -1) {
NetLog_Direct("OFT: errno=%d", errno);
-#endif
+
icq_LogMessage(LOG_ERROR, LPGEN("Your file receive has been aborted because Miranda could not open the destination file in order to write to it. You may be trying to save to a read-only folder."));
ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0);
@@ -1156,26 +1002,21 @@ void CIcqProto::oftFileResume(oscar_filetransfer *ft, int action, const TCHAR *s ft->qwBytesDone += ft->qwFileBytesDone;
- if (action == FILERESUME_RESUME)
- { // use smart-resume
+ if (action == FILERESUME_RESUME) { // use smart-resume
oc->status = OCS_RESUME;
ft->dwRecvFileCheck = oft_calc_file_checksum(ft->fileId, ft->qwFileBytesDone);
_lseek(ft->fileId, 0, SEEK_END);
-#ifdef _DEBUG
NetLog_Direct("OFT: Starting Smart-Resume");
-#endif
sendOFT2FramePacket(oc, OFT_TYPE_RESUMEREQUEST);
-
return;
}
- else if (action == FILERESUME_SKIP)
- { // we are skipping the file, send "we are done"
+
+ if (action == FILERESUME_SKIP) // we are skipping the file, send "we are done"
oc->status = OCS_NEGOTIATION;
- }
- else
- { // Send "we are ready"
+
+ else { // Send "we are ready"
oc->status = OCS_DATA;
ft->flags |= OFTF_FILE_RECEIVING;
@@ -1183,8 +1024,7 @@ void CIcqProto::oftFileResume(oscar_filetransfer *ft, int action, const TCHAR *s }
ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, ft, 0);
- if (!ft->qwThisFileSize || action == FILERESUME_SKIP)
- { // if the file is empty we will not receive any data
+ if (!ft->qwThisFileSize || action == FILERESUME_SKIP) { // if the file is empty we will not receive any data
BYTE buf;
oft_handleFileData(oc, &buf, 0);
}
@@ -1206,29 +1046,23 @@ static void oft_buildProtoFileTransferStatus(oscar_filetransfer* ft, PROTOFILETR pfts->totalBytes = ft->qwTotalSize;
pfts->totalProgress = ft->qwBytesDone;
pfts->szWorkingDir = ft->szThisPath;
- pfts->szCurrentFile = ft->szThisFile;
+ pfts->szCurrentFile = ft->szThisFile;
pfts->currentFileSize = ft->qwThisFileSize;
pfts->currentFileTime = ft->dwThisFileDate;
pfts->currentFileProgress = ft->qwFileBytesDone;
}
-
void CIcqProto::CloseOscarConnection(oscar_connection *oc)
{
icq_lock l(oftMutex);
- if (oc)
- {
+ if (oc) {
oc->type = OCT_CLOSING;
-
- if (oc->hConnection)
- { // we need this for Netlib handle consistency
+ if (oc->hConnection) // we need this for Netlib handle consistency
NetLib_CloseConnection(&oc->hConnection, FALSE);
- }
}
}
-
/////////////////////////////////////////////////////////////////////////////////////////
void CIcqProto::OpenOscarConnection(MCONTACT hContact, oscar_filetransfer *ft, int type)
@@ -1239,17 +1073,15 @@ void CIcqProto::OpenOscarConnection(MCONTACT hContact, oscar_filetransfer *ft, i otsi->type = type;
otsi->ft = ft;
- ForkThread((MyThreadFunc)&CIcqProto::oft_connectionThread, otsi );
+ ForkThread((MyThreadFunc)&CIcqProto::oft_connectionThread, otsi);
}
-
int CIcqProto::CreateOscarProxyConnection(oscar_connection *oc)
{
- NETLIBOPENCONNECTION nloc = {0};
-
// inform UI
ProtoBroadcastAck(oc->ft->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTPROXY, oc->ft, 0);
+ NETLIBOPENCONNECTION nloc = { 0 };
nloc.szHost = OSCAR_PROXY_HOST;
nloc.wPort = getWord("OscarPort", m_bSecureConnection ? DEFAULT_SERVER_PORT_SSL : DEFAULT_SERVER_PORT);
if (nloc.wPort == 0)
@@ -1258,25 +1090,23 @@ int CIcqProto::CreateOscarProxyConnection(oscar_connection *oc) nloc.flags |= NLOCF_HTTPGATEWAY;
oc->hConnection = NetLib_OpenConnection(m_hNetlibUser, "Proxy ", &nloc);
- if (!oc->hConnection)
- { // proxy connection failed
+ if (!oc->hConnection) // proxy connection failed
return 0;
- }
+
oc->type = OCT_PROXY;
oc->status = OCS_PROXY;
oc->ft->connection = oc;
+
// init proxy
proxy_sendInitTunnel(oc);
-
return 1; // Success
}
-
-void __cdecl CIcqProto::oft_connectionThread( oscarthreadstartinfo *otsi )
+void __cdecl CIcqProto::oft_connectionThread(oscarthreadstartinfo *otsi)
{
- oscar_connection oc = {0};
+ oscar_connection oc = { 0 };
oscar_listener *source;
- NETLIBPACKETRECVER packetRecv={0};
+ NETLIBPACKETRECVER packetRecv = { 0 };
HANDLE hPacketRecver;
oc.hContact = otsi->hContact;
@@ -1285,18 +1115,15 @@ void __cdecl CIcqProto::oft_connectionThread( oscarthreadstartinfo *otsi ) oc.incoming = otsi->incoming;
oc.ft = otsi->ft;
source = otsi->listener;
- if (oc.incoming)
- {
- if (IsValidOscarTransfer(source->ft))
- {
+ if (oc.incoming) {
+ if (IsValidOscarTransfer(source->ft)) {
oc.ft = source->ft;
oc.ft->dwRemoteExternalIP = otsi->dwRemoteIP;
oc.hContact = oc.ft->hContact;
oc.ft->connection = &oc;
oc.status = OCS_CONNECTED;
}
- else
- { // FT is already over, kill listener
+ else { // FT is already over, kill listener
NetLog_Direct("Received unexpected connection, closing.");
CloseOscarConnection(&oc);
@@ -1308,26 +1135,21 @@ void __cdecl CIcqProto::oft_connectionThread( oscarthreadstartinfo *otsi ) }
SAFE_FREE((void**)&otsi);
- if (oc.hContact)
- { // Load contact information
+ if (oc.hContact) // Load contact information
getContactUid(oc.hContact, &oc.dwUin, &oc.szUid);
- }
// Load local IP information
oc.dwLocalExternalIP = getDword("IP", 0);
oc.dwLocalInternalIP = getDword("RealIP", 0);
- if (!oc.incoming)
- { // create outgoing connection
- if (oc.type == OCT_NORMAL || oc.type == OCT_REVERSE)
- { // create outgoing connection to peer
- NETLIBOPENCONNECTION nloc = {0};
- IN_ADDR addr = {0}, addr2 = {0};
+ if (!oc.incoming) { // create outgoing connection
+ if (oc.type == OCT_NORMAL || oc.type == OCT_REVERSE) { // create outgoing connection to peer
+ NETLIBOPENCONNECTION nloc = { 0 };
+ IN_ADDR addr = { 0 }, addr2 = { 0 };
if (oc.ft->dwRemoteExternalIP == oc.dwLocalExternalIP && oc.ft->dwRemoteInternalIP)
addr.S_un.S_addr = htonl(oc.ft->dwRemoteInternalIP);
- else if (oc.ft->dwRemoteExternalIP)
- {
+ else if (oc.ft->dwRemoteExternalIP) {
addr.S_un.S_addr = htonl(oc.ft->dwRemoteExternalIP);
// for different internal, try it also (for LANs with multiple external IP, VPNs, etc.)
if (oc.ft->dwRemoteInternalIP != oc.ft->dwRemoteExternalIP)
@@ -1339,12 +1161,10 @@ void __cdecl CIcqProto::oft_connectionThread( oscarthreadstartinfo *otsi ) // Inform UI that we will attempt to connect
ProtoBroadcastAck(oc.ft->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTING, oc.ft, 0);
- if (!addr.S_un.S_addr && oc.type == OCT_NORMAL)
- { // IP to connect to is empty, request reverse
+ if (!addr.S_un.S_addr && oc.type == OCT_NORMAL) { // IP to connect to is empty, request reverse
oscar_listener* listener = CreateOscarListener(oc.ft, oft_newConnectionReceived);
- if (listener)
- { // we got listening port, fine send request
+ if (listener) { // we got listening port, fine send request
oc.ft->listener = listener;
// notify UI
ProtoBroadcastAck(oc.ft->hContact, ACKTYPE_FILE, ACKRESULT_LISTENING, oc.ft, 0);
@@ -1352,32 +1172,26 @@ void __cdecl CIcqProto::oft_connectionThread( oscarthreadstartinfo *otsi ) oft_sendFileRedirect(oc.dwUin, oc.szUid, oc.ft, oc.dwLocalInternalIP, listener->wPort, FALSE);
return;
}
- if (!CreateOscarProxyConnection(&oc))
- { // normal connection failed, notify peer, wait for error or stage 3 proxy
+ if (!CreateOscarProxyConnection(&oc)) { // normal connection failed, notify peer, wait for error or stage 3 proxy
oft_sendFileRedirect(oc.dwUin, oc.szUid, oc.ft, 0, 0, FALSE);
// stage 3 can follow
return;
}
}
- else if (addr.S_un.S_addr && oc.ft->wRemotePort)
- {
+ else if (addr.S_un.S_addr && oc.ft->wRemotePort) {
nloc.szHost = inet_ntoa(addr);
nloc.wPort = oc.ft->wRemotePort;
nloc.timeout = 8; // 8 secs to connect
- oc.hConnection = NetLib_OpenConnection(m_hDirectNetlibUser, oc.type==OCT_REVERSE?"Reverse ":NULL, &nloc);
- if (!oc.hConnection && addr2.S_un.S_addr)
- { // first address failed, try second one if available
+ oc.hConnection = NetLib_OpenConnection(m_hDirectNetlibUser, oc.type == OCT_REVERSE ? "Reverse " : NULL, &nloc);
+ if (!oc.hConnection && addr2.S_un.S_addr) { // first address failed, try second one if available
nloc.szHost = inet_ntoa(addr2);
- oc.hConnection = NetLib_OpenConnection(m_hDirectNetlibUser, oc.type==OCT_REVERSE?"Reverse ":NULL, &nloc);
+ oc.hConnection = NetLib_OpenConnection(m_hDirectNetlibUser, oc.type == OCT_REVERSE ? "Reverse " : NULL, &nloc);
}
- if (!oc.hConnection)
- {
- if (oc.type == OCT_NORMAL)
- { // connection failed, try reverse
+ if (!oc.hConnection) {
+ if (oc.type == OCT_NORMAL) { // connection failed, try reverse
oscar_listener* listener = CreateOscarListener(oc.ft, oft_newConnectionReceived);
- if (listener)
- { // we got listening port, fine send request
+ if (listener) { // we got listening port, fine send request
oc.ft->listener = listener;
// notify UI that we await connection
ProtoBroadcastAck(oc.ft->hContact, ACKTYPE_FILE, ACKRESULT_LISTENING, oc.ft, 0);
@@ -1386,15 +1200,13 @@ void __cdecl CIcqProto::oft_connectionThread( oscarthreadstartinfo *otsi ) return;
}
}
- if (!CreateOscarProxyConnection(&oc))
- { // proxy connection failed, notify peer, wait for error or stage 4 proxy
+ if (!CreateOscarProxyConnection(&oc)) { // proxy connection failed, notify peer, wait for error or stage 4 proxy
oft_sendFileRedirect(oc.dwUin, oc.szUid, oc.ft, 0, 0, FALSE);
// stage 3 or stage 4 can follow
return;
}
}
- else
- {
+ else {
oc.status = OCS_CONNECTED;
// ack normal connection
oc.ft->connection = &oc;
@@ -1404,22 +1216,18 @@ void __cdecl CIcqProto::oft_connectionThread( oscarthreadstartinfo *otsi ) ProtoBroadcastAck(oc.ft->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, oc.ft, 0);
}
}
- else
- { // try proxy, stage 3 (sending)
- if (!CreateOscarProxyConnection(&oc))
- { // proxy connection failed, notify peer, wait for error or stage 4 proxy
+ else { // try proxy, stage 3 (sending)
+ if (!CreateOscarProxyConnection(&oc)) { // proxy connection failed, notify peer, wait for error or stage 4 proxy
oft_sendFileRedirect(oc.dwUin, oc.szUid, oc.ft, 0, 0, FALSE);
// stage 4 can follow
return;
}
}
}
- else if (oc.type == OCT_PROXY_RECV)
- { // stage 2 & stage 4
- if (oc.ft->dwProxyIP && oc.ft->wRemotePort)
- { // create proxy connection, join tunnel
- NETLIBOPENCONNECTION nloc = {0};
- IN_ADDR addr = {0};
+ else if (oc.type == OCT_PROXY_RECV) { // stage 2 & stage 4
+ if (oc.ft->dwProxyIP && oc.ft->wRemotePort) { // create proxy connection, join tunnel
+ NETLIBOPENCONNECTION nloc = { 0 };
+ IN_ADDR addr = { 0 };
// inform UI that we will connect to file proxy
ProtoBroadcastAck(oc.ft->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTPROXY, oc.ft, 0);
@@ -1432,8 +1240,7 @@ void __cdecl CIcqProto::oft_connectionThread( oscarthreadstartinfo *otsi ) if (m_bGatewayMode)
nloc.flags |= NLOCF_HTTPGATEWAY;
oc.hConnection = NetLib_OpenConnection(m_hNetlibUser, "Proxy ", &nloc);
- if (!oc.hConnection)
- { // proxy connection failed, we are out of possibilities
+ if (!oc.hConnection) { // proxy connection failed, we are out of possibilities
ProtoBroadcastAck(oc.ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, oc.ft, 0);
// notify the other side, that we failed
oft_sendFileResponse(oc.dwUin, oc.szUid, oc.ft, 0x04);
@@ -1448,8 +1255,7 @@ void __cdecl CIcqProto::oft_connectionThread( oscarthreadstartinfo *otsi ) }
else // stage 2 failed (empty IP)
{ // try stage 3, or send response error 0x06
- if (!CreateOscarProxyConnection(&oc))
- {
+ if (!CreateOscarProxyConnection(&oc)) {
oft_sendFileResponse(oc.dwUin, oc.szUid, oc.ft, 0x06);
// notify UI
ProtoBroadcastAck(oc.ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, oc.ft, 0);
@@ -1459,10 +1265,8 @@ void __cdecl CIcqProto::oft_connectionThread( oscarthreadstartinfo *otsi ) }
}
}
- else if (oc.type == OCT_PROXY)
- { // stage 4
- if (!CreateOscarProxyConnection(&oc))
- { // proxy connection failed, we are out of possibilities
+ else if (oc.type == OCT_PROXY) { // stage 4
+ if (!CreateOscarProxyConnection(&oc)) { // proxy connection failed, we are out of possibilities
ProtoBroadcastAck(oc.ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, oc.ft, 0);
// notify the other side, that we failed
oft_sendFileResponse(oc.dwUin, oc.szUid, oc.ft, 0x06);
@@ -1471,10 +1275,8 @@ void __cdecl CIcqProto::oft_connectionThread( oscarthreadstartinfo *otsi ) return;
}
}
- else if (oc.type == OCT_PROXY_INIT)
- { // stage 1
- if (!CreateOscarProxyConnection(&oc))
- { // We failed to init transfer, notify UI
+ else if (oc.type == OCT_PROXY_INIT) { // stage 1
+ if (!CreateOscarProxyConnection(&oc)) { // We failed to init transfer, notify UI
icq_LogMessage(LOG_ERROR, LPGEN("Failed to Initialize File Transfer. Unable to bind local port and File proxy unavailable."));
// Release transfer
SafeReleaseFileTransfer((void**)&oc.ft);
@@ -1484,18 +1286,17 @@ void __cdecl CIcqProto::oft_connectionThread( oscarthreadstartinfo *otsi ) oc.type = OCT_PROXY_INIT;
}
}
- if (!oc.hConnection)
- { // one more sanity check
+
+ if (!oc.hConnection) { // one more sanity check
NetLog_Direct("Error: No OFT connection.");
return;
}
- if (oc.status != OCS_PROXY)
- { // Connected, notify FT UI
+
+ if (oc.status != OCS_PROXY) { // Connected, notify FT UI
ProtoBroadcastAck(oc.ft->hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, oc.ft, 0);
// send init OFT frame - just for different order of packets (just like Trillian)
- if (oc.status == OCS_CONNECTED && (oc.ft->flags & OFTF_SENDING) && ((oc.ft->flags & OFTF_INITIALIZED) || oc.type == OCT_REVERSE) && !(oc.ft->flags & OFTF_FILE_REQUEST_SENT))
- {
+ if (oc.status == OCS_CONNECTED && (oc.ft->flags & OFTF_SENDING) && ((oc.ft->flags & OFTF_INITIALIZED) || oc.type == OCT_REVERSE) && !(oc.ft->flags & OFTF_FILE_REQUEST_SENT)) {
oc.ft->flags |= OFTF_FILE_REQUEST_SENT;
// proceed with first file
oft_sendPeerInit(&oc);
@@ -1506,35 +1307,26 @@ void __cdecl CIcqProto::oft_connectionThread( oscarthreadstartinfo *otsi ) // Packet receiving loop
- while (oc.hConnection)
- {
- int recvResult;
-
+ while (oc.hConnection) {
packetRecv.dwTimeout = oc.wantIdleTime ? 0 : 120000;
- recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hPacketRecver, (LPARAM)&packetRecv);
- if (!recvResult)
- {
+ int recvResult = CallService(MS_NETLIB_GETMOREPACKETS, (WPARAM)hPacketRecver, (LPARAM)&packetRecv);
+ if (!recvResult) {
NetLog_Direct("Clean closure of oscar socket (%p)", oc.hConnection);
break;
}
- if (recvResult == SOCKET_ERROR)
- {
- if (GetLastError() == ERROR_TIMEOUT)
- { // TODO: this will not work on some systems
- if (oc.wantIdleTime)
- { // here we want to send file data packets
+ if (recvResult == SOCKET_ERROR) {
+ if (GetLastError() == ERROR_TIMEOUT) { // TODO: this will not work on some systems
+ if (oc.wantIdleTime) { // here we want to send file data packets
oft_sendFileData(&oc);
}
- else if (oc.status != OCS_WAITING)
- {
+ else if (oc.status != OCS_WAITING) {
NetLog_Direct("Connection timeouted, closing.");
break;
}
}
- else if (oc.type != OCT_CLOSING || GetLastError() != 87)
- { // log only significant errors, not "connection killed by us"
+ else if (oc.type != OCT_CLOSING || GetLastError() != 87) { // log only significant errors, not "connection killed by us"
NetLog_Direct("Abortive closure of oscar socket (%p) (%d)", oc.hConnection, GetLastError());
break;
}
@@ -1552,7 +1344,8 @@ void __cdecl CIcqProto::oft_connectionThread( oscarthreadstartinfo *otsi ) CloseOscarConnection(&oc);
- { // Clean up
+ // Clean up
+ {
icq_lock l(oftMutex);
if (getFileTransferIndex(oc.ft) != -1)
@@ -1561,18 +1354,15 @@ void __cdecl CIcqProto::oft_connectionThread( oscarthreadstartinfo *otsi ) // Give server some time for abort/cancel to arrive
SleepEx(1000, TRUE);
// Error handling
- if (IsValidOscarTransfer(oc.ft))
- {
- if (oc.status == OCS_DATA)
- {
+ if (IsValidOscarTransfer(oc.ft)) {
+ if (oc.status == OCS_DATA) {
ProtoBroadcastAck(oc.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, oc.ft, 0);
icq_LogMessage(LOG_ERROR, LPGEN("Connection lost during file transfer."));
// Release structure
SafeReleaseFileTransfer((void**)&oc.ft);
}
- else if (oc.status == OCS_NEGOTIATION)
- {
+ else if (oc.status == OCS_NEGOTIATION) {
ProtoBroadcastAck(oc.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, oc.ft, 0);
icq_LogMessage(LOG_ERROR, LPGEN("File transfer negotiation failed for unknown reason."));
@@ -1582,17 +1372,11 @@ void __cdecl CIcqProto::oft_connectionThread( oscarthreadstartinfo *otsi ) }
}
-
void CIcqProto::sendOscarPacket(oscar_connection *oc, icq_packet *packet)
{
- if (oc->hConnection)
- {
- int nResult;
-
- nResult = Netlib_Send(oc->hConnection, (const char*)packet->pData, packet->wLen, 0);
-
- if (nResult == SOCKET_ERROR)
- {
+ if (oc->hConnection) {
+ int nResult = Netlib_Send(oc->hConnection, (const char*)packet->pData, packet->wLen, 0);
+ if (nResult == SOCKET_ERROR) {
NetLog_Direct("Oscar %p socket error: %d, closing", oc->hConnection, GetLastError());
CloseOscarConnection(oc);
}
@@ -1601,29 +1385,24 @@ void CIcqProto::sendOscarPacket(oscar_connection *oc, icq_packet *packet) SAFE_FREE((void**)&packet->pData);
}
-
int CIcqProto::oft_handlePackets(oscar_connection *oc, BYTE *buf, int len)
{
int bytesUsed = 0;
- while (len > 0)
- {
+ while (len > 0) {
if (oc->status == OCS_DATA && (oc->ft->flags & OFTF_FILE_RECEIVING))
- {
return oft_handleFileData(oc, buf, len);
- }
- else if (oc->status == OCS_PROXY)
- {
+
+ if (oc->status == OCS_PROXY)
return oft_handleProxyData(oc, buf, len);
- }
+
if (len < 6)
break;
BYTE *pBuf = buf;
DWORD dwHead;
unpackDWord(&pBuf, &dwHead);
- if (dwHead != 0x4F465432)
- { // bad packet
+ if (dwHead != 0x4F465432) { // bad packet
NetLog_Direct("OFT: Received invalid packet (dwHead = 0x%x).", dwHead);
CloseOscarConnection(oc);
@@ -1652,18 +1431,15 @@ int CIcqProto::oft_handlePackets(oscar_connection *oc, BYTE *buf, int len) return bytesUsed;
}
-
int CIcqProto::oft_handleProxyData(oscar_connection *oc, BYTE *buf, int len)
{
oscar_filetransfer *ft = oc->ft;
- BYTE *pBuf;
+ BYTE *pBuf;
WORD datalen;
WORD wCommand;
int bytesUsed = 0;
-
- while (len > 2)
- {
+ while (len > 2) {
pBuf = buf;
unpackWord(&pBuf, &datalen);
@@ -1672,8 +1448,7 @@ int CIcqProto::oft_handleProxyData(oscar_connection *oc, BYTE *buf, int len) if (len < datalen)
break; // packet is not complete
- if (datalen < 12)
- { // malformed packet
+ if (datalen < 12) { // malformed packet
CloseOscarConnection(oc);
break;
}
@@ -1681,16 +1456,14 @@ int CIcqProto::oft_handleProxyData(oscar_connection *oc, BYTE *buf, int len) unpackWord(&pBuf, &wCommand);
pBuf += 6;
// handle packet
- switch (wCommand)
- {
+ switch (wCommand) {
case 0x01: // Error
{
WORD wError;
char* szError;
unpackWord(&pBuf, &wError);
- switch(wError)
- {
+ switch (wError) {
case 0x0D:
szError = "Bad request";
break;
@@ -1729,8 +1502,7 @@ int CIcqProto::oft_handleProxyData(oscar_connection *oc, BYTE *buf, int len) unpackWord(&pBuf, &wCode);
unpackDWord(&pBuf, &dwIP);
- if (oc->type == OCT_PROXY_INIT)
- { // Proxy ready, send Stage 1 Request
+ if (oc->type == OCT_PROXY_INIT) { // Proxy ready, send Stage 1 Request
ft->bUseProxy = 1;
ft->wRemotePort = wCode;
ft->dwProxyIP = dwIP;
@@ -1739,8 +1511,7 @@ int CIcqProto::oft_handleProxyData(oscar_connection *oc, BYTE *buf, int len) // Notify UI
ProtoBroadcastAck(oc->hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, oc->ft, 0);
}
- else
- {
+ else {
debugLogA("Proxy Tunnel ready, notify peer.");
oft_sendFileRedirect(oc->dwUin, oc->szUid, ft, dwIP, wCode, TRUE);
}
@@ -1752,8 +1523,7 @@ int CIcqProto::oft_handleProxyData(oscar_connection *oc, BYTE *buf, int len) // Notify UI
ProtoBroadcastAck(oc->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTED, oc->ft, 0);
// signal we are ready
- if (oc->type == OCT_PROXY_RECV)
- {
+ if (oc->type == OCT_PROXY_RECV) {
oft_sendFileAccept(oc->dwUin, oc->szUid, ft);
if (ft->flags & OFTF_SENDING) // connection is ready for transfer (sending only)
ft->flags |= OFTF_INITIALIZED;
@@ -1761,8 +1531,7 @@ int CIcqProto::oft_handleProxyData(oscar_connection *oc, BYTE *buf, int len) debugLogA("Proxy Tunnel established");
- if ((ft->flags & OFTF_INITIALIZED) && (ft->flags & OFTF_SENDING) && !(ft->flags & OFTF_FILE_REQUEST_SENT))
- {
+ if ((ft->flags & OFTF_INITIALIZED) && (ft->flags & OFTF_SENDING) && !(ft->flags & OFTF_FILE_REQUEST_SENT)) {
ft->flags |= OFTF_FILE_REQUEST_SENT;
// proceed with first file
oft_sendPeerInit(ft->connection);
@@ -1781,7 +1550,6 @@ int CIcqProto::oft_handleProxyData(oscar_connection *oc, BYTE *buf, int len) return bytesUsed;
}
-
int CIcqProto::oft_handleFileData(oscar_connection *oc, BYTE *buf, int len)
{
oscar_filetransfer *ft = oc->ft;
@@ -1792,14 +1560,11 @@ int CIcqProto::oft_handleFileData(oscar_connection *oc, BYTE *buf, int len) if (ft->qwThisFileSize - ft->qwFileBytesDone < dwLen)
dwLen = (int)(ft->qwThisFileSize - ft->qwFileBytesDone);
- if (ft->fileId == -1)
- { // something went terribly bad
-#ifdef _DEBUG
- NetLog_Direct("Error: handleFileData(%u bytes) without fileId!", len);
-#endif
+ if (ft->fileId == -1) { // something went terribly bad
CloseOscarConnection(oc);
return 0;
}
+
_write(ft->fileId, buf, dwLen);
// update checksum
ft->dwRecvFileCheck = oft_calc_checksum((int)ft->qwFileBytesDone, buf, dwLen, ft->dwRecvFileCheck);
@@ -1807,45 +1572,40 @@ int CIcqProto::oft_handleFileData(oscar_connection *oc, BYTE *buf, int len) ft->qwBytesDone += dwLen;
ft->qwFileBytesDone += dwLen;
- if (GetTickCount() > ft->dwLastNotify + 700 || ft->qwFileBytesDone == ft->qwThisFileSize)
- { // notify FT UI of our progress, at most every 700ms - do not be faster than Miranda
+ if (GetTickCount() > ft->dwLastNotify + 700 || ft->qwFileBytesDone == ft->qwThisFileSize) { // notify FT UI of our progress, at most every 700ms - do not be faster than Miranda
PROTOFILETRANSFERSTATUS pfts;
oft_buildProtoFileTransferStatus(ft, &pfts);
ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&pfts);
ft->dwLastNotify = GetTickCount();
}
- if (ft->qwFileBytesDone == ft->qwThisFileSize)
- {
+
+ if (ft->qwFileBytesDone == ft->qwThisFileSize) {
/* EOF */
ft->flags &= ~OFTF_FILE_RECEIVING;
-#ifdef _DEBUG
- NetLog_Direct("OFT: _close(%u)", ft->fileId);
-#endif
_close(ft->fileId);
ft->fileId = -1;
- if (ft->resumeAction != FILERESUME_SKIP && ft->dwRecvFileCheck != ft->dwThisFileCheck)
- {
+ if (ft->resumeAction != FILERESUME_SKIP && ft->dwRecvFileCheck != ft->dwThisFileCheck) {
NetLog_Direct("Error: File checksums does not match!");
- { // Notify UI
- char *pszMsg = ICQTranslateUtf(LPGEN("The checksum of file \"%s\" does not match, the file is probably damaged."));
- char szBuf[MAX_PATH];
- mir_snprintf(szBuf, MAX_PATH, pszMsg, ExtractFileName(ft->szThisFile));
- icq_LogMessage(LOG_ERROR, szBuf);
+ // Notify UI
+ char *pszMsg = ICQTranslateUtf(LPGEN("The checksum of file \"%s\" does not match, the file is probably damaged."));
+ char szBuf[MAX_PATH];
- SAFE_FREE(&pszMsg);
- }
- } // keep transfer going (icq6 ignores checksums completely)
+ mir_snprintf(szBuf, MAX_PATH, pszMsg, ExtractFileName(ft->szThisFile));
+ icq_LogMessage(LOG_ERROR, szBuf);
+
+ SAFE_FREE(&pszMsg);
+ }
+ // keep transfer going (icq6 ignores checksums completely)
else if (ft->resumeAction == FILERESUME_SKIP)
NetLog_Direct("OFT: File receive skipped.");
else
NetLog_Direct("OFT: File received successfully.");
- if ((DWORD)(ft->iCurrentFile + 1) == ft->wFilesCount)
- {
+ if ((DWORD)(ft->iCurrentFile + 1) == ft->wFilesCount) {
ft->bHeaderFlags = 0x01; // the whole process is over
// ack received file
sendOFT2FramePacket(oc, OFT_TYPE_DONE);
@@ -1855,25 +1615,21 @@ int CIcqProto::oft_handleFileData(oscar_connection *oc, BYTE *buf, int len) // Release transfer
SafeReleaseFileTransfer((void**)&ft);
}
- else
- { // ack received file
+ else { // ack received file
sendOFT2FramePacket(oc, OFT_TYPE_DONE);
oc->status = OCS_NEGOTIATION;
}
-
}
return bytesUsed;
}
-
void CIcqProto::handleOFT2FramePacket(oscar_connection *oc, WORD datatype, BYTE *pBuffer, WORD wLen)
{
oscar_filetransfer *ft = oc->ft;
DWORD dwID1;
DWORD dwID2;
- if (wLen < 232)
- { // allow shorter packets, but at least with filename
+ if (wLen < 232) { // allow shorter packets, but at least with filename
NetLog_Direct("Error: Malformed OFT2 Frame, ignoring.");
return;
}
@@ -1883,237 +1639,208 @@ void CIcqProto::handleOFT2FramePacket(oscar_connection *oc, WORD datatype, BYTE unpackLEDWord(&pBuffer, &dwID2);
wLen -= 4;
- if (datatype == OFT_TYPE_REQUEST && !(ft->flags & OFTF_FILE_REQUEST_RECEIVED))
- { // first request does not contain MsgIDs we need to send them in ready packet
+ if (datatype == OFT_TYPE_REQUEST && !(ft->flags & OFTF_FILE_REQUEST_RECEIVED)) { // first request does not contain MsgIDs we need to send them in ready packet
dwID1 = ft->pMessage.dwMsgID1;
dwID2 = ft->pMessage.dwMsgID2;
}
- if (ft->pMessage.dwMsgID1 != dwID1 || ft->pMessage.dwMsgID2 != dwID2)
- { // this is not the right packet - bad Message IDs
+ if (ft->pMessage.dwMsgID1 != dwID1 || ft->pMessage.dwMsgID2 != dwID2) { // this is not the right packet - bad Message IDs
NetLog_Direct("Error: Invalid Packet Cookie, closing.");
CloseOscarConnection(oc);
-
return;
}
switch (datatype) {
case OFT_TYPE_REQUEST:
- { // Sender ready
- if (ft->flags & OFTF_SENDING)
- { // just sanity check - this is only for receiving client
- NetLog_Direct("Error: Invalid Packet, closing.");
- CloseOscarConnection(oc);
- return;
- }
+ { // Sender ready
+ if (ft->flags & OFTF_SENDING) { // just sanity check - this is only for receiving client
+ NetLog_Direct("Error: Invalid Packet, closing.");
+ CloseOscarConnection(oc);
+ return;
+ }
- // Read Frame data
- if (!(ft->flags & OFTF_FILE_REQUEST_RECEIVED))
- {
- unpackWord(&pBuffer, &ft->wEncrypt);
- unpackWord(&pBuffer, &ft->wCompress);
- unpackWord(&pBuffer, &ft->wFilesCount);
- }
- else
- pBuffer += 6;
- unpackWord(&pBuffer, &ft->wFilesLeft);
- ft->iCurrentFile = ft->wFilesCount - ft->wFilesLeft;
- if (!(ft->flags & OFTF_FILE_REQUEST_RECEIVED))
- unpackWord(&pBuffer, &ft->wPartsCount);
- else
- pBuffer += 2;
- unpackWord(&pBuffer, &ft->wPartsLeft);
- if (!(ft->flags & OFTF_FILE_REQUEST_RECEIVED))
- { // just check it
- DWORD dwSize;
-
- unpackDWord(&pBuffer, &dwSize);
- if (dwSize != (DWORD)ft->qwTotalSize)
- { // the 32bits does not match, use them as full size
- ft->qwTotalSize = dwSize;
-
- debugLogA("Warning: Invalid total size.");
- }
- }
- else
- pBuffer += 4;
- { // this allows us to receive single >4GB file correctly
- DWORD dwSize;
-
- unpackDWord(&pBuffer, &dwSize);
- if (dwSize == (DWORD)ft->qwTotalSize && ft->wFilesCount == 1)
- ft->qwThisFileSize = ft->qwTotalSize;
- else
- ft->qwThisFileSize = dwSize;
- }
- unpackDWord(&pBuffer, &ft->dwThisFileDate);
- unpackDWord(&pBuffer, &ft->dwThisFileCheck);
- unpackDWord(&pBuffer, &ft->dwRecvForkCheck);
- unpackDWord(&pBuffer, &ft->dwThisForkSize);
- unpackDWord(&pBuffer, &ft->dwThisFileCreation);
- unpackDWord(&pBuffer, &ft->dwThisForkCheck);
- pBuffer += 4; // File Bytes Done
- unpackDWord(&pBuffer, &ft->dwRecvFileCheck);
- if (!(ft->flags & OFTF_FILE_REQUEST_RECEIVED))
- unpackString(&pBuffer, ft->rawIDString, 32);
- else
- pBuffer += 32;
- unpackByte(&pBuffer, &ft->bHeaderFlags);
- unpackByte(&pBuffer, &ft->bNameOff);
- unpackByte(&pBuffer, &ft->bSizeOff);
- if (!(ft->flags & OFTF_FILE_REQUEST_RECEIVED))
- {
- unpackString(&pBuffer, (char*)ft->rawDummy, 69);
- unpackString(&pBuffer, (char*)ft->rawMacInfo, 16);
- }
- else
- pBuffer += 85;
- unpackWord(&pBuffer, &ft->wEncoding);
- unpackWord(&pBuffer, &ft->wSubEncoding);
- ft->cbRawFileName = wLen - 176;
- SAFE_FREE((void**)&ft->rawFileName); // release previous buffers
- SAFE_FREE(&ft->szThisFile);
- ft->rawFileName = (char*)SAFE_MALLOC(ft->cbRawFileName + 2);
- unpackString(&pBuffer, ft->rawFileName, ft->cbRawFileName);
- // Prepare file
- if (ft->wEncoding == 2)
- { // UCS-2 encoding
- ft->szThisFile = ApplyEncoding(ft->rawFileName, "unicode-2-0");
- }
- else
- {
- ft->szThisFile = ansi_to_utf8(ft->rawFileName);
+ // Read Frame data
+ if (!(ft->flags & OFTF_FILE_REQUEST_RECEIVED)) {
+ unpackWord(&pBuffer, &ft->wEncrypt);
+ unpackWord(&pBuffer, &ft->wCompress);
+ unpackWord(&pBuffer, &ft->wFilesCount);
+ }
+ else
+ pBuffer += 6;
+ unpackWord(&pBuffer, &ft->wFilesLeft);
+ ft->iCurrentFile = ft->wFilesCount - ft->wFilesLeft;
+ if (!(ft->flags & OFTF_FILE_REQUEST_RECEIVED))
+ unpackWord(&pBuffer, &ft->wPartsCount);
+ else
+ pBuffer += 2;
+ unpackWord(&pBuffer, &ft->wPartsLeft);
+ if (!(ft->flags & OFTF_FILE_REQUEST_RECEIVED)) { // just check it
+ DWORD dwSize;
+
+ unpackDWord(&pBuffer, &dwSize);
+ if (dwSize != (DWORD)ft->qwTotalSize) { // the 32bits does not match, use them as full size
+ ft->qwTotalSize = dwSize;
+ debugLogA("Warning: Invalid total size.");
}
+ }
+ else pBuffer += 4;
+
+ // this allows us to receive single >4GB file correctly
+ DWORD dwSize;
+ unpackDWord(&pBuffer, &dwSize);
+ if (dwSize == (DWORD)ft->qwTotalSize && ft->wFilesCount == 1)
+ ft->qwThisFileSize = ft->qwTotalSize;
+ else
+ ft->qwThisFileSize = dwSize;
+
+ unpackDWord(&pBuffer, &ft->dwThisFileDate);
+ unpackDWord(&pBuffer, &ft->dwThisFileCheck);
+ unpackDWord(&pBuffer, &ft->dwRecvForkCheck);
+ unpackDWord(&pBuffer, &ft->dwThisForkSize);
+ unpackDWord(&pBuffer, &ft->dwThisFileCreation);
+ unpackDWord(&pBuffer, &ft->dwThisForkCheck);
+ pBuffer += 4; // File Bytes Done
+ unpackDWord(&pBuffer, &ft->dwRecvFileCheck);
+ if (!(ft->flags & OFTF_FILE_REQUEST_RECEIVED))
+ unpackString(&pBuffer, ft->rawIDString, 32);
+ else
+ pBuffer += 32;
+ unpackByte(&pBuffer, &ft->bHeaderFlags);
+ unpackByte(&pBuffer, &ft->bNameOff);
+ unpackByte(&pBuffer, &ft->bSizeOff);
+ if (!(ft->flags & OFTF_FILE_REQUEST_RECEIVED)) {
+ unpackString(&pBuffer, (char*)ft->rawDummy, 69);
+ unpackString(&pBuffer, (char*)ft->rawMacInfo, 16);
+ }
+ else pBuffer += 85;
- { // convert dir markings to normal backslashes
- int i;
+ unpackWord(&pBuffer, &ft->wEncoding);
+ unpackWord(&pBuffer, &ft->wSubEncoding);
+ ft->cbRawFileName = wLen - 176;
+ SAFE_FREE((void**)&ft->rawFileName); // release previous buffers
+ SAFE_FREE(&ft->szThisFile);
+ ft->rawFileName = (char*)SAFE_MALLOC(ft->cbRawFileName + 2);
+ unpackString(&pBuffer, ft->rawFileName, ft->cbRawFileName);
+ // Prepare file
+ if (ft->wEncoding == 2) // UCS-2 encoding
+ ft->szThisFile = ApplyEncoding(ft->rawFileName, "unicode-2-0");
+ else
+ ft->szThisFile = ansi_to_utf8(ft->rawFileName);
- for (i = 0; i < strlennull(ft->szThisFile); i++)
- {
- if (ft->szThisFile[i] == 0x01) ft->szThisFile[i] = '\\';
- }
- }
+ // convert dir markings to normal backslashes
+ for (int i = 0; i < strlennull(ft->szThisFile); i++)
+ if (ft->szThisFile[i] == 0x01)
+ ft->szThisFile[i] = '\\';
- ft->flags |= OFTF_FILE_REQUEST_RECEIVED; // First Frame Processed
+ ft->flags |= OFTF_FILE_REQUEST_RECEIVED; // First Frame Processed
- NetLog_Direct("File '%s', %I64u Bytes", ft->szThisFile, ft->qwThisFileSize);
+ NetLog_Direct("File '%s', %I64u Bytes", ft->szThisFile, ft->qwThisFileSize);
- { // Prepare Path Information
- char *szFile = strrchr(ft->szThisFile, '\\');
+ { // Prepare Path Information
+ char *szFile = strrchr(ft->szThisFile, '\\');
- SAFE_FREE(&ft->szThisPath); // release previous path
- if (szFile)
- {
- ft->szThisPath = ft->szThisFile;
- szFile[0] = '\0'; // split that strings
- ft->szThisFile = null_strdup(szFile + 1);
- // no cheating with paths
- if (!IsValidRelativePath(ft->szThisPath))
- {
- NetLog_Direct("Invalid path information");
- break;
- }
+ SAFE_FREE(&ft->szThisPath); // release previous path
+ if (szFile) {
+ ft->szThisPath = ft->szThisFile;
+ szFile[0] = '\0'; // split that strings
+ ft->szThisFile = null_strdup(szFile + 1);
+ // no cheating with paths
+ if (!IsValidRelativePath(ft->szThisPath)) {
+ NetLog_Direct("Invalid path information");
+ break;
}
- else
- ft->szThisPath = null_strdup("");
}
+ else ft->szThisPath = null_strdup("");
+ }
- /* no cheating with paths */
- if (!IsValidRelativePath(ft->szThisFile))
- {
- NetLog_Direct("Invalid path information");
- break;
- }
- char *szFullPath = (char*)SAFE_MALLOC(strlennull(ft->szSavePath)+strlennull(ft->szThisPath)+strlennull(ft->szThisFile)+3);
- strcpy(szFullPath, ft->szSavePath);
- NormalizeBackslash(szFullPath);
- strcat(szFullPath, ft->szThisPath);
- NormalizeBackslash(szFullPath);
- // make sure the dest dir exists
- if (MakeDirUtf(szFullPath))
- NetLog_Direct("Failed to create destination directory!");
-
- strcat(szFullPath, ft->szThisFile);
- // we joined the full path to dest file
- SAFE_FREE(&ft->szThisFile);
- ft->szThisFile = szFullPath;
+ /* no cheating with paths */
+ if (!IsValidRelativePath(ft->szThisFile)) {
+ NetLog_Direct("Invalid path information");
+ break;
+ }
+
+ char *szFullPath = (char*)SAFE_MALLOC(strlennull(ft->szSavePath) + strlennull(ft->szThisPath) + strlennull(ft->szThisFile) + 3);
+ strcpy(szFullPath, ft->szSavePath);
+ NormalizeBackslash(szFullPath);
+ strcat(szFullPath, ft->szThisPath);
+ NormalizeBackslash(szFullPath);
+ // make sure the dest dir exists
+ if (MakeDirUtf(szFullPath))
+ NetLog_Direct("Failed to create destination directory!");
+
+ strcat(szFullPath, ft->szThisFile);
+ // we joined the full path to dest file
+ SAFE_FREE(&ft->szThisFile);
+ ft->szThisFile = szFullPath;
- ft->qwFileBytesDone = 0;
+ ft->qwFileBytesDone = 0;
- {
- /* file resume */
- PROTOFILETRANSFERSTATUS pfts;
+ {
+ /* file resume */
+ PROTOFILETRANSFERSTATUS pfts;
- oft_buildProtoFileTransferStatus(ft, &pfts);
- if (ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FILERESUME, ft, (LPARAM)&pfts))
- {
- oc->status = OCS_WAITING;
- break; /* UI supports resume: it will call PS_FILERESUME */
- }
+ oft_buildProtoFileTransferStatus(ft, &pfts);
+ if (ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FILERESUME, ft, (LPARAM)&pfts)) {
+ oc->status = OCS_WAITING;
+ break; /* UI supports resume: it will call PS_FILERESUME */
+ }
- ft->fileId = OpenFileUtf(ft->szThisFile, _O_BINARY | _O_CREAT | _O_TRUNC | _O_WRONLY, _S_IREAD | _S_IWRITE);
+ ft->fileId = OpenFileUtf(ft->szThisFile, _O_BINARY | _O_CREAT | _O_TRUNC | _O_WRONLY, _S_IREAD | _S_IWRITE);
#ifdef _DEBUG
- NetLog_Direct("OFT: OpenFileUtf(%s, %u) returned %u", ft->szThisFile, _O_BINARY | _O_CREAT | _O_TRUNC | _O_WRONLY, ft->fileId);
+ NetLog_Direct("OFT: OpenFileUtf(%s, %u) returned %u", ft->szThisFile, _O_BINARY | _O_CREAT | _O_TRUNC | _O_WRONLY, ft->fileId);
#endif
- if (ft->fileId == -1)
- {
+ if (ft->fileId == -1) {
#ifdef _DEBUG
- NetLog_Direct("OFT: errno=%d", errno);
+ NetLog_Direct("OFT: errno=%d", errno);
#endif
- icq_LogMessage(LOG_ERROR, LPGEN("Your file receive has been aborted because Miranda could not open the destination file in order to write to it. You may be trying to save to a read-only folder."));
+ icq_LogMessage(LOG_ERROR, LPGEN("Your file receive has been aborted because Miranda could not open the destination file in order to write to it. You may be trying to save to a read-only folder."));
- ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0);
- // Release transfer
- SafeReleaseFileTransfer((void**)&oc->ft);
- return;
- }
+ ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0);
+ // Release transfer
+ SafeReleaseFileTransfer((void**)&oc->ft);
+ return;
}
- // Send "we are ready"
- oc->status = OCS_DATA;
- ft->flags |= OFTF_FILE_RECEIVING;
-
- sendOFT2FramePacket(oc, OFT_TYPE_READY);
- ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, ft, 0);
- if (!ft->qwThisFileSize)
- { // if the file is empty we will not receive any data
- BYTE buf;
+ }
+ // Send "we are ready"
+ oc->status = OCS_DATA;
+ ft->flags |= OFTF_FILE_RECEIVING;
- oft_handleFileData(oc, &buf, 0);
- }
- return;
+ sendOFT2FramePacket(oc, OFT_TYPE_READY);
+ ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, ft, 0);
+ if (!ft->qwThisFileSize) { // if the file is empty we will not receive any data
+ BYTE buf;
+ oft_handleFileData(oc, &buf, 0);
}
+ return;
+ }
case OFT_TYPE_READY:
case OFT_TYPE_RESUMEACK:
- { // Receiver is ready
- oc->status = OCS_DATA;
- oc->wantIdleTime = 1;
- ft->flags |= OFTF_FILE_SENDING;
+ // Receiver is ready
+ oc->status = OCS_DATA;
+ oc->wantIdleTime = 1;
+ ft->flags |= OFTF_FILE_SENDING;
- NetLog_Direct("OFT: Receiver ready.");
- }
+ NetLog_Direct("OFT: Receiver ready.");
break;
case OFT_TYPE_RESUMEREQUEST:
- { // Receiver wants to resume file transfer from point
+ // Receiver wants to resume file transfer from point
+ if (!(ft->flags & OFTF_SENDING)) { // just sanity check - this is only for sending client
+ NetLog_Direct("Error: Invalid Packet, closing.");
+ CloseOscarConnection(oc);
+ return;
+ }
+ {
DWORD dwResumeCheck, dwResumeOffset, dwFileCheck;
-
- if (!(ft->flags & OFTF_SENDING))
- { // just sanity check - this is only for sending client
- NetLog_Direct("Error: Invalid Packet, closing.");
- CloseOscarConnection(oc);
-
- return;
- }
// Read Resume Frame data
pBuffer += 44;
unpackDWord(&pBuffer, &dwResumeOffset);
unpackDWord(&pBuffer, &dwResumeCheck);
dwFileCheck = oft_calc_file_checksum(ft->fileId, dwResumeOffset);
- if (dwFileCheck == dwResumeCheck && dwResumeOffset <= ft->qwThisFileSize)
- { // resume seems ok
+ if (dwFileCheck == dwResumeCheck && dwResumeOffset <= ft->qwThisFileSize) { // resume seems ok
ft->qwFileBytesDone = dwResumeOffset;
ft->qwBytesDone += dwResumeOffset;
_lseek(ft->fileId, dwResumeOffset, SEEK_SET);
@@ -2129,23 +1856,20 @@ void CIcqProto::handleOFT2FramePacket(oscar_connection *oc, WORD datatype, BYTE break;
case OFT_TYPE_RESUMEREADY:
- { // Process Smart-resume reply
+ // Process Smart-resume reply
+ if (ft->flags & OFTF_SENDING) { // just sanity check - this is only for receiving client
+ NetLog_Direct("Error: Invalid Packet, closing.");
+ CloseOscarConnection(oc);
+ return;
+ }
+ {
DWORD dwResumeOffset, dwResumeCheck;
-
- if (ft->flags & OFTF_SENDING)
- { // just sanity check - this is only for receiving client
- NetLog_Direct("Error: Invalid Packet, closing.");
- CloseOscarConnection(oc);
-
- return;
- }
// Read Resume Reply data
pBuffer += 44;
unpackDWord(&pBuffer, &dwResumeOffset);
unpackDWord(&pBuffer, &dwResumeCheck);
- if (ft->qwFileBytesDone != dwResumeOffset)
- {
+ if (ft->qwFileBytesDone != dwResumeOffset) {
ft->qwBytesDone -= (ft->qwFileBytesDone - dwResumeOffset);
ft->qwFileBytesDone = dwResumeOffset;
if (dwResumeOffset)
@@ -2166,8 +1890,7 @@ void CIcqProto::handleOFT2FramePacket(oscar_connection *oc, WORD datatype, BYTE // Ready for receive
sendOFT2FramePacket(oc, OFT_TYPE_RESUMEACK);
- if (ft->qwThisFileSize == ft->qwFileBytesDone)
- { // all data already processed
+ if (ft->qwThisFileSize == ft->qwFileBytesDone) { // all data already processed
BYTE buf;
oft_handleFileData(oc, &buf, 0);
@@ -2176,23 +1899,22 @@ void CIcqProto::handleOFT2FramePacket(oscar_connection *oc, WORD datatype, BYTE break;
case OFT_TYPE_DONE:
- { // File done
- oc->status = OCS_NEGOTIATION;
- oc->wantIdleTime = 0;
+ // File done
+ oc->status = OCS_NEGOTIATION;
+ oc->wantIdleTime = 0;
- ft->flags &= ~OFTF_FILE_SENDING;
+ ft->flags &= ~OFTF_FILE_SENDING;
- NetLog_Direct("OFT: File sent successfully.");
+ NetLog_Direct("OFT: File sent successfully.");
#ifdef _DEBUG
- NetLog_Direct("OFT: _close(%u)", ft->fileId);
+ NetLog_Direct("OFT: _close(%u)", ft->fileId);
#endif
- _close(ft->fileId); // FIXME: this needs fix for "skip file" feature
- ft->fileId = -1;
- ft->iCurrentFile++;
- // continue with next file
- oft_sendPeerInit(oc);
- }
+ _close(ft->fileId); // FIXME: this needs fix for "skip file" feature
+ ft->fileId = -1;
+ ft->iCurrentFile++;
+ // continue with next file
+ oft_sendPeerInit(oc);
break;
default:
@@ -2200,7 +1922,6 @@ void CIcqProto::handleOFT2FramePacket(oscar_connection *oc, WORD datatype, BYTE }
}
-
//
// Proxy packets
/////////////////////////////
@@ -2266,22 +1987,18 @@ void CIcqProto::oft_sendFileData(oscar_connection *oc) if (bytesRead == -1)
return;
- if (!bytesRead)
- { //
+ if (!bytesRead) { //
oc->wantIdleTime = 0;
return;
}
- if ((DWORD)bytesRead > (ft->qwThisFileSize - ft->qwFileBytesDone))
- { // do not send more than expected, limit to known size
+ if ((DWORD)bytesRead > (ft->qwThisFileSize - ft->qwFileBytesDone)) { // do not send more than expected, limit to known size
bytesRead = (DWORD)(ft->qwThisFileSize - ft->qwFileBytesDone);
oc->wantIdleTime = 0;
}
- if (bytesRead)
- {
+ if (bytesRead) {
icq_packet packet;
-
packet.wLen = bytesRead;
init_generic_packet(&packet, 0);
packBuffer(&packet, buf, (WORD)bytesRead); // we are sending raw data
@@ -2291,10 +2008,8 @@ void CIcqProto::oft_sendFileData(oscar_connection *oc) ft->qwFileBytesDone += bytesRead;
}
- if (GetTickCount() > ft->dwLastNotify + 700 || oc->wantIdleTime == 0 || ft->qwFileBytesDone == ft->qwThisFileSize)
- { // notify only once a while or after last data packet sent
+ if (GetTickCount() > ft->dwLastNotify + 700 || oc->wantIdleTime == 0 || ft->qwFileBytesDone == ft->qwThisFileSize) { // notify only once a while or after last data packet sent
PROTOFILETRANSFERSTATUS pfts;
-
oft_buildProtoFileTransferStatus(ft, &pfts);
ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_DATA, ft, (LPARAM)&pfts);
ft->dwLastNotify = GetTickCount();
@@ -2310,8 +2025,7 @@ void CIcqProto::oft_sendPeerInit(oscar_connection *oc) char *pszThisFileName;
// prepare init frame
- if (ft->iCurrentFile >= (int)ft->wFilesCount)
- { // All files done, great!
+ if (ft->iCurrentFile >= (int)ft->wFilesCount) { // All files done, great!
ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, ft, 0);
// Release transfer
SafeReleaseFileTransfer((void**)&oc->ft);
@@ -2320,8 +2034,7 @@ void CIcqProto::oft_sendPeerInit(oscar_connection *oc) SAFE_FREE(&ft->szThisFile);
ft->szThisFile = null_strdup(ft->files[ft->iCurrentFile].szFile);
- if (FileStatUtf(ft->szThisFile, &statbuf))
- {
+ if (FileStatUtf(ft->szThisFile, &statbuf)) {
icq_LogMessage(LOG_ERROR, LPGEN("Your file transfer has been aborted because one of the files that you selected to send is no longer readable from the disk. You may have deleted or moved it."));
ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0);
@@ -2338,27 +2051,20 @@ void CIcqProto::oft_sendPeerInit(oscar_connection *oc) NormalizeBackslash(pszThisFileName);
strcat(pszThisFileName, ExtractFileName(ft->szThisFile));
}
- { // convert backslashes to dir markings
- int i;
- for (i = 0; i < strlennull(pszThisFileName); i++)
- if (pszThisFileName[i] == '\\' || pszThisFileName[i] == '/')
- pszThisFileName[i] = 0x01;
- }
+
+ // convert backslashes to dir markings
+ for (int i = 0; i < strlennull(pszThisFileName); i++)
+ if (pszThisFileName[i] == '\\' || pszThisFileName[i] == '/')
+ pszThisFileName[i] = 0x01;
ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, ft, 0);
ft->fileId = OpenFileUtf(ft->szThisFile, _O_BINARY | _O_RDONLY, 0);
-#ifdef _DEBUG
- NetLog_Direct("OFT: OpenFileUtf(%s, %u) returned %u", ft->szThisFile, _O_BINARY | _O_RDONLY, ft->fileId);
-#endif
- if (ft->fileId == -1)
- {
-#ifdef _DEBUG
- NetLog_Direct("OFT: errno=%d", errno);
-#endif
+ if (ft->fileId == -1) {
+ NetLog_Direct("OFT: error opening file %s, errno=%d", ft->szThisFile, errno);
SAFE_FREE((void**)&pszThisFileName);
- icq_LogMessage(LOG_ERROR, LPGEN("Your file transfer has been aborted because one of the files that you selected to send is no longer readable from the disk. You may have deleted or moved it."));
- //
+ icq_LogMessage(LOG_ERROR, LPGEN("Your file transfer has been aborted (error=%d), because one of the files that you selected to send is no longer readable from the disk. You may have deleted or moved it."));
+
ProtoBroadcastAck(ft->hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0);
// Release transfer
SafeReleaseFileTransfer((void**)&oc->ft);
@@ -2373,8 +2079,7 @@ void CIcqProto::oft_sendPeerInit(oscar_connection *oc) ft->dwRecvFileCheck = 0xFFFF0000;
SAFE_FREE((void**)&ft->rawFileName);
- if (IsUSASCII(pszThisFileName, strlennull(pszThisFileName)))
- {
+ if (IsUSASCII(pszThisFileName, strlennull(pszThisFileName))) {
ft->wEncoding = 0; // ascii
ft->cbRawFileName = strlennull(pszThisFileName) + 1;
if (ft->cbRawFileName < 64) ft->cbRawFileName = 64;
@@ -2382,8 +2087,7 @@ void CIcqProto::oft_sendPeerInit(oscar_connection *oc) strcpy(ft->rawFileName, (char*)pszThisFileName);
SAFE_FREE((void**)&pszThisFileName);
}
- else
- {
+ else {
ft->wEncoding = 2; // ucs-2
WCHAR *pwsThisFile = make_unicode_string(pszThisFileName);
SAFE_FREE((void**)&pszThisFileName);
diff --git a/protocols/IcqOscarJ/src/utilities.cpp b/protocols/IcqOscarJ/src/utilities.cpp index dd09f132cf..fed294427a 100644 --- a/protocols/IcqOscarJ/src/utilities.cpp +++ b/protocols/IcqOscarJ/src/utilities.cpp @@ -339,10 +339,6 @@ void CIcqProto::AddToContactsCache(MCONTACT hContact, DWORD dwUin, const char *s if (!hContact || (!dwUin && !szUid))
return;
-#ifdef _DEBUG
- debugLogA("Adding contact to cache: %u%s%s", dwUin, dwUin ? "" : " - ", dwUin ? "" : szUid);
-#endif
-
icq_contacts_cache *cache_item = (icq_contacts_cache*)SAFE_MALLOC(sizeof(icq_contacts_cache));
cache_item->hContact = hContact;
cache_item->dwUin = dwUin;
@@ -413,9 +409,6 @@ void CIcqProto::DeleteFromContactsCache(MCONTACT hContact) icq_contacts_cache *cache_item = contactsCache[i];
if (cache_item->hContact == hContact) {
-#ifdef _DEBUG
- debugLogA("Removing contact from cache: %u%s%s, position: %u", cache_item->dwUin, cache_item->dwUin ? "" : " - ", cache_item->dwUin ? "" : cache_item->szUid, i);
-#endif
contactsCache.remove(i);
// Release memory
SAFE_FREE((void**)&cache_item->szUid);
@@ -463,6 +456,8 @@ MCONTACT CIcqProto::HContactFromUIN(DWORD dwUin, int *Added) //not present: add
if (Added) {
+ debugLogA("Attempt to create ICQ contact %u", dwUin);
+
hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
if (!hContact) {
debugLogA("Failed to create ICQ contact %u", dwUin);
@@ -491,7 +486,7 @@ MCONTACT CIcqProto::HContactFromUIN(DWORD dwUin, int *Added) }
AddToContactsCache(hContact, dwUin, NULL);
*Added = 1;
-
+ debugLogA("ICQ contact %u created ok", dwUin);
return hContact;
}
@@ -502,7 +497,6 @@ MCONTACT CIcqProto::HContactFromUIN(DWORD dwUin, int *Added) return INVALID_CONTACT_ID;
}
-
MCONTACT CIcqProto::HContactFromUID(DWORD dwUin, const char *szUid, int *Added)
{
if (dwUin)
@@ -1069,9 +1063,9 @@ void __cdecl CIcqProto::SetStatusNoteThread(void *pDelay) m_ratesMutex->Leave();
cookieMutex->Leave();
-#ifdef _DEBUG
+
debugLogA("Rates: SetStatusNote delayed %dms", nDelay);
-#endif
+
SleepEx(nDelay, TRUE); // do not keep things locked during sleep
cookieMutex->Enter();
m_ratesMutex->Enter();
@@ -1100,9 +1094,9 @@ void __cdecl CIcqProto::SetStatusNoteThread(void *pDelay) m_ratesMutex->Leave();
cookieMutex->Leave();
-#ifdef _DEBUG
+
debugLogA("Rates: SetStatusNote delayed %dms", nDelay);
-#endif
+
SleepEx(nDelay, TRUE); // do not keep things locked during sleep
cookieMutex->Enter();
m_ratesMutex->Enter();
|