File: gpiInfo.c

package info (click to toggle)
openmohaa 0.81.1%2Bdfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: trixie
  • size: 29,124 kB
  • sloc: ansic: 270,865; cpp: 250,173; sh: 234; asm: 141; xml: 64; makefile: 7
file content (1286 lines) | stat: -rw-r--r-- 31,951 bytes parent folder | download | duplicates (2)
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
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
/*
gpiInfo.c
GameSpy Presence SDK 
Dan "Mr. Pants" Schoenblum

Copyright 1999-2007 GameSpy Industries, Inc

devsupport@gamespy.com

***********************************************************************
Please see the GameSpy Presence SDK documentation for more information
**********************************************************************/

//INCLUDES
//////////
#include "gpi.h"

//FUNCTIONS
///////////
static GPIBool
gpiIsValidDate(
  int day,
  int month,
  int year
)
{
	// Check for a blank.
	/////////////////////
	if((day == 0) && (month == 0) && (year == 0))
		return GPITrue;

	// Check for negatives.
	///////////////////////
	if((day < 0) || (month < 0) || (year < 0))
		return GPIFalse;

	// Validate the day of the month.
	/////////////////////////////////
	switch(month)
	{
	// No month.
	////////////
	case 0:
		// Can't specify a day without a month.
		///////////////////////////////////////
		if(day != 0)
			return GPIFalse;
		break;

	// 31-day month.
	////////////////
	case 1:
	case 3:
	case 5:
	case 7:
	case 8:
	case 10:
	case 12:
		if(day > 31)
			return GPIFalse;
		break;

	// 30-day month.
	////////////////
	case 4:
	case 6:
	case 9:
	case 11:
		if(day > 30)
			return GPIFalse;
		break;

	// 28/29-day month.
	///////////////////
	case 2:
		// Leap year?
		/////////////
		if((((year % 4) == 0) && ((year % 100) != 0)) || ((year % 400) == 0))
		{
			if(day > 29)
				return GPIFalse;
		}
		else
		{
			if(day > 28)
				return GPIFalse;
		}
		break;

	// Invalid month.
	/////////////////
	default:
		return GPIFalse;
	}

	// Check that the date is in the valid range.
	// 01.01.1900 - 06.06.2079
	// PANTS|02.14.2000
	/////////////////////////////////////////////
	if(year < 1900)
		return GPIFalse;
	if(year > 2079)
		return GPIFalse;
	if(year == 2079)
	{
		if(month > 6)
			return GPIFalse;
		if((month == 6) && (day > 6))
			return GPIFalse;
	}

	return GPITrue;
}

static GPResult
gpiDateToInt(
  GPConnection * connection,
  int * date,
  int day,
  int month,
  int year
)
{
	int temp;
	
	// Pack the day/month/year into an int.
	// 31-22: day
	// 23-16: month
	// 15-00: year
	///////////////////////////////////////
	
	// Error check.
	///////////////
	assert(gpiIsValidDate(day, month, year));
	if(!gpiIsValidDate(day, month, year))
		Error(connection, GP_PARAMETER_ERROR, "Invalid date.");

	// Pack!
	////////
	temp = 0;
	temp |= (day << 24);
	temp |= (month << 16);
	temp |= year;

	// Set it.
	//////////
	*date = temp;

	return GP_NO_ERROR;
}

static GPResult
gpiIntToDate(
  GPConnection * connection,
  int date,
  int * day,
  int * month,
  int * year
)
{
	int d;
	int m;
	int y;

	// Unpack the int into a day/month/year.
	// 31-22: day
	// 23-16: month
	// 15-00: year
	////////////////////////////////////////

	// Split up the date.
	/////////////////////
	d = ((date >> 24) & 0xFF);
	m = ((date >> 16) & 0xFF);
	y = (date & 0xFFFF);

	// Error check.
	///////////////
	assert(gpiIsValidDate(d, m, y));
	if(!gpiIsValidDate(d, m, y))
		Error(connection, GP_PARAMETER_ERROR, "Invalid date.");

	// It's all good.
	/////////////////
	*day = d;
	*month = m;
	*year = y;

	return GP_NO_ERROR;
}

