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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
// ---------------------------------------------------------------------------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,2006,2007 Joe Kucera
// Copyright 2006,2007 [sss], chaos.persei, [sin], Faith Healer, Theif, nullbie
//
// 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$
// Revision : $Revision: 36 $
// Last change on : $Date: 2007-08-05 03:45:10 +0300 (Вс, 05 авг 2007) $
// Last change by : $Author: sss123next $
//
// DESCRIPTION:
//
// Internal Database API
//
// -----------------------------------------------------------------------------
#include "icqoscar.h"
static BOOL bUtfReadyDB = FALSE;
void InitDB()
{
bUtfReadyDB = ServiceExists(MS_DB_CONTACT_GETSETTING_STR);
if (!bUtfReadyDB)
NetLog_Server("Warning: DB module does not support Unicode.");
}
void __stdcall ICQCreateResidentSetting(const char* szSetting)
{
char pszSetting[2*MAX_PATH];
strcpy(pszSetting, gpszICQProtoName);
strcat(pszSetting, "/");
strcat(pszSetting, szSetting);
CallService(MS_DB_SETSETTINGRESIDENT, 1, (WPARAM)pszSetting);
}
BYTE __stdcall ICQGetContactSettingByte(HANDLE hContact, const char* szSetting, BYTE bDef)
{
return DBGetContactSettingByte(hContact, gpszICQProtoName, szSetting, bDef);
}
WORD __stdcall ICQGetContactSettingWord(HANDLE hContact, const char* szSetting, WORD wDef)
{
return DBGetContactSettingWord(hContact, gpszICQProtoName, szSetting, wDef);
}
DWORD __stdcall ICQGetContactSettingDword(HANDLE hContact, const char* szSetting, DWORD dwDef)
{
DBVARIANT dbv;
DBCONTACTGETSETTING cgs;
DWORD dwRes;
cgs.szModule = gpszICQProtoName;
cgs.szSetting = szSetting;
cgs.pValue = &dbv;
if (CallService(MS_DB_CONTACT_GETSETTING,(WPARAM)hContact,(LPARAM)&cgs))
return dwDef; // not found, give default
if (dbv.type != DBVT_DWORD)
dwRes = dwDef; // invalid type, give default
else // found and valid, give result
dwRes = dbv.dVal;
ICQFreeVariant(&dbv);
return dwRes;
}
DWORD __stdcall ICQGetContactSettingUIN(HANDLE hContact)
{
return ICQGetContactSettingDword(hContact, UNIQUEIDSETTING, 0);
}
int __stdcall ICQGetContactSettingUID(HANDLE hContact, DWORD *pdwUin, uid_str* ppszUid)
{
DBVARIANT dbv;
int iRes = 1;
*pdwUin = 0;
if (ppszUid) *ppszUid[0] = '\0';
if (!ICQGetContactSetting(hContact, UNIQUEIDSETTING, &dbv))
{
if (dbv.type == DBVT_DWORD)
{
*pdwUin = dbv.dVal;
iRes = 0;
}
else if (dbv.type == DBVT_ASCIIZ)
{
if (ppszUid && gbAimEnabled)
{
strcpy(*ppszUid, dbv.pszVal);
iRes = 0;
}
else
NetLog_Server("AOL screennames not accepted");
}
ICQFreeVariant(&dbv);
}
return iRes;
}
int __stdcall ICQGetContactSetting(HANDLE hContact, const char* szSetting, DBVARIANT *dbv)
{
if (bUtfReadyDB)
return DBGetContactSettingW(hContact, gpszICQProtoName, szSetting, dbv);
else
return DBGetContactSetting(hContact, gpszICQProtoName, szSetting, dbv);
}
int __stdcall ICQGetContactSettingString(HANDLE hContact, const char* szSetting, DBVARIANT *dbv)
{
if (bUtfReadyDB)
return DBGetContactSettingString(hContact, gpszICQProtoName, szSetting, dbv);
else
return ICQGetContactSetting(hContact, szSetting, dbv);
}
char* __stdcall UniGetContactSettingUtf(HANDLE hContact, const char *szModule,const char* szSetting, char* szDef)
{
DBVARIANT dbv = {DBVT_DELETED};
char* szRes;
if (bUtfReadyDB)
{
if (DBGetContactSettingUTF8String(hContact, szModule, szSetting, &dbv))
return null_strdup(szDef);
szRes = null_strdup(dbv.pszVal);
ICQFreeVariant(&dbv);
}
else
{ // old DB, we need to convert the string to UTF-8
if (DBGetContactSetting(hContact, szModule, szSetting, &dbv))
return null_strdup(szDef);
szRes = ansi_to_utf8(dbv.pszVal);
ICQFreeVariant(&dbv);
}
return szRes;
}
char* __stdcall ICQGetContactSettingUtf(HANDLE hContact, const char* szSetting, char* szDef)
{
return UniGetContactSettingUtf(hContact, gpszICQProtoName, szSetting, szDef);
}
WORD __stdcall ICQGetContactStatus(HANDLE hContact)
{
return ICQGetContactSettingWord(hContact, "Status", ID_STATUS_OFFLINE);
}
// (c) by George Hazan
int __stdcall ICQGetContactStaticString(HANDLE hContact, const char* valueName, char* dest, int dest_len)
{
DBVARIANT dbv;
DBCONTACTGETSETTING sVal;
dbv.pszVal = dest;
dbv.cchVal = dest_len;
dbv.type = DBVT_ASCIIZ;
sVal.pValue = &dbv;
sVal.szModule = gpszICQProtoName;
sVal.szSetting = valueName;
if (CallService(MS_DB_CONTACT_GETSETTINGSTATIC, (WPARAM)hContact, (LPARAM)&sVal) != 0)
{
dbv.pszVal = dest;
dbv.cchVal = dest_len;
dbv.type = DBVT_UTF8;
if (CallService(MS_DB_CONTACT_GETSETTINGSTATIC, (WPARAM)hContact, (LPARAM)&sVal) != 0)
return 1; // this is here due to DB module bug...
}
return (dbv.type != DBVT_ASCIIZ);
}
int __stdcall ICQDeleteContactSetting(HANDLE hContact, const char* szSetting)
{
return DBDeleteContactSetting(hContact, gpszICQProtoName, szSetting);
}
int __stdcall ICQWriteContactSettingByte(HANDLE hContact, const char* szSetting, BYTE bValue)
{
return DBWriteContactSettingByte(hContact, gpszICQProtoName, szSetting, bValue);
}
int __stdcall ICQWriteContactSettingWord(HANDLE hContact, const char* szSetting, WORD wValue)
{
return DBWriteContactSettingWord(hContact, gpszICQProtoName, szSetting, wValue);
}
int __stdcall ICQWriteContactSettingDword(HANDLE hContact, const char* szSetting, DWORD dwValue)
{
return DBWriteContactSettingDword(hContact, gpszICQProtoName, szSetting, dwValue);
}
int __stdcall ICQWriteContactSettingString(HANDLE hContact, const char* szSetting, char* szValue)
{
return DBWriteContactSettingString(hContact, gpszICQProtoName, szSetting, szValue);
}
int __stdcall UniWriteContactSettingUtf(HANDLE hContact, const char *szModule, const char* szSetting, char* szValue)
{
if (bUtfReadyDB)
return DBWriteContactSettingUTF8String(hContact, szModule, szSetting, szValue);
else
{ // old DB, we need to convert the string to Ansi
int size = strlennull(szValue) + 2;
char* szAnsi = (char*)_alloca(size);
if (utf8_decode_static(szValue, szAnsi, size))
return DBWriteContactSettingString(hContact, szModule, szSetting, szAnsi);
// failed to convert - give error
return 1;
}
}
int __stdcall ICQWriteContactSettingUtf(HANDLE hContact, const char* szSetting, char* szValue)
{
return UniWriteContactSettingUtf(hContact, gpszICQProtoName, szSetting, szValue);
}
int __stdcall ICQWriteContactSettingBlob(HANDLE hContact,const char *szSetting,const char *val, const int cbVal)
{
DBCONTACTWRITESETTING cws;
cws.szModule=gpszICQProtoName;
cws.szSetting=szSetting;
cws.value.type=DBVT_BLOB;
cws.value.pbVal=(char*)val;
cws.value.cpbVal = cbVal;
return CallService(MS_DB_CONTACT_WRITESETTING,(WPARAM)hContact,(LPARAM)&cws);
}
int __stdcall ICQFreeVariant(DBVARIANT* dbv)
{
return DBFreeVariant(dbv);
}
int __fastcall IsICQContact(HANDLE hContact)
{
char* szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0);
return !strcmpnull(szProto, gpszICQProtoName);
}
HANDLE __stdcall ICQAddEvent(HANDLE hContact, WORD wType, DWORD dwTime, DWORD flags, DWORD cbBlob, PBYTE pBlob)
{
DBEVENTINFO dbei = {0};
dbei.cbSize = sizeof(dbei);
dbei.szModule = gpszICQProtoName;
dbei.timestamp = dwTime;
dbei.flags = flags;
dbei.eventType = wType;
dbei.cbBlob = cbBlob;
dbei.pBlob = pBlob;
return (HANDLE)CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)&dbei);
}
HANDLE __fastcall ICQFindFirstContact()
{
HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, (LPARAM)gpszICQProtoName);
if (IsICQContact(hContact))
{
return hContact;
}
return ICQFindNextContact(hContact);
}
HANDLE __fastcall ICQFindNextContact(HANDLE hContact)
{
hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact,(LPARAM)gpszICQProtoName);
while (hContact != NULL)
{
if (IsICQContact(hContact))
{
return hContact;
}
hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact,(LPARAM)gpszICQProtoName);
}
return hContact;
}
char* __stdcall ICQGetContactCListGroup(HANDLE hContact)
{
return UniGetContactSettingUtf(hContact, "CList", "Group", NULL);
}
int __stdcall ICQSetContactCListGroup(HANDLE hContact, const char *szGroup)
{
/// TODO
return 0;
}
|