]> andersk Git - libfaim.git/blobdiff - aim_ft.c
- Mon Sep 4 21:38:09 GMT 2000
[libfaim.git] / aim_ft.c
index 7a77717624414cfc3a3cfc2425616233fe424357..53075774c51ea13c2b98c70270bd23bafc2640ed 100644 (file)
--- a/aim_ft.c
+++ b/aim_ft.c
@@ -1,5 +1,8 @@
 #include <faim/aim.h>
 
+#include <netdb.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
 #include <sys/utsname.h> /* for aim_directim_initiate */
 #include <arpa/inet.h> /* for inet_ntoa */
 
    aim_filetransfer_accept aim_im.c
    aim_getlisting aim_misc.c (?!) -- prototype function. can be ignored.
    establish aim_misc.c
-   aim_get_command_rendezvous aim_rxqueue.c
+   aim_get_command_rendezvous aim_r
    oft_getfh aim_rxqueue.c
 */
 
-int aim_handlerendconnect(struct aim_session_t *sess, struct aim_conn_t *cur)
+faim_export int aim_handlerendconnect(struct aim_session_t *sess, struct aim_conn_t *cur)
 {
   int acceptfd = 0;
   rxcallback_t userfunc;
@@ -84,9 +87,9 @@ int aim_handlerendconnect(struct aim_session_t *sess, struct aim_conn_t *cur)
  * msg  - null-terminated string to send
  */
 
-int aim_send_im_direct(struct aim_session_t *sess, 
-                      struct aim_conn_t *conn,
-                      char *msg)
+faim_export int aim_send_im_direct(struct aim_session_t *sess, 
+                                  struct aim_conn_t *conn,
+                                  char *msg)
 {
   struct command_tx_struct *newpacket , *newpacket2; 
 
@@ -130,7 +133,7 @@ int aim_send_im_direct(struct aim_session_t *sess,
   i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0006);
   i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
 
-  i += aimutil_putstr(newpacket2->hdr.oft.hdr2+i, priv->cookie, 8);
+  i += aimutil_putstr(newpacket2->hdr.oft.hdr2+i, (char *)priv->cookie, 8);
 
   i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
   i += aimutil_put16(newpacket2->hdr.oft.hdr2+i, 0x0000);
@@ -186,7 +189,7 @@ int aim_send_im_direct(struct aim_session_t *sess,
   i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0006);
   i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
 
-  i += aimutil_putstr(newpacket->hdr.oft.hdr2+i, priv->cookie, 8);
+  i += aimutil_putstr(newpacket->hdr.oft.hdr2+i, (char *)priv->cookie, 8);
 
   i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
   i += aimutil_put16(newpacket->hdr.oft.hdr2+i, 0x0000);
@@ -244,10 +247,10 @@ int aim_send_im_direct(struct aim_session_t *sess,
  */
 
 
-struct aim_conn_t *aim_directim_initiate(struct aim_session_t *sess,
-                         struct aim_conn_t *conn,
-                         struct aim_directim_priv *priv,
-                         char *destsn)
+faim_export struct aim_conn_t *aim_directim_initiate(struct aim_session_t *sess,
+                                                    struct aim_conn_t *conn,
+                                                    struct aim_directim_priv *priv,
+                                                    char *destsn)
 {
   struct command_tx_struct *newpacket;
   struct aim_conn_t *newconn;
@@ -260,7 +263,7 @@ struct aim_conn_t *aim_directim_initiate(struct aim_session_t *sess,
   struct hostent *hptr;
   struct utsname myname;
 
-  char cap[16];
+  unsigned char cap[16];
   char d[4]; /* XXX: IPv6. *cough* */
 
   /*
@@ -445,9 +448,9 @@ struct aim_conn_t *aim_directim_initiate(struct aim_session_t *sess,
 } 
 
 
-struct aim_conn_t *aim_directim_connect(struct aim_session_t *sess,
-                                       struct aim_conn_t *conn,
-                                       struct aim_directim_priv *priv )
+faim_export struct aim_conn_t *aim_directim_connect(struct aim_session_t *sess,
+                                                   struct aim_conn_t *conn,
+                                                   struct aim_directim_priv *priv )
 {
   struct aim_conn_t *newconn = NULL;;
 
@@ -466,12 +469,12 @@ struct aim_conn_t *aim_directim_connect(struct aim_session_t *sess,
   return newconn;
 }
 
-u_long aim_accepttransfer(struct aim_session_t *sess,
-                         struct aim_conn_t *conn, 
-                         struct aim_conn_t *oftconn,
-                         char *sn,
-                         char *cookie,
-                         unsigned short rendid)
+faim_export unsigned long aim_accepttransfer(struct aim_session_t *sess,
+                                            struct aim_conn_t *conn, 
+                                            struct aim_conn_t *oftconn,
+                                            char *sn,
+                                            char *cookie,
+                                            unsigned short rendid)
 {
   struct command_tx_struct *newpacket, *newoft;
   struct aim_fileheader_t *listingfh;
@@ -583,7 +586,7 @@ u_long aim_accepttransfer(struct aim_session_t *sess,
  *  
  */
 
-struct aim_fileheader_t *aim_getlisting(struct aim_session_t *sess) 
+faim_internal struct aim_fileheader_t *aim_getlisting(struct aim_session_t *sess) 
 {
   struct aim_fileheader_t *fh;
 
@@ -639,7 +642,7 @@ struct aim_fileheader_t *aim_getlisting(struct aim_session_t *sess)
  * returns your fd
  */
 
-int aim_listenestablish(u_short portnum)
+faim_internal int aim_listenestablish(u_short portnum)
 {
   int listenfd;
   const int on = 1;
@@ -674,7 +677,7 @@ int aim_listenestablish(u_short portnum)
   return listenfd;
 }
 
-int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *conn)
+faim_internal int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *conn)
 {
 
   /* XXX: NOT THREAD SAFE RIGHT NOW. the locks are acting up. deal. -- jbm */
@@ -688,14 +691,15 @@ int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *co
 
   memset(hdrbuf1, 0, sizeof(hdrbuf1));
 
+  faim_mutex_lock(&conn->active); /* gets locked down for the entirety */
+
   if ( (hdrlen = read(conn->fd, hdrbuf1, 6)) < 6) {    
     if(hdrlen < 0)
       perror("read");
     printf("faim: rend: read error (fd: %i) %02x%02x%02x%02x%02x%02x (%i)\n", conn->fd, hdrbuf1[0],hdrbuf1[1],hdrbuf1[0],hdrbuf1[0],hdrbuf1[0],hdrbuf1[0],hdrlen);
-    aim_conn_kill(sess, &conn);
-    return -1; /* return -1 prematurely signal'd a bad read(). it's *
-              * direct, so we don't really care if the connection *
-              * falls apart.  -- jbm                              */
+    faim_mutex_unlock(&conn->active);
+    aim_conn_close(conn);
+    return -1;
   }
 
   hdrlen = aimutil_get16(hdrbuf1+4);
@@ -704,18 +708,15 @@ int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *co
   if (!(hdr = malloc(hdrlen)))
     return -1;
 
-  //    faim_mutex_lock(&conn->active);
   if (read(conn->fd, hdr, hdrlen) < hdrlen) {
     perror("read");
     printf("faim: rend: read2 error\n");
     free(hdr);
-    //    faim_mutex_unlock(&conn->active);
-    aim_conn_kill(sess, &conn);
+    faim_mutex_unlock(&conn->active);
+    aim_conn_close(conn);
     return 0; /* see comment on previous read check */
   }
 
-  //  faim_mutex_unlock(&conn->active);
-
   hdrtype = aimutil_get16(hdr);  
 
   switch (hdrtype) {
@@ -729,38 +730,39 @@ int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *co
 
     payloadlength = aimutil_get32(hdr+22);
     flags = aimutil_get16(hdr+32);
-    snptr = hdr+38;
+    snptr = (char *)hdr+38;
 
     strncpy(priv->sn, snptr, MAXSNLEN);
 
-    /*    printf("faim: OFT frame: %04x / %04x / %04x / %s\n", hdrtype, payloadlength, flags, snptr); */
+#if 0
+    printf("faim: OFT frame: %04x / %04x / %04x / %s\n", hdrtype, payloadlength, flags, snptr); 
+#endif
 
     if (flags == 0x000e) {
-      //      printf("faim: directim: %s has started typing. yippee.\n", snptr);
+      faim_mutex_unlock(&conn->active);
       if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING)) )
        return userfunc(sess, NULL, snptr);
     } else if ((flags == 0x0000) && payloadlength) {
       unsigned char *msg;
-      if(! (msg = calloc(1, payloadlength+1)) )
+
+      if(! (msg = calloc(1, payloadlength+1)) ) {
+       faim_mutex_unlock(&conn->active);
        return 0;
+      }
       
-      /* XXX: theres got to be a better way */
-      /* XXX: that's a moot point, as the locks never seem to be free. */
-      /*
-       faim_mutex_lock(&conn->active);
-      */
-
       if (recv(conn->fd, msg, payloadlength, MSG_WAITALL) < payloadlength) {
        perror("read");
        printf("faim: rend: read3 error\n");
        free(msg);
-       // faim_mutex_unlock(&conn->active);
-       aim_conn_kill(sess, &conn);
-       return 0;
+       faim_mutex_unlock(&conn->active);
+       aim_conn_close(conn);
+       return -1;
       }
-      //      faim_mutex_unlock(&conn->active);
+      faim_mutex_unlock(&conn->active);
       msg[payloadlength] = '\0';
-      //   printf("faim: directim: %s/%04x/%04x/%s\n", snptr, payloadlength, flags, msg);
+#if 0     
+      printf("faim: directim: %s/%04x/%04x/%s\n", snptr, payloadlength, flags, msg);
+#endif
 
       if ( (userfunc = aim_callhandler(conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING)) )
        i = userfunc(sess, NULL, conn, snptr, msg);
@@ -775,7 +777,6 @@ int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *co
     struct aim_fileheader_t *fh;
     struct aim_msgcookie_t *cook;
 
-
     int commandlen;
     char *data;
 
@@ -786,6 +787,7 @@ int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *co
     
     if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) {
       printf("faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n");
+      faim_mutex_unlock(&conn->active);
       return 0;
     }
 
@@ -793,7 +795,7 @@ int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *co
 
     memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t));
     
-    cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
+    cook = aim_checkcookie(sess, (unsigned char *)ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
 
     if(cook->data)
       free(cook->data); /* XXX */
@@ -810,6 +812,7 @@ int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *co
     if (write(conn->fd, data, commandlen) != commandlen) {
       perror("listing write error");
     }
+    faim_mutex_unlock(&conn->active);
 
     printf("jbm: hit end of 1209\n");
 
@@ -825,6 +828,7 @@ int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *co
 
     if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) {
       printf("faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n");
+      faim_mutex_unlock(&conn->active);
       return 0;
     }
 
@@ -835,7 +839,7 @@ int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *co
 
     memcpy(&(ft->fh), fh, sizeof(struct aim_fileheader_t));
     
-    cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
+    cook = aim_checkcookie(sess, (unsigned char *)ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
   
     if(cook->data)
       free(cook->data); /* XXX: integrate cookie caching */
@@ -843,6 +847,8 @@ int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *co
     cook->data = ft;
     
     aim_cachecookie(sess, cook);
+
+    faim_mutex_unlock(&conn->active);
     
     break;
   }
@@ -857,17 +863,18 @@ int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *co
 
     if(!(ft = (struct aim_filetransfer_priv *)calloc(1, sizeof(struct aim_filetransfer_priv)))) {
       printf("faim: couldn't malloc ft. um. bad. bad bad. file transfer will likely fail, sorry.\n");
+      faim_mutex_unlock(&conn->active);
       return 0;
     }
 
     if(hdrlen != 0x100)
       printf("faim: fileget_command(120c): um. hdrlen != 0x100..\n");
 
-    listingfh = aim_oft_getfh((char *)hdr);
+    listingfh = aim_oft_getfh(hdr);
 
     memcpy(&(ft->fh), listingfh, sizeof(struct aim_fileheader_t));
     
-    cook = aim_checkcookie(sess, ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
+    cook = aim_checkcookie(sess, (unsigned char *)ft->fh.bcookie, AIM_COOKIETYPE_OFTGET);
   
     if(cook->data)
       free(cook->data); /* XXX */
@@ -876,6 +883,8 @@ int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *co
     
     aim_cachecookie(sess, cook);
 
+    faim_mutex_unlock(&conn->active);
+
     printf("faim: fileget: %s seems to want %s\n", ft->sn, ft->fh.name);
  
     if(!(newoft = aim_tx_new(AIM_FRAMETYPE_OFT, 0x0101, conn, 0/*listingfh->size*/))) {
@@ -936,7 +945,7 @@ int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *co
     curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, 0 /*listingfh->nrecvd*/);
     curbyte += aimutil_put32(newoft->hdr.oft.hdr2+curbyte, 0/*listingfh->recvcsum*/);
 
-    strncpy(newoft->hdr.oft.hdr2+curbyte, listingfh->idstring, 32);
+    strncpy((char *)newoft->hdr.oft.hdr2+curbyte, listingfh->idstring, 32);
     curbyte += 32;
 
     curbyte += aimutil_put8(newoft->hdr.oft.hdr2+curbyte, 0x20 /*listingfh->flags */);
@@ -952,7 +961,7 @@ int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *co
     curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->nencode);
     curbyte += aimutil_put16(newoft->hdr.oft.hdr2+curbyte, listingfh->nlanguage);
 
-    strncpy(newoft->hdr.oft.hdr2+curbyte, listingfh->name, 64);
+    strncpy((char *)newoft->hdr.oft.hdr2+curbyte, listingfh->name, 64);
     curbyte += 64;
 
     free(listingfh);
@@ -968,7 +977,7 @@ int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *co
     int i;
 
     struct aim_fileheader_t *fh;    
-    fh = aim_oft_getfh((char *)hdr);
+    fh = aim_oft_getfh(hdr);
 
     c = (char *)calloc(1, fh->size);
 
@@ -983,16 +992,20 @@ int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *co
       printf("whoopsy, didn't write it all...\n");
     }
 
+    faim_mutex_unlock(&conn->active);
+
     break;
   }
   case 0x0204: { /* get file: finished. close it up */
     printf("looks like we're done with a transfer (oft 0x0204)\n");
-    aim_conn_kill(sess, &conn);
+    faim_mutex_unlock(&conn->active);
+    aim_conn_close(conn);
     break;
   }
   default: {
     printf("OFT frame: type %04x\n", hdrtype);  
     /* data connection may be unreliable here */
+    faim_mutex_unlock(&conn->active);
     break;
   }
   } /* switch */
@@ -1006,7 +1019,7 @@ int aim_get_command_rendezvous(struct aim_session_t *sess, struct aim_conn_t *co
  * this currently feeds totally bogus data
  */
 
-struct aim_fileheader_t *aim_oft_getfh(char *hdr) 
+faim_internal struct aim_fileheader_t *aim_oft_getfh(unsigned char *hdr) 
 {
   struct aim_fileheader_t *fh;
   int i, j;
This page took 0.068184 seconds and 4 git commands to generate.