+ unsigned char *cookie;
+
+ va_start(ap, command);
+ serviceid = va_arg(ap, int);
+ ip = va_arg(ap, char *);
+ cookie = va_arg(ap, unsigned char *);
+
+ switch(serviceid) {
+ case 0x0005: { /* Adverts */
+ struct aim_conn_t *tstconn;
+
+ tstconn = aim_newconn(sess, AIM_CONN_TYPE_ADS, ip);
+ if ((tstconn==NULL) || (tstconn->status & AIM_CONN_STATUS_RESOLVERR)) {
+ dprintf("faimtest: unable to reconnect with authorizer\n");
+ } else {
+ aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_FLAPVER, faimtest_flapversion, 0);
+ aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE, faimtest_conncomplete, 0);
+ aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, faimtest_serverready, 0);
+ aim_conn_addhandler(sess, tstconn, 0x0001, 0x0007, faimtest_rateresp, 0); /* rate info */
+ aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_GEN, 0x0018, faimtest_hostversions, 0);
+ aim_auth_sendcookie(sess, tstconn, cookie);
+ dprintf("sent cookie to adverts host\n");
+ }
+ break;
+ }
+ case 0x0007: { /* Authorizer */
+ struct aim_conn_t *tstconn;
+ /* Open a connection to the Auth */
+ tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, ip);
+ if ((tstconn==NULL) || (tstconn->status & AIM_CONN_STATUS_RESOLVERR)) {
+ dprintf("faimtest: unable to reconnect with authorizer\n");
+ } else {
+ aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_FLAPVER, faimtest_flapversion, 0);
+ aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE, faimtest_conncomplete, 0);
+ aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, faimtest_serverready, 0);
+ aim_conn_addhandler(sess, tstconn, 0x0001, 0x0007, faimtest_rateresp, 0); /* rate info */
+ aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_GEN, 0x0018, faimtest_hostversions, 0);
+ aim_conn_addhandler(sess, tstconn, 0x0007, 0x0007, faimtest_accountconfirm, 0);
+ aim_conn_addhandler(sess, tstconn, 0x0007, 0x0003, faimtest_infochange, 0);
+ aim_conn_addhandler(sess, tstconn, 0x0007, 0x0005, faimtest_infochange, 0);
+ /* Send the cookie to the Auth */
+ aim_auth_sendcookie(sess, tstconn, cookie);
+ dprintf("sent cookie to authorizer host\n");
+ }
+ break;
+ }
+ case 0x000d: { /* ChatNav */
+ struct aim_conn_t *tstconn = NULL;
+ tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHATNAV, ip);
+ if ( (tstconn==NULL) || (tstconn->status & AIM_CONN_STATUS_RESOLVERR)) {
+ dprintf("faimtest: unable to connect to chatnav server\n");
+ if (tstconn) aim_conn_kill(sess, &tstconn);
+ return 1;
+ }
+
+ aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, faimtest_serverready, 0);
+ aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE, faimtest_conncomplete, 0);
+ aim_auth_sendcookie(sess, tstconn, cookie);
+ dprintf("\achatnav: connected\n");
+ break;
+ }
+ case 0x000e: { /* Chat */
+ char *roomname = NULL;
+ int exchange;
+ struct aim_conn_t *tstconn = NULL;
+
+ roomname = va_arg(ap, char *);
+ exchange = va_arg(ap, int);
+
+ tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHAT, ip);
+ if ( (tstconn==NULL) || (tstconn->status & AIM_CONN_STATUS_RESOLVERR)) {
+ dprintf("faimtest: unable to connect to chat server\n");
+ if (tstconn) aim_conn_kill(sess, &tstconn);
+ return 1;
+ }
+ dvprintf("faimtest: chat: connected to %s on exchange %d\n", roomname, exchange);
+
+ /*
+ * We must do this to attach the stored name to the connection!
+ */
+ aim_chat_attachname(tstconn, roomname);
+
+ aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, faimtest_serverready, 0);
+ aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE, faimtest_conncomplete, 0);
+ aim_auth_sendcookie(sess, tstconn, cookie);
+
+ break;
+ }
+ default:
+ dvprintf("uh oh... got redirect for unknown service 0x%04x!!\n", serviceid);
+ /* dunno */
+ }
+
+ va_end(ap);
+
+ return 1;
+}
+
+/*
+ * This is a little more complicated than it looks. The module
+ * name (proto, boscore, etc) may or may not be given. If it is
+ * not given, then use aim.exe. If it is given, put ".ocm" on the
+ * end of it.
+ *
+ * Now, if the offset or length requested would cause a read past
+ * the end of the file, then the request is considered invalid. Invalid
+ * requests are processed specially. The value hashed is the
+ * the request, put into little-endian (eight bytes: offset followed
+ * by length).
+ *
+ * Additionally, if the request is valid, the length is mod 4096. It is
+ * important that the length is checked for validity first before doing
+ * the mod.
+ *
+ * Note to Bosco's Brigade: if you'd like to break this, put the
+ * module name on an invalid request.
+ *
+ */
+static int getaimdata(unsigned char **bufret, int *buflenret, unsigned long offset, unsigned long len, const char *modname)
+{
+ FILE *f;
+ static const char defaultmod[] = "aim.exe";
+ char *filename = NULL;
+ struct stat st;
+ unsigned char *buf;
+ int invalid = 0;
+
+ if (!bufret || !buflenret)
+ return -1;
+
+ if (modname) {
+
+ if (!(filename = malloc(strlen(aimbinarypath)+1+strlen(modname)+4+1))) {
+ dperror("memrequest: malloc");
+ return -1;
+ }
+
+ sprintf(filename, "%s/%s.ocm", aimbinarypath, modname);
+
+ } else {
+
+ if (!(filename = malloc(strlen(aimbinarypath)+1+strlen(defaultmod)+1))) {
+ dperror("memrequest: malloc");
+ return -1;
+ }
+
+ sprintf(filename, "%s/%s", aimbinarypath, defaultmod);
+
+ }
+
+ if (stat(filename, &st) == -1) {
+ if (!modname) {
+ dperror("memrequest: stat");
+ free(filename);
+ return -1;
+ }
+ invalid = 1;
+ }
+
+ if (!invalid) {
+ if ((offset > st.st_size) || (len > st.st_size))
+ invalid = 1;
+ else if ((st.st_size - offset) < len)
+ len = st.st_size - offset;
+ else if ((st.st_size - len) < len)
+ len = st.st_size - len;
+ }
+
+ if (!invalid && len)
+ len %= 4096;
+
+ if (invalid) {
+ int i;
+
+ free(filename); /* not needed */
+
+ dvprintf("memrequest: recieved invalid request for 0x%08lx bytes at 0x%08lx (file %s)\n", len, offset, modname);
+
+ i = 8;
+ if (modname)
+ i += strlen(modname);
+
+ if (!(buf = malloc(i)))
+ return -1;
+
+ i = 0;
+
+ if (modname) {
+ memcpy(buf, modname, strlen(modname));
+ i += strlen(modname);
+ }
+
+ /* Damn endianness. This must be little (LSB first) endian. */
+ buf[i++] = offset & 0xff;
+ buf[i++] = (offset >> 8) & 0xff;
+ buf[i++] = (offset >> 16) & 0xff;
+ buf[i++] = (offset >> 24) & 0xff;
+ buf[i++] = len & 0xff;
+ buf[i++] = (len >> 8) & 0xff;
+ buf[i++] = (len >> 16) & 0xff;
+ buf[i++] = (len >> 24) & 0xff;
+
+ *bufret = buf;
+ *buflenret = i;
+
+ } else {
+
+ if (!(buf = malloc(len))) {
+ free(filename);
+ return -1;
+ }
+
+ dvprintf("memrequest: loading %ld bytes from 0x%08lx in \"%s\"...\n", len, offset, filename);
+
+ if (!(f = fopen(filename, "r"))) {
+ dperror("memrequest: fopen");
+ free(filename);
+ free(buf);
+ return -1;
+ }
+
+ free(filename);
+
+ if (fseek(f, offset, SEEK_SET) == -1) {
+ dperror("memrequest: fseek");
+ fclose(f);
+ free(buf);
+ return -1;
+ }
+
+ if (fread(buf, len, 1, f) != 1) {
+ dperror("memrequest: fread");
+ fclose(f);
+ free(buf);
+ return -1;
+ }
+
+ fclose(f);
+
+ *bufret = buf;
+ *buflenret = len;
+
+ }
+
+ return 0; /* success! */
+}
+
+/*
+ * This will get an offset and a length. The client should read this
+ * data out of whatever AIM.EXE binary the user has provided (hopefully
+ * it matches the client information thats sent at login) and pass a
+ * buffer back to libfaim so it can hash the data and send it to AOL for
+ * inspection by the client police.
+ */
+static int faimtest_memrequest(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ va_list ap;
+ unsigned long offset, len;
+ char *modname;
+ unsigned char *buf;
+ int buflen;
+
+ va_start(ap, command);
+ offset = va_arg(ap, unsigned long);
+ len = va_arg(ap, unsigned long);
+ modname = va_arg(ap, char *);
+ va_end(ap);
+
+ if (aimbinarypath && (getaimdata(&buf, &buflen, offset, len, modname) == 0)) {
+
+ aim_sendmemblock(sess, command->conn, offset, buflen, buf, AIM_SENDMEMBLOCK_FLAG_ISREQUEST);
+
+ free(buf);
+
+ } else {
+
+ dvprintf("memrequest: unable to use AIM binary (\"%s/%s\"), sending defaults...\n", aimbinarypath, modname);
+
+ aim_sendmemblock(sess, command->conn, offset, len, NULL, AIM_SENDMEMBLOCK_FLAG_ISREQUEST);
+
+ }
+
+ return 1;
+}
+
+static int faimtest_parse_authresp(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ va_list ap;
+ struct aim_conn_t *bosconn = NULL;
+ char *sn = NULL, *bosip = NULL, *errurl = NULL, *email = NULL;
+ unsigned char *cookie = NULL;
+ int errorcode = 0, regstatus = 0;
+ int latestbuild = 0, latestbetabuild = 0;
+ char *latestrelease = NULL, *latestbeta = NULL;
+ char *latestreleaseurl = NULL, *latestbetaurl = NULL;
+ char *latestreleaseinfo = NULL, *latestbetainfo = NULL;
+
+ va_start(ap, command);
+ sn = va_arg(ap, char *);
+ errorcode = va_arg(ap, int);
+ errurl = va_arg(ap, char *);
+ regstatus = va_arg(ap, int);
+ email = va_arg(ap, char *);
+ bosip = va_arg(ap, char *);
+ cookie = va_arg(ap, unsigned char *);
+
+ latestrelease = va_arg(ap, char *);
+ latestbuild = va_arg(ap, int);
+ latestreleaseurl = va_arg(ap, char *);
+ latestreleaseinfo = va_arg(ap, char *);
+
+ latestbeta = va_arg(ap, char *);
+ latestbetabuild = va_arg(ap, int);
+ latestbetaurl = va_arg(ap, char *);
+ latestbetainfo = va_arg(ap, char *);
+
+ va_end(ap);
+
+ dvprintf("Screen name: %s\n", sn);
+
+ /*
+ * Check for error.
+ */
+ if (errorcode || !bosip || !cookie) {
+ dvprintf("Login Error Code 0x%04x\n", errorcode);
+ dvprintf("Error URL: %s\n", errurl);
+ aim_conn_kill(sess, &command->conn);
+ return 1;
+ }
+
+ dvprintf("Reg status: %2d\n", regstatus);
+ dvprintf("Email: %s\n", email);
+ dvprintf("BOS IP: %s\n", bosip);
+
+ if (latestbeta)
+ dvprintf("Latest beta version: %s, build %d, at %s (more info at %s)\n", latestbeta, latestbetabuild, latestbetaurl, latestbetainfo);
+
+ if (latestrelease)
+ dvprintf("Latest released version: %s, build %d, at %s (more info at %s)\n", latestrelease, latestbuild, latestreleaseurl, latestreleaseinfo);
+
+ dprintf("Closing auth connection...\n");
+ aim_conn_kill(sess, &command->conn);
+ if (!(bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, bosip))) {
+ dprintf("faimtest: could not connect to BOS: internal error\n");
+ return 1;
+ } else if (bosconn->status & AIM_CONN_STATUS_CONNERR) {
+ dprintf("faimtest: could not connect to BOS\n");
+ aim_conn_kill(sess, &bosconn);
+ return 1;
+ }
+
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE, faimtest_conncomplete, 0);
+ aim_conn_addhandler(sess, bosconn, 0x0009, 0x0003, faimtest_bosrights, 0);
+ aim_conn_addhandler(sess, bosconn, 0x0001, 0x0007, faimtest_rateresp, 0); /* rate info */
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ACK, AIM_CB_ACK_ACK, NULL, 0);
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, 0x0018, faimtest_hostversions, 0);
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_SERVERREADY, faimtest_serverready, 0);
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATEINFO, NULL, 0);
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_REDIRECT, faimtest_handleredirect, 0);
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_STS, AIM_CB_STS_SETREPORTINTERVAL, faimtest_reportinterval, 0);
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_RIGHTSINFO, faimtest_parse_buddyrights, 0);
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING, faimtest_parse_oncoming, 0);
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING, faimtest_parse_offgoing, 0);
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_INCOMING, faimtest_parse_incoming_im, 0);
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_ERROR, faimtest_parse_locerr, 0);
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_MISSEDCALL, faimtest_parse_misses, 0);
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATECHANGE, faimtest_parse_ratechange, 0);
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_EVIL, faimtest_parse_evilnotify, 0);
+ aim_conn_addhandler(sess, bosconn, 0x000a, 0x0001, faimtest_parse_searcherror, 0);
+ aim_conn_addhandler(sess, bosconn, 0x000a, 0x0003, faimtest_parse_searchreply, 0);
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ERROR, faimtest_parse_msgerr, 0);
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO, faimtest_parse_userinfo, 0);
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_RIGHTSINFO, faimtest_locrights, 0);
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ACK, faimtest_parse_msgack, 0);
+
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, faimtest_parse_motd, 0);
+
+ aim_conn_addhandler(sess, bosconn, 0x0004, 0x0005, faimtest_icbmparaminfo, 0);
+ aim_conn_addhandler(sess, bosconn, 0x0001, 0x0001, faimtest_parse_genericerr, 0);
+ aim_conn_addhandler(sess, bosconn, 0x0003, 0x0001, faimtest_parse_genericerr, 0);
+ aim_conn_addhandler(sess, bosconn, 0x0009, 0x0001, faimtest_parse_genericerr, 0);
+
+ aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR, faimtest_parse_connerr, 0);
+ aim_conn_addhandler(sess, bosconn, 0x0001, 0x001f, faimtest_memrequest, 0);
+ aim_conn_addhandler(sess, bosconn, 0xffff, 0xffff, faimtest_parse_unknown, 0);
+
+ aim_auth_sendcookie(sess, bosconn, cookie);
+
+ return 1;
+}
+
+static void printuserflags(unsigned short flags)
+{
+ if (flags & AIM_FLAG_UNCONFIRMED)
+ dinlineprintf("UNCONFIRMED ");
+ if (flags & AIM_FLAG_ADMINISTRATOR)
+ dinlineprintf("ADMINISTRATOR ");
+ if (flags & AIM_FLAG_AOL)
+ dinlineprintf("AOL ");
+ if (flags & AIM_FLAG_OSCAR_PAY)
+ dinlineprintf("OSCAR_PAY ");
+ if (flags & AIM_FLAG_FREE)
+ dinlineprintf("FREE ");
+ if (flags & AIM_FLAG_AWAY)
+ dinlineprintf("AWAY ");
+ if (flags & AIM_FLAG_UNKNOWN40)
+ dinlineprintf("ICQ? ");
+ if (flags & AIM_FLAG_UNKNOWN80)
+ dinlineprintf("UNKNOWN80 ");
+ return;
+}
+
+int faimtest_parse_userinfo(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ struct aim_userinfo_s *userinfo;
+ char *prof_encoding = NULL;
+ char *prof = NULL;
+ unsigned short inforeq = 0;
+
+ va_list ap;
+ va_start(ap, command);
+ userinfo = va_arg(ap, struct aim_userinfo_s *);
+ prof_encoding = va_arg(ap, char *);
+ prof = va_arg(ap, char *);
+ inforeq = va_arg(ap, int);
+ va_end(ap);
+
+ dvprintf("faimtest: userinfo: sn: %s\n", userinfo->sn);
+ dvprintf("faimtest: userinfo: warnlevel: 0x%04x\n", userinfo->warnlevel);
+ dvprintf("faimtest: userinfo: flags: 0x%04x = ", userinfo->flags);
+ printuserflags(userinfo->flags);
+ dinlineprintf("\n");
+
+ dvprintf("faimtest: userinfo: membersince: %lu\n", userinfo->membersince);
+ dvprintf("faimtest: userinfo: onlinesince: %lu\n", userinfo->onlinesince);
+ dvprintf("faimtest: userinfo: idletime: 0x%04x\n", userinfo->idletime);
+
+ if (inforeq == AIM_GETINFO_GENERALINFO) {
+ dvprintf("faimtest: userinfo: profile_encoding: %s\n", prof_encoding ? prof_encoding : "[none]");
+ dvprintf("faimtest: userinfo: prof: %s\n", prof ? prof : "[none]");
+ } else if (inforeq == AIM_GETINFO_AWAYMESSAGE) {
+ dvprintf("faimtest: userinfo: awaymsg_encoding: %s\n", prof_encoding ? prof_encoding : "[none]");
+ dvprintf("faimtest: userinfo: awaymsg: %s\n", prof ? prof : "[none]");
+ } else
+ dprintf("faimtest: userinfo: unknown info request\n");
+
+ return 1;
+}
+
+static int faimtest_handlecmd(struct aim_session_t *sess, struct command_rx_struct *command, struct aim_userinfo_s *userinfo, char *tmpstr)
+{
+
+ if (!strncmp(tmpstr, "disconnect", 10)) {
+
+ logout();
+
+ } else if (strstr(tmpstr, "goodday")) {
+
+ aim_send_im(sess, command->conn, userinfo->sn, AIM_IMFLAGS_ACK, "Good day to you too.");
+
+ } else if (strstr(tmpstr, "haveicon") && buddyicon) {
+ struct aim_sendimext_args args;
+ static const char iconmsg[] = {"I have an icon"};
+
+ args.destsn = userinfo->sn;
+ args.flags = AIM_IMFLAGS_HASICON;
+ args.msg = iconmsg;
+ args.msglen = strlen(iconmsg);
+ args.iconlen = buddyiconlen;
+ args.iconstamp = buddyiconstamp;
+ args.iconsum = buddyiconsum;
+
+ aim_send_im_ext(sess, command->conn, &args);
+
+ } else if (strstr(tmpstr, "sendicon") && buddyicon) {
+
+ aim_send_icon(sess, command->conn, userinfo->sn, buddyicon, buddyiconlen, buddyiconstamp, buddyiconsum);
+
+ } else if (strstr(tmpstr, "warnme")) {
+
+ dprintf("faimtest: icbm: sending non-anon warning\n");
+ aim_send_warning(sess, command->conn, userinfo->sn, 0);
+
+ } else if (strstr(tmpstr, "anonwarn")) {
+
+ dprintf("faimtest: icbm: sending anon warning\n");
+ aim_send_warning(sess, command->conn, userinfo->sn, AIM_WARN_ANON);
+
+ } else if (strstr(tmpstr, "setdirectoryinfo")) {
+
+ dprintf("faimtest: icbm: sending backwards profile data\n");
+ aim_setdirectoryinfo(sess, command->conn, "tsrif", "elddim", "tsal", "nediam", "emankcin", "teerts", "ytic", "etats", "piz", 0, 1);
+
+ } else if (strstr(tmpstr, "setinterests")) {
+
+ dprintf("faimtest: icbm: setting fun interests\n");
+ aim_setuserinterests(sess, command->conn, "interest1", "interest2", "interest3", "interest4", "interest5", 1);
+
+ } else if (!strncmp(tmpstr, "getfile", 7)) {
+
+ if (!ohcaptainmycaptain) {
+
+ aim_send_im(sess, command->conn, userinfo->sn, AIM_IMFLAGS_ACK, "I have no owner!");
+
+ } else {
+ struct aim_conn_t *newconn;
+
+ newconn = aim_getfile_initiate(sess, command->conn, (strlen(tmpstr) < 8)?ohcaptainmycaptain:tmpstr+8);
+ dvprintf("faimtest: getting file listing from %s\n", (strlen(tmpstr) < 8)?ohcaptainmycaptain:tmpstr+8);
+ aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEINITIATE, faimtest_getfile_initiate,0);
+ }
+
+ } else if (!strncmp(tmpstr, "open chatnav", 12)) {
+
+ aim_bos_reqservice(sess, command->conn, AIM_CONN_TYPE_CHATNAV);
+
+ } else if (!strncmp(tmpstr, "create", 6)) {
+
+ aim_chatnav_createroom(sess,aim_getconn_type(sess, AIM_CONN_TYPE_CHATNAV), (strlen(tmpstr) < 7)?"WorldDomination":tmpstr+7, 0x0004);
+
+ } else if (!strncmp(tmpstr, "close chatnav", 13)) {
+ struct aim_conn_t *chatnavconn;
+
+ chatnavconn = aim_getconn_type(sess, AIM_CONN_TYPE_CHATNAV);
+ aim_conn_kill(sess, &chatnavconn);
+
+ } else if (!strncmp(tmpstr, "join", 4)) {
+
+ aim_chat_join(sess, command->conn, 0x0004, "worlddomination");
+
+ } else if (!strncmp(tmpstr, "leave", 5)) {
+
+ aim_chat_leaveroom(sess, "worlddomination");
+
+ } else if (!strncmp(tmpstr, "getinfo", 7)) {
+
+ aim_getinfo(sess, command->conn, "75784102", AIM_GETINFO_GENERALINFO);
+ aim_getinfo(sess, command->conn, "15853637", AIM_GETINFO_AWAYMESSAGE);
+ aim_getinfo(sess, command->conn, "midendian", AIM_GETINFO_GENERALINFO);
+ aim_getinfo(sess, command->conn, "midendian", AIM_GETINFO_AWAYMESSAGE);
+
+ } else if (!strncmp(tmpstr, "open directim", 13)) {
+ struct aim_conn_t *newconn;
+
+ printf("faimtest: opening directim to %s\n", (strlen(tmpstr) < 14)?userinfo->sn:tmpstr+14);
+ newconn = aim_directim_initiate(sess, command->conn, NULL, (strlen(tmpstr) < 14)?userinfo->sn:tmpstr+14);
+ if(!newconn || newconn->fd == -1)
+ printf("connection failed!\n");
+ aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE, faimtest_directim_initiate,0);
+
+ } else if(!(strncmp(tmpstr, "lookup", 6))) {
+
+ aim_usersearch_address(sess, command->conn, tmpstr+7);
+
+ } else if (!strncmp(tmpstr, "reqsendmsg", 10)) {
+
+ aim_send_im(sess, command->conn, ohcaptainmycaptain, 0, "sendmsg 7900");
+
+ } else if (!strncmp(tmpstr, "reqauth", 7)) {
+
+ aim_bos_reqservice(sess, command->conn, AIM_CONN_TYPE_AUTH);
+
+ } else if (!strncmp(tmpstr, "reqconfirm", 10)) {
+
+ aim_auth_reqconfirm(sess, aim_getconn_type(sess, AIM_CONN_TYPE_AUTH));
+
+ } else if (!strncmp(tmpstr, "reqemail", 8)) {
+
+ aim_auth_getinfo(sess, aim_getconn_type(sess, AIM_CONN_TYPE_AUTH), 0x0011);
+
+ } else if (!strncmp(tmpstr, "changepass", 8)) {
+
+ aim_auth_changepasswd(sess, aim_getconn_type(sess, AIM_CONN_TYPE_AUTH), "NEWPASSWORD", "OLDPASSWORD");
+
+ } else if (!strncmp(tmpstr, "setemail", 8)) {
+
+ aim_auth_setemail(sess, aim_getconn_type(sess, AIM_CONN_TYPE_AUTH), "NEWEMAILADDRESS");
+
+ } else if (!strncmp(tmpstr, "sendmsg", 7)) {
+ int i;
+ i = atoi(tmpstr+8);
+ if (i < 10000) {
+ char *newbuf;
+ int z;
+
+ newbuf = malloc(i+1);
+ for (z = 0; z < i; z++) {
+ newbuf[z] = (z % 10)+0x30;
+ }
+ newbuf[i] = '\0';
+ aim_send_im(sess, command->conn, userinfo->sn, 0, newbuf);
+ free(newbuf);
+ }
+
+ } else {
+
+ dprintf("unknown command.\n");
+ aim_add_buddy(sess, command->conn, userinfo->sn);
+
+ }
+
+ return 0;
+}
+
+/*
+ * The user-level Incoming ICBM callback.
+ *
+ */
+int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ int channel;
+ struct aim_userinfo_s *userinfo;
+ va_list ap;
+
+ va_start(ap, command);
+ channel = va_arg(ap, int);
+ userinfo = va_arg(ap, struct aim_userinfo_s *);
+
+ /*
+ * Channel 1: Standard Message
+ */
+ if (channel == 1) {
+ char *tmpstr;
+ struct aim_incomingim_ch1_args *args;
+ int clienttype = AIM_CLIENTTYPE_UNKNOWN;
+ char realmsg[8192+1] = {""};
+
+ args = va_arg(ap, struct aim_incomingim_ch1_args *);
+ va_end(ap);
+
+ clienttype = aim_fingerprintclient(args->fingerprint, args->finlen);
+
+ dvprintf("faimtest: icbm: sn = \"%s\"\n", userinfo->sn);
+ dvprintf("faimtest: icbm: probable client type: %d\n", clienttype);
+ dvprintf("faimtest: icbm: warnlevel = 0x%04x\n", userinfo->warnlevel);
+ dvprintf("faimtest: icbm: flags = 0x%04x = ", userinfo->flags);
+ printuserflags(userinfo->flags);
+ dinlineprintf("\n");
+
+ dvprintf("faimtest: icbm: membersince = %lu\n", userinfo->membersince);
+ dvprintf("faimtest: icbm: onlinesince = %lu\n", userinfo->onlinesince);
+ dvprintf("faimtest: icbm: idletime = 0x%04x\n", userinfo->idletime);
+ dvprintf("faimtest: icbm: capabilities = 0x%04x\n", userinfo->capabilities);
+
+ dprintf("faimtest: icbm: icbmflags = ");
+ if (args->icbmflags & AIM_IMFLAGS_AWAY)
+ dinlineprintf("away ");
+ if (args->icbmflags & AIM_IMFLAGS_ACK)
+ dinlineprintf("ackrequest ");
+ if (args->icbmflags & AIM_IMFLAGS_BUDDYREQ)
+ dinlineprintf("buddyreq ");
+ if (args->icbmflags & AIM_IMFLAGS_HASICON)
+ dinlineprintf("hasicon ");
+ dinlineprintf("\n");
+
+ dvprintf("faimtest: icbm: encoding flags = {%04x, %04x}\n", args->flag1, args->flag2);
+
+ /*
+ * Quickly convert it to eight bit format, replacing non-ASCII UNICODE
+ * characters with their equivelent HTML entity.
+ */
+ if (args->icbmflags & AIM_IMFLAGS_UNICODE) {
+ int i;
+
+ for (i = 0; i < args->msglen; i += 2) {
+ unsigned short uni;
+
+ uni = ((args->msg[i] & 0xff) << 8) | (args->msg[i+1] & 0xff);
+
+ if ((uni < 128) || ((uni >= 160) && (uni <= 255))) { /* ISO 8859-1 */
+
+ snprintf(realmsg+strlen(realmsg), sizeof(realmsg)-strlen(realmsg),
+ "%c", uni);
+
+ } else { /* something else, do UNICODE entity */
+
+ snprintf(realmsg+strlen(realmsg), sizeof(realmsg)-strlen(realmsg),
+ "&#%04x;", uni);
+
+ }
+
+ }
+
+ } else {
+
+ /*
+ * For non-UNICODE encodings (ASCII and ISO 8859-1), there is no
+ * need to do anything special here. Most terminals/whatever will
+ * be able to display such characters unmodified.
+ *
+ * Beware that PC-ASCII 128 through 159 are _not_ actually defined in
+ * ASCII or ISO 8859-1, and you should send them as UNICODE. WinAIM
+ * will send these characters in a UNICODE message, so you need
+ * to do so as well.
+ *
+ * You may not think it necessary to handle UNICODE messages. You're
+ * probably wrong. For one thing, Microsoft "Smart Quotes" will
+ * be sent by WinAIM as UNICODE (not HTML UNICODE, but real UNICODE).
+ * If you don't parse UNICODE at all, your users will get a blank
+ * message instead of the message containing Smart Quotes.
+ *
+ */
+ strncpy(realmsg, args->msg, sizeof(realmsg));
+ }
+
+ dvprintf("faimtest: icbm: message: %s\n", realmsg);
+
+ if (args->icbmflags & AIM_IMFLAGS_HASICON)
+ aim_send_im(sess, command->conn, userinfo->sn, AIM_IMFLAGS_BUDDYREQ, "You have an icon");
+
+ if (realmsg) {
+ int i = 0;
+
+ while (realmsg[i] == '<') {
+ if (realmsg[i] == '<') {
+ while (realmsg[i] != '>')
+ i++;
+ i++;
+ }
+ }
+ tmpstr = realmsg+i;
+
+ faimtest_handlecmd(sess, command, userinfo, tmpstr);
+
+ }
+ }
+ /*
+ * Channel 2: Rendevous Request
+ */
+ else if (channel == 2) {
+ struct aim_incomingim_ch2_args *args;
+
+ args = va_arg(ap, struct aim_incomingim_ch2_args *);
+ va_end(ap);
+
+ switch (args->reqclass) {
+ case AIM_CAPS_VOICE: {
+
+ dvprintf("faimtest: voice invitation: source sn = %s\n", userinfo->sn);
+ dvprintf("faimtest: voice invitation: \twarnlevel = 0x%04x\n", userinfo->warnlevel);
+ dvprintf("faimtest: voice invitation: \tclass = 0x%04x = ", userinfo->flags);
+ printuserflags(userinfo->flags);
+ dinlineprintf("\n");
+
+ /* we dont get membersince on chat invites! */
+ dvprintf("faimtest: voice invitation: \tonlinesince = %lu\n", userinfo->onlinesince);
+ dvprintf("faimtest: voice invitation: \tidletime = 0x%04x\n", userinfo->idletime);
+
+ break;
+ }
+ case AIM_CAPS_GETFILE: {
+ struct aim_conn_t *newconn;
+ struct aim_fileheader_t *fh;
+
+ dvprintf("faimtest: get file request from %s (at %s) %x\n", userinfo->sn, args->info.getfile.ip, args->reqclass);
+
+ fh = aim_getlisting(sess, listingfile);
+
+ 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);
+
+ if ( (!newconn) || (newconn->fd == -1) ) {
+ dprintf("faimtest: getfile: requestconn: apparent error in accepttransfer\n");
+ if(newconn)
+ aim_conn_kill(sess, &newconn);
+ break;
+ }
+
+ free(fh);
+
+ aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILELISTINGREQ, faimtest_getfile_listingreq, 0);
+ aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILEREQ, faimtest_getfile_filereq, 0);
+ aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEFILESEND, faimtest_getfile_filesend, 0);
+ aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILECOMPLETE, faimtest_getfile_complete, 0);
+
+ aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_GETFILEDISCONNECT, faimtest_getfile_disconnect, 0);
+
+ dprintf("faimtest: getfile connect succeeded, handlers added.\n");
+
+ break;
+ }
+ case AIM_CAPS_SENDFILE: {
+ dprintf("faimtest: send file!\n");
+ break;
+ }
+ case AIM_CAPS_CHAT: {
+
+ dvprintf("faimtest: chat invitation: source sn = %s\n", userinfo->sn);
+ dvprintf("faimtest: chat invitation: \twarnlevel = 0x%04x\n", userinfo->warnlevel);
+ dvprintf("faimtest: chat invitation: \tclass = 0x%04x = ", userinfo->flags);
+ printuserflags(userinfo->flags);
+ dinlineprintf("\n");
+
+ /* we dont get membersince on chat invites! */
+ dvprintf("faimtest: chat invitation: \tonlinesince = %lu\n", userinfo->onlinesince);
+ dvprintf("faimtest: chat invitation: \tidletime = 0x%04x\n", userinfo->idletime);
+
+ dvprintf("faimtest: chat invitation: message = %s\n", args->info.chat.msg);
+ dvprintf("faimtest: chat invitation: room name = %s\n", args->info.chat.roominfo.name);
+ dvprintf("faimtest: chat invitation: encoding = %s\n", args->info.chat.encoding);
+ dvprintf("faimtest: chat invitation: language = %s\n", args->info.chat.lang);
+ dvprintf("faimtest: chat invitation: exchange = 0x%04x\n", args->info.chat.roominfo.exchange);
+ dvprintf("faimtest: chat invitation: instance = 0x%04x\n", args->info.chat.roominfo.instance);
+ dvprintf("faimtest: chat invitiation: autojoining %s...\n", args->info.chat.roominfo.name);
+
+ /*
+ * Automatically join room...
+ */
+ aim_chat_join(sess, command->conn, args->info.chat.roominfo.exchange, args->info.chat.roominfo.name);
+ break;
+ }
+ case AIM_CAPS_IMIMAGE: {
+ struct aim_conn_t *newconn;
+
+ dprintf("faimtest: icbm: rendezvous imimage\n");
+
+ dvprintf("faimtest: OFT: DirectIM: request from %s (%s)\n", userinfo->sn, args->info.directim->ip);
+
+ newconn = aim_directim_connect(sess, command->conn, args->info.directim);
+
+ if ( (!newconn) || (newconn->fd == -1) ) {
+ dprintf("faimtest: icbm: imimage: could not connect\n");
+
+ if (newconn)
+ aim_conn_kill(sess, &newconn);
+
+ break;
+ }
+
+ aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, faimtest_directim_incoming, 0);
+ aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT, faimtest_directim_disconnect, 0);
+ aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, faimtest_directim_typing, 0);
+
+ dvprintf("faimtest: OFT: DirectIM: connected to %s\n", userinfo->sn);
+
+ aim_send_im_direct(sess, newconn, "goodday");
+
+ break;
+ }
+ case AIM_CAPS_BUDDYICON: {
+
+ dvprintf("faimtest: Buddy Icon from %s, length = %u\n", userinfo->sn, args->info.icon.length);
+ break;
+ }
+ default:
+ dvprintf("faimtest: icbm: unknown reqclass (%d)\n", args->reqclass);
+ } /* switch */
+ } else
+ dvprintf("faimtest does not support channels > 2 (chan = %02x)\n", channel);
+
+ dprintf("faimtest: icbm: done with ICBM handling\n");
+
+ return 1;
+}
+
+int faimtest_directim_initiate(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ va_list ap;
+ struct aim_directim_priv *priv;
+ struct aim_conn_t *newconn, *listenerconn;
+
+ va_start(ap, command);
+ newconn = va_arg(ap, struct aim_conn_t *);
+ listenerconn = va_arg(ap, struct aim_conn_t *);
+ va_end(ap);
+
+ aim_conn_close(listenerconn);
+ aim_conn_kill(sess, &listenerconn);
+
+ priv = (struct aim_directim_priv *)newconn->priv;
+
+ dvprintf("faimtest: OFT: DirectIM: intitiate success to %s\n", priv->ip);
+
+ aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, faimtest_directim_incoming, 0);
+ aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT, faimtest_directim_disconnect, 0);
+ aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, faimtest_directim_typing, 0);
+
+ aim_send_im_direct(sess, newconn, "goodday");
+
+ dvprintf("faimtest: OFT: DirectIM: connected to %s\n", priv->sn);
+
+ return 1;
+}
+
+int faimtest_directim_connect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ va_list ap;
+ struct aim_directim_priv *priv;
+
+ va_start(ap, command);
+ priv = va_arg(ap, struct aim_directim_priv *);
+
+ va_end(ap);
+
+ dprintf("faimtest: directim_connect\n");
+
+ return 1;
+}
+
+int faimtest_directim_incoming(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ va_list ap;
+ char *msg = NULL;
+ struct aim_conn_t *conn;
+ struct aim_directim_priv *priv;
+
+ va_start(ap, command);
+ conn = va_arg(ap, struct aim_conn_t *);
+ msg = va_arg(ap, char *);
+ va_end(ap);
+
+ if(!(priv = conn->priv)) {
+ dvprintf("faimtest: directim: no private struct on conn with fd %d\n", conn->fd);
+ return -1;
+ }
+
+ dvprintf("faimtest: Directim from %s: %s\n", priv->sn, msg);
+ if (!strncmp(msg, "sendmsg", 7)) {
+ int i;
+ i = atoi(msg+8);
+ if (i < 10000) {
+ char *newbuf;
+ int z;
+
+ newbuf = malloc(i+1);
+ for (z = 0; z < i; z++) {
+ newbuf[z] = (z % 10)+0x30;
+ }
+ newbuf[i] = '\0';
+ aim_send_im_direct(sess, conn, newbuf);
+ free(newbuf);
+ }
+ } else if (!strncmp(msg, "goodday", 7)) {
+ aim_send_im_direct(sess, conn, "Good day to you, too");
+ } else {
+ char newmsg[1024];
+ snprintf(newmsg, sizeof(newmsg), "unknown (%s)\n", msg);
+ aim_send_im_direct(sess, conn, newmsg);
+ }
+ return 1;
+}
+
+int faimtest_directim_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ va_list ap;
+ struct aim_conn_t *conn;
+ char *sn;
+
+ va_start(ap, command);
+ conn = va_arg(ap, struct aim_conn_t *);
+ sn = va_arg(ap, char *);
+ va_end(ap);
+
+ dvprintf("faimtest: directim: disconnected from %s\n", sn);
+
+ aim_conn_kill(sess, &conn);
+ return 1;
+}
+
+int faimtest_directim_typing(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ va_list ap;
+ struct aim_conn_t *conn;
+ struct aim_directim_priv *priv;
+
+ va_start(ap, command);
+ conn = va_arg(ap, struct aim_conn_t *);
+ va_end(ap);
+
+ if(!(priv = (struct aim_directim_priv *)conn->priv)) {
+ dvprintf("faimtest: no private struct on conn with fd %d!\n", conn->fd);
+ return -1;
+ }
+
+ dvprintf("faimtest: ohmigod! %s has started typing (DirectIM). He's going to send you a message! *squeal*\n", priv->sn);
+ return 1;
+}
+
+int faimtest_infochange(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ unsigned short change = 0;
+ int perms, type, length, str;
+ char *val;
+ va_list ap;
+
+ va_start(ap, command);
+ perms = va_arg(ap, int);
+ type = va_arg(ap, int);
+ length = va_arg(ap, int);
+ val = va_arg(ap, char *);
+ str = va_arg(ap, int);
+ va_end(ap);
+
+ if (aimutil_get16(command->data+2) == 0x0005)
+ change = 1;
+
+ dvprintf("info%s: perms = %d, type = %x, length = %d, val = %s\n", change?" change":"", perms, type, length, str?val:"(not string)");
+
+ return 1;
+}
+
+int faimtest_parse_oncoming(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ struct aim_userinfo_s *userinfo;
+
+ va_list ap;
+ va_start(ap, command);
+ userinfo = va_arg(ap, struct aim_userinfo_s *);
+ va_end(ap);
+
+ dvprintf("%ld %s is now online (flags: %04x = %s%s%s%s%s%s%s%s) (caps = 0x%04x)\n",
+ time(NULL),
+ userinfo->sn, userinfo->flags,
+ (userinfo->flags&AIM_FLAG_UNCONFIRMED)?" UNCONFIRMED":"",
+ (userinfo->flags&AIM_FLAG_ADMINISTRATOR)?" ADMINISTRATOR":"",
+ (userinfo->flags&AIM_FLAG_AOL)?" AOL":"",
+ (userinfo->flags&AIM_FLAG_OSCAR_PAY)?" OSCAR_PAY":"",
+ (userinfo->flags&AIM_FLAG_FREE)?" FREE":"",
+ (userinfo->flags&AIM_FLAG_AWAY)?" AWAY":"",
+ (userinfo->flags&AIM_FLAG_UNKNOWN40)?" UNKNOWN40":"",
+ (userinfo->flags&AIM_FLAG_UNKNOWN80)?" UNKNOWN80":"",
+ userinfo->capabilities);
+ return 1;
+}
+
+int faimtest_parse_offgoing(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ struct aim_userinfo_s *userinfo;
+
+ va_list ap;
+ va_start(ap, command);
+ userinfo = va_arg(ap, struct aim_userinfo_s *);
+ va_end(ap);
+
+ dvprintf("%ld %s is now offline (flags: %04x = %s%s%s%s%s%s%s%s) (caps = 0x%04x)\n",
+ time(NULL),
+ userinfo->sn, userinfo->flags,
+ (userinfo->flags&AIM_FLAG_UNCONFIRMED)?" UNCONFIRMED":"",
+ (userinfo->flags&AIM_FLAG_ADMINISTRATOR)?" ADMINISTRATOR":"",
+ (userinfo->flags&AIM_FLAG_AOL)?" AOL":"",
+ (userinfo->flags&AIM_FLAG_OSCAR_PAY)?" OSCAR_PAY":"",
+ (userinfo->flags&AIM_FLAG_FREE)?" FREE":"",
+ (userinfo->flags&AIM_FLAG_AWAY)?" AWAY":"",
+ (userinfo->flags&AIM_FLAG_UNKNOWN40)?" UNKNOWN40":"",
+ (userinfo->flags&AIM_FLAG_UNKNOWN80)?" UNKNOWN80":"",
+ userinfo->capabilities);
+ return 1;
+}
+
+int faimtest_parse_motd(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ static char *codes[] = {
+ "Unknown",
+ "Mandatory upgrade",
+ "Advisory upgrade",
+ "System bulletin",
+ "Top o' the world!"
+ };
+ static int codeslen = 5;
+ char *msg;
+ unsigned short id;
+ va_list ap;
+
+ va_start(ap, command);
+ id = va_arg(ap, int);
+ msg = va_arg(ap, char *);
+ va_end(ap);
+
+ dvprintf("faimtest: motd: %s (%d / %s)\n", msg, id, (id < codeslen)?codes[id]:"unknown");
+
+ return 1;
+}
+
+int faimtest_parse_genericerr(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ va_list ap;
+ unsigned short reason;
+
+ va_start(ap, command);
+ reason = va_arg(ap, int);
+ va_end(ap);
+
+ dvprintf("faimtest: snac threw error (reason 0x%04x: %s)\n", reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown");
+
+ return 1;
+}
+
+int faimtest_parse_msgerr(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ va_list ap;
+ char *destsn;
+ unsigned short reason;
+
+ va_start(ap, command);
+ reason = va_arg(ap, int);
+ destsn = va_arg(ap, char *);
+ va_end(ap);
+
+ dvprintf("faimtest: message to %s bounced (reason 0x%04x: %s)\n", destsn, reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown");
+
+ return 1;
+}
+
+int faimtest_parse_locerr(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ va_list ap;
+ char *destsn;
+ unsigned short reason;
+
+ va_start(ap, command);
+ reason = va_arg(ap, int);
+ destsn = va_arg(ap, char *);
+ va_end(ap);
+
+ dvprintf("faimtest: user information for %s unavailable (reason 0x%04x: %s)\n", destsn, reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown");
+
+ return 1;
+}
+
+/*
+ * Handles callbacks for AIM_CB_MISSED_CALL.
+ */
+int faimtest_parse_misses(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ static char *missedreasons[] = {
+ "Invalid (0)",
+ "Message too large",
+ "Rate exceeded",
+ "Evil Sender",
+ "Evil Receiver"
+ };
+ static int missedreasonslen = 5;
+
+ va_list ap;
+ unsigned short chan, nummissed, reason;
+ struct aim_userinfo_s *userinfo;
+
+ va_start(ap, command);
+ chan = va_arg(ap, int);
+ userinfo = va_arg(ap, struct aim_userinfo_s *);
+ nummissed = va_arg(ap, int);
+ reason = va_arg(ap, int);
+ va_end(ap);
+
+ dvprintf("faimtest: missed %d messages from %s (reason %d: %s)\n", nummissed, userinfo->sn, reason, (reason<missedreasonslen)?missedreasons[reason]:"unknown");
+
+ return 1;
+}
+
+int faimtest_parse_login(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ struct client_info_s info = AIM_CLIENTINFO_KNOWNGOOD;
+ char *key;
+ va_list ap;
+
+ va_start(ap, command);
+ key = va_arg(ap, char *);
+ va_end(ap);
+
+ aim_send_login(sess, command->conn, screenname, password, &info, key);
+
+ return 1;
+}
+
+int faimtest_chat_join(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+ va_list ap;
+ struct aim_userinfo_s *userinfo;
+ int count = 0, i = 0;
+
+ va_start(ap, command);
+ count = va_arg(ap, int);
+ userinfo = va_arg(ap, struct aim_userinfo_s *);
+ va_end(ap);