void
gpiInfoCacheToArg(
  const GPIInfoCache * cache,
  GPGetInfoResponseArg * arg
)
{
#ifndef GSI_UNICODE
	// Copy....
	///////////
	if(cache->nick)
		strzcpy(arg->nick, cache->nick, GP_NICK_LEN);
	else
		arg->nick[0] = '\0';
	if(cache->uniquenick)
		strzcpy(arg->uniquenick, cache->uniquenick, GP_UNIQUENICK_LEN);
	else
		arg->uniquenick[0] = '\0';
	if(cache->email)
		strzcpy(arg->email, cache->email, GP_EMAIL_LEN);
	else
		arg->email[0] = '\0';
	if(cache->firstname)
		strzcpy(arg->firstname, cache->firstname, GP_FIRSTNAME_LEN);
	else
		arg->firstname[0] = '\0';
	if(cache->lastname)
		strzcpy(arg->lastname, cache->lastname, GP_LASTNAME_LEN);
	else
		arg->lastname[0] = '\0';
	if(cache->homepage)
		strzcpy(arg->homepage, cache->homepage, GP_HOMEPAGE_LEN);
	else
		arg->homepage[0] = '\0';
	arg->icquin = cache->icquin;
	strzcpy(arg->zipcode, cache->zipcode, GP_ZIPCODE_LEN);
	strzcpy(arg->countrycode, cache->countrycode, GP_COUNTRYCODE_LEN);
	arg->longitude = cache->longitude;
	arg->latitude = cache->latitude;
	if(cache->place)
		strzcpy(arg->place, cache->place, GP_PLACE_LEN);
	else
		arg->place[0] = '\0';
	arg->birthday = cache->birthday;
	arg->birthmonth = cache->birthmonth;
	arg->birthyear = cache->birthyear;
	arg->sex = (GPEnum)cache->sex;
	arg->publicmask = (GPEnum)cache->publicmask;
	if(cache->aimname)
		strzcpy(arg->aimname, cache->aimname, GP_AIMNAME_LEN);
	else
		arg->aimname[0] = '\0';
#else
	// Copy....
	///////////
	if(cache->nick)
		UTF8ToUCS2StringLen(cache->nick, arg->nick, GP_NICK_LEN);
	else
		arg->nick[0] = '\0';
	if(cache->uniquenick)
		UTF8ToUCS2StringLen(cache->uniquenick, arg->uniquenick, GP_UNIQUENICK_LEN);
	else
		arg->uniquenick[0] = '\0';
	if(cache->email)
		UTF8ToUCS2StringLen(cache->email, arg->email, GP_EMAIL_LEN);
	else
		arg->email[0] = '\0';
	if(cache->firstname)
		UTF8ToUCS2StringLen(cache->firstname, arg->firstname, GP_FIRSTNAME_LEN);
	else
		arg->firstname[0] = '\0';
	if(cache->lastname)
		UTF8ToUCS2StringLen(cache->lastname, arg->lastname, GP_LASTNAME_LEN);
	else
		arg->lastname[0] = '\0';
	if(cache->homepage)
		UTF8ToUCS2StringLen(cache->homepage, arg->homepage, GP_HOMEPAGE_LEN);
	else
		arg->homepage[0] = '\0';
	UTF8ToUCS2StringLen(cache->zipcode, arg->zipcode, GP_ZIPCODE_LEN);
	UTF8ToUCS2StringLen(cache->countrycode, arg->countrycode, GP_COUNTRYCODE_LEN);
	if(cache->place)
		UTF8ToUCS2StringLen(cache->place, arg->place, GP_PLACE_LEN);
	else
		arg->place[0] = '\0';
	if(cache->aimname)
		UTF8ToUCS2StringLen(cache->aimname, arg->aimname, GP_AIMNAME_LEN);
	else
		arg->aimname[0] = '\0';
#endif

	// Non string members
	arg->icquin = cache->icquin;
	arg->longitude = cache->longitude;
	arg->latitude = cache->latitude;

	arg->birthday = cache->birthday;
	arg->birthmonth = cache->birthmonth;
	arg->birthyear = cache->birthyear;
	arg->sex = (GPEnum)cache->sex;
	arg->publicmask = (GPEnum)cache->publicmask;

	arg->pic = cache->pic;
	arg->occupationid = cache->occupationid;
	arg->industryid = cache->industryid;
	arg->incomeid = cache->incomeid;
	arg->marriedid = cache->marriedid;
	arg->childcount = cache->childcount;
	arg->interests1 = cache->interests1;
	arg->ownership1 = cache->ownership1;
	arg->conntypeid = cache->conntypeid;
}

