diff options
author | George Hazan <george.hazan@gmail.com> | 2014-06-29 12:24:18 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-06-29 12:24:18 +0000 |
commit | 4530fb627722a4c2018184dcdaea7fa9f44c10d7 (patch) | |
tree | 3ae98b2130d2f77bbb7fc3840a67b8bae6a6fb39 /protocols/IcqOscarJ/src/capabilities.cpp | |
parent | 9a1218da04b7887c4d7f6e88e0a33aea76b12f57 (diff) |
- fixes #646 (Database Encryption mode, ICQ and email contacts);
- code cleaning;
git-svn-id: http://svn.miranda-ng.org/main/trunk@9614 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/IcqOscarJ/src/capabilities.cpp')
-rw-r--r-- | protocols/IcqOscarJ/src/capabilities.cpp | 96 |
1 files changed, 36 insertions, 60 deletions
diff --git a/protocols/IcqOscarJ/src/capabilities.cpp b/protocols/IcqOscarJ/src/capabilities.cpp index 8a61dc9f44..00b6250a9a 100644 --- a/protocols/IcqOscarJ/src/capabilities.cpp +++ b/protocols/IcqOscarJ/src/capabilities.cpp @@ -34,7 +34,6 @@ // -----------------------------------------------------------------------------
#include "icqoscar.h"
-
struct icq_capability
{
DWORD capID; // A bitmask, we use it in order to save database space
@@ -43,14 +42,14 @@ struct icq_capability static const icq_capability CapabilityRecord[] =
{
- {CAPF_SRV_RELAY, {CAP_SRV_RELAY }},
- {CAPF_UTF, {CAP_UTF }},
- {CAPF_RTF, {CAP_RTF }},
- {CAPF_CONTACTS, {CAP_CONTACTS }},
- {CAPF_TYPING, {CAP_TYPING }},
- {CAPF_ICQDIRECT, {CAP_ICQDIRECT }},
- {CAPF_XTRAZ, {CAP_XTRAZ }},
- {CAPF_OSCAR_FILE,{CAP_OSCAR_FILE}}
+ { CAPF_SRV_RELAY, { CAP_SRV_RELAY }},
+ { CAPF_UTF, { CAP_UTF }},
+ { CAPF_RTF, { CAP_RTF }},
+ { CAPF_CONTACTS, { CAP_CONTACTS }},
+ { CAPF_TYPING, { CAP_TYPING }},
+ { CAPF_ICQDIRECT, { CAP_ICQDIRECT }},
+ { CAPF_XTRAZ, { CAP_XTRAZ }},
+ { CAPF_OSCAR_FILE, { CAP_OSCAR_FILE }}
};
// Mask of all handled capabilities' flags
@@ -66,17 +65,17 @@ struct icq_capability_name static const icq_capability_name CapabilityNames[] =
{
- {CAPF_SRV_RELAY, "ServerRelay"},
- {CAPF_UTF, "UTF8 Messages"},
- {CAPF_RTF, "RTF Messages"},
- {CAPF_CONTACTS, "Contact Transfer"},
- {CAPF_TYPING, "Typing Notifications"},
- {CAPF_ICQDIRECT, "Direct Connections"},
- {CAPF_XTRAZ, "Xtraz"},
- {CAPF_OSCAR_FILE, "File Transfers"},
- {CAPF_STATUS_MESSAGES,"Individual Status Messages"},
- {CAPF_STATUS_MOOD, "Mood"},
- {CAPF_XSTATUS, "Custom Status"}
+ { CAPF_SRV_RELAY, "ServerRelay"},
+ { CAPF_UTF, "UTF8 Messages"},
+ { CAPF_RTF, "RTF Messages"},
+ { CAPF_CONTACTS, "Contact Transfer"},
+ { CAPF_TYPING, "Typing Notifications"},
+ { CAPF_ICQDIRECT, "Direct Connections"},
+ { CAPF_XTRAZ, "Xtraz"},
+ { CAPF_OSCAR_FILE, "File Transfers"},
+ { CAPF_STATUS_MESSAGES,"Individual Status Messages"},
+ { CAPF_STATUS_MOOD, "Mood"},
+ { CAPF_XSTATUS, "Custom Status"}
};
void NetLog_CapabilityChange(CIcqProto *ppro, const char *szChange, DWORD fdwCapabilities)
@@ -85,11 +84,9 @@ void NetLog_CapabilityChange(CIcqProto *ppro, const char *szChange, DWORD fdwCap if (!fdwCapabilities) return;
- for (int nIndex = 0; nIndex < SIZEOF(CapabilityNames); nIndex++)
- {
+ for (int nIndex = 0; nIndex < SIZEOF(CapabilityNames); nIndex++) {
// Check if the current capability is present
- if ((fdwCapabilities & CapabilityNames[nIndex].capID) == CapabilityNames[nIndex].capID)
- {
+ if ((fdwCapabilities & CapabilityNames[nIndex].capID) == CapabilityNames[nIndex].capID) {
if (strlennull(szBuffer))
strcat(szBuffer, ", ");
strcat(szBuffer, CapabilityNames[nIndex].capName);
@@ -100,22 +97,18 @@ void NetLog_CapabilityChange(CIcqProto *ppro, const char *szChange, DWORD fdwCap }
#endif
-
// Deletes all oscar capabilities for a given contact
void CIcqProto::ClearAllContactCapabilities(MCONTACT hContact)
{
setDword(hContact, DBSETTING_CAPABILITIES, 0);
}
-
// Deletes one or many oscar capabilities for a given contact
void CIcqProto::ClearContactCapabilities(MCONTACT hContact, DWORD fdwCapabilities)
{
// Get current capability flags
- DWORD fdwContactCaps = getDword(hContact, DBSETTING_CAPABILITIES, 0);
-
- if (fdwContactCaps != (fdwContactCaps & ~fdwCapabilities))
- {
+ DWORD fdwContactCaps = getDword(hContact, DBSETTING_CAPABILITIES, 0);
+ if (fdwContactCaps != (fdwContactCaps & ~fdwCapabilities)) {
#ifdef _DEBUG
NetLog_CapabilityChange(this, "Removed", fdwCapabilities & fdwContactCaps);
#endif
@@ -127,15 +120,12 @@ void CIcqProto::ClearContactCapabilities(MCONTACT hContact, DWORD fdwCapabilitie }
}
-
// Sets one or many oscar capabilities for a given contact
void CIcqProto::SetContactCapabilities(MCONTACT hContact, DWORD fdwCapabilities)
{
// Get current capability flags
- DWORD fdwContactCaps = getDword(hContact, DBSETTING_CAPABILITIES, 0);
-
- if (fdwContactCaps != (fdwContactCaps | fdwCapabilities))
- {
+ DWORD fdwContactCaps = getDword(hContact, DBSETTING_CAPABILITIES, 0);
+ if (fdwContactCaps != (fdwContactCaps | fdwCapabilities)) {
#ifdef _DEBUG
NetLog_CapabilityChange(this, "Added", fdwCapabilities & ~fdwContactCaps);
#endif
@@ -147,7 +137,6 @@ void CIcqProto::SetContactCapabilities(MCONTACT hContact, DWORD fdwCapabilities) }
}
-
// Returns true if the given contact supports the requested capabilites
BOOL CIcqProto::CheckContactCapabilities(MCONTACT hContact, DWORD fdwCapabilities)
{
@@ -165,17 +154,12 @@ BOOL CIcqProto::CheckContactCapabilities(MCONTACT hContact, DWORD fdwCapabilitie // Scan capability against the capability buffer
capstr* MatchCapability(BYTE *buf, int bufsize, const capstr *cap, int capsize)
{
- while (bufsize >= BINARY_CAP_SIZE) // search the buffer for a capability
- {
+ while (bufsize >= BINARY_CAP_SIZE) { // search the buffer for a capability
if (!memcmp(buf, cap, capsize))
- {
return (capstr*)buf; // give found capability for version info
- }
- else
- {
- buf += BINARY_CAP_SIZE;
- bufsize -= BINARY_CAP_SIZE;
- }
+
+ buf += BINARY_CAP_SIZE;
+ bufsize -= BINARY_CAP_SIZE;
}
return 0;
}
@@ -185,7 +169,6 @@ capstr* MatchCapability(BYTE *buf, int bufsize, const capstr *cap, int capsize) capstr* MatchShortCapability(BYTE *buf, int bufsize, const shortcapstr *cap)
{
capstr fullCap;
-
memcpy(fullCap, capShortCaps, BINARY_CAP_SIZE);
fullCap[2] = (*cap)[0];
fullCap[3] = (*cap)[1];
@@ -193,7 +176,6 @@ capstr* MatchShortCapability(BYTE *buf, int bufsize, const shortcapstr *cap) return MatchCapability(buf, bufsize, &fullCap, BINARY_CAP_SIZE);
}
-
// Scans a binary buffer for OSCAR capabilities.
DWORD GetCapabilitiesFromBuffer(BYTE *pBuffer, int nLength)
{
@@ -204,18 +186,15 @@ DWORD GetCapabilitiesFromBuffer(BYTE *pBuffer, int nLength) // Loop over all capabilities in the buffer and
// compare them to our own record of capabilities
- for (int nIndex = 0; nIndex < nRecordSize; nIndex++)
- {
+ for (int nIndex = 0; nIndex < nRecordSize; nIndex++) {
+ // Match, add capability flag
if (MatchCapability(pBuffer, nLength, &CapabilityRecord[nIndex].capCLSID, BINARY_CAP_SIZE))
- { // Match, add capability flag
fdwCaps |= CapabilityRecord[nIndex].capID;
- }
}
return fdwCaps;
}
-
// Scans a binary buffer for oscar capabilities and adds them to the contact.
// You probably want to call ClearAllContactCapabilities() first.
void CIcqProto::AddCapabilitiesFromBuffer(MCONTACT hContact, BYTE *pBuffer, int nLength)
@@ -225,8 +204,7 @@ void CIcqProto::AddCapabilitiesFromBuffer(MCONTACT hContact, BYTE *pBuffer, int // Get capability flags from buffer
DWORD fdwCapabilities = GetCapabilitiesFromBuffer(pBuffer, nLength);
- if (fdwContactCaps != (fdwContactCaps | fdwCapabilities))
- {
+ if (fdwContactCaps != (fdwContactCaps | fdwCapabilities)) {
#ifdef _DEBUG
NetLog_CapabilityChange(this, "Added", fdwCapabilities & ~fdwContactCaps);
#endif
@@ -238,7 +216,6 @@ void CIcqProto::AddCapabilitiesFromBuffer(MCONTACT hContact, BYTE *pBuffer, int }
}
-
// Scans a binary buffer for oscar capabilities and adds them to the contact.
// You probably want to call ClearAllContactCapabilities() first.
void CIcqProto::SetCapabilitiesFromBuffer(MCONTACT hContact, BYTE *pBuffer, int nLength, BOOL bReset)
@@ -251,15 +228,14 @@ void CIcqProto::SetCapabilitiesFromBuffer(MCONTACT hContact, BYTE *pBuffer, int #ifdef _DEBUG
if (bReset)
NetLog_CapabilityChange(this, "Set", fdwCapabilities);
- else
- {
+ else {
NetLog_CapabilityChange(this, "Removed", fdwContactCaps & ~fdwCapabilities & CapabilityFlagsMask);
- NetLog_CapabilityChange(this, "Added", fdwCapabilities & ~fdwContactCaps);
+ NetLog_CapabilityChange(this, "Added", fdwCapabilities & ~fdwContactCaps);
}
#endif
- if (fdwCapabilities != (fdwContactCaps & ~CapabilityFlagsMask))
- { // Get current unmanaged capability flags
+ if (fdwCapabilities != (fdwContactCaps & ~CapabilityFlagsMask)) {
+ // Get current unmanaged capability flags
fdwContactCaps &= ~CapabilityFlagsMask;
// Add capability flags from buffer
|