4 * The routines for sending/receiving Instant Messages.
11 * Send an ICBM (instant message).
15 * AIM_IMFLAGS_AWAY -- Marks the message as an autoresponse
16 * AIM_IMFLAGS_ACK -- Requests that the server send an ack
17 * when the message is received (of type 0x0004/0x000c)
20 u_long aim_send_im(struct aim_session_t *sess,
21 struct aim_conn_t *conn,
22 char *destsn, u_int flags, char *msg)
26 struct command_tx_struct *newpacket;
28 if (strlen(msg) >= MAXMSGLEN)
31 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, strlen(msg)+256)))
34 newpacket->lock = 1; /* lock struct */
37 curbyte += aim_putsnac(newpacket->data+curbyte,
38 0x0004, 0x0006, 0x0000, sess->snac_nextid);
41 * Generate a random message cookie
43 * We could cache these like we do SNAC IDs. (In fact, it
44 * might be a good idea.) In the message error functions,
45 * the 8byte message cookie is returned as well as the
50 curbyte += aimutil_put8(newpacket->data+curbyte, (u_char) random());
55 curbyte += aimutil_put16(newpacket->data+curbyte,0x0001);
58 * Destination SN (prepended with byte length)
60 curbyte += aimutil_put8(newpacket->data+curbyte,strlen(destsn));
61 curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn));
66 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
67 curbyte += aimutil_put16(newpacket->data+curbyte, strlen(msg) + 0x0d);
72 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0501);
73 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001);
74 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0101);
75 curbyte += aimutil_put8 (newpacket->data+curbyte, 0x01);
78 * Message block length.
80 curbyte += aimutil_put16(newpacket->data+curbyte, strlen(msg) + 0x04);
85 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
86 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
89 * Message. Not terminated.
91 curbyte += aimutil_putstr(newpacket->data+curbyte,msg, strlen(msg));
94 * Set the Request Acknowledge flag.
96 if (flags & AIM_IMFLAGS_ACK) {
97 curbyte += aimutil_put16(newpacket->data+curbyte,0x0003);
98 curbyte += aimutil_put16(newpacket->data+curbyte,0x0000);
102 * Set the Autoresponse flag.
104 if (flags & AIM_IMFLAGS_AWAY) {
105 curbyte += aimutil_put16(newpacket->data+curbyte,0x0004);
106 curbyte += aimutil_put16(newpacket->data+curbyte,0x0000);
109 newpacket->commandlen = curbyte;
112 aim_tx_enqueue(sess, newpacket);
114 #ifdef USE_SNAC_FOR_IMS
116 struct aim_snac_t snac;
118 snac.id = sess->snac_nextid;
119 snac.family = 0x0004;
123 snac.data = malloc(strlen(destsn)+1);
124 memcpy(snac.data, destsn, strlen(destsn)+1);
126 aim_newsnac(sess, &snac);
129 aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */
132 return (sess->snac_nextid++);
135 struct aim_directim_priv {
136 unsigned char cookie[8];
140 int aim_send_im_direct(struct aim_session_t *sess,
141 struct aim_conn_t *conn,
144 struct command_tx_struct *newpacket;
145 struct aim_directim_priv *priv = NULL;
148 if (strlen(msg) >= MAXMSGLEN)
151 if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS) || !conn->priv) {
152 printf("faim: directim: invalid arguments\n");
156 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0001, conn, strlen(msg)))) {
157 printf("faim: directim: tx_new failed\n");
161 newpacket->lock = 1; /* lock struct */
163 priv = (struct aim_directim_priv *)conn->priv;
165 newpacket->hdr.oft.hdr2len = 0x44;
167 if (!(newpacket->hdr.oft.hdr2 = malloc(newpacket->hdr.oft.hdr2len))) {
173 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0006);
174 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
176 i += aimutil_putstr(newpacket->hdr.oft.hdr2+i, priv->cookie, 8);
178 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
179 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
180 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
181 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
183 i += aimutil_put32(newpacket->hdr.oft.hdr2+i, strlen(msg));
185 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
186 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
187 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
188 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
189 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
190 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
192 i += aimutil_putstr(newpacket->hdr.oft.hdr2+i, sess->logininfo.screen_name, strlen(sess->logininfo.screen_name));
195 i += aimutil_put8(newpacket->hdr.oft.hdr2+i, 0x00);
196 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
197 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
198 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
199 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
200 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
201 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
202 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
203 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
204 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
205 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
206 i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
208 memcpy(newpacket->data, msg, strlen(msg));
212 aim_tx_enqueue(sess, newpacket);
218 * It can easily be said that parsing ICBMs is THE single
219 * most difficult thing to do in the in AIM protocol. In
220 * fact, I think I just did say that.
222 * Below is the best damned solution I've come up with
223 * over the past sixteen months of battling with it. This
224 * can parse both away and normal messages from every client
225 * I have access to. Its not fast, its not clean. But it works.
227 * We should also support at least minimal parsing of
228 * Channel 2, so that we can at least know the name of the
229 * room we're invited to, but obviously can't attend...
232 int aim_parse_incoming_im_middle(struct aim_session_t *sess,
233 struct command_rx_struct *command)
236 rxcallback_t userfunc = NULL;
239 struct aim_tlvlist_t *tlvlist;
240 struct aim_userinfo_s userinfo;
243 memset(&userinfo, 0x00, sizeof(struct aim_userinfo_s));
245 i = 10; /* Skip SNAC header */
248 * Read ICBM Cookie. And throw away.
250 for (z=0; z<8; z++,i++)
251 cookie[z] = command->data[i];
256 * Channel 0x0001 is the message channel. There are
257 * other channels for things called "rendevous"
258 * which represent chat and some of the other new
259 * features of AIM2/3/3.5.
261 * Channel 0x0002 is the Rendevous channel, which
262 * is where Chat Invitiations and various client-client
263 * connection negotiations come from.
266 channel = aimutil_get16(command->data+i);
272 if ((channel != 0x01) && (channel != 0x02))
274 printf("faim: icbm: ICBM received on an unsupported channel. Ignoring.\n (chan = %04x)", channel);
279 * Source screen name.
281 memcpy(userinfo.sn, command->data+i+1, (int)command->data[i]);
282 userinfo.sn[(int)command->data[i]] = '\0';
283 i += 1 + (int)command->data[i];
288 userinfo.warnlevel = aimutil_get16(command->data+i); /* guess */
292 * Number of TLVs that follow. Not needed.
294 wastebits = aimutil_get16(command->data+i);
298 * Read block of TLVs. All further data is derived
299 * from what is parsed here.
301 tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i);
304 * From here on, its depends on what channel we're on.
308 u_int j = 0, y = 0, z = 0;
311 struct aim_tlv_t *msgblocktlv, *tmptlv;
316 * Check Autoresponse status. If it is an autoresponse,
317 * it will contain a second type 0x0004 TLV, with zero length.
319 if (aim_gettlv(tlvlist, 0x0004, 2))
320 icbmflags |= AIM_IMFLAGS_AWAY;
323 * Check Ack Request status.
325 if (aim_gettlv(tlvlist, 0x0003, 2))
326 icbmflags |= AIM_IMFLAGS_ACK;
329 * Extract the various pieces of the userinfo struct.
332 if ((tmptlv = aim_gettlv(tlvlist, 0x0001, 1)))
333 userinfo.class = aimutil_get16(tmptlv->value);
334 /* Member-since date. */
335 if ((tmptlv = aim_gettlv(tlvlist, 0x0002, 1)))
337 /* If this is larger than 4, its probably the message block, skip */
338 if (tmptlv->length <= 4)
339 userinfo.membersince = aimutil_get32(tmptlv->value);
342 if ((tmptlv = aim_gettlv(tlvlist, 0x0003, 1)))
343 userinfo.onlinesince = aimutil_get32(tmptlv->value);
345 if ((tmptlv = aim_gettlv(tlvlist, 0x0004, 1)))
346 userinfo.idletime = aimutil_get16(tmptlv->value);
347 /* Session Length (AIM) */
348 if ((tmptlv = aim_gettlv(tlvlist, 0x000f, 1)))
349 userinfo.sessionlen = aimutil_get16(tmptlv->value);
350 /* Session Length (AOL) */
351 if ((tmptlv = aim_gettlv(tlvlist, 0x0010, 1)))
352 userinfo.sessionlen = aimutil_get16(tmptlv->value);
357 * XXX: Will the msgblock always be the second 0x0002?
359 msgblocktlv = aim_gettlv(tlvlist, 0x0002, 1);
360 if (!msgblocktlv || !msgblocktlv->value)
362 printf("faim: icbm: major error! no message block TLV found!\n");
363 aim_freetlvchain(&tlvlist);
368 * Extracting the message from the unknown cruft.
370 * This is a bit messy, and I'm not really qualified,
371 * even as the author, to comment on it. At least
372 * its not as bad as a while loop shooting into infinity.
374 * "Do you believe in magic?"
377 msgblock = msgblocktlv->value;
380 wastebits = aimutil_get8(msgblock+j++);
381 wastebits = aimutil_get8(msgblock+j++);
383 y = aimutil_get16(msgblock+j);
385 for (z = 0; z < y; z++)
386 wastebits = aimutil_get8(msgblock+j++);
387 wastebits = aimutil_get8(msgblock+j++);
388 wastebits = aimutil_get8(msgblock+j++);
391 * Message string length, including flag words.
393 i = aimutil_get16(msgblock+j);
399 * Its rumored that these can kick in some funky
400 * 16bit-wide char stuff that used to really kill
401 * libfaim. Hopefully the latter is no longer true.
403 * Though someone should investiagte the former.
406 flag1 = aimutil_get16(msgblock+j);
408 flag2 = aimutil_get16(msgblock+j);
412 printf("faim: icbm: **warning: encoding flags are being used! {%04x, %04x}\n", flag1, flag2);
418 msg = (char *)malloc(i+1);
419 memcpy(msg, msgblock+j, i);
425 userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
427 i = userfunc(sess, command, channel, &userinfo, msg, icbmflags, flag1, flag2);
433 else if (channel == 0x0002)
435 struct aim_tlv_t *block1;
436 struct aim_tlvlist_t *list2;
437 struct aim_tlv_t *tmptlv;
438 unsigned short reqclass = 0;
439 unsigned short status = 0;
442 if ((tmptlv = aim_gettlv(tlvlist, 0x0001, 1)))
443 userinfo.class = aimutil_get16(tmptlv->value);
445 if ((tmptlv = aim_gettlv(tlvlist, 0x0003, 1)))
446 userinfo.onlinesince = aimutil_get32(tmptlv->value);
448 if ((tmptlv = aim_gettlv(tlvlist, 0x0004, 1)))
449 userinfo.idletime = aimutil_get16(tmptlv->value);
450 /* Session Length (AIM) */
451 if ((tmptlv = aim_gettlv(tlvlist, 0x000f, 1)))
452 userinfo.sessionlen = aimutil_get16(tmptlv->value);
453 /* Session Length (AOL) */
454 if ((tmptlv = aim_gettlv(tlvlist, 0x0010, 1)))
455 userinfo.sessionlen = aimutil_get16(tmptlv->value);
458 * There's another block of TLVs embedded in the type 5 here.
460 block1 = aim_gettlv(tlvlist, 0x0005, 1);
462 printf("faim: no tlv 0x0005 in rendezvous transaction!\n");
463 aim_freetlvchain(&tlvlist);
464 return 1; /* major problem */
468 * First two bytes represent the status of the connection.
470 * 0 is a request, 2 is an accept
472 status = aimutil_get16(block1->value+0);
475 * Next comes the cookie. Should match the ICBM cookie.
477 if (memcmp(block1->value+2, cookie, 8) != 0)
478 printf("faim: rend: warning cookies don't match!\n");
481 * The next 16bytes are a capability block so we can
482 * identify what type of rendezvous this is.
484 * Thanks to Eric Warmenhoven <warmenhoven@linux.com> (of GAIM)
485 * for pointing some of this out to me. In fact, a lot of
486 * the client-to-client info comes from the work of the GAIM
487 * developers. Thanks!
489 * Read off one capability string and we should have it ID'd.
492 reqclass = aim_getcap(block1->value+2+8, 0x10);
493 if (reqclass == 0x0000) {
494 printf("faim: rend: no ID block\n");
495 aim_freetlvchain(&tlvlist);
500 * What follows may be TLVs or nothing, depending on the
501 * purpose of the message.
503 * Ack packets for instance have nothing more to them.
505 list2 = aim_readtlvchain(block1->value+2+8+16, block1->length-2-8-16);
507 if (!list2 || ((reqclass != AIM_CAPS_IMIMAGE) && !(aim_gettlv(list2, 0x2711, 1)))) {
508 struct aim_msgcookie_t *cook;
510 if ((cook = aim_uncachecookie(sess, cookie)) == NULL) {
511 printf("faim: non-data rendezvous thats not in cache!\n");
512 aim_freetlvchain(&list2);
513 aim_freetlvchain(&tlvlist);
517 if (cook->type == AIM_CAPS_SENDFILE) {
518 struct aim_filetransfer_t *ft;
521 struct aim_tlv_t *errortlv;
524 ft = (struct aim_filetransfer_t *)cook->data;
526 if ((errortlv = aim_gettlv(list2, 0x000b, 1))) {
527 errorcode = aimutil_get16(errortlv->value);
530 printf("faim: transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sender, ft->ip, ft->filename, errorcode);
531 } else if (status == 0x0002) { /* connection accepted */
532 printf("faim: transfer from %s (%s) for %s accepted\n", ft->sender, ft->ip, ft->filename);
536 printf("faim: not data attached to file transfer\n");
538 } else if (cook->type == AIM_CAPS_VOICE) {
539 printf("faim: voice request cancelled\n");
541 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) {
559 userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
560 if (userfunc || (i = 0))
567 } else if (reqclass & AIM_CAPS_VOICE) {
568 struct aim_msgcookie_t cachedcook;
570 printf("faim: rend: voice!\n");
572 memcpy(cachedcook.cookie, cookie, 8);
573 cachedcook.type = AIM_CAPS_VOICE;
574 cachedcook.data = NULL;
575 if (aim_cachecookie(sess, &cachedcook) != 0)
576 printf("faim: ERROR caching message cookie\n");
578 /* XXX: implement all this */
583 userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
584 if (userfunc || (i = 0)) {
591 } else if (reqclass & AIM_CAPS_IMIMAGE) {
593 struct aim_msgcookie_t cachedcook;
595 memset(ip, 0, sizeof(ip));
597 if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0003, 1)) {
598 struct aim_tlv_t *iptlv, *porttlv;
600 iptlv = aim_gettlv(list2, 0x0003, 1);
601 porttlv = aim_gettlv(list2, 0x0005, 1);
603 snprintf(ip, sizeof(ip)-1, "%d.%d.%d.%d:%d",
604 aimutil_get8(iptlv->value+0),
605 aimutil_get8(iptlv->value+1),
606 aimutil_get8(iptlv->value+2),
607 aimutil_get8(iptlv->value+3),
608 4443 /*aimutil_get16(porttlv->value)*/);
611 printf("faim: rend: directIM request from %s (%s)\n",
617 struct aim_conn_t *newconn;
619 newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, ip);
620 if (!newconn || (newconn->fd == -1)) {
621 printf("could not connect to %s\n", ip);
622 perror("aim_newconn");
623 aim_conn_kill(sess, &newconn);
625 struct aim_directim_priv *priv;
626 priv = (struct aim_directim_priv *)malloc(sizeof(struct aim_directim_priv));
627 memcpy(priv->cookie, cookie, 8);
628 strncpy(priv->sn, userinfo.sn, MAXSNLEN);
629 newconn->priv = priv;
630 printf("faim: connected to peer (fd = %d)\n", newconn->fd);
636 memcpy(cachedcook.cookie, cookie, 8);
638 ft = malloc(sizeof(struct aim_filetransfer_t));
639 strncpy(ft->sender, userinfo.sn, sizeof(ft->sender));
640 strncpy(ft->ip, ip, sizeof(ft->ip));
641 ft->filename = strdup(miscinfo->value+8);
642 cachedcook.type = AIM_CAPS_SENDFILE;
643 cachedcook.data = ft;
645 if (aim_cachecookie(sess, &cachedcook) != 0)
646 printf("faim: ERROR caching message cookie\n");
652 userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
653 if (userfunc || (i = 0))
660 } else if (reqclass & AIM_CAPS_CHAT) {
661 struct aim_tlv_t *miscinfo;
662 struct aim_chat_roominfo roominfo;
663 char *msg=NULL,*encoding=NULL,*lang=NULL;
665 miscinfo = aim_gettlv(list2, 0x2711, 1);
666 aim_chat_readroominfo(miscinfo->value, &roominfo);
668 if (aim_gettlv(list2, 0x000c, 1))
669 msg = aim_gettlv_str(list2, 0x000c, 1);
671 if (aim_gettlv(list2, 0x000d, 1))
672 encoding = aim_gettlv_str(list2, 0x000d, 1);
674 if (aim_gettlv(list2, 0x000e, 1))
675 lang = aim_gettlv_str(list2, 0x000e, 1);
680 userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
681 if (userfunc || (i = 0))
689 encoding?encoding+1:NULL,
695 } else if (reqclass & AIM_CAPS_GETFILE) {
700 userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
701 if (userfunc || (i = 0))
708 } else if (reqclass & AIM_CAPS_SENDFILE) {
712 userfunc = aim_callhandler(command->conn, 0x0004, 0x0007);
713 if (userfunc || (i = 0))
722 struct aim_msgcookie_t cachedcook;
723 struct aim_filetransfer_t *ft;
724 struct aim_tlv_t *miscinfo;
726 memset(ip, 0, sizeof(ip));
728 miscinfo = aim_gettlv(list2, 0x2711, 1);
730 if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0003, 1)) {
731 struct aim_tlv_t *iptlv, *porttlv;
733 iptlv = aim_gettlv(list2, 0x0003, 1);
734 porttlv = aim_gettlv(list2, 0x0005, 1);
736 snprintf(ip, sizeof(ip)-1, "%d.%d.%d.%d:%d",
737 aimutil_get8(iptlv->value+0),
738 aimutil_get8(iptlv->value+1),
739 aimutil_get8(iptlv->value+2),
740 aimutil_get8(iptlv->value+3),
741 aimutil_get16(porttlv->value));
744 if (aim_gettlv(list2, 0x000c, 1)) {
745 desc = aim_gettlv_str(list2, 0x000c, 1);
748 printf("faim: rend: file transfer request from %s for %s: %s (%s)\n",
754 memcpy(cachedcook.cookie, cookie, 8);
756 ft = malloc(sizeof(struct aim_filetransfer_t));
757 strncpy(ft->sender, userinfo.sn, sizeof(ft->sender));
758 strncpy(ft->ip, ip, sizeof(ft->ip));
759 ft->filename = strdup(miscinfo->value+8);
760 cachedcook.type = AIM_CAPS_SENDFILE;
761 cachedcook.data = ft;
763 if (aim_cachecookie(sess, &cachedcook) != 0)
764 printf("faim: ERROR caching message cookie\n");
767 aim_accepttransfer(sess, command->conn, ft->sender, cookie, AIM_CAPS_SENDFILE);
773 printf("faim: rend: unknown rendezvous 0x%04x\n", reqclass);
776 aim_freetlvchain(&list2);
780 * Free up the TLV chain.
782 aim_freetlvchain(&tlvlist);
788 u_long aim_accepttransfer(struct aim_session_t *sess,
789 struct aim_conn_t *conn,
792 unsigned short rendid)
794 struct command_tx_struct *newpacket;
797 if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(sender)+4+2+8+16)))
802 curbyte = aim_putsnac(newpacket->data, 0x0004, 0x0006, 0x0000, sess->snac_nextid);
803 for (i = 0; i < 8; i++)
804 curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]);
805 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
806 curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sender));
807 curbyte += aimutil_putstr(newpacket->data+curbyte, sender, strlen(sender));
808 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005);
809 curbyte += aimutil_put16(newpacket->data+curbyte, 0x001a);
810 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002 /* accept */);
811 for (i = 0; i < 8; i++)
812 curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]);
813 curbyte += aim_putcap(newpacket->data+curbyte, 0x10, rendid);
816 aim_tx_enqueue(sess, newpacket);
818 return (sess->snac_nextid++);
823 * AIM_TRANSFER_DENY_NOTSUPPORTED -- "client does not support"
824 * AIM_TRANSFER_DENY_DECLINE -- "client has declined transfer"
825 * AIM_TRANSFER_DENY_NOTACCEPTING -- "client is not accepting transfers"
828 u_long aim_denytransfer(struct aim_session_t *sess,
829 struct aim_conn_t *conn,
834 struct command_tx_struct *newpacket;
837 if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(sender)+6)))
842 curbyte = aim_putsnac(newpacket->data, 0x0004, 0x000b, 0x0000, sess->snac_nextid);
843 for (i = 0; i < 8; i++)
844 curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]);
845 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002);
846 curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sender));
847 curbyte += aimutil_putstr(newpacket->data+curbyte, sender, strlen(sender));
848 curbyte += aim_puttlv_16(newpacket->data+curbyte, 0x0003, code);
851 aim_tx_enqueue(sess, newpacket);
853 return (sess->snac_nextid++);
857 * Not real sure what this does, nor does anyone I've talk to.
859 * Didn't use to send it. But now I think it might be a good
863 u_long aim_seticbmparam(struct aim_session_t *sess,
864 struct aim_conn_t *conn)
866 struct command_tx_struct *newpacket;
869 if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+16)))
874 curbyte = aim_putsnac(newpacket->data, 0x0004, 0x0002, 0x0000, sess->snac_nextid);
875 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
876 curbyte += aimutil_put32(newpacket->data+curbyte, 0x00000003);
877 curbyte += aimutil_put8(newpacket->data+curbyte, 0x1f);
878 curbyte += aimutil_put8(newpacket->data+curbyte, 0x40);
879 curbyte += aimutil_put8(newpacket->data+curbyte, 0x03);
880 curbyte += aimutil_put8(newpacket->data+curbyte, 0xe7);
881 curbyte += aimutil_put8(newpacket->data+curbyte, 0x03);
882 curbyte += aimutil_put8(newpacket->data+curbyte, 0xe7);
883 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
884 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000);
887 aim_tx_enqueue(sess, newpacket);
889 return (sess->snac_nextid++);
892 int aim_parse_msgerror_middle(struct aim_session_t *sess,
893 struct command_rx_struct *command)
895 u_long snacid = 0x000000000;
896 struct aim_snac_t *snac = NULL;
898 rxcallback_t userfunc = NULL;
901 * Get SNAC from packet and look it up
902 * the list of unrepliedto/outstanding
905 * After its looked up, the SN that the
906 * message should've gone to will be
907 * in the ->data element of the snac struct.
910 snacid = aimutil_get32(command->data+6);
911 snac = aim_remsnac(sess, snacid);
914 printf("faim: msgerr: got an ICBM-failed error on an unknown SNAC ID! (%08lx)\n", snacid);
920 userfunc = aim_callhandler(command->conn, 0x0004, 0x0001);
922 ret = userfunc(sess, command, (snac)?snac->data:"(UNKNOWN)");