GPResult
gpiProcessGetInfo(
  GPConnection * connection,
  GPIOperation * operation,
  const char * input
)
{
	GPIInfoCache infoCache;
	char buffer[64];
	int profileid;
	GPIProfile * profile;
	GPIConnection * iconnection = (GPIConnection*)*connection;
	GPICallback callback;
	GPIPeer * peer;
	char nick[GP_NICK_LEN];
	char uniquenick[GP_UNIQUENICK_LEN];
	char email[GP_EMAIL_LEN];
	char firstname[GP_FIRSTNAME_LEN];
	char lastname[GP_LASTNAME_LEN];
	char homepage[GP_HOMEPAGE_LEN];
	char aimname[GP_AIMNAME_LEN];
	GPIBool saveSig;

	// Check for an error.
	//////////////////////
	if(gpiCheckForError(connection, input, GPITrue))
		return GP_SERVER_ERROR;

	// This should be \pi\.
	///////////////////////
	if(strncmp(input, "\\pi\\", 4) != 0)
		CallbackFatalError(connection, GP_NETWORK_ERROR, GP_PARSE, "Unexpected data was received from the server.");

	// Get the profile id.
	//////////////////////
	if(!gpiValueForKey(input, "\\profileid\\", buffer, sizeof(buffer)))
		CallbackFatalError(connection, GP_NETWORK_ERROR, GP_PARSE, "Unexpected data was received from the server.");
	profileid = atoi(buffer);
	assert(profileid > 0);

	// Get the profile - we might not have a profile object.
	////////////////////////////////////////////////////////
	gpiGetProfile(connection, (GPProfile)profileid, &profile);

	// Setup the info cache.
	////////////////////////
	memset(&infoCache, 0, sizeof(GPIInfoCache));
	infoCache.nick = nick;
	infoCache.uniquenick = uniquenick;
	infoCache.email = email;
	infoCache.firstname = firstname;
	infoCache.lastname = lastname;
	infoCache.homepage = homepage;
	infoCache.aimname = aimname;

	// Parse the info.
	//////////////////
	if(!gpiValueForKey(input, "\\nick\\", infoCache.nick, GP_NICK_LEN))
		infoCache.nick[0] = '\0';
	if(!gpiValueForKey(input, "\\uniquenick\\", infoCache.uniquenick, GP_UNIQUENICK_LEN))
		infoCache.uniquenick[0] = '\0';
	if(!gpiValueForKey(input, "\\email\\", infoCache.email, GP_EMAIL_LEN))
		infoCache.email[0] = '\0';
	if(!gpiValueForKey(input, "\\firstname\\", infoCache.firstname, GP_FIRSTNAME_LEN))
		infoCache.firstname[0] = '\0';
	if(!gpiValueForKey(input, "\\lastname\\", infoCache.lastname, GP_LASTNAME_LEN))
		infoCache.lastname[0] = '\0';
	if(!gpiValueForKey(input, "\\icquin\\", buffer, sizeof(buffer)))
		infoCache.icquin = -1;
	else
		infoCache.icquin = atoi(buffer);
	if(!gpiValueForKey(input, "\\homepage\\", infoCache.homepage, GP_HOMEPAGE_LEN))
		infoCache.homepage[0] = '\0';
	if(!gpiValueForKey(input, "\\zipcode\\", infoCache.zipcode, sizeof(infoCache.zipcode)))
		infoCache.zipcode[0] = '\0';
	if(!gpiValueForKey(input, "\\countrycode\\", infoCache.countrycode, sizeof(infoCache.countrycode)))
		infoCache.countrycode[0] = '\0';
	if(!gpiValueForKey(input, "\\lon\\", buffer, sizeof(buffer)))
		infoCache.longitude = 0;
	else
		infoCache.longitude = (float)atof(buffer);
	if(!gpiValueForKey(input, "\\lat\\", buffer, sizeof(buffer)))
		infoCache.latitude = 0;
	else
		infoCache.latitude = (float)atof(buffer);
	if(!gpiValueForKey(input, "\\loc\\", infoCache.place, GP_PLACE_LEN))
		infoCache.place[0] = '\0';
	if(!gpiValueForKey(input, "\\birthday\\", buffer, sizeof(buffer)))
	{
		infoCache.birthday = 0;
		infoCache.birthmonth = 0;
		infoCache.birthyear = 0;
	}
	else
	{
		CHECK_RESULT(gpiIntToDate(connection, atoi(buffer), &infoCache.birthday, &infoCache.birthmonth, &infoCache.birthyear));
	}
	if(!gpiValueForKey(input, "\\sex\\", buffer, sizeof(buffer)))
		infoCache.sex = GP_PAT;
	else if(buffer[0] == '0')
		infoCache.sex = GP_MALE;
	else if(buffer[0] == '1')
		infoCache.sex = GP_FEMALE;
	else
		infoCache.sex = GP_PAT;
	if(!gpiValueForKey(input, "\\pmask\\", buffer, sizeof(buffer)))
		infoCache.publicmask = 0xFFFFFFFF;
	else
		infoCache.publicmask = atoi(buffer);
	if(!gpiValueForKey(input, "\\aim\\", infoCache.aimname, GP_AIMNAME_LEN))
		infoCache.aimname[0] = '\0';
	if(!gpiValueForKey(input, "\\pic\\", buffer, sizeof(buffer)))
		infoCache.pic = 0;
	else
		infoCache.pic = atoi(buffer);
	if(!gpiValueForKey(input, "\\occ\\", buffer, sizeof(buffer)))
		infoCache.occupationid = 0;
	else
		infoCache.occupationid = atoi(buffer);
	if(!gpiValueForKey(input, "\\ind\\", buffer, sizeof(buffer)))
		infoCache.industryid = 0;
	else
		infoCache.industryid = atoi(buffer);
	if(!gpiValueForKey(input, "\\inc\\", buffer, sizeof(buffer)))
		infoCache.incomeid = 0;
	else
		infoCache.incomeid = atoi(buffer);
	if(!gpiValueForKey(input, "\\mar\\", buffer, sizeof(buffer)))
		infoCache.marriedid = 0;
	else
		infoCache.marriedid = atoi(buffer);
	if(!gpiValueForKey(input, "\\chc\\", buffer, sizeof(buffer)))
		infoCache.childcount = 0;
	else
		infoCache.childcount = atoi(buffer);
	if(!gpiValueForKey(input, "\\i1\\", buffer, sizeof(buffer)))
		infoCache.interests1 = 0;
	else
		infoCache.interests1 = atoi(buffer);
	if(!gpiValueForKey(input, "\\o1\\", buffer, sizeof(buffer)))
		infoCache.ownership1 = 0;
	else
		infoCache.ownership1 = atoi(buffer);
	if(!gpiValueForKey(input, "\\conn\\", buffer, sizeof(buffer)))
		infoCache.conntypeid = 0;
	else
		infoCache.conntypeid = atoi(buffer);

	// Get the peer sig.
	////////////////////
	if(!gpiValueForKey(input, "\\sig\\", buffer, sizeof(buffer)))
		CallbackFatalError(connection, GP_NETWORK_ERROR, GP_PARSE, "Unexpected data was received from the server.");

	saveSig = iconnection->infoCaching;

	// Is there a pending peer connection looking for a sig?
	////////////////////////////////////////////////////////
	for(peer = iconnection->peerList ; peer != NULL ; peer = peer->pnext)
	{
		// Is it the same profile?
		//////////////////////////
		if(peer->profile == profileid)
		{
			// Is it getting the sig?
			/////////////////////////
			if(peer->state == GPI_PEER_GETTING_SIG)
			{
				// We need to make sure there's an actual profile object.
				/////////////////////////////////////////////////////////
				if(!profile)
					profile = gpiProfileListAdd(connection, profileid);

				// It got it.
				/////////////
				peer->state = GPI_PEER_GOT_SIG;

				saveSig = GPITrue;
			}
		}
	}

	// Cache info?
	//////////////
	if(!profile && iconnection->infoCaching)
		profile = gpiProfileListAdd(connection, profileid);

	// Set the peer sig.
	////////////////////
	if(saveSig)
	{
		freeclear(profile->peerSig);
		profile->peerSig = goastrdup(buffer);
	}

	// Caching info?
	////////////////
	if(iconnection->infoCaching)
		gpiSetInfoCache(connection, profile, &infoCache);

	// Call the callback.
	/////////////////////
	callback = operation->callback;
	if(callback.callback != NULL)
	{
		GPGetInfoResponseArg * arg;
		arg = (GPGetInfoResponseArg *)gsimalloc(sizeof(GPGetInfoResponseArg));
		if(arg == NULL)
			Error(connection, GP_MEMORY_ERROR, "Out of memory.");
		
		gpiInfoCacheToArg(&infoCache, arg);
		arg->result = GP_NO_ERROR;
		arg->profile = (GPProfile)profileid;

		CHECK_RESULT(gpiAddCallback(connection, callback, arg, operation, 0));
	}

	// This operation is complete.
	//////////////////////////////
	gpiRemoveOperation(connection, operation);

	return GP_NO_ERROR;
}

