4 * The routines for sending/receiving Instant Messages.
12 * Takes a msghdr (and a length) and returns a client type
13 * code. Note that this is *only a guess* and has a low likelihood
14 * of actually being accurate.
16 * Its based on experimental data, with the help of Eric Warmenhoven
17 * who seems to have collected a wide variety of different AIM clients.
20 * Heres the current collection:
21 * 0501 0003 0101 0101 01 AOL Mobile Communicator, WinAIM 1.0.414
22 * 0501 0003 0101 0201 01 WinAIM 2.0.847, 2.1.1187, 3.0.1464,
24 * 0501 0004 0101 0102 0101 WinAIM 4.1.2010, libfaim (right here)
25 * 0501 0001 0101 01 AOL v6.0, CompuServe 2000 v6.0, any
28 faim_export unsigned short aim_fingerprintclient(unsigned char *msghdr, int len)
31 unsigned short clientid;
33 unsigned char data[10];
35 /* AOL Mobile Communicator, WinAIM 1.0.414 */
37 9, {0x05, 0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01}},
39 /* WinAIM 2.0.847, 2.1.1187, 3.0.1464, 4.3.2229, 4.4.2286 */
40 { AIM_CLIENTTYPE_WINAIM,
41 9, {0x05, 0x01, 0x00, 0x03, 0x01, 0x01, 0x02, 0x01, 0x01}},
43 /* WinAIM 4.1.2010, libfaim */
44 { AIM_CLIENTTYPE_WINAIM41,
45 10, {0x05, 0x01, 0x00, 0x04, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01}},
47 /* AOL v6.0, CompuServe 2000 v6.0, any TOC client */
48 { AIM_CLIENTTYPE_AOL_TOC,
49 7, {0x05, 0x01, 0x00, 0x01, 0x01, 0x01, 0x01}},
55 if (!msghdr || (len <= 0))
58 for (i = 0; fingerprints[i].len; i++) {
59 if (fingerprints[i].len != len)
61 if (memcmp(fingerprints[i].data, msghdr, fingerprints[i].len) == 0)
62 return fingerprints[i].clientid;
65 return AIM_CLIENTTYPE_UNKNOWN;
69 * Send an ICBM (instant message).
73 * AIM_IMFLAGS_AWAY -- Marks the message as an autoresponse
74 * AIM_IMFLAGS_ACK -- Requests that the server send an ack
75 * when the message is received (of type 0x0004/0x000c)
78 faim_export unsigned long aim_send_im(struct aim_session_t *sess, struct aim_conn_t *conn, const char *destsn, unsigned short flags, const char *msg, int msglen)
81 struct command_tx_struct *newpacket;
83 if (!msg || (msglen <= 0))
86 if (msglen >= MAXMSGLEN)
89 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, msglen+256)))
92 newpacket->lock = 1; /* lock struct */
95 curbyte += aim_putsnac(newpacket->data+curbyte,
96 0x0004, 0x0006, 0x0000, sess->snac_nextid);
99 * Generate a random message cookie
101 * We could cache these like we do SNAC IDs. (In fact, it
102 * might be a good idea.) In the message error functions,
103 * the 8byte message cookie is returned as well as the
108 curbyte += aimutil_put8(newpacket->data+curbyte, (u_char) rand());
113 curbyte += aimutil_put16(newpacket->data+curbyte,0x0001);
116 * Destination SN (prepended with byte length)
118 curbyte += aimutil_put8(newpacket->data+curbyte,strlen(destsn));
119 curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn));
124 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
125 curbyte += aimutil_put16(newpacket->data+curbyte, msglen + 0x10);
128 * Flag data / ICBM Parameters?
130 * I don't know what these are...
133 curbyte += aimutil_put8(newpacket->data+curbyte, 0x05);
134 curbyte += aimutil_put8(newpacket->data+curbyte, 0x01);
136 /* number of bytes to follow */
137 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0004);
138 curbyte += aimutil_put8(newpacket->data+curbyte, 0x01);
139 curbyte += aimutil_put8(newpacket->data+curbyte, 0x01);
140 curbyte += aimutil_put8(newpacket->data+curbyte, 0x01);
141 curbyte += aimutil_put8(newpacket->data+curbyte, 0x02);
143 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0101);
146 * Message block length.
148 curbyte += aimutil_put16(newpacket->data+curbyte, msglen + 0x04);
151 * Character set data?
153 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
154 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
157 * Message. Not terminated.
159 curbyte += aimutil_putstr(newpacket->data+curbyte,msg, msglen);
162 * Set the Request Acknowledge flag.
164 if (flags & AIM_IMFLAGS_ACK) {
165 curbyte += aimutil_put16(newpacket->data+curbyte,0x0003);
166 curbyte += aimutil_put16(newpacket->data+curbyte,0x0000);
170 * Set the Autoresponse flag.
172 if (flags & AIM_IMFLAGS_AWAY) {
173 curbyte += aimutil_put16(newpacket->data+curbyte,0x0004);
174 curbyte += aimutil_put16(newpacket->data+curbyte,0x0000);
177 newpacket->commandlen = curbyte;
180 aim_tx_enqueue(sess, newpacket);
182 aim_cachesnac(sess, 0x0004, 0x0006, 0x0000, destsn, strlen(destsn)+1);
183 aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */
185 return sess->snac_nextid;
188 static int outgoingim(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
190 unsigned int i, ret = 0;
191 aim_rxcallback_t userfunc;
192 unsigned char cookie[8];
194 struct aim_tlvlist_t *tlvlist;
196 unsigned short icbmflags = 0;
197 unsigned char flag1 = 0, flag2 = 0;
198 unsigned char *msgblock = NULL, *msg = NULL;
201 for (i = 0; i < 8; i++)
202 cookie[i] = aimutil_get8(data+i);
205 channel = aimutil_get16(data+i);
208 if (channel != 0x01) {
209 faimdprintf(sess, 0, "icbm: ICBM recieved on unsupported channel. Ignoring. (chan = %04x)\n", channel);
213 strncpy(sn, (char *) data+i+1, (int) *(data+i));
214 i += 1 + (int) *(data+i);
216 tlvlist = aim_readtlvchain(data+i, datalen-i);
218 if (aim_gettlv(tlvlist, 0x0003, 1))
219 icbmflags |= AIM_IMFLAGS_ACK;
220 if (aim_gettlv(tlvlist, 0x0004, 1))
221 icbmflags |= AIM_IMFLAGS_AWAY;
223 if (aim_gettlv(tlvlist, 0x0002, 1)) {
226 msgblock = (unsigned char *)aim_gettlv_str(tlvlist, 0x0002, 1);
228 /* no, this really is correct. I'm not high or anything either. */
230 j += 2 + aimutil_get16(msgblock+j);
233 j += 2; /* final block length */
235 flag1 = aimutil_get16(msgblock);
237 flag2 = aimutil_get16(msgblock);
243 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
244 ret = userfunc(sess, rx, channel, sn, msg, icbmflags, flag1, flag2);
248 aim_freetlvchain(&tlvlist);
253 static int incomingim_ch1(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned short channel, struct aim_userinfo_s *userinfo, struct aim_tlvlist_t *tlvlist, unsigned char *cookie)
255 aim_rxcallback_t userfunc;
256 int i, j = 0, y = 0, z = 0, ret = 0;
258 unsigned long icbmflags = 0;
259 struct aim_tlv_t *msgblocktlv;
260 unsigned char *msgblock;
261 unsigned short flag1, flag2;
263 unsigned char fingerprint[10];
264 unsigned short wastebits;
267 * Check Autoresponse status. If it is an autoresponse,
268 * it will contain a type 0x0004 TLV, with zero length.
270 if (aim_gettlv(tlvlist, 0x0004, 1))
271 icbmflags |= AIM_IMFLAGS_AWAY;
274 * Check Ack Request status.
276 if (aim_gettlv(tlvlist, 0x0003, 1))
277 icbmflags |= AIM_IMFLAGS_ACK;
282 msgblocktlv = aim_gettlv(tlvlist, 0x0002, 1);
283 if (!msgblocktlv || !(msgblock = msgblocktlv->value)) {
284 faimdprintf(sess, 0, "icbm: major error! no message block TLV found!\n");
289 * Extracting the message from the unknown cruft.
291 * This is a bit messy, and I'm not really qualified,
292 * even as the author, to comment on it. At least
293 * its not as bad as a while loop shooting into infinity.
295 * "Do you believe in magic?"
299 wastebits = aimutil_get8(msgblock+j++);
300 wastebits = aimutil_get8(msgblock+j++);
302 y = aimutil_get16(msgblock+j);
304 for (z = 0; z < y; z++)
305 wastebits = aimutil_get8(msgblock+j++);
306 wastebits = aimutil_get8(msgblock+j++);
307 wastebits = aimutil_get8(msgblock+j++);
310 if (finlen > sizeof(fingerprint))
311 finlen = sizeof(fingerprint);
312 memcpy(fingerprint, msgblocktlv->value, finlen);
315 * Message string length, including flag words.
317 i = aimutil_get16(msgblock+j);
323 * Its rumored that these can kick in some funky
324 * 16bit-wide char stuff that used to really kill
325 * libfaim. Hopefully the latter is no longer true.
327 * Though someone should investiagte the former.
330 flag1 = aimutil_get16(msgblock+j);
332 flag2 = aimutil_get16(msgblock+j);
336 faimdprintf(sess, 0, "icbm: **warning: encoding flags are being used! {%04x, %04x}\n", flag1, flag2);
342 msg = (char *)malloc(i+1);
343 memcpy(msg, msgblock+j, i);
346 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
347 ret = userfunc(sess, rx, channel, userinfo, msg, icbmflags, flag1, flag2, finlen, fingerprint);
354 static int incomingim_ch2(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned short channel, struct aim_userinfo_s *userinfo, struct aim_tlvlist_t *tlvlist, unsigned char *cookie)
356 aim_rxcallback_t userfunc;
357 struct aim_tlv_t *block1;
358 struct aim_tlvlist_t *list2;
359 unsigned short reqclass = 0;
360 unsigned short status = 0;
364 * There's another block of TLVs embedded in the type 5 here.
366 block1 = aim_gettlv(tlvlist, 0x0005, 1);
367 if (!block1 || !block1->value) {
368 faimdprintf(sess, 0, "no tlv 0x0005 in rendezvous transaction!\n");
373 * First two bytes represent the status of the connection.
375 * 0 is a request, 2 is an accept
377 status = aimutil_get16(block1->value+0);
380 * Next comes the cookie. Should match the ICBM cookie.
382 if (memcmp(block1->value+2, cookie, 8) != 0)
383 faimdprintf(sess, 0, "rend: warning cookies don't match!\n");
386 * The next 16bytes are a capability block so we can
387 * identify what type of rendezvous this is.
389 * Thanks to Eric Warmenhoven <warmenhoven@linux.com> (of GAIM)
390 * for pointing some of this out to me. In fact, a lot of
391 * the client-to-client info comes from the work of the GAIM
392 * developers. Thanks!
394 * Read off one capability string and we should have it ID'd.
397 reqclass = aim_getcap(sess, block1->value+2+8, 0x10);
398 if (reqclass == 0x0000) {
399 faimdprintf(sess, 0, "rend: no ID block\n");
404 * What follows may be TLVs or nothing, depending on the
405 * purpose of the message.
407 * Ack packets for instance have nothing more to them.
409 list2 = aim_readtlvchain(block1->value+2+8+16, block1->length-2-8-16);
411 if (!list2 || ((reqclass != AIM_CAPS_IMIMAGE) && !(aim_gettlv(list2, 0x2711, 1)))) {
412 struct aim_msgcookie_t *cook;
415 type = aim_msgcookie_gettype(reqclass); /* XXX: fix this shitty code */
417 if ((cook = aim_checkcookie(sess, cookie, type)) == NULL) {
418 faimdprintf(sess, 0, "non-data rendezvous thats not in cache %d/%s!\n", type, cookie);
419 aim_freetlvchain(&list2);
423 if (cook->type == AIM_COOKIETYPE_OFTGET) {
424 struct aim_filetransfer_priv *ft;
427 int errorcode = -1; /* XXX shouldnt this be 0? */
429 ft = (struct aim_filetransfer_priv *)cook->data;
431 if(status != 0x0002) {
432 if (aim_gettlv(list2, 0x000b, 1))
433 errorcode = aim_gettlv16(list2, 0x000b, 1);
435 /* XXX this should make it up to the client, you know.. */
437 faimdprintf(sess, 0, "transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sn, ft->ip, ft->fh.name, errorcode);
440 faimdprintf(sess, 0, "no data attached to file transfer\n");
442 } else if (cook->type == AIM_CAPS_VOICE) {
443 faimdprintf(sess, 0, "voice request cancelled\n");
445 faimdprintf(sess, 0, "unknown cookie cache type %d\n", cook->type);
448 aim_freetlvchain(&list2);
454 * The rest of the handling depends on what type it is.
456 if (reqclass & AIM_CAPS_BUDDYICON) {
458 /* XXX implement this (its in ActiveBuddy...) */
459 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
460 ret = userfunc(sess, rx, channel, reqclass, userinfo);
462 } else if (reqclass & AIM_CAPS_VOICE) {
463 struct aim_msgcookie_t *cachedcook;
465 faimdprintf(sess, 0, "rend: voice!\n");
467 if(!(cachedcook = (struct aim_msgcookie_t*)calloc(1, sizeof(struct aim_msgcookie_t)))) {
468 aim_freetlvchain(&list2);
472 memcpy(cachedcook->cookie, cookie, 8);
473 cachedcook->type = AIM_COOKIETYPE_OFTVOICE;
474 cachedcook->data = NULL;
476 if (aim_cachecookie(sess, cachedcook) == -1)
477 faimdprintf(sess, 0, "ERROR caching message cookie\n");
479 /* XXX: implement all this */
481 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
482 ret = userfunc(sess, rx, channel, reqclass, &userinfo);
484 } else if ((reqclass & AIM_CAPS_IMIMAGE) ||
485 (reqclass & AIM_CAPS_BUDDYICON)) {
487 struct aim_directim_priv *priv;
489 memset(ip, 0, sizeof(ip));
491 if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) {
492 struct aim_tlv_t *iptlv, *porttlv;
494 iptlv = aim_gettlv(list2, 0x0003, 1);
495 porttlv = aim_gettlv(list2, 0x0005, 1);
497 snprintf(ip, 30, "%d.%d.%d.%d:%d",
498 aimutil_get8(iptlv->value+0),
499 aimutil_get8(iptlv->value+1),
500 aimutil_get8(iptlv->value+2),
501 aimutil_get8(iptlv->value+3),
502 4443 /*aimutil_get16(porttlv->value)*/);
505 faimdprintf(sess, 0, "rend: directIM request from %s (%s)\n",
509 * XXX: there are a couple of different request packets for
513 priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv));
514 memcpy(priv->ip, ip, sizeof(priv->ip));
515 memcpy(priv->sn, userinfo->sn, sizeof(priv->sn));
516 memcpy(priv->cookie, cookie, sizeof(priv->cookie));
518 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
519 ret = userfunc(sess, rx, channel, reqclass, userinfo, priv);
521 } else if (reqclass & AIM_CAPS_CHAT) {
522 struct aim_tlv_t *miscinfo;
523 struct aim_chat_roominfo roominfo;
524 char *msg=NULL,*encoding=NULL,*lang=NULL;
526 miscinfo = aim_gettlv(list2, 0x2711, 1);
527 aim_chat_readroominfo(miscinfo->value, &roominfo);
529 if (aim_gettlv(list2, 0x000c, 1))
530 msg = aim_gettlv_str(list2, 0x000c, 1);
532 if (aim_gettlv(list2, 0x000d, 1))
533 encoding = aim_gettlv_str(list2, 0x000d, 1);
535 if (aim_gettlv(list2, 0x000e, 1))
536 lang = aim_gettlv_str(list2, 0x000e, 1);
538 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
539 ret = userfunc(sess, rx, channel, reqclass, userinfo, &roominfo, msg, encoding?encoding+1:NULL, lang?lang+1:NULL);
546 } else if (reqclass & AIM_CAPS_GETFILE) {
548 struct aim_msgcookie_t *cachedcook;
549 struct aim_tlv_t *miscinfo;
550 struct aim_tlv_t *iptlv, *porttlv;
554 if (!(cachedcook = calloc(1, sizeof(struct aim_msgcookie_t)))) {
555 aim_freetlvchain(&list2);
559 if (!(miscinfo = aim_gettlv(list2, 0x2711, 1)) ||
560 !(iptlv = aim_gettlv(list2, 0x0003, 1)) ||
561 !(porttlv = aim_gettlv(list2, 0x0005, 1))) {
562 faimdprintf(sess, 0, "rend: badly damaged file get request from %s...\n", userinfo->sn);
563 aim_cookie_free(sess, cachedcook);
564 aim_freetlvchain(&list2);
568 snprintf(ip, 30, "%d.%d.%d.%d:%d",
569 aimutil_get8(iptlv->value+0),
570 aimutil_get8(iptlv->value+1),
571 aimutil_get8(iptlv->value+2),
572 aimutil_get8(iptlv->value+3),
573 aimutil_get16(porttlv->value));
575 faimdprintf(sess, 0, "rend: file get request from %s (%s)\n", userinfo->sn, ip);
576 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
577 ret = userfunc(sess, rx, channel, reqclass, userinfo, ip, cookie);
579 } else if (reqclass & AIM_CAPS_SENDFILE) {
582 struct aim_msgcookie_t *cachedcook;
583 struct aim_tlv_t *miscinfo;
584 struct aim_tlv_t *iptlv, *porttlv;
588 if (!(cachedcook = calloc(1, sizeof(struct aim_msgcookie_t)))) {
589 aim_freetlvchain(&list2);
593 if (!(miscinfo = aim_gettlv(list2, 0x2711, 1)) ||
594 !(iptlv = aim_gettlv(list2, 0x0003, 1)) ||
595 !(porttlv = aim_gettlv(list2, 0x0005, 1))) {
596 faimdprintf(sess, 0, "rend: badly damaged file get request from %s...\n", userinfo->sn);
597 aim_cookie_free(sess, cachedcook);
598 aim_freetlvchain(&list2);
602 snprintf(ip, 30, "%d.%d.%d.%d:%d",
603 aimutil_get8(iptlv->value+0),
604 aimutil_get8(iptlv->value+1),
605 aimutil_get8(iptlv->value+2),
606 aimutil_get8(iptlv->value+3),
607 aimutil_get16(porttlv->value));
609 if (aim_gettlv(list2, 0x000c, 1))
610 desc = aim_gettlv_str(list2, 0x000c, 1);
612 faimdprintf(sess, 0, "rend: file transfer request from %s for %s: %s (%s)\n",
613 userinfo->sn, miscinfo->value+8,
616 memcpy(cachedcook->cookie, cookie, 8);
618 ft = malloc(sizeof(struct aim_filetransfer_priv));
619 strncpy(ft->sn, userinfo.sn, sizeof(ft->sn));
620 strncpy(ft->ip, ip, sizeof(ft->ip));
621 strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name));
622 cachedcook->type = AIM_COOKIETYPE_OFTSEND;
623 cachedcook->data = ft;
625 if (aim_cachecookie(sess, cachedcook) == -1)
626 faimdprintf(sess, 0, "ERROR caching message cookie\n");
628 aim_accepttransfer(sess, rx->conn, ft->sn, cookie, AIM_CAPS_SENDFILE);
633 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
634 ret = userfunc(sess, rx, channel, reqclass, userinfo);
638 faimdprintf(sess, 0, "rend: unknown rendezvous 0x%04x\n", reqclass);
640 aim_freetlvchain(&list2);
646 * It can easily be said that parsing ICBMs is THE single
647 * most difficult thing to do in the in AIM protocol. In
648 * fact, I think I just did say that.
650 * Below is the best damned solution I've come up with
651 * over the past sixteen months of battling with it. This
652 * can parse both away and normal messages from every client
653 * I have access to. Its not fast, its not clean. But it works.
656 static int incomingim(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
659 unsigned char cookie[8];
661 struct aim_tlvlist_t *tlvlist;
662 struct aim_userinfo_s userinfo;
664 memset(&userinfo, 0x00, sizeof(struct aim_userinfo_s));
667 * Read ICBM Cookie. And throw away.
669 for (i = 0; i < 8; i++)
670 cookie[i] = aimutil_get8(data+i);
675 * Channel 0x0001 is the message channel. There are
676 * other channels for things called "rendevous"
677 * which represent chat and some of the other new
678 * features of AIM2/3/3.5.
680 * Channel 0x0002 is the Rendevous channel, which
681 * is where Chat Invitiations and various client-client
682 * connection negotiations come from.
685 channel = aimutil_get16(data+i);
691 if ((channel != 0x01) && (channel != 0x02)) {
692 faimdprintf(sess, 0, "icbm: ICBM received on an unsupported channel. Ignoring.\n (chan = %04x)", channel);
697 * Extract the standard user info block.
699 * Note that although this contains TLVs that appear contiguous
700 * with the TLVs read below, they are two different pieces. The
701 * userinfo block contains the number of TLVs that contain user
702 * information, the rest are not even though there is no seperation.
703 * aim_extractuserinfo() returns the number of bytes used by the
704 * userinfo tlvs, so you can start reading the rest of them right
707 * That also means that TLV types can be duplicated between the
708 * userinfo block and the rest of the message, however there should
709 * never be two TLVs of the same type in one block.
712 i += aim_extractuserinfo(sess, data+i, &userinfo);
715 * Read block of TLVs (not including the userinfo data). All
716 * further data is derived from what is parsed here.
718 tlvlist = aim_readtlvchain(data+i, datalen-i);
721 * From here on, its depends on what channel we're on.
724 ret = incomingim_ch1(sess, mod, rx, snac, channel, &userinfo, tlvlist, cookie);
725 else if (channel == 0x0002)
726 ret = incomingim_ch2(sess, mod, rx, snac, channel, &userinfo, tlvlist, cookie);
729 * Free up the TLV chain.
731 aim_freetlvchain(&tlvlist);
738 * AIM_TRANSFER_DENY_NOTSUPPORTED -- "client does not support"
739 * AIM_TRANSFER_DENY_DECLINE -- "client has declined transfer"
740 * AIM_TRANSFER_DENY_NOTACCEPTING -- "client is not accepting transfers"
743 faim_export unsigned long aim_denytransfer(struct aim_session_t *sess,
744 struct aim_conn_t *conn,
749 struct command_tx_struct *newpacket;
752 if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+8+2+1+strlen(sender)+6)))
757 curbyte = aim_putsnac(newpacket->data, 0x0004, 0x000b, 0x0000, sess->snac_nextid);
758 for (i = 0; i < 8; i++)
759 curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]);
760 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
761 curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sender));
762 curbyte += aimutil_putstr(newpacket->data+curbyte, sender, strlen(sender));
763 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0003, code);
766 aim_tx_enqueue(sess, newpacket);
768 return (sess->snac_nextid++);
772 * Not real sure what this does, nor does anyone I've talk to.
774 * Didn't use to send it. But now I think it might be a good
778 faim_export unsigned long aim_seticbmparam(struct aim_session_t *sess,
779 struct aim_conn_t *conn)
781 struct command_tx_struct *newpacket;
784 if(!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+16)))
789 curbyte = aim_putsnac(newpacket->data, 0x0004, 0x0002, 0x0000, sess->snac_nextid);
790 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
791 curbyte += aimutil_put32(newpacket->data+curbyte, 0x00000003);
792 curbyte += aimutil_put16(newpacket->data+curbyte, 0x1f40);
793 curbyte += aimutil_put16(newpacket->data+curbyte, 0x03e7);
794 curbyte += aimutil_put16(newpacket->data+curbyte, 0x03e7);
795 curbyte += aimutil_put32(newpacket->data+curbyte, 0x00000000);
798 aim_tx_enqueue(sess, newpacket);
800 return (sess->snac_nextid++);
803 static int paraminfo(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
805 unsigned long defflags, minmsginterval;
806 unsigned short maxicbmlen, maxsenderwarn, maxrecverwarn, maxchannel;
807 aim_rxcallback_t userfunc;
810 maxchannel = aimutil_get16(data+i);
813 defflags = aimutil_get32(data+i);
816 maxicbmlen = aimutil_get16(data+i);
819 maxsenderwarn = aimutil_get16(data+i);
822 maxrecverwarn = aimutil_get16(data+i);
825 minmsginterval = aimutil_get32(data+i);
828 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
829 return userfunc(sess, rx, maxchannel, defflags, maxicbmlen, maxsenderwarn, maxrecverwarn, minmsginterval);
834 static int missedcall(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
837 aim_rxcallback_t userfunc;
838 unsigned short channel, nummissed, reason;
839 struct aim_userinfo_s userinfo;
842 * XXX: supposedly, this entire packet can repeat as many times
843 * as necessary. Should implement that.
849 channel = aimutil_get16(data+i);
853 * Extract the standard user info block.
855 i += aim_extractuserinfo(sess, data+i, &userinfo);
857 nummissed = aimutil_get16(data+i);
860 reason = aimutil_get16(data+i);
863 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
864 return userfunc(sess, rx, channel, &userinfo, nummissed, reason);
869 static int msgack(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
871 aim_rxcallback_t userfunc;
881 type = aimutil_get16(data+i);
884 snlen = aimutil_get8(data+i);
887 memset(sn, 0, sizeof(sn));
888 strncpy(sn, (char *)data+i, snlen);
890 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
891 return userfunc(sess, rx, type, sn);
896 static int snachandler(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen)
899 if (snac->subtype == 0x0005)
900 return paraminfo(sess, mod, rx, snac, data, datalen);
901 else if (snac->subtype == 0x0006)
902 return outgoingim(sess, mod, rx, snac, data, datalen);
903 else if (snac->subtype == 0x0007)
904 return incomingim(sess, mod, rx, snac, data, datalen);
905 else if (snac->subtype == 0x000a)
906 return missedcall(sess, mod, rx, snac, data, datalen);
907 else if (snac->subtype == 0x000c)
908 return msgack(sess, mod, rx, snac, data, datalen);
913 faim_internal int msg_modfirst(struct aim_session_t *sess, aim_module_t *mod)
916 mod->family = 0x0004;
917 mod->version = 0x0000;
919 strncpy(mod->name, "messaging", sizeof(mod->name));
920 mod->snachandler = snachandler;