forked from aglasgall/barnowl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicq.c
684 lines (545 loc) · 18.7 KB
/
icq.c
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
/*
* Family 0x0015 - Encapsulated ICQ.
*
*/
#define FAIM_INTERNAL
#include <aim.h>
faim_export int aim_icq_reqofflinemsgs(aim_session_t *sess)
{
aim_conn_t *conn;
aim_frame_t *fr;
aim_snacid_t snacid;
int bslen;
if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015)))
return -EINVAL;
bslen = 2 + 4 + 2 + 2;
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
return -ENOMEM;
snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0);
aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid);
/* For simplicity, don't bother using a tlvlist */
aimbs_put16(&fr->data, 0x0001);
aimbs_put16(&fr->data, bslen);
aimbs_putle16(&fr->data, bslen - 2);
aimbs_putle32(&fr->data, atoi(sess->sn));
aimbs_putle16(&fr->data, 0x003c); /* I command thee. */
aimbs_putle16(&fr->data, snacid); /* eh. */
aim_tx_enqueue(sess, fr);
return 0;
}
faim_export int aim_icq_ackofflinemsgs(aim_session_t *sess)
{
aim_conn_t *conn;
aim_frame_t *fr;
aim_snacid_t snacid;
int bslen;
if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015)))
return -EINVAL;
bslen = 2 + 4 + 2 + 2;
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
return -ENOMEM;
snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0);
aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid);
/* For simplicity, don't bother using a tlvlist */
aimbs_put16(&fr->data, 0x0001);
aimbs_put16(&fr->data, bslen);
aimbs_putle16(&fr->data, bslen - 2);
aimbs_putle32(&fr->data, atoi(sess->sn));
aimbs_putle16(&fr->data, 0x003e); /* I command thee. */
aimbs_putle16(&fr->data, snacid); /* eh. */
aim_tx_enqueue(sess, fr);
return 0;
}
faim_export int aim_icq_hideip(aim_session_t *sess)
{
aim_conn_t *conn;
aim_frame_t *fr;
aim_snacid_t snacid;
int bslen;
if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015)))
return -EINVAL;
bslen = 2+4+2+2+2+4;
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
return -ENOMEM;
snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0);
aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid);
/* For simplicity, don't bother using a tlvlist */
aimbs_put16(&fr->data, 0x0001);
aimbs_put16(&fr->data, bslen);
aimbs_putle16(&fr->data, bslen - 2);
aimbs_putle32(&fr->data, atoi(sess->sn));
aimbs_putle16(&fr->data, 0x07d0); /* I command thee. */
aimbs_putle16(&fr->data, snacid); /* eh. */
aimbs_putle16(&fr->data, 0x0424); /* shrug. */
aimbs_putle16(&fr->data, 0x0001);
aimbs_putle16(&fr->data, 0x0001);
aim_tx_enqueue(sess, fr);
return 0;
}
/**
* Change your ICQ password.
*
* @param sess The oscar session
* @param passwd The new password. If this is longer than 8 characters it
* will be truncated.
* @return Return 0 if no errors, otherwise return the error number.
*/
faim_export int aim_icq_changepasswd(aim_session_t *sess, const char *passwd)
{
aim_conn_t *conn;
aim_frame_t *fr;
aim_snacid_t snacid;
int bslen, passwdlen;
if (!passwd)
return -EINVAL;
if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015)))
return -EINVAL;
passwdlen = strlen(passwd);
if (passwdlen > MAXICQPASSLEN)
passwdlen = MAXICQPASSLEN;
bslen = 2+4+2+2+2+2+passwdlen+1;
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
return -ENOMEM;
snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0);
aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid);
/* For simplicity, don't bother using a tlvlist */
aimbs_put16(&fr->data, 0x0001);
aimbs_put16(&fr->data, bslen);
aimbs_putle16(&fr->data, bslen - 2);
aimbs_putle32(&fr->data, atoi(sess->sn));
aimbs_putle16(&fr->data, 0x07d0); /* I command thee. */
aimbs_putle16(&fr->data, snacid); /* eh. */
aimbs_putle16(&fr->data, 0x042e); /* shrug. */
aimbs_putle16(&fr->data, passwdlen+1);
aimbs_putraw(&fr->data, passwd, passwdlen);
aimbs_putle8(&fr->data, '\0');
aim_tx_enqueue(sess, fr);
return 0;
}
faim_export int aim_icq_getallinfo(aim_session_t *sess, const char *uin)
{
aim_conn_t *conn;
aim_frame_t *fr;
aim_snacid_t snacid;
int bslen;
struct aim_icq_info *info;
if (!uin || uin[0] < '0' || uin[0] > '9')
return -EINVAL;
if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015)))
return -EINVAL;
bslen = 2 + 4 + 2 + 2 + 2 + 4;
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
return -ENOMEM;
snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0);
aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid);
/* For simplicity, don't bother using a tlvlist */
aimbs_put16(&fr->data, 0x0001);
aimbs_put16(&fr->data, bslen);
aimbs_putle16(&fr->data, bslen - 2);
aimbs_putle32(&fr->data, atoi(sess->sn));
aimbs_putle16(&fr->data, 0x07d0); /* I command thee. */
aimbs_putle16(&fr->data, snacid); /* eh. */
aimbs_putle16(&fr->data, 0x04b2); /* shrug. */
aimbs_putle32(&fr->data, atoi(uin));
aim_tx_enqueue(sess, fr);
/* Keep track of this request and the ICQ number and request ID */
info = (struct aim_icq_info *)calloc(1, sizeof(struct aim_icq_info));
info->reqid = snacid;
info->uin = atoi(uin);
info->next = sess->icq_info;
sess->icq_info = info;
return 0;
}
faim_export int aim_icq_getalias(aim_session_t *sess, const char *uin)
{
aim_conn_t *conn;
aim_frame_t *fr;
aim_snacid_t snacid;
int bslen;
struct aim_icq_info *info;
if (!uin || uin[0] < '0' || uin[0] > '9')
return -EINVAL;
if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015)))
return -EINVAL;
bslen = 2 + 4 + 2 + 2 + 2 + 4;
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
return -ENOMEM;
snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0);
aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid);
/* For simplicity, don't bother using a tlvlist */
aimbs_put16(&fr->data, 0x0001);
aimbs_put16(&fr->data, bslen);
aimbs_putle16(&fr->data, bslen - 2);
aimbs_putle32(&fr->data, atoi(sess->sn));
aimbs_putle16(&fr->data, 0x07d0); /* I command thee. */
aimbs_putle16(&fr->data, snacid); /* eh. */
aimbs_putle16(&fr->data, 0x04ba); /* shrug. */
aimbs_putle32(&fr->data, atoi(uin));
aim_tx_enqueue(sess, fr);
/* Keep track of this request and the ICQ number and request ID */
info = (struct aim_icq_info *)calloc(1, sizeof(struct aim_icq_info));
info->reqid = snacid;
info->uin = atoi(uin);
info->next = sess->icq_info;
sess->icq_info = info;
return 0;
}
faim_export int aim_icq_getsimpleinfo(aim_session_t *sess, const char *uin)
{
aim_conn_t *conn;
aim_frame_t *fr;
aim_snacid_t snacid;
int bslen;
if (!uin || uin[0] < '0' || uin[0] > '9')
return -EINVAL;
if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015)))
return -EINVAL;
bslen = 2 + 4 + 2 + 2 + 2 + 4;
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
return -ENOMEM;
snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0);
aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid);
/* For simplicity, don't bother using a tlvlist */
aimbs_put16(&fr->data, 0x0001);
aimbs_put16(&fr->data, bslen);
aimbs_putle16(&fr->data, bslen - 2);
aimbs_putle32(&fr->data, atoi(sess->sn));
aimbs_putle16(&fr->data, 0x07d0); /* I command thee. */
aimbs_putle16(&fr->data, snacid); /* eh. */
aimbs_putle16(&fr->data, 0x051f); /* shrug. */
aimbs_putle32(&fr->data, atoi(uin));
aim_tx_enqueue(sess, fr);
return 0;
}
faim_export int aim_icq_sendxmlreq(aim_session_t *sess, const char *xml)
{
aim_conn_t *conn;
aim_frame_t *fr;
aim_snacid_t snacid;
int bslen;
if (!xml || !strlen(xml))
return -EINVAL;
if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015)))
return -EINVAL;
bslen = 2 + 10 + 2 + strlen(xml) + 1;
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen)))
return -ENOMEM;
snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0);
aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid);
/* For simplicity, don't bother using a tlvlist */
aimbs_put16(&fr->data, 0x0001);
aimbs_put16(&fr->data, bslen);
aimbs_putle16(&fr->data, bslen - 2);
aimbs_putle32(&fr->data, atoi(sess->sn));
aimbs_putle16(&fr->data, 0x07d0); /* I command thee. */
aimbs_putle16(&fr->data, snacid); /* eh. */
aimbs_putle16(&fr->data, 0x0998); /* shrug. */
aimbs_putle16(&fr->data, strlen(xml) + 1);
aimbs_putraw(&fr->data, xml, strlen(xml) + 1);
aim_tx_enqueue(sess, fr);
return 0;
}
/*
* Send an SMS message. This is the non-US way. The US-way is to IM
* their cell phone number (+19195551234).
*
* We basically construct and send an XML message. The format is:
* <icq_sms_message>
* <destination>full_phone_without_leading_+</destination>
* <text>message</text>
* <codepage>1252</codepage>
* <senders_UIN>self_uin</senders_UIN>
* <senders_name>self_name</senders_name>
* <delivery_receipt>Yes|No</delivery_receipt>
* <time>Wkd, DD Mmm YYYY HH:MM:SS TMZ</time>
* </icq_sms_message>
*
* Yeah hi Peter, whaaaat's happening. If there's any way to use
* a codepage other than 1252 that would be great. Thaaaanks.
*/
faim_export int aim_icq_sendsms(aim_session_t *sess, const char *name, const char *msg, const char *alias)
{
aim_conn_t *conn;
aim_frame_t *fr;
aim_snacid_t snacid;
int bslen, xmllen;
char *xml, timestr[30];
time_t t;
struct tm *tm;
if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015)))
return -EINVAL;
if (!name || !msg || !alias)
return -EINVAL;
time(&t);
tm = gmtime(&t);
strftime(timestr, 30, "%a, %d %b %Y %T %Z", tm);
/* The length of xml included the null terminating character */
xmllen = 225 + strlen(name) + strlen(msg) + strlen(sess->sn) + strlen(alias) + strlen(timestr) + 1;
if (!(xml = (char *)malloc(xmllen*sizeof(char))))
return -ENOMEM;
snprintf(xml, xmllen, "<icq_sms_message>\n"
"\t<destination>%s</destination>\n"
"\t<text>%s</text>\n"
"\t<codepage>1252</codepage>\n"
"\t<senders_UIN>%s</senders_UIN>\n"
"\t<senders_name>%s</senders_name>\n"
"\t<delivery_receipt>Yes</delivery_receipt>\n"
"\t<time>%s</time>\n"
"</icq_sms_message>\n",
name, msg, sess->sn, alias, timestr);
bslen = 37 + xmllen;
if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen))) {
free(xml);
return -ENOMEM;
}
snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0);
aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid);
/* For simplicity, don't bother using a tlvlist */
aimbs_put16(&fr->data, 0x0001);
aimbs_put16(&fr->data, bslen);
aimbs_putle16(&fr->data, bslen - 2);
aimbs_putle32(&fr->data, atoi(sess->sn));
aimbs_putle16(&fr->data, 0x07d0); /* I command thee. */
aimbs_putle16(&fr->data, snacid); /* eh. */
/* From libicq200-0.3.2/src/SNAC-SRV.cpp */
aimbs_putle16(&fr->data, 0x8214);
aimbs_put16(&fr->data, 0x0001);
aimbs_put16(&fr->data, 0x0016);
aimbs_put32(&fr->data, 0x00000000);
aimbs_put32(&fr->data, 0x00000000);
aimbs_put32(&fr->data, 0x00000000);
aimbs_put32(&fr->data, 0x00000000);
aimbs_put16(&fr->data, 0x0000);
aimbs_put16(&fr->data, xmllen);
aimbs_putraw(&fr->data, xml, xmllen);
aim_tx_enqueue(sess, fr);
free(xml);
return 0;
}
static void aim_icq_freeinfo(struct aim_icq_info *info) {
int i;
if (!info)
return;
free(info->nick);
free(info->first);
free(info->last);
free(info->email);
free(info->homecity);
free(info->homestate);
free(info->homephone);
free(info->homefax);
free(info->homeaddr);
free(info->mobile);
free(info->homezip);
free(info->personalwebpage);
if (info->email2)
for (i = 0; i < info->numaddresses; i++)
free(info->email2[i]);
free(info->email2);
free(info->workcity);
free(info->workstate);
free(info->workphone);
free(info->workfax);
free(info->workaddr);
free(info->workzip);
free(info->workcompany);
free(info->workdivision);
free(info->workposition);
free(info->workwebpage);
free(info->info);
free(info);
}
/**
* Subtype 0x0003 - Response to 0x0015/0x002, contains an ICQesque packet.
*/
static int icqresponse(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
{
int ret = 0;
aim_tlvlist_t *tl;
aim_tlv_t *datatlv;
aim_bstream_t qbs;
fu32_t ouruin;
fu16_t cmdlen, cmd, reqid;
if (!(tl = aim_tlvlist_read(bs)) || !(datatlv = aim_tlv_gettlv(tl, 0x0001, 1))) {
aim_tlvlist_free(&tl);
faimdprintf(sess, 0, "corrupt ICQ response\n");
return 0;
}
aim_bstream_init(&qbs, datatlv->value, datatlv->length);
cmdlen = aimbs_getle16(&qbs);
ouruin = aimbs_getle32(&qbs);
cmd = aimbs_getle16(&qbs);
reqid = aimbs_getle16(&qbs);
faimdprintf(sess, 1, "icq response: %d bytes, %ld, 0x%04x, 0x%04x\n", cmdlen, ouruin, cmd, reqid);
if (cmd == 0x0041) { /* offline message */
struct aim_icq_offlinemsg msg;
aim_rxcallback_t userfunc;
memset(&msg, 0, sizeof(msg));
msg.sender = aimbs_getle32(&qbs);
msg.year = aimbs_getle16(&qbs);
msg.month = aimbs_getle8(&qbs);
msg.day = aimbs_getle8(&qbs);
msg.hour = aimbs_getle8(&qbs);
msg.minute = aimbs_getle8(&qbs);
msg.type = aimbs_getle8(&qbs);
msg.flags = aimbs_getle8(&qbs);
msg.msglen = aimbs_getle16(&qbs);
msg.msg = aimbs_getstr(&qbs, msg.msglen);
if ((userfunc = aim_callhandler(sess, rx->conn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSG)))
ret = userfunc(sess, rx, &msg);
free(msg.msg);
} else if (cmd == 0x0042) {
aim_rxcallback_t userfunc;
if ((userfunc = aim_callhandler(sess, rx->conn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSGCOMPLETE)))
ret = userfunc(sess, rx);
} else if (cmd == 0x07da) { /* information */
fu16_t subtype;
struct aim_icq_info *info;
aim_rxcallback_t userfunc;
subtype = aimbs_getle16(&qbs);
aim_bstream_advance(&qbs, 1); /* 0x0a */
/* find other data from the same request */
for (info = sess->icq_info; info && (info->reqid != reqid); info = info->next);
if (!info) {
info = (struct aim_icq_info *)calloc(1, sizeof(struct aim_icq_info));
info->reqid = reqid;
info->next = sess->icq_info;
sess->icq_info = info;
}
switch (subtype) {
case 0x00a0: { /* hide ip status */
/* nothing */
} break;
case 0x00aa: { /* password change status */
/* nothing */
} break;
case 0x00c8: { /* general and "home" information */
info->nick = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->first = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->last = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->email = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->homecity = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->homestate = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->homephone = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->homefax = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->homeaddr = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->mobile = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->homezip = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->homecountry = aimbs_getle16(&qbs);
/* 0x0a 00 02 00 */
/* 1 byte timezone? */
/* 1 byte hide email flag? */
} break;
case 0x00dc: { /* personal information */
info->age = aimbs_getle8(&qbs);
info->unknown = aimbs_getle8(&qbs);
info->gender = aimbs_getle8(&qbs);
info->personalwebpage = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->birthyear = aimbs_getle16(&qbs);
info->birthmonth = aimbs_getle8(&qbs);
info->birthday = aimbs_getle8(&qbs);
info->language1 = aimbs_getle8(&qbs);
info->language2 = aimbs_getle8(&qbs);
info->language3 = aimbs_getle8(&qbs);
/* 0x00 00 01 00 00 01 00 00 00 00 00 */
} break;
case 0x00d2: { /* work information */
info->workcity = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->workstate = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->workphone = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->workfax = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->workaddr = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->workzip = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->workcountry = aimbs_getle16(&qbs);
info->workcompany = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->workdivision = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->workposition = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
aim_bstream_advance(&qbs, 2); /* 0x01 00 */
info->workwebpage = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
} break;
case 0x00e6: { /* additional personal information */
info->info = aimbs_getstr(&qbs, aimbs_getle16(&qbs)-1);
} break;
case 0x00eb: { /* email address(es) */
int i;
info->numaddresses = aimbs_getle16(&qbs);
info->email2 = (char **)calloc(info->numaddresses, sizeof(char *));
for (i = 0; i < info->numaddresses; i++) {
info->email2[i] = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
if (i+1 != info->numaddresses)
aim_bstream_advance(&qbs, 1); /* 0x00 */
}
} break;
case 0x00f0: { /* personal interests */
} break;
case 0x00fa: { /* past background and current organizations */
} break;
case 0x0104: { /* alias info */
info->nick = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->first = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->last = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
aim_bstream_advance(&qbs, aimbs_getle16(&qbs)); /* email address? */
/* Then 0x00 02 00 */
} break;
case 0x010e: { /* unknown */
/* 0x00 00 */
} break;
case 0x019a: { /* simple info */
aim_bstream_advance(&qbs, 2);
info->uin = aimbs_getle32(&qbs);
info->nick = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->first = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->last = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
info->email = aimbs_getstr(&qbs, aimbs_getle16(&qbs));
/* Then 0x00 02 00 00 00 00 00 */
} break;
} /* End switch statement */
if (!(snac->flags & 0x0001)) {
if (subtype != 0x0104)
if ((userfunc = aim_callhandler(sess, rx->conn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_INFO)))
ret = userfunc(sess, rx, info);
if (info->uin && info->nick)
if ((userfunc = aim_callhandler(sess, rx->conn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_ALIAS)))
ret = userfunc(sess, rx, info);
if (sess->icq_info == info) {
sess->icq_info = info->next;
} else {
struct aim_icq_info *cur;
for (cur=sess->icq_info; (cur->next && (cur->next!=info)); cur=cur->next);
if (cur->next)
cur->next = cur->next->next;
}
aim_icq_freeinfo(info);
}
}
aim_tlvlist_free(&tl);
return ret;
}
static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
{
if (snac->subtype == 0x0003)
return icqresponse(sess, mod, rx, snac, bs);
return 0;
}
static void icq_shutdown(aim_session_t *sess, aim_module_t *mod)
{
struct aim_icq_info *del;
while (sess->icq_info) {
del = sess->icq_info;
sess->icq_info = sess->icq_info->next;
aim_icq_freeinfo(del);
}
return;
}
faim_internal int icq_modfirst(aim_session_t *sess, aim_module_t *mod)
{
mod->family = 0x0015;
mod->version = 0x0001;
mod->toolid = 0x0110;
mod->toolversion = 0x047c;
mod->flags = 0;
strncpy(mod->name, "icq", sizeof(mod->name));
mod->snachandler = snachandler;
mod->shutdown = icq_shutdown;
return 0;
}