GPResult
gpiAddLocalInfo(
  GPConnection * connection,
  GPIBuffer * buffer
)
{
	GPIConnection * iconnection = (GPIConnection*)*connection;

	// Add updatepro info.
	//////////////////////
	if(iconnection->updateproBuffer.len > 0)
	{
		gpiAppendStringToBuffer(connection, buffer, "\\updatepro\\\\sesskey\\");
		gpiAppendIntToBuffer(connection, buffer, iconnection->sessKey);
		gpiAppendStringToBuffer(connection, buffer, iconnection->updateproBuffer.buffer);
		gpiAppendStringToBuffer(connection, buffer, "\\partnerid\\");
		gpiAppendIntToBuffer(connection, buffer, iconnection->partnerID);
		gpiAppendStringToBuffer(connection, buffer, "\\final\\");

		iconnection->updateproBuffer.len = 0;
	}

	// Add updateui info.
	//////////////////////
	if(iconnection->updateuiBuffer.len > 0)
	{
		gpiAppendStringToBuffer(connection, buffer, "\\updateui\\\\sesskey\\");
		gpiAppendIntToBuffer(connection, buffer, iconnection->sessKey);
		gpiAppendStringToBuffer(connection, buffer, iconnection->updateuiBuffer.buffer);
		gpiAppendStringToBuffer(connection, buffer, "\\final\\");

		iconnection->updateuiBuffer.len = 0;
	}

	return GP_NO_ERROR;
}

static GPResult
gpiSendLocalInfo(
  GPConnection * connection,
  const char * info,
  const char * value
)
{
	GPIConnection * iconnection = (GPIConnection*)*connection;

	CHECK_RESULT(gpiAppendStringToBuffer(connection, &iconnection->updateproBuffer, info));
	CHECK_RESULT(gpiAppendStringToBuffer(connection, &iconnection->updateproBuffer, value));

	return GP_NO_ERROR;
}

