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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
#include "StdAfx.h"
#include "sametime.h"
#define DEFAULT_ID (0x1800)
#define NUM_IDS 24
TCHAR* client_names[NUM_IDS] = {
_T("Official Binary Library"),
_T("Official Java Applet"),
_T("Official Binary Application"),
_T("Official Java Application"),
_T("Notes 6.5"),
_T("Notes 7.0"),
_T("Notes 8.0 Basic"),
_T("Notes 8.5.2"),
_T("Sametime Connect 8.0"),
_T("Sametime Connect 8.5.2"),
_T("ICT"),
_T("NotesBuddy"),
_T("NotesBuddy 4.15"),
_T("Sanity"),
_T("Perl"),
_T("PMR Alert"),
_T("Trillian (SourceForge)"),
_T("Trillian (IBM)"),
_T("Meanwhile Library"),
_T("Meanwhile (Python)"),
_T("Meanwhile (Gaim)"),
_T("Meanwhile (Adium)"),
_T("Meanwhile (Kopete)"),
_T("Custom")
};
int client_ids[NUM_IDS] = {
0x1000,
0x1001,
0x1002,
0x1003,
0x1200,
0x1210,
0x1215,
0x1240,
0x1306,
0x130D,
0x1300,
0x1400,
0x1405,
0x1600,
0x1625,
0x1650,
0x16aa,
0x16bb,
0x1700,
0x1701,
0x1702,
0x1703,
0x1704,
0xFFFF
};
#define DEFAULT_CV_MAJOR (0x001e)
#define DEFAULT_CV_MINOR (0x1f4b)
#define NUM_CVS 5
TCHAR* CV_names[NUM_CVS] = {
_T("Sametime (Use old client version)"),
_T("Sametime (Miranda default)"),
_T("Sametime 8"),
_T("Sametime 8.5.1"),
_T("Sametime 8.5.2")
};
int CV_major[NUM_CVS] = {
MW_PROTOCOL_VERSION_MAJOR,
0x001e,
0x001e,
0x001e,
0x001e
};
int CV_minor[NUM_CVS] = {
MW_PROTOCOL_VERSION_MINOR,
0x196f,
0x1f4b,
0x213f,
0x2149
};
static INT_PTR CALLBACK DlgProcOptNet(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
CSametimeProto* proto = (CSametimeProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
switch (msg) {
case WM_INITDIALOG: {
TranslateDialogDefault(hwndDlg);
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
proto = (CSametimeProto*)lParam;
WORD client_ver = proto->GetClientVersion();
if (client_ver) {
TCHAR verbuf[100];
mir_sntprintf(verbuf, SIZEOF(verbuf), TranslateT("Client protocol version: %03d.%03d"), (client_ver & 0xFF00) >> 8, client_ver & 0xFF);
SetDlgItemText(hwndDlg, IDC_ST_CLIENTVER, verbuf);
}
WORD server_ver = proto->GetServerVersion();
if (server_ver) {
TCHAR verbuf[100];
mir_sntprintf(verbuf, SIZEOF(verbuf), TranslateT("Server protocol version: %03d.%03d"), (server_ver & 0xFF00) >> 8, server_ver & 0xFF);
SetDlgItemText(hwndDlg, IDC_ST_SERVERVER, verbuf);
}
TCHAR *s = mir_utf8decodeT(proto->options.server_name); SetDlgItemText(hwndDlg, IDC_ED_SNAME, s); mir_free(s);
s = mir_utf8decodeT(proto->options.id); SetDlgItemText(hwndDlg, IDC_ED_NAME, s); mir_free(s);
s = mir_utf8decodeT(proto->options.pword); SetDlgItemText(hwndDlg, IDC_ED_PWORD, s); mir_free(s);
SetDlgItemInt(hwndDlg, IDC_ED_PORT, proto->options.port, FALSE);
CheckDlgButton(hwndDlg, IDC_CHK_GETSERVERCONTACTS, proto->options.get_server_contacts ? TRUE : FALSE);
CheckDlgButton(hwndDlg, IDC_CHK_ADDCONTACTS, proto->options.add_contacts ? TRUE : FALSE);
CheckDlgButton(hwndDlg, IDC_CHK_IDLEAWAY, proto->options.idle_as_away ? TRUE : FALSE);
SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENT, CB_RESETCONTENT, 0, 0);
int pos = 0;
bool found = false;
for (int i = 0; i < NUM_IDS; i++) {
pos = SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENT, CB_ADDSTRING, -1, (LPARAM)client_names[i]);
SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENT, CB_SETITEMDATA, pos, client_ids[i]);
if (client_ids[i] == proto->options.client_id) {
found = true;
SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENT, CB_SETCURSEL, pos, 0);
SetDlgItemInt(hwndDlg, IDC_ED_CLIENTID, client_ids[i], FALSE);
if (i != sizeof(client_ids) / sizeof(int)-1) {
HWND hw = GetDlgItem(hwndDlg, IDC_ED_CLIENTID);
EnableWindow(hw, false);
}
}
}
if (!found) {
SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENT, CB_SETCURSEL, pos, 0); // pos is last item, i.e. custom
SetDlgItemInt(hwndDlg, IDC_ED_CLIENTID, proto->options.client_id, FALSE);
}
SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENTVN, CB_RESETCONTENT, 0, 0);
pos = 0;
for (int i = 0; i < NUM_CVS; i++) {
pos = SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENTVN, CB_ADDSTRING, -1, (LPARAM)CV_names[i]);
SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENTVN, CB_SETITEMDATA, pos, i);
if (CV_major[i] == proto->options.client_versionMajor && CV_minor[i] == proto->options.client_versionMinor) {
found = true;
SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENTVN, CB_SETCURSEL, pos, 0);
}
}
if (!ServiceExists(MS_POPUP_ADDPOPUPT)) {
HWND hw = GetDlgItem(hwndDlg, IDC_RAD_ERRPOP);
EnableWindow(hw, FALSE);
}
if (!ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) {
HWND hw = GetDlgItem(hwndDlg, IDC_RAD_ERRBAL);
EnableWindow(hw, FALSE);
}
switch (proto->options.err_method) {
case ED_POP: CheckDlgButton(hwndDlg, IDC_RAD_ERRPOP, TRUE); break;
case ED_MB: CheckDlgButton(hwndDlg, IDC_RAD_ERRMB, TRUE); break;
case ED_BAL: CheckDlgButton(hwndDlg, IDC_RAD_ERRBAL, TRUE); break;
}
if (proto->options.encrypt_session)
CheckDlgButton(hwndDlg, IDC_RAD_ENC, TRUE);
else
CheckDlgButton(hwndDlg, IDC_RAD_NOENC, TRUE);
return FALSE;
}
case WM_COMMAND:
if (HIWORD(wParam) == EN_CHANGE && (HWND)lParam == GetFocus())
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
if (HIWORD(wParam) == CBN_SELCHANGE) {
switch (LOWORD(wParam)) {
case IDC_CMB_CLIENT:
{
int sel = SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENT, CB_GETCURSEL, 0, 0);
int id = SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENT, CB_GETITEMDATA, sel, 0);
bool custom = (id == client_ids[sizeof(client_ids) / sizeof(int)-1]);
if (!custom)
SetDlgItemInt(hwndDlg, IDC_ED_CLIENTID, id, FALSE);
else
SetDlgItemInt(hwndDlg, IDC_ED_CLIENTID, DEFAULT_ID, FALSE);
HWND hw = GetDlgItem(hwndDlg, IDC_ED_CLIENTID);
EnableWindow(hw, custom);
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
return TRUE;
}
case IDC_CMB_CLIENTVN:
{
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
return TRUE;
}
}
}
if (HIWORD(wParam) == BN_CLICKED) {
switch (LOWORD(wParam)) {
case IDC_BTN_UPLOADCONTACTS:
{
EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_UPLOADCONTACTS), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_IMPORTCONTACTS), FALSE);
proto->ExportContactsToServer();
SendMessage(hwndDlg, WMU_STORECOMPLETE, 0, 0);
}
return TRUE;
case IDC_BTN_IMPORTCONTACTS:
{
TCHAR import_filename[MAX_PATH]; import_filename[0] = 0;
OPENFILENAME ofn = { 0 };
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFile = import_filename;
ofn.hwndOwner = hwndDlg;
ofn.Flags = CC_FULLOPEN;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = _T("All\0*.*\0");
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST;
if (GetOpenFileName(&ofn) == TRUE) {
HWND hBut = GetDlgItem(hwndDlg, IDC_BTN_UPLOADCONTACTS);
EnableWindow(hBut, FALSE);
hBut = GetDlgItem(hwndDlg, IDC_BTN_IMPORTCONTACTS);
EnableWindow(hBut, FALSE);
proto->ImportContactsFromFile(ofn.lpstrFile);
SendMessage(hwndDlg, WMU_STORECOMPLETE, 0, 0);
}
}
return TRUE;
case IDC_CHK_GETSERVERCONTACTS:
case IDC_CHK_ENCMESSAGES:
case IDC_RAD_ERRMB:
case IDC_RAD_ERRBAL:
case IDC_RAD_ERRPOP:
case IDC_CHK_USERCP:
case IDC_CHK_ADDCONTACTS:
case IDC_CHK_IDLEAWAY:
case IDC_RAD_ENC:
case IDC_RAD_NOENC:
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
return TRUE;
case IDC_RAD_ANSI:
case IDC_RAD_UTF8:
case IDC_RAD_OEM:
case IDC_RAD_UTF7:
case IDC_RAD_USERCP:
HWND hw = GetDlgItem(hwndDlg, IDC_CHK_USERCP);
EnableWindow(hw, !IsDlgButtonChecked(hwndDlg, IDC_RAD_USERCP));
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
return TRUE;
}
}
break;
case WMU_STORECOMPLETE:
EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_UPLOADCONTACTS), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_IMPORTCONTACTS), TRUE);
return TRUE;
case WM_NOTIFY:
if (((LPNMHDR)lParam)->code == PSN_APPLY) {
TCHAR ws[2048];
char* utf;
GetDlgItemText(hwndDlg, IDC_ED_SNAME, ws, LSTRINGLEN);
strcpy(proto->options.server_name, utf = mir_utf8encodeT(ws)); mir_free(utf);
GetDlgItemText(hwndDlg, IDC_ED_NAME, ws, LSTRINGLEN);
strcpy(proto->options.id, utf = mir_utf8encodeT(ws)); mir_free(utf);
GetDlgItemText(hwndDlg, IDC_ED_PWORD, ws, LSTRINGLEN);
strcpy(proto->options.pword, utf = mir_utf8encodeT(ws)); mir_free(utf);
BOOL translated;
int port = GetDlgItemInt(hwndDlg, IDC_ED_PORT, &translated, FALSE);
if (translated)
proto->options.port = port;
proto->options.get_server_contacts = (IsDlgButtonChecked(hwndDlg, IDC_CHK_GETSERVERCONTACTS) != FALSE);
int sel = SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENT, CB_GETCURSEL, 0, 0);
int id = SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENT, CB_GETITEMDATA, sel, 0);
if (id == client_ids[sizeof(client_ids) / sizeof(int)-1]) {
BOOL trans;
id = GetDlgItemInt(hwndDlg, IDC_ED_CLIENTID, &trans, FALSE);
if (trans)
proto->options.client_id = id;
}
else proto->options.client_id = id;
sel = SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENTVN, CB_GETCURSEL, 0, 0);
int CVpos = SendDlgItemMessage(hwndDlg, IDC_CMB_CLIENTVN, CB_GETITEMDATA, sel, 0);
proto->options.client_versionMajor = CV_major[CVpos];
proto->options.client_versionMinor = CV_minor[CVpos];
if (IsDlgButtonChecked(hwndDlg, IDC_RAD_ERRMB)) proto->options.err_method = ED_MB;
else if (IsDlgButtonChecked(hwndDlg, IDC_RAD_ERRBAL)) proto->options.err_method = ED_BAL;
else if (IsDlgButtonChecked(hwndDlg, IDC_RAD_ERRPOP)) proto->options.err_method = ED_POP;
proto->options.add_contacts = (IsDlgButtonChecked(hwndDlg, IDC_CHK_ADDCONTACTS) != FALSE);
proto->options.encrypt_session = (IsDlgButtonChecked(hwndDlg, IDC_RAD_ENC) != FALSE);
proto->options.idle_as_away = (IsDlgButtonChecked(hwndDlg, IDC_CHK_IDLEAWAY) != FALSE);
proto->SaveOptions();
return TRUE;
}
break;
case WM_DESTROY:
break;
}
return FALSE;
}
int CSametimeProto::OptInit(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = { sizeof(odp) };
odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR | ODPF_DONTTRANSLATE;
odp.hInstance = hInst;
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTNET);
odp.ptszTitle = m_tszUserName;
odp.ptszGroup = LPGENT("Network");
odp.pfnDlgProc = DlgProcOptNet;
odp.dwInitParam = (LPARAM)this;
Options_AddPage(wParam, &odp);
return 0;
}
void CSametimeProto::LoadOptions()
{
DBVARIANT dbv;
if (!db_get_utf(0, m_szModuleName, "ServerName", &dbv)) {
strncpy(options.server_name, dbv.pszVal, LSTRINGLEN);
db_free(&dbv);
}
if (!db_get_utf(0, m_szModuleName, "stid", &dbv)) {
strncpy(options.id, dbv.pszVal, LSTRINGLEN);
db_free(&dbv);
}
if (!db_get_utf(0, m_szModuleName, "Password", &dbv)) {
strncpy(options.pword, dbv.pszVal, LSTRINGLEN);
db_free(&dbv);
}
options.port = db_get_dw(0, m_szModuleName, "ServerPort", DEFAULT_PORT);
options.encrypt_session = (db_get_b(0, m_szModuleName, "EncryptSession", 0) == 1);
options.client_id = db_get_dw(0, m_szModuleName, "ClientID", DEFAULT_ID);
options.client_versionMajor = db_get_dw(0, m_szModuleName, "ClientVersionMajor", DEFAULT_CV_MAJOR);
DWORD defaultCVMinor;
if (db_get_b(0, m_szModuleName, "UseOldClientVer", 0) == 1){
// if sb have checked old deprecated option 'Use old client version' respect it
defaultCVMinor = 0x001d;
} else {
defaultCVMinor = DEFAULT_CV_MINOR;
}
options.client_versionMinor = db_get_dw(0, m_szModuleName, "ClientVersionMinor", defaultCVMinor);
// one time options conversion
if (db_get_b(0, m_szModuleName, "UseOldClientVer", -1) != -1){
db_unset(0, m_szModuleName, "UseOldClientVer");
db_set_dw(0, m_szModuleName, "ClientVersionMajor", options.client_versionMajor);
db_set_dw(0, m_szModuleName, "ClientVersionMinor", options.client_versionMinor);
}
options.get_server_contacts = (db_get_b(0, m_szModuleName, "GetServerContacts", 1) == 1);
options.add_contacts = (db_get_b(0, m_szModuleName, "AutoAddContacts", 0) == 1);
options.idle_as_away = (db_get_b(0, m_szModuleName, "IdleAsAway", 1) == 1);
// if popups not installed, will be changed to 'ED_BAL' (balloons) in main.cpp, modules loaded
options.err_method = (ErrorDisplay)db_get_b(0, m_szModuleName, "ErrorDisplay", ED_POP);
// funny logic :) ... try to avoid message boxes
// if want baloons but no balloons, try popups
// if want popups but no popups, try baloons
// if, after that, you want balloons but no balloons, revert to message boxes
if (options.err_method == ED_BAL && !ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) options.err_method = ED_POP;
if (options.err_method == ED_POP && !ServiceExists(MS_POPUP_SHOWMESSAGE)) options.err_method = ED_BAL;
if (options.err_method == ED_BAL && !ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) options.err_method = ED_MB;
debugLog(_T("LoadOptions() loaded: ServerName:len=[%d], id:len=[%d], pword:len=[%d]"), options.server_name == NULL ? -1 : strlen(options.server_name), options.id == NULL ? -1 : strlen(options.id), options.pword == NULL ? -1 : strlen(options.pword));
debugLog(_T("LoadOptions() loaded: port=[%d], encrypt_session=[%d], ClientID=[%d], ClientVersionMajor=[%d], ClientVersionMinor=[%d]"), options.port, options.encrypt_session, options.client_id, options.client_versionMajor, options.client_versionMinor);
debugLog(_T("LoadOptions() loaded: get_server_contacts=[%d], add_contacts=[%d], idle_as_away=[%d], err_method=[%d]"), options.get_server_contacts, options.add_contacts, options.idle_as_away, options.err_method);
}
void CSametimeProto::SaveOptions()
{
db_set_utf(0, m_szModuleName, "ServerName", options.server_name);
db_set_utf(0, m_szModuleName, "stid", options.id);
//db_set_s(0, m_szModuleName, "Nick", options.id);
db_set_utf(0, m_szModuleName, "Password", options.pword);
db_set_dw(0, m_szModuleName, "ServerPort", options.port);
db_set_b(0, m_szModuleName, "GetServerContacts", options.get_server_contacts ? 1 : 0);
db_set_dw(0, m_szModuleName, "ClientID", options.client_id);
db_set_dw(0, m_szModuleName, "ClientVersionMajor", options.client_versionMajor);
db_set_dw(0, m_szModuleName, "ClientVersionMinor", options.client_versionMinor);
db_set_b(0, m_szModuleName, "ErrorDisplay", options.err_method);
db_set_b(0, m_szModuleName, "AutoAddContacts", options.add_contacts ? 1 : 0);
db_set_b(0, m_szModuleName, "EncryptSession", options.encrypt_session ? 1 : 0);
db_set_b(0, m_szModuleName, "IdleAsAway", options.idle_as_away ? 1 : 0);
}
|