4 * The routines for sending/receiving Instant Messages.
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
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
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.
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.
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,
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
42 * Note that in this function, only the feature bytes are tested, since
43 * the rest will always be the same.
46 faim_export fu16_t aim_fingerprintclient(fu8_t *msghdr, int len)
53 /* AOL Mobile Communicator, WinAIM 1.0.414 */
55 3, {0x01, 0x01, 0x01}},
57 /* WinAIM 2.0.847, 2.1.1187, 3.0.1464, 4.3.2229, 4.4.2286 */
58 { AIM_CLIENTTYPE_WINAIM,
59 3, {0x01, 0x01, 0x02}},
61 /* WinAIM 4.1.2010, libfaim */
62 { AIM_CLIENTTYPE_WINAIM41,
63 4, {0x01, 0x01, 0x01, 0x02}},
65 /* AOL v6.0, CompuServe 2000 v6.0, any TOC client */
66 { AIM_CLIENTTYPE_AOL_TOC,
73 if (!msghdr || (len <= 0))
74 return AIM_CLIENTTYPE_UNKNOWN;
76 for (i = 0; fingerprints[i].len; i++) {
77 if (fingerprints[i].len != len)
79 if (memcmp(fingerprints[i].data, msghdr, fingerprints[i].len) == 0)
80 return fingerprints[i].clientid;
83 return AIM_CLIENTTYPE_UNKNOWN;
86 /* This should be endian-safe now... but who knows... */
87 faim_export fu32_t aim_iconsum(const fu8_t *buf, int buflen)
92 for (i = 0, sum = 0; i < buflen; i += 2)
93 sum += (buf[i+1] << 8) + buf[i];
95 sum = ((sum & 0xffff0000) >> 16) + (sum & 0x0000ffff);
101 * Send an ICBM (instant message).
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)
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
112 * AIM_IMFLAGS_ISO_8859_1 -- The message contains the ASCII8 subset
113 * known as ISO-8859-1.
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.)
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 ߪ where 2026 is the hex
132 * representation of the UNICODE index (in this case, UNICODE
133 * "Horizontal Ellipsis", or 133 in in ASCII8).
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.
141 * XXX more precise verification that we never send SNACs larger than 8192
142 * XXX check SNAC size for multipart
145 faim_export int aim_send_im_ext(aim_session_t *sess, aim_conn_t *conn, struct aim_sendimext_args *args)
147 static const fu8_t deffeatures[] = {
148 0x01, 0x01, 0x01, 0x02, 0x42,
154 if (!sess || !conn || !args)
157 if (args->flags & AIM_IMFLAGS_MULTIPART) {
158 if (args->mpmsg->numparts <= 0)
161 if (!args->msg || (args->msglen <= 0))
164 if (args->msglen >= MAXMSGLEN)
168 /* Painfully calculate the size of the message TLV */
169 msgtlvlen = 1 + 1; /* 0501 */
171 if (args->flags & AIM_IMFLAGS_CUSTOMFEATURES)
172 msgtlvlen += 2 + args->featureslen;
174 msgtlvlen += 2 + sizeof(deffeatures);
176 if (args->flags & AIM_IMFLAGS_MULTIPART) {
177 aim_mpmsg_section_t *sec;
179 for (sec = args->mpmsg->parts; sec; sec = sec->next) {
180 msgtlvlen += 2 /* 0101 */ + 2 /* block len */;
181 msgtlvlen += 4 /* charset */ + sec->datalen;
185 msgtlvlen += 2 /* 0101 */ + 2 /* block len */;
186 msgtlvlen += 4 /* charset */ + args->msglen;
190 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, msgtlvlen+128)))
193 /* XXX should be optional */
194 snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, args->destsn, strlen(args->destsn)+1);
195 aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid);
198 * Generate a random message cookie
200 * We could cache these like we do SNAC IDs. (In fact, it
201 * might be a good idea.) In the message error functions,
202 * the 8byte message cookie is returned as well as the
206 for (i = 0; i < 8; i++)
207 aimbs_put8(&fr->data, (fu8_t) rand());
212 aimbs_put16(&fr->data, 0x0001);
215 * Destination SN (prepended with byte length)
217 aimbs_put8(&fr->data, strlen(args->destsn));
218 aimbs_putraw(&fr->data, args->destsn, strlen(args->destsn));
223 aimbs_put16(&fr->data, 0x0002);
224 aimbs_put16(&fr->data, msgtlvlen);
230 aimbs_put8(&fr->data, 0x05);
231 aimbs_put8(&fr->data, 0x01);
233 if (args->flags & AIM_IMFLAGS_CUSTOMFEATURES) {
234 aimbs_put16(&fr->data, args->featureslen);
235 aimbs_putraw(&fr->data, args->features, args->featureslen);
237 aimbs_put16(&fr->data, sizeof(deffeatures));
238 aimbs_putraw(&fr->data, deffeatures, sizeof(deffeatures));
241 if (args->flags & AIM_IMFLAGS_MULTIPART) {
242 aim_mpmsg_section_t *sec;
244 for (sec = args->mpmsg->parts; sec; sec = sec->next) {
245 aimbs_put16(&fr->data, 0x0101);
246 aimbs_put16(&fr->data, sec->datalen + 4);
247 aimbs_put16(&fr->data, sec->charset);
248 aimbs_put16(&fr->data, sec->charsubset);
249 aimbs_putraw(&fr->data, sec->data, sec->datalen);
254 aimbs_put16(&fr->data, 0x0101);
257 * Message block length.
259 aimbs_put16(&fr->data, args->msglen + 0x04);
264 if (args->flags & AIM_IMFLAGS_CUSTOMCHARSET) {
266 aimbs_put16(&fr->data, args->charset);
267 aimbs_put16(&fr->data, args->charsubset);
270 if (args->flags & AIM_IMFLAGS_UNICODE)
271 aimbs_put16(&fr->data, 0x0002);
272 else if (args->flags & AIM_IMFLAGS_ISO_8859_1)
273 aimbs_put16(&fr->data, 0x0003);
275 aimbs_put16(&fr->data, 0x0000);
277 aimbs_put16(&fr->data, 0x0000);
281 * Message. Not terminated.
283 aimbs_putraw(&fr->data, args->msg, args->msglen);
287 * Set the Request Acknowledge flag.
289 if (args->flags & AIM_IMFLAGS_ACK) {
290 aimbs_put16(&fr->data, 0x0003);
291 aimbs_put16(&fr->data, 0x0000);
295 * Set the Autoresponse flag.
297 if (args->flags & AIM_IMFLAGS_AWAY) {
298 aimbs_put16(&fr->data, 0x0004);
299 aimbs_put16(&fr->data, 0x0000);
303 * Set the Buddy Icon Requested flag.
305 if (args->flags & AIM_IMFLAGS_BUDDYREQ) {
306 aimbs_put16(&fr->data, 0x0009);
307 aimbs_put16(&fr->data, 0x0000);
311 * Set the I HAVE A REALLY PURTY ICON flag.
313 if (args->flags & AIM_IMFLAGS_HASICON) {
314 aimbs_put16(&fr->data, 0x0008);
315 aimbs_put16(&fr->data, 0x000c);
316 aimbs_put32(&fr->data, args->iconlen);
317 aimbs_put32(&fr->data, args->iconsum);
318 aimbs_put32(&fr->data, args->iconstamp);
321 aim_tx_enqueue(sess, fr);
323 #if 1 /* XXX do this with autoconf or something... */
324 aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */
331 * Simple wrapper for aim_send_im_ext()
333 * You cannot use aim_send_im if you need the HASICON flag. You must
334 * use aim_send_im_ext directly for that.
336 * aim_send_im also cannot be used if you require UNICODE messages, because
337 * that requires an explicit message length. Use aim_send_im_ext().
340 faim_export int aim_send_im(aim_session_t *sess, aim_conn_t *conn, const char *destsn, fu16_t flags, const char *msg)
342 struct aim_sendimext_args args;
344 args.destsn = destsn;
347 args.msglen = strlen(msg);
349 /* Make these don't get set by accident -- they need aim_send_im_ext */
350 args.flags &= ~(AIM_IMFLAGS_CUSTOMFEATURES | AIM_IMFLAGS_HASICON | AIM_IMFLAGS_MULTIPART);
352 return aim_send_im_ext(sess, conn, &args);
356 * This is also performance sensitive. (If you can believe it...)
359 faim_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, fu32_t iconsum)
366 if (!sess || !conn || !sn || !icon || (iconlen <= 0) || (iconlen >= MAXICONLEN))
369 if (conn->type != AIM_CONN_TYPE_BOS)
372 for (i = 0; i < 8; i++)
373 aimutil_put8(ck+i, (fu8_t) rand());
375 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)))
378 snacid = aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, NULL, 0);
379 aim_putsnac(&fr->data, 0x0004, 0x0006, 0x0000, snacid);
384 aimbs_putraw(&fr->data, ck, 8);
389 aimbs_put16(&fr->data, 0x0002);
394 aimbs_put8(&fr->data, strlen(sn));
395 aimbs_putraw(&fr->data, sn, strlen(sn));
400 * Encompasses everything below.
402 aimbs_put16(&fr->data, 0x0005);
403 aimbs_put16(&fr->data, 2+8+16+6+4+4+iconlen+4+4+4+strlen(AIM_ICONIDENT));
405 aimbs_put16(&fr->data, 0x0000);
406 aimbs_putraw(&fr->data, ck, 8);
407 aim_putcap(&fr->data, AIM_CAPS_BUDDYICON);
410 aimbs_put16(&fr->data, 0x000a);
411 aimbs_put16(&fr->data, 0x0002);
412 aimbs_put16(&fr->data, 0x0001);
415 aimbs_put16(&fr->data, 0x000f);
416 aimbs_put16(&fr->data, 0x0000);
419 aimbs_put16(&fr->data, 0x2711);
420 aimbs_put16(&fr->data, 4+4+4+iconlen+strlen(AIM_ICONIDENT));
421 aimbs_put32(&fr->data, iconsum);
422 aimbs_put32(&fr->data, iconlen);
423 aimbs_put32(&fr->data, stamp);
424 aimbs_putraw(&fr->data, icon, iconlen);
425 aimbs_putraw(&fr->data, AIM_ICONIDENT, strlen(AIM_ICONIDENT));
428 aimbs_put16(&fr->data, 0x0003);
429 aimbs_put16(&fr->data, 0x0000);
431 aim_tx_enqueue(sess, fr);
436 static int outgoingim(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
439 aim_rxcallback_t userfunc;
442 aim_tlvlist_t *tlvlist;
445 fu16_t icbmflags = 0;
446 fu8_t flag1 = 0, flag2 = 0;
451 for (i = 0; i < 8; i++)
452 cookie[i] = aimbs_get8(bs);
455 channel = aimbs_get16(bs);
457 if (channel != 0x01) {
458 faimdprintf(sess, 0, "icbm: ICBM recieved on unsupported channel. Ignoring. (chan = %04x)\n", channel);
462 snlen = aimbs_get8(bs);
463 sn = aimbs_getstr(bs, snlen);
465 tlvlist = aim_readtlvchain(bs);
467 if (aim_gettlv(tlvlist, 0x0003, 1))
468 icbmflags |= AIM_IMFLAGS_ACK;
469 if (aim_gettlv(tlvlist, 0x0004, 1))
470 icbmflags |= AIM_IMFLAGS_AWAY;
472 if ((msgblock = aim_gettlv(tlvlist, 0x0002, 1))) {
474 int featurelen, msglen;
476 aim_bstream_init(&mbs, msgblock->value, msgblock->length);
480 for (featurelen = aimbs_get16(&mbs); featurelen; featurelen--)
485 msglen = aimbs_get16(&mbs) - 4; /* final block length */
487 flag1 = aimbs_get16(&mbs);
488 flag2 = aimbs_get16(&mbs);
490 msg = aimbs_getstr(&mbs, msglen);
493 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
494 ret = userfunc(sess, rx, channel, sn, msg, icbmflags, flag1, flag2);
497 aim_freetlvchain(&tlvlist);
503 * Ahh, the joys of nearly ridiculous over-engineering.
505 * Not only do AIM ICBM's support multiple channels. Not only do they
506 * support multiple character sets. But they support multiple character
507 * sets / encodings within the same ICBM.
509 * These multipart messages allow for complex space savings techniques, which
510 * seem utterly unnecessary by today's standards. In fact, there is only
511 * one client still in popular use that still uses this method: AOL for the
512 * Macintosh, Version 5.0. Obscure, yes, I know.
514 * In modern (non-"legacy") clients, if the user tries to send a character
515 * that is not ISO-8859-1 or ASCII, the client will send the entire message
516 * as UNICODE, meaning that every character in the message will occupy the
517 * full 16 bit UNICODE field, even if the high order byte would be zero.
518 * Multipart messages prevent this wasted space by allowing the client to
519 * only send the characters in UNICODE that need to be sent that way, and
520 * the rest of the message can be sent in whatever the native character
521 * set is (probably ASCII).
523 * An important note is that sections will be displayed in the order that
524 * they appear in the ICBM. There is no facility for merging or rearranging
525 * sections at run time. So if you have, say, ASCII then UNICODE then ASCII,
526 * you must supply two ASCII sections with a UNICODE in the middle, and incur
527 * the associated overhead.
529 * Normally I would have laughed and given a firm 'no' to supporting this
530 * seldom-used feature, but something is attracting me to it. In the future,
531 * it may be possible to abuse this to send mixed-media messages to other
532 * open source clients (like encryption or something) -- see faimtest for
533 * examples of how to do this.
535 * I would definitly recommend avoiding this feature unless you really
536 * know what you are doing, and/or you have something neat to do with it.
539 faim_export int aim_mpmsg_init(aim_session_t *sess, aim_mpmsg_t *mpm)
542 memset(mpm, 0, sizeof(aim_mpmsg_t));
547 static int mpmsg_addsection(aim_session_t *sess, aim_mpmsg_t *mpm, fu16_t charset, fu16_t charsubset, fu8_t *data, fu16_t datalen)
549 aim_mpmsg_section_t *sec;
551 if (!(sec = malloc(sizeof(aim_mpmsg_section_t))))
554 sec->charset = charset;
555 sec->charsubset = charsubset;
557 sec->datalen = datalen;
563 aim_mpmsg_section_t *cur;
565 for (cur = mpm->parts; cur->next; cur = cur->next)
575 faim_export int aim_mpmsg_addraw(aim_session_t *sess, aim_mpmsg_t *mpm, fu16_t charset, fu16_t charsubset, const fu8_t *data, fu16_t datalen)
579 if (!(dup = malloc(datalen)))
581 memcpy(dup, data, datalen);
583 if (mpmsg_addsection(sess, mpm, charset, charsubset, dup, datalen) == -1) {
591 /* XXX should provide a way of saying ISO-8859-1 specifically */
592 faim_export int aim_mpmsg_addascii(aim_session_t *sess, aim_mpmsg_t *mpm, const char *ascii)
596 if (!(dup = strdup(ascii)))
599 if (mpmsg_addsection(sess, mpm, 0x0000, 0x0000, dup, strlen(ascii)) == -1) {
607 faim_export int aim_mpmsg_addunicode(aim_session_t *sess, aim_mpmsg_t *mpm, const fu16_t *unicode, fu16_t unicodelen)
613 if (!(buf = malloc(unicodelen * 2)))
616 aim_bstream_init(&bs, buf, unicodelen * 2);
618 /* We assume unicode is in /host/ byte order -- convert to network */
619 for (i = 0; i < unicodelen; i++)
620 aimbs_put16(&bs, unicode[i]);
622 if (mpmsg_addsection(sess, mpm, 0x0002, 0x0000, buf, aim_bstream_curpos(&bs)) == -1) {
630 faim_export void aim_mpmsg_free(aim_session_t *sess, aim_mpmsg_t *mpm)
632 aim_mpmsg_section_t *cur;
634 for (cur = mpm->parts; cur; ) {
635 aim_mpmsg_section_t *tmp;
650 * Start by building the multipart structures, then pick the first
651 * human-readable section and stuff it into args->msg so no one gets
655 static int incomingim_ch1_parsemsgs(aim_session_t *sess, fu8_t *data, int len, struct aim_incomingim_ch1_args *args)
657 static const fu16_t charsetpri[] = {
658 0x0000, /* ASCII first */
659 0x0003, /* then ISO-8859-1 */
660 0x0002, /* UNICODE as last resort */
662 static const int charsetpricount = 3;
665 aim_mpmsg_section_t *sec;
667 aim_bstream_init(&mbs, data, len);
669 while (aim_bstream_empty(&mbs)) {
670 fu16_t msglen, flag1, flag2;
673 aimbs_get8(&mbs); /* 01 */
674 aimbs_get8(&mbs); /* 01 */
676 /* Message string length, including character set info. */
677 msglen = aimbs_get16(&mbs);
679 /* Character set info */
680 flag1 = aimbs_get16(&mbs);
681 flag2 = aimbs_get16(&mbs);
687 * For now, we don't care what the encoding is. Just copy
688 * it into a multipart struct and deal with it later. However,
689 * always pad the ending with a NULL. This makes it easier
690 * to treat ASCII sections as strings. It won't matter for
691 * UNICODE or binary data, as you should never read past
692 * the specified data length, which will not include the pad.
694 * XXX There's an API bug here. For sending, the UNICODE is
695 * given in host byte order (aim_mpmsg_addunicode), but here
696 * the received messages are given in network byte order.
699 msgbuf = aimbs_getstr(&mbs, msglen);
700 mpmsg_addsection(sess, &args->mpmsg, flag1, flag2, msgbuf, msglen);
704 args->icbmflags |= AIM_IMFLAGS_MULTIPART; /* always set */
707 * Clients that support multiparts should never use args->msg, as it
708 * will point to an arbitrary section.
710 * Here, we attempt to provide clients that do not support multipart
711 * messages with something to look at -- hopefully a human-readable
712 * string. But, failing that, a UNICODE message, or nothing at all.
714 * Which means that even if args->msg is NULL, it does not mean the
718 for (i = 0; i < charsetpricount; i++) {
719 for (sec = args->mpmsg.parts; sec; sec = sec->next) {
721 if (sec->charset != charsetpri[i])
724 /* Great. We found one. Fill it in. */
725 args->charset = sec->charset;
726 args->charsubset = sec->charsubset;
727 args->icbmflags |= AIM_IMFLAGS_CUSTOMCHARSET;
729 /* Set up the simple flags */
730 if (args->charset == 0x0000)
732 else if (args->charset == 0x0002)
733 args->icbmflags |= AIM_IMFLAGS_UNICODE;
734 else if (args->charset == 0x0003)
735 args->icbmflags |= AIM_IMFLAGS_ISO_8859_1;
736 else if (args->charset == 0xffff)
737 ; /* no encoding (yeep!) */
739 if (args->charsubset == 0x0000)
740 ; /* standard subencoding? */
741 else if (args->charsubset == 0x000b)
742 args->icbmflags |= AIM_IMFLAGS_SUBENC_MACINTOSH;
743 else if (args->charsubset == 0xffff)
744 ; /* no subencoding */
746 /* XXX this isn't really necesary... */
747 if ( ((args.flag1 != 0x0000) &&
748 (args.flag1 != 0x0002) &&
749 (args.flag1 != 0x0003) &&
750 (args.flag1 != 0xffff)) ||
751 ((args.flag2 != 0x0000) &&
752 (args.flag2 != 0x000b) &&
753 (args.flag2 != 0xffff))) {
754 faimdprintf(sess, 0, "icbm: **warning: encoding flags are being used! {%04x, %04x}\n", args.flag1, args.flag2);
758 args->msg = sec->data;
759 args->msglen = sec->datalen;
765 /* No human-readable sections found. Oh well. */
766 args->charset = args->charsubset = 0xffff;
775 * This should use tlvlists, but doesn't for performance reasons.
777 * XXX support multipart IMs:
779 * 0004 0007 0000 8f08 d295
780 * 0031 6520 3b7b f9fd
786 * 0010 0004 0000 01a3
787 * 0002 0004 3ab6 94fa
788 * 0003 0004 3b7b f85a
791 * 0101 000a 0000 0000 3c48 544d 4c3e ASCII part
793 * 0101 0016 0003 0000 6c6b 7364 6a6b 6c6a 676c a56b 3b73 646a 6b6a
794 * 0101 000b 0000 0000 3c2f 4854 4d4c 3e another ASCII part
797 static 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)
800 aim_rxcallback_t userfunc;
802 struct aim_incomingim_ch1_args args;
805 memset(&args, 0, sizeof(args));
807 aim_mpmsg_init(sess, &args.mpmsg);
810 * This used to be done using tlvchains. For performance reasons,
811 * I've changed it to process the TLVs in-place. This avoids lots
812 * of per-IM memory allocations.
814 while (aim_bstream_empty(bs)) {
816 type = aimbs_get16(bs);
817 length = aimbs_get16(bs);
819 endpos = aim_bstream_curpos(bs) + length;
821 if (type == 0x0002) { /* Message Block */
824 * This TLV consists of the following:
826 * - Features: Don't know how to interpret these
832 aimbs_get8(bs); /* 05 */
833 aimbs_get8(bs); /* 01 */
835 args.featureslen = aimbs_get16(bs);
836 /* XXX XXX this is all evil! */
837 args.features = bs->data + bs->offset;
838 aim_bstream_advance(bs, args.featureslen);
839 args.icbmflags |= AIM_IMFLAGS_CUSTOMFEATURES;
842 * The rest of the TLV contains one or more message
845 incomingim_ch1_parsemsgs(sess, bs->data + bs->offset /* XXX evil!!! */, length - 2 - 2 - args.featureslen, &args);
847 } else if (type == 0x0003) { /* Server Ack Requested */
849 args.icbmflags |= AIM_IMFLAGS_ACK;
851 } else if (type == 0x0004) { /* Message is Auto Response */
853 args.icbmflags |= AIM_IMFLAGS_AWAY;
855 } else if (type == 0x0008) { /* I-HAVE-A-REALLY-PURTY-ICON Flag */
857 args.iconsum = aimbs_get32(bs);
858 args.iconlen = aimbs_get32(bs);
859 args.iconstamp = aimbs_get32(bs);
860 args.icbmflags |= AIM_IMFLAGS_HASICON;
862 } else if (type == 0x0009) {
864 args.icbmflags |= AIM_IMFLAGS_BUDDYREQ;
866 } else if (type == 0x0017) {
868 args.extdatalen = length;
869 args.extdata = aimbs_getraw(bs, args.extdatalen);
872 faimdprintf(sess, 0, "incomingim_ch1: unknown TLV 0x%04x (len %d)\n", type, length);
876 * This is here to protect ourselves from ourselves. That
877 * is, if something above doesn't completly parse its value
878 * section, or, worse, overparses it, this will set the
879 * stream where it needs to be in order to land on the next
880 * TLV when the loop continues.
883 aim_bstream_setpos(bs, endpos);
887 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
888 ret = userfunc(sess, rx, channel, userinfo, &args);
890 aim_mpmsg_free(sess, &args.mpmsg);
896 static int incomingim_ch2_buddylist(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, struct aim_userinfo_s *userinfo, struct aim_incomingim_ch2_args *args, aim_tlvlist_t *list2)
898 aim_rxcallback_t userfunc;
903 if (args->status != 0x0000)
904 return 1; /* ignore it -- not sure what it means */
906 tse = aim_gettlv(list2, 0x2711, 1);
907 aim_bstream_init(&tbs, tse->value, tse->length);
910 * This goes like this...
914 * num of buddies in group
922 * num of buddies in group
928 while (aim_bstream_empty(&tbs)) {
933 gnlen = aimbs_get16(&tbs);
934 gn = aimbs_getstr(&tbs, gnlen);
935 numb = aimbs_get16(&tbs);
937 for (i = 0; i < numb; i++) {
941 bnlen = aimbs_get16(&tbs);
942 bn = aimbs_getstr(&tbs, bnlen);
944 faimdprintf(sess, 0, "got a buddy list from %s: group %s, buddy %s\n", userinfo->sn, gn, bn);
952 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
953 ret = userfunc(sess, rx, 0x0002, userinfo, args);
958 static int incomingim_ch2_buddyicon(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, struct aim_userinfo_s *userinfo, struct aim_incomingim_ch2_args *args, aim_tlvlist_t *list2)
960 aim_rxcallback_t userfunc;
965 miscinfo = aim_gettlv(list2, 0x2711, 1);
966 aim_bstream_init(&tbs, miscinfo->value, miscinfo->length);
968 args->info.icon.checksum = aimbs_get32(&tbs);
969 args->info.icon.length = aimbs_get32(&tbs);
970 args->info.icon.timestamp = aimbs_get32(&tbs);
971 args->info.icon.icon = aimbs_getraw(&tbs, args->info.icon.length);
973 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
974 ret = userfunc(sess, rx, 0x0002, userinfo, args);
976 free(args->info.icon.icon);
981 static int incomingim_ch2_voice(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, struct aim_userinfo_s *userinfo, struct aim_incomingim_ch2_args *args, aim_tlvlist_t *list2)
983 aim_msgcookie_t *cachedcook;
985 aim_rxcallback_t userfunc;
987 faimdprintf(sess, 1, "rend: voice!\n");
989 if (!(cachedcook = (aim_msgcookie_t*)calloc(1, sizeof(aim_msgcookie_t))))
992 memcpy(cachedcook->cookie, args->cookie, 8);
993 cachedcook->type = AIM_COOKIETYPE_OFTVOICE;
994 cachedcook->data = NULL;
996 if (aim_cachecookie(sess, cachedcook) == -1)
997 faimdprintf(sess, 0, "ERROR caching message cookie\n");
999 /* XXX: implement all this */
1001 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
1002 ret = userfunc(sess, rx, 0x0002, userinfo, args);
1007 static int incomingim_ch2_chat(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, struct aim_userinfo_s *userinfo, struct aim_incomingim_ch2_args *args, aim_tlvlist_t *list2)
1009 aim_tlv_t *miscinfo;
1011 aim_rxcallback_t userfunc;
1014 miscinfo = aim_gettlv(list2, 0x2711, 1);
1015 aim_bstream_init(&tbs, miscinfo->value, miscinfo->length);
1017 aim_chat_readroominfo(&tbs, &args->info.chat.roominfo);
1019 if (aim_gettlv(list2, 0x000c, 1))
1020 args->info.chat.msg = aim_gettlv_str(list2, 0x000c, 1);
1022 if (aim_gettlv(list2, 0x000d, 1))
1023 args->info.chat.encoding = aim_gettlv_str(list2, 0x000d, 1);
1025 if (aim_gettlv(list2, 0x000e, 1))
1026 args->info.chat.lang = aim_gettlv_str(list2, 0x000e, 1);
1028 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
1029 ret = userfunc(sess, rx, 0x0002, userinfo, args);
1031 /* XXX free_roominfo */
1032 free(args->info.chat.roominfo.name);
1033 free(args->info.chat.msg);
1034 free(args->info.chat.encoding);
1035 free(args->info.chat.lang);
1040 static int incomingim_ch2_getfile(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, struct aim_userinfo_s *userinfo, struct aim_incomingim_ch2_args *args, aim_tlvlist_t *list2)
1043 aim_msgcookie_t *cachedcook;
1044 aim_tlv_t *miscinfo;
1045 aim_tlv_t *iptlv, *porttlv;
1047 aim_rxcallback_t userfunc;
1051 if (!(cachedcook = calloc(1, sizeof(aim_msgcookie_t)))) {
1052 aim_freetlvchain(&list2);
1056 if (!(miscinfo = aim_gettlv(list2, 0x2711, 1)) ||
1057 !(iptlv = aim_gettlv(list2, 0x0003, 1)) ||
1058 !(porttlv = aim_gettlv(list2, 0x0005, 1))) {
1060 faimdprintf(sess, 0, "rend: badly damaged file get request from %s...\n", userinfo->sn);
1061 aim_cookie_free(sess, cachedcook);
1062 aim_freetlvchain(&list2);
1067 snprintf(ip, 30, "%d.%d.%d.%d:%d",
1068 aimutil_get8(iptlv->value+0),
1069 aimutil_get8(iptlv->value+1),
1070 aimutil_get8(iptlv->value+2),
1071 aimutil_get8(iptlv->value+3),
1072 aimutil_get16(porttlv->value));
1074 faimdprintf(sess, 0, "rend: file get request from %s (%s)\n", userinfo->sn, ip);
1076 args->info.getfile.ip = ip;
1077 memcpy(args->info.getfile.cookie, args->cookie, 8);
1079 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
1080 ret = userfunc(sess, rx, 0x0002, userinfo, args);
1085 static int incomingim_ch2_sendfile(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, struct aim_userinfo_s *userinfo, struct aim_incomingim_ch2_args *args, aim_tlvlist_t *list2)
1089 aim_msgcookie_t *cachedcook;
1090 aim_tlv_t *miscinfo;
1091 aim_tlv_t *iptlv, *porttlv;
1093 aim_rxcallback_t userfunc;
1098 if (!(cachedcook = calloc(1, sizeof(aim_msgcookie_t))))
1101 if (!(miscinfo = aim_gettlv(list2, 0x2711, 1)) ||
1102 !(iptlv = aim_gettlv(list2, 0x0003, 1)) ||
1103 !(porttlv = aim_gettlv(list2, 0x0005, 1))) {
1105 faimdprintf(sess, 0, "rend: badly damaged file get request from %s...\n", userinfo->sn);
1106 aim_cookie_free(sess, cachedcook);
1111 snprintf(ip, 30, "%d.%d.%d.%d:%d",
1112 aimutil_get8(iptlv->value+0),
1113 aimutil_get8(iptlv->value+1),
1114 aimutil_get8(iptlv->value+2),
1115 aimutil_get8(iptlv->value+3),
1116 aimutil_get16(porttlv->value));
1118 if (aim_gettlv(list2, 0x000c, 1))
1119 desc = aim_gettlv_str(list2, 0x000c, 1);
1121 faimdprintf(sess, 0, "rend: file transfer request from %s: %s (%s)\n",
1122 userinfo->sn, desc, ip);
1124 memcpy(cachedcook->cookie, args->cookie, 8);
1126 ft = malloc(sizeof(struct aim_filetransfer_priv)); /* XXX */
1127 strncpy(ft->sn, userinfo.sn, sizeof(ft->sn));
1128 strncpy(ft->ip, ip, sizeof(ft->ip));
1129 strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name));
1130 cachedcook->type = AIM_COOKIETYPE_OFTSEND;
1131 cachedcook->data = ft;
1133 if (aim_cachecookie(sess, cachedcook) == -1)
1134 faimdprintf(sess, 0, "ERROR caching message cookie\n");
1136 aim_accepttransfer(sess, rx->conn, ft->sn, cookie, AIM_CAPS_SENDFILE);
1141 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
1142 ret = userfunc(sess, rx, 0x0002, userinfo, &args);
1147 static int incomingim_ch2_imimage(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, struct aim_userinfo_s *userinfo, struct aim_incomingim_ch2_args *args, aim_tlvlist_t *list2)
1149 aim_rxcallback_t userfunc;
1152 /* Primary IP address */
1153 if (aim_gettlv(list2, 0x0003, 1)) {
1156 tlv = aim_gettlv(list2, 0x0003, 1);
1158 snprintf(args->info.imimage.ip, sizeof(args->info.imimage.ip),
1167 * Alternate IP address
1169 * Sort of. The peer doesn't send this -- the OSCAR
1170 * server does. So it will be the IP address that the
1171 * peer is directly connected to the internet with, which
1172 * may not be the same as the IP above. If these two
1173 * values differ, it's rather unlikely that this
1174 * rendezvous is going to happen...
1177 if (aim_gettlv(list2, 0x0004, 1))
1180 /* Port number (not correct -- ignore) */
1181 if (aim_gettlv(list2, 0x0005, 1))
1184 /* Unknown -- two bytes = 0x0001 */
1185 if (aim_gettlv(list2, 0x000a, 1))
1188 /* Unknown -- no value */
1189 if (aim_gettlv(list2, 0x000f, 1))
1192 faimdprintf(sess, 1, "rend: directIM request from %s (%s)\n", userinfo->sn, args->info.imimage.ip);
1195 * XXX: there are a couple of different request packets for
1199 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
1200 ret = userfunc(sess, rx, 0x0002, userinfo, args);
1205 /* XXX Ugh. I think its obvious. */
1206 static 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)
1209 aim_tlvlist_t *list2;
1211 struct aim_incomingim_ch2_args args;
1215 memset(&args, 0, sizeof(args));
1218 * There's another block of TLVs embedded in the type 5 here.
1220 if (!(block1 = aim_gettlv(tlvlist, 0x0005, 1)) || !block1->value) {
1221 faimdprintf(sess, 0, "no tlv 0x0005 in rendezvous transaction!\n");
1225 aim_bstream_init(&bbs, block1->value, block1->length);
1228 * First two bytes represent the status of the connection.
1230 * 0 is a request, 2 is an accept
1232 args.status = aimbs_get16(&bbs);
1235 * Next comes the cookie. Should match the ICBM cookie.
1237 cookie2 = aimbs_getraw(&bbs, 8);
1238 if (memcmp(cookie, cookie2, 8) != 0)
1239 faimdprintf(sess, 0, "rend: warning cookies don't match!\n");
1240 memcpy(args.cookie, cookie2, 8);
1244 * The next 16bytes are a capability block so we can
1245 * identify what type of rendezvous this is.
1247 * Thanks to Eric Warmenhoven <warmenhoven@linux.com> (of GAIM)
1248 * for pointing some of this out to me. In fact, a lot of
1249 * the client-to-client info comes from the work of the GAIM
1250 * developers. Thanks!
1252 * Read off one capability string and we should have it ID'd.
1255 if ((args.reqclass = aim_getcap(sess, &bbs, 0x10)) == 0x0000) {
1256 faimdprintf(sess, 0, "rend: no ID block\n");
1261 * What follows may be TLVs or nothing, depending on the
1262 * purpose of the message.
1264 * Ack packets for instance have nothing more to them.
1266 list2 = aim_readtlvchain(&bbs);
1268 #if 0 /* this should be in the per-type blocks */
1269 if (!list2 || ((args.reqclass != AIM_CAPS_IMIMAGE) && !(aim_gettlv(list2, 0x2711, 1)))) {
1270 aim_msgcookie_t *cook;
1273 type = aim_msgcookie_gettype(args.reqclass); /* XXX: fix this shitty code */
1275 if ((cook = aim_checkcookie(sess, cookie, type)) == NULL) {
1276 faimdprintf(sess, 0, "non-data rendezvous thats not in cache (type %d)\n", type);
1277 aim_freetlvchain(&list2);
1281 if (cook->type == AIM_COOKIETYPE_OFTGET) {
1282 struct aim_filetransfer_priv *ft;
1285 int errorcode = -1; /* XXX shouldnt this be 0? */
1287 ft = (struct aim_filetransfer_priv *)cook->data;
1289 if (args.status != 0x0002) {
1291 if (aim_gettlv(list2, 0x000b, 1))
1292 errorcode = aim_gettlv16(list2, 0x000b, 1);
1294 /* XXX this should make it up to the client, you know.. */
1296 faimdprintf(sess, 0, "transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sn, ft->ip, ft->fh.name, errorcode);
1297 } /* args.status != 0x0002 */
1300 faimdprintf(sess, 0, "no data attached to file transfer\n");
1303 } else if (cook->type == AIM_CAPS_VOICE) {
1305 faimdprintf(sess, 0, "voice request cancelled\n");
1309 faimdprintf(sess, 0, "unknown cookie cache type %d\n", cook->type);
1312 aim_freetlvchain(&list2);
1319 * The rest of the handling depends on what type it is.
1321 if (args.reqclass & AIM_CAPS_BUDDYICON)
1322 ret = incomingim_ch2_buddyicon(sess, mod, rx, snac, userinfo, &args, list2);
1323 else if (args.reqclass & AIM_CAPS_SENDBUDDYLIST)
1324 ret = incomingim_ch2_buddylist(sess, mod, rx, snac, userinfo, &args, list2);
1325 else if (args.reqclass & AIM_CAPS_VOICE)
1326 ret = incomingim_ch2_voice(sess, mod, rx, snac, userinfo, &args, list2);
1327 else if (args.reqclass & AIM_CAPS_IMIMAGE)
1328 ret = incomingim_ch2_imimage(sess, mod, rx, snac, userinfo, &args, list2);
1329 else if (args.reqclass & AIM_CAPS_CHAT)
1330 ret = incomingim_ch2_chat(sess, mod, rx, snac, userinfo, &args, list2);
1331 else if (args.reqclass & AIM_CAPS_GETFILE)
1332 ret = incomingim_ch2_getfile(sess, mod, rx, snac, userinfo, &args, list2);
1333 else if (args.reqclass & AIM_CAPS_SENDFILE)
1334 ret = incomingim_ch2_sendfile(sess, mod, rx, snac, userinfo, &args, list2);
1336 faimdprintf(sess, 0, "rend: unknown rendezvous 0x%04x\n", args.reqclass);
1338 aim_freetlvchain(&list2);
1344 * It can easily be said that parsing ICBMs is THE single
1345 * most difficult thing to do in the in AIM protocol. In
1346 * fact, I think I just did say that.
1348 * Below is the best damned solution I've come up with
1349 * over the past sixteen months of battling with it. This
1350 * can parse both away and normal messages from every client
1351 * I have access to. Its not fast, its not clean. But it works.
1354 static int incomingim(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
1359 struct aim_userinfo_s userinfo;
1361 memset(&userinfo, 0x00, sizeof(struct aim_userinfo_s));
1364 * Read ICBM Cookie. And throw away.
1366 for (i = 0; i < 8; i++)
1367 cookie[i] = aimbs_get8(bs);
1372 * Channel 0x0001 is the message channel. There are
1373 * other channels for things called "rendevous"
1374 * which represent chat and some of the other new
1375 * features of AIM2/3/3.5.
1377 * Channel 0x0002 is the Rendevous channel, which
1378 * is where Chat Invitiations and various client-client
1379 * connection negotiations come from.
1382 channel = aimbs_get16(bs);
1385 * Technically Channel 3 in chat could be done here too.
1387 if ((channel != 0x01) && (channel != 0x02)) {
1388 faimdprintf(sess, 0, "icbm: ICBM received on an unsupported channel. Ignoring.\n (chan = %04x)", channel);
1393 * Extract the standard user info block.
1395 * Note that although this contains TLVs that appear contiguous
1396 * with the TLVs read below, they are two different pieces. The
1397 * userinfo block contains the number of TLVs that contain user
1398 * information, the rest are not even though there is no seperation.
1399 * aim_extractuserinfo() returns the number of bytes used by the
1400 * userinfo tlvs, so you can start reading the rest of them right
1403 * That also means that TLV types can be duplicated between the
1404 * userinfo block and the rest of the message, however there should
1405 * never be two TLVs of the same type in one block.
1408 aim_extractuserinfo(sess, bs, &userinfo);
1411 * From here on, its depends on what channel we're on.
1413 * Technically all channels have a TLV list have this, however,
1414 * for the common channel 1 case, in-place parsing is used for
1415 * performance reasons (less memory allocation).
1419 ret = incomingim_ch1(sess, mod, rx, snac, channel, &userinfo, bs, cookie);
1421 } else if (channel == 0x0002) {
1422 aim_tlvlist_t *tlvlist;
1425 * Read block of TLVs (not including the userinfo data). All
1426 * further data is derived from what is parsed here.
1428 tlvlist = aim_readtlvchain(bs);
1430 ret = incomingim_ch2(sess, mod, rx, snac, channel, &userinfo, tlvlist, cookie);
1433 * Free up the TLV chain.
1435 aim_freetlvchain(&tlvlist);
1443 * AIM_TRANSFER_DENY_NOTSUPPORTED -- "client does not support"
1444 * AIM_TRANSFER_DENY_DECLINE -- "client has declined transfer"
1445 * AIM_TRANSFER_DENY_NOTACCEPTING -- "client is not accepting transfers"
1448 faim_export int aim_denytransfer(aim_session_t *sess, aim_conn_t *conn, const char *sender, const char *cookie, fu16_t code)
1451 aim_snacid_t snacid;
1452 aim_tlvlist_t *tl = NULL;
1454 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+8+2+1+strlen(sender)+6)))
1457 snacid = aim_cachesnac(sess, 0x0004, 0x000b, 0x0000, NULL, 0);
1458 aim_putsnac(&fr->data, 0x0004, 0x000b, 0x0000, snacid);
1460 aimbs_putraw(&fr->data, cookie, 8);
1462 aimbs_put16(&fr->data, 0x0002); /* channel */
1463 aimbs_put8(&fr->data, strlen(sender));
1464 aimbs_putraw(&fr->data, sender, strlen(sender));
1466 aim_addtlvtochain16(&tl, 0x0003, code);
1467 aim_writetlvchain(&fr->data, &tl);
1468 aim_freetlvchain(&tl);
1470 aim_tx_enqueue(sess, fr);
1476 * aim_reqicbmparaminfo()
1478 * Request ICBM parameter information.
1481 faim_export int aim_reqicbmparams(aim_session_t *sess, aim_conn_t *conn)
1483 return aim_genericreq_n(sess, conn, 0x0004, 0x0004);
1488 * I definitly recommend sending this. If you don't, you'll be stuck
1489 * with the rather unreasonable defaults. You don't want those. Send this.
1492 faim_export int aim_seticbmparam(aim_session_t *sess, aim_conn_t *conn, struct aim_icbmparameters *params)
1495 aim_snacid_t snacid;
1497 if (!sess || !conn || !params)
1500 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+16)))
1503 snacid = aim_cachesnac(sess, 0x0004, 0x0002, 0x0000, NULL, 0);
1504 aim_putsnac(&fr->data, 0x0004, 0x0002, 0x0000, snacid);
1506 /* This is read-only (see Parameter Reply). Must be set to zero here. */
1507 aimbs_put16(&fr->data, 0x0000);
1509 /* These are all read-write */
1510 aimbs_put32(&fr->data, params->flags);
1511 aimbs_put16(&fr->data, params->maxmsglen);
1512 aimbs_put16(&fr->data, params->maxsenderwarn);
1513 aimbs_put16(&fr->data, params->maxrecverwarn);
1514 aimbs_put32(&fr->data, params->minmsginterval);
1516 aim_tx_enqueue(sess, fr);
1521 static int paraminfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
1523 struct aim_icbmparameters params;
1524 aim_rxcallback_t userfunc;
1526 params.maxchan = aimbs_get16(bs);
1527 params.flags = aimbs_get32(bs);
1528 params.maxmsglen = aimbs_get16(bs);
1529 params.maxsenderwarn = aimbs_get16(bs);
1530 params.maxrecverwarn = aimbs_get16(bs);
1531 params.minmsginterval = aimbs_get32(bs);
1533 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
1534 return userfunc(sess, rx, ¶ms);
1539 static int missedcall(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
1542 aim_rxcallback_t userfunc;
1543 fu16_t channel, nummissed, reason;
1544 struct aim_userinfo_s userinfo;
1546 while (aim_bstream_empty(bs)) {
1548 channel = aimbs_get16(bs);
1549 aim_extractuserinfo(sess, bs, &userinfo);
1550 nummissed = aimbs_get16(bs);
1551 reason = aimbs_get16(bs);
1553 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
1554 ret = userfunc(sess, rx, channel, &userinfo, nummissed, reason);
1560 static int clienterr(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
1563 aim_rxcallback_t userfunc;
1564 fu16_t channel, reason;
1568 ck = aimbs_getraw(bs, 8);
1569 channel = aimbs_get16(bs);
1570 snlen = aimbs_get8(bs);
1571 sn = aimbs_getstr(bs, snlen);
1572 reason = aimbs_get16(bs);
1574 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
1575 ret = userfunc(sess, rx, channel, sn, reason);
1580 static int msgack(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
1582 aim_rxcallback_t userfunc;
1587 ck = aimbs_getraw(bs, 8);
1588 type = aimbs_get16(bs);
1589 snlen = aimbs_get8(bs);
1590 sn = aimbs_getstr(bs, snlen);
1592 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
1593 return userfunc(sess, rx, type, sn);
1601 static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
1604 if (snac->subtype == 0x0005)
1605 return paraminfo(sess, mod, rx, snac, bs);
1606 else if (snac->subtype == 0x0006)
1607 return outgoingim(sess, mod, rx, snac, bs);
1608 else if (snac->subtype == 0x0007)
1609 return incomingim(sess, mod, rx, snac, bs);
1610 else if (snac->subtype == 0x000a)
1611 return missedcall(sess, mod, rx, snac, bs);
1612 else if (snac->subtype == 0x000b)
1613 return clienterr(sess, mod, rx, snac, bs);
1614 else if (snac->subtype == 0x000c)
1615 return msgack(sess, mod, rx, snac, bs);
1620 faim_internal int msg_modfirst(aim_session_t *sess, aim_module_t *mod)
1623 mod->family = 0x0004;
1624 mod->version = 0x0000;
1626 strncpy(mod->name, "messaging", sizeof(mod->name));
1627 mod->snachandler = snachandler;