static GPResult
gpiSendUserInfo(
  GPConnection * connection,
  const char * info,
  const char * value
)
{
	GPIConnection * iconnection = (GPIConnection*)*connection;

	CHECK_RESULT(gpiAppendStringToBuffer(connection, &iconnection->updateuiBuffer, info));
	CHECK_RESULT(gpiAppendStringToBuffer(connection, &iconnection->updateuiBuffer, value));

	return GP_NO_ERROR;
}

GPResult
gpiSetInfoi(
  GPConnection * connection, 
  GPEnum info, 
  int value
)
{
	char intValue[16];

	// Check the info param.
	////////////////////////
	switch(info)
	{
	case GP_ZIPCODE:
		// Error check.
		///////////////
		if(value < 0)
			Error(connection, GP_PARAMETER_ERROR, "Invalid zipcode.");

		// Convert it to a string.
		//////////////////////////
		sprintf(intValue,"%d",value);

		// Send it to the server.
		/////////////////////////
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\zipcode\\", intValue));

		break;

	case GP_SEX:
		// Check the sex type.
		//////////////////////
		switch(value)
		{
		case GP_MALE:
			CHECK_RESULT(gpiSendLocalInfo(connection, "\\sex\\", "0"));
			break;

		case GP_FEMALE:
			CHECK_RESULT(gpiSendLocalInfo(connection, "\\sex\\", "1"));
			break;

		case GP_PAT:
			CHECK_RESULT(gpiSendLocalInfo(connection, "\\sex\\", "2"));
			break;

		default:
			Error(connection, GP_PARAMETER_ERROR, "Invalid sex.");
		}

		break;

	case GP_ICQUIN:
		// Convert it to a string.
		//////////////////////////
		sprintf(intValue,"%d",value);

		// Send it to the server.
		/////////////////////////
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\icquin\\", intValue));

		break;
		
	case GP_CPUBRANDID:
		// Convert it to a string.
		//////////////////////////
		sprintf(intValue,"%d",value);

		// Send it to the server.
		/////////////////////////
		CHECK_RESULT(gpiSendUserInfo(connection, "\\cpubrandid\\", intValue));

		break;

	case GP_CPUSPEED:
		// Convert it to a string.
		//////////////////////////
		sprintf(intValue,"%d",value);

		// Send it to the server.
		/////////////////////////
		CHECK_RESULT(gpiSendUserInfo(connection, "\\cpuspeed\\", intValue));

		break;

	case GP_MEMORY:
		// Divide by 16.
		////////////////
		value /= 16;

		// Convert it to a string.
		//////////////////////////
		sprintf(intValue,"%d",value);

		// Send it to the server.
		/////////////////////////
		CHECK_RESULT(gpiSendUserInfo(connection, "\\memory\\", intValue));

		break;

	case GP_VIDEOCARD1RAM:
		// Divide by 4.
		///////////////
		value /= 4;

		// Convert it to a string.
		//////////////////////////
		sprintf(intValue,"%d",value);

		// Send it to the server.
		/////////////////////////
		CHECK_RESULT(gpiSendUserInfo(connection, "\\videocard1ram\\", intValue));

		break;

	case GP_VIDEOCARD2RAM:
		// Divide by 4.
		///////////////
		value /= 4;

		// Convert it to a string.
		//////////////////////////
		sprintf(intValue,"%d",value);

		// Send it to the server.
		/////////////////////////
		CHECK_RESULT(gpiSendUserInfo(connection, "\\videocard2ram\\", intValue));

		break;

	case GP_CONNECTIONID:
		// Convert it to a string.
		//////////////////////////
		sprintf(intValue,"%d",value);

		// Send it to the server.
		/////////////////////////
		CHECK_RESULT(gpiSendUserInfo(connection, "\\connectionid\\", intValue));

		break;

	case GP_CONNECTIONSPEED:
		// Convert it to a string.
		//////////////////////////
		sprintf(intValue,"%d",value);

		// Send it to the server.
		/////////////////////////
		CHECK_RESULT(gpiSendUserInfo(connection, "\\connectionspeed\\", intValue));

		break;

	case GP_HASNETWORK:
		// A boolean.
		/////////////
		if(value)
			value = 1;

		// Convert it to a string.
		//////////////////////////
		sprintf(intValue,"%d",value);

		// Send it to the server.
		/////////////////////////
		CHECK_RESULT(gpiSendUserInfo(connection, "\\hasnetwork\\", intValue));

		break;

	case GP_PIC:
		// Convert it to a string.
		//////////////////////////
		sprintf(intValue,"%d",value);

		// Send it to the server.
		/////////////////////////
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\pic\\", intValue));

		break;

	case GP_OCCUPATIONID:
		// Convert it to a string.
		//////////////////////////
		sprintf(intValue,"%d",value);

		// Send it to the server.
		/////////////////////////
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\occ\\", intValue));

		break;

	case GP_INDUSTRYID:
		// Convert it to a string.
		//////////////////////////
		sprintf(intValue,"%d",value);

		// Send it to the server.
		/////////////////////////
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\ind\\", intValue));

		break;

	case GP_INCOMEID:
		// Convert it to a string.
		//////////////////////////
		sprintf(intValue,"%d",value);

		// Send it to the server.
		/////////////////////////
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\inc\\", intValue));

		break;

	case GP_MARRIEDID:
		// Convert it to a string.
		//////////////////////////
		sprintf(intValue,"%d",value);

		// Send it to the server.
		/////////////////////////
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\mar\\", intValue));

		break;

	case GP_CHILDCOUNT:
		// Convert it to a string.
		//////////////////////////
		sprintf(intValue,"%d",value);

		// Send it to the server.
		/////////////////////////
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\chc\\", intValue));

		break;

	case GP_INTERESTS1:
		// Convert it to a string.
		//////////////////////////
		sprintf(intValue,"%d",value);

		// Send it to the server.
		/////////////////////////
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\i1\\", intValue));

		break;

	default:
		Error(connection, GP_PARAMETER_ERROR, "Invalid info.");
	}

	return GP_NO_ERROR;
}

