]> andersk Git - libfaim.git/blame - src/im.c
- Mon Sep 3 18:48:26 PDT 2001
[libfaim.git] / src / im.c
CommitLineData
9de3ca7e 1/*
2 * aim_im.c
3 *
4 * The routines for sending/receiving Instant Messages.
5 *
6ae3c48d 6 * Note the term ICBM (Inter-Client Basic Message) which blankets
7 * all types of genericly routed through-server messages. Within
8 * the ICBM types (family 4), a channel is defined. Each channel
9 * represents a different type of message. Channel 1 is used for
10 * what would commonly be called an "instant message". Channel 2
11 * is used for negotiating "rendezvous". These transactions end in
12 * something more complex happening, such as a chat invitation, or
13 * a file transfer.
14 *
15 * In addition to the channel, every ICBM contains a cookie. For
16 * standard IMs, these are only used for error messages. However,
17 * the more complex rendezvous messages make suitably more complex
18 * use of this field.
19 *
9de3ca7e 20 */
21
37ee990e 22#define FAIM_INTERNAL
dd60ff8b 23#include <aim.h>
9de3ca7e 24
9d83220c 25/*
26 * Takes a msghdr (and a length) and returns a client type
27 * code. Note that this is *only a guess* and has a low likelihood
28 * of actually being accurate.
29 *
30 * Its based on experimental data, with the help of Eric Warmenhoven
31 * who seems to have collected a wide variety of different AIM clients.
32 *
33 *
34 * Heres the current collection:
35 * 0501 0003 0101 0101 01 AOL Mobile Communicator, WinAIM 1.0.414
36 * 0501 0003 0101 0201 01 WinAIM 2.0.847, 2.1.1187, 3.0.1464,
37 * 4.3.2229, 4.4.2286
38 * 0501 0004 0101 0102 0101 WinAIM 4.1.2010, libfaim (right here)
39 * 0501 0001 0101 01 AOL v6.0, CompuServe 2000 v6.0, any
40 * TOC client
d410cf58 41 *
42 * Note that in this function, only the feature bytes are tested, since
43 * the rest will always be the same.
44 *
9d83220c 45 */
d410cf58 46faim_export fu16_t aim_fingerprintclient(fu8_t *msghdr, int len)
9d83220c 47{
6ae3c48d 48 static const struct {
d410cf58 49 fu16_t clientid;
6ae3c48d 50 int len;
d410cf58 51 fu8_t data[10];
6ae3c48d 52 } fingerprints[] = {
53 /* AOL Mobile Communicator, WinAIM 1.0.414 */
54 { AIM_CLIENTTYPE_MC,
d410cf58 55 3, {0x01, 0x01, 0x01}},
6ae3c48d 56
57 /* WinAIM 2.0.847, 2.1.1187, 3.0.1464, 4.3.2229, 4.4.2286 */
58 { AIM_CLIENTTYPE_WINAIM,
d410cf58 59 3, {0x01, 0x01, 0x02}},
6ae3c48d 60
61 /* WinAIM 4.1.2010, libfaim */
62 { AIM_CLIENTTYPE_WINAIM41,
d410cf58 63 4, {0x01, 0x01, 0x01, 0x02}},
6ae3c48d 64
65 /* AOL v6.0, CompuServe 2000 v6.0, any TOC client */
66 { AIM_CLIENTTYPE_AOL_TOC,
d410cf58 67 1, {0x01}},
6ae3c48d 68
69 { 0, 0}
70 };
71 int i;
72
73 if (!msghdr || (len <= 0))
74 return AIM_CLIENTTYPE_UNKNOWN;
75
76 for (i = 0; fingerprints[i].len; i++) {
77 if (fingerprints[i].len != len)
78 continue;
79 if (memcmp(fingerprints[i].data, msghdr, fingerprints[i].len) == 0)
80 return fingerprints[i].clientid;
81 }
82
83 return AIM_CLIENTTYPE_UNKNOWN;
9d83220c 84}
85
50038c74 86/* This should be endian-safe now... but who knows... */
d410cf58 87faim_export fu16_t aim_iconsum(const fu8_t *buf, int buflen)
50038c74 88{
d410cf58 89 fu32_t sum;
6ae3c48d 90 int i;
50038c74 91
6ae3c48d 92 for (i = 0, sum = 0; i < buflen; i += 2)
93 sum += (buf[i+1] << 8) + buf[i];
50038c74 94
6ae3c48d 95 sum = ((sum & 0xffff0000) >> 16) + (sum & 0x0000ffff);
50038c74 96
6ae3c48d 97 return sum & 0xffff;
50038c74 98}
99
9de3ca7e 100/*
101 * Send an ICBM (instant message).
102 *
103 *
104 * Possible flags:
105 * AIM_IMFLAGS_AWAY -- Marks the message as an autoresponse
106 * AIM_IMFLAGS_ACK -- Requests that the server send an ack
107 * when the message is received (of type 0x0004/0x000c)
7b91722d 108 * AIM_IMFLAGS_UNICODE--Instead of ASCII7, the passed message is
109 * made up of UNICODE duples. If you set
110 * this, you'd better be damn sure you know
111 * what you're doing.
112 * AIM_IMFLAGS_ISO_8859_1 -- The message contains the ASCII8 subset
113 * known as ISO-8859-1.
114 *
115 * Generally, you should use the lowest encoding possible to send
116 * your message. If you only use basic punctuation and the generic
117 * Latin alphabet, use ASCII7 (no flags). If you happen to use non-ASCII7
118 * characters, but they are all clearly defined in ISO-8859-1, then
119 * use that. Keep in mind that not all characters in the PC ASCII8
120 * character set are defined in the ISO standard. For those cases (most
121 * notably when the (r) symbol is used), you must use the full UNICODE
122 * encoding for your message. In UNICODE mode, _all_ characters must
123 * occupy 16bits, including ones that are not special. (Remember that
124 * the first 128 UNICODE symbols are equivelent to ASCII7, however they
125 * must be prefixed with a zero high order byte.)
126 *
127 * I strongly discourage the use of UNICODE mode, mainly because none
128 * of the clients I use can parse those messages (and besides that,
129 * wchars are difficult and non-portable to handle in most UNIX environments).
130 * If you really need to include special characters, use the HTML UNICODE
131 * entities. These are of the form &#2026; where 2026 is the hex
132 * representation of the UNICODE index (in this case, UNICODE
133 * "Horizontal Ellipsis", or 133 in in ASCII8).
9de3ca7e 134 *
d410cf58 135 * Implementation note: Since this is one of the most-used functions
136 * in all of libfaim, it is written with performance in mind. As such,
137 * it is not as clear as it could be in respect to how this message is
138 * supposed to be layed out. Most obviously, tlvlists should be used
139 * instead of writing out the bytes manually.
140 *
141 * XXX support multipart
142 *
9de3ca7e 143 */
d410cf58 144faim_export int aim_send_im_ext(aim_session_t *sess, aim_conn_t *conn, struct aim_sendimext_args *args)
a2244dd9 145{
d410cf58 146 int i;
147 aim_frame_t *fr;
148 aim_snacid_t snacid;
2d5fd943 149
150 if (!sess || !conn || !args)
d410cf58 151 return -EINVAL;
2d5fd943 152
153 if (!args->msg || (args->msglen <= 0))
154 return -EINVAL;
155
156 if (args->msglen >= MAXMSGLEN)
157 return -E2BIG;
158
d410cf58 159 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, args->msglen+512)))
2d5fd943 160 return -ENOMEM;
161
d410cf58 162 /* XXX should be optional */
163 snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, args->destsn, strlen(args->destsn)+1);
164 aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid);
2d5fd943 165
166 /*
167 * Generate a random message cookie
168 *
169 * We could cache these like we do SNAC IDs. (In fact, it
170 * might be a good idea.) In the message error functions,
171 * the 8byte message cookie is returned as well as the
172 * SNAC ID.
173 *
174 */
d410cf58 175 for (i = 0; i < 8; i++)
176 aimbs_put8(&fr->data, (fu8_t) rand());
2d5fd943 177
178 /*
179 * Channel ID
180 */
d410cf58 181 aimbs_put16(&fr->data, 0x0001);
2d5fd943 182
183 /*
184 * Destination SN (prepended with byte length)
185 */
d410cf58 186 aimbs_put8(&fr->data, strlen(args->destsn));
187 aimbs_putraw(&fr->data, args->destsn, strlen(args->destsn));
2d5fd943 188
189 /*
190 * metaTLV start.
191 */
d410cf58 192 aimbs_put16(&fr->data, 0x0002);
193 aimbs_put16(&fr->data, args->msglen + 0x10);
2d5fd943 194
195 /*
196 * Flag data / ICBM Parameters?
197 *
198 * I don't know what these are...
199 *
200 */
d410cf58 201 aimbs_put8(&fr->data, 0x05);
202 aimbs_put8(&fr->data, 0x01);
2d5fd943 203
204 /* number of bytes to follow */
d410cf58 205 aimbs_put16(&fr->data, 0x0004);
206 aimbs_put8(&fr->data, 0x01);
207 aimbs_put8(&fr->data, 0x01);
208 aimbs_put8(&fr->data, 0x01);
209 aimbs_put8(&fr->data, 0x02);
2d5fd943 210
d410cf58 211 aimbs_put16(&fr->data, 0x0101);
2d5fd943 212
213 /*
214 * Message block length.
215 */
d410cf58 216 aimbs_put16(&fr->data, args->msglen + 0x04);
2d5fd943 217
218 /*
219 * Character set.
220 */
221 if (args->flags & AIM_IMFLAGS_UNICODE)
d410cf58 222 aimbs_put16(&fr->data, 0x0002);
2d5fd943 223 else if (args->flags & AIM_IMFLAGS_ISO_8859_1)
d410cf58 224 aimbs_put16(&fr->data, 0x0003);
2d5fd943 225 else
d410cf58 226 aimbs_put16(&fr->data, 0x0000);
2d5fd943 227
d410cf58 228 aimbs_put16(&fr->data, 0x0000);
2d5fd943 229
230 /*
231 * Message. Not terminated.
232 */
d410cf58 233 aimbs_putraw(&fr->data, args->msg, args->msglen);
2d5fd943 234
235 /*
236 * Set the Request Acknowledge flag.
237 */
238 if (args->flags & AIM_IMFLAGS_ACK) {
d410cf58 239 aimbs_put16(&fr->data, 0x0003);
240 aimbs_put16(&fr->data, 0x0000);
2d5fd943 241 }
d410cf58 242
2d5fd943 243 /*
244 * Set the Autoresponse flag.
245 */
246 if (args->flags & AIM_IMFLAGS_AWAY) {
d410cf58 247 aimbs_put16(&fr->data, 0x0004);
248 aimbs_put16(&fr->data, 0x0000);
2d5fd943 249 }
250
251 /*
252 * Set the Buddy Icon Requested flag.
253 */
254 if (args->flags & AIM_IMFLAGS_BUDDYREQ) {
d410cf58 255 aimbs_put16(&fr->data, 0x0009);
256 aimbs_put16(&fr->data, 0x0000);
2d5fd943 257 }
258
259 /*
d410cf58 260 * Set the I HAVE A REALLY PURTY ICON flag.
2d5fd943 261 */
262 if (args->flags & AIM_IMFLAGS_HASICON) {
d410cf58 263 aimbs_put16(&fr->data, 0x0009);
264 aimbs_put16(&fr->data, 0x000c);
265 aimbs_put32(&fr->data, args->iconlen);
266 aimbs_put16(&fr->data, 0x0001); /* XXX is this right?! */
267 aimbs_put16(&fr->data, args->iconsum);
268 aimbs_put32(&fr->data, args->iconstamp);
2d5fd943 269 }
270
d410cf58 271 aim_tx_enqueue(sess, fr);
49c8a2fa 272
7b91722d 273#if 1 /* XXX do this with autoconf or something... */
2d5fd943 274 aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */
7b91722d 275#endif
9de3ca7e 276
2d5fd943 277 return 0;
9de3ca7e 278}
279
7b91722d 280/*
281 * Simple wrapper for aim_send_im_ext()
282 *
283 * You cannot use aim_send_im if you need the HASICON flag. You must
284 * use aim_send_im_ext directly for that.
285 *
286 * aim_send_im also cannot be used if you require UNICODE messages, because
287 * that requires an explicit message length. Use aim_send_im_ext().
288 *
289 */
d410cf58 290faim_export int aim_send_im(aim_session_t *sess, aim_conn_t *conn, const char *destsn, fu16_t flags, const char *msg)
7b91722d 291{
2d5fd943 292 struct aim_sendimext_args args;
7b91722d 293
2d5fd943 294 args.destsn = destsn;
295 args.flags = flags;
296 args.msg = msg;
297 args.msglen = strlen(msg);
7b91722d 298
2d5fd943 299 return aim_send_im_ext(sess, conn, &args);
7b91722d 300}
301
d410cf58 302/*
303 * This is also performance sensative. (If you can believe it...)
304 *
305 */
306faim_export int aim_send_icon(aim_session_t *sess, aim_conn_t *conn, const char *sn, const fu8_t *icon, int iconlen, time_t stamp, fu16_t iconsum)
7b91722d 307{
d410cf58 308 int i;
309 fu8_t ck[8];
310 aim_frame_t *fr;
311 aim_snacid_t snacid;
6ae3c48d 312
d410cf58 313 if (!sess || !conn || !sn || !icon || (iconlen <= 0) || (iconlen >= MAXICONLEN))
314 return -EINVAL;
6ae3c48d 315
316 if (conn->type != AIM_CONN_TYPE_BOS)
317 return -EINVAL;
318
d410cf58 319 for (i = 0; i < 8; i++)
320 aimutil_put8(ck+i, (fu8_t) rand());
6ae3c48d 321
d410cf58 322 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sn)+2+2+2+8+16+2+2+2+2+2+2+2+4+4+4+iconlen+strlen(AIM_ICONIDENT)+2+2)))
6ae3c48d 323 return -ENOMEM;
324
d410cf58 325 snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0);
326 aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid);
6ae3c48d 327
328 /*
329 * Cookie
330 */
d410cf58 331 aimbs_putraw(&fr->data, ck, 8);
6ae3c48d 332
333 /*
334 * Channel (2)
335 */
d410cf58 336 aimbs_put16(&fr->data, 0x0002);
6ae3c48d 337
338 /*
339 * Dest sn
340 */
d410cf58 341 aimbs_put8(&fr->data, strlen(sn));
342 aimbs_putraw(&fr->data, sn, strlen(sn));
6ae3c48d 343
344 /*
345 * TLV t(0005)
d410cf58 346 *
347 * Encompasses everything below.
6ae3c48d 348 */
d410cf58 349 aimbs_put16(&fr->data, 0x0005);
350 aimbs_put16(&fr->data, 2+8+16+6+4+4+iconlen+4+4+4+strlen(AIM_ICONIDENT));
6ae3c48d 351
d410cf58 352 aimbs_put16(&fr->data, 0x0000);
353 aimbs_putraw(&fr->data, ck, 8);
354 aim_putcap(&fr->data, AIM_CAPS_BUDDYICON);
6ae3c48d 355
356 /* TLV t(000a) */
d410cf58 357 aimbs_put16(&fr->data, 0x000a);
358 aimbs_put16(&fr->data, 0x0002);
359 aimbs_put16(&fr->data, 0x0001);
6ae3c48d 360
361 /* TLV t(000f) */
d410cf58 362 aimbs_put16(&fr->data, 0x000f);
363 aimbs_put16(&fr->data, 0x0000);
6ae3c48d 364
365 /* TLV t(2711) */
d410cf58 366 aimbs_put16(&fr->data, 0x2711);
367 aimbs_put16(&fr->data, 4+4+4+iconlen+strlen(AIM_ICONIDENT));
368 aimbs_put16(&fr->data, 0x0000); /* XXX is this right?! */
369 aimbs_put16(&fr->data, iconsum);
370 aimbs_put32(&fr->data, iconlen);
371 aimbs_put32(&fr->data, stamp);
372 aimbs_putraw(&fr->data, icon, iconlen);
373 aimbs_putraw(&fr->data, AIM_ICONIDENT, strlen(AIM_ICONIDENT));
6ae3c48d 374
375 /* TLV t(0003) */
d410cf58 376 aimbs_put16(&fr->data, 0x0003);
377 aimbs_put16(&fr->data, 0x0000);
6ae3c48d 378
d410cf58 379 aim_tx_enqueue(sess, fr);
6ae3c48d 380
381 return 0;
7b91722d 382}
383
d410cf58 384static int outgoingim(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
e5012450 385{
d410cf58 386 int i, ret = 0;
6ae3c48d 387 aim_rxcallback_t userfunc;
d410cf58 388 fu8_t cookie[8];
389 fu16_t channel;
390 aim_tlvlist_t *tlvlist;
391 char *sn;
392 int snlen;
393 fu16_t icbmflags = 0;
394 fu8_t flag1 = 0, flag2 = 0;
395 fu8_t *msg = NULL;
396 aim_tlv_t *msgblock;
6ae3c48d 397
398 /* ICBM Cookie. */
399 for (i = 0; i < 8; i++)
d410cf58 400 cookie[i] = aimbs_get8(bs);
6ae3c48d 401
402 /* Channel ID */
d410cf58 403 channel = aimbs_get16(bs);
6ae3c48d 404
405 if (channel != 0x01) {
406 faimdprintf(sess, 0, "icbm: ICBM recieved on unsupported channel. Ignoring. (chan = %04x)\n", channel);
d410cf58 407 return 0;
6ae3c48d 408 }
409
d410cf58 410 snlen = aimbs_get8(bs);
411 sn = aimbs_getstr(bs, snlen);
6ae3c48d 412
d410cf58 413 tlvlist = aim_readtlvchain(bs);
6ae3c48d 414
415 if (aim_gettlv(tlvlist, 0x0003, 1))
416 icbmflags |= AIM_IMFLAGS_ACK;
417 if (aim_gettlv(tlvlist, 0x0004, 1))
418 icbmflags |= AIM_IMFLAGS_AWAY;
e5012450 419
d410cf58 420 if ((msgblock = aim_gettlv(tlvlist, 0x0002, 1))) {
421 aim_bstream_t mbs;
422 int featurelen, msglen;
423
424 aim_bstream_init(&mbs, msgblock->value, msgblock->length);
6ae3c48d 425
d410cf58 426 aimbs_get8(&mbs);
427 aimbs_get8(&mbs);
428 for (featurelen = aimbs_get16(&mbs); featurelen; featurelen--)
429 aimbs_get8(&mbs);
430 aimbs_get8(&mbs);
431 aimbs_get8(&mbs);
6ae3c48d 432
d410cf58 433 msglen = aimbs_get16(&mbs) - 4; /* final block length */
6ae3c48d 434
d410cf58 435 flag1 = aimbs_get16(&mbs);
436 flag2 = aimbs_get16(&mbs);
6ae3c48d 437
d410cf58 438 msg = aimbs_getstr(&mbs, msglen);
6ae3c48d 439 }
440
441 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
442 ret = userfunc(sess, rx, channel, sn, msg, icbmflags, flag1, flag2);
443
d410cf58 444 free(sn);
6ae3c48d 445 aim_freetlvchain(&tlvlist);
446
447 return ret;
00ef5271 448}
449
6ae3c48d 450/*
d410cf58 451 *
452 * This should use tlvlists, but doesn't for performance reasons.
453 *
454 * XXX support multipart IMs:
6ae3c48d 455 *
456 * 0004 0007 0000 8f08 d295
457 * 0031 6520 3b7b f9fd
458 * 0001
459 * 06 XXXX XXXX XXXX
460 * 0000
461 * 0004
462 * 0001 0002 0004
463 * 0010 0004 0000 01a3
464 * 0002 0004 3ab6 94fa
465 * 0003 0004 3b7b f85a
466 * 0002 003c
467 * 0501 0001 01
468 * 0101 000a 0000 0000 3c48 544d 4c3e ASCII part
469 * ISO-8859 part:
470 * 0101 0016 0003 0000 6c6b 7364 6a6b 6c6a 676c a56b 3b73 646a 6b6a
471 * 0101 000b 0000 0000 3c2f 4854 4d4c 3e another ASCII part
472 *
473 */
d410cf58 474static int incomingim_ch1(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, fu16_t channel, struct aim_userinfo_s *userinfo, aim_bstream_t *bs, fu8_t *cookie)
00ef5271 475{
d410cf58 476 fu16_t type, length;
1dcd23dd 477 aim_rxcallback_t userfunc;
d410cf58 478 int ret = 0;
1dcd23dd 479 struct aim_incomingim_ch1_args args;
d410cf58 480 int endpos;
00ef5271 481
1dcd23dd 482 memset(&args, 0, sizeof(args));
00ef5271 483
1dcd23dd 484 /*
485 * This used to be done using tlvchains. For performance reasons,
486 * I've changed it to process the TLVs in-place. This avoids lots
487 * of per-IM memory allocations.
488 */
d410cf58 489 while (aim_bstream_empty(bs)) {
490
491 type = aimbs_get16(bs);
492 length = aimbs_get16(bs);
1dcd23dd 493
d410cf58 494 endpos = aim_bstream_curpos(bs) + length;
1dcd23dd 495
496 if (type == 0x0002) { /* Message Block */
d410cf58 497 fu16_t featureslen;
498 int z;
1dcd23dd 499
1dcd23dd 500 /*
d410cf58 501 * This TLV consists of the following:
502 * - 0501 -- Unknown
503 * - Features: Don't know how to interpret these
504 * - 0101 -- Unknown
505 * - Message
1dcd23dd 506 *
507 */
508
d410cf58 509 aimbs_get8(bs); /* 05 */
510 aimbs_get8(bs); /* 01 */
511 featureslen = aimbs_get16(bs);
512 for (z = 0, args.finlen = 0; z < featureslen; z++) {
513 fu8_t tmp;
514
515 tmp = aimbs_get8(bs);
516 if (z < sizeof(args.fingerprint)) {
517 args.fingerprint[z] = tmp;
518 args.finlen++;
519 }
520 }
521 aimbs_get8(bs); /* 01 */
522 aimbs_get8(bs); /* 01 */
1dcd23dd 523
524 /* Message string length, including flag words. */
d410cf58 525 args.msglen = aimbs_get16(bs);
1dcd23dd 526
527 /* Flag words. */
d410cf58 528 args.flag1 = aimbs_get16(bs);
1dcd23dd 529 if (args.flag1 == 0x0000)
530 ; /* ASCII */
531 else if (args.flag1 == 0x0002)
532 args.icbmflags |= AIM_IMFLAGS_UNICODE;
533 else if (args.flag1 == 0x0003)
534 args.icbmflags |= AIM_IMFLAGS_ISO_8859_1;
535 else if (args.flag1 == 0xffff)
536 ; /* no encoding (yeep!) */
1dcd23dd 537
d410cf58 538 args.flag2 = aimbs_get16(bs);
1dcd23dd 539 if (args.flag2 == 0x0000)
540 ; /* standard subencoding? */
541 else if (args.flag2 == 0x000b)
542 args.icbmflags |= AIM_IMFLAGS_SUBENC_MACINTOSH;
543 else if (args.flag2 == 0xffff)
544 ; /* no subencoding */
d410cf58 545
546 /* XXX this isn't really necesary... */
1dcd23dd 547 if ( ((args.flag1 != 0x0000) &&
548 (args.flag1 != 0x0002) &&
549 (args.flag1 != 0x0003) &&
550 (args.flag1 != 0xffff)) ||
551 ((args.flag2 != 0x0000) &&
552 (args.flag2 != 0x000b) &&
553 (args.flag2 != 0xffff))) {
554 faimdprintf(sess, 0, "icbm: **warning: encoding flags are being used! {%04x, %04x}\n", args.flag1, args.flag2);
555 }
556
d410cf58 557 /* Message. */
1dcd23dd 558 args.msglen -= 4;
559 if (args.icbmflags & AIM_IMFLAGS_UNICODE) {
d410cf58 560 fu8_t *umsg;
561
562 /* Can't use getstr because of wide null */
563 umsg = aimbs_getraw(bs, args.msglen);
1dcd23dd 564 args.msg = malloc(args.msglen+2);
d410cf58 565 memcpy(args.msg, umsg, args.msglen);
1dcd23dd 566 args.msg[args.msglen] = '\0'; /* wide NULL */
567 args.msg[args.msglen+1] = '\0';
d410cf58 568
569 free(umsg);
570
571 } else
572 args.msg = aimbs_getstr(bs, args.msglen);
1dcd23dd 573
574 } else if (type == 0x0003) { /* Server Ack Requested */
575
576 args.icbmflags |= AIM_IMFLAGS_ACK;
577
578 } else if (type == 0x0004) { /* Message is Auto Response */
579
580 args.icbmflags |= AIM_IMFLAGS_AWAY;
581
d410cf58 582 } else if (type == 0x0008) { /* I-HAVE-A-REALLY-PURTY-ICON Flag */
1dcd23dd 583
d410cf58 584 args.iconchecksum = aimbs_get32(bs);
585 args.iconlength = aimbs_get32(bs);
586 args.iconstamp = aimbs_get32(bs);
1dcd23dd 587 args.icbmflags |= AIM_IMFLAGS_HASICON;
588
589 } else if (type == 0x0009) {
590
591 args.icbmflags |= AIM_IMFLAGS_BUDDYREQ;
592
593 } else if (type == 0x0017) {
594
595 args.extdatalen = length;
d410cf58 596 args.extdata = aimbs_getraw(bs, args.extdatalen);
1dcd23dd 597
598 } else {
6ae3c48d 599 faimdprintf(sess, 0, "incomingim_ch1: unknown TLV 0x%04x (len %d)\n", type, length);
1dcd23dd 600 }
601
d410cf58 602 /*
603 * This is here to protect ourselves from ourselves. That
604 * is, if something above doesn't completly parse its value
605 * section, or, worse, overparses it, this will set the
606 * stream where it needs to be in order to land on the next
607 * TLV when the loop continues.
608 *
609 */
610 aim_bstream_setpos(bs, endpos);
1dcd23dd 611 }
00ef5271 612
00ef5271 613
1dcd23dd 614 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
615 ret = userfunc(sess, rx, channel, userinfo, &args);
00ef5271 616
d410cf58 617 free(args.extdata);
1dcd23dd 618 free(args.msg);
00ef5271 619
1dcd23dd 620 return ret;
00ef5271 621}
622
d410cf58 623/* XXX Ugh. I think its obvious. */
624static int incomingim_ch2(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, fu16_t channel, struct aim_userinfo_s *userinfo, aim_tlvlist_t *tlvlist, fu8_t *cookie)
00ef5271 625{
6ae3c48d 626 aim_rxcallback_t userfunc;
d410cf58 627 aim_tlv_t *block1;
628 aim_tlvlist_t *list2;
6ae3c48d 629 int ret = 0;
630 struct aim_incomingim_ch2_args args;
d410cf58 631 aim_bstream_t bbs;
632 fu8_t *cookie2;
6ae3c48d 633
634 memset(&args, 0, sizeof(args));
635
636 /*
637 * There's another block of TLVs embedded in the type 5 here.
638 */
355229fe 639 if (!(block1 = aim_gettlv(tlvlist, 0x0005, 1)) || !block1->value) {
6ae3c48d 640 faimdprintf(sess, 0, "no tlv 0x0005 in rendezvous transaction!\n");
641 return 0;
642 }
643
d410cf58 644 aim_bstream_init(&bbs, block1->value, block1->length);
645
6ae3c48d 646 /*
647 * First two bytes represent the status of the connection.
648 *
649 * 0 is a request, 2 is an accept
650 */
d410cf58 651 args.status = aimbs_get16(&bbs);
6ae3c48d 652
653 /*
654 * Next comes the cookie. Should match the ICBM cookie.
655 */
d410cf58 656 cookie2 = aimbs_getraw(&bbs, 8);
657 if (memcmp(cookie, cookie2, 8) != 0)
6ae3c48d 658 faimdprintf(sess, 0, "rend: warning cookies don't match!\n");
d410cf58 659 free(cookie2);
6ae3c48d 660
661 /*
662 * The next 16bytes are a capability block so we can
663 * identify what type of rendezvous this is.
664 *
665 * Thanks to Eric Warmenhoven <warmenhoven@linux.com> (of GAIM)
666 * for pointing some of this out to me. In fact, a lot of
667 * the client-to-client info comes from the work of the GAIM
668 * developers. Thanks!
669 *
670 * Read off one capability string and we should have it ID'd.
671 *
672 */
d410cf58 673 if ((args.reqclass = aim_getcap(sess, &bbs, 0x10)) == 0x0000) {
6ae3c48d 674 faimdprintf(sess, 0, "rend: no ID block\n");
675 return 0;
676 }
677
678 /*
70b889c5 679 * What follows may be TLVs or nothing, depending on the
680 * purpose of the message.
681 *
682 * Ack packets for instance have nothing more to them.
683 */
d410cf58 684 list2 = aim_readtlvchain(&bbs);
6ae3c48d 685
686 if (!list2 || ((args.reqclass != AIM_CAPS_IMIMAGE) && !(aim_gettlv(list2, 0x2711, 1)))) {
d410cf58 687 aim_msgcookie_t *cook;
6ae3c48d 688 int type;
689
690 type = aim_msgcookie_gettype(args.reqclass); /* XXX: fix this shitty code */
691
692 if ((cook = aim_checkcookie(sess, cookie, type)) == NULL) {
693 faimdprintf(sess, 0, "non-data rendezvous thats not in cache (type %d)\n", type);
d410cf58 694 aim_freetlvchain(&list2);
695 return 1;
6ae3c48d 696 }
697
698 if (cook->type == AIM_COOKIETYPE_OFTGET) {
699 struct aim_filetransfer_priv *ft;
700
701 if (cook->data) {
702 int errorcode = -1; /* XXX shouldnt this be 0? */
703
704 ft = (struct aim_filetransfer_priv *)cook->data;
705
706 if (args.status != 0x0002) {
707
d410cf58 708 if (aim_gettlv(list2, 0x000b, 1))
709 errorcode = aim_gettlv16(list2, 0x000b, 1);
6ae3c48d 710
d410cf58 711 /* XXX this should make it up to the client, you know.. */
712 if (errorcode)
713 faimdprintf(sess, 0, "transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sn, ft->ip, ft->fh.name, errorcode);
6ae3c48d 714 } /* args.status != 0x0002 */
d410cf58 715
6ae3c48d 716 } else {
717 faimdprintf(sess, 0, "no data attached to file transfer\n");
718 } /* !cook->data */
719
720 } else if (cook->type == AIM_CAPS_VOICE) {
721
722 faimdprintf(sess, 0, "voice request cancelled\n");
723
724 } else {
725
726 faimdprintf(sess, 0, "unknown cookie cache type %d\n", cook->type);
727 }
728
729 aim_freetlvchain(&list2);
730
731 return 1;
00ef5271 732 }
6ae3c48d 733
734 /*
735 * The rest of the handling depends on what type it is.
736 */
737 if (args.reqclass & AIM_CAPS_BUDDYICON) {
d410cf58 738 aim_tlv_t *miscinfo;
739 aim_bstream_t tbs;
6ae3c48d 740
741 miscinfo = aim_gettlv(list2, 0x2711, 1);
d410cf58 742 aim_bstream_init(&tbs, miscinfo->value, miscinfo->length);
6ae3c48d 743
d410cf58 744 args.info.icon.checksum = aimbs_get32(&tbs);
745 args.info.icon.length = aimbs_get32(&tbs);
746 args.info.icon.timestamp = aimbs_get32(&tbs);
747 args.info.icon.icon = aimbs_getraw(&tbs, args.info.icon.length);
6ae3c48d 748
749 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
750 ret = userfunc(sess, rx, channel, userinfo, &args);
751
752 free(args.info.icon.icon);
753
754 } else if (args.reqclass & AIM_CAPS_VOICE) {
d410cf58 755 aim_msgcookie_t *cachedcook;
6ae3c48d 756
757 faimdprintf(sess, 1, "rend: voice!\n");
758
d410cf58 759 if(!(cachedcook = (aim_msgcookie_t*)calloc(1, sizeof(aim_msgcookie_t)))) {
6ae3c48d 760 aim_freetlvchain(&list2);
761 return 0;
762 }
763
764 memcpy(cachedcook->cookie, cookie, 8);
765 cachedcook->type = AIM_COOKIETYPE_OFTVOICE;
766 cachedcook->data = NULL;
767
768 if (aim_cachecookie(sess, cachedcook) == -1)
769 faimdprintf(sess, 0, "ERROR caching message cookie\n");
770
771 /* XXX: implement all this */
772
773 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
774 ret = userfunc(sess, rx, channel, userinfo, &args);
775
776 } else if (args.reqclass & AIM_CAPS_IMIMAGE) {
777 char ip[30];
778 struct aim_directim_priv *priv;
779
780 memset(ip, 0, sizeof(ip));
781
782 if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) {
d410cf58 783 aim_tlv_t *iptlv, *porttlv;
6ae3c48d 784
785 iptlv = aim_gettlv(list2, 0x0003, 1);
786 porttlv = aim_gettlv(list2, 0x0005, 1);
787
788 snprintf(ip, 30, "%d.%d.%d.%d:%d",
789 aimutil_get8(iptlv->value+0),
790 aimutil_get8(iptlv->value+1),
791 aimutil_get8(iptlv->value+2),
792 aimutil_get8(iptlv->value+3),
793 4443 /*aimutil_get16(porttlv->value)*/);
794 }
795
796 faimdprintf(sess, 1, "rend: directIM request from %s (%s)\n",
797 userinfo->sn, ip);
798
799 /*
800 * XXX: there are a couple of different request packets for
801 * different things
802 */
803
804 args.info.directim = priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv)); /* XXX error */
805 memcpy(priv->ip, ip, sizeof(priv->ip));
806 memcpy(priv->sn, userinfo->sn, sizeof(priv->sn));
807 memcpy(priv->cookie, cookie, sizeof(priv->cookie));
808
809 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
810 ret = userfunc(sess, rx, channel, userinfo, &args);
811
812 } else if (args.reqclass & AIM_CAPS_CHAT) {
d410cf58 813 aim_tlv_t *miscinfo;
814 aim_bstream_t tbs;
6ae3c48d 815
816 miscinfo = aim_gettlv(list2, 0x2711, 1);
d410cf58 817
818 aim_bstream_init(&tbs, miscinfo->value, miscinfo->length);
819
820 aim_chat_readroominfo(&tbs, &args.info.chat.roominfo);
6ae3c48d 821
822 if (aim_gettlv(list2, 0x000c, 1))
823 args.info.chat.msg = aim_gettlv_str(list2, 0x000c, 1);
824
825 if (aim_gettlv(list2, 0x000d, 1))
826 args.info.chat.encoding = aim_gettlv_str(list2, 0x000d, 1);
827
828 if (aim_gettlv(list2, 0x000e, 1))
829 args.info.chat.lang = aim_gettlv_str(list2, 0x000e, 1);
830
831 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
832 ret = userfunc(sess, rx, channel, userinfo, &args);
833
834 free(args.info.chat.roominfo.name);
835 free(args.info.chat.msg);
836 free(args.info.chat.encoding);
837 free(args.info.chat.lang);
838
839 } else if (args.reqclass & AIM_CAPS_GETFILE) {
840 char ip[30];
d410cf58 841 aim_msgcookie_t *cachedcook;
842 aim_tlv_t *miscinfo;
843 aim_tlv_t *iptlv, *porttlv;
6ae3c48d 844
845 memset(ip, 0, 30);
846
d410cf58 847 if (!(cachedcook = calloc(1, sizeof(aim_msgcookie_t)))) {
6ae3c48d 848 aim_freetlvchain(&list2);
849 return 0;
850 }
851
852 if (!(miscinfo = aim_gettlv(list2, 0x2711, 1)) ||
853 !(iptlv = aim_gettlv(list2, 0x0003, 1)) ||
854 !(porttlv = aim_gettlv(list2, 0x0005, 1))) {
855
856 faimdprintf(sess, 0, "rend: badly damaged file get request from %s...\n", userinfo->sn);
857 aim_cookie_free(sess, cachedcook);
858 aim_freetlvchain(&list2);
859
860 return 0;
861 }
862
863 snprintf(ip, 30, "%d.%d.%d.%d:%d",
864 aimutil_get8(iptlv->value+0),
865 aimutil_get8(iptlv->value+1),
866 aimutil_get8(iptlv->value+2),
867 aimutil_get8(iptlv->value+3),
868 aimutil_get16(porttlv->value));
869
870 faimdprintf(sess, 0, "rend: file get request from %s (%s)\n", userinfo->sn, ip);
871
872 args.info.getfile.ip = ip;
873 args.info.getfile.cookie = cookie;
874
875 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
876 ret = userfunc(sess, rx, channel, userinfo, &args);
877
878 } else if (args.reqclass & AIM_CAPS_SENDFILE) {
879#if 0
880 char ip[30];
d410cf58 881 aim_msgcookie_t *cachedcook;
882 aim_tlv_t *miscinfo;
883 aim_tlv_t *iptlv, *porttlv;
6ae3c48d 884
885 memset(ip, 0, 30);
886
d410cf58 887 if (!(cachedcook = calloc(1, sizeof(aim_msgcookie_t)))) {
6ae3c48d 888 aim_freetlvchain(&list2);
889 return 0;
890 }
891
892 if (!(miscinfo = aim_gettlv(list2, 0x2711, 1)) ||
893 !(iptlv = aim_gettlv(list2, 0x0003, 1)) ||
894 !(porttlv = aim_gettlv(list2, 0x0005, 1))) {
895
896 faimdprintf(sess, 0, "rend: badly damaged file get request from %s...\n", userinfo->sn);
897 aim_cookie_free(sess, cachedcook);
898 aim_freetlvchain(&list2);
899
900 return 0;
901 }
902
903 snprintf(ip, 30, "%d.%d.%d.%d:%d",
904 aimutil_get8(iptlv->value+0),
905 aimutil_get8(iptlv->value+1),
906 aimutil_get8(iptlv->value+2),
907 aimutil_get8(iptlv->value+3),
908 aimutil_get16(porttlv->value));
909
910 if (aim_gettlv(list2, 0x000c, 1))
911 desc = aim_gettlv_str(list2, 0x000c, 1);
912
913 faimdprintf(sess, 0, "rend: file transfer request from %s: %s (%s)\n",
914 userinfo->sn, desc, ip);
915
916 memcpy(cachedcook->cookie, cookie, 8);
917
918 ft = malloc(sizeof(struct aim_filetransfer_priv)); /* XXX */
919 strncpy(ft->sn, userinfo.sn, sizeof(ft->sn));
920 strncpy(ft->ip, ip, sizeof(ft->ip));
921 strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name));
922 cachedcook->type = AIM_COOKIETYPE_OFTSEND;
923 cachedcook->data = ft;
924
925 if (aim_cachecookie(sess, cachedcook) == -1)
926 faimdprintf(sess, 0, "ERROR caching message cookie\n");
927
928 aim_accepttransfer(sess, rx->conn, ft->sn, cookie, AIM_CAPS_SENDFILE);
929
930 if (desc)
931 free(desc);
932
933 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
934 ret = userfunc(sess, rx, channel, userinfo, &args);
00ef5271 935
936#endif
6ae3c48d 937 } else
938 faimdprintf(sess, 0, "rend: unknown rendezvous 0x%04x\n", args.reqclass);
00ef5271 939
6ae3c48d 940 aim_freetlvchain(&list2);
00ef5271 941
6ae3c48d 942 return ret;
e5012450 943}
944
49c8a2fa 945/*
946 * It can easily be said that parsing ICBMs is THE single
947 * most difficult thing to do in the in AIM protocol. In
948 * fact, I think I just did say that.
949 *
950 * Below is the best damned solution I've come up with
951 * over the past sixteen months of battling with it. This
952 * can parse both away and normal messages from every client
953 * I have access to. Its not fast, its not clean. But it works.
954 *
49c8a2fa 955 */
d410cf58 956static int incomingim(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
9de3ca7e 957{
6ae3c48d 958 int i, ret = 0;
d410cf58 959 fu8_t cookie[8];
960 fu16_t channel;
6ae3c48d 961 struct aim_userinfo_s userinfo;
962
963 memset(&userinfo, 0x00, sizeof(struct aim_userinfo_s));
964
965 /*
966 * Read ICBM Cookie. And throw away.
967 */
968 for (i = 0; i < 8; i++)
d410cf58 969 cookie[i] = aimbs_get8(bs);
6ae3c48d 970
971 /*
972 * Channel ID.
973 *
974 * Channel 0x0001 is the message channel. There are
975 * other channels for things called "rendevous"
976 * which represent chat and some of the other new
977 * features of AIM2/3/3.5.
978 *
979 * Channel 0x0002 is the Rendevous channel, which
980 * is where Chat Invitiations and various client-client
981 * connection negotiations come from.
982 *
983 */
d410cf58 984 channel = aimbs_get16(bs);
6ae3c48d 985
986 /*
987 * Technically Channel 3 in chat could be done here too.
988 */
989 if ((channel != 0x01) && (channel != 0x02)) {
990 faimdprintf(sess, 0, "icbm: ICBM received on an unsupported channel. Ignoring.\n (chan = %04x)", channel);
d410cf58 991 return 0;
6ae3c48d 992 }
993
994 /*
995 * Extract the standard user info block.
996 *
997 * Note that although this contains TLVs that appear contiguous
998 * with the TLVs read below, they are two different pieces. The
999 * userinfo block contains the number of TLVs that contain user
1000 * information, the rest are not even though there is no seperation.
1001 * aim_extractuserinfo() returns the number of bytes used by the
1002 * userinfo tlvs, so you can start reading the rest of them right
1003 * afterward.
1004 *
1005 * That also means that TLV types can be duplicated between the
1006 * userinfo block and the rest of the message, however there should
1007 * never be two TLVs of the same type in one block.
1008 *
1009 */
d410cf58 1010 aim_extractuserinfo(sess, bs, &userinfo);
6ae3c48d 1011
1012 /*
1013 * From here on, its depends on what channel we're on.
1014 *
1015 * Technically all channels have a TLV list have this, however,
1016 * for the common channel 1 case, in-place parsing is used for
1017 * performance reasons (less memory allocation).
1018 */
1019 if (channel == 1) {
1020
d410cf58 1021 ret = incomingim_ch1(sess, mod, rx, snac, channel, &userinfo, bs, cookie);
6ae3c48d 1022
1023 } else if (channel == 0x0002) {
d410cf58 1024 aim_tlvlist_t *tlvlist;
6ae3c48d 1025
1026 /*
1027 * Read block of TLVs (not including the userinfo data). All
1028 * further data is derived from what is parsed here.
1029 */
d410cf58 1030 tlvlist = aim_readtlvchain(bs);
6ae3c48d 1031
1032 ret = incomingim_ch2(sess, mod, rx, snac, channel, &userinfo, tlvlist, cookie);
1033
1034 /*
1035 * Free up the TLV chain.
1036 */
1037 aim_freetlvchain(&tlvlist);
1038 }
1039
1040 return ret;
49c8a2fa 1041}
1042
040457cc 1043/*
1044 * Possible codes:
1045 * AIM_TRANSFER_DENY_NOTSUPPORTED -- "client does not support"
1046 * AIM_TRANSFER_DENY_DECLINE -- "client has declined transfer"
1047 * AIM_TRANSFER_DENY_NOTACCEPTING -- "client is not accepting transfers"
1048 *
1049 */
d410cf58 1050faim_export int aim_denytransfer(aim_session_t *sess, aim_conn_t *conn, const char *sender, const char *cookie, fu16_t code)
040457cc 1051{
d410cf58 1052 aim_frame_t *fr;
1053 aim_snacid_t snacid;
1054 aim_tlvlist_t *tl = NULL;
1055
1056 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sender)+6)))
6ae3c48d 1057 return -ENOMEM;
040457cc 1058
d410cf58 1059 snacid = aim_cachesnac(sess, 0x0004, 0x000b, 0x0000, NULL, 0);
1060 aim_putsnac(&fr->data, 0x0004, 0x000b, 0x0000, snacid);
1061
1062 aimbs_putraw(&fr->data, cookie, 8);
040457cc 1063
d410cf58 1064 aimbs_put16(&fr->data, 0x0002); /* channel */
1065 aimbs_put8(&fr->data, strlen(sender));
1066 aimbs_putraw(&fr->data, sender, strlen(sender));
040457cc 1067
d410cf58 1068 aim_addtlvtochain16(&tl, 0x0003, code);
1069 aim_writetlvchain(&fr->data, &tl);
1070 aim_freetlvchain(&tl);
1071
1072 aim_tx_enqueue(sess, fr);
040457cc 1073
6ae3c48d 1074 return 0;
040457cc 1075}
1076
49c8a2fa 1077/*
355229fe 1078 * aim_reqicbmparaminfo()
49c8a2fa 1079 *
355229fe 1080 * Request ICBM parameter information.
49c8a2fa 1081 *
1082 */
d410cf58 1083faim_export int aim_reqicbmparams(aim_session_t *sess, aim_conn_t *conn)
355229fe 1084{
1085 return aim_genericreq_n(sess, conn, 0x0004, 0x0004);
1086}
1087
1088/*
1089 *
d410cf58 1090 * I definitly recommend sending this. If you don't, you'll be stuck
1091 * with the rather unreasonable defaults. You don't want those. Send this.
1092 *
355229fe 1093 */
d410cf58 1094faim_export int aim_seticbmparam(aim_session_t *sess, aim_conn_t *conn, struct aim_icbmparameters *params)
49c8a2fa 1095{
d410cf58 1096 aim_frame_t *fr;
1097 aim_snacid_t snacid;
49c8a2fa 1098
355229fe 1099 if (!sess || !conn || !params)
1100 return -EINVAL;
1101
d410cf58 1102 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+16)))
6ae3c48d 1103 return -ENOMEM;
5b79dc93 1104
d410cf58 1105 snacid = aim_cachesnac(sess, 0x0004, 0x0002, 0x0000, NULL, 0);
1106 aim_putsnac(&fr->data, 0x0004, 0x0002, 0x0000, snacid);
5b79dc93 1107
d410cf58 1108 /* This is read-only (see Parameter Reply). Must be set to zero here. */
1109 aimbs_put16(&fr->data, 0x0000);
355229fe 1110
1111 /* These are all read-write */
d410cf58 1112 aimbs_put32(&fr->data, params->flags);
1113 aimbs_put16(&fr->data, params->maxmsglen);
1114 aimbs_put16(&fr->data, params->maxsenderwarn);
1115 aimbs_put16(&fr->data, params->maxrecverwarn);
1116 aimbs_put32(&fr->data, params->minmsginterval);
5b79dc93 1117
d410cf58 1118 aim_tx_enqueue(sess, fr);
a25832e6 1119
6ae3c48d 1120 return 0;
a25832e6 1121}
1122
d410cf58 1123static int paraminfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
a25832e6 1124{
355229fe 1125 struct aim_icbmparameters params;
6ae3c48d 1126 aim_rxcallback_t userfunc;
e6b05d80 1127
d410cf58 1128 params.maxchan = aimbs_get16(bs);
1129 params.flags = aimbs_get32(bs);
1130 params.maxmsglen = aimbs_get16(bs);
1131 params.maxsenderwarn = aimbs_get16(bs);
1132 params.maxrecverwarn = aimbs_get16(bs);
1133 params.minmsginterval = aimbs_get32(bs);
1134
6ae3c48d 1135 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
355229fe 1136 return userfunc(sess, rx, &params);
00ef5271 1137
6ae3c48d 1138 return 0;
00ef5271 1139}
1140
d410cf58 1141static int missedcall(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
96f8b1ed 1142{
d410cf58 1143 int ret = 0;
6ae3c48d 1144 aim_rxcallback_t userfunc;
d410cf58 1145 fu16_t channel, nummissed, reason;
6ae3c48d 1146 struct aim_userinfo_s userinfo;
6ae3c48d 1147
d410cf58 1148 while (aim_bstream_empty(bs)) {
6ae3c48d 1149
d410cf58 1150 channel = aimbs_get16(bs);
1151 aim_extractuserinfo(sess, bs, &userinfo);
1152 nummissed = aimbs_get16(bs);
1153 reason = aimbs_get16(bs);
6ae3c48d 1154
36a61e0d 1155 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
1156 ret = userfunc(sess, rx, channel, &userinfo, nummissed, reason);
1157 }
6ae3c48d 1158
36a61e0d 1159 return ret;
00ef5271 1160}
1161
d410cf58 1162static int clienterr(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
00ef5271 1163{
d410cf58 1164 int ret = 0;
6ae3c48d 1165 aim_rxcallback_t userfunc;
d410cf58 1166 fu16_t channel, reason;
1167 char *sn;
1168 fu8_t *ck, snlen;
00ef5271 1169
d410cf58 1170 ck = aimbs_getraw(bs, 8);
1171 channel = aimbs_get16(bs);
1172 snlen = aimbs_get8(bs);
1173 sn = aimbs_getstr(bs, snlen);
1174 reason = aimbs_get16(bs);
00ef5271 1175
d410cf58 1176 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
1177 ret = userfunc(sess, rx, channel, sn, reason);
00ef5271 1178
d410cf58 1179 return ret;
1180}
00ef5271 1181
d410cf58 1182static int msgack(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
1183{
1184 aim_rxcallback_t userfunc;
1185 fu16_t type;
1186 fu8_t snlen, *ck;
1187 char *sn;
1188
1189 ck = aimbs_getraw(bs, 8);
1190 type = aimbs_get16(bs);
1191 snlen = aimbs_get8(bs);
1192 sn = aimbs_getstr(bs, snlen);
00ef5271 1193
6ae3c48d 1194 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
1195 return userfunc(sess, rx, type, sn);
00ef5271 1196
d410cf58 1197 free(sn);
1198 free(ck);
1199
6ae3c48d 1200 return 0;
00ef5271 1201}
1202
d410cf58 1203static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
00ef5271 1204{
1205
6ae3c48d 1206 if (snac->subtype == 0x0005)
d410cf58 1207 return paraminfo(sess, mod, rx, snac, bs);
6ae3c48d 1208 else if (snac->subtype == 0x0006)
d410cf58 1209 return outgoingim(sess, mod, rx, snac, bs);
6ae3c48d 1210 else if (snac->subtype == 0x0007)
d410cf58 1211 return incomingim(sess, mod, rx, snac, bs);
6ae3c48d 1212 else if (snac->subtype == 0x000a)
d410cf58 1213 return missedcall(sess, mod, rx, snac, bs);
1214 else if (snac->subtype == 0x000b)
1215 return clienterr(sess, mod, rx, snac, bs);
6ae3c48d 1216 else if (snac->subtype == 0x000c)
d410cf58 1217 return msgack(sess, mod, rx, snac, bs);
6ae3c48d 1218
1219 return 0;
00ef5271 1220}
1221
d410cf58 1222faim_internal int msg_modfirst(aim_session_t *sess, aim_module_t *mod)
00ef5271 1223{
1224
6ae3c48d 1225 mod->family = 0x0004;
1226 mod->version = 0x0000;
1227 mod->flags = 0;
1228 strncpy(mod->name, "messaging", sizeof(mod->name));
1229 mod->snachandler = snachandler;
00ef5271 1230
6ae3c48d 1231 return 0;
96f8b1ed 1232}
This page took 2.504473 seconds and 5 git commands to generate.