summaryrefslogtreecommitdiff
path: root/protocols/Gadu-Gadu/src/import.cpp
blob: 6e6d8aa15554793c6c45711404734dfcd004edc0 (plain)
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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
////////////////////////////////////////////////////////////////////////////////
// Gadu-Gadu Plugin for Miranda IM
//
// Copyright (c) 2003-2006 Adam Strzelecki <ono+miranda@java.pl>
//
// 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.
////////////////////////////////////////////////////////////////////////////////

#include "gg.h"

////////////////////////////////////////////////////////////////////////////////
// Checks if a group already exists in Miranda with
// the specified name.
// Returns 1 if a group with the name exists, returns 0 otherwise.
int GroupNameExists(const char *name)
{
	char idstr[33];
	DBVARIANT dbv;
	int i;

	for (i = 0; ; i++) {
		_itoa(i, idstr, 10);
		if (db_get_s(NULL, "CListGroups", idstr, &dbv, DBVT_ASCIIZ)) break;
		if (!strcmp(dbv.pszVal + 1, name)) {
			DBFreeVariant(&dbv);
			return 1;
		}
		DBFreeVariant(&dbv);
	}
	return 0;
}


////////////////////////////////////////////////////////////////////////////////
// Creates a group with a specified name in the
// Miranda contact list.
// Returns proper group name

char *CreateGroup(char *groupName)
{
	int groupId;
	char groupIdStr[11];
	char groupName2[127];
	char *p;
	DBVARIANT dbv;

	// Cleanup group name from weird characters

	// Skip first break
	while(*groupName && *groupName == '\\') groupName++;

	p = strrchr(groupName, '\\');
	// Cleanup end
	while(p && !(*(p + 1)))
	{
		*p = 0;
		p = strrchr(groupName, '\\');
	}
	// Create upper groups
	if (p)
	{
		*p = 0;
		CreateGroup(groupName);
		*p = '\\';
	}

	// Is this a duplicate?
	if (!GroupNameExists(groupName))
	{
		lstrcpynA(groupName2 + 1, groupName, (int)strlen(groupName) + 1);

		// Find an unused id
		for (groupId = 0; ; groupId++) {
				_itoa(groupId, groupIdStr,10);
				if (db_get_s(NULL, "CListGroups", groupIdStr, &dbv, DBVT_ASCIIZ))
						break;
				DBFreeVariant(&dbv);
		}

		groupName2[0] = 1|GROUPF_EXPANDED;	// 1 is required so we never get '\0'
		db_set_s(NULL, "CListGroups", groupIdStr, groupName2);
	}
	return groupName;
}

