]> andersk Git - libfaim.git/blobdiff - utils/faimtest/faimtest.c
(guest commit by jbm)
[libfaim.git] / utils / faimtest / faimtest.c
index 1e7b2fab1186a73d534e61e2c95bea5242c19620..c1013f4e3151180b4e19a454709a3a0248fc9131 100644 (file)
@@ -74,6 +74,14 @@ int faimtest_directim_connect(struct aim_session_t *sess, struct command_rx_stru
 int faimtest_directim_incoming(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 int faimtest_directim_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 int faimtest_directim_typing(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+#define FILESUPPORT
+#ifdef FILESUPPORT
+int faimtest_getfile_filereq(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+int faimtest_getfile_filesend(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+int faimtest_getfile_complete(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+int faimtest_getfile_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...);
+#endif
+
 int faimtest_parse_ratechange(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 int faimtest_parse_evilnotify(struct aim_session_t *sess, struct command_rx_struct *command, ...);
 int faimtest_parse_msgerr(struct aim_session_t *sess, struct command_rx_struct *command, ...);
@@ -141,9 +149,16 @@ int main(void)
   struct aim_session_t aimsess;
   struct aim_conn_t *authconn = NULL, *waitingconn = NULL;
   int keepgoing = 1;
+  char *proxy, *proxyusername, *proxypass;
+
+  char *listingpath;
 
   int selstat = 0;
 
+#ifdef FILESUPPORT
+  FILE *listingfile;
+#endif
+
   if ( !(screenname = getenv("SCREENNAME")) ||
        !(password = getenv("PASSWORD")))
     {
@@ -153,6 +168,14 @@ int main(void)
 
   server = getenv("AUTHSERVER");
 
+  proxy = getenv("SOCKSPROXY");
+  proxyusername = getenv("SOCKSNAME");
+  proxypass = getenv("SOCKSPASS");
+
+#ifdef FILESUPPORT
+  listingpath = getenv("LISTINGPATH");
+#endif
+
 #ifdef _WIN32
   if (initwsa() != 0) {
     printf("faimtest: could not initialize windows sockets\n");
@@ -162,6 +185,28 @@ int main(void)
 
   aim_session_init(&aimsess);
 
+#ifdef FILESUPPORT
+  if(listingpath) {
+    char *listingname;
+    if(!(listingname = (char *)calloc(1, strlen(listingpath)+strlen("/listing.txt")))) {
+      perror("listingname calloc.");
+      exit(-1);
+    }
+    sprintf(listingname, "%s/listing.txt", listingpath);
+    if( (listingfile = fopen(listingname, "r")) == NULL) {
+      printf("Couldn't open %s... bombing.\n", listingname);
+      exit(-1);
+    }
+
+    aim_oft_registerlisting(&aimsess, listingfile, listingpath);
+
+    free(listingname);
+  }
+#endif
+
+  if (proxy)
+    aim_setupproxy(&aimsess, proxy, proxyusername, proxypass);
+
   authconn = aim_newconn(&aimsess, AIM_CONN_TYPE_AUTH, server?server:FAIM_LOGIN_SERVER);
 
   if (authconn == NULL) {
@@ -204,16 +249,21 @@ int main(void)
     case 2: /* incoming data pending */
       if (waitingconn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) {
        if (aim_handlerendconnect(&aimsess, waitingconn) < 0) {
-         printf("connection error (rend)\n");
+         printf("connection error (rend out)\n");
        }
       } else {
        if (aim_get_command(&aimsess, waitingconn) >= 0) {
          aim_rxdispatch(&aimsess);
        } else {
-         printf("connection error\n");
-         aim_conn_kill(&aimsess, &waitingconn);
+         printf("connection error (type 0x%04x:0x%04x)\n", waitingconn->type, waitingconn->subtype);
+         if(waitingconn->type == AIM_CONN_TYPE_RENDEZVOUS) {
+           /* we should have callbacks for all these, else the library will do the conn_kill for us. */
+           printf("connection error: rendezvous connection. you forgot register a disconnect callback, right?\n");
+         }
+         else
+           aim_conn_kill(&aimsess, &waitingconn);
          if (!aim_getconn_type(&aimsess, AIM_CONN_TYPE_BOS)) {
-           printf("major connetion error\n");
+           printf("major connection error\n");
            keepgoing = 0;
          }
        }
@@ -305,9 +355,7 @@ int faimtest_serverready(struct aim_session_t *sess, struct command_rx_struct *c
       aim_chat_clientready(sess, command->conn);
       break;
 
-    case AIM_CONN_TYPE_RENDEZVOUS: /* this is an overloaded function?? - mid */
-      aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, faimtest_directim_incoming, 0);
-      aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT, faimtest_directim_disconnect, 0);
+    case AIM_CONN_TYPE_RENDEZVOUS: /* empty */
       break;
 
     default:
@@ -317,7 +365,7 @@ int faimtest_serverready(struct aim_session_t *sess, struct command_rx_struct *c
 }
 
 int faimtest_parse_buddyrights(struct aim_session_t *sess, struct command_rx_struct *command, ...)
-{      
+{
   va_list ap;
   unsigned short maxbuddies, maxwatchers;
 
@@ -653,6 +701,12 @@ int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_str
       } else if (strstr(tmpstr, "anonwarn")) {
        printf("faimtest: icbm: sending anon warning\n");
        aim_send_warning(sess, command->conn, userinfo->sn, AIM_WARN_ANON);
+      } else if (strstr(tmpstr, "setdirectoryinfo")) {
+       printf("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")) {
+       printf("faimtest: icbm: setting fun interests\n");
+       aim_setuserinterests(sess, command->conn, "interest1", "interest2", "interest3", "interest4", "interest5", 1);
       } else if (!strncmp(tmpstr, "open chatnav", 12)) {
        aim_bos_reqservice(sess, command->conn, AIM_CONN_TYPE_CHATNAV);
        //aim_chat_join(sess, command->conn, "thishereisaname2_chat85");
@@ -672,7 +726,6 @@ int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_str
       } else if (!strncmp(tmpstr, "open directim", 13)) {
        struct aim_conn_t *newconn;
        newconn = aim_directim_initiate(sess, command->conn, NULL, userinfo->sn);
-       //aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE, faimtest_directim_initiate, 0);
       } else if (!strncmp(tmpstr, "reqsendmsg", 10)) {
        aim_send_im(sess, command->conn, "vaxherder", 0, "sendmsg 7900");
       } else if (!strncmp(tmpstr, "sendmsg", 7)) {
@@ -723,8 +776,33 @@ int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_str
       break;
     }
     case AIM_CAPS_GETFILE: {
-      printf("faimtset: get file!\n");
+#ifdef FILESUPPORT
+      char *ip, *cookie;
+      struct aim_conn_t *newconn;
+
+      userinfo = va_arg(ap, struct aim_userinfo_s *);
+      ip = va_arg(ap, char *);
+      cookie = va_arg(ap, char *);
+      va_end(ap);
+      
+      printf("faimtest: get file request from %s (at %s)\n", userinfo->sn, ip);
+
+      sleep(1);
+
+      if( (newconn = aim_accepttransfer(sess, command->conn, userinfo->sn, cookie, ip, sess->oft.listing, reqclass)) == NULL ) {
+       printf("faimtest: getfile: requestconn: apparent error in accepttransfer\n");
+       break;
+      }
+      
+      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);      
+
+      printf("faimtest: getfile connect succeeded, handlers added.\n");
+
       break;
+#endif
     }
     case AIM_CAPS_SENDFILE: {
       printf("faimtest: send file!\n");
@@ -784,10 +862,10 @@ int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_str
       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");
-
       printf("faimtest: OFT: DirectIM: connected to %s\n", userinfo->sn);
 
+      aim_send_im_direct(sess, newconn, "goodday");
+
       break;
     }
     default:
@@ -800,7 +878,6 @@ int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_str
   return 1;
 }
 
-#if 0
 int faimtest_directim_initiate(struct aim_session_t *sess, struct command_rx_struct *command, ...)
 {
   va_list ap;
@@ -825,7 +902,6 @@ int faimtest_directim_initiate(struct aim_session_t *sess, struct command_rx_str
 
   return 1;
 }
-#endif
 
 int faimtest_directim_connect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
 {
@@ -882,7 +958,18 @@ int faimtest_directim_incoming(struct aim_session_t *sess, struct command_rx_str
 
 int faimtest_directim_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
 {
-  printf("faimtest: directim_disconnect\n");
+  va_list ap;
+  struct aim_conn_t *conn;
+  char *sn;
+
+  ap = va_start(ap, command);
+  conn = va_arg(ap, struct aim_conn_t *);
+  sn = va_arg(ap, char *);
+  va_end(ap);
+
+  printf("faimtest: directim: disconnected from %s\n", sn);
+
+  aim_conn_kill(sess, &conn);
   return 1;
 }
 
@@ -1042,7 +1129,7 @@ int faimtest_parse_misses(struct aim_session_t *sess, struct command_rx_struct *
 
   printf("faimtest: missed %d messages from %s (reason %d: %s)\n", nummissed, userinfo->sn, reason, (reason<missedreasonslen)?missedreasons[reason]:"unknown");
   
-  return 0;
+  return 1;
 }
 
 int faimtest_parse_login(struct aim_session_t *sess, struct command_rx_struct *command, ...)
@@ -1283,6 +1370,102 @@ int faimtest_parse_msgack(struct aim_session_t *sess, struct command_rx_struct *
   return 1;
 }
 
+#ifdef FILESUPPORT
+int faimtest_getfile_filereq(struct aim_session_t *ses, struct command_rx_struct *command, ...)
+{
+  va_list ap;
+  struct aim_conn_t *oftconn;
+  struct aim_fileheader_t *fh;
+  char *cookie;
+
+  ap = va_start(ap, command);
+  oftconn = va_arg(ap, struct aim_conn_t *);
+  fh = va_arg(ap, struct aim_fileheader_t *);
+  cookie = va_arg(ap, char *);
+  va_end(ap);
+
+  printf("faimtest: request for file %s.\n", fh->name);
+
+  return 1;
+}
+
+
+int faimtest_getfile_filesend(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+  va_list ap;
+  struct aim_conn_t *oftconn;
+  struct aim_fileheader_t *fh;
+  char *path, *cookie;
+
+  FILE *file;
+
+  ap = va_start(ap, command);
+  oftconn = va_arg(ap, struct aim_conn_t *);
+  fh = va_arg(ap, struct aim_fileheader_t *);
+  cookie = va_arg(ap, char *);
+  va_end(ap);
+
+  printf("faimtest: sending file %s.\n", fh->name);
+
+  if( (path = (char *)calloc(1, strlen(sess->oft.listingdir) +strlen(fh->name)+2)) == NULL) {
+    perror("calloc:");
+    printf("faimtest: error in calloc of path\n");
+    return 0; /* XXX: no idea what winaim expects here =) */
+  }
+  
+  snprintf(path, strlen(sess->oft.listingdir)+strlen(fh->name)+2, "%s/%s", sess->oft.listingdir, fh->name);
+
+
+  if( (file = fopen(path, "r")) == NULL) {
+    printf("faimtest: getfile_send fopen failed for %s. damn.\n", path);
+    return 0;
+  }
+
+  if (aim_getfile_send(oftconn, file, fh) == -1) {
+    printf("faimtest: getfile_send failed. damn.\n");
+  } else {
+    printf("faimtest: looks like getfile went clean\n");
+  }
+
+  free(fh);  
+  return 1;
+}
+
+int faimtest_getfile_complete(struct aim_session_t *sess, struct command_rx_struct *command, ...) 
+{
+  va_list ap;
+  struct aim_conn_t *conn;
+  struct aim_fileheader_t *fh;
+
+  ap = va_start(ap, command);
+  conn = va_arg(ap, struct aim_conn_t *);
+  fh = va_arg(ap, struct aim_fileheader_t *);
+  va_end(ap);
+
+  printf("faimtest: completed file transfer for %s.\n", fh->name);
+
+  /*  aim_conn_kill(sess, &conn); */ /* we'll let winaim close the conn */
+  return 1;
+}
+
+int faimtest_getfile_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
+{
+  va_list ap;
+  struct aim_conn_t *conn;
+  char *sn;
+
+  ap = va_start(ap, command);
+  conn = va_arg(ap, struct aim_conn_t *);
+  sn = va_arg(ap, char *);
+  va_end(ap);
+
+  aim_conn_kill(sess, &conn);
+
+  printf("faimtest: getfile: disconnected from %s\n", sn);
+  return 1;
+}
+#endif
+
 int faimtest_parse_ratechange(struct aim_session_t *sess, struct command_rx_struct *command, ...)
 {
   va_list ap;
@@ -1294,7 +1477,7 @@ int faimtest_parse_ratechange(struct aim_session_t *sess, struct command_rx_stru
 
   printf("faimtest: ratechange: %lu\n", newrate);
 
-  return (1);
+  return 1;
 }
 
 int faimtest_parse_evilnotify(struct aim_session_t *sess, struct command_rx_struct *command, ...)
This page took 0.058495 seconds and 4 git commands to generate.