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,
79 struct aim_conn_t *conn,
80 char *destsn, u_int flags, char *msg)
84 struct command_tx_struct *newpacket;
86 if (strlen(msg) >= MAXMSGLEN)
89 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, strlen(msg)+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, strlen(msg) + 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, strlen(msg) + 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, strlen(msg));
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 faim_internal int aim_parse_outgoing_im_middle(struct aim_session_t *sess,
189 struct command_rx_struct *command)
191 unsigned int i = 0, z;
192 rxcallback_t userfunc = NULL;
193 unsigned char cookie[8];
195 struct aim_tlvlist_t *tlvlist;
197 unsigned short icbmflags = 0;
198 unsigned char flag1 = 0, flag2 = 0;
199 unsigned char *msgblock = NULL, *msg = NULL;
204 for (z=0; z<8; z++,i++)
205 cookie[z] = command->data[i];
208 channel = aimutil_get16(command->data+i);
211 if (channel != 0x01) {
212 printf("faim: icbm: ICBM recieved on unsupported channel. Ignoring. (chan = %04x)\n", channel);
216 strncpy(sn, (char *) command->data+i+1, (int) *(command->data+i));
217 i += 1 + (int) *(command->data+i);
219 tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i);
221 if (aim_gettlv(tlvlist, 0x0003, 1))
222 icbmflags |= AIM_IMFLAGS_ACK;
223 if (aim_gettlv(tlvlist, 0x0004, 1))
224 icbmflags |= AIM_IMFLAGS_AWAY;
226 if (aim_gettlv(tlvlist, 0x0002, 1)) {
229 msgblock = (unsigned char *)aim_gettlv_str(tlvlist, 0x0002, 1);
231 /* no, this really is correct. I'm not high or anything either. */
233 j += 2 + aimutil_get16(msgblock+j);
236 j += 2; /* final block length */
238 flag1 = aimutil_get16(msgblock);
240 flag2 = aimutil_get16(msgblock);
246 if ((userfunc = aim_callhandler(command->conn, 0x0004, 0x0006)) || (i = 0))
247 i = userfunc(sess, command, channel, sn, msg, icbmflags, flag1, flag2);
251 aim_freetlvchain(&tlvlist);
257 * It can easily be said that parsing ICBMs is THE single
258 * most difficult thing to do in the in AIM protocol. In
259 * fact, I think I just did say that.
261 * Below is the best damned solution I've come up with
262 * over the past sixteen months of battling with it. This
263 * can parse both away and normal messages from every client
264 * I have access to. Its not fast, its not clean. But it works.
266 * We should also support at least minimal parsing of
267 * Channel 2, so that we can at least know the name of the
268 * room we're invited to, but obviously can't attend...
271 faim_internal int aim_parse_incoming_im_middle(struct aim_session_t *sess,
272 struct command_rx_struct *command)
275 rxcallback_t userfunc = NULL;
278 struct aim_tlvlist_t *tlvlist;
279 struct aim_userinfo_s userinfo;
281 memset(&userinfo, 0x00, sizeof(struct aim_userinfo_s));
283 i = 10; /* Skip SNAC header */
286 * Read ICBM Cookie. And throw away.
288 for (z=0; z<8; z++,i++)
289 cookie[z] = command->data[i];
294 * Channel 0x0001 is the message channel. There are
295 * other channels for things called "rendevous"
296 * which represent chat and some of the other new
297 * features of AIM2/3/3.5.
299 * Channel 0x0002 is the Rendevous channel, which
300 * is where Chat Invitiations and various client-client
301 * connection negotiations come from.
304 channel = aimutil_get16(command->data+i);
310 if ((channel != 0x01) && (channel != 0x02))
312 printf("faim: icbm: ICBM received on an unsupported channel. Ignoring.\n (chan = %04x)", channel);
317 * Extract the standard user info block.
319 * Note that although this contains TLVs that appear contiguous
320 * with the TLVs read below, they are two different pieces. The
321 * userinfo block contains the number of TLVs that contain user
322 * information, the rest are not even though there is no seperation.
323 * aim_extractuserinfo() returns the number of bytes used by the
324 * userinfo tlvs, so you can start reading the rest of them right
327 * That also means that TLV types can be duplicated between the
328 * userinfo block and the rest of the message, however there should
329 * never be two TLVs of the same type in one block.
332 i += aim_extractuserinfo(command->data+i, &userinfo);
335 * Read block of TLVs (not including the userinfo data). All
336 * further data is derived from what is parsed here.
338 tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i);
341 * From here on, its depends on what channel we're on.
345 u_int j = 0, y = 0, z = 0;
348 struct aim_tlv_t *msgblocktlv;
352 unsigned char fingerprint[10];
356 * Check Autoresponse status. If it is an autoresponse,
357 * it will contain a type 0x0004 TLV, with zero length.
359 if (aim_gettlv(tlvlist, 0x0004, 1))
360 icbmflags |= AIM_IMFLAGS_AWAY;
363 * Check Ack Request status.
365 if (aim_gettlv(tlvlist, 0x0003, 1))
366 icbmflags |= AIM_IMFLAGS_ACK;
371 msgblocktlv = aim_gettlv(tlvlist, 0x0002, 1);
372 if (!msgblocktlv || !msgblocktlv->value) {
373 printf("faim: icbm: major error! no message block TLV found!\n");
374 aim_freetlvchain(&tlvlist);
379 * Extracting the message from the unknown cruft.
381 * This is a bit messy, and I'm not really qualified,
382 * even as the author, to comment on it. At least
383 * its not as bad as a while loop shooting into infinity.
385 * "Do you believe in magic?"
388 msgblock = msgblocktlv->value;
391 wastebits = aimutil_get8(msgblock+j++);
392 wastebits = aimutil_get8(msgblock+j++);
394 y = aimutil_get16(msgblock+j);
396 for (z = 0; z < y; z++)
397 wastebits = aimutil_get8(msgblock+j++);
398 wastebits = aimutil_get8(msgblock+j++);
399 wastebits = aimutil_get8(msgblock+j++);
402 if (finlen > sizeof(fingerprint))
403 finlen = sizeof(fingerprint);
404 memcpy(fingerprint, msgblocktlv->value, finlen);
407 * Message string length, including flag words.
409 i = aimutil_get16(msgblock+j);
415 * Its rumored that these can kick in some funky
416 * 16bit-wide char stuff that used to really kill
417 * libfaim. Hopefully the latter is no longer true.
419 * Though someone should investiagte the former.
422 flag1 = aimutil_get16(msgblock+j);
424 flag2 = aimutil_get16(msgblock+j);
428 printf("faim: icbm: **warning: encoding flags are being used! {%04x, %04x}\n", flag1, flag2);
434 msg = (char *)malloc(i+1);
435 memcpy(msg, msgblock+j, i);
441 userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
443 i = userfunc(sess, command, channel, &userinfo, msg, icbmflags, flag1, flag2, finlen, fingerprint);
449 else if (channel == 0x0002)
451 struct aim_tlv_t *block1;
452 struct aim_tlvlist_t *list2;
453 unsigned short reqclass = 0;
454 unsigned short status = 0;
457 * There's another block of TLVs embedded in the type 5 here.
459 block1 = aim_gettlv(tlvlist, 0x0005, 1);
461 printf("faim: no tlv 0x0005 in rendezvous transaction!\n");
462 aim_freetlvchain(&tlvlist);
463 return 1; /* major problem */
467 * First two bytes represent the status of the connection.
469 * 0 is a request, 2 is an accept
471 status = aimutil_get16(block1->value+0);
474 * Next comes the cookie. Should match the ICBM cookie.
476 if (memcmp(block1->value+2, cookie, 8) != 0)
477 printf("faim: rend: warning cookies don't match!\n");
480 * The next 16bytes are a capability block so we can
481 * identify what type of rendezvous this is.
483 * Thanks to Eric Warmenhoven <warmenhoven@linux.com> (of GAIM)
484 * for pointing some of this out to me. In fact, a lot of
485 * the client-to-client info comes from the work of the GAIM
486 * developers. Thanks!
488 * Read off one capability string and we should have it ID'd.
491 reqclass = aim_getcap(block1->value+2+8, 0x10);
492 if (reqclass == 0x0000) {
493 printf("faim: rend: no ID block\n");
494 aim_freetlvchain(&tlvlist);
499 * What follows may be TLVs or nothing, depending on the
500 * purpose of the message.
502 * Ack packets for instance have nothing more to them.
504 list2 = aim_readtlvchain(block1->value+2+8+16, block1->length-2-8-16);
506 if (!list2 || ((reqclass != AIM_CAPS_IMIMAGE) && !(aim_gettlv(list2, 0x2711, 1)))) {
507 struct aim_msgcookie_t *cook;
510 type = aim_msgcookie_gettype(reqclass); /* XXX: fix this shitty code */
513 if ((cook = aim_uncachecookie(sess, cookie, type)) == NULL) {
514 printf("faim: non-data rendezvous thats not in cache!\n");
515 aim_freetlvchain(&list2);
516 aim_freetlvchain(&tlvlist);
521 if (cook->type == AIM_COOKIETYPE_OFTGET) {
522 struct aim_filetransfer_priv *ft;
525 int errorcode = -1; /* XXX shouldnt this be 0? */
527 ft = (struct aim_filetransfer_priv *)cook->data;
529 if(status != 0x0002) {
530 if (aim_gettlv(list2, 0x000b, 1))
531 errorcode = aim_gettlv16(list2, 0x000b, 1);
534 printf("faim: transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sn, ft->ip, ft->fh.name, errorcode);
537 printf("faim: no data attached to file transfer\n");
539 } else if (cook->type == AIM_CAPS_VOICE) {
540 printf("faim: voice request cancelled\n");
542 printf("faim: unknown cookie cache type %d\n", cook->type);
546 aim_freetlvchain(&list2);
547 aim_freetlvchain(&tlvlist);
552 * The rest of the handling depends on what type it is.
554 if (reqclass & AIM_CAPS_BUDDYICON) {
560 userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
561 if (userfunc || (i = 0))
571 } else if (reqclass & AIM_CAPS_VOICE) {
572 struct aim_msgcookie_t *cachedcook;
574 printf("faim: rend: voice!\n");
576 if(!(cachedcook = (struct aim_msgcookie_t*)calloc(1, sizeof(struct aim_msgcookie_t))))
579 memcpy(cachedcook->cookie, cookie, 8);
580 cachedcook->type = AIM_COOKIETYPE_OFTVOICE;
581 cachedcook->data = NULL;
583 if (aim_cachecookie(sess, cachedcook) != 0)
584 printf("faim: ERROR caching message cookie\n");
586 /* XXX: implement all this */
591 userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
592 if (userfunc || (i = 0)) {
593 i = userfunc(sess, command, channel, reqclass, &userinfo);
595 } else if ((reqclass & AIM_CAPS_IMIMAGE) || (reqclass & AIM_CAPS_BUDDYICON)) {
597 struct aim_directim_priv *priv;
601 if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) {
602 struct aim_tlv_t *iptlv, *porttlv;
604 iptlv = aim_gettlv(list2, 0x0003, 1);
605 porttlv = aim_gettlv(list2, 0x0005, 1);
607 snprintf(ip, 30, "%d.%d.%d.%d:%d",
608 aimutil_get8(iptlv->value+0),
609 aimutil_get8(iptlv->value+1),
610 aimutil_get8(iptlv->value+2),
611 aimutil_get8(iptlv->value+3),
612 4443 /*aimutil_get16(porttlv->value)*/);
615 printf("faim: rend: directIM request from %s (%s)\n",
619 /* XXX: there are a couple of different request packets for
620 * different things */
622 priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv));
623 memcpy(priv->ip, ip, sizeof(priv->ip));
624 memcpy(priv->sn, userinfo.sn, sizeof(priv->sn));
625 memcpy(priv->cookie, cookie, sizeof(priv->cookie));
630 userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
631 if (userfunc || (i = 0))
638 } else if (reqclass & AIM_CAPS_CHAT) {
639 struct aim_tlv_t *miscinfo;
640 struct aim_chat_roominfo roominfo;
641 char *msg=NULL,*encoding=NULL,*lang=NULL;
643 miscinfo = aim_gettlv(list2, 0x2711, 1);
644 aim_chat_readroominfo(miscinfo->value, &roominfo);
646 if (aim_gettlv(list2, 0x000c, 1))
647 msg = aim_gettlv_str(list2, 0x000c, 1);
649 if (aim_gettlv(list2, 0x000d, 1))
650 encoding = aim_gettlv_str(list2, 0x000d, 1);
652 if (aim_gettlv(list2, 0x000e, 1))
653 lang = aim_gettlv_str(list2, 0x000e, 1);
658 userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
659 if (userfunc || (i = 0))
667 encoding?encoding+1:NULL,
673 } else if (reqclass & AIM_CAPS_GETFILE) {
675 struct aim_msgcookie_t *cachedcook;
676 struct aim_tlv_t *miscinfo;
678 if (!(cachedcook = calloc(1, sizeof(struct aim_msgcookie_t))))
683 if (!(miscinfo = aim_gettlv(list2, 0x2711, 1))) {
688 if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) {
689 struct aim_tlv_t *iptlv, *porttlv;
691 if (!(iptlv = aim_gettlv(list2, 0x0003, 1)) || !(porttlv = aim_gettlv(list2, 0x0005, 1))) {
696 snprintf(ip, 30, "%d.%d.%d.%d:%d",
697 aimutil_get8(iptlv->value+0),
698 aimutil_get8(iptlv->value+1),
699 aimutil_get8(iptlv->value+2),
700 aimutil_get8(iptlv->value+3),
701 aimutil_get16(porttlv->value));
704 printf("faim: rend: file get request from %s (%s)\n", userinfo.sn, ip);
709 userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
710 if (userfunc || (i = 0))
719 } else if (reqclass & AIM_CAPS_SENDFILE) {
723 struct aim_msgcookie_t *cachedcook;
724 struct aim_filetransfer_priv *ft;
725 struct aim_tlv_t *miscinfo;
727 memset(ip, 0, sizeof(ip));
729 if (!(miscinfo = aim_gettlv(list2, 0x2711, 1)))
732 if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0003, 1)) {
733 struct aim_tlv_t *iptlv, *porttlv;
735 iptlv = aim_gettlv(list2, 0x0003, 1);
736 porttlv = aim_gettlv(list2, 0x0005, 1);
738 snprintf(ip, sizeof(ip)-1, "%d.%d.%d.%d:%d",
739 aimutil_get8(iptlv->value+0),
740 aimutil_get8(iptlv->value+1),
741 aimutil_get8(iptlv->value+2),
742 aimutil_get8(iptlv->value+3),
743 aimutil_get16(porttlv->value));
746 if (aim_gettlv(list2, 0x000c, 1)) {
747 desc = aim_gettlv_str(list2, 0x000c, 1);
750 printf("faim: rend: file transfer request from %s for %s: %s (%s)\n",
756 memcpy(cachedcook->cookie, cookie, 8);
758 ft = malloc(sizeof(struct aim_filetransfer_priv));
759 strncpy(ft->sn, userinfo.sn, sizeof(ft->sn));
760 strncpy(ft->ip, ip, sizeof(ft->ip));
761 strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name));
762 cachedcook->type = AIM_COOKIETYPE_OFTSEND;
763 cachedcook->data = ft;
765 if (aim_cachecookie(sess, cachedcook) != 0)
766 printf("faim: ERROR caching message cookie\n");
769 aim_accepttransfer(sess, command->conn, ft->sn, cookie, AIM_CAPS_SENDFILE);
777 userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
778 if (userfunc || (i = 0))
785 printf("faim: rend: unknown rendezvous 0x%04x\n", reqclass);
788 aim_freetlvchain(&list2);
792 * Free up the TLV chain.
794 aim_freetlvchain(&tlvlist);
802 * AIM_TRANSFER_DENY_NOTSUPPORTED -- "client does not support"
803 * AIM_TRANSFER_DENY_DECLINE -- "client has declined transfer"
804 * AIM_TRANSFER_DENY_NOTACCEPTING -- "client is not accepting transfers"
807 faim_export unsigned long aim_denytransfer(struct aim_session_t *sess,
808 struct aim_conn_t *conn,
813 struct command_tx_struct *newpacket;
816 if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(sender)+6)))
821 curbyte = aim_putsnac(newpacket->data, 0x0004, 0x000b, 0x0000, sess->snac_nextid);
822 for (i = 0; i < 8; i++)
823 curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]);
824 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
825 curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sender));
826 curbyte += aimutil_putstr(newpacket->data+curbyte, sender, strlen(sender));
827 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0003, code);
830 aim_tx_enqueue(sess, newpacket);
832 return (sess->snac_nextid++);
836 * Not real sure what this does, nor does anyone I've talk to.
838 * Didn't use to send it. But now I think it might be a good
842 faim_export unsigned long aim_seticbmparam(struct aim_session_t *sess,
843 struct aim_conn_t *conn)
845 struct command_tx_struct *newpacket;
848 if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+16)))
853 curbyte = aim_putsnac(newpacket->data, 0x0004, 0x0002, 0x0000, sess->snac_nextid);
854 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
855 curbyte += aimutil_put32(newpacket->data+curbyte, 0x00000003);
856 curbyte += aimutil_put8(newpacket->data+curbyte, 0x1f);
857 curbyte += aimutil_put8(newpacket->data+curbyte, 0x40);
858 curbyte += aimutil_put8(newpacket->data+curbyte, 0x03);
859 curbyte += aimutil_put8(newpacket->data+curbyte, 0xe7);
860 curbyte += aimutil_put8(newpacket->data+curbyte, 0x03);
861 curbyte += aimutil_put8(newpacket->data+curbyte, 0xe7);
862 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
863 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
866 aim_tx_enqueue(sess, newpacket);
868 return (sess->snac_nextid++);
871 faim_internal int aim_parse_msgerror_middle(struct aim_session_t *sess,
872 struct command_rx_struct *command)
874 u_long snacid = 0x000000000;
875 struct aim_snac_t *snac = NULL;
877 rxcallback_t userfunc = NULL;
879 unsigned short reason = 0;
882 * Get SNAC from packet and look it up
883 * the list of unrepliedto/outstanding
886 * After its looked up, the SN that the
887 * message should've gone to will be
888 * in the ->data element of the snac struct.
891 snacid = aimutil_get32(command->data+6);
892 snac = aim_remsnac(sess, snacid);
895 printf("faim: msgerr: got an ICBM-failed error on an unknown SNAC ID! (%08lx)\n", snacid);
900 reason = aimutil_get16(command->data+10);
905 userfunc = aim_callhandler(command->conn, 0x0004, 0x0001);
907 ret = userfunc(sess, command, dest, reason);
920 faim_internal int aim_parse_missedcall(struct aim_session_t *sess,
921 struct command_rx_struct *command)
924 rxcallback_t userfunc = NULL;
925 unsigned short channel, nummissed, reason;
926 struct aim_userinfo_s userinfo;
928 i = 10; /* Skip SNAC header */
932 * XXX: supposedly, this entire packet can repeat as many times
933 * as necessary. Should implement that.
939 channel = aimutil_get16(command->data+i);
943 * Extract the standard user info block.
945 i += aim_extractuserinfo(command->data+i, &userinfo);
947 nummissed = aimutil_get16(command->data+i);
950 reason = aimutil_get16(command->data+i);
956 userfunc = aim_callhandler(command->conn, 0x0004, 0x000a);
958 ret = userfunc(sess, command, channel, &userinfo, nummissed, reason);