GPResult
gpiSetInfos(
  GPConnection * connection, 
  GPEnum info, 
  const char * value
)
{
	
	GPIConnection * iconnection = (GPIConnection*)*connection;
	char buffer[256];
	char sex;
	
	//password encryption stuff
	char passwordenc[GP_PASSWORDENC_LEN];
	
	// Error check.
	///////////////
	if(value == NULL)
		Error(connection, GP_PARAMETER_ERROR, "Invalid value.");

	// Check the info param.
	////////////////////////
	switch(info)
	{
	case GP_NICK:
		if(!value[0])
			Error(connection, GP_PARAMETER_ERROR, "Invalid value.");
		strzcpy(buffer, value, GP_NICK_LEN);
		strzcpy(iconnection->nick, buffer, GP_NICK_LEN);
#ifdef GSI_UNICODE
		UTF8ToUCS2StringLen(iconnection->nick, iconnection->nick_W, GP_NICK_LEN); // update the UCS2 version
#endif
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\nick\\", buffer));
		break;

	case GP_UNIQUENICK:
		if(!value[0])
			Error(connection, GP_PARAMETER_ERROR, "Invalid value.");
		strzcpy(buffer, value, GP_UNIQUENICK_LEN);
		strzcpy(iconnection->uniquenick, buffer, GP_UNIQUENICK_LEN);
#ifdef GSI_UNICODE
		UTF8ToUCS2StringLen(iconnection->uniquenick, iconnection->uniquenick_W, GP_UNIQUENICK_LEN);
#endif
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\uniquenick\\", buffer));
		break;

	case GP_EMAIL:
		if(!value[0])
			Error(connection, GP_PARAMETER_ERROR, "Invalid value.");
		strzcpy(buffer, value, GP_EMAIL_LEN);
		_strlwr(buffer);
		strzcpy(iconnection->email, buffer, GP_EMAIL_LEN);
#ifdef GSI_UNICODE
		UTF8ToUCS2StringLen(iconnection->email, iconnection->email_W, GP_EMAIL_LEN);
#endif
		CHECK_RESULT(gpiSendUserInfo(connection, "\\email\\", buffer));
		break;

	case GP_PASSWORD:
		if(!value[0])
			Error(connection, GP_PARAMETER_ERROR, "Invalid value.");
		strzcpy(buffer, value, GP_PASSWORD_LEN);
		strzcpy(iconnection->password, buffer, GP_PASSWORD_LEN);
#ifdef GSI_UNICODE
		UTF8ToUCS2StringLen(iconnection->password, iconnection->password_W, GP_PASSWORD_LEN);
#endif
		gpiEncodeString(iconnection->password, passwordenc);
		CHECK_RESULT(gpiSendUserInfo(connection, "\\passwordenc\\", passwordenc));
		break;

	case GP_FIRSTNAME:
		strzcpy(buffer, value, GP_FIRSTNAME_LEN);
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\firstname\\", buffer));
		break;

	case GP_LASTNAME:
		strzcpy(buffer, value, GP_LASTNAME_LEN);
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\lastname\\", buffer));
		break;

	case GP_HOMEPAGE:
		strzcpy(buffer, value, GP_HOMEPAGE_LEN);
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\homepage\\", buffer));
		break;

	case GP_ZIPCODE:
		strzcpy(buffer, value, GP_ZIPCODE_LEN);
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\zipcode\\", buffer));
		break;

	case GP_COUNTRYCODE:
		// Error check.
		///////////////
		if(strlen(value) != 2)
			Error(connection, GP_PARAMETER_ERROR, "Invalid countrycode.");

		strzcpy(buffer, value, GP_COUNTRYCODE_LEN);
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\countrycode\\", buffer));
		break;

	case GP_SEX:
		sex = (char)toupper(value[0]);
		if(sex == 'M')
			strcpy(buffer, "0");
		else if(sex == 'F')
			strcpy(buffer, "1");
		else
			strcpy(buffer, "2");

		CHECK_RESULT(gpiSendLocalInfo(connection, "\\sex\\", buffer));
		break;

	case GP_ICQUIN:
		strzcpy(buffer, value, sizeof(buffer));
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\icquin\\", buffer));
		break;

	case GP_CPUSPEED:
		CHECK_RESULT(gpiSetInfoi(connection, GP_CPUSPEED, atoi(value)));
		break;

	case GP_MEMORY:
		CHECK_RESULT(gpiSetInfoi(connection, GP_MEMORY, atoi(value)));
		break;

	case GP_VIDEOCARD1STRING:
		strzcpy(buffer, value, sizeof(buffer));
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\videocard1string\\", buffer));
		break;

	case GP_VIDEOCARD1RAM:
		CHECK_RESULT(gpiSetInfoi(connection, GP_VIDEOCARD1RAM, atoi(value)));
		break;

	case GP_VIDEOCARD2STRING:
		strzcpy(buffer, value, sizeof(buffer));
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\videocard2string\\", buffer));
		break;

	case GP_VIDEOCARD2RAM:
		CHECK_RESULT(gpiSetInfoi(connection, GP_VIDEOCARD2RAM, atoi(value)));
		break;

	case GP_CONNECTIONSPEED:
		CHECK_RESULT(gpiSetInfoi(connection, GP_CONNECTIONSPEED, atoi(value)));
		break;

	case GP_HASNETWORK:
		CHECK_RESULT(gpiSetInfoi(connection, GP_HASNETWORK, atoi(value)));
		break;

	case GP_OSSTRING:
		strzcpy(buffer, value, sizeof(buffer));
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\osstring\\", buffer));
		break;

	case GP_AIMNAME:
		strzcpy(buffer, value, GP_AIMNAME_LEN);
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\aim\\", buffer));
		break;

	case GP_PIC:
		strzcpy(buffer, value, sizeof(buffer));
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\pic\\", buffer));
		break;

	case GP_OCCUPATIONID:
		strzcpy(buffer, value, sizeof(buffer));
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\occ\\", buffer));
		break;

	case GP_INDUSTRYID:
		strzcpy(buffer, value, sizeof(buffer));
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\ind\\", buffer));
		break;

	case GP_INCOMEID:
		strzcpy(buffer, value, sizeof(buffer));
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\inc\\", buffer));
		break;

	case GP_MARRIEDID:
		strzcpy(buffer, value, sizeof(buffer));
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\mar\\", buffer));
		break;

	case GP_CHILDCOUNT:
		strzcpy(buffer, value, sizeof(buffer));
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\chc\\", buffer));
		break;

	case GP_INTERESTS1:
		strzcpy(buffer, value, sizeof(buffer));
		CHECK_RESULT(gpiSendLocalInfo(connection, "\\i1\\", buffer));
		break;

	default:
		Error(connection, GP_PARAMETER_ERROR, "Invalid info.");
	}

	return GP_NO_ERROR;
}

