X-Git-Url: http://andersk.mit.edu/gitweb/libfaim.git/blobdiff_plain/b1eac25ac75949707e082afcb8e0d702e536cef1..d2698e035898b59fdff9e49da05904152cdedd03:/utils/faimtest/faimtest.c diff --git a/utils/faimtest/faimtest.c b/utils/faimtest/faimtest.c index 35ca6a2..f01d265 100644 --- a/utils/faimtest/faimtest.c +++ b/utils/faimtest/faimtest.c @@ -260,7 +260,7 @@ int logout(void) { if (ohcaptainmycaptain) - aim_send_im(&aimsess, aim_getconn_type(&aimsess, AIM_CONN_TYPE_BOS), ohcaptainmycaptain, 0, "ta ta..."); + aim_send_im(&aimsess, aim_getconn_type(&aimsess, AIM_CONN_TYPE_BOS), ohcaptainmycaptain, 0, "ta ta...", strlen("ta ta...")); aim_session_kill(&aimsess); @@ -797,25 +797,56 @@ int faimtest_handleredirect(struct aim_session_t *sess, struct command_rx_struct return 1; } -static int getaimdata(unsigned char *buf, int buflen, unsigned long offset) +static int getaimdata(unsigned char *buf, int buflen, unsigned long offset, const char *modname) { FILE *f; + static const char defaultmod[] = "aim.exe"; + char *filename = NULL; + + memset(buf, 0, buflen); + + 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 (!(f = fopen(aimbinarypath, "r"))) { - dperror("memrequest: fopen"); - return -1; } - if (fseek(f, offset, SEEK_SET) == -1) { - dperror("memrequest: fseek"); - fclose(f); + dvprintf("memrequest: loading %d bytes from 0x%08lx in \"%s\"...\n", buflen, offset, filename); + + if (!(f = fopen(filename, "r"))) { + dperror("memrequest: fopen"); + free(filename); return -1; } - if (fread(buf, buflen, 1, f) != 1) { - dperror("memrequest: fread"); - fclose(f); - return -1; + free(filename); + + if (buflen) { + if (fseek(f, offset, SEEK_SET) == -1) { + dperror("memrequest: fseek"); + fclose(f); + return -1; + } + + if (fread(buf, buflen, 1, f) != 1) { + dperror("memrequest: fread"); + fclose(f); + return -1; + } } fclose(f); @@ -835,10 +866,12 @@ static int faimtest_memrequest(struct aim_session_t *sess, struct command_rx_str va_list ap; unsigned long offset, len; unsigned char *buf; + char *modname; 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 (!(buf = malloc(len))) { @@ -846,17 +879,15 @@ static int faimtest_memrequest(struct aim_session_t *sess, struct command_rx_str return 0; } - if (aimbinarypath && (getaimdata(buf, len, offset) == len)) { - - dvprintf("memrequest: sending %ld bytes from 0x%08lx in %s...\n", len, offset, aimbinarypath); + if (aimbinarypath && (getaimdata(buf, len, offset, modname) == len)) { - aim_sendmemblock(sess, command->conn, offset, len, buf); + aim_sendmemblock(sess, command->conn, offset, len, buf, AIM_SENDMEMBLOCK_FLAG_ISREQUEST); } else { - dprintf("memrequest: unable to use AIM binary, sending defaults...\n"); + dvprintf("memrequest: unable to use AIM binary (\"%s/%s\"), sending defaults...\n", aimbinarypath, modname); - aim_sendmemblock(sess, command->conn, offset, len, NULL); + aim_sendmemblock(sess, command->conn, offset, len, NULL, AIM_SENDMEMBLOCK_FLAG_ISREQUEST); } @@ -1037,7 +1068,7 @@ static int faimtest_handlecmd(struct aim_session_t *sess, struct command_rx_stru } else if (strstr(tmpstr, "goodday")) { - aim_send_im(sess, command->conn, userinfo->sn, AIM_IMFLAGS_ACK, "Good day to you too."); + aim_send_im(sess, command->conn, userinfo->sn, AIM_IMFLAGS_ACK, "Good day to you too.", strlen("Good day to you too.")); } else if (strstr(tmpstr, "warnme")) { @@ -1063,7 +1094,7 @@ static int faimtest_handlecmd(struct aim_session_t *sess, struct command_rx_stru if (!ohcaptainmycaptain) { - aim_send_im(sess, command->conn, userinfo->sn, AIM_IMFLAGS_ACK, "I have no owner!"); + aim_send_im(sess, command->conn, userinfo->sn, AIM_IMFLAGS_ACK, "I have no owner!", strlen("I have no owner!")); } else { struct aim_conn_t *newconn; @@ -1117,7 +1148,7 @@ static int faimtest_handlecmd(struct aim_session_t *sess, struct command_rx_stru } else if (!strncmp(tmpstr, "reqsendmsg", 10)) { - aim_send_im(sess, command->conn, ohcaptainmycaptain, 0, "sendmsg 7900"); + aim_send_im(sess, command->conn, ohcaptainmycaptain, 0, "sendmsg 7900", strlen("sendmsg 7900")); } else if (!strncmp(tmpstr, "reqauth", 7)) { @@ -1151,7 +1182,7 @@ static int faimtest_handlecmd(struct aim_session_t *sess, struct command_rx_stru newbuf[z] = (z % 10)+0x30; } newbuf[i] = '\0'; - aim_send_im(sess, command->conn, userinfo->sn, 0, newbuf); + aim_send_im(sess, command->conn, userinfo->sn, 0, newbuf, strlen(newbuf)); free(newbuf); } @@ -1803,7 +1834,7 @@ int faimtest_chat_incomingmsg(struct aim_session_t *sess, struct command_rx_stru if (strcmp(userinfo->sn, sess->sn) != 0) { sprintf(tmpbuf, "(%s said \"%s\")", userinfo->sn, msg); - aim_chat_send_im(sess, command->conn, tmpbuf); + aim_chat_send_im(sess, command->conn, 0, tmpbuf, strlen(tmpbuf)); } return 1;