diff options
Diffstat (limited to 'protocols/IcqOscarJ/src/fam_03buddy.cpp')
-rw-r--r-- | protocols/IcqOscarJ/src/fam_03buddy.cpp | 182 |
1 files changed, 73 insertions, 109 deletions
diff --git a/protocols/IcqOscarJ/src/fam_03buddy.cpp b/protocols/IcqOscarJ/src/fam_03buddy.cpp index bf1a5ff66e..06783be2df 100644 --- a/protocols/IcqOscarJ/src/fam_03buddy.cpp +++ b/protocols/IcqOscarJ/src/fam_03buddy.cpp @@ -34,8 +34,7 @@ extern const char* cliSpamBot; void CIcqProto::handleBuddyFam(BYTE *pBuffer, WORD wBufferLength, snac_header *pSnacHeader, serverthread_info *info)
{
- switch (pSnacHeader->wSubtype)
- {
+ switch (pSnacHeader->wSubtype) {
case ICQ_USER_ONLINE:
handleUserOnline(pBuffer, wBufferLength, info);
break;
@@ -58,12 +57,12 @@ void CIcqProto::handleBuddyFam(BYTE *pBuffer, WORD wBufferLength, snac_header *p if (wBufferLength >= 2)
unpackWord(&pBuffer, &wError);
- else
+ else
wError = 0;
LogFamilyError(ICQ_BUDDY_FAMILY, wError);
- break;
}
+ break;
default:
debugLogA("Warning: Ignoring SNAC(x%02x,x%02x) - Unknown SNAC (Flags: %u, Ref: %u)", ICQ_BUDDY_FAMILY, pSnacHeader->wSubtype, pSnacHeader->wFlags, pSnacHeader->dwRef);
@@ -75,9 +74,7 @@ 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);
-
- if (pChain)
- {
+ if (pChain) {
DWORD wMaxUins = pChain->getWord(1, 1);
DWORD wMaxWatchers = pChain->getWord(2, 1);
DWORD wMaxTemporary = pChain->getWord(4, 1);
@@ -88,30 +85,25 @@ void CIcqProto::handleReplyBuddy(BYTE *buf, WORD wPackLen) disposeChain(&pChain);
}
- else
- {
- debugLogA("Error: Malformed BuddyReply");
- }
+ else debugLogA("Error: Malformed BuddyReply");
}
int unpackSessionDataItem(oscar_tlv_chain *pChain, WORD wItemType, BYTE **ppItemData, WORD *pwItemSize, BYTE *pbItemFlags)
{
- oscar_tlv *tlv = pChain->getTLV(0x1D, 1);
int len = 0;
BYTE *data;
- if (tlv)
- {
+ oscar_tlv *tlv = pChain->getTLV(0x1D, 1);
+ if (tlv) {
len = tlv->wLen;
data = tlv->pData;
}
- while (len >= 4)
- { // parse session data items one by one
+ while (len >= 4) {
+ // parse session data items one by one
WORD itemType;
- BYTE itemFlags;
- BYTE itemLen;
+ BYTE itemFlags, itemLen;
unpackWord(&data, &itemType);
unpackByte(&data, &itemFlags);
@@ -122,8 +114,8 @@ int unpackSessionDataItem(oscar_tlv_chain *pChain, WORD wItemType, BYTE **ppItem if (itemLen > len)
itemLen = len;
- if (itemType == wItemType)
- { // found the requested item
+ if (itemType == wItemType) {
+ // found the requested item
if (ppItemData)
*ppItemData = data;
if (pwItemSize)
@@ -181,7 +173,8 @@ void CIcqProto::handleUserOnline(BYTE *buf, WORD wLen, serverthread_info *info) char szStrBuf[MAX_PATH];
// Unpack the sender's user ID
- if (!unpackUID(&buf, &wLen, &dwUIN, &szUID)) return;
+ if (!unpackUID(&buf, &wLen, &dwUIN, &szUID))
+ return;
// Syntax check
if (wLen < 4)
@@ -197,8 +190,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)
- {
+ if (hContact == INVALID_CONTACT_ID) {
#ifdef _DEBUG
debugLogA("Ignoring user online (%s)", strUID(dwUIN, szUID));
#endif
@@ -221,12 +213,10 @@ void CIcqProto::handleUserOnline(BYTE *buf, WORD wLen, serverthread_info *info) WORD wClass = pChain->getWord(0x01, 1);
int nIsICQ = wClass & CLASS_ICQ;
- if (dwUIN)
- {
+ if (dwUIN) {
// Get DC info TLV
pTLV = pChain->getTLV(0x0C, 1);
- if (pTLV && (pTLV->wLen >= 15))
- {
+ if (pTLV && (pTLV->wLen >= 15)) {
BYTE *pBuffer = pTLV->pData;
nIsICQ = TRUE;
@@ -240,29 +230,21 @@ void CIcqProto::handleUserOnline(BYTE *buf, WORD wLen, serverthread_info *info) pBuffer += 4; // Client features
// Get faked time signatures, used to identify clients
- if (pTLV->wLen >= 0x23)
- {
+ if (pTLV->wLen >= 0x23) {
unpackDWord(&pBuffer, &dwFT1);
unpackDWord(&pBuffer, &dwFT2);
unpackDWord(&pBuffer, &dwFT3);
}
}
- else
- {
- // This client doesnt want DCs
- }
// Get Status info TLV
pTLV = pChain->getTLV(0x06, 1);
- if (pTLV && (pTLV->wLen >= 4))
- {
+ if (pTLV && (pTLV->wLen >= 4)) {
BYTE *pBuffer = pTLV->pData;
-
unpackWord(&pBuffer, &wStatusFlags);
unpackWord(&pBuffer, &wStatus);
}
- else if (!nIsICQ)
- {
+ else if (!nIsICQ) {
// Connected thru AIM client, guess by user class
if (wClass & CLASS_AWAY)
wStatus = ID_STATUS_AWAY;
@@ -273,15 +255,13 @@ void CIcqProto::handleUserOnline(BYTE *buf, WORD wLen, serverthread_info *info) wStatusFlags = 0;
}
- else
- {
+ else {
// Huh? No status TLV? Lets guess then...
wStatusFlags = 0;
wStatus = ICQ_STATUS_ONLINE;
}
}
- else
- {
+ else {
nIsICQ = FALSE;
if (wClass & CLASS_AWAY)
@@ -314,11 +294,10 @@ void CIcqProto::handleUserOnline(BYTE *buf, WORD wLen, serverthread_info *info) // Get Idle timer TLV
WORD wIdleTimer = pChain->getWord(0x04, 1);
time_t tIdleTS = 0;
- if (wIdleTimer)
- {
+ if (wIdleTimer) {
time(&tIdleTS);
tIdleTS -= (wIdleTimer*60);
- };
+ }
#ifdef _DEBUG
if (wIdleTimer)
@@ -329,8 +308,7 @@ void CIcqProto::handleUserOnline(BYTE *buf, WORD wLen, serverthread_info *info) #endif
// Check client capabilities
- if (hContact != NULL)
- {
+ if (hContact != NULL) {
wOldStatus = getContactStatus(hContact);
// Collect all Capability info from TLV chain
@@ -349,21 +327,20 @@ void CIcqProto::handleUserOnline(BYTE *buf, WORD wLen, serverthread_info *info) capBuf = (BYTE*)_alloca(capLen + BINARY_CAP_SIZE);
- if (capLen)
- {
+ if (capLen) {
BYTE *pCapability = capBuf;
capLen = 0; // we need to recount that
- if (pFullTLV && (pFullTLV->wLen >= BINARY_CAP_SIZE))
- { // copy classic Capabilities
+ if (pFullTLV && (pFullTLV->wLen >= BINARY_CAP_SIZE)) {
+ // copy classic Capabilities
BYTE *cData = pFullTLV->pData;
int cLen = pFullTLV->wLen;
- while (cLen)
- { // be impervious to duplicates (AOL sends them sometimes)
- if (!capLen || !MatchCapability(capBuf, capLen, (capstr*)cData, BINARY_CAP_SIZE))
- { // not present, add
+ while (cLen) {
+ // be impervious to duplicates (AOL sends them sometimes)
+ if (!capLen || !MatchCapability(capBuf, capLen, (capstr*)cData, BINARY_CAP_SIZE)) {
+ // not present, add
memcpy(pCapability, cData, BINARY_CAP_SIZE);
capLen += BINARY_CAP_SIZE;
pCapability += BINARY_CAP_SIZE;
@@ -373,20 +350,20 @@ void CIcqProto::handleUserOnline(BYTE *buf, WORD wLen, serverthread_info *info) }
}
- if (pShortTLV && (pShortTLV->wLen >= 2))
- { // copy short Capabilities
+ if (pShortTLV && (pShortTLV->wLen >= 2)) {
+ // copy short Capabilities
capstr tmp;
BYTE *cData = pShortTLV->pData;
int cLen = pShortTLV->wLen;
memcpy(tmp, capShortCaps, BINARY_CAP_SIZE);
- while (cLen)
- { // be impervious to duplicates (AOL sends them sometimes)
+ while (cLen) {
+ // be impervious to duplicates (AOL sends them sometimes)
tmp[2] = cData[0];
tmp[3] = cData[1];
- if (!capLen || !MatchCapability(capBuf, capLen, &tmp, BINARY_CAP_SIZE))
- { // not present, add
+ if (!capLen || !MatchCapability(capBuf, capLen, &tmp, BINARY_CAP_SIZE)) {
+ // not present, add
memcpy(pCapability, tmp, BINARY_CAP_SIZE);
capLen += BINARY_CAP_SIZE;
pCapability += BINARY_CAP_SIZE;
@@ -480,25 +457,25 @@ void CIcqProto::handleUserOnline(BYTE *buf, WORD wLen, serverthread_info *info) // Save contacts details in database
if (hContact != NULL) {
- setDword(hContact, "LogonTS", dwOnlineSince);
- setDword(hContact, "AwayTS", dwAwaySince);
- setDword(hContact, "IdleTS", tIdleTS);
+ setDword(hContact, "LogonTS", dwOnlineSince);
+ setDword(hContact, "AwayTS", dwAwaySince);
+ setDword(hContact, "IdleTS", tIdleTS);
if (dwMemberSince)
- setDword(hContact, "MemberTS", dwMemberSince);
+ setDword(hContact, "MemberTS", dwMemberSince);
if (nIsICQ) {
// on AIM these are not used
setDword(hContact, "DirectCookie", dwDirectConnCookie);
- setByte(hContact, "DCType", (BYTE)nTCPFlag);
- setWord(hContact, "UserPort", (WORD)(dwPort & 0xffff));
- setWord(hContact, "Version", wVersion);
+ setByte(hContact, "DCType", (BYTE)nTCPFlag);
+ setWord(hContact, "UserPort", (WORD)(dwPort & 0xffff));
+ setWord(hContact, "Version", wVersion);
}
else {
- delSetting(hContact, "DirectCookie");
- delSetting(hContact, "DCType");
- delSetting(hContact, "UserPort");
- delSetting(hContact, "Version");
+ delSetting(hContact, "DirectCookie");
+ delSetting(hContact, "DCType");
+ delSetting(hContact, "UserPort");
+ delSetting(hContact, "Version");
}
// if no detection, set uknown
@@ -507,19 +484,19 @@ void CIcqProto::handleUserOnline(BYTE *buf, WORD wLen, serverthread_info *info) if (szClient != (char*)-1) {
db_set_utf(hContact, m_szModuleName, "MirVer", szClient);
- setByte(hContact, "ClientID", bClientId);
+ setByte(hContact, "ClientID", bClientId);
}
if (wOldStatus == ID_STATUS_OFFLINE) {
- setDword(hContact, "IP", dwIP);
- setDword(hContact, "RealIP", dwRealIP);
+ setDword(hContact, "IP", dwIP);
+ setDword(hContact, "RealIP", dwRealIP);
}
else {
// if not first notification only write significant information
if (dwIP)
- setDword(hContact, "IP", dwIP);
+ setDword(hContact, "IP", dwIP);
if (dwRealIP)
- setDword(hContact, "RealIP", dwRealIP);
+ setDword(hContact, "RealIP", dwRealIP);
}
setWord(hContact, "Status", (WORD)IcqStatusToMiranda(wStatus));
@@ -584,8 +561,7 @@ void CIcqProto::handleUserOffline(BYTE *buf, WORD wLen) wLen -= 4;
// Skip the TLV chain
- while (wTLVCount && wLen >= 4)
- {
+ while (wTLVCount && wLen >= 4) {
WORD wTLVType;
WORD wTLVLen;
@@ -594,20 +570,19 @@ void CIcqProto::handleUserOffline(BYTE *buf, WORD wLen) wLen -= 4;
// stop parsing overflowed packet
- if (wTLVLen > wLen)
- {
+ if (wTLVLen > wLen) {
disposeChain(&pChain);
return;
}
- if (wTLVType == 0x1D)
- { // read only TLV with Session data into chain
+ if (wTLVType == 0x1D) {
+ // read only TLV with Session data into chain
BYTE *pTLV = buf - 4;
disposeChain(&pChain);
pChain = readIntoTLVChain(&pTLV, wLen + 4, 1);
}
- else if (wTLVType == 0x29 && wTLVLen == sizeof(DWORD))
- { // get Away Since value
+ else if (wTLVType == 0x29 && wTLVLen == sizeof(DWORD)) {
+ // get Away Since value
BYTE *pData = buf;
unpackDWord(&pData, &dwAwaySince);
}
@@ -621,8 +596,7 @@ void CIcqProto::handleUserOffline(BYTE *buf, WORD wLen) MCONTACT hContact = HContactFromUID(dwUIN, szUID, NULL);
// Skip contacts that are not already on our list or are already offline
- if (hContact != INVALID_CONTACT_ID)
- {
+ if (hContact != INVALID_CONTACT_ID) {
WORD wOldStatus = getContactStatus(hContact);
// Process Avatar Hash
@@ -643,8 +617,7 @@ void CIcqProto::handleUserOffline(BYTE *buf, WORD wLen) char tmp = NULL;
handleXStatusCaps(dwUIN, szUID, hContact, (BYTE*)&tmp, 0, &tmp, 0);
- if (wOldStatus != ID_STATUS_OFFLINE)
- {
+ if (wOldStatus != ID_STATUS_OFFLINE) {
debugLogA("%s went offline.", strUID(dwUIN, szUID));
setWord(hContact, "Status", ID_STATUS_OFFLINE);
@@ -677,12 +650,10 @@ void CIcqProto::parseStatusNote(DWORD dwUin, char *szUid, MCONTACT hContact, osc unpackDWord(&pStatusNoteTS, &dwStatusNoteTS);
// Get Status Note session item
- if (unpackSessionDataItem(pChain, 0x02, &pStatusNote, &wStatusNoteLen, &bStatusNoteFlags))
- {
+ if (unpackSessionDataItem(pChain, 0x02, &pStatusNote, &wStatusNoteLen, &bStatusNoteFlags)) {
char *szStatusNote = NULL;
- if ((bStatusNoteFlags & 4) == 4 && wStatusNoteLen >= 4)
- {
+ if ((bStatusNoteFlags & 4) == 4 && wStatusNoteLen >= 4) {
BYTE *buf = pStatusNote;
WORD buflen = wStatusNoteLen - 2;
WORD wTextLen;
@@ -691,8 +662,7 @@ void CIcqProto::parseStatusNote(DWORD dwUin, char *szUid, MCONTACT hContact, osc if (wTextLen > buflen)
wTextLen = buflen;
- if (wTextLen > 0)
- {
+ if (wTextLen > 0) {
szStatusNote = (char*)_alloca(wStatusNoteLen + 1);
unpackString(&buf, szStatusNote, wTextLen);
szStatusNote[wTextLen] = '\0';
@@ -704,8 +674,8 @@ void CIcqProto::parseStatusNote(DWORD dwUin, char *szUid, MCONTACT hContact, osc if (buflen >= 2)
unpackWord(&buf, &wEncodingType);
- if (wEncodingType == 1 && buflen > 6)
- { // Encoding specified
+ if (wEncodingType == 1 && buflen > 6) {
+ // Encoding specified
buf += 2;
buflen -= 2;
unpackWord(&buf, &wTextLen);
@@ -722,8 +692,7 @@ void CIcqProto::parseStatusNote(DWORD dwUin, char *szUid, MCONTACT hContact, osc }
}
// Check if the status note was changed
- if (dwStatusNoteTS > getDword(hContact, DBSETTING_STATUS_NOTE_TIME, 0))
- {
+ if (dwStatusNoteTS > getDword(hContact, DBSETTING_STATUS_NOTE_TIME, 0)) {
DBVARIANT dbv = {DBVT_DELETED};
if (strlennull(szStatusNote) || (!getString(hContact, DBSETTING_STATUS_NOTE, &dbv) && (dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_UTF8) && strlennull(dbv.pszVal)))
@@ -740,25 +709,20 @@ void CIcqProto::parseStatusNote(DWORD dwUin, char *szUid, MCONTACT hContact, osc if (getContactXStatus(hContact) != 0 || !CheckContactCapabilities(hContact, CAPF_STATUS_MESSAGES)) {
setStatusMsgVar(hContact, szStatusNote, false);
- TCHAR* tszNote = mir_utf8decodeT(szStatusNote);
+ TCHAR *tszNote = mir_utf8decodeT(szStatusNote);
ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, NULL, (LPARAM)tszNote);
mir_free(tszNote);
}
}
SAFE_FREE(&szStatusNote);
}
- else
- {
- if (getContactStatus(hContact) == ID_STATUS_OFFLINE)
- {
- setStatusMsgVar(hContact, NULL, false);
- delSetting(hContact, DBSETTING_STATUS_NOTE);
- setDword(hContact, DBSETTING_STATUS_NOTE_TIME, dwStatusNoteTS);
- }
+ else if (getContactStatus(hContact) == ID_STATUS_OFFLINE) {
+ setStatusMsgVar(hContact, NULL, false);
+ delSetting(hContact, DBSETTING_STATUS_NOTE);
+ setDword(hContact, DBSETTING_STATUS_NOTE_TIME, dwStatusNoteTS);
}
}
-
void CIcqProto::handleNotifyRejected(BYTE *buf, WORD wPackLen)
{
DWORD dwUIN;
|