GPResult
gpiSetInfod(
  GPConnection * connection, 
  GPEnum info, 
  int day,
  int month,
  int year
)
{
	int date;
	char intValue[16];

	// Birthday is the only date supported.
	///////////////////////////////////////
	if(info != GP_BIRTHDAY)
		Error(connection, GP_PARAMETER_ERROR, "Invalid info.");

	// Convert the date into our internal format.
	/////////////////////////////////////////////
	CHECK_RESULT(gpiDateToInt(connection, &date, day, month, year));

	// Convert the int to a string.
	///////////////////////////////
	sprintf(intValue,"%d",date);

	// Send the date.
	/////////////////
	CHECK_RESULT(gpiSendLocalInfo(connection, "\\birthday\\", intValue));

	return GP_NO_ERROR;
}

GPResult
gpiSetInfoMask(
  GPConnection * connection, 
  GPEnum mask
)
{
	char buffer[16];

	// Convert the mask to a string.
	////////////////////////////////
	sprintf(buffer,"%d",mask);

	// Send it.
	///////////
	CHECK_RESULT(gpiSendLocalInfo(connection, "\\publicmask\\", buffer));

	return GP_NO_ERROR;

}

GPResult
gpiSendGetInfo(
  GPConnection * connection,
  int profileid,
  int operationid
)
{
	GPIConnection * iconnection = (GPIConnection*)*connection;

	gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\getprofile\\\\sesskey\\");
	gpiAppendIntToBuffer(connection, &iconnection->outputBuffer, iconnection->sessKey);
	gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\profileid\\");
	gpiAppendIntToBuffer(connection, &iconnection->outputBuffer, profileid);
	gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\id\\");
	gpiAppendIntToBuffer(connection, &iconnection->outputBuffer, operationid);
	gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\final\\");
	
	return GP_NO_ERROR;
}

