1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
// ---------------------------------------------------------------------------80
// ICQ plugin for Miranda Instant Messenger
// ________________________________________
//
// Copyright © 2000,2001 Richard Hughes, Roland Rabien, Tristan Van de Vreede
// Copyright © 2001,2002 Jon Keating, Richard Hughes
// Copyright © 2002,2003,2004 Martin Öberg, Sam Kothari, Robert Rainwater
// Copyright © 2004,2005 Joe Kucera
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// -----------------------------------------------------------------------------
//
// File name : $Source: /cvsroot/miranda/miranda/protocols/IcqOscarJ/capabilities.c,v $
// Revision : $Revision: 2874 $
// Last change on : $Date: 2006-05-16 23:38:00 +0200 (Tue, 16 May 2006) $
// Last change by : $Author: ghazan $
//
// DESCRIPTION:
//
// Contains helper functions to handle oscar user capabilities. Scanning and
// adding capabilities are assumed to be more timecritical than looking up
// capabilites. During the login sequence there could possibly be many hundred
// scans but only a few lookups. So when you add or change something in this
// code you must have this in mind, dont do anything that will slow down the
// adding process too much.
//
// -----------------------------------------------------------------------------
#include "icqoscar.h"
typedef struct icq_capability_s
{
DWORD fdwMirandaID; // A bitmask, we use it in order to save database space
BYTE CapCLSID[BINARY_CAP_SIZE]; // A binary representation of a oscar capability
} icq_capability;
static icq_capability CapabilityRecord[] =
{
{CAPF_SRV_RELAY, {CAP_SRV_RELAY}},
{CAPF_UTF, {CAP_UTF }},
{CAPF_TYPING, {CAP_TYPING }},
{CAPF_XTRAZ, {CAP_XTRAZ }},
{CAPF_AIM_FILE, {CAP_AIM_FILE }},
{CAPF_PUSH2TALK, {CAP_PUSH2TALK }},
{CAPF_ICQ_LITE, {CAP_ICQ_LITE }},
{CAPF_RTF, {CAP_RTF }},
{CAPF_XTRAZ_CHAT, {CAP_XTRAZ_CHAT}},
{CAPF_VOICE_CHAT, {CAP_VOICE_CHAT}},
{CAPF_ICQ_DEVIL, {CAP_ICQ_DEVIL }},
{CAPF_DIRECT, {CAP_DIRECT }}
};
// Deletes all oscar capabilities for a given contact
void ClearAllContactCapabilities(HANDLE hContact)
{
ICQWriteContactSettingDword(hContact, DBSETTING_CAPABILITIES, 0);
}
// Deletes one or many oscar capabilities for a given contact
void ClearContactCapabilities(HANDLE hContact, DWORD fdwCapabilities)
{
DWORD fdwContactCaps;
// Get current capability flags
fdwContactCaps = ICQGetContactSettingDword(hContact, DBSETTING_CAPABILITIES, 0);
// Clear unwanted capabilities
fdwContactCaps &= ~fdwCapabilities;
// And write it back to disk
ICQWriteContactSettingDword(hContact, DBSETTING_CAPABILITIES, fdwContactCaps);
}
// Sets one or many oscar capabilities for a given contact
void SetContactCapabilities(HANDLE hContact, DWORD fdwCapabilities)
{
DWORD fdwContactCaps;
// Get current capability flags
fdwContactCaps = ICQGetContactSettingDword(hContact, DBSETTING_CAPABILITIES, 0);
// Update them
fdwContactCaps |= fdwCapabilities;
// And write it back to disk
ICQWriteContactSettingDword(hContact, DBSETTING_CAPABILITIES, fdwContactCaps);
}
// Returns true if the given contact supports the requested capabilites
BOOL CheckContactCapabilities(HANDLE hContact, DWORD fdwCapabilities)
{
DWORD fdwContactCaps;
// Get current capability flags
fdwContactCaps = ICQGetContactSettingDword(hContact, DBSETTING_CAPABILITIES, 0);
// Check if all requested capabilities are supported
if ((fdwContactCaps & fdwCapabilities) == fdwCapabilities)
{
return TRUE;
}
else
{
return FALSE;
}
}
// Scans a binary buffer for oscar capabilities and adds them to the contact.
// You probably want to call ClearAllContactCapabilities() first.
void AddCapabilitiesFromBuffer(HANDLE hContact, BYTE* pbyBuffer, int nLength)
{
DWORD fdwContactCaps;
int iCapability;
int nIndex;
int nRecordSize;
// Calculate the number of records
nRecordSize = sizeof(CapabilityRecord)/sizeof(icq_capability);
// Get current capability flags
fdwContactCaps = ICQGetContactSettingDword(hContact, DBSETTING_CAPABILITIES, 0);
// Loop over all capabilities in the buffer and
// compare them to our own record of capabilities
for (iCapability = 0; (iCapability + BINARY_CAP_SIZE) <= nLength; iCapability += BINARY_CAP_SIZE)
{
BOOL knownCAP = FALSE;
for (nIndex = 0; nIndex < nRecordSize; nIndex++)
{
if (!memcmp(pbyBuffer + iCapability, CapabilityRecord[nIndex].CapCLSID, BINARY_CAP_SIZE))
{
// Match
fdwContactCaps |= CapabilityRecord[nIndex].fdwMirandaID;
knownCAP = TRUE;
break;
}
}
if(!knownCAP) {
char szCap[64];
int i;
for (i = 0; i < 16; i++)
wsprintf(szCap+i*3, " %02X", (BYTE)((BYTE*)(pbyBuffer + iCapability)[i]));
Netlib_Logf(ghServerNetlibUser, "Found unknown CAP%s", szCap);
}
}
// And write it back to disk
ICQWriteContactSettingDword(hContact, DBSETTING_CAPABILITIES, fdwContactCaps);
}
|