char *gg_makecontacts(GGPROTO *gg, int cr)
{
	string_t s = string_init(NULL);
	char *contacts;

	// Readup contacts
	HANDLE hContact = db_find_first();
	while (hContact)
	{
		char *szProto = GetContactProto(hContact);
		if (szProto != NULL && !strcmp(szProto, gg->m_szModuleName) && !db_get_b(hContact, gg->m_szModuleName, "ChatRoom", 0))
		{
			DBVARIANT dbv;

			// Readup FirstName
			if (!db_get_s(hContact, gg->m_szModuleName, GG_KEY_PD_FIRSTNAME, &dbv, DBVT_WCHAR))
			{
				char* pszValA = mir_t2a(dbv.ptszVal);
				string_append(s, dbv.pszVal);
				mir_free(pszValA);
				DBFreeVariant(&dbv);
			}
			string_append_c(s, ';');
			// Readup LastName
			if (!db_get_s(hContact, gg->m_szModuleName, GG_KEY_PD_LASTNAME, &dbv, DBVT_WCHAR))
			{
				char* pszValA = mir_t2a(dbv.ptszVal);
				string_append(s, dbv.pszVal);
				mir_free(pszValA);
				DBFreeVariant(&dbv);
			}
			string_append_c(s, ';');

			// Readup Nick
			if (!db_get_s(hContact, "CList", "MyHandle", &dbv, DBVT_TCHAR) || !db_get_s(hContact, gg->m_szModuleName, GG_KEY_NICK, &dbv, DBVT_TCHAR))
			{
				char* dbvA = mir_t2a(dbv.ptszVal);
				DBVARIANT dbv2;
				if (!db_get_s(hContact, gg->m_szModuleName, GG_KEY_PD_NICKNAME, &dbv2, DBVT_WCHAR))
				{
					char* pszValA = mir_t2a(dbv2.ptszVal);
					string_append(s, pszValA);
					mir_free(pszValA);
					DBFreeVariant(&dbv2);
				} else {
					string_append(s, dbvA);
				}
				string_append_c(s, ';');
				string_append(s, dbvA);
				mir_free(dbvA);
				DBFreeVariant(&dbv);
			}
			else
				string_append_c(s, ';');
			string_append_c(s, ';');

			// Readup Phone (fixed: uses stored editable phones)
			if (!db_get_s(hContact, "UserInfo", "MyPhone0", &dbv, DBVT_ASCIIZ))
			{
				// Remove SMS postfix
				char *sms = strstr(dbv.pszVal, " SMS");
				if (sms) *sms = 0;

				string_append(s, dbv.pszVal);
				DBFreeVariant(&dbv);
			}
			string_append_c(s, ';');
			// Readup Group
			if (!db_get_s(hContact, "CList", "Group", &dbv, DBVT_ASCIIZ))
			{
				string_append(s, dbv.pszVal);
				DBFreeVariant(&dbv);
			}
			string_append_c(s, ';');
			// Readup Uin
			string_append(s, ditoa(db_get_dw(hContact, gg->m_szModuleName, GG_KEY_UIN, 0)));
			string_append_c(s, ';');
			// Readup Mail (fixed: uses stored editable mails)
			if (!db_get_s(hContact, "UserInfo", "Mye-mail0", &dbv, DBVT_ASCIIZ))
			{
				string_append(s, dbv.pszVal);
				DBFreeVariant(&dbv);
			}
			if (cr)
				string_append(s, ";0;;0;\r\n");
			else
				string_append(s, ";0;;0;\n");
		}
		hContact = db_find_next(hContact);
	}

	contacts = string_free(s, 0);

#ifdef DEBUGMODE
	gg->netlog("gg_makecontacts(): \n%s", contacts);
#endif

	return contacts;
}

char *strndup(char *str, int c)
{
	char *ret = (char*)malloc(c + 1);
	ret[c] = 0;
	strncpy(ret, str, c);
	return ret;
}