GPResult
gpiGetInfo(
  GPConnection * connection,
  GPProfile profile, 
  GPEnum checkCache,
  GPEnum blocking,
  GPCallback callback,
  void * param
)
{
	GPIProfile * pProfile;
	GPIConnection * iconnection = (GPIConnection*)*connection;
	GPIOperation * operation = NULL;
	GPIBool useCache;
	GPResult result;
	int id;

	// Check checkCache.
	////////////////////
	useCache = (checkCache == GP_CHECK_CACHE) ? GPITrue:GPIFalse;

	// Check the info cache state.
	//////////////////////////////
	if(!iconnection->infoCaching)
		useCache = GPIFalse;

	// Check for using cached info.
	///////////////////////////////
	if(callback && useCache && gpiGetProfile(connection, profile, &pProfile) && pProfile->cache)
	{
		GPICallback gpiCallback;
		GPGetInfoResponseArg * arg;

		arg = (GPGetInfoResponseArg *)gsimalloc(sizeof(GPGetInfoResponseArg));
		if(arg == NULL)
			Error(connection, GP_MEMORY_ERROR, "Out of memory.");

		gpiInfoCacheToArg(pProfile->cache, arg);
		arg->result = GP_NO_ERROR;
		arg->profile = profile;
		
		gpiCallback.callback = callback;
		gpiCallback.param = param;

		// Add a dummy operation.
		/////////////////////////
		CHECK_RESULT(gpiAddOperation(connection, GPI_GET_INFO, NULL, &operation, GP_BLOCKING, callback, param));
		id = operation->id;

		// Add the callback.
		////////////////////
		CHECK_RESULT(gpiAddCallback(connection, gpiCallback, arg, operation, 0));

		// Remove the dummy operation.
		//////////////////////////////
		gpiRemoveOperation(connection, operation);
	}
	else
	{
		// Add the operation.
		/////////////////////
		CHECK_RESULT(gpiAddOperation(connection, GPI_GET_INFO, NULL, &operation, blocking, callback, param));
		id = operation->id;

		// Send a request for info.
		///////////////////////////
		result = gpiSendGetInfo(connection, profile, operation->id);
		CHECK_RESULT(result);
	}

	// Process it if blocking.
	//////////////////////////
	if(blocking)
	{
		result = gpiProcess(connection, id);
		CHECK_RESULT(result);
	}

	return GP_NO_ERROR;
}

GPResult
gpiGetInfoNoWait(
  GPConnection * connection,
  GPProfile profile,
  GPGetInfoResponseArg * arg
)
{
	GPIProfile * pProfile;
	GPIConnection * iconnection = (GPIConnection*)*connection;

	// Check the info cache state.
	//////////////////////////////
	if(!iconnection->infoCaching)
		return GP_NETWORK_ERROR;

	// Check to see if we have the info cached.
	///////////////////////////////////////////
	if(!gpiGetProfile(connection, profile, &pProfile) || !pProfile->cache)
		return GP_NETWORK_ERROR;

	// Fill in the arg.
	///////////////////
	gpiInfoCacheToArg(pProfile->cache, arg);
	arg->result = GP_NO_ERROR;
	arg->profile = profile;

	return GP_NO_ERROR;
}

GPIBool
gpiSetInfoCache(
  GPConnection * connection,
  pGPIProfile  profile,
  const GPIInfoCache * cache
)
{
	GPIConnection * iconnection = (GPIConnection*)*connection;

	// Check if we're caching info.
	///////////////////////////////
	if(!iconnection->infoCaching)
		return GPITrue;

	// Free any old cached info.
	////////////////////////////
	gpiFreeInfoCache(profile);

	// Allocate the new info.
	/////////////////////////
	profile->cache = (GPIInfoCache *)gsimalloc(sizeof(GPIInfoCache));

	// Copy in the new info.
	////////////////////////
	if(profile->cache)
	{
		*profile->cache = *cache;
		profile->cache->nick = goastrdup(cache->nick);
		profile->cache->uniquenick = goastrdup(cache->uniquenick);
		profile->cache->email = goastrdup(cache->email);
		profile->cache->firstname = goastrdup(cache->firstname);
		profile->cache->lastname = goastrdup(cache->lastname);
		profile->cache->homepage = goastrdup(cache->homepage);
		profile->cache->aimname = goastrdup(cache->aimname);
	}

	return (profile->cache != NULL) ? GPITrue:GPIFalse;
}

void
gpiFreeInfoCache(
  pGPIProfile  profile
)
{
	if(!profile->cache)
		return;
	
	freeclear(profile->cache->nick);
	freeclear(profile->cache->uniquenick);
	freeclear(profile->cache->email);
	freeclear(profile->cache->firstname);
	freeclear(profile->cache->lastname);
	freeclear(profile->cache->homepage);
	freeclear(profile->cache->aimname);
	freeclear(profile->cache);
}