ayttm-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Ayttm-commits] CVS: ayttm/modules/msn2/libmsn2 msn_bittybits.C,1.13,1.1


From: Colin Leroy <address@hidden>
Subject: [Ayttm-commits] CVS: ayttm/modules/msn2/libmsn2 msn_bittybits.C,1.13,1.14 msn_bittybits.h,1.1.1.1,1.2 msn_core.C,1.48,1.49msn_core.h,1.14,1.15
Date: Wed, 26 Mar 2003 11:18:52 -0500

Update of /cvsroot/ayttm/ayttm/modules/msn2/libmsn2
In directory subversions:/tmp/cvs-serv28888/modules/msn2/libmsn2

Modified Files:
        msn_bittybits.C msn_bittybits.h msn_core.C msn_core.h 
Log Message:
fix msn socks 
crossing fingers


Index: msn_bittybits.C
===================================================================
RCS file: /cvsroot/ayttm/ayttm/modules/msn2/libmsn2/msn_bittybits.C,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- msn_bittybits.C     26 Mar 2003 08:03:24 -0000      1.13
+++ msn_bittybits.C     26 Mar 2003 16:18:50 -0000      1.14
@@ -16,26 +16,27 @@
 #include <errno.h>
 #include <time.h>
 
-char ** msn_read_line(int sock, int * numargs)
+char ** msn_read_line(msnconn *conn, int * numargs)
 {
   // Right, this is quite a task. Step One is to read the thing in.
   char ** retval;
   char c;
-  int pos=0, numspaces=0;
   int should_terminate=0;
 #ifndef __MINGW32__
   struct pollfd pfd;
   struct timespec delay;
-
+  int sock = conn->sock;
+  
   pfd.fd=sock;
   pfd.events=POLLIN;
 
   delay.tv_sec = 0;
   delay.tv_nsec = 10000000;
+  int finished = 0;
 #endif
   do
   {
-    should_terminate = 0;
+    
     if(read(sock, &c, 1)<1)
     {
       if (errno == EAGAIN) {  
@@ -46,89 +47,81 @@
 #else
        int res=0;
        if((res=poll(&pfd,1,5000))==0) {
-               should_terminate = 1;
-               break;
+               *numargs=0;
+               return NULL;
        } else if (res > 0) {
                continue;
-       } else
+       } else {
+               *numargs=-1;
                return NULL;
+       }
        
 #endif
        continue;
-      } else {
-        printf("What the.. (%d) (%s)?!\n", sock, buf); //DEBUG
+      } else if (errno) {
+       printf("error %d %s\n",errno, strerror(errno));
+        printf("What the.. (%d) (%s)?!\n", sock, conn->readbuf); //DEBUG
+       *numargs=-1;
        return NULL;      
-      }        
+      }        else if(conn->type==CONN_FTP)
+         { conn->numspaces++; conn->readbuf[conn->pos]='\0'; finished=1; 
break; }            
     }
 
-    if(pos == 1249) {buf[pos]='\0'; continue; }
-    if(c=='\r' || pos > 1249) { continue; }
-    if(c=='\n') { numspaces++; buf[pos]='\0'; break; }
-    if(c==' ') { numspaces++; }
-    buf[pos]=c;
-    pos++;
-#ifndef __MINGW32__
-    {
-           int res = 0;
-           if((res=poll(&pfd,1,5000))==0) {
-                   should_terminate=1;
-                   break;
-           } 
-           else if (res > 0) {
-               continue;
-           } else {    
-               printf("uh, msnconn closed\n");    
-               return NULL;
-           }
-    }
-#endif
+    if(conn->pos == 1249) {conn->readbuf[conn->pos]='\0'; continue; }
+    if(c=='\r' || conn->pos > 1249) { continue; }
+    if(c=='\n') { conn->numspaces++; conn->readbuf[conn->pos]='\0'; 
finished=1; break; }
+    if(c==' ') { conn->numspaces++; }
+    conn->readbuf[conn->pos]=c;
+    conn->pos++;
   }
 #ifndef __MINGW32__
   while(poll(&pfd, 1, 0)==1);
 #else
   while (1);
 #endif
