Mercurial > pidgin
changeset 503:6e318907bcce
[gaim-migrate @ 513]
bringing gaim up to latest libfaim
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 18 Jul 2000 05:37:39 +0000 |
parents | 4d1e39112cbd |
children | 182074f73487 |
files | libfaim/CHANGES libfaim/CHANGES.gaim libfaim/Makefile.am libfaim/README.gaim libfaim/aim_chat.c libfaim/aim_ft.c libfaim/aim_im.c libfaim/aim_msgcookie.c libfaim/aim_rxhandlers.c libfaim/aim_rxqueue.c libfaim/faim/aim.h libfaim/faim/aim_cbtypes.h src/oscar.c src/server.c |
diffstat | 14 files changed, 1646 insertions(+), 336 deletions(-) [+] |
line wrap: on
line diff
--- a/libfaim/CHANGES Tue Jul 18 05:23:25 2000 +0000 +++ b/libfaim/CHANGES Tue Jul 18 05:37:39 2000 +0000 @@ -1,6 +1,32 @@ No release numbers ------------------ + - Mon Jul 17 01:56:31 UTC 2000 + - Added 0004/000c callback (for message acknowledgments) + - This goes with the AIM_IMFLAGS_ACK option that has been there + for ages now. When you send a message with that option, you'll + get a message back containing the screenname, telling you it was sent. + - Moved the aim_conn_kill's out of aim_get_command() and into + the client. They're only closed in there now. This is so that you + can detect what type of connection died. You'll want to handle + BOS and chat connections in special ways most likely. You'll also + need to call aim_conn_kill when you're done with it. + - Added/fixed the Rate Change handlers. Now passes up a long that + should contain a number. I'm currently in pattern-searching mode. + + - Sun Jul 16 22:59:39 GMT 2000 + - Fixed the locking in the rendezvous code. Hopefully is safe now. + + - Sun Jul 16 11:03:28 GMT 2000 + - Fixed 0001/000a chat printf. (Actually a one liner a few days ago.) + - Started integrating josh's 3k rendezvous patch. Currently only + directim is working. And its got bugs. But he's not online + right now, so I can't bitch. I'd love to bitch here, but I'm + tired. + - Can definitly accept directim connections and send/recieve. + - See faimtest for the new callbacks. (Urg.) + - Here weeee gooooo. (Not sure if this will break everyone or not.) + - Fri Jun 30 00:04:47 UTC 2000 - Removed the forceful ICQ-related warnings, just in case they're wrong - Added three new fields to the client info.
--- a/libfaim/CHANGES.gaim Tue Jul 18 05:23:25 2000 +0000 +++ b/libfaim/CHANGES.gaim Tue Jul 18 05:37:39 2000 +0000 @@ -1,3 +1,10 @@ + +Tue Jul 18 05:31:15 UTC 2000 EWarmenhoven + - Lots of updates to libfaim; updates to gaim to use latest libfaim. + - libfaim can do directIM now, but I haven't brought gaim up-to-date + on that yet. I will soon (hopefully tonight). + - Just a side note: I got WinAIM to run under wine, which means I + don't need to do testing in the dark anymore (hopefully). Fri Jun 30 02:29:40 UTC 2000 EWarmenhoven - AOL is trying to prevent us from using Oscar. Fortunately, Adam's
--- a/libfaim/Makefile.am Tue Jul 18 05:23:25 2000 +0000 +++ b/libfaim/Makefile.am Tue Jul 18 05:37:39 2000 +0000 @@ -9,6 +9,7 @@ aim_chat.c \ aim_chatnav.c \ aim_conn.c \ + aim_ft.c \ aim_im.c \ aim_info.c \ aim_login.c \
--- a/libfaim/README.gaim Tue Jul 18 05:23:25 2000 +0000 +++ b/libfaim/README.gaim Tue Jul 18 05:37:39 2000 +0000 @@ -60,7 +60,7 @@ - whispering (this will never happen) Getting/setting dir info Changing your password -File transfer/IM images/voice chat/etc. +File transfer/IM images/voice chat/etc. (RVOUS stuff) KNOWN ISSUES ============ @@ -87,15 +87,11 @@ this in gdb or gotten a backtrace on it, so I'm not exactly sure what the problem is. I think this actually happens on the TOC side of things too. -- Gaim/TOC can do file transfers, but Gaim/Faim cannot. This is not because +- Gaim/TOC can do RVOUS actions, but Gaim/Faim cannot. This is not because there is any difference in the two protocols as far as the actual transfer is -concerned. The only thing preventing this is it is currently not possible to -recognize when we've received a file transfer request using libfaim. Once -libfaim can tell us that we've received the request, the only thing we should -need to change is to have oscar.c wait for one of those notifications and then -call accept_file_transfer() from rvous.c. No modification of rvous.c should be -necessary at that point. (The same should apply to IM Images and Voice Chat and -all the other RVOUS stuff - they are all protocol-independent.) +concerned. Adam wants libfaim to handle *all* of the RVOUS connection stuff, +which I can understand. Unfortunately, the only part he's implemented is Direct +Direct IM, and I haven't implemented that on the gaim side yet. - What *is* protocol-dependent about the RVOUS stuff is that only Oscar can request RVOUS actions, though both can receive them. However, libfaim cannot
--- a/libfaim/aim_chat.c Tue Jul 18 05:23:25 2000 +0000 +++ b/libfaim/aim_chat.c Tue Jul 18 05:37:39 2000 +0000 @@ -70,6 +70,8 @@ for (i=0;i<8;i++) curbyte += aimutil_put8(newpacket->data+curbyte, (u_char) random()); + aim_cachecookie(sess, aim_mkcookie(newpacket->data+curbyte-8, AIM_COOKIETYPE_CHAT, NULL)); + /* * metaTLV start. -- i assume this is a metaTLV. it could be the * channel ID though. @@ -430,11 +432,13 @@ i = 10; /* skip snac */ /* - * ICBM Cookie. Ignore it. + * ICBM Cookie. Cache it. */ for (z=0; z<8; z++,i++) cookie[z] = command->data[i]; + aim_cachecookie(sess, aim_mkcookie(cookie, AIM_COOKIETYPE_ICBM, NULL)); + /* * Channel ID * @@ -579,6 +583,7 @@ */ for (i=0;i<8;i++) curbyte += aimutil_put8(newpacket->data+curbyte, (u_char)rand()); + aim_cachecookie(sess, aim_mkcookie(newpacket->data+curbyte-8, AIM_COOKIETYPE_CHAT, NULL)); /* * Channel (2)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libfaim/aim_ft.c Tue Jul 18 05:37:39 2000 +0000 @@ -0,0 +1,1091 @@ +#include <faim/aim.h> + +#include <sys/utsname.h> /* for aim_directim_initiate */ +#include <arpa/inet.h> /* for inet_ntoa */ + +/* aim_msgcookies.c is mostly new. just look at the diff and replace yours, easiest. */ + +/* + function name where i had it + aim_send_im_direct aim_im.c + aim_directim_initiate aim_im.c + aim_filetransfer_accept aim_im.c + aim_getlisting aim_misc.c (?!) -- prototype function. can be ignored. + establish aim_misc.c + aim_get_command_rendezvous aim_rxqueue.c + oft_getfh aim_rxqueue.c +*/ + +int aim_handlerendconnect(struct aim_session_t *sess, struct aim_conn_t *cur) +{ + int acceptfd = 0; + rxcallback_t userfunc; + struct sockaddr cliaddr; + socklen_t clilen = sizeof(cliaddr); + int ret = 0; + + /* + * Listener sockets only have incoming connections. No data. + */ + if( (acceptfd = accept(cur->fd, &cliaddr, &clilen)) == -1) + return -1; + + if (cliaddr.sa_family != AF_INET) /* just in case IPv6 really is happening */ + return -1; + + switch(cur->subtype) { + case AIM_CONN_SUBTYPE_OFT_DIRECTIM: { + struct aim_directim_priv *priv; + + priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv)); + + snprintf(priv->ip, sizeof(priv->ip), "%s:%u", inet_ntoa(((struct sockaddr_in *)&cliaddr)->sin_addr), ntohs(((struct sockaddr_in *)&cliaddr)->sin_port)); + + if(!cur->priv) + cur->priv = priv; /* what happens if there is one?! -- mid */ + + cur->type = AIM_CONN_TYPE_RENDEZVOUS; + close(cur->fd); /* should we really do this? seems like the client should decide. maybe clone the connection and keep the listener open. -- mid */ + cur->fd = acceptfd; + + if ( (userfunc = aim_callhandler(cur, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE))) + ret = userfunc(sess, NULL, cur); + + break; + } + case AIM_CONN_SUBTYPE_OFT_GETFILE: { + struct aim_filetransfer_priv *priv; + + priv->state = 0; + + priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)); + + snprintf(priv->ip, sizeof(priv->ip), "%s:%u", inet_ntoa(((struct sockaddr_in *)&cliaddr)->sin_addr), ntohs(((struct sockaddr_in *)&cliaddr)->sin_port)); + + if(!cur->priv) + cur->priv = priv; + + if ( (userfunc = aim_callhandler(cur, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEINITIATE))) + ret = userfunc(sess, NULL, cur); + break; + } + default: { + /* XXX */ + } + } + return ret; +} + + +/* + * aim_send_im_direct: + * sess - session + * conn - directim connection + * msg - null-terminated string to send + */ + +int aim_send_im_direct(struct aim_session_t *sess, + struct aim_conn_t *conn, + char *msg) +{ + struct command_tx_struct *newpacket , *newpacket2; + + /* newpacket contains a real header with data, newpacket2 is just a + null packet, with a cookie and a lot of 0x00s. newpacket is the + "i'm sending", newpacket2 is the "i'm typing".*/ + + /* uhm. the client should send those as two seperate things -- mid */ + + struct aim_directim_priv *priv = NULL; + int i; + + if (strlen(msg) >= MAXMSGLEN) + return -1; + + if (!sess || !conn || !(conn->type) || (conn->type != AIM_CONN_TYPE_RENDEZVOUS) || !conn->priv) { + printf("faim: directim: invalid arguments\n"); + return -1; + }; + + priv = (struct aim_directim_priv *)conn->priv; + + /* NULLish Header */ + + if (!(newpacket2 = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0001, conn, 0))) { + printf("faim: directim: tx_new2 failed\n"); + return -1; + } + + newpacket2->lock = 1; /* lock struct */ + + memcpy(newpacket2->hdr.oft.magic, "ODC2", 4); + newpacket2->hdr.oft.hdr2len = 0x44; + + if (!(newpacket2->hdr.oft.hdr2 = calloc(1,newpacket2->hdr.oft.hdr2len))) { + free(newpacket2); + return -1; + } + + i = 0; + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0006); + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); + + i += aimutil_putstr(newpacket2->hdr.oft.hdr2+i, priv->cookie, 8); + + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); + + i += aimutil_put32(newpacket2->hdr.oft.hdr2+i, 0x00000000); + + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); + + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x000e); + + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); + + i += aimutil_putstr(newpacket2->hdr.oft.hdr2+i, sess->logininfo.screen_name, strlen(sess->logininfo.screen_name)); + + i = 52; /* 0x34 */ + i += aimutil_put8(newpacket2->hdr.oft.hdr2+i, 0x00); /* 53 */ + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); /* 55 */ + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);/* 61 */ + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);/* 65 */ + i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);/* end of hdr2 */ + + newpacket2->lock = 0; + newpacket2->data = NULL; + + aim_tx_enqueue(sess, newpacket2); + + /* Header packet */ + + if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0001, conn, strlen(msg)))) { + printf("faim: directim: tx_new failed\n"); + return -1; + } + + newpacket->lock = 1; /* lock struct */ + + memcpy(newpacket->hdr.oft.magic, "ODC2", 4); + newpacket->hdr.oft.hdr2len = 0x54; + + if (!(newpacket->hdr.oft.hdr2 = calloc(1,newpacket->hdr.oft.hdr2len))) { + free(newpacket); + return -1; + } + + i = 0; + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0006); + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); + + i += aimutil_putstr(newpacket->hdr.oft.hdr2+i, priv->cookie, 8); + + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); + + i += aimutil_put32(newpacket->hdr.oft.hdr2+i, strlen(msg)); + + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); + + i += aimutil_putstr(newpacket->hdr.oft.hdr2+i, sess->logininfo.screen_name, strlen(sess->logininfo.screen_name)); + + i = 52; /* 0x34 */ + i += aimutil_put8(newpacket->hdr.oft.hdr2+i, 0x00); /* 53 */ + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); /* 55 */ + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);/* 61 */ + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);/* 65 */ + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);/* end of hdr2 */ + + /* values grabbed from a dump */ + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0008); /* 69 */ + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x000c); + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);/* 71 */ + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x1466);/* 73 */ + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0001);/* 73 */ + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x2e0f); + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x393e); + i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0xcac8); + + memcpy(newpacket->data, msg, strlen(msg)); + + newpacket->lock = 0; + + aim_tx_enqueue(sess, newpacket); + + return 0; +} + +/* + * aim_directim_intitiate: + * For those times when we want to open up the directim channel ourselves. + * sess is your session, + * conn is the BOS conn, + * priv is a dummy priv value (we'll let it get filled in later) (if + * you pass a NULL, we alloc one) + * destsn is the SN to connect to. + */ + + +struct aim_conn_t *aim_directim_initiate(struct aim_session_t *sess, + struct aim_conn_t *conn, + struct aim_directim_priv *priv, + char *destsn) +{ + struct command_tx_struct *newpacket; + struct aim_conn_t *newconn; + + struct aim_msgcookie_t *cookie; + + int curbyte, i, listenfd; + short port = 4443; + + struct hostent *hptr; + struct utsname myname; + + char cap[16]; + char d[4]; /* XXX: IPv6. *cough* */ + + /* + * Open our socket + */ + + if( (listenfd = aim_listenestablish(port)) == -1) + return NULL; + + /* + * get our local IP + */ + + if(uname(&myname) < 0) + return NULL; + + if( (hptr = gethostbyname(myname.nodename)) == NULL) + return NULL; + + memcpy(&d, hptr->h_addr_list[0], 4); /* XXX: this probably isn't quite kosher, but it works */ + + aim_putcap(cap, 16, AIM_CAPS_IMIMAGE); + + /* + * create the OSCAR packet + */ + + if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(destsn)+4+4+0x32))) + return NULL; + + newpacket->lock = 1; /* lock struct */ + + curbyte = 0; + curbyte += aim_putsnac(newpacket->data+curbyte, + 0x0004, 0x0006, 0x0000, sess->snac_nextid); + + /* + * Generate a random message cookie + * This cookie needs to be alphanumeric and NULL-terminated to be TOC-compatible. + */ + for (i=0;i<7;i++) + curbyte += aimutil_put8(newpacket->data+curbyte, 0x30 + ((u_char) random() % 20)); + curbyte += aimutil_put8(newpacket->data+curbyte, 0x00); + + /* + * grab all the data for cookie caching. + */ + cookie = (struct aim_msgcookie_t *)calloc(1, sizeof(struct aim_msgcookie_t)); + + memcpy(cookie->cookie, newpacket->data+curbyte-8, 8); + cookie->type = AIM_COOKIETYPE_OFTIM; + + if(!priv) + priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv)); + + memcpy(priv->cookie, cookie, 8); + memcpy(priv->sn, destsn, sizeof(priv->sn)); + + cookie->data = priv; + + aim_cachecookie(sess, cookie); /* cache da cookie */ + + /* + * Channel ID + */ + curbyte += aimutil_put16(newpacket->data+curbyte,0x0002); + + /* + * Destination SN (prepended with byte length) + */ + curbyte += aimutil_put8(newpacket->data+curbyte,strlen(destsn)); + curbyte += aimutil_putstr(newpacket->data+curbyte, destsn, strlen(destsn)); + + curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003); + curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); + + /* + * enTLV start + */ + curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005); + curbyte += aimutil_put16(newpacket->data+curbyte, 0x0032); + + /* + * Flag data / ICBM Parameters? + */ + curbyte += aimutil_put8(newpacket->data+curbyte, 0x00); + curbyte += aimutil_put8(newpacket->data+curbyte, 0x00); + + /* + * Cookie + */ + curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cookie, 8); + + /* + * Capability String + */ + curbyte += aimutil_putstr(newpacket->data+curbyte, (char *)cap, 0x10); + + /* + * 000a/0002 : 0001 + */ + curbyte += aimutil_put16(newpacket->data+curbyte, 0x000a); + curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); + curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001); + + /* + * 0003/0004: IP address + */ + + curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003); + curbyte += aimutil_put16(newpacket->data+curbyte, 0x0004); + + for(i = 0; i < 4; i++) + curbyte += aimutil_put8(newpacket->data+curbyte, d[i]); /* already in network byte order */ + + /* + * 0005/0002: Port + */ + + curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005); + curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); + curbyte += aimutil_put16(newpacket->data+curbyte, port); + + /* + * 000f/0000: umm.. dunno. Zigamorph[1]? + * [1]: see esr's TNHD. + */ + + curbyte += aimutil_put16(newpacket->data+curbyte, 0x000f); + curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); + + printf("curbyte: 0x%x\n",curbyte); + + newpacket->commandlen = curbyte; + newpacket->lock = 0; + + aim_tx_enqueue(sess, newpacket); + + /* + * allocate and set up our connection + */ + + i = fcntl(listenfd, F_GETFL, 0); + fcntl(listenfd, F_SETFL, i | O_NONBLOCK); + + newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS_OUT, NULL); + if (!newconn) { + perror("aim_newconn"); + aim_conn_kill(sess, &newconn); + return NULL; + } + + newconn->fd = listenfd; + newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM; + newconn->priv = priv; + printf("faim: listening (fd = %d, unconnected)\n", newconn->fd); + + /* + * XXX We need some way of closing the listener socket after + * n seconds of no connection. -- mid + */ + +#ifdef USE_SNAC_FOR_IMS + { + struct aim_snac_t snac; + + snac.id = sess->snac_nextid; + snac.family = 0x0004; + snac.type = 0x0006; + snac.flags = 0x0000; + + snac.data = malloc(strlen(destsn)+1); + memcpy(snac.data, destsn, strlen(destsn)+1); + + aim_newsnac(sess, &snac); + + aim_cleansnacs(sess, 60); /* clean out all SNACs over 60sec old */ + } +#endif + + return (newconn); +} + + +struct aim_conn_t *aim_directim_connect(struct aim_session_t *sess, + struct aim_conn_t *conn, + struct aim_directim_priv *priv ) +{ + struct aim_conn_t *newconn = NULL;; + + newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, priv->ip); + if (!newconn || (newconn->fd == -1)) { + printf("could not connect to %s\n", priv->ip); + perror("aim_newconn"); + aim_conn_kill(sess, &newconn); + return NULL; + } else { + newconn->subtype = AIM_CONN_SUBTYPE_OFT_DIRECTIM; + newconn->priv = priv; + printf("faim: connected to peer (fd = %d)\n", newconn->fd); + return newconn; + } + return newconn; +} + +u_long aim_accepttransfer(struct aim_session_t *sess, + struct aim_conn_t *conn, + struct aim_conn_t *oftconn, + char *sn, + char *cookie, + unsigned short rendid) +{ + struct command_tx_struct *newpacket, *newoft; + struct aim_fileheader_t *listingfh; + int curbyte, i; + /* now for the oft bits */ + + if(rendid == AIM_CAPS_GETFILE) { + printf("jbm: getfile request accept\n"); + if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x1108, oftconn, 0))) { + printf("faim: accept_transfer: tx_new OFT failed\n"); + return -1; + } + + newoft->lock = 1; + + memcpy(newoft->hdr.oft.magic, "OFT2", 4); + newoft->hdr.oft.hdr2len = 0xf8; /* 0x100 - 8 */ + + if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) { + free(newoft); + return -1; + } + + listingfh = aim_getlisting(sess); + + memcpy(listingfh->bcookie, cookie, 8); + + curbyte = 0; + + for(i = 0; i < 8; i++) + curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, cookie[i]); + curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->encrypt); + curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->compress); + curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->totfiles); + curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->filesleft); + curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->totparts); + curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->partsleft); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->totsize); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->size); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->modtime); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->checksum); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->rfrcsum); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->rfsize); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->cretime); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->rfcsum); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->nrecvd); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->recvcsum); + + memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->idstring, 32); + curbyte += 32; + + curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, listingfh->flags); + curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, listingfh->lnameoffset); + curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, listingfh->lsizeoffset); + + memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->dummy, 69); + curbyte += 69; + + memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->macfileinfo, 16); + curbyte += 16; + + curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->nencode); + curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->nlanguage); + + memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->name, 64); + curbyte += 64; + + free(listingfh); + + newoft->lock = 0; + aim_tx_enqueue(sess, newoft); + printf("faim: getfile: OFT listing enqueued.\n"); + + } + + + if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(sn)+4+2+8+16))) + return -1; + + newpacket->lock = 1; + + curbyte = aim_putsnac(newpacket->data, 0x0004, 0x0006, 0x0000, sess->snac_nextid); + for (i = 0; i < 8; i++) + curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]); + curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); + curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sn)); + curbyte += aimutil_putstr(newpacket->data+curbyte, sn, strlen(sn)); + curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005); + curbyte += aimutil_put16(newpacket->data+curbyte, 0x001a); + curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002 /* accept */); + for (i = 0; i < 8; i++) + curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]); + curbyte += aim_putcap(newpacket->data+curbyte, 0x10, rendid); + + newpacket->lock = 0; + aim_tx_enqueue(sess, newpacket); + + + + return (sess->snac_nextid++); +} + +/* + * aim_getlisting() + * + * Get file listing.txt info. where else to put it? i + * dunno. client-side issue for sure tho. for now we just side-step + * the issue with a nice default. =) + * + */ + +struct aim_fileheader_t *aim_getlisting(struct aim_session_t *sess) +{ + struct aim_fileheader_t *fh; + + if(!(fh = (struct aim_fileheader_t*)calloc(1, sizeof(struct aim_fileheader_t)))) + return NULL; + + fh->encrypt = 0x0000; + fh->compress = 0x0000; + fh->totfiles = 0x0001; + fh->filesleft = 0x0001; + fh->totparts = 0x0001; + fh->partsleft = 0x0001; + fh->totsize = 0x00000064; + fh->size = 0x00000024; /* ls -l listing.txt */ + fh->modtime = (int)time(NULL); /*0x39441fb4; */ + fh->checksum = 0xb8350000; + fh->rfcsum = 0x00000000; + fh->rfsize = 0x00000000; + fh->cretime = 0x00000000; + fh->rfcsum = 0x00000000; + fh->nrecvd = 0x00000000; + fh->recvcsum = 0x00000000; + + memset(fh->idstring, 0, 32/*sizeof(fh->idstring)*/); + memcpy(fh->idstring, "OFT_Windows ICBMFT V1.1 32", 32/*sizeof(fh->idstring)*/); + memset(fh->idstring+strlen(fh->idstring), 0, 32-strlen(fh->idstring)); /* jbm hack */ + + fh->flags = 0x02; + fh->lnameoffset = 0x1a; + fh->lsizeoffset = 0x10; + + memset(fh->dummy, 0, 69/*sizeof(fh->dummy)*/); + /* fh->dummy = ;*/ + + memset(fh->macfileinfo, 0, 16/*sizeof(fh->macfileinfo)*/); + /* fh->macfileinfo = ; */ + + fh->nencode = 0x0000; + fh->nlanguage = 0x0000; + + memset(fh->name, 0, 64/*sizeof(fh->name)*/); + memcpy(fh->name, "listing.txt", 64 /*sizeof(fh->name)*/); + memset(fh->name+strlen(fh->name), 0, 64-strlen(fh->name)); /* jbm hack */ + + printf("jbm: fh name %s / %s\n", fh->name, (fh->name+(strlen(fh->name)))); + return fh; +} + +/* + * establish: create a listening socket on a port. you need to call + * accept() when it's connected. + * portnum is the port number to bind to. + * returns your fd + */ + +int aim_listenestablish(u_short portnum) +{ + int listenfd; + const int on = 1; + struct addrinfo hints, *res, *ressave; + char serv[5]; + sprintf(serv, "%d", portnum); + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_flags = AI_PASSIVE; + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + if (getaddrinfo(NULL/*any IP*/, serv, &hints, &res) != 0) { + perror("getaddrinfo"); + return -1; + } + ressave = res; + do { + listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + if (listenfd < 0) + continue; + setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); + if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0) + break; /* success */ + close(listenfd); + } while ( (res = res->ai_next) ); + if (!res) + return -1; + if (listen(listenfd, 1024)!=0) { + perror("listen"); + return -1; + } + freeaddrinfo(ressave); + return listenfd; +} + +int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *conn) +{ + + /* XXX: NOT THREAD SAFE RIGHT NOW. the locks are acting up. deal. -- jbm */ + + unsigned char hdrbuf1[6]; + unsigned char *hdr = NULL; + int hdrlen, hdrtype; + int flags = 0; + rxcallback_t userfunc = NULL; + + + memset(hdrbuf1, 0, sizeof(hdrbuf1)); + + faim_mutex_lock(&conn->active); /* gets locked down for the entirety */ + + if ( (hdrlen = read(conn->fd, hdrbuf1, 6)) < 6) { + if(hdrlen < 0) + perror("read"); + printf("faim: rend: read error (fd: %i) %02x%02x%02x%02x%02x%02x (%i)\n", conn->fd, hdrbuf1[0],hdrbuf1[1],hdrbuf1[0],hdrbuf1[0],hdrbuf1[0],hdrbuf1[0],hdrlen); + faim_mutex_unlock(&conn->active); + aim_conn_close(conn); + return -1; + } + + hdrlen = aimutil_get16(hdrbuf1+4); + + hdrlen -= 6; + if (!(hdr = malloc(hdrlen))) + return -1; + + if (read(conn->fd, hdr, hdrlen) < hdrlen) { + perror("read"); + printf("faim: rend: read2 error\n"); + free(hdr); + faim_mutex_unlock(&conn->active); + aim_conn_close(conn); + return 0; /* see comment on previous read check */ + } + + hdrtype = aimutil_get16(hdr); + + switch (hdrtype) { + case 0x0001: { /* directim */ + int payloadlength = 0; + char *snptr = NULL; + struct aim_directim_priv *priv; + int i; + + priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv)); + + payloadlength = aimutil_get32(hdr+22); + flags = aimutil_get16(hdr+32); + snptr = hdr+38; + + strncpy(priv->sn, snptr, MAXSNLEN); + +#if 0 + printf("faim: OFT frame: %04x / %04x / %04x / %s\n", hdrtype, payloadlength, flags, snptr); +#endif + + if (flags == 0x000e) { + faim_mutex_unlock(&conn->active); + if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING)) ) + return userfunc(sess, NULL, snptr); + } else if ((flags == 0x0000) && payloadlength) { + unsigned char *msg; + + if(! (msg = calloc(1, payloadlength+1)) ) { + faim_mutex_unlock(&conn->active); + return 0; + } + + if (recv(conn->fd, msg, payloadlength, MSG_WAITALL) < payloadlength) { + perror("read"); + printf("faim: rend: read3 error\n"); + free(msg); + faim_mutex_unlock(&conn->active); + aim_conn_close(conn); + return -1; + } + faim_mutex_unlock(&conn->active); + msg[payloadlength] = '\0'; +#if 0 + printf("faim: directim: %s/%04x/%04x/%s\n", snptr, payloadlength, flags, msg); +#endif + + if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING)) ) + i = userfunc(sess, NULL, conn, snptr, msg); + + free(msg); + return i; + } + break; + } + case 0x1209: { /* get file first */ + struct aim_filetransfer_priv *ft; + struct aim_fileheader_t *fh; + struct aim_msgcookie_t *cook; + + int commandlen; + char *data; + + printf("faim: rend: fileget 0x1209\n"); + + if(hdrlen != 0x100) + printf("faim: fileget_command(1209): um. hdrlen != 0x100.. 0x%x\n", hdrlen); + + if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) { + printf("faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n"); + faim_mutex_unlock(&conn->active); + return 0; + } + + fh = aim_oft_getfh(hdr); + + memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t)); + + cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET); + + if(cook->data) + free(cook->data); /* XXX */ + + cook->data = ft; + + aim_cachecookie(sess, cook); + + commandlen = 36; + + data = calloc(1, commandlen); + memcpy(data, "01/01/1999 00:00 100 file.txt\r\n", commandlen); + + if (write(conn->fd, data, commandlen) != commandlen) { + perror("listing write error"); + } + faim_mutex_unlock(&conn->active); + + printf("jbm: hit end of 1209\n"); + + break; + } + case 0x120b: { /* get file second */ + struct aim_filetransfer_priv *ft; + struct aim_msgcookie_t *cook; + + struct aim_fileheader_t *fh; + + printf("faim: rend: fileget 120b\n"); + + if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) { + printf("faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n"); + faim_mutex_unlock(&conn->active); + return 0; + } + + if(hdrlen != 0x100) + printf("faim: fileget_command(120b): um. hdrlen != 0x100..\n"); + + fh = aim_oft_getfh(hdr); + + memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t)); + + cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET); + + if(cook->data) + free(cook->data); /* XXX: integrate cookie caching */ + + cook->data = ft; + + aim_cachecookie(sess, cook); + + faim_mutex_unlock(&conn->active); + + break; + } + case 0x120c: { /* yet more get file */ + struct aim_filetransfer_priv *ft; + struct aim_msgcookie_t *cook; + struct aim_fileheader_t *listingfh; + struct command_tx_struct *newoft; + int curbyte, i; + + printf("faim: rend: fileget 120c\n"); + + if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) { + printf("faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n"); + faim_mutex_unlock(&conn->active); + return 0; + } + + if(hdrlen != 0x100) + printf("faim: fileget_command(120c): um. hdrlen != 0x100..\n"); + + listingfh = aim_oft_getfh((char *)hdr); + + memcpy(&(ft->fh), listingfh, sizeof(struct aim_fileheader_t)); + + cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET); + + if(cook->data) + free(cook->data); /* XXX */ + + cook->data = ft; + + aim_cachecookie(sess, cook); + + faim_mutex_unlock(&conn->active); + + printf("faim: fileget: %s seems to want %s\n", ft->sn, ft->fh.name); + + if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0101, conn, 0/*listingfh->size*/))) { + printf("faim: send_final_transfer: tx_new OFT failed\n"); + return 0; + } + + /* XXX: actually implement Real Handling of all this */ + + printf("jbm: listingfh->size: 0x%lx\n", listingfh->size); + + newoft->lock = 1; + + /* if(!(newoft->data = calloc(1, listingfh->size))) { + printf("newoft data malloc failed. bombing.\n"); + return 0; + }*/ + + if(newoft->commandlen > 0) { + int i; + bzero(newoft->data, newoft->commandlen); + for(i = 0; i < newoft->commandlen; i++) + newoft->data[i] = 0x30 + (i%10); + + // memcpy(newoft->data, "This has been a Test\r\n-josh\r\n", newoft->commandlen); + } + + memcpy(newoft->hdr.oft.magic, "OFT2", 4); + newoft->hdr.oft.hdr2len = 0xf8; /* 0x100 - 8 */ + + if (!(newoft->hdr.oft.hdr2 = calloc(1,newoft->hdr.oft.hdr2len))) { + if(newoft->data) + free(newoft->data); /* XXX: make this into a destructor function */ + free(newoft); + return 0; + } + + memcpy(listingfh->bcookie, ft->fh.bcookie, 8); + + curbyte = 0; + + for(i = 0; i < 8; i++) + curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, listingfh->bcookie[i]); + curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->encrypt); + curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->compress); + curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->totfiles); + curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->filesleft); + curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->totparts); + curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->partsleft); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->totsize); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->size); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->modtime); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->checksum); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->rfrcsum); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->rfsize); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->cretime); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, listingfh->rfcsum); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, 0 /*listingfh->nrecvd*/); + curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, 0/*listingfh->recvcsum*/); + + strncpy(newoft->hdr.oft.hdr2+curbyte, listingfh->idstring, 32); + curbyte += 32; + + curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, 0x20 /*listingfh->flags */); + curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, listingfh->lnameoffset); + curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, listingfh->lsizeoffset); + + memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->dummy, 69); + curbyte += 69; + + memcpy(newoft->hdr.oft.hdr2+curbyte, listingfh->macfileinfo, 16); + curbyte += 16; + + curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->nencode); + curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->nlanguage); + + strncpy(newoft->hdr.oft.hdr2+curbyte, listingfh->name, 64); + curbyte += 64; + + free(listingfh); + + newoft->lock = 0; + aim_tx_enqueue(sess, newoft); + printf("jbm: OFT listing enqueued.\n"); + + break; + } + case 0x0202: { /* get file: ready to recieve data */ + char *c; + int i; + + struct aim_fileheader_t *fh; + fh = aim_oft_getfh((char *)hdr); + + c = (char *)calloc(1, fh->size); + + printf("looks like we're ready to send data.(oft 0x0202)\n"); + + + + for(i = 0; i < fh->size; i++) + c[i] = 0x30 + (i%10); + + if ( (i = write(conn->fd, c, fh->size)) != fh->size ) { + printf("whoopsy, didn't write it all...\n"); + } + + faim_mutex_unlock(&conn->active); + + break; + } + case 0x0204: { /* get file: finished. close it up */ + printf("looks like we're done with a transfer (oft 0x0204)\n"); + faim_mutex_unlock(&conn->active); + aim_conn_close(conn); + break; + } + default: { + printf("OFT frame: type %04x\n", hdrtype); + /* data connection may be unreliable here */ + faim_mutex_unlock(&conn->active); + break; + } + } /* switch */ + + free(hdr); + + return 0; +} + +/* + * this currently feeds totally bogus data + */ + +struct aim_fileheader_t *aim_oft_getfh(char *hdr) +{ + struct aim_fileheader_t *fh; + int i, j; + + if(!(fh = calloc(1, sizeof(struct aim_fileheader_t)))) + return NULL; + + /* [0] and [1] are the type. we can ignore those here. */ + + i = 2; + + for(j = 0; j < 8; j++, i++) + fh->bcookie[j] = hdr[i]; + fh->encrypt = aimutil_get16(hdr+i); + i += 2; + fh->compress = aimutil_get16(hdr+i); + i += 2; + fh->totfiles = aimutil_get16(hdr+i); + i += 2; + fh->filesleft = aimutil_get16(hdr+i); + i += 2; + fh->totparts = aimutil_get16(hdr+i); + i += 2; + fh->partsleft = aimutil_get16(hdr+i); + i += 2; + fh->totsize = aimutil_get32(hdr+i); + i += 4; + fh->size = aimutil_get32(hdr+i); + i += 4; + fh->modtime = aimutil_get32(hdr+i); + i += 4; + fh->checksum = aimutil_get32(hdr+i); + i += 4; + fh->rfrcsum = aimutil_get32(hdr+i); + i += 4; + fh->rfsize = aimutil_get32(hdr+i); + i += 4; + fh->cretime = aimutil_get32(hdr+i); + i += 4; + fh->rfcsum = aimutil_get32(hdr+i); + i += 4; + fh->nrecvd = aimutil_get32(hdr+i); + i += 4; + fh->recvcsum = aimutil_get32(hdr+i); + i += 4; + + memcpy(fh->idstring, hdr+i, 32); + i += 32; + + fh->flags = aimutil_get8(hdr+i); + i += 1; + fh->lnameoffset = aimutil_get8(hdr+i); + i += 1; + fh->lsizeoffset = aimutil_get8(hdr+i); + i += 1; + + memcpy(fh->dummy, hdr+i, 69); + i += 69; + + memcpy(fh->macfileinfo, hdr+i, 16); + i += 16; + + fh->nencode = aimutil_get16(hdr+i); + i += 2; + fh->nlanguage = aimutil_get16(hdr+i); + i += 2; + + memcpy(fh->name, hdr+i, 64); + i += 64; + + return fh; +}
--- a/libfaim/aim_im.c Tue Jul 18 05:23:25 2000 +0000 +++ b/libfaim/aim_im.c Tue Jul 18 05:37:39 2000 +0000 @@ -139,88 +139,6 @@ return (sess->snac_nextid++); } -struct aim_directim_priv { - unsigned char cookie[8]; - char sn[MAXSNLEN+1]; -}; - -int aim_send_im_direct(struct aim_session_t *sess, - struct aim_conn_t *conn, - char *msg) -{ - struct command_tx_struct *newpacket; - struct aim_directim_priv *priv = NULL; - int i; - - if (strlen(msg) >= MAXMSGLEN) - return -1; - - if (!sess || !conn || (conn->type != AIM_CONN_TYPE_RENDEZVOUS) || !conn->priv) { - printf("faim: directim: invalid arguments\n"); - return -1; - } - - if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0001, conn, strlen(msg)))) { - printf("faim: directim: tx_new failed\n"); - return -1; - } - - newpacket->lock = 1; /* lock struct */ - - priv = (struct aim_directim_priv *)conn->priv; - - newpacket->hdr.oft.hdr2len = 0x44; - - if (!(newpacket->hdr.oft.hdr2 = malloc(newpacket->hdr.oft.hdr2len))) { - free(newpacket); - return -1; - } - - i = 0; - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0006); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - - i += aimutil_putstr(newpacket->hdr.oft.hdr2+i, priv->cookie, 8); - - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - - i += aimutil_put32(newpacket->hdr.oft.hdr2+i, strlen(msg)); - - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - - i += aimutil_putstr(newpacket->hdr.oft.hdr2+i, sess->logininfo.screen_name, strlen(sess->logininfo.screen_name)); - - i = 52; - i += aimutil_put8(newpacket->hdr.oft.hdr2+i, 0x00); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000); - - memcpy(newpacket->data, msg, strlen(msg)); - - newpacket->lock = 0; - - aim_tx_enqueue(sess, newpacket); - - return 0; -} - int aim_parse_outgoing_im_middle(struct aim_session_t *sess, struct command_rx_struct *command) { @@ -382,7 +300,7 @@ u_int j = 0, y = 0, z = 0; char *msg = NULL; u_int icbmflags = 0; - struct aim_tlv_t *msgblocktlv, *tmptlv; + struct aim_tlv_t *msgblocktlv; u_char *msgblock; u_short flag1,flag2; @@ -535,8 +453,11 @@ if (!list2 || ((reqclass != AIM_CAPS_IMIMAGE) && !(aim_gettlv(list2, 0x2711, 1)))) { struct aim_msgcookie_t *cook; + int type; + + type = aim_msgcookie_gettype(reqclass); /* XXX: fix this shitty code */ - if ((cook = aim_uncachecookie(sess, cookie)) == NULL) { + if ((cook = aim_uncachecookie(sess, cookie, type)) == NULL) { printf("faim: non-data rendezvous thats not in cache!\n"); aim_freetlvchain(&list2); aim_freetlvchain(&tlvlist); @@ -544,21 +465,21 @@ } if (cook->type == AIM_CAPS_SENDFILE) { - struct aim_filetransfer_t *ft; + struct aim_filetransfer_priv *ft; if (cook->data) { struct aim_tlv_t *errortlv; int errorcode = -1; - ft = (struct aim_filetransfer_t *)cook->data; + ft = (struct aim_filetransfer_priv *)cook->data; if ((errortlv = aim_gettlv(list2, 0x000b, 1))) { errorcode = aimutil_get16(errortlv->value); } if (errorcode) { - printf("faim: transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sender, ft->ip, ft->filename, errorcode); + printf("faim: transfer from %s (%s) for %s cancelled (error code %d)\n", ft->sn, ft->ip, ft->fh.name, errorcode); } else if (status == 0x0002) { /* connection accepted */ - printf("faim: transfer from %s (%s) for %s accepted\n", ft->sender, ft->ip, ft->filename); + printf("faim: transfer from %s (%s) for %s accepted\n", ft->sn, ft->ip, ft->fh.name); } free(cook->data); } else { @@ -594,14 +515,18 @@ &userinfo); } else if (reqclass & AIM_CAPS_VOICE) { - struct aim_msgcookie_t cachedcook; + struct aim_msgcookie_t *cachedcook; printf("faim: rend: voice!\n"); - memcpy(cachedcook.cookie, cookie, 8); - cachedcook.type = AIM_CAPS_VOICE; - cachedcook.data = NULL; - if (aim_cachecookie(sess, &cachedcook) != 0) + if(!(cachedcook = (struct aim_msgcookie_t*)calloc(1, sizeof(struct aim_msgcookie_t)))) + return 1; + + memcpy(cachedcook->cookie, cookie, 8); + cachedcook->type = AIM_COOKIETYPE_OFTVOICE; + cachedcook->data = NULL; + + if (aim_cachecookie(sess, cachedcook) != 0) printf("faim: ERROR caching message cookie\n"); /* XXX: implement all this */ @@ -611,19 +536,15 @@ */ userfunc = aim_callhandler(command->conn, 0x0004, 0x0007); if (userfunc || (i = 0)) { - i = userfunc(sess, - command, - channel, - reqclass, - &userinfo); + i = userfunc(sess, command, channel, reqclass, &userinfo); } - } else if (reqclass & AIM_CAPS_IMIMAGE) { + } else if ((reqclass & AIM_CAPS_IMIMAGE) || (reqclass & AIM_CAPS_BUDDYICON)) { char ip[30]; - struct aim_msgcookie_t cachedcook; + struct aim_directim_priv *priv; memset(ip, 0, sizeof(ip)); - if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0003, 1)) { + if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) { struct aim_tlv_t *iptlv, *porttlv; iptlv = aim_gettlv(list2, 0x0003, 1); @@ -641,39 +562,13 @@ userinfo.sn, ip); -#if 0 - { - struct aim_conn_t *newconn; - - newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, ip); - if (!newconn || (newconn->fd == -1)) { - printf("could not connect to %s\n", ip); - perror("aim_newconn"); - aim_conn_kill(sess, &newconn); - } else { - struct aim_directim_priv *priv; - priv = (struct aim_directim_priv *)malloc(sizeof(struct aim_directim_priv)); - memcpy(priv->cookie, cookie, 8); - strncpy(priv->sn, userinfo.sn, MAXSNLEN); - newconn->priv = priv; - printf("faim: connected to peer (fd = %d)\n", newconn->fd); - } - } -#endif + /* XXX: there are a couple of different request packets for + * different things */ -#if 0 - memcpy(cachedcook.cookie, cookie, 8); - - ft = malloc(sizeof(struct aim_filetransfer_t)); - strncpy(ft->sender, userinfo.sn, sizeof(ft->sender)); - strncpy(ft->ip, ip, sizeof(ft->ip)); - ft->filename = strdup(miscinfo->value+8); - cachedcook.type = AIM_CAPS_SENDFILE; - cachedcook.data = ft; - - if (aim_cachecookie(sess, &cachedcook) != 0) - printf("faim: ERROR caching message cookie\n"); -#endif + priv = (struct aim_directim_priv *)calloc(1, sizeof(struct aim_directim_priv)); + memcpy(priv->ip, ip, sizeof(priv->ip)); + memcpy(priv->sn, userinfo.sn, sizeof(priv->sn)); + memcpy(priv->cookie, cookie, sizeof(priv->cookie)); /* * Call client. @@ -684,7 +579,7 @@ command, channel, reqclass, - &userinfo); + &userinfo, priv); } else if (reqclass & AIM_CAPS_CHAT) { struct aim_tlv_t *miscinfo; @@ -722,7 +617,75 @@ free(encoding); free(lang); } else if (reqclass & AIM_CAPS_GETFILE) { + char ip[30]; + char *desc = NULL; + struct aim_msgcookie_t *cachedcook; + struct aim_filetransfer_priv *ft; + struct aim_tlv_t *miscinfo; + struct aim_conn_t *newconn; + if (!(cachedcook = calloc(1, sizeof(struct aim_msgcookie_t)))) + return 0; + + memset(ip, 0, sizeof(ip)); + + if (!(miscinfo = aim_gettlv(list2, 0x2711, 1))) { + free(cachedcook); + return 0; + } + + if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0005, 1)) { + struct aim_tlv_t *iptlv, *porttlv; + + if (!(iptlv = aim_gettlv(list2, 0x0003, 1)) || !(porttlv = aim_gettlv(list2, 0x0005, 1))) { + free(cachedcook); + return 0; + } + + snprintf(ip, sizeof(ip)-1, "%d.%d.%d.%d:%d", + aimutil_get8(iptlv->value+0), + aimutil_get8(iptlv->value+1), + aimutil_get8(iptlv->value+2), + aimutil_get8(iptlv->value+3), + aimutil_get16(porttlv->value)); + } + + printf("faim: rend: file get request from %s (%s)\n", userinfo.sn, ip); + +#if 0 /* XXX finish this */ + newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS, ip); + if (!newconn || (newconn->fd == -1)) { + printf("could not connect to %s\n", ip); + perror("aim_newconn"); + aim_conn_kill(sess, &newconn); + } else { + struct aim_filetransfer_priv *priv; + priv = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)); + memcpy(priv->cookie, cookie, 8); + strncpy(priv->sn, userinfo.sn, MAXSNLEN); + newconn->priv = priv; + printf("faim: connected to peer (fd = %d)\n", newconn->fd); + } + + memcpy(cachedcook->cookie, cookie, 8); + + ft = malloc(sizeof(struct aim_filetransfer_priv)); + ft->state = 1; + strncpy(ft->sn, userinfo.sn, sizeof(ft->sn)); + strncpy(ft->ip, ip, sizeof(ft->ip)); +#if 0 + strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name)); +#endif + cachedcook->type = AIM_COOKIETYPE_OFTGET; + cachedcook->data = ft; + + if (aim_cachecookie(sess, cachedcook) != 0) + printf("faim: ERROR caching message cookie\n"); + + aim_accepttransfer(sess, command->conn, newconn, ft->sn, cookie, AIM_CAPS_GETFILE); + + free(desc); +#endif /* * Call client. */ @@ -735,26 +698,17 @@ &userinfo); } else if (reqclass & AIM_CAPS_SENDFILE) { - /* - * Call client. - */ - userfunc = aim_callhandler(command->conn, 0x0004, 0x0007); - if (userfunc || (i = 0)) - i = userfunc(sess, - command, - channel, - reqclass, - &userinfo); #if 0 - char ip[30]; - char *desc = NULL; - struct aim_msgcookie_t cachedcook; - struct aim_filetransfer_t *ft; - struct aim_tlv_t *miscinfo; + char ip[30]; + char *desc = NULL; + struct aim_msgcookie_t *cachedcook; + struct aim_filetransfer_priv *ft; + struct aim_tlv_t *miscinfo; memset(ip, 0, sizeof(ip)); - miscinfo = aim_gettlv(list2, 0x2711, 1); + if (!(miscinfo = aim_gettlv(list2, 0x2711, 1))) + return 0; if (aim_gettlv(list2, 0x0003, 1) && aim_gettlv(list2, 0x0003, 1)) { struct aim_tlv_t *iptlv, *porttlv; @@ -780,24 +734,34 @@ desc, ip); - memcpy(cachedcook.cookie, cookie, 8); + memcpy(cachedcook->cookie, cookie, 8); - ft = malloc(sizeof(struct aim_filetransfer_t)); - strncpy(ft->sender, userinfo.sn, sizeof(ft->sender)); + ft = malloc(sizeof(struct aim_filetransfer_priv)); + strncpy(ft->sn, userinfo.sn, sizeof(ft->sn)); strncpy(ft->ip, ip, sizeof(ft->ip)); - ft->filename = strdup(miscinfo->value+8); - cachedcook.type = AIM_CAPS_SENDFILE; - cachedcook.data = ft; + strncpy(ft->fh.name, miscinfo->value+8, sizeof(ft->fh.name)); + cachedcook->type = AIM_COOKIETYPE_OFTSEND; + cachedcook->data = ft; - if (aim_cachecookie(sess, &cachedcook) != 0) + if (aim_cachecookie(sess, cachedcook) != 0) printf("faim: ERROR caching message cookie\n"); - aim_accepttransfer(sess, command->conn, ft->sender, cookie, AIM_CAPS_SENDFILE); - - free(desc); + aim_accepttransfer(sess, command->conn, ft->sn, cookie, AIM_CAPS_SENDFILE); + + if (desc) + free(desc); #endif - i = 1; + /* + * Call client. + */ + userfunc = aim_callhandler(command->conn, 0x0004, 0x0007); + if (userfunc || (i = 0)) + i = userfunc(sess, + command, + channel, + reqclass, + &userinfo); } else { printf("faim: rend: unknown rendezvous 0x%04x\n", reqclass); } @@ -814,39 +778,6 @@ return i; } -u_long aim_accepttransfer(struct aim_session_t *sess, - struct aim_conn_t *conn, - char *sender, - char *cookie, - unsigned short rendid) -{ - struct command_tx_struct *newpacket; - int curbyte, i; - - if(!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+8+2+1+strlen(sender)+4+2+8+16))) - return -1; - - newpacket->lock = 1; - - curbyte = aim_putsnac(newpacket->data, 0x0004, 0x0006, 0x0000, sess->snac_nextid); - for (i = 0; i < 8; i++) - curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]); - curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); - curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sender)); - curbyte += aimutil_putstr(newpacket->data+curbyte, sender, strlen(sender)); - curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005); - curbyte += aimutil_put16(newpacket->data+curbyte, 0x001a); - curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002 /* accept */); - for (i = 0; i < 8; i++) - curbyte += aimutil_put8(newpacket->data+curbyte, cookie[i]); - curbyte += aim_putcap(newpacket->data+curbyte, 0x10, rendid); - - newpacket->lock = 0; - aim_tx_enqueue(sess, newpacket); - - return (sess->snac_nextid++); -} - /* * Possible codes: * AIM_TRANSFER_DENY_NOTSUPPORTED -- "client does not support"
--- a/libfaim/aim_msgcookie.c Tue Jul 18 05:23:25 2000 +0000 +++ b/libfaim/aim_msgcookie.c Tue Jul 18 05:37:39 2000 +0000 @@ -1,11 +1,31 @@ +/* + * Cookie Caching stuff. Adam wrote this, apparently just some + * derivatives of n's SNAC work. I cleaned it up, added comments. + * + * I'm going to rewrite this stuff eventually, honest. -jbm + * + */ /* - * - * + * I'm assuming that cookies are type-specific. that is, we can have + * "1234578" for type 1 and type 2 concurrently. if i'm wrong, then we + * lose some error checking. if we assume cookies are not type-specific and are + * wrong, we get quirky behavior when cookies step on each others' toes. */ #include <faim/aim.h> +/* + * aim_cachecookie: + * appends a cookie to the cookie list for sess. + * - if cookie->cookie for type cookie->type is found, addtime is updated. + * - copies cookie struct; you need to free() it afterwards; + * - cookie->data is not copied, but passed along. don't free it. + * - newcook->addtime is updated accordingly; + * - cookie->type is just passed across. + * + * returns -1 on error, 0 on success. */ + int aim_cachecookie(struct aim_session_t *sess, struct aim_msgcookie_t *cookie) { @@ -14,45 +34,68 @@ if (!cookie) return -1; + if( (newcook = aim_checkcookie(sess, cookie->cookie, cookie->type)) ) { + newcook->addtime = time(NULL); + if(cookie->data != newcook->data) { + + printf("faim: cachecookie: matching cookie/type pair " + "%x%x%x%x%x%x%x%x/%x has different *data. free()ing cookie copy..\n", + cookie->cookie[0], cookie->cookie[1], cookie->cookie[2], + cookie->cookie[3], cookie->cookie[4], cookie->cookie[5], + cookie->cookie[6], cookie->cookie[7], cookie->type); + + free(cookie->data); + } + return(0); + } + if (!(newcook = malloc(sizeof(struct aim_msgcookie_t)))) return -1; memcpy(newcook, cookie, sizeof(struct aim_msgcookie_t)); newcook->addtime = time(NULL); + + if(newcook->next) + printf("faim: cachecookie: newcook->next isn't NULL ???\n"); + newcook->next = NULL; - + cur = sess->msgcookies; if (cur == NULL) { sess->msgcookies = newcook; return 0; } + while (cur->next != NULL) cur = cur->next; cur->next = newcook; - + return 0; } -struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess, - char *cookie) +/* + * aim_uncachecookie: + * takes a cookie string and grabs the cookie struct associated with + * it. removes struct from chain. returns the struct if found, or + * NULL on not found. + */ + +struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess, char *cookie, int type) { struct aim_msgcookie_t *cur; - if (!cookie) + if (!cookie || !sess->msgcookies) return NULL; - if (!sess->msgcookies) - return NULL; + cur = sess->msgcookies; - if (memcmp(sess->msgcookies->cookie, cookie, 8) == 0) { - cur = sess->msgcookies; + if ( (memcmp(cur->cookie, cookie, 8) == 0) && (cur->type == type) ) { sess->msgcookies = cur->next; return cur; } - cur = sess->msgcookies; while (cur->next) { - if (memcmp(cur->next->cookie, cookie, 8) == 0) { + if ( (memcmp(cur->next->cookie, cookie, 8) == 0) && (cur->next->type == type) ) { struct aim_msgcookie_t *tmp; tmp = cur->next; @@ -65,10 +108,20 @@ } /* + * aim_purgecookies: + * purge out old cookies + * + * finds old cookies, calls uncache on them. + * + * this is highly inefficient, but It Works. and i don't feel like + * totally rewriting this. it might have some concurrency issues as + * well, if i rewrite it. + * + * i'll avoid the puns. */ -int aim_purgecookies(struct aim_session_t *sess) + +int aim_purgecookies(struct aim_session_t *sess, int maxage) { - int maxage = 5*60; struct aim_msgcookie_t *cur; struct aim_msgcookie_t *remed = NULL; time_t curtime; @@ -78,22 +131,93 @@ curtime = time(&curtime); while (cur) { - if ( (cur) && (((cur->addtime) + maxage) < curtime)) { + if ( (cur->addtime) > (curtime - maxage) ) { #if DEBUG > 1 printf("aimmsgcookie: WARNING purged obsolete message cookie %x%x%x%x %x%x%x%x\n", cur->cookie[0], cur->cookie[1], cur->cookie[2], cur->cookie[3], cur->cookie[4], cur->cookie[5], cur->cookie[6], cur->cookie[7]); #endif - remed = aim_uncachecookie(sess, cur->cookie); + + remed = aim_uncachecookie(sess, cur->cookie, cur->type); if (remed) { if (remed->data) free(remed->data); free(remed); } } + cur = cur->next; + } return 0; } +struct aim_msgcookie_t *aim_mkcookie(unsigned char *c, int type, void *data) +{ + struct aim_msgcookie_t *cookie; + + if(!c) + return(NULL); + + if( (cookie = calloc(1, sizeof(struct aim_msgcookie_t))) == NULL) + return(NULL); + + cookie->data = data; + + cookie->type = type; + + memcpy(cookie->cookie, c, 8); + + return(cookie); +} + +struct aim_msgcookie_t *aim_checkcookie(struct aim_session_t *sess, char *cookie, int type) +{ + struct aim_msgcookie_t *cur; + + if(!sess->msgcookies) + return NULL; + + cur = sess->msgcookies; + + if( (memcmp(cur->cookie, cookie, 8) == 0) && (cur->type == type)) + return(cur); + + while( (cur = cur->next) ) + if( (memcmp(cur->cookie, cookie, 8) == 0) && (cur->type == type)) + return(cur); + + return(NULL); +} + +int aim_freecookie(struct aim_msgcookie_t *cookie) { + return(0); +} + +int aim_msgcookie_gettype(int reqclass) { + /* XXX: hokey-assed. needs fixed. */ + switch(reqclass) { + case AIM_CAPS_BUDDYICON: + return AIM_COOKIETYPE_OFTICON; + break; + case AIM_CAPS_VOICE: + return AIM_COOKIETYPE_OFTVOICE; + break; + case AIM_CAPS_IMIMAGE: + return AIM_COOKIETYPE_OFTIMAGE; + break; + case AIM_CAPS_CHAT: + return AIM_COOKIETYPE_CHAT; + break; + case AIM_CAPS_GETFILE: + return AIM_COOKIETYPE_OFTGET; + break; + case AIM_CAPS_SENDFILE: + return AIM_COOKIETYPE_OFTSEND; + break; + default: + return AIM_COOKIETYPE_UNKNOWN; + break; + } +}
--- a/libfaim/aim_rxhandlers.c Tue Jul 18 05:23:25 2000 +0000 +++ b/libfaim/aim_rxhandlers.c Tue Jul 18 05:37:39 2000 +0000 @@ -420,7 +420,7 @@ workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0001, 0x0007, workingPtr); break; case 0x000a: - workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0001, 0x000a, workingPtr); + workingPtr->handled = aim_parse_ratechange_middle(sess, workingPtr); break; case 0x000f: workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0001, 0x000f, workingPtr); @@ -482,6 +482,9 @@ case 0x000a: workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0004, 0x000a, workingPtr); break; + case 0x000c: + workingPtr->handled = aim_parse_msgack_middle(sess, workingPtr); + break; default: workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_MSG, AIM_CB_MSG_DEFAULT, workingPtr); } @@ -555,7 +558,7 @@ else if (subtype == 0x0007) workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0001, 0x0007, workingPtr); else - printf("Chat: unknown snac %04x/%04x\n", family, subtype); + workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, family, subtype, workingPtr); } else if (family == 0x000e) { if (subtype == 0x0002) workingPtr->handled = aim_chat_parse_infoupdate(sess, workingPtr); @@ -586,6 +589,10 @@ break; } + case AIM_CONN_TYPE_RENDEZVOUS_OUT: { + /* not possible */ + break; + } default: printf("\ninternal error: unknown connection type (very bad.) (type = %d, fd = %d, commandlen = %02x)\n\n", workingPtr->conn->type, workingPtr->conn->fd, workingPtr->commandlen); workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_UNKNOWN, workingPtr); @@ -605,8 +612,52 @@ return 0; } +int aim_parse_msgack_middle(struct aim_session_t *sess, struct command_rx_struct *command) +{ + rxcallback_t userfunc = NULL; + char sn[MAXSNLEN]; + unsigned short type; + int i = 10+8; /* skip SNAC and cookie */ + int ret = 1; + unsigned char snlen; + + type = aimutil_get16(command->data+i); + i += 2; + + snlen = aimutil_get8(command->data+i); + i++; + + memset(sn, 0, sizeof(sn)); + strncpy(sn, command->data+i, snlen); + + if ((userfunc = aim_callhandler(command->conn, 0x0004, 0x000c))) + ret = userfunc(sess, command, type, sn); + + return ret; +} + +int aim_parse_ratechange_middle(struct aim_session_t *sess, struct command_rx_struct *command) +{ + rxcallback_t userfunc = NULL; + int i = 10; /* skip SNAC */ + int ret = 1; + unsigned long newrate; + + if (command->commandlen != 0x2f) { + printf("faim: unknown rate change length 0x%04x\n", command->commandlen); + return 1; + } + + newrate = aimutil_get32(command->data+34); + + if ((userfunc = aim_callhandler(command->conn, 0x0001, 0x000a))) + ret = userfunc(sess, command, newrate); + + return ret; +} + int aim_parsemotd_middle(struct aim_session_t *sess, - struct command_rx_struct *command, ...) + struct command_rx_struct *command, ...) { rxcallback_t userfunc = NULL; char *msg;
--- a/libfaim/aim_rxqueue.c Tue Jul 18 05:23:25 2000 +0000 +++ b/libfaim/aim_rxqueue.c Tue Jul 18 05:37:39 2000 +0000 @@ -29,6 +29,8 @@ */ if (conn->type == AIM_CONN_TYPE_RENDEZVOUS) return aim_get_command_rendezvous(sess, conn); + if (conn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) + return 0; /* * Read FLAP header. Six bytes: @@ -40,7 +42,7 @@ */ faim_mutex_lock(&conn->active); if (read(conn->fd, generic, 6) < 6){ - aim_conn_kill(sess, &conn); + aim_conn_close(conn); faim_mutex_unlock(&conn->active); return -1; } @@ -51,6 +53,7 @@ */ if (generic[0] != 0x2a) { faimdprintf(1, "Bad incoming data!"); + aim_conn_close(conn); faim_mutex_unlock(&conn->active); return -1; } @@ -89,7 +92,7 @@ if (read(conn->fd, newrx->data, newrx->commandlen) < newrx->commandlen){ free(newrx->data); free(newrx); - aim_conn_kill(sess, &conn); + aim_conn_close(conn); faim_mutex_unlock(&conn->active); return -1; } @@ -122,82 +125,6 @@ return 0; } -int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *conn) -{ - unsigned char hdrbuf1[6]; - unsigned char *hdr = NULL; - int hdrlen, hdrtype; - int payloadlength = 0; - int flags = 0; - char *snptr = NULL; - - if (read(conn->fd, hdrbuf1, 6) < 6) { - perror("read"); - printf("faim: rend: read error\n"); - aim_conn_kill(sess, &conn); - return -1; - } - - hdrlen = aimutil_get16(hdrbuf1+4); - - hdrlen -= 6; - hdr = malloc(hdrlen); - - faim_mutex_lock(&conn->active); - if (read(conn->fd, hdr, hdrlen) < hdrlen) { - perror("read"); - printf("faim: rend: read2 error\n"); - free(hdr); - faim_mutex_unlock(&conn->active); - aim_conn_kill(sess, &conn); - return -1; - } - - hdrtype = aimutil_get16(hdr); - - switch (hdrtype) { - case 0x0001: { - payloadlength = aimutil_get32(hdr+22); - flags = aimutil_get16(hdr+32); - snptr = hdr+38; - - printf("OFT frame: %04x / %04x / %04x / %s\n", hdrtype, payloadlength, flags, snptr); - - if (flags == 0x000e) { - printf("directim: %s has started typing\n", snptr); - } else if ((flags == 0x0000) && payloadlength) { - unsigned char *buf; - buf = malloc(payloadlength+1); - - /* XXX theres got to be a better way */ - faim_mutex_lock(&conn->active); - if (recv(conn->fd, buf, payloadlength, MSG_WAITALL) < payloadlength) { - perror("read"); - printf("faim: rend: read3 error\n"); - free(buf); - faim_mutex_unlock(&conn->active); - aim_conn_kill(sess, &conn); - return -1; - } - faim_mutex_unlock(&conn->active); - buf[payloadlength] = '\0'; - printf("directim: %s/%04x/%04x/%s\n", snptr, payloadlength, flags, buf); - aim_send_im_direct(sess, conn, buf); - free(buf); - } - break; - } - default: - printf("OFT frame: type %04x\n", hdrtype); - /* data connection may be unreliable here */ - break; - } /* switch */ - - free(hdr); - - return 0; -} - /* * Purge recieve queue of all handled commands (->handled==1). Also * allows for selective freeing using ->nofree so that the client can
--- a/libfaim/faim/aim.h Tue Jul 18 05:23:25 2000 +0000 +++ b/libfaim/faim/aim.h Tue Jul 18 05:37:39 2000 +0000 @@ -25,6 +25,18 @@ #include <stdarg.h> #include <errno.h> +#ifdef _WIN32 +#include <windows.h> +#include <time.h> +#include <io.h> +#else +#include <netdb.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <sys/time.h> +#include <unistd.h> +#endif + #ifdef FAIM_USEPTHREADS #include <pthread.h> #define faim_mutex_t pthread_mutex_t @@ -45,18 +57,6 @@ #define faim_mutex_unlock(x) *x = 0; #endif -#ifdef _WIN32 -#include <windows.h> -#include <time.h> -#include <io.h> -#else -#include <netdb.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <sys/time.h> -#include <unistd.h> -#endif - /* Portability stuff (DMP) */ #ifdef _WIN32 @@ -167,7 +167,19 @@ #define AIM_CONN_TYPE_BOS 0x0002 #define AIM_CONN_TYPE_CHAT 0x000e #define AIM_CONN_TYPE_CHATNAV 0x000d + +/* they start getting arbitrary in rendezvous stuff =) */ #define AIM_CONN_TYPE_RENDEZVOUS 0x0101 /* these do not speak OSCAR! */ +#define AIM_CONN_TYPE_RENDEZVOUS_OUT 0x0102 /* socket waiting for accept() */ + +/* + * Subtypes, we need these for OFT stuff. + */ +#define AIM_CONN_SUBTYPE_OFT_DIRECTIM 0x0001 +#define AIM_CONN_SUBTYPE_OFT_GETFILE 0x0002 +#define AIM_CONN_SUBTYPE_OFT_SENDFILE 0x0003 +#define AIM_CONN_SUBTYPE_OFT_BUDDYICON 0x0004 +#define AIM_CONN_SUBTYPE_OFT_VOICE 0x0005 /* * Status values returned from aim_conn_new(). ORed together. @@ -182,7 +194,8 @@ struct aim_conn_t { int fd; - int type; + unsigned short type; + unsigned short subtype; int seqnum; int status; void *priv; /* misc data the client may want to store */ @@ -199,11 +212,12 @@ unsigned char hdrtype; /* defines which piece of the union to use */ union { struct { - char type; + char type; unsigned short seqnum; } oscar; struct { unsigned short type; + unsigned char magic[4]; /* ODC2 OFT2 */ unsigned short hdr2len; unsigned char *hdr2; /* rest of bloated header */ } oft; @@ -227,6 +241,7 @@ } oscar; struct { unsigned short type; + unsigned char magic[4]; /* ODC2 OFT2 */ unsigned short hdr2len; unsigned char *hdr2; } oft; @@ -362,8 +377,9 @@ */ int aim_get_command(struct aim_session_t *, struct aim_conn_t *); int aim_rxdispatch(struct aim_session_t *); -u_long aim_debugconn_sendconnect(struct aim_session_t *sess, - struct aim_conn_t *conn); + +u_long aim_debugconn_sendconnect(struct aim_session_t *sess, struct aim_conn_t *conn); + int aim_logoff(struct aim_session_t *); void aim_conn_kill(struct aim_session_t *sess, struct aim_conn_t **deadconn); @@ -375,6 +391,8 @@ u_long aim_genericreq_l(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_long *); u_long aim_genericreq_s(struct aim_session_t *, struct aim_conn_t *conn, u_short family, u_short subtype, u_short *); +struct aim_fileheader_t *aim_oft_getfh(char *hdr); + /* aim_login.c */ int aim_sendconnack(struct aim_session_t *sess, struct aim_conn_t *conn); int aim_request_login (struct aim_session_t *sess, struct aim_conn_t *conn, char *sn); @@ -399,7 +417,7 @@ int aim_parse_unknown(struct aim_session_t *, struct command_rx_struct *command, ...); int aim_parse_missed_im(struct aim_session_t *, struct command_rx_struct *, ...); int aim_parse_last_bad(struct aim_session_t *, struct command_rx_struct *, ...); - +int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *conn); struct command_tx_struct *aim_tx_new(unsigned short framing, int chan, struct aim_conn_t *conn, int datalen); int aim_tx_enqueue__queuebased(struct aim_session_t *, struct command_tx_struct *); @@ -479,6 +497,9 @@ u_long aim_bos_reqicbmparaminfo(struct aim_session_t *, struct aim_conn_t *); u_long aim_setversions(struct aim_session_t *sess, struct aim_conn_t *conn); +struct aim_fileheader_t *aim_getlisting(struct aim_session_t*); +int aim_listenestablish(u_short); + /* aim_rxhandlers.c */ int aim_rxdispatch(struct aim_session_t *); int aim_authparse(struct aim_session_t *, struct command_rx_struct *); @@ -489,6 +510,12 @@ int aim_parsemotd_middle(struct aim_session_t *sess, struct command_rx_struct *command, ...); /* aim_im.c */ +struct aim_directim_priv { + unsigned char cookie[8]; + char sn[MAXSNLEN+1]; + char ip[30]; +}; + #define AIM_IMFLAGS_AWAY 0x01 /* mark as an autoreply */ #define AIM_IMFLAGS_ACK 0x02 /* request a receipt notice */ @@ -499,6 +526,10 @@ int aim_parse_msgerror_middle(struct aim_session_t *, struct command_rx_struct *); int aim_negchan_middle(struct aim_session_t *sess, struct command_rx_struct *command); +struct aim_conn_t * aim_directim_intiate(struct aim_session_t *, struct aim_conn_t *, struct aim_directim_priv *, char *); +int aim_send_im_direct(struct aim_session_t *, struct aim_conn_t *, char *); +struct aim_conn_t *aim_directim_connect(struct aim_session_t *, struct aim_conn_t *, struct aim_directim_priv *); + /* aim_info.c */ #define AIM_CAPS_BUDDYICON 0x01 #define AIM_CAPS_VOICE 0x02 @@ -522,20 +553,79 @@ struct aim_msgcookie_t *next; }; -struct aim_filetransfer_t { - char sender[MAXSNLEN]; +struct aim_fileheader_t { +#if 0 + char magic[4]; /* 0 */ + short hdrlen; /* 4 */ + short hdrtype; /* 6 */ +#endif + char bcookie[8]; /* 8 */ + short encrypt; /* 16 */ + short compress; /* 18 */ + short totfiles; /* 20 */ + short filesleft; /* 22 */ + short totparts; /* 24 */ + short partsleft; /* 26 */ + long totsize; /* 28 */ + long size; /* 32 */ + long modtime; /* 36 */ + long checksum; /* 40 */ + long rfrcsum; /* 44 */ + long rfsize; /* 48 */ + long cretime; /* 52 */ + long rfcsum; /* 56 */ + long nrecvd; /* 60 */ + long recvcsum; /* 64 */ + char idstring[32]; /* 68 */ + char flags; /* 100 */ + char lnameoffset; /* 101 */ + char lsizeoffset; /* 102 */ + char dummy[69]; /* 103 */ + char macfileinfo[16]; /* 172 */ + short nencode; /* 188 */ + short nlanguage; /* 190 */ + char name[64]; /* 192 */ + /* 256 */ +}; + +struct aim_filetransfer_priv { + char sn[MAXSNLEN]; + char cookie[8]; char ip[30]; - char *filename; + int state; + struct aim_fileheader_t fh; }; + +#define AIM_COOKIETYPE_UNKNOWN 0x00 +#define AIM_COOKIETYPE_ICBM 0x01 +#define AIM_COOKIETYPE_ADS 0x02 +#define AIM_COOKIETYPE_BOS 0x03 +#define AIM_COOKIETYPE_IM 0x04 +#define AIM_COOKIETYPE_CHAT 0x05 +#define AIM_COOKIETYPE_CHATNAV 0x06 +/* we'll move OFT up a bit to give breathing room. not like it really + * matters. */ +#define AIM_COOKIETYPE_OFTIM 0x10 +#define AIM_COOKIETYPE_OFTGET 0x11 +#define AIM_COOKIETYPE_OFTSEND 0x12 +#define AIM_COOKIETYPE_OFTVOICE 0x13 +#define AIM_COOKIETYPE_OFTIMAGE 0x14 +#define AIM_COOKIETYPE_OFTICON 0x15 + int aim_cachecookie(struct aim_session_t *sess, struct aim_msgcookie_t *cookie); -struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess, char *cookie); -int aim_purgecookies(struct aim_session_t *sess); +int aim_purgecookies(struct aim_session_t *sess, int maxage); +struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess, char *cookie, int type); +struct aim_msgcookie_t *aim_mkcookie(unsigned char *, int, void *); +struct aim_msgcookie_t *aim_checkcookie(struct aim_session_t *, char *, int); +int aim_getcookietype(int); + +int aim_handlerendconnect(struct aim_session_t *sess, struct aim_conn_t *cur); #define AIM_TRANSFER_DENY_NOTSUPPORTED 0x0000 #define AIM_TRANSFER_DENY_DECLINE 0x0001 #define AIM_TRANSFER_DENY_NOTACCEPTING 0x0002 u_long aim_denytransfer(struct aim_session_t *sess, struct aim_conn_t *conn, char *sender, char *cookie, unsigned short code); -u_long aim_accepttransfer(struct aim_session_t *sess, struct aim_conn_t *conn, char *sender, char *cookie, unsigned short rendid); +u_long aim_accepttransfer(struct aim_session_t *sess, struct aim_conn_t *conn,struct aim_conn_t *oftconn, char *sender, char *cookie, unsigned short rendid); u_long aim_getinfo(struct aim_session_t *, struct aim_conn_t *, const char *, unsigned short); int aim_extractuserinfo(u_char *, struct aim_userinfo_s *);
--- a/libfaim/faim/aim_cbtypes.h Tue Jul 18 05:23:25 2000 +0000 +++ b/libfaim/faim/aim_cbtypes.h Tue Jul 18 05:37:39 2000 +0000 @@ -24,6 +24,7 @@ #define AIM_CB_FAM_CTN 0x000d /* ChatNav */ #define AIM_CB_FAM_CHT 0x000e /* Chat */ #define AIM_CB_FAM_ATH 0x0017 +#define AIM_CB_FAM_OFT 0xfffe /* OFT/Rvous */ #define AIM_CB_FAM_SPECIAL 0xffff /* Internal libfaim use */ /* @@ -181,6 +182,21 @@ #define AIM_CB_ATH_AUTHRESPONSE 0x0007 /* + * OFT Services + * + * See non-SNAC note below. + */ +#define AIM_CB_OFT_DIRECTIMCONNECTREQ 0x0001 +#define AIM_CB_OFT_DIRECTIMINCOMING 0x0002 +#define AIM_CB_OFT_DIRECTIMDISCONNECT 0x0003 +#define AIM_CB_OFT_DIRECTIMTYPING 0x0006 +#define AIM_CB_OFT_DIRECTIMINITIATE 0x0007 + +#define AIM_CB_OFT_GETFILECONNECT 0x0004 +#define AIM_CB_OFT_GETFILECOMPLETE 0x0005 +#define AIM_CB_OFT_GETFILEINITIATE 0x0007 + +/* * SNAC Family: Internal Messages * * This isn't truely a SNAC family either, but using
--- a/src/oscar.c Tue Jul 18 05:23:25 2000 +0000 +++ b/src/oscar.c Tue Jul 18 05:37:39 2000 +0000 @@ -82,6 +82,8 @@ static int gaim_chat_leave (struct aim_session_t *, struct command_rx_struct *, ...); static int gaim_chat_info_update (struct aim_session_t *, struct command_rx_struct *, ...); static int gaim_chat_incoming_msg(struct aim_session_t *, struct command_rx_struct *, ...); +static int gaim_parse_msgack (struct aim_session_t *, struct command_rx_struct *, ...); +static int gaim_parse_ratechange (struct aim_session_t *, struct command_rx_struct *, ...); extern void auth_failed(); @@ -98,15 +100,25 @@ return; } if (condition & GDK_INPUT_READ) { - if (aim_get_command(gaim_sess, conn) < 0) { - debug_print(_("connection error!\n")); - signoff(); - hide_login_progress(_("Disconnected.")); - aim_logoff(gaim_sess); - auth_failed(); - gdk_input_remove(inpa); + if (conn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) { + if (aim_handlerendconnect(gaim_sess, conn) < 0) { + debug_print(_("connection error (rend)\n")); + } } else { - aim_rxdispatch(gaim_sess); + if (aim_get_command(gaim_sess, conn) >= 0) { + aim_rxdispatch(gaim_sess); + } else { + debug_print(_("connection error!\n")); + aim_conn_kill(gaim_sess, &conn); + if (!aim_getconn_type(gaim_sess, AIM_CONN_TYPE_BOS)) { + debug_print(_("major connection error\n")); + signoff(); + hide_login_progress(_("Disconnected.")); + aim_logoff(gaim_sess); + auth_failed(); + gdk_input_remove(inpa); + } + } } } } @@ -277,9 +289,10 @@ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_INCOMING, gaim_parse_incoming_im, 0); aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_ERROR, gaim_parse_misses, 0); aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_MISSEDCALL, gaim_parse_misses, 0); - aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATECHANGE, gaim_parse_misses, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATECHANGE, gaim_parse_ratechange, 0); aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ERROR, gaim_parse_misses, 0); aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO, gaim_parse_user_info, 0); + aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ACK, gaim_parse_msgack, 0); aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_CTN, AIM_CB_CTN_DEFAULT, aim_parse_unknown, 0); aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0); aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, gaim_parse_motd, 0); @@ -775,7 +788,6 @@ int gaim_chat_info_update(struct aim_session_t *sess, struct command_rx_struct *command, ...) { - /* FIXME */ debug_print("inside chat_info_update\n"); return 1; } @@ -807,3 +819,36 @@ return 1; } + + /* + * Recieved in response to an IM sent with the AIM_IMFLAGS_ACK option. + */ +int gaim_parse_msgack(struct aim_session_t *sess, struct command_rx_struct *command, ...) { + va_list ap; + unsigned short type; + char *sn = NULL; + + ap = va_start(ap, command); + type = va_arg(ap, unsigned short); + sn = va_arg(ap, char *); + va_end(ap); + + sprintf(debug_buff, "Sent message to %s.\n", sn); + debug_print(debug_buff); + + return 1; +} + +int gaim_parse_ratechange(struct aim_session_t *sess, struct command_rx_struct *command, ...) { + va_list ap; + unsigned long newrate; + + va_start(ap, command); + newrate = va_arg(ap, unsigned long); + va_end(ap); + + sprintf(debug_buff, "ratechange: %lu\n", newrate); + debug_print(debug_buff); + + return 1; +};
--- a/src/server.c Tue Jul 18 05:23:25 2000 +0000 +++ b/src/server.c Tue Jul 18 05:37:39 2000 +0000 @@ -167,7 +167,7 @@ if (away) aim_send_im(gaim_sess, gaim_conn, name, AIM_IMFLAGS_AWAY, message); else - aim_send_im(gaim_sess, gaim_conn, name, 0, message); + aim_send_im(gaim_sess, gaim_conn, name, AIM_IMFLAGS_ACK, message); } if (!away) serv_touch_idle();