void GGPROTO::parsecontacts(char *contacts)
{
	char *p = strchr(contacts, ':'), *n;
	char *strFirstName, *strLastName, *strNickname, *strNick, *strPhone, *strGroup, *strUin, *strMail;
	uin_t uin;

	// Skip to proper data
	if (p && p < strchr(contacts, ';')) p++;
	else p = contacts;

	while(p)
	{
		// Processing line
		strFirstName = strLastName = strNickname = strNick = strPhone = strGroup = strUin = strMail = NULL;
		uin = 0;

		// FirstName
		if (p)
		{
			n = strchr(p, ';');
			if (n && n != p) strFirstName = strndup(p, (n - p));
			p = (n + 1);
		}
		// LastName
		if (n && p)
		{
			n = strchr(p, ';');
			if (n && n != p) strLastName = strndup(p, (n - p));
			p = (n + 1);
		}
		// Nickname
		if (n && p)
		{
			n = strchr(p, ';');
			if (n && n != p) strNickname = strndup(p, (n - p));
			p = (n + 1);
		}
		// Nick
		if (n && p)
		{
			n = strchr(p, ';');
			if (n && n != p) strNick = strndup(p, (n - p));
			p = (n + 1);
		}
		// Phone
		if (n && p)
		{
			n = strchr(p, ';');
			if (n && n != p)
			{
				strPhone = (char*)malloc((n - p) + 5);
				strncpy(strPhone, p, (n - p));
				strcpy((strPhone + (n - p)), " SMS"); // Add SMS postfix
			}
			p = (n + 1);
		}
		// Group
		if (n && p)
		{
			n = strchr(p, ';');
			if (n && n != p) strGroup = strndup(p, (n - p));
			p = (n + 1);
		}
		// Uin
		if (n && p)
		{
			n = strchr(p, ';');
			if (n && n != p)
			{
				strUin = strndup(p, (n - p));
				uin = atoi(strUin);
			}
			p = (n + 1);
		}
		// Mail
		if (n && p)
		{
			n = strchr(p, ';');
			if (n && n != p) strMail = strndup(p, (n - p));
			n = strchr(p, '\n');
			p = (n + 1);
		}
		if (!n) p = NULL;

		// Loadup contact
		if (uin && strNick)
		{
			HANDLE hContact = getcontact(uin, 1, 1, _A2T(strNick));
#ifdef DEBUGMODE
			netlog("parsecontacts(): Found contact %d with nickname \"%s\".", uin, strNick);
#endif
			// Write group
			if (hContact && strGroup)
				db_set_s(hContact, "CList", "Group", CreateGroup(strGroup));

			// Write misc data
			if (hContact && strFirstName){
				TCHAR *tstrFirstName = mir_a2t(strFirstName);
				db_set_ts(hContact, m_szModuleName, GG_KEY_PD_FIRSTNAME, tstrFirstName);
				mir_free(tstrFirstName);
			}
			if (hContact && strLastName){
				TCHAR *tstrLastName = mir_a2t(strLastName);
				db_set_ts(hContact, m_szModuleName, GG_KEY_PD_LASTNAME, tstrLastName);
				mir_free(tstrLastName);
			}
			if (hContact && strPhone) db_set_s(hContact, "UserInfo", "MyPhone0", strPhone); // Store now in User Info
			if (hContact && strMail) db_set_s(hContact, "UserInfo", "Mye-mail0", strMail); // Store now in User Info
		}

		// Release stuff
		if (strFirstName) free(strFirstName);
		if (strLastName) free(strLastName);
		if (strNickname) free(strNickname);
		if (strNick) free(strNick);
		if (strPhone) free(strPhone);
		if (strGroup) free(strGroup);
		if (strUin) free(strUin);
		if (strMail) free(strMail);
	}
}

//////////////////////////////////////////////////////////
// import from server

INT_PTR GGPROTO::import_server(WPARAM wParam, LPARAM lParam)
{
	char *password;
	uin_t uin;
	DBVARIANT dbv;

	// Check if connected
	if (!isonline())
	{
		MessageBox(NULL,
			TranslateT("You have to be connected before you can import/export contacts from/to server."),
			m_tszUserName, MB_OK | MB_ICONSTOP
		);
		return 0;
	}

	// Readup password
	if (!db_get_s(NULL, m_szModuleName, GG_KEY_PASSWORD, &dbv, DBVT_ASCIIZ))
	{
		CallService(MS_DB_CRYPT_DECODESTRING, strlen(dbv.pszVal) + 1, (LPARAM) dbv.pszVal);
		password = _strdup(dbv.pszVal);
		DBFreeVariant(&dbv);
	}
	else return 0;

	if (!(uin = db_get_dw(NULL, m_szModuleName, GG_KEY_UIN, 0)))
		return 0;

	// Making contacts list
	gg_EnterCriticalSection(&sess_mutex, "import_server", 65, "sess_mutex", 1);
	if (gg_userlist_request(sess, GG_USERLIST_GET, NULL) == -1)
	{
		TCHAR error[128];
		gg_LeaveCriticalSection(&sess_mutex, "import_server", 65, 1, "sess_mutex", 1);
		mir_sntprintf(error, SIZEOF(error), TranslateT("List cannot be imported because of error:\n\t%s"), _tcserror(errno));
		MessageBox(NULL, error, m_tszUserName, MB_OK | MB_ICONSTOP);
		netlog("import_server(): Cannot import list because of \"%s\".", strerror(errno));
	}
	gg_LeaveCriticalSection(&sess_mutex, "import_server", 65, 2, "sess_mutex", 1);
	free(password);

	return 0;
}

//////////////////////////////////////////////////////////
// remove from server