-  if (should_terminate) {
-         printf("terminating short string\n");
-         numspaces++; buf[pos]='\0';
-         pos++;
+  if (!finished) {
+         *numargs=0;
+         return NULL;
   }
   
-  if(numspaces==0) { printf("What the..?\n"); return NULL; }
+  if(conn->numspaces==0) { printf("What the..?\n"); *numargs=-1; return NULL; }
 
-  retval=new char * [numspaces];
-  retval[0]=new char[strlen(buf)+1];
-  strcpy(retval[0], buf); /* long enough */
-  *numargs=numspaces;
+  retval=new char * [conn->numspaces];
+  retval[0]=new char[strlen(conn->readbuf)+1];
+  strcpy(retval[0], conn->readbuf); /* long enough */
+  *numargs=conn->numspaces;
 
   // OK, take it as read (boom, boom!)
   // Now we cruise through the string, changing all spaces to null 0's and 
setting
   // a pointer at the beginning of each substring
 
-  pos=0;
-  numspaces=1; // pointer #0 is already set at the beginning
+  conn->pos=0;
+  conn->numspaces=1; // pointer #0 is already set at the beginning
   while(1)
   {
-    if(retval[0][pos]==' ')
+    if(retval[0][conn->pos]==' ')
     {
-      retval[0][pos]='\0';
-      retval[numspaces]=retval[0]+pos+1;
-      numspaces++;
-      pos++;
+      retval[0][conn->pos]='\0';
+      retval[conn->numspaces]=retval[0]+conn->pos+1;
+      conn->numspaces++;
+      conn->pos++;
       continue;
     }
-    if(retval[0][pos]=='\0') { break; }
+    if(retval[0][conn->pos]=='\0') { break; }
 
-    pos++;
+    conn->pos++;
   }
 
+  conn->pos = conn->numspaces = 0;
+  memset(conn->readbuf,0, sizeof(conn->readbuf));
+
   return retval;
 }
 
 void msn_clean_up(msnconn * conn)
 {
   llist * connlist;
-  connlist=connections;
+  connlist=msnconnections;
 
   if(conn->type!=CONN_FTP)
   { ext_closing_connection(conn); }
@@ -151,7 +144,7 @@
   if(connlist->next!=NULL)
   { connlist->next->prev=connlist->prev; }
   if(connlist->prev!=NULL)
-  { connlist->prev->next=connlist->next; } else { connections=connlist->next; }
+  { connlist->prev->next=connlist->next; } else { 
msnconnections=connlist->next; }
   connlist->prev=NULL; // no recursive destructors, please...
   connlist->next=NULL;
   connlist->data=NULL; // already deleted the conn object

Index: msn_bittybits.h
===================================================================
RCS file: /cvsroot/ayttm/ayttm/modules/msn2/libmsn2/msn_bittybits.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -r1.1.1.1 -r1.2
--- msn_bittybits.h     23 Dec 2002 22:04:58 -0000      1.1.1.1
+++ msn_bittybits.h     26 Mar 2003 16:18:50 -0000      1.2
@@ -10,7 +10,7 @@
           numargs       Gets set to the number of arguments
         Returns:        A NULL-terminated array of strings, or NULL on error
 */
-char ** msn_read_line(int sock, int * numargs);
+char ** msn_read_line(msnconn *conn, int * numargs);
 
 void msn_clean_up(msnconn * conn);
 

Index: msn_core.C
===================================================================
RCS file: /cvsroot/ayttm/ayttm/modules/msn2/libmsn2/msn_core.C,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- msn_core.C  26 Mar 2003 13:17:58 -0000      1.48
+++ msn_core.C  26 Mar 2003 16:18:50 -0000      1.49
@@ -40,7 +40,7 @@
 #define DEBUG do_msn_debug
 
 // Define all those extern'ed variables in msn_core.h:
-llist * connections=NULL;
+llist * msnconnections=NULL;
 
 int next_trid=10;
 char buf[1250]; // used for anything temporary
@@ -108,7 +108,7 @@
   errors[913]=msn_permstring("This action is not allowed while you are 
offline");
   errors[920]=msn_permstring("This server is not accepting new users");
 
-  msn_add_to_llist(connections, conn);
+  msn_add_to_llist(msnconnections, conn);
 }
 
 void msn_show_verbose_error(msnconn * conn, int errcode)
@@ -150,7 +150,7 @@
   {
     llist * list;
 
-    list=connections;
+    list=msnconnections;
     while(1)
     {
       msnconn * c;
@@ -310,10 +310,10 @@
   {
     if(numargs >=3 && !strcmp(args[2], "FL"))
     {
-      if(numargs >=7 && !strcmp(args[5], "0"))
+      if(!strcmp(args[5], "0"))
       {
         info->fl=NULL; info->complete|=LST_FL;
-      } else {
+      } else if (numargs >=7) {
         userdata * newuser=new userdata();
         newuser->username=msn_permstring(args[6]);
         newuser->friendlyname=msn_decode_URL(msn_permstring(args[6]));
@@ -326,10 +326,10 @@
     }
     if(numargs >=3 && !strcmp(args[2], "RL"))
     {
-      if(numargs >=7 && !strcmp(args[5], "0"))
+      if(!strcmp(args[5], "0"))
       {
         info->rl=NULL; info->complete|=LST_RL; // no mates! :-)
-      } else {
+      } else if (numargs >=7) {
         userdata * newuser=new userdata();
         newuser->username=msn_permstring(args[6]);
         newuser->friendlyname=msn_decode_URL(msn_permstring(args[6]));
@@ -340,10 +340,10 @@
     }
     if(numargs >=3 && !strcmp(args[2], "AL"))
     {
-      if(numargs >=7 && !strcmp(args[5], "0"))
+      if(!strcmp(args[5], "0"))
       {
         info->al=NULL; info->complete|=LST_AL;
-      } else {
+      } else if (numargs >=7) {
         userdata * newuser=new userdata();
         newuser->username=msn_permstring(args[6]);
         newuser->friendlyname=msn_decode_URL(msn_permstring(args[6]));
@@ -354,10 +354,10 @@
     }
     if(numargs >=3 && !strcmp(args[2], "BL"))
     {
-      if(numargs >=7 && !strcmp(args[5], "0"))
+      if(!strcmp(args[5], "0"))
       {
         info->bl=NULL; info->complete|=LST_BL;
-      } else {
+      } else  if (numargs >=7) {
         userdata * newuser=new userdata();
         newuser->username=msn_permstring(args[6]);
         newuser->friendlyname=msn_decode_URL(msn_permstring(args[6]));
@@ -525,7 +525,7 @@
   newconn->type=CONN_SB;
   newconn->ready=0;
 
-  msn_add_to_llist(connections, newconn);
+  msn_add_to_llist(msnconnections, newconn);
 
   int port=1863;
   char * c;
@@ -572,43 +572,25 @@
   ext_new_connection(conn);
 }
 
-void msn_handle_incoming(int sock, int readable, int writable)
+void msn_handle_incoming(msnconn *conn, int readable, int writable,
+               char **args, int numargs)
 {
   // First, we find which msnconn this socket belongs to
 
-  llist * list;
-  msnconn * conn;
   callback * call;
-
-  char ** args;
-  int numargs;
+  int sock = conn->sock;
   int trid;
 
-  list=connections;
-
-  if(list==NULL) { return; }
-
-  while(1)
-  {
-    conn=(msnconn *)list->data;
-    if(conn->sock==sock)
-    { break; }
-    list=list->next;
-    if(list==NULL)
-    { if(DEBUG) printf("Network traffic not for us\n"); 
-       return; } // not for us
-  }
-
   // first, siphon off any file transfer traffic to the special handler
   if(conn->type==CONN_FTP)
-  { msn_handle_filetrans_incoming(conn, readable, writable); return; }
+  { //msn_handle_filetrans_incoming(conn, readable, writable, args, numargs); 
+         printf("WHY THE FUCK IS CONN_FTP HANDLED HERE?\n");
+    return; }
 
   // OK, it's for us. If it's readable, parse it, then deliver it to the 
appropriate handler
 
   if(!readable) { return; }
 
-  args=msn_read_line(sock, &numargs);
-
   if(args==NULL)
   { msn_clean_up(conn); return; }
 
@@ -645,7 +627,7 @@
   if(numargs >=2)
          trid=atoi(args[1]);
 
-  list=conn->callbacks;
+  llist *list=conn->callbacks;
 
   if(list!=NULL && trid>0)
   {
@@ -675,7 +657,7 @@
   llist * list;
   msnconn * conn;
 
-  list=connections;
+  list=msnconnections;
 
   if(list==NULL) { return; }
 
@@ -809,12 +791,12 @@
 
 void msn_handle_MSG(msnconn * conn, char ** args, int numargs)
 {
-  int msglen;
+  int msglen, remaining;
   char * msg = NULL;
   char * mime;
   char * body;
   char * tmp;
-
+  int tries = 0;
   if (numargs < 4)
          return;
 
@@ -822,7 +804,24 @@
 
   msg=(char *)malloc(msglen+1);
   memset(msg,'\0',msglen);
-  read(conn->sock, msg, msglen);
+  ext_unregister_sock(conn->sock);
+
+  remaining=msglen;
+  do {
+         char tbuf[1250]="";
+         int i=read(conn->sock, tbuf, remaining);
+         if (errno == EAGAIN || i < remaining) {
+                 sleep(1);
+                 tries++;
+         }
+         if (i>=0) {
+               remaining -= i;
+         }
+         strncat(msg, tbuf, msglen-strlen(msg));
+  } while (remaining > 0 && tries < 6);
+  
+  ext_register_sock(conn->sock, 1, 0);
+  
   msg[msglen]='\0';
 
   mime=msg;
@@ -1146,7 +1145,7 @@
 
   conn->auth=auth;
 
-  msn_add_to_llist(connections, conn);
+  msn_add_to_llist(msnconnections, conn);
 
   write(conn->sock, "VER MSNFTP\r\n", strlen("VER MSNFTP\r\n"));
 }
@@ -1169,7 +1168,7 @@
   msn_del_from_llist(inv->conn->invitations_in, inv);
   msn_del_from_llist(inv->conn->invitations_out, inv);
 
-  l=connections;
+  l=msnconnections;
 
   while(1)
   {
@@ -1199,7 +1198,7 @@
       char ** args;
       int numargs;
 
-      args=msn_read_line(conn->sock, &numargs);
+      args=msn_read_line(conn, &numargs);
 
       if(args==NULL) { msn_clean_up(conn); return; }
 
@@ -1253,6 +1252,9 @@
     fd_set fds;
     FD_ZERO(&fds);
     FD_SET(conn->sock,&fds);
+    ext_unregister_sock(conn->sock);
+    if (DEBUG) printf("unregistered FTP sock\n");
+    
     while(select(conn->sock+1,&fds,NULL,NULL,&zerotime))
 #endif
     {
@@ -1282,6 +1284,7 @@
         ext_filetrans_success(auth->inv);
 
         msn_del_from_llist(auth->inv->conn->invitations_in, auth->inv);
+        msn_del_from_llist(auth->inv->conn->invitations_out, auth->inv);
         msn_clean_up(conn);
         return;
       }
@@ -1291,7 +1294,8 @@
       if(auth->bytes_done%8192==0) /* force getting out of loop to be able to 
do something else */
              return;
     }
-
+    ext_register_sock(conn->sock, 1, 0);
+    if (DEBUG) printf("registered again\n");
   } else {
     // We are sending
 
@@ -1325,9 +1329,10 @@
         char ** args;
         int numargs;
 
+
         if(!readable) { return; } // not interested...
 
-        if((args=msn_read_line(conn->sock, &numargs))==NULL)
+        if((args=msn_read_line(conn, &numargs))==NULL)
         {
           perror("read() failed");
           ext_filetrans_failed(auth->inv, errno, strerror(errno));
@@ -1406,7 +1411,7 @@
             unsigned char check[3];
            if (poll(&pin, 1, 0)==1) {
                int numargs;
-               char **args =msn_read_line(conn->sock, &numargs);
+               char **args =msn_read_line(conn, &numargs);
                /* TODO Check if args is NULL */
                if (!strcmp(args[0],"CCL")) {
                        /* remote cancelled reception */
@@ -1454,6 +1459,7 @@
            if(auth->inv) {
                    ext_filetrans_success(auth->inv);
                    msn_del_from_llist(auth->inv->conn->invitations_in, 
auth->inv);
+                   msn_del_from_llist(auth->inv->conn->invitations_out, 
auth->inv);
            }
             msn_clean_up(conn);
             return;
@@ -1490,7 +1496,7 @@
 
   ext_register_sock(conn->sock, 1, 0);
 
-  msn_add_to_llist(connections, conn);
+  msn_add_to_llist(msnconnections, conn);
 
   authdata_FTP * auth=new authdata_FTP;
 
@@ -1563,7 +1569,7 @@
   auth->cookie=msn_permstring(args[4]);
   auth->msg=NULL;
 
-  msn_add_to_llist(connections, newSBconn);
+  msn_add_to_llist(msnconnections, newSBconn);
 
   char * c;
   int port=1863;

Index: msn_core.h
===================================================================
RCS file: /cvsroot/ayttm/ayttm/modules/msn2/libmsn2/msn_core.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- msn_core.h  22 Mar 2003 01:56:43 -0000      1.14
+++ msn_core.h  26 Mar 2003 16:18:50 -0000      1.15
@@ -90,7 +90,17 @@
   llist * callbacks;
   authdata * auth;
 
-  msnconn() { users=NULL; callbacks=NULL; invitations_out=NULL; 
invitations_in=NULL; }
+  int pos, numspaces;
+  char readbuf[1250];
+  
+  msnconn() { 
+       users=NULL; 
+       callbacks=NULL; 
+       invitations_out=NULL; 
+       invitations_in=NULL; 
+       pos=numspaces=0;
+       memset(readbuf,0,sizeof(readbuf));
+       }
   ~msnconn()
   {
     if(users!=NULL) { delete users; }
@@ -204,7 +214,7 @@
 };
 
 
-extern llist * connections;
+extern llist * msnconnections;
 extern int next_trid;
 extern char buf[]; // Used for anything temporary
 
@@ -302,7 +312,7 @@
 void msn_SBconn_2(msnconn * conn, int trid, char ** args, int numargs, 
callback_data * data);
 void msn_SBconn_3(msnconn * conn, int trid, char ** args, int numargs, 
callback_data * data);
 
-void msn_handle_incoming(int sock, int readable, int writable);
+void msn_handle_incoming(msnconn *conn, int readable, int writable, char 
**args, int nargs);
 
 void msn_handle_filetrans_incoming(msnconn * conn, int readable, int writable);
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]