2 * -----------------------------------------------------------
3 * ProtoFAIM: v1.xx.xxplxx
4 * -----------------------------------------------------------
6 * This is ProtoFAIM v1.xx.xxplxx!!! Its nearly completely
7 * different than that ugly thing called v0. This app is
8 * compatible with the latest version of the libfaim library.
11 * ProtoFAIM should only be used for two things...
12 * 1) Testing the libfaim backend.
13 * 2) For reference on the libfaim API when developing clients.
15 * Its very ugly. Probably always will be. Nothing is more
16 * ugly than the backend itself, however.
18 * -----------------------------------------------------------
20 * I'm releasing this code and all it's associated linkage
21 * under the GNU General Public License. For more information,
22 * please refer to http://www.fsf.org. For any questions,
23 * please contact me at the address below.
26 * (c) 1998 Adam Fritzler, PST, mid@zigamoprh.net
28 * The password algorithms
29 * (c) 1998 Brock Wilcox, awwaiid@zigamorph.net
31 * THERE IS NO CODE FROM AOL'S AIM IN THIS CODE, NOR
32 * WAS THERE ANY DISASSEMBLAGE TO DEFINE PROTOCOL. All
33 * information was gained through painstakingly comparing
34 * TCP dumps while the AIM Java client was running. Nothing
35 * more than that, except for a lot of experimenting.
37 * -----------------------------------------------------------
44 static char *dprintf_ctime(void)
46 static char retbuf[64];
51 gettimeofday(&tv, &tz);
52 lt = localtime((time_t *)&tv.tv_sec);
53 strftime(retbuf, 64, "%a %b %e %H:%M:%S %Z %Y", lt);
57 #define DPRINTF_OUTSTREAM stdout
58 #define dprintf(x) { \
59 fprintf(DPRINTF_OUTSTREAM, "%s %s: " x, dprintf_ctime(), "faimtest"); \
60 fflush(DPRINTF_OUTSTREAM); \
62 #define dvprintf(x, y...) { \
63 fprintf(DPRINTF_OUTSTREAM, "%s %s: " x, dprintf_ctime(), "faimtest", y); \
64 fflush(DPRINTF_OUTSTREAM); \
66 #define dinlineprintf(x) { \
67 fprintf(DPRINTF_OUTSTREAM, x); \
68 fflush(DPRINTF_OUTSTREAM); \
70 #define dvinlineprintf(x, y...) { \
71 fprintf(DPRINTF_OUTSTREAM, x, y); \
72 fflush(DPRINTF_OUTSTREAM); \
74 #define dperror(x) dvprintf("%s: %s\n", x, strerror(errno));
76 int faimtest_parse_oncoming(struct aim_session_t *, struct command_rx_struct *, ...);
77 int faimtest_parse_offgoing(struct aim_session_t *, struct command_rx_struct *, ...);
78 int faimtest_parse_login_phase3d_f(struct aim_session_t *, struct command_rx_struct *, ...);
79 static int faimtest_parse_authresp(struct aim_session_t *, struct command_rx_struct *, ...);
80 int faimtest_parse_incoming_im(struct aim_session_t *, struct command_rx_struct *command, ...);
81 int faimtest_parse_userinfo(struct aim_session_t *, struct command_rx_struct *command, ...);
82 int faimtest_handleredirect(struct aim_session_t *, struct command_rx_struct *command, ...);
83 int faimtest_infochange(struct aim_session_t *sess, struct command_rx_struct *command, ...);
84 int faimtest_serverready(struct aim_session_t *, struct command_rx_struct *command, ...);
85 int faimtest_hostversions(struct aim_session_t *sess, struct command_rx_struct *command, ...);
86 int faimtest_parse_misses(struct aim_session_t *, struct command_rx_struct *command, ...);
87 int faimtest_parse_msgack(struct aim_session_t *, struct command_rx_struct *command, ...);
88 int faimtest_parse_motd(struct aim_session_t *, struct command_rx_struct *command, ...);
89 int faimtest_parse_login(struct aim_session_t *, struct command_rx_struct *command, ...);
90 int faimtest_chatnav_info(struct aim_session_t *, struct command_rx_struct *command, ...);
91 int faimtest_chat_incomingmsg(struct aim_session_t *sess, struct command_rx_struct *command, ...);
92 int faimtest_chat_infoupdate(struct aim_session_t *sess, struct command_rx_struct *command, ...);
93 int faimtest_chat_leave(struct aim_session_t *sess, struct command_rx_struct *command, ...);
94 int faimtest_chat_join(struct aim_session_t *sess, struct command_rx_struct *command, ...);
95 int faimtest_parse_connerr(struct aim_session_t *sess, struct command_rx_struct *command, ...);
96 int faimtest_debugconn_connect(struct aim_session_t *sess, struct command_rx_struct *command, ...);
98 int faimtest_directim_request(struct aim_session_t *sess, struct command_rx_struct *command, ...);
99 int faimtest_directim_initiate(struct aim_session_t *sess, struct command_rx_struct *command, ...);
100 int faimtest_directim_connect(struct aim_session_t *sess, struct command_rx_struct *command, ...);
101 int faimtest_directim_incoming(struct aim_session_t *sess, struct command_rx_struct *command, ...);
102 int faimtest_directim_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...);
103 int faimtest_directim_typing(struct aim_session_t *sess, struct command_rx_struct *command, ...);
105 int faimtest_getfile_filereq(struct aim_session_t *sess, struct command_rx_struct *command, ...);
106 int faimtest_getfile_filesend(struct aim_session_t *sess, struct command_rx_struct *command, ...);
107 int faimtest_getfile_complete(struct aim_session_t *sess, struct command_rx_struct *command, ...);
108 int faimtest_getfile_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...);
109 int faimtest_getfile_initiate(struct aim_session_t *sess, struct command_rx_struct *command, ...);
110 int faimtest_getfile_listing(struct aim_session_t *sess, struct command_rx_struct *command, ...);
111 int faimtest_getfile_listingreq(struct aim_session_t *sess, struct command_rx_struct *command, ...);
112 int faimtest_getfile_receive(struct aim_session_t *sess, struct command_rx_struct *command, ...);
113 int faimtest_getfile_state4(struct aim_session_t *sess, struct command_rx_struct *command, ...);
115 int faimtest_parse_ratechange(struct aim_session_t *sess, struct command_rx_struct *command, ...);
116 int faimtest_parse_evilnotify(struct aim_session_t *sess, struct command_rx_struct *command, ...);
117 int faimtest_parse_searcherror(struct aim_session_t *sess, struct command_rx_struct *command, ...);
118 int faimtest_parse_searchreply(struct aim_session_t *sess, struct command_rx_struct *command, ...);
119 int faimtest_parse_msgerr(struct aim_session_t *sess, struct command_rx_struct *command, ...);
120 int faimtest_parse_buddyrights(struct aim_session_t *sess, struct command_rx_struct *command, ...);
121 int faimtest_parse_locerr(struct aim_session_t *sess, struct command_rx_struct *command, ...);
122 int faimtest_parse_genericerr(struct aim_session_t *sess, struct command_rx_struct *command, ...);
124 static char *msgerrreasons[] = {
130 "Service unavailable",
131 "Service not defined",
133 "Not supported by host",
134 "Not supported by client",
139 "Busted SNAC payload",
140 "Insufficient rights",
141 "In local permit/deny",
143 "Too evil (receiver)",
144 "User temporarily unavailable",
150 static int msgerrreasonslen = 25;
152 static char *aimbinarypath = NULL;
153 static char *screenname,*password,*server=NULL;
154 static char *proxy = NULL, *proxyusername = NULL, *proxypass = NULL;
155 static char *ohcaptainmycaptain = NULL;
156 static int connected = 0;
158 struct aim_session_t aimsess;
161 static FILE *listingfile;
162 static char *listingpath;
164 static unsigned char *buddyicon = NULL;
165 static int buddyiconlen = 0;
166 static time_t buddyiconstamp = 0;
167 static unsigned short buddyiconsum = 0;
169 static void faimtest_debugcb(struct aim_session_t *sess, int level, const char *format, va_list va)
172 vfprintf(stderr, format, va);
177 int faimtest_reportinterval(struct aim_session_t *sess, struct command_rx_struct *command, ...)
180 unsigned short interval = 0;
182 va_start(ap, command);
183 interval = va_arg(ap, int);
186 dvprintf("aim: minimum report interval: %d (seconds?)\n", interval);
191 int faimtest_flapversion(struct aim_session_t *sess, struct command_rx_struct *command, ...)
194 dvprintf("faimtest: using FLAP version %u\n", aimutil_get32(command->data));
198 * This is an alternate location for starting the login process.
200 /* XXX should do more checking to make sure its really the right AUTH conn */
201 if (command->conn->type == AIM_CONN_TYPE_AUTH) {
202 /* do NOT send a connack/flapversion, request_login will send it if needed */
203 aim_request_login(sess, command->conn, screenname);
204 dprintf("faimtest: login request sent\n");
212 * This is a frivilous callback. You don't need it. I only used it for
213 * debugging non-blocking connects.
215 * If packets are sent to a conn before its fully connected, they
216 * will be queued and then transmitted when the connection completes.
219 int faimtest_conncomplete(struct aim_session_t *sess, struct command_rx_struct *command, ...)
222 struct aim_conn_t *conn;
224 va_start(ap, command);
225 conn = va_arg(ap, struct aim_conn_t *);
229 dvprintf("faimtest: connection on %d completed\n", conn->fd);
236 * This is really all thats needed to link against libfaim on win32.
238 * Note that this particular version of faimtest has never been tested
239 * on win32, but I'm fairly sure it should.
243 WORD wVersionRequested;
246 wVersionRequested = MAKEWORD(2,2);
247 return WSAStartup(wVersionRequested, &wsaData);
251 int faimtest_init(void)
253 struct aim_conn_t *stdinconn = NULL;
255 if (!(stdinconn = aim_newconn(&aimsess, 0, NULL))) {
256 dprintf("unable to create connection for stdin!\n");
260 stdinconn->fd = STDIN_FILENO;
268 if (ohcaptainmycaptain)
269 aim_send_im(&aimsess, aim_getconn_type(&aimsess, AIM_CONN_TYPE_BOS), ohcaptainmycaptain, 0, "ta ta...");
271 aim_session_kill(&aimsess);
273 if (faimtest_init() == -1)
274 dprintf("faimtest_init failed\n");
279 int login(const char *sn, const char *passwd)
281 struct aim_conn_t *authconn;
284 screenname = strdup(sn);
286 password = strdup(passwd);
289 aim_setupproxy(&aimsess, proxy, proxyusername, proxypass);
291 if (!screenname || !password) {
292 dprintf("need SN and password\n");
296 if (!(authconn = aim_newconn(&aimsess, AIM_CONN_TYPE_AUTH, server?server:FAIM_LOGIN_SERVER))) {
297 dprintf("faimtest: internal connection error while in aim_login. bailing out.\n");
299 } else if (authconn->fd == -1) {
300 if (authconn->status & AIM_CONN_STATUS_RESOLVERR) {
301 dprintf("faimtest: could not resolve authorizer name\n");
302 } else if (authconn->status & AIM_CONN_STATUS_CONNERR) {
303 dprintf("faimtest: could not connect to authorizer\n");
305 aim_conn_kill(&aimsess, &authconn);
309 aim_conn_addhandler(&aimsess, authconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_FLAPVER, faimtest_flapversion, 0);
310 aim_conn_addhandler(&aimsess, authconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE, faimtest_conncomplete, 0);
311 aim_conn_addhandler(&aimsess, authconn, 0x0017, 0x0007, faimtest_parse_login, 0);
312 aim_conn_addhandler(&aimsess, authconn, 0x0017, 0x0003, faimtest_parse_authresp, 0);
314 aim_conn_addhandler(&aimsess, authconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEBUGCONN_CONNECT, faimtest_debugconn_connect, 0);
316 /* If the connection is in progress, this will just be queued */
317 aim_request_login(&aimsess, authconn, screenname);
318 dprintf("faimtest: login request sent\n");
323 int main(int argc, char **argv)
325 struct aim_conn_t *waitingconn = NULL;
328 static int faimtest_mode = 0;
331 const char *buddyiconpath = NULL;
333 screenname = getenv("SCREENNAME");
334 password = getenv("PASSWORD");
335 server = getenv("AUTHSERVER");
336 proxy = getenv("SOCKSPROXY");
337 proxyusername = getenv("SOCKSNAME");
338 proxypass = getenv("SOCKSPASS");
340 listingpath = getenv("LISTINGPATH");
342 while ((i = getopt(argc, argv, "u:p:a:U:P:A:l:c:hoOb:i:")) != EOF) {
344 case 'u': screenname = optarg; break;
345 case 'p': password = optarg; break;
346 case 'a': server = optarg; break;
347 case 'U': proxyusername = optarg; break;
348 case 'P': proxypass = optarg; break;
349 case 'A': proxy = optarg; break;
350 case 'l': listingpath = optarg; break;
351 case 'c': ohcaptainmycaptain = optarg; break;
352 case 'o': faimtest_mode = 1; break; /* half old interface */
353 case 'O': faimtest_mode = 2; break; /* full old interface */
354 case 'b': aimbinarypath = optarg; break;
355 case 'i': buddyiconpath = optarg; break;
358 printf("faimtest\n");
359 printf(" Options: \n");
360 printf(" -u name Screen name ($SCREENNAME)\n");
361 printf(" -p passwd Password ($PASSWORD)\n");
362 printf(" -a host:port Authorizer ($AUTHSERVER)\n");
363 printf(" -U name Proxy user name ($SOCKSPROXY)\n");
364 printf(" -P passwd Proxy password ($SOCKSNAME)\n");
365 printf(" -A host:port Proxy host ($SOCKSPASS)\n");
366 printf(" -l path Path to listing file ($LISTINGPATH)\n");
367 printf(" -c name Screen name of owner\n");
368 printf(" -o Login at startup, then prompt\n");
369 printf(" -O Login, never give prompt\n");
370 printf(" -b path Path to AIM 3.5.1670 binaries\n");
371 printf(" -i file Buddy Icon to send\n");
377 if (initwsa() != 0) {
378 dprintf("faimtest: could not initialize windows sockets\n");
383 /* Pass zero as flags if you want blocking connects */
384 aim_session_init(&aimsess, AIM_SESS_FLAGS_NONBLOCKCONNECT, 1);
385 aim_setdebuggingcb(&aimsess, faimtest_debugcb); /* still needed even if debuglevel = 0 ! */
389 if(!(listingname = (char *)calloc(1, strlen(listingpath)+strlen("/listing.txt")))) {
390 dperror("listingname calloc");
393 sprintf(listingname, "%s/listing.txt", listingpath);
394 if( (listingfile = fopen(listingname, "r")) == NULL) {
395 dvprintf("Couldn't open %s... disabling that shit.\n", listingname);
405 if ((stat(buddyiconpath, &st) != -1) && (st.st_size <= MAXICONLEN) && (f = fopen(buddyiconpath, "r"))) {
407 buddyiconlen = st.st_size;
408 buddyiconstamp = st.st_mtime;
409 buddyicon = malloc(buddyiconlen);
410 fread(buddyicon, 1, st.st_size, f);
412 buddyiconsum = aim_iconsum(buddyicon, buddyiconlen);
414 dvprintf("read %d bytes of %s for buddy icon (sum 0x%08x)\n", buddyiconlen, buddyiconpath, buddyiconsum);
419 dvprintf("could not open buddy icon %s\n", buddyiconpath);
425 if (faimtest_mode < 2)
428 if (faimtest_mode >= 1) {
429 if (login(screenname, password) == -1) {
430 if (faimtest_mode < 2)
441 waitingconn = aim_select(&aimsess, &tv, &selstat);
443 if (connected && ((time(NULL) - lastnop) > 30)) {
444 lastnop = time(NULL);
445 aim_flap_nop(&aimsess, aim_getconn_type(&aimsess, AIM_CONN_TYPE_BOS));
448 if (selstat == -1) { /* error */
449 keepgoing = 0; /* fall through */
450 } else if (selstat == 0) { /* no events pending */
452 } else if (selstat == 1) { /* outgoing data pending */
453 aim_tx_flushqueue(&aimsess);
454 } else if (selstat == 2) { /* incoming data pending */
455 if ((faimtest_mode < 2) && (waitingconn->fd == STDIN_FILENO)) {
458 if (waitingconn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) {
459 if (aim_handlerendconnect(&aimsess, waitingconn) < 0) {
460 dprintf("connection error (rend out)\n");
461 aim_conn_kill(&aimsess, &waitingconn);
464 if (aim_get_command(&aimsess, waitingconn) >= 0) {
465 aim_rxdispatch(&aimsess);
467 dvprintf("connection error (type 0x%04x:0x%04x)\n", waitingconn->type, waitingconn->subtype);
468 /* we should have callbacks for all these, else the library will do the conn_kill for us. */
469 if(waitingconn->type == AIM_CONN_TYPE_RENDEZVOUS) {
470 dprintf("connection error: rendezvous connection. you forgot register a disconnect callback, right?\n");
471 aim_conn_kill(&aimsess, &waitingconn);
473 aim_conn_kill(&aimsess, &waitingconn);
474 if (!aim_getconn_type(&aimsess, AIM_CONN_TYPE_BOS)) {
475 dprintf("major connection error\n");
476 if (faimtest_mode == 2)
485 /* close up all connections, dead or no */
486 aim_session_kill(&aimsess);
488 if (faimtest_mode < 2) {
499 int faimtest_rateresp(struct aim_session_t *sess, struct command_rx_struct *command, ...)
502 switch(command->conn->type) {
503 case AIM_CONN_TYPE_BOS: {
504 /* this is the new buddy list */
506 /* this is the new profile */
508 char awaymsg[] = {"blah blah blah Ole! blah blah blah"};
510 /* Caution: Buddy1 and Buddy2 are real people! (who I don't know) */
511 snprintf(buddies, sizeof(buddies), "Buddy1&Buddy2&%s&", ohcaptainmycaptain?ohcaptainmycaptain:"blah");
512 snprintf(profile, sizeof(profile), "Hello.<br>My captain is %s. They were dumb enough to leave this message in their client, or they are using faimtest. Shame on them.", ohcaptainmycaptain);
514 aim_bos_ackrateresp(sess, command->conn); /* ack rate info response */
515 aim_bos_reqpersonalinfo(sess, command->conn);
516 aim_bos_reqlocaterights(sess, command->conn);
517 aim_bos_setprofile(sess, command->conn, profile, awaymsg, AIM_CAPS_BUDDYICON | AIM_CAPS_CHAT | AIM_CAPS_GETFILE | AIM_CAPS_SENDFILE | AIM_CAPS_IMIMAGE /*| AIM_CAPS_GAMES | AIM_CAPS_SAVESTOCKS*/);
518 aim_bos_reqbuddyrights(sess, command->conn);
520 /* send the buddy list and profile (required, even if empty) */
521 aim_bos_setbuddylist(sess, command->conn, buddies);
523 /* dont really know what this does */
524 aim_addicbmparam(sess, command->conn);
525 aim_bos_reqicbmparaminfo(sess, command->conn);
527 aim_bos_reqrights(sess, command->conn);
528 /* set group permissions -- all user classes */
529 aim_bos_setgroupperm(sess, command->conn, AIM_FLAG_ALLUSERS);
530 aim_bos_setprivacyflags(sess, command->conn, AIM_PRIVFLAGS_ALLOWIDLE);
534 case AIM_CONN_TYPE_AUTH:
535 aim_bos_ackrateresp(sess, command->conn);
536 aim_auth_clientready(sess, command->conn);
537 dprintf("faimtest: connected to authorization/admin service\n");
541 dvprintf("faimtest: got rate response for unhandled connection type %04x\n", command->conn->type);
548 static int faimtest_icbmparaminfo(struct aim_session_t *sess, struct command_rx_struct *command, ...)
550 unsigned long defflags, minmsginterval;
551 unsigned short maxicbmlen, maxsenderwarn, maxrecverwarn, maxchannel;
554 va_start(ap, command);
555 maxchannel = va_arg(ap, unsigned short);
556 defflags = va_arg(ap, unsigned long);
557 maxicbmlen = va_arg(ap, unsigned short);
558 maxsenderwarn = va_arg(ap, unsigned short);
559 maxrecverwarn = va_arg(ap, unsigned short);
560 minmsginterval = va_arg(ap, unsigned long);
563 dvprintf("ICBM Parameters: maxchannel = %d, default flags = 0x%08lx, max msg len = %d, max sender evil = %f, max reciever evil = %f, min msg interval = %ld\n", maxchannel, defflags, maxicbmlen, ((float)maxsenderwarn)/10.0, ((float)maxrecverwarn)/10.0, minmsginterval);
568 int faimtest_hostversions(struct aim_session_t *sess, struct command_rx_struct *command, ...)
571 unsigned char *versions;
574 va_start(ap, command);
575 vercount = va_arg(ap, int); /* number of family/version pairs */
576 versions = va_arg(ap, unsigned char *);
579 dprintf("faimtest: SNAC versions supported by this host: ");
580 for (i = 0; i < vercount*4; i += 4)
581 dvinlineprintf("0x%04x:0x%04x ",
582 aimutil_get16(versions+i), /* SNAC family */
583 aimutil_get16(versions+i+2) /* Version number */);
589 int faimtest_accountconfirm(struct aim_session_t *sess, struct command_rx_struct *command, ...)
594 va_start(ap, command);
595 status = va_arg(ap, int); /* status code of confirmation request */
598 dvprintf("account confirmation returned status 0x%04x (%s)\n", status, (status==0x0000)?"email sent":"unknown");
603 int faimtest_serverready(struct aim_session_t *sess, struct command_rx_struct *command, ...)
606 unsigned short *families;
609 va_start(ap, command);
610 famcount = va_arg(ap, int);
611 families = va_arg(ap, unsigned short *);
614 dvprintf("faimtest: SNAC families supported by this host (type %d): ", command->conn->type);
615 for (i = 0; i < famcount; i++)
616 dvinlineprintf("0x%04x ", families[i]);
619 switch (command->conn->type) {
620 case AIM_CONN_TYPE_AUTH:
621 aim_auth_setversions(sess, command->conn);
622 aim_bos_reqrate(sess, command->conn); /* request rate info */
624 dprintf("faimtest: done with auth ServerReady\n");
627 case AIM_CONN_TYPE_BOS:
629 aim_setversions(sess, command->conn);
630 aim_bos_reqrate(sess, command->conn); /* request rate info */
632 dprintf("faimtest: done with BOS ServerReady\n");
635 case AIM_CONN_TYPE_CHATNAV:
636 dprintf("faimtest: chatnav: got server ready\n");
637 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CTN, AIM_CB_CTN_INFO, faimtest_chatnav_info, 0);
638 aim_bos_reqrate(sess, command->conn);
639 aim_bos_ackrateresp(sess, command->conn);
640 aim_chatnav_clientready(sess, command->conn);
641 aim_chatnav_reqrights(sess, command->conn);
645 case AIM_CONN_TYPE_CHAT:
646 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERJOIN, faimtest_chat_join, 0);
647 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERLEAVE, faimtest_chat_leave, 0);
648 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_ROOMINFOUPDATE, faimtest_chat_infoupdate, 0);
649 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_INCOMINGMSG, faimtest_chat_incomingmsg, 0);
650 aim_bos_reqrate(sess, command->conn);
651 aim_bos_ackrateresp(sess, command->conn);
652 aim_chat_clientready(sess, command->conn);
655 case AIM_CONN_TYPE_RENDEZVOUS: /* empty */
659 dvprintf("faimtest: unknown connection type on Host Online (0x%04x)\n", command->conn->type);
665 int faimtest_parse_buddyrights(struct aim_session_t *sess, struct command_rx_struct *command, ...)
668 unsigned short maxbuddies, maxwatchers;
670 va_start(ap, command);
671 maxbuddies = va_arg(ap, int);
672 maxwatchers = va_arg(ap, int);
675 dvprintf("faimtest: buddy list rights: Max buddies = %d / Max watchers = %d\n", maxbuddies, maxwatchers);
680 int faimtest_bosrights(struct aim_session_t *sess, struct command_rx_struct *command, ...)
682 unsigned short maxpermits, maxdenies;
685 va_start(ap, command);
686 maxpermits = va_arg(ap, int);
687 maxdenies = va_arg(ap, int);
690 dvprintf("faimtest: BOS rights: Max permit = %d / Max deny = %d\n", maxpermits, maxdenies);
692 aim_bos_clientready(sess, command->conn);
694 dprintf("faimtest: officially connected to BOS.\n");
699 int faimtest_locrights(struct aim_session_t *sess, struct command_rx_struct *command, ...)
701 unsigned short maxsiglen;
704 va_start(ap, command);
705 maxsiglen = va_arg(ap, int);
708 dvprintf("faimtest: locate rights: max signature length = %d\n", maxsiglen);
713 int faimtest_parse_unknown(struct aim_session_t *sess, struct command_rx_struct *command, ...)
717 if (!sess || !command)
720 dprintf("\nReceived unknown packet:");
721 for (i = 0; i < command->commandlen; i++) {
723 dinlineprintf("\n\t");
724 dvinlineprintf("0x%2x ", command->data[i]);
726 dinlineprintf("\n\n");
734 This, of course, handles Service Redirects from OSCAR.
736 Should get passed in the following:
737 struct command_rx_struct *command
740 the destination service ID
742 the IP address of the service's server
746 int faimtest_handleredirect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
751 unsigned char *cookie;
753 va_start(ap, command);
754 serviceid = va_arg(ap, int);
755 ip = va_arg(ap, char *);
756 cookie = va_arg(ap, unsigned char *);
759 case 0x0005: { /* Adverts */
760 struct aim_conn_t *tstconn;
762 tstconn = aim_newconn(sess, AIM_CONN_TYPE_ADS, ip);
763 if ((tstconn==NULL) || (tstconn->status & AIM_CONN_STATUS_RESOLVERR)) {
764 dprintf("faimtest: unable to reconnect with authorizer\n");
766 aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_FLAPVER, faimtest_flapversion, 0);
767 aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE, faimtest_conncomplete, 0);
768 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, faimtest_serverready, 0);
769 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0007, faimtest_rateresp, 0); /* rate info */
770 aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_GEN, 0x0018, faimtest_hostversions, 0);
771 aim_auth_sendcookie(sess, tstconn, cookie);
772 dprintf("sent cookie to adverts host\n");
776 case 0x0007: { /* Authorizer */
777 struct aim_conn_t *tstconn;
778 /* Open a connection to the Auth */
779 tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, ip);
780 if ((tstconn==NULL) || (tstconn->status & AIM_CONN_STATUS_RESOLVERR)) {
781 dprintf("faimtest: unable to reconnect with authorizer\n");
783 aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_FLAPVER, faimtest_flapversion, 0);
784 aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE, faimtest_conncomplete, 0);
785 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, faimtest_serverready, 0);
786 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0007, faimtest_rateresp, 0); /* rate info */
787 aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_GEN, 0x0018, faimtest_hostversions, 0);
788 aim_conn_addhandler(sess, tstconn, 0x0007, 0x0007, faimtest_accountconfirm, 0);
789 aim_conn_addhandler(sess, tstconn, 0x0007, 0x0003, faimtest_infochange, 0);
790 aim_conn_addhandler(sess, tstconn, 0x0007, 0x0005, faimtest_infochange, 0);
791 /* Send the cookie to the Auth */
792 aim_auth_sendcookie(sess, tstconn, cookie);
793 dprintf("sent cookie to authorizer host\n");
797 case 0x000d: { /* ChatNav */
798 struct aim_conn_t *tstconn = NULL;
799 tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHATNAV, ip);
800 if ( (tstconn==NULL) || (tstconn->status & AIM_CONN_STATUS_RESOLVERR)) {
801 dprintf("faimtest: unable to connect to chatnav server\n");
802 if (tstconn) aim_conn_kill(sess, &tstconn);
806 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, faimtest_serverready, 0);
807 aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE, faimtest_conncomplete, 0);
808 aim_auth_sendcookie(sess, tstconn, cookie);
809 dprintf("\achatnav: connected\n");
812 case 0x000e: { /* Chat */
813 char *roomname = NULL;
815 struct aim_conn_t *tstconn = NULL;
817 roomname = va_arg(ap, char *);
818 exchange = va_arg(ap, int);
820 tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHAT, ip);
821 if ( (tstconn==NULL) || (tstconn->status & AIM_CONN_STATUS_RESOLVERR)) {
822 dprintf("faimtest: unable to connect to chat server\n");
823 if (tstconn) aim_conn_kill(sess, &tstconn);
826 dvprintf("faimtest: chat: connected to %s on exchange %d\n", roomname, exchange);
829 * We must do this to attach the stored name to the connection!
831 aim_chat_attachname(tstconn, roomname);
833 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, faimtest_serverready, 0);
834 aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE, faimtest_conncomplete, 0);
835 aim_auth_sendcookie(sess, tstconn, cookie);
840 dvprintf("uh oh... got redirect for unknown service 0x%04x!!\n", serviceid);
850 * This is a little more complicated than it looks. The module
851 * name (proto, boscore, etc) may or may not be given. If it is
852 * not given, then use aim.exe. If it is given, put ".ocm" on the
855 * Now, if the offset or length requested would cause a read past
856 * the end of the file, then the request is considered invalid. Invalid
857 * requests are processed specially. The value hashed is the
858 * the request, put into little-endian (eight bytes: offset followed
861 * Additionally, if the request is valid, the length is mod 4096. It is
862 * important that the length is checked for validity first before doing
865 * Note to Bosco's Brigade: if you'd like to break this, put the
866 * module name on an invalid request.
869 static int getaimdata(unsigned char **bufret, int *buflenret, unsigned long offset, unsigned long len, const char *modname)
872 static const char defaultmod[] = "aim.exe";
873 char *filename = NULL;
878 if (!bufret || !buflenret)
883 if (!(filename = malloc(strlen(aimbinarypath)+1+strlen(modname)+4+1))) {
884 dperror("memrequest: malloc");
888 sprintf(filename, "%s/%s.ocm", aimbinarypath, modname);
892 if (!(filename = malloc(strlen(aimbinarypath)+1+strlen(defaultmod)+1))) {
893 dperror("memrequest: malloc");
897 sprintf(filename, "%s/%s", aimbinarypath, defaultmod);
901 if (stat(filename, &st) == -1) {
903 dperror("memrequest: stat");
911 if ((offset > st.st_size) || (len > st.st_size))
913 else if ((st.st_size - offset) < len)
914 len = st.st_size - offset;
915 else if ((st.st_size - len) < len)
916 len = st.st_size - len;
925 free(filename); /* not needed */
927 dvprintf("memrequest: recieved invalid request for 0x%08lx bytes at 0x%08lx (file %s)\n", len, offset, modname);
931 i += strlen(modname);
933 if (!(buf = malloc(i)))
939 memcpy(buf, modname, strlen(modname));
940 i += strlen(modname);
943 /* Damn endianness. This must be little (LSB first) endian. */
944 buf[i++] = offset & 0xff;
945 buf[i++] = (offset >> 8) & 0xff;
946 buf[i++] = (offset >> 16) & 0xff;
947 buf[i++] = (offset >> 24) & 0xff;
948 buf[i++] = len & 0xff;
949 buf[i++] = (len >> 8) & 0xff;
950 buf[i++] = (len >> 16) & 0xff;
951 buf[i++] = (len >> 24) & 0xff;
958 if (!(buf = malloc(len))) {
963 dvprintf("memrequest: loading %ld bytes from 0x%08lx in \"%s\"...\n", len, offset, filename);
965 if (!(f = fopen(filename, "r"))) {
966 dperror("memrequest: fopen");
974 if (fseek(f, offset, SEEK_SET) == -1) {
975 dperror("memrequest: fseek");
981 if (fread(buf, len, 1, f) != 1) {
982 dperror("memrequest: fread");
995 return 0; /* success! */
999 * This will get an offset and a length. The client should read this
1000 * data out of whatever AIM.EXE binary the user has provided (hopefully
1001 * it matches the client information thats sent at login) and pass a
1002 * buffer back to libfaim so it can hash the data and send it to AOL for
1003 * inspection by the client police.
1005 static int faimtest_memrequest(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1008 unsigned long offset, len;
1013 va_start(ap, command);
1014 offset = va_arg(ap, unsigned long);
1015 len = va_arg(ap, unsigned long);
1016 modname = va_arg(ap, char *);
1019 if (aimbinarypath && (getaimdata(&buf, &buflen, offset, len, modname) == 0)) {
1021 aim_sendmemblock(sess, command->conn, offset, buflen, buf, AIM_SENDMEMBLOCK_FLAG_ISREQUEST);
1027 dvprintf("memrequest: unable to use AIM binary (\"%s/%s\"), sending defaults...\n", aimbinarypath, modname);
1029 aim_sendmemblock(sess, command->conn, offset, len, NULL, AIM_SENDMEMBLOCK_FLAG_ISREQUEST);
1036 static int faimtest_parse_authresp(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1039 struct aim_conn_t *bosconn = NULL;
1040 char *sn = NULL, *bosip = NULL, *errurl = NULL, *email = NULL;
1041 unsigned char *cookie = NULL;
1042 int errorcode = 0, regstatus = 0;
1043 int latestbuild = 0, latestbetabuild = 0;
1044 char *latestrelease = NULL, *latestbeta = NULL;
1045 char *latestreleaseurl = NULL, *latestbetaurl = NULL;
1046 char *latestreleaseinfo = NULL, *latestbetainfo = NULL;
1048 va_start(ap, command);
1049 sn = va_arg(ap, char *);
1050 errorcode = va_arg(ap, int);
1051 errurl = va_arg(ap, char *);
1052 regstatus = va_arg(ap, int);
1053 email = va_arg(ap, char *);
1054 bosip = va_arg(ap, char *);
1055 cookie = va_arg(ap, unsigned char *);
1057 latestrelease = va_arg(ap, char *);
1058 latestbuild = va_arg(ap, int);
1059 latestreleaseurl = va_arg(ap, char *);
1060 latestreleaseinfo = va_arg(ap, char *);
1062 latestbeta = va_arg(ap, char *);
1063 latestbetabuild = va_arg(ap, int);
1064 latestbetaurl = va_arg(ap, char *);
1065 latestbetainfo = va_arg(ap, char *);
1069 dvprintf("Screen name: %s\n", sn);
1074 if (errorcode || !bosip || !cookie) {
1075 dvprintf("Login Error Code 0x%04x\n", errorcode);
1076 dvprintf("Error URL: %s\n", errurl);
1077 aim_conn_kill(sess, &command->conn);
1081 dvprintf("Reg status: %2d\n", regstatus);
1082 dvprintf("Email: %s\n", email);
1083 dvprintf("BOS IP: %s\n", bosip);
1086 dvprintf("Latest beta version: %s, build %d, at %s (more info at %s)\n", latestbeta, latestbetabuild, latestbetaurl, latestbetainfo);
1089 dvprintf("Latest released version: %s, build %d, at %s (more info at %s)\n", latestrelease, latestbuild, latestreleaseurl, latestreleaseinfo);
1091 dprintf("Closing auth connection...\n");
1092 aim_conn_kill(sess, &command->conn);
1093 if (!(bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, bosip))) {
1094 dprintf("faimtest: could not connect to BOS: internal error\n");
1096 } else if (bosconn->status & AIM_CONN_STATUS_CONNERR) {
1097 dprintf("faimtest: could not connect to BOS\n");
1098 aim_conn_kill(sess, &bosconn);
1102 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE, faimtest_conncomplete, 0);
1103 aim_conn_addhandler(sess, bosconn, 0x0009, 0x0003, faimtest_bosrights, 0);
1104 aim_conn_addhandler(sess, bosconn, 0x0001, 0x0007, faimtest_rateresp, 0); /* rate info */
1105 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ACK, AIM_CB_ACK_ACK, NULL, 0);
1106 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, 0x0018, faimtest_hostversions, 0);
1107 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_SERVERREADY, faimtest_serverready, 0);
1108 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATEINFO, NULL, 0);
1109 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_REDIRECT, faimtest_handleredirect, 0);
1110 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_STS, AIM_CB_STS_SETREPORTINTERVAL, faimtest_reportinterval, 0);
1111 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_RIGHTSINFO, faimtest_parse_buddyrights, 0);
1112 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING, faimtest_parse_oncoming, 0);
1113 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING, faimtest_parse_offgoing, 0);
1114 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_INCOMING, faimtest_parse_incoming_im, 0);
1115 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_ERROR, faimtest_parse_locerr, 0);
1116 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_MISSEDCALL, faimtest_parse_misses, 0);
1117 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATECHANGE, faimtest_parse_ratechange, 0);
1118 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_EVIL, faimtest_parse_evilnotify, 0);
1119 aim_conn_addhandler(sess, bosconn, 0x000a, 0x0001, faimtest_parse_searcherror, 0);
1120 aim_conn_addhandler(sess, bosconn, 0x000a, 0x0003, faimtest_parse_searchreply, 0);
1121 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ERROR, faimtest_parse_msgerr, 0);
1122 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO, faimtest_parse_userinfo, 0);
1123 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_RIGHTSINFO, faimtest_locrights, 0);
1124 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ACK, faimtest_parse_msgack, 0);
1126 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, faimtest_parse_motd, 0);
1128 aim_conn_addhandler(sess, bosconn, 0x0004, 0x0005, faimtest_icbmparaminfo, 0);
1129 aim_conn_addhandler(sess, bosconn, 0x0001, 0x0001, faimtest_parse_genericerr, 0);
1130 aim_conn_addhandler(sess, bosconn, 0x0003, 0x0001, faimtest_parse_genericerr, 0);
1131 aim_conn_addhandler(sess, bosconn, 0x0009, 0x0001, faimtest_parse_genericerr, 0);
1133 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR, faimtest_parse_connerr, 0);
1134 aim_conn_addhandler(sess, bosconn, 0x0001, 0x001f, faimtest_memrequest, 0);
1135 aim_conn_addhandler(sess, bosconn, 0xffff, 0xffff, faimtest_parse_unknown, 0);
1137 aim_auth_sendcookie(sess, bosconn, cookie);
1142 static void printuserflags(unsigned short flags)
1144 if (flags & AIM_FLAG_UNCONFIRMED)
1145 dinlineprintf("UNCONFIRMED ");
1146 if (flags & AIM_FLAG_ADMINISTRATOR)
1147 dinlineprintf("ADMINISTRATOR ");
1148 if (flags & AIM_FLAG_AOL)
1149 dinlineprintf("AOL ");
1150 if (flags & AIM_FLAG_OSCAR_PAY)
1151 dinlineprintf("OSCAR_PAY ");
1152 if (flags & AIM_FLAG_FREE)
1153 dinlineprintf("FREE ");
1154 if (flags & AIM_FLAG_AWAY)
1155 dinlineprintf("AWAY ");
1156 if (flags & AIM_FLAG_UNKNOWN40)
1157 dinlineprintf("ICQ? ");
1158 if (flags & AIM_FLAG_UNKNOWN80)
1159 dinlineprintf("UNKNOWN80 ");
1163 int faimtest_parse_userinfo(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1165 struct aim_userinfo_s *userinfo;
1166 char *prof_encoding = NULL;
1168 unsigned short inforeq = 0;
1171 va_start(ap, command);
1172 userinfo = va_arg(ap, struct aim_userinfo_s *);
1173 prof_encoding = va_arg(ap, char *);
1174 prof = va_arg(ap, char *);
1175 inforeq = va_arg(ap, int);
1178 dvprintf("faimtest: userinfo: sn: %s\n", userinfo->sn);
1179 dvprintf("faimtest: userinfo: warnlevel: 0x%04x\n", userinfo->warnlevel);
1180 dvprintf("faimtest: userinfo: flags: 0x%04x = ", userinfo->flags);
1181 printuserflags(userinfo->flags);
1182 dinlineprintf("\n");
1184 dvprintf("faimtest: userinfo: membersince: %lu\n", userinfo->membersince);
1185 dvprintf("faimtest: userinfo: onlinesince: %lu\n", userinfo->onlinesince);
1186 dvprintf("faimtest: userinfo: idletime: 0x%04x\n", userinfo->idletime);
1188 if (inforeq == AIM_GETINFO_GENERALINFO) {
1189 dvprintf("faimtest: userinfo: profile_encoding: %s\n", prof_encoding ? prof_encoding : "[none]");
1190 dvprintf("faimtest: userinfo: prof: %s\n", prof ? prof : "[none]");
1191 } else if (inforeq == AIM_GETINFO_AWAYMESSAGE) {
1192 dvprintf("faimtest: userinfo: awaymsg_encoding: %s\n", prof_encoding ? prof_encoding : "[none]");
1193 dvprintf("faimtest: userinfo: awaymsg: %s\n", prof ? prof : "[none]");
1195 dprintf("faimtest: userinfo: unknown info request\n");
1200 static int faimtest_handlecmd(struct aim_session_t *sess, struct command_rx_struct *command, struct aim_userinfo_s *userinfo, char *tmpstr)
1203 if (!strncmp(tmpstr, "disconnect", 10)) {
1207 } else if (strstr(tmpstr, "goodday")) {
1209 aim_send_im(sess, command->conn, userinfo->sn, AIM_IMFLAGS_ACK, "Good day to you too.");
1211 } else if (strstr(tmpstr, "haveicon") && buddyicon) {
1212 struct aim_sendimext_args args;
1213 static const char iconmsg[] = {"I have an icon"};
1215 args.destsn = userinfo->sn;
1216 args.flags = AIM_IMFLAGS_HASICON;
1218 args.msglen = strlen(iconmsg);
1219 args.iconlen = buddyiconlen;
1220 args.iconstamp = buddyiconstamp;
1221 args.iconsum = buddyiconsum;
1223 aim_send_im_ext(sess, command->conn, &args);
1225 } else if (strstr(tmpstr, "sendicon") && buddyicon) {
1227 aim_send_icon(sess, command->conn, userinfo->sn, buddyicon, buddyiconlen, buddyiconstamp, buddyiconsum);
1229 } else if (strstr(tmpstr, "warnme")) {
1231 dprintf("faimtest: icbm: sending non-anon warning\n");
1232 aim_send_warning(sess, command->conn, userinfo->sn, 0);
1234 } else if (strstr(tmpstr, "anonwarn")) {
1236 dprintf("faimtest: icbm: sending anon warning\n");
1237 aim_send_warning(sess, command->conn, userinfo->sn, AIM_WARN_ANON);
1239 } else if (strstr(tmpstr, "setdirectoryinfo")) {
1241 dprintf("faimtest: icbm: sending backwards profile data\n");
1242 aim_setdirectoryinfo(sess, command->conn, "tsrif", "elddim", "tsal", "nediam", "emankcin", "teerts", "ytic", "etats", "piz", 0, 1);
1244 } else if (strstr(tmpstr, "setinterests")) {
1246 dprintf("faimtest: icbm: setting fun interests\n");
1247 aim_setuserinterests(sess, command->conn, "interest1", "interest2", "interest3", "interest4", "interest5", 1);
1249 } else if (!strncmp(tmpstr, "getfile", 7)) {
1251 if (!ohcaptainmycaptain) {
1253 aim_send_im(sess, command->conn, userinfo->sn, AIM_IMFLAGS_ACK, "I have no owner!");
1256 struct aim_conn_t *newconn;
1258 newconn = aim_getfile_initiate(sess, command->conn, (strlen(tmpstr) < 8)?ohcaptainmycaptain:tmpstr+8);
1259 dvprintf("faimtest: getting file listing from %s\n", (strlen(tmpstr) < 8)?ohcaptainmycaptain:tmpstr+8);
1260 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEINITIATE, faimtest_getfile_initiate,0);
1263 } else if (!strncmp(tmpstr, "open chatnav", 12)) {
1265 aim_bos_reqservice(sess, command->conn, AIM_CONN_TYPE_CHATNAV);
1267 } else if (!strncmp(tmpstr, "create", 6)) {
1269 aim_chatnav_createroom(sess,aim_getconn_type(sess, AIM_CONN_TYPE_CHATNAV), (strlen(tmpstr) < 7)?"WorldDomination":tmpstr+7, 0x0004);
1271 } else if (!strncmp(tmpstr, "close chatnav", 13)) {
1272 struct aim_conn_t *chatnavconn;
1274 chatnavconn = aim_getconn_type(sess, AIM_CONN_TYPE_CHATNAV);
1275 aim_conn_kill(sess, &chatnavconn);
1277 } else if (!strncmp(tmpstr, "join", 4)) {
1279 aim_chat_join(sess, command->conn, 0x0004, "worlddomination");
1281 } else if (!strncmp(tmpstr, "leave", 5)) {
1283 aim_chat_leaveroom(sess, "worlddomination");
1285 } else if (!strncmp(tmpstr, "getinfo", 7)) {
1287 aim_getinfo(sess, command->conn, "75784102", AIM_GETINFO_GENERALINFO);
1288 aim_getinfo(sess, command->conn, "15853637", AIM_GETINFO_AWAYMESSAGE);
1289 aim_getinfo(sess, command->conn, "midendian", AIM_GETINFO_GENERALINFO);
1290 aim_getinfo(sess, command->conn, "midendian", AIM_GETINFO_AWAYMESSAGE);
1292 } else if (!strncmp(tmpstr, "open directim", 13)) {
1293 struct aim_conn_t *newconn;
1295 printf("faimtest: opening directim to %s\n", (strlen(tmpstr) < 14)?userinfo->sn:tmpstr+14);
1296 newconn = aim_directim_initiate(sess, command->conn, NULL, (strlen(tmpstr) < 14)?userinfo->sn:tmpstr+14);
1297 if(!newconn || newconn->fd == -1)
1298 printf("connection failed!\n");
1299 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE, faimtest_directim_initiate,0);
1301 } else if(!(strncmp(tmpstr, "lookup", 6))) {
1303 aim_usersearch_address(sess, command->conn, tmpstr+7);
1305 } else if (!strncmp(tmpstr, "reqsendmsg", 10)) {
1307 aim_send_im(sess, command->conn, ohcaptainmycaptain, 0, "sendmsg 7900");
1309 } else if (!strncmp(tmpstr, "reqauth", 7)) {
1311 aim_bos_reqservice(sess, command->conn, AIM_CONN_TYPE_AUTH);
1313 } else if (!strncmp(tmpstr, "reqconfirm", 10)) {
1315 aim_auth_reqconfirm(sess, aim_getconn_type(sess, AIM_CONN_TYPE_AUTH));
1317 } else if (!strncmp(tmpstr, "reqemail", 8)) {
1319 aim_auth_getinfo(sess, aim_getconn_type(sess, AIM_CONN_TYPE_AUTH), 0x0011);
1321 } else if (!strncmp(tmpstr, "changepass", 8)) {
1323 aim_auth_changepasswd(sess, aim_getconn_type(sess, AIM_CONN_TYPE_AUTH), "NEWPASSWORD", "OLDPASSWORD");
1325 } else if (!strncmp(tmpstr, "setemail", 8)) {
1327 aim_auth_setemail(sess, aim_getconn_type(sess, AIM_CONN_TYPE_AUTH), "NEWEMAILADDRESS");
1329 } else if (!strncmp(tmpstr, "sendmsg", 7)) {
1336 newbuf = malloc(i+1);
1337 for (z = 0; z < i; z++) {
1338 newbuf[z] = (z % 10)+0x30;
1341 aim_send_im(sess, command->conn, userinfo->sn, 0, newbuf);
1347 dprintf("unknown command.\n");
1348 aim_add_buddy(sess, command->conn, userinfo->sn);
1356 * The user-level Incoming ICBM callback.
1359 int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1362 struct aim_userinfo_s *userinfo;
1365 va_start(ap, command);
1366 channel = va_arg(ap, int);
1367 userinfo = va_arg(ap, struct aim_userinfo_s *);
1370 * Channel 1: Standard Message
1374 struct aim_incomingim_ch1_args *args;
1375 int clienttype = AIM_CLIENTTYPE_UNKNOWN;
1377 args = va_arg(ap, struct aim_incomingim_ch1_args *);
1380 clienttype = aim_fingerprintclient(args->fingerprint, args->finlen);
1382 dvprintf("faimtest: icbm: sn = \"%s\"\n", userinfo->sn);
1383 dvprintf("faimtest: icbm: probable client type: %d\n", clienttype);
1384 dvprintf("faimtest: icbm: warnlevel = 0x%04x\n", userinfo->warnlevel);
1385 dvprintf("faimtest: icbm: flags = 0x%04x = ", userinfo->flags);
1386 printuserflags(userinfo->flags);
1387 dinlineprintf("\n");
1389 dvprintf("faimtest: icbm: membersince = %lu\n", userinfo->membersince);
1390 dvprintf("faimtest: icbm: onlinesince = %lu\n", userinfo->onlinesince);
1391 dvprintf("faimtest: icbm: idletime = 0x%04x\n", userinfo->idletime);
1392 dvprintf("faimtest: icbm: capabilities = 0x%04x\n", userinfo->capabilities);
1394 dprintf("faimtest: icbm: icbmflags = ");
1395 if (args->icbmflags & AIM_IMFLAGS_AWAY)
1396 dinlineprintf("away ");
1397 if (args->icbmflags & AIM_IMFLAGS_ACK)
1398 dinlineprintf("ackrequest ");
1399 if (args->icbmflags & AIM_IMFLAGS_BUDDYREQ)
1400 dinlineprintf("buddyreq ");
1401 if (args->icbmflags & AIM_IMFLAGS_HASICON)
1402 dinlineprintf("hasicon ");
1403 dinlineprintf("\n");
1405 dvprintf("faimtest: icbm: encoding flags = {%04x, %04x}\n", args->flag1, args->flag2);
1407 dvprintf("faimtest: icbm: message: %s\n", args->msg);
1409 if (args->icbmflags & AIM_IMFLAGS_HASICON)
1410 aim_send_im(sess, command->conn, userinfo->sn, AIM_IMFLAGS_BUDDYREQ, "You have an icon");
1415 while (args->msg[i] == '<') {
1416 if (args->msg[i] == '<') {
1417 while (args->msg[i] != '>')
1422 tmpstr = args->msg+i;
1424 faimtest_handlecmd(sess, command, userinfo, tmpstr);
1429 * Channel 2: Rendevous Request
1431 else if (channel == 2) {
1432 struct aim_incomingim_ch2_args *args;
1434 args = va_arg(ap, struct aim_incomingim_ch2_args *);
1437 switch (args->reqclass) {
1438 case AIM_CAPS_VOICE: {
1440 dvprintf("faimtest: voice invitation: source sn = %s\n", userinfo->sn);
1441 dvprintf("faimtest: voice invitation: \twarnlevel = 0x%04x\n", userinfo->warnlevel);
1442 dvprintf("faimtest: voice invitation: \tclass = 0x%04x = ", userinfo->flags);
1443 printuserflags(userinfo->flags);
1444 dinlineprintf("\n");
1446 /* we dont get membersince on chat invites! */
1447 dvprintf("faimtest: voice invitation: \tonlinesince = %lu\n", userinfo->onlinesince);
1448 dvprintf("faimtest: voice invitation: \tidletime = 0x%04x\n", userinfo->idletime);
1452 case AIM_CAPS_GETFILE: {
1453 struct aim_conn_t *newconn;
1454 struct aim_fileheader_t *fh;
1456 dvprintf("faimtest: get file request from %s (at %s) %x\n", userinfo->sn, args->info.getfile.ip, args->reqclass);
1458 fh = aim_getlisting(sess, listingfile);
1460 newconn = aim_accepttransfer(sess, command->conn, userinfo->sn, args->info.getfile.cookie, args->info.getfile.ip, fh->totfiles, fh->totsize, fh->size, fh->checksum, args->reqclass);
1462 if ( (!newconn) || (newconn->fd == -1) ) {
1463 dprintf("faimtest: getfile: requestconn: apparent error in accepttransfer\n");
1465 aim_conn_kill(sess, &newconn);
1471 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTINGREQ, faimtest_getfile_listingreq, 0);
1472 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ, faimtest_getfile_filereq, 0);
1473 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILESEND, faimtest_getfile_filesend, 0);
1474 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILECOMPLETE, faimtest_getfile_complete, 0);
1476 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEDISCONNECT, faimtest_getfile_disconnect, 0);
1478 dprintf("faimtest: getfile connect succeeded, handlers added.\n");
1482 case AIM_CAPS_SENDFILE: {
1483 dprintf("faimtest: send file!\n");
1486 case AIM_CAPS_CHAT: {
1488 dvprintf("faimtest: chat invitation: source sn = %s\n", userinfo->sn);
1489 dvprintf("faimtest: chat invitation: \twarnlevel = 0x%04x\n", userinfo->warnlevel);
1490 dvprintf("faimtest: chat invitation: \tclass = 0x%04x = ", userinfo->flags);
1491 printuserflags(userinfo->flags);
1492 dinlineprintf("\n");
1494 /* we dont get membersince on chat invites! */
1495 dvprintf("faimtest: chat invitation: \tonlinesince = %lu\n", userinfo->onlinesince);
1496 dvprintf("faimtest: chat invitation: \tidletime = 0x%04x\n", userinfo->idletime);
1498 dvprintf("faimtest: chat invitation: message = %s\n", args->info.chat.msg);
1499 dvprintf("faimtest: chat invitation: room name = %s\n", args->info.chat.roominfo.name);
1500 dvprintf("faimtest: chat invitation: encoding = %s\n", args->info.chat.encoding);
1501 dvprintf("faimtest: chat invitation: language = %s\n", args->info.chat.lang);
1502 dvprintf("faimtest: chat invitation: exchange = 0x%04x\n", args->info.chat.roominfo.exchange);
1503 dvprintf("faimtest: chat invitation: instance = 0x%04x\n", args->info.chat.roominfo.instance);
1504 dvprintf("faimtest: chat invitiation: autojoining %s...\n", args->info.chat.roominfo.name);
1507 * Automatically join room...
1509 aim_chat_join(sess, command->conn, args->info.chat.roominfo.exchange, args->info.chat.roominfo.name);
1512 case AIM_CAPS_IMIMAGE: {
1513 struct aim_conn_t *newconn;
1515 dprintf("faimtest: icbm: rendezvous imimage\n");
1517 dvprintf("faimtest: OFT: DirectIM: request from %s (%s)\n", userinfo->sn, args->info.directim->ip);
1519 newconn = aim_directim_connect(sess, command->conn, args->info.directim);
1521 if ( (!newconn) || (newconn->fd == -1) ) {
1522 dprintf("faimtest: icbm: imimage: could not connect\n");
1525 aim_conn_kill(sess, &newconn);
1530 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, faimtest_directim_incoming, 0);
1531 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT, faimtest_directim_disconnect, 0);
1532 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, faimtest_directim_typing, 0);
1534 dvprintf("faimtest: OFT: DirectIM: connected to %s\n", userinfo->sn);
1536 aim_send_im_direct(sess, newconn, "goodday");
1540 case AIM_CAPS_BUDDYICON: {
1542 dvprintf("faimtest: Buddy Icon from %s, length = %u\n", userinfo->sn, args->info.icon.length);
1546 dvprintf("faimtest: icbm: unknown reqclass (%d)\n", args->reqclass);
1549 dvprintf("faimtest does not support channels > 2 (chan = %02x)\n", channel);
1551 dprintf("faimtest: icbm: done with ICBM handling\n");
1556 int faimtest_directim_initiate(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1559 struct aim_directim_priv *priv;
1560 struct aim_conn_t *newconn, *listenerconn;
1562 va_start(ap, command);
1563 newconn = va_arg(ap, struct aim_conn_t *);
1564 listenerconn = va_arg(ap, struct aim_conn_t *);
1567 aim_conn_close(listenerconn);
1568 aim_conn_kill(sess, &listenerconn);
1570 priv = (struct aim_directim_priv *)newconn->priv;
1572 dvprintf("faimtest: OFT: DirectIM: intitiate success to %s\n", priv->ip);
1574 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, faimtest_directim_incoming, 0);
1575 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT, faimtest_directim_disconnect, 0);
1576 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, faimtest_directim_typing, 0);
1578 aim_send_im_direct(sess, newconn, "goodday");
1580 dvprintf("faimtest: OFT: DirectIM: connected to %s\n", priv->sn);
1585 int faimtest_directim_connect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1588 struct aim_directim_priv *priv;
1590 va_start(ap, command);
1591 priv = va_arg(ap, struct aim_directim_priv *);
1595 dprintf("faimtest: directim_connect\n");
1600 int faimtest_directim_incoming(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1604 struct aim_conn_t *conn;
1605 struct aim_directim_priv *priv;
1607 va_start(ap, command);
1608 conn = va_arg(ap, struct aim_conn_t *);
1609 msg = va_arg(ap, char *);
1612 if(!(priv = conn->priv)) {
1613 dvprintf("faimtest: directim: no private struct on conn with fd %d\n", conn->fd);
1617 dvprintf("faimtest: Directim from %s: %s\n", priv->sn, msg);
1618 if (!strncmp(msg, "sendmsg", 7)) {
1625 newbuf = malloc(i+1);
1626 for (z = 0; z < i; z++) {
1627 newbuf[z] = (z % 10)+0x30;
1630 aim_send_im_direct(sess, conn, newbuf);
1633 } else if (!strncmp(msg, "goodday", 7)) {
1634 aim_send_im_direct(sess, conn, "Good day to you, too");
1637 snprintf(newmsg, sizeof(newmsg), "unknown (%s)\n", msg);
1638 aim_send_im_direct(sess, conn, newmsg);
1643 int faimtest_directim_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1646 struct aim_conn_t *conn;
1649 va_start(ap, command);
1650 conn = va_arg(ap, struct aim_conn_t *);
1651 sn = va_arg(ap, char *);
1654 dvprintf("faimtest: directim: disconnected from %s\n", sn);
1656 aim_conn_kill(sess, &conn);
1660 int faimtest_directim_typing(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1663 struct aim_conn_t *conn;
1664 struct aim_directim_priv *priv;
1666 va_start(ap, command);
1667 conn = va_arg(ap, struct aim_conn_t *);
1670 if(!(priv = (struct aim_directim_priv *)conn->priv)) {
1671 dvprintf("faimtest: no private struct on conn with fd %d!\n", conn->fd);
1675 dvprintf("faimtest: ohmigod! %s has started typing (DirectIM). He's going to send you a message! *squeal*\n", priv->sn);
1679 int faimtest_infochange(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1681 unsigned short change = 0;
1682 int perms, type, length, str;
1686 va_start(ap, command);
1687 perms = va_arg(ap, int);
1688 type = va_arg(ap, int);
1689 length = va_arg(ap, int);
1690 val = va_arg(ap, char *);
1691 str = va_arg(ap, int);
1694 if (aimutil_get16(command->data+2) == 0x0005)
1697 dvprintf("info%s: perms = %d, type = %x, length = %d, val = %s\n", change?" change":"", perms, type, length, str?val:"(not string)");
1702 int faimtest_parse_oncoming(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1704 struct aim_userinfo_s *userinfo;
1707 va_start(ap, command);
1708 userinfo = va_arg(ap, struct aim_userinfo_s *);
1711 dvprintf("%ld %s is now online (flags: %04x = %s%s%s%s%s%s%s%s) (caps = 0x%04x)\n",
1713 userinfo->sn, userinfo->flags,
1714 (userinfo->flags&AIM_FLAG_UNCONFIRMED)?" UNCONFIRMED":"",
1715 (userinfo->flags&AIM_FLAG_ADMINISTRATOR)?" ADMINISTRATOR":"",
1716 (userinfo->flags&AIM_FLAG_AOL)?" AOL":"",
1717 (userinfo->flags&AIM_FLAG_OSCAR_PAY)?" OSCAR_PAY":"",
1718 (userinfo->flags&AIM_FLAG_FREE)?" FREE":"",
1719 (userinfo->flags&AIM_FLAG_AWAY)?" AWAY":"",
1720 (userinfo->flags&AIM_FLAG_UNKNOWN40)?" UNKNOWN40":"",
1721 (userinfo->flags&AIM_FLAG_UNKNOWN80)?" UNKNOWN80":"",
1722 userinfo->capabilities);
1726 int faimtest_parse_offgoing(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1728 struct aim_userinfo_s *userinfo;
1731 va_start(ap, command);
1732 userinfo = va_arg(ap, struct aim_userinfo_s *);
1735 dvprintf("%ld %s is now offline (flags: %04x = %s%s%s%s%s%s%s%s) (caps = 0x%04x)\n",
1737 userinfo->sn, userinfo->flags,
1738 (userinfo->flags&AIM_FLAG_UNCONFIRMED)?" UNCONFIRMED":"",
1739 (userinfo->flags&AIM_FLAG_ADMINISTRATOR)?" ADMINISTRATOR":"",
1740 (userinfo->flags&AIM_FLAG_AOL)?" AOL":"",
1741 (userinfo->flags&AIM_FLAG_OSCAR_PAY)?" OSCAR_PAY":"",
1742 (userinfo->flags&AIM_FLAG_FREE)?" FREE":"",
1743 (userinfo->flags&AIM_FLAG_AWAY)?" AWAY":"",
1744 (userinfo->flags&AIM_FLAG_UNKNOWN40)?" UNKNOWN40":"",
1745 (userinfo->flags&AIM_FLAG_UNKNOWN80)?" UNKNOWN80":"",
1746 userinfo->capabilities);
1750 int faimtest_parse_motd(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1752 static char *codes[] = {
1754 "Mandatory upgrade",
1757 "Top o' the world!"};
1758 static int codeslen = 5;
1764 va_start(ap, command);
1765 id = va_arg(ap, int);
1766 msg = va_arg(ap, char *);
1769 dvprintf("faimtest: motd: %s (%d / %s)\n", msg, id,
1770 (id < codeslen)?codes[id]:"unknown");
1776 aim_bos_reqservice(sess, command->conn, 0x0005); /* adverts */
1777 aim_bos_reqservice(sess, command->conn, 0x000f); /* user directory */
1779 /* Don't know what this does... */
1780 /* XXX sess->sn should be normalized by the 0001/000f handler */
1781 aim_0002_000b(sess, command->conn, sess->sn);
1787 int faimtest_parse_genericerr(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1790 unsigned short reason;
1792 va_start(ap, command);
1793 reason = va_arg(ap, int);
1796 dvprintf("faimtest: snac threw error (reason 0x%04x: %s)\n", reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown");
1801 int faimtest_parse_msgerr(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1805 unsigned short reason;
1807 va_start(ap, command);
1808 reason = va_arg(ap, int);
1809 destsn = va_arg(ap, char *);
1812 dvprintf("faimtest: message to %s bounced (reason 0x%04x: %s)\n", destsn, reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown");
1817 int faimtest_parse_locerr(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1821 unsigned short reason;
1823 va_start(ap, command);
1824 reason = va_arg(ap, int);
1825 destsn = va_arg(ap, char *);
1828 dvprintf("faimtest: user information for %s unavailable (reason 0x%04x: %s)\n", destsn, reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown");
1834 * Handles callbacks for AIM_CB_MISSED_CALL.
1836 int faimtest_parse_misses(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1838 static char *missedreasons[] = {
1840 "Message too large"};
1841 static int missedreasonslen = 2;
1844 unsigned short chan, nummissed, reason;
1845 struct aim_userinfo_s *userinfo;
1847 va_start(ap, command);
1848 chan = va_arg(ap, int);
1849 userinfo = va_arg(ap, struct aim_userinfo_s *);
1850 nummissed = va_arg(ap, int);
1851 reason = va_arg(ap, int);
1854 dvprintf("faimtest: missed %d messages from %s (reason %d: %s)\n", nummissed, userinfo->sn, reason, (reason<missedreasonslen)?missedreasons[reason]:"unknown");
1859 int faimtest_parse_login(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1861 struct client_info_s info = AIM_CLIENTINFO_KNOWNGOOD;
1865 va_start(ap, command);
1866 key = va_arg(ap, char *);
1869 aim_send_login(sess, command->conn, screenname, password, &info, key);
1874 int faimtest_chat_join(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1877 struct aim_userinfo_s *userinfo;
1878 int count = 0, i = 0;
1880 va_start(ap, command);
1881 count = va_arg(ap, int);
1882 userinfo = va_arg(ap, struct aim_userinfo_s *);
1885 dvprintf("faimtest: chat: %s: New occupants have joined:\n", (char *)command->conn->priv);
1887 dvprintf("faimtest: chat: %s: \t%s\n", (char *)command->conn->priv, userinfo[i++].sn);
1892 int faimtest_chat_leave(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1895 struct aim_userinfo_s *userinfo;
1896 int count = 0, i = 0;
1898 va_start(ap, command);
1899 count = va_arg(ap, int);
1900 userinfo = va_arg(ap, struct aim_userinfo_s *);
1903 dvprintf("faimtest: chat: %s: Some occupants have left:\n", (char *)command->conn->priv);
1905 for (i = 0; i < count; )
1906 dvprintf("faimtest: chat: %s: \t%s\n", (char *)command->conn->priv, userinfo[i++].sn);
1911 int faimtest_chat_infoupdate(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1914 struct aim_userinfo_s *userinfo;
1915 struct aim_chat_roominfo *roominfo;
1919 unsigned short unknown_c9, unknown_d2, unknown_d5, maxmsglen;
1920 unsigned long creationtime;
1922 va_start(ap, command);
1923 roominfo = va_arg(ap, struct aim_chat_roominfo *);
1924 roomname = va_arg(ap, char *);
1925 usercount= va_arg(ap, int);
1926 userinfo = va_arg(ap, struct aim_userinfo_s *);
1927 roomdesc = va_arg(ap, char *);
1928 unknown_c9 = va_arg(ap, int);
1929 creationtime = va_arg(ap, unsigned long);
1930 maxmsglen = va_arg(ap, int);
1931 unknown_d2 = va_arg(ap, int);
1932 unknown_d5 = va_arg(ap, int);
1935 dvprintf("faimtest: chat: %s: info update:\n", (char *)command->conn->priv);
1936 dvprintf("faimtest: chat: %s: \tRoominfo: {%04x, %s, %04x}\n",
1937 (char *)command->conn->priv,
1940 roominfo->instance);
1941 dvprintf("faimtest: chat: %s: \tRoomname: %s\n", (char *)command->conn->priv, roomname);
1942 dvprintf("faimtest: chat: %s: \tRoomdesc: %s\n", (char *)command->conn->priv, roomdesc);
1943 dvprintf("faimtest: chat: %s: \tOccupants: (%d)\n", (char *)command->conn->priv, usercount);
1945 for (i = 0; i < usercount; )
1946 dvprintf("faimtest: chat: %s: \t\t%s\n", (char *)command->conn->priv, userinfo[i++].sn);
1948 dvprintf("faimtest: chat: %s: \tUnknown_c9: 0x%04x\n", (char *)command->conn->priv, unknown_c9);
1949 dvprintf("faimtest: chat: %s: \tCreation time: %lu (time_t)\n", (char *)command->conn->priv, creationtime);
1950 dvprintf("faimtest: chat: %s: \tMax message length: %d bytes\n", (char *)command->conn->priv, maxmsglen);
1951 dvprintf("faimtest: chat: %s: \tUnknown_d2: 0x%04x\n", (char *)command->conn->priv, unknown_d2);
1952 dvprintf("faimtest: chat: %s: \tUnknown_d5: 0x%02x\n", (char *)command->conn->priv, unknown_d5);
1957 int faimtest_chat_incomingmsg(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1960 struct aim_userinfo_s *userinfo;
1964 va_start(ap, command);
1965 userinfo = va_arg(ap, struct aim_userinfo_s *);
1966 msg = va_arg(ap, char *);
1969 dvprintf("faimtest: chat: %s: incoming msg from %s: %s\n", (char *)command->conn->priv, userinfo->sn, msg);
1972 * Do an echo for testing purposes. But not for ourselves ("oops!")
1974 if (strcmp(userinfo->sn, sess->sn) != 0)
1976 sprintf(tmpbuf, "(%s said \"%s\")", userinfo->sn, msg);
1977 aim_chat_send_im(sess, command->conn, 0, tmpbuf, strlen(tmpbuf));
1983 int faimtest_chatnav_info(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1985 unsigned short type;
1988 va_start(ap, command);
1989 type = va_arg(ap, int);
1994 struct aim_chat_exchangeinfo *exchanges;
1995 int exchangecount,i = 0;
1997 maxrooms = va_arg(ap, int);
1998 exchangecount = va_arg(ap, int);
1999 exchanges = va_arg(ap, struct aim_chat_exchangeinfo *);
2002 dprintf("faimtest: chat info: Chat Rights:\n");
2003 dvprintf("faimtest: chat info: \tMax Concurrent Rooms: %d\n", maxrooms);
2005 dvprintf("faimtest: chat info: \tExchange List: (%d total)\n", exchangecount);
2006 for (i = 0; i < exchangecount; i++) {
2007 dvprintf("faimtest: chat info: \t\t%x: %s (%s/%s)\n",
2008 exchanges[i].number,
2010 exchanges[i].charset1,
2011 exchanges[i].lang1);
2017 char *fqcn, *name, *ck;
2018 unsigned short instance, flags, maxmsglen, maxoccupancy, unknown, exchange;
2019 unsigned char createperms;
2020 unsigned long createtime;
2022 fqcn = va_arg(ap, char *);
2023 instance = va_arg(ap, int);
2024 exchange = va_arg(ap, int);
2025 flags = va_arg(ap, int);
2026 createtime = va_arg(ap, unsigned long);
2027 maxmsglen = va_arg(ap, int);
2028 maxoccupancy = va_arg(ap, int);
2029 createperms = va_arg(ap, int);
2030 unknown = va_arg(ap, int);
2031 name = va_arg(ap, char *);
2032 ck = va_arg(ap, char *);
2035 dvprintf("faimtest: received room create reply for %s/0x%04x\n", fqcn, exchange);
2040 dvprintf("faimtest: chatnav info: unknown type (%04x)\n", type);
2045 int faimtest_parse_connerr(struct aim_session_t *sess, struct command_rx_struct *command, ...)
2048 unsigned short code;
2051 va_start(ap, command);
2052 code = va_arg(ap, int);
2053 msg = va_arg(ap, char *);
2056 dvprintf("faimtest: connerr: Code 0x%04x: %s\n", code, msg);
2057 aim_conn_kill(sess, &command->conn); /* this will break the main loop */
2064 int faimtest_debugconn_connect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
2066 dprintf("faimtest: connecting to an aimdebugd!\n");
2068 /* convert the authorizer connection to a BOS connection */
2069 command->conn->type = AIM_CONN_TYPE_BOS;
2071 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_MSG, AIM_CB_MSG_INCOMING, faimtest_parse_incoming_im, 0);
2073 /* tell the aimddebugd we're ready */
2074 aim_debugconn_sendconnect(sess, command->conn);
2076 /* go right into main loop (don't open a BOS connection, etc) */
2081 * Received in response to an IM sent with the AIM_IMFLAGS_ACK option.
2083 int faimtest_parse_msgack(struct aim_session_t *sess, struct command_rx_struct *command, ...)
2086 unsigned short type;
2089 va_start(ap, command);
2090 type = va_arg(ap, int);
2091 sn = va_arg(ap, char *);
2094 dvprintf("faimtest: msgack: 0x%04x / %s\n", type, sn);
2099 int faimtest_getfile_filereq(struct aim_session_t *ses, struct command_rx_struct *command, ...)
2102 struct aim_conn_t *oftconn;
2103 struct aim_fileheader_t *fh;
2106 va_start(ap, command);
2107 oftconn = va_arg(ap, struct aim_conn_t *);
2108 fh = va_arg(ap, struct aim_fileheader_t *);
2109 cookie = va_arg(ap, char *);
2112 dvprintf("faimtest: request for file %s.\n", fh->name);
2118 int faimtest_getfile_filesend(struct aim_session_t *sess, struct command_rx_struct *command, ...)
2121 struct aim_conn_t *oftconn;
2122 struct aim_fileheader_t *fh;
2123 char *path, *cookie;
2124 int pos, bufpos = 0, bufsize = 2048, i;
2129 va_start(ap, command);
2130 oftconn = va_arg(ap, struct aim_conn_t *);
2131 fh = va_arg(ap, struct aim_fileheader_t *);
2132 cookie = va_arg(ap, char *);
2135 dvprintf("faimtest: sending file %s(%ld).\n", fh->name, fh->size);
2137 if(!(buf = malloc(2048)))
2140 if( (path = (char *)calloc(1, strlen(listingpath) +strlen(fh->name)+2)) == NULL) {
2142 dprintf("faimtest: error in calloc of path\n");
2143 return 0; /* XXX: no idea what winaim expects here =) */
2146 snprintf(path, strlen(listingpath)+strlen(fh->name)+2, "%s/%s", listingpath, fh->name);
2149 if( (file = fopen(path, "r")) == NULL) {
2150 dvprintf("faimtest: getfile_send fopen failed for %s. damn.\n", path);
2155 * This is a mess. Remember that faimtest is demonstration code
2156 * only and for the sake of the gods, don't use this code in any
2157 * of your clients. --mid
2159 for(pos = 0; pos < fh->size; pos++) {
2160 bufpos = pos % bufsize;
2162 if(bufpos == 0 && pos > 0) { /* filled our buffer. spit it across the wire */
2163 if ( (i = send(oftconn->fd, buf, bufsize, 0)) != bufsize ) {
2164 dperror("faim: getfile_send: write1");
2165 dprintf("faim: getfile_send: whoopsy, didn't write it all...\n");
2170 if( (buf[bufpos] = fgetc(file)) == EOF) {
2171 if(pos != fh->size) {
2172 dvprintf("faim: getfile_send: hrm... apparent early EOF at pos 0x%x of 0x%lx\n", pos, fh->size);
2177 dvprintf("%c(0x%02x) ", buf[pos], buf[pos]);
2180 if( (i = send(oftconn->fd, buf, bufpos+1, 0)) != (bufpos+1)) {
2181 dperror("faim: getfile_send: write2");
2182 dprintf("faim: getfile_send cleanup: whoopsy, didn't write it all...\n");
2192 int faimtest_getfile_complete(struct aim_session_t *sess, struct command_rx_struct *command, ...)
2195 struct aim_conn_t *conn;
2196 struct aim_fileheader_t *fh;
2198 va_start(ap, command);
2199 conn = va_arg(ap, struct aim_conn_t *);
2200 fh = va_arg(ap, struct aim_fileheader_t *);
2203 dvprintf("faimtest: completed file transfer for %s.\n", fh->name);
2205 aim_conn_close(conn);
2206 aim_conn_kill(sess, &conn);
2210 int faimtest_getfile_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
2213 struct aim_conn_t *conn;
2216 va_start(ap, command);
2217 conn = va_arg(ap, struct aim_conn_t *);
2218 sn = va_arg(ap, char *);
2221 aim_conn_kill(sess, &conn);
2223 dvprintf("faimtest: getfile: disconnected from %s\n", sn);
2226 int faimtest_getfile_initiate(struct aim_session_t *sess, struct command_rx_struct *command, ...)
2229 struct aim_conn_t *conn, *listenerconn;
2230 struct aim_filetransfer_priv *priv;
2232 va_start(ap, command);
2233 conn = va_arg(ap, struct aim_conn_t *);
2234 listenerconn = va_arg(ap, struct aim_conn_t *);
2237 aim_conn_close(listenerconn);
2238 aim_conn_kill(sess, &listenerconn);
2240 aim_conn_addhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ, faimtest_getfile_filereq, 0);
2241 aim_conn_addhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILESEND, faimtest_getfile_filesend, 0);
2242 aim_conn_addhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILECOMPLETE, faimtest_getfile_complete, 0);
2243 aim_conn_addhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEDISCONNECT, faimtest_getfile_disconnect, 0);
2244 aim_conn_addhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTING, faimtest_getfile_listing, 0);
2245 aim_conn_addhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTINGREQ, faimtest_getfile_listingreq, 0);
2246 aim_conn_addhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILERECEIVE, faimtest_getfile_receive, 0);
2247 aim_conn_addhandler(sess, conn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILESTATE4, faimtest_getfile_state4, 0);
2249 priv = (struct aim_filetransfer_priv *)conn->priv;
2251 dvprintf("faimtest: getfile: %s (%s) connected to us on %d\n", priv->sn, priv->ip, conn->fd);
2255 int faimtest_getfile_listing(struct aim_session_t *sess, struct command_rx_struct *command, ...)
2258 struct aim_conn_t *conn;
2260 struct aim_filetransfer_priv *ft;
2261 char *filename, *nameend, *sizec;
2262 int filesize, namelen;
2264 va_start(ap, command);
2265 conn = va_arg(ap, struct aim_conn_t *);
2266 ft = va_arg(ap, struct aim_filetransfer_priv *);
2267 listing = va_arg(ap, char *);
2270 dvprintf("listing on %d==================\n%s\n===========\n", conn->fd, listing);
2272 nameend = strstr(listing+0x1a, "\r");
2274 namelen = nameend - (listing + 0x1a);
2276 filename = malloc(namelen + 1);
2277 strncpy(filename, listing+0x1a, namelen);
2278 filename[namelen] = 0x00;
2280 sizec = malloc(8+1);
2281 memcpy(sizec, listing + 0x11, 8);
2284 filesize = strtol(sizec, (char **)NULL, 10);
2286 dvprintf("faimtest: requesting %d %s(%d long)\n", namelen, filename, filesize);
2288 aim_oft_getfile_request(sess, conn, filename, filesize);
2296 int faimtest_getfile_listingreq(struct aim_session_t *sess, struct command_rx_struct *command, ...)
2299 struct aim_conn_t *oftconn;
2300 struct aim_fileheader_t *fh;
2301 int pos, bufpos = 0, bufsize = 2048, i;
2304 va_start(ap, command);
2305 oftconn = va_arg(ap, struct aim_conn_t *);
2306 fh = va_arg(ap, struct aim_fileheader_t *);
2309 dvprintf("faimtest: sending listing of size %ld\n", fh->size);
2311 if(!(buf = malloc(2048)))
2314 for(pos = 0; pos < fh->size; pos++) {
2315 bufpos = pos % bufsize;
2317 if(bufpos == 0 && pos > 0) { /* filled our buffer. spit it across the wire */
2318 if ( (i = send(oftconn->fd, buf, bufsize, 0)) != bufsize ) {
2319 dperror("faim: getfile_send: write1");
2320 dprintf("faim: getfile_send: whoopsy, didn't write it all...\n");
2325 if( (buf[bufpos] = fgetc(listingfile)) == EOF) {
2326 if(pos != fh->size) {
2327 dvprintf("faim: getfile_send: hrm... apparent early EOF at pos 0x%x of 0x%lx\n", pos, fh->size);
2334 if( (i = send(oftconn->fd, buf, bufpos+1, 0)) != (bufpos+1)) {
2335 dperror("faim: getfile_send: write2");
2336 dprintf("faim: getfile_send cleanup: whoopsy, didn't write it all...\n");
2341 dprintf("faimtest: sent listing\n");
2346 int faimtest_getfile_receive(struct aim_session_t *sess, struct command_rx_struct *command, ...)
2349 struct aim_conn_t *conn;
2350 struct aim_filetransfer_priv *ft;
2354 va_start(ap, command);
2355 conn = va_arg(ap, struct aim_conn_t *);
2356 ft = va_arg(ap, struct aim_filetransfer_priv *);
2359 dvprintf("faimtest: receiving %ld bytes of file data for %s:\n\t", ft->fh.size, ft->fh.name);
2361 for(pos = 0; pos < ft->fh.size; pos++) {
2362 read(conn->fd, &data, 1);
2363 printf("%c(%02x) ", data, data);
2368 aim_oft_getfile_end(sess, conn);
2373 int faimtest_getfile_state4(struct aim_session_t *sess, struct command_rx_struct *command, ...)
2376 struct aim_conn_t *conn;
2378 va_start(ap, command);
2379 conn = va_arg(ap, struct aim_conn_t *);
2382 aim_conn_close(conn);
2383 aim_conn_kill(sess, &conn);
2388 int faimtest_parse_ratechange(struct aim_session_t *sess, struct command_rx_struct *command, ...)
2390 static char *codes[5] = {"invalid",
2397 unsigned long rateclass, windowsize, clear, alert, limit, disconnect;
2398 unsigned long currentavg, maxavg;
2400 va_start(ap, command);
2402 /* See code explanations below */
2403 code = va_arg(ap, int);
2406 * See comments above aim_parse_ratechange_middle() in aim_rxhandlers.c.
2408 rateclass = va_arg(ap, unsigned long);
2411 * Not sure what this is exactly. I think its the temporal
2412 * relation factor (ie, how to make the rest of the numbers
2413 * make sense in the real world).
2415 windowsize = va_arg(ap, unsigned long);
2417 /* Explained below */
2418 clear = va_arg(ap, unsigned long);
2419 alert = va_arg(ap, unsigned long);
2420 limit = va_arg(ap, unsigned long);
2421 disconnect = va_arg(ap, unsigned long);
2422 currentavg = va_arg(ap, unsigned long);
2423 maxavg = va_arg(ap, unsigned long);
2428 dvprintf("faimtest: rate %s (rate class 0x%04lx): curavg = %ld, maxavg = %ld, alert at %ld, clear warning at %ld, limit at %ld, disconnect at %ld (window size = %ld)\n",
2429 (code < 5)?codes[code]:"invalid",
2436 if (code == AIM_RATE_CODE_CHANGE) {
2438 * Not real sure when these get sent.
2440 if (currentavg >= clear)
2441 aim_conn_setlatency(command->conn, 0);
2443 } else if (code == AIM_RATE_CODE_WARNING) {
2445 * We start getting WARNINGs the first time we go below the 'alert'
2446 * limit (currentavg < alert) and they stop when either we pause
2447 * long enough for currentavg to go above 'clear', or until we
2448 * flood it bad enough to go below 'limit' (and start getting
2449 * LIMITs instead) or even further and go below 'disconnect' and
2450 * get disconnected completely (and won't be able to login right
2453 aim_conn_setlatency(command->conn, windowsize/4); /* XXX this is bogus! */
2455 } else if (code == AIM_RATE_CODE_LIMIT) {
2457 * When we hit LIMIT, messages will start getting dropped.
2459 aim_conn_setlatency(command->conn, windowsize/2); /* XXX this is bogus! */
2461 } else if (code == AIM_RATE_CODE_CLEARLIMIT) {
2463 * The limit is cleared when curavg goes above 'clear'.
2465 aim_conn_setlatency(command->conn, 0);
2471 int faimtest_parse_evilnotify(struct aim_session_t *sess, struct command_rx_struct *command, ...)
2475 struct aim_userinfo_s *userinfo;
2477 va_start(ap, command);
2478 newevil = va_arg(ap, int);
2479 userinfo = va_arg(ap, struct aim_userinfo_s *);
2483 * Evil Notifications that are lacking userinfo->sn are anon-warns
2484 * if they are an evil increases, but are not warnings at all if its
2485 * a decrease (its the natural backoff happening).
2487 * newevil is passed as an int representing the new evil value times
2490 dvprintf("faimtest: evil level change: new value = %2.1f%% (caused by %s)\n", ((float)newevil)/10, (userinfo && strlen(userinfo->sn))?userinfo->sn:"anonymous");
2495 int faimtest_parse_searchreply(struct aim_session_t *sess, struct command_rx_struct *command, ...)
2498 char *address, *SNs;
2501 va_start(ap, command);
2502 address = va_arg(ap, char *);
2503 num = va_arg(ap, int);
2504 SNs = va_arg(ap, char *);
2507 dvprintf("faimtest: E-Mail Search Results for %s: ", address);
2509 for(i = 0; i < num; i++)
2510 dvinlineprintf("%s, ", &SNs[i*(MAXSNLEN+1)]);
2511 dinlineprintf("\n");
2516 int faimtest_parse_searcherror(struct aim_session_t *sess, struct command_rx_struct *command, ...)
2521 va_start(ap, command);
2522 address = va_arg(ap, char *);
2525 dvprintf("faimtest: E-Mail Search Results for %s: No Results or Invalid Email\n", address);