INT_PTR GGPROTO::remove_server(WPARAM wParam, LPARAM lParam)
{
	char *password;
	uin_t uin;
	DBVARIANT dbv;

	// Check if connected
	if (!isonline())
	{
		MessageBox(NULL,
			TranslateT("You have to be connected before you can import/export contacts from/to server."),
			m_tszUserName, MB_OK | MB_ICONSTOP
		);
		return 0;
	}

	// Readup password
	if (!db_get_s(NULL, m_szModuleName, GG_KEY_PASSWORD, &dbv, DBVT_ASCIIZ))
	{
		CallService(MS_DB_CRYPT_DECODESTRING, strlen(dbv.pszVal) + 1, (LPARAM) dbv.pszVal);
		password = _strdup(dbv.pszVal);
		DBFreeVariant(&dbv);
	}
	else return 0;

	if (!(uin = db_get_dw(NULL, m_szModuleName, GG_KEY_UIN, 0)))
		return 0;

	// Making contacts list
	gg_EnterCriticalSection(&sess_mutex, "remove_server", 66, "sess_mutex", 1);
	if (gg_userlist_request(sess, GG_USERLIST_PUT, NULL) == -1)
	{
		TCHAR error[128];
		gg_LeaveCriticalSection(&sess_mutex, "remove_server", 66, 1, "sess_mutex", 1);
		mir_sntprintf(error, SIZEOF(error), TranslateT("List cannot be removeed because of error:\n\t%s"), _tcserror(errno));
		MessageBox(NULL, error, m_tszUserName, MB_OK | MB_ICONSTOP);
		netlog("remove_server(): Cannot remove list because of \"%s\".", strerror(errno));
	}
	gg_LeaveCriticalSection(&sess_mutex, "remove_server", 66, 2, "sess_mutex", 1);

	// Set list removal
	is_list_remove = TRUE;
	free(password);

	return 0;
}

INT_PTR GGPROTO::import_text(WPARAM wParam, LPARAM lParam)
{
	TCHAR str[MAX_PATH];
	TCHAR filter[512], *pfilter;
	struct _stat st;
	FILE *f;

	OPENFILENAME ofn = {0};
	ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
	_tcsncpy(filter, TranslateT("Text files"), SIZEOF(filter));
	_tcsncat(filter, _T(" (*.txt)"), SIZEOF(filter) - _tcslen(filter));
	pfilter = filter + _tcslen(filter) + 1;
	if (pfilter >= filter + SIZEOF(filter))
		return 0;

	_tcsncpy(pfilter, _T("*.TXT"), SIZEOF(filter) - (pfilter - filter));
	pfilter = pfilter + _tcslen(pfilter) + 1;
	if (pfilter >= filter + SIZEOF(filter))
		return 0;
	_tcsncpy(pfilter, TranslateT("All Files"), SIZEOF(filter) - (pfilter - filter));
	_tcsncat(pfilter, _T(" (*)"), SIZEOF(filter) - (pfilter - filter) - _tcslen(pfilter));
	pfilter = pfilter + _tcslen(pfilter) + 1;

	if (pfilter >= filter + SIZEOF(filter))
		return 0;

	_tcsncpy(pfilter, _T("*"), SIZEOF(filter) - (pfilter - filter));
	pfilter = pfilter + _tcslen(pfilter) + 1;
	if (pfilter >= filter + SIZEOF(filter))
		return 0;

	*pfilter = '\0';
	*str = '\0';

	ofn.lpstrFilter = filter;
	ofn.lpstrFile = str;
	ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
	ofn.nMaxFile = sizeof(str);
	ofn.nMaxFileTitle = MAX_PATH;
	ofn.lpstrDefExt = _T("txt");

#ifdef DEBUGMODE
	netlog("import_text()");
#endif
	if (!GetOpenFileName(&ofn)) return 0;

	f = _tfopen(str, _T("r"));
	_tstat(str, &st);

	if (f && st.st_size)
	{
		char *contacts = (char*)malloc(st.st_size * sizeof(char));
		fread(contacts, sizeof(char), st.st_size, f);
		fclose(f);
		parsecontacts(contacts);
		free(contacts);

		MessageBox(NULL, TranslateT("List import successful."), m_tszUserName, MB_OK | MB_ICONINFORMATION);
	}
	else
	{
		TCHAR error[128];
		mir_sntprintf(error, SIZEOF(error), TranslateT("List cannot be imported from file \"%s\" because of error:\n\t%s"), str, _tcserror(errno));
		MessageBox(NULL, error, m_tszUserName, MB_OK | MB_ICONSTOP);
		netlog("import_text(): Cannot import list from file \"%S\" because of \"%s\".", str, strerror(errno));
	}

	return 0;
}

INT_PTR GGPROTO::export_text(WPARAM wParam, LPARAM lParam)
{
	TCHAR str[MAX_PATH];
	OPENFILENAME ofn = {0};
	TCHAR filter[512], *pfilter;
	FILE *f;

	_tcsncpy(str, TranslateT("contacts"), SIZEOF(str));
	_tcsncat(str, _T(".txt"), SIZEOF(str) - _tcslen(str));

	ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
	_tcsncpy(filter, TranslateT("Text files"), SIZEOF(filter));
	_tcsncat(filter, _T(" (*.txt)"), SIZEOF(filter) - _tcslen(filter));
	pfilter = filter + _tcslen(filter) + 1;
	if (pfilter >= filter + SIZEOF(filter))
		return 0;
	_tcsncpy(pfilter, _T("*.TXT"), SIZEOF(filter) - (pfilter - filter));
	pfilter = pfilter + _tcslen(pfilter) + 1;
	if (pfilter >= filter + SIZEOF(filter))
		return 0;
	_tcsncpy(pfilter, TranslateT("All Files"), SIZEOF(filter) - (pfilter - filter));
	_tcsncat(pfilter, _T(" (*)"), SIZEOF(filter) - (pfilter - filter) - _tcslen(pfilter));
	pfilter = pfilter + _tcslen(pfilter) + 1;
	if (pfilter >= filter + SIZEOF(filter))
		return 0;
	_tcsncpy(pfilter, _T("*"), SIZEOF(filter) - (pfilter - filter));
	pfilter = pfilter + _tcslen(pfilter) + 1;
	if (pfilter >= filter + SIZEOF(filter))
		return 0;
	*pfilter = '\0';
	ofn.lpstrFilter = filter;
	ofn.lpstrFile = str;
	ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
	ofn.nMaxFile = sizeof(str);
	ofn.nMaxFileTitle = MAX_PATH;
	ofn.lpstrDefExt = _T("txt");

#ifdef DEBUGMODE
	netlog("export_text(%S).", str);
#endif
	if (!GetSaveFileName(&ofn)) return 0;

	if (f = _tfopen(str, _T("w"))) {
		char *contacts = gg_makecontacts(this, 0);
		fwrite(contacts, sizeof(char), strlen(contacts), f);
		fclose(f);
		free(contacts);

		MessageBox(NULL, TranslateT("List export successful."), m_tszUserName, MB_OK | MB_ICONINFORMATION);
	}
	else
	{
		TCHAR error[128];
		mir_sntprintf(error, SIZEOF(error), TranslateT("List cannot be exported to file \"%s\" because of error:\n\t%s"), str, _tcserror(errno));
		MessageBox(NULL, error, m_tszUserName, MB_OK | MB_ICONSTOP);
		netlog("export_text(): Cannot export list to file \"%s\" because of \"%s\".", str, strerror(errno));
	}

	return 0;
}

//////////////////////////////////////////////////////////
// export to server

INT_PTR GGPROTO::export_server(WPARAM wParam, LPARAM lParam)
{
	char *password, *contacts;
	uin_t uin;
	DBVARIANT dbv;

	// Check if connected
	if (!isonline())
	{
		MessageBox(NULL,
			TranslateT("You have to be connected before you can import/export contacts from/to server."),
			m_tszUserName, MB_OK | MB_ICONSTOP
		);
		return 0;
	}

	// Readup password
	if (!db_get_s(NULL, m_szModuleName, GG_KEY_PASSWORD, &dbv, DBVT_ASCIIZ))
	{
		CallService(MS_DB_CRYPT_DECODESTRING, strlen(dbv.pszVal) + 1, (LPARAM) dbv.pszVal);
		password = _strdup(dbv.pszVal);
		DBFreeVariant(&dbv);
	}
	else return 0;

	if (!(uin = db_get_dw(NULL, m_szModuleName, GG_KEY_UIN, 0)))
		return 0;

	// Making contacts list
	contacts = gg_makecontacts(this, 1);

#ifdef DEBUGMODE
		netlog("export_server(): gg_userlist_request(%s).", contacts);
#endif

	gg_EnterCriticalSection(&sess_mutex, "export_server", 67, "sess_mutex", 1);
	if (gg_userlist_request(sess, GG_USERLIST_PUT, contacts) == -1)
	{
		TCHAR error[128];
		gg_LeaveCriticalSection(&sess_mutex, "export_server", 67, 1, "sess_mutex", 1);
		mir_sntprintf(error, SIZEOF(error), TranslateT("List cannot be exported because of error:\n\t%s"), _tcserror(errno));
		MessageBox(NULL, error, m_tszUserName, MB_OK | MB_ICONSTOP);
		netlog("export_server(): Cannot export list because of \"%s\".", strerror(errno));
	}
	gg_LeaveCriticalSection(&sess_mutex, "export_server", 67, 2, "sess_mutex", 1);

	// Set list removal
	is_list_remove = FALSE;
	free(contacts);
	free(password);

	return 0;
}

//////////////////////////////////////////////////////////
// Import menus and stuff

void GGPROTO::import_init(HGENMENU hRoot)
{
	// Import from server item
	char service[64];
	mir_snprintf(service, sizeof(service), GGS_IMPORT_SERVER, m_szModuleName);
	createObjService(service, &GGPROTO::import_server);

	CLISTMENUITEM mi = { sizeof(mi) };
	mi.flags = CMIF_ICONFROMICOLIB | CMIF_ROOTHANDLE | CMIF_TCHAR;
	mi.hParentMenu = hRoot;
	mi.position = 2000500001;
	mi.icolibItem = iconList[1].hIcolib;
	mi.ptszName = LPGENT("Import List From &Server");
	mi.pszService = service;
 	hMainMenu[2] = Menu_AddProtoMenuItem(&mi);

	// Import from textfile
	mir_snprintf(service, sizeof(service), GGS_IMPORT_TEXT, m_szModuleName);
	createObjService(service, &GGPROTO::import_text);

	mi.position = 2000500002;
	mi.icolibItem = iconList[2].hIcolib;
	mi.ptszName = LPGENT("Import List From &Text File...");
	mi.pszService = service;
	hMainMenu[3] = Menu_AddProtoMenuItem(&mi);

	// Remove from server
	mir_snprintf(service, sizeof(service), GGS_REMOVE_SERVER, m_szModuleName);
	createObjService(service, &GGPROTO::remove_server);

	mi.position = 2000500003;
	mi.icolibItem = iconList[3].hIcolib;
	mi.ptszName = LPGENT("&Remove List From Server");
	mi.pszService = service;
	hMainMenu[4] = Menu_AddProtoMenuItem(&mi);

	// Export to server
	mir_snprintf(service, sizeof(service), GGS_EXPORT_SERVER, m_szModuleName);
	createObjService(service, &GGPROTO::export_server);

	mi.position = 2005000001;
	mi.icolibItem = iconList[4].hIcolib;
	mi.ptszName = LPGENT("Export List To &Server");
	mi.pszService = service;
	hMainMenu[5] = Menu_AddProtoMenuItem(&mi);

	// Export to textfile
	mir_snprintf(service, sizeof(service), GGS_EXPORT_TEXT, m_szModuleName);
	createObjService(service, &GGPROTO::export_text);

	mi.position = 2005000002;
	mi.icolibItem = iconList[5].hIcolib;
	mi.ptszName = LPGENT("Export List To &Text File...");
	mi.pszService = service;
	hMainMenu[6] = Menu_AddProtoMenuItem(&mi);
}