Re: core segfaults (Yahoo?)

"A. Craig West" <[email protected]> Wed, 17 Mar 2004 16:54:00 -0500 (EST)
Newsgroups gmane.network.everybuddy.devel
Message-ID <[email protected]>
As I threatened/promised, here is my latest version of the yahoo changes.
There is still one point under negotiation, but people probably want it to
stop crashing sooner rather than later...

-------- Patch Begins --------
Index: core/plugins/yahoo/yahoo_util.c
===================================================================
--- core/plugins/yahoo/yahoo_util.c	(revision 307)
+++ core/plugins/yahoo/yahoo_util.c	(working copy)
@@ -122,12 +122,12 @@
 	char *s, *p;
 	int i=0;
 	int l = strlen(sep);
-	if(nelem < 0) {
+	if(nelem <= 0) {
 		char * s;
 		nelem=0;
 		for(s=strstr(str, sep); s; s=strstr(s+l, sep),nelem++)
 			;
-		if(strcmp(str+strlen(str)-l, sep))
+		if(strlen(str) == 0 || strcmp(str+strlen(str)-l, sep))
 			nelem++;
 	}
 
Index: core/plugins/yahoo/yahoo.c
===================================================================
--- core/plugins/yahoo/yahoo.c	(revision 307)
+++ core/plugins/yahoo/yahoo.c	(working copy)
@@ -41,6 +41,7 @@
 #include "yahoo2.h"
 #include "yahoo2_callbacks.h"
 #include "yahoo_util.h"
+#include "yahoo_debug.h"
 
 typedef struct _eb_ylad
 {
@@ -134,8 +135,6 @@
   if (lad->id != -1)
   {
     yahoo_logoff(lad->id);
-    yahoo_close(lad->id);
-    lad->id = -1;
   }
 }
 
@@ -376,6 +375,7 @@
 {
   EList * states = NULL;
   printf("Hi-ho, hi-ho, Yahoo here we go!\n");
+  /*yahoo_set_log_level(YAHOO_LOG_DEBUG);*/
 
   memset(&yahoo_callbacks, 0, sizeof(yahoo_callbacks));
   
@@ -446,16 +446,20 @@
       la->status_string = strdup(GET_LAD(la)->invisible ? "Invisible" : "Online");
       break;
     }
+    case YAHOO_LOGIN_DUPL:
+    {
+      printf("Yahoo forced offline by duplicate login\n");
+      logout(la);
+      break;
+    }
     default:
     {
       char buf[512];
       perror("Weird error");
       sprintf(buf, "Disconnected from the Yahoo network - error code %d", succ);
       eb_show_error(buf, "Yahoo error");
-      la->ready = la->connected = 0;
-      free(la->status_string);
-      la->status_string = strdup("Offline");
-      printf("Login error for %s (Yahoo id %d)\n", la->handle, id);
+      logout(la);
+      printf("Login error %d for %s (Yahoo id %d)\n", succ, la->handle, id); fflush(stdout);
     }
   }
   eb_local_account_update(la);
@@ -664,6 +668,7 @@
       do_login = 0;
       acc->status = EB_ACCOUNT_OFFLINE;
       acc->status_string = strdup("Offline");
+      eb_buddy_logout(acc);
       break;
     }
     default:
@@ -739,7 +744,8 @@
  *      members - the initial members of the conference (null terminated list)
  */
 void ext_yahoo_got_conf_invite(int id, char *who, char *room, char *msg, YList *members)
-{}
+{
+}
 
 
 
@@ -754,7 +760,8 @@
  * 	msg  - the declining message
  */
 void ext_yahoo_conf_userdecline(int id, char *who, char *room, char *msg)
-{}
+{
+}
 
 
 
@@ -768,7 +775,8 @@
  * 	room - the room joined
  */
 void ext_yahoo_conf_userjoin(int id, char *who, char *room)
-{}
+{
+}
 
 
 
@@ -782,7 +790,8 @@
  * 	room - the room left
  */
 void ext_yahoo_conf_userleave(int id, char *who, char *room)
-{}
+{
+}
 
 
 /*
@@ -795,7 +804,8 @@
  *      members - the initial members of the chatroom (null terminated YList of yahoo_chat_member's) Must be freed by the client
  */
 void ext_yahoo_chat_cat_xml(int id, char *xml)
-{}
+{
+}
 
 /*
  * Name: ext_yahoo_chat_join
@@ -808,7 +818,8 @@
  * 	fd      - the socket where the connection is coming from (for tracking)
  */
 void ext_yahoo_chat_join(int id, char *room, char *topic, YList *members, int fd)
-{}
+{
+}
 
 /*
  * Name: ext_yahoo_chat_userjoin
@@ -819,7 +830,8 @@
  * 	who  - the user who has joined, Must be freed by the client
  */
 void ext_yahoo_chat_userjoin(int id, char *room, struct yahoo_chat_member *who)
-{}
+{
+}
 
 
 
@@ -833,7 +845,8 @@
  * 	who  - the user who has left (Just the User ID)
  */
 void ext_yahoo_chat_userleave(int id, char *room, char *who)
-{}
+{
+}
 
 
 
@@ -1331,13 +1344,14 @@
 {
   yahoo_connect_callback cb;
   void * data;
+  int done;
 } conn_cb_data;
 
 static void conn_cb(int fd, void * data)
 {
   conn_cb_data * d = (conn_cb_data *)data;
   d->cb(fd, (fd >= 0) ? (0) : (errno), d->data);
-  free(d);
+  d->done = 1;
 }
 
 /*
@@ -1361,9 +1375,14 @@
 int ext_yahoo_connect_async(int id, char *host, int port, 
 		yahoo_connect_callback callback, void *callback_data)
 {
+  int rval;
   conn_cb_data * d = (conn_cb_data *)malloc(sizeof(conn_cb_data));
   d->cb = callback;
   d->data = callback_data;
-  return eb_connect_socket(host, port, conn_cb, d);
+  d->done = 0;
+  rval = eb_connect_socket(host, port, conn_cb, d);
+  if (d->done && rval > 0)
+    return 0; // Successful, but callback has already been called
+  return rval;
 }
 
Index: core/plugins/yahoo/libyahoo2.c
===================================================================
--- core/plugins/yahoo/libyahoo2.c	(revision 307)
+++ core/plugins/yahoo/libyahoo2.c	(working copy)
@@ -373,7 +373,7 @@
 }
 
 /* call repeatedly to get the next one */
-/*
+
 static struct yahoo_input_data * find_input_by_id(int id)
 {
 	YList *l;
@@ -384,8 +384,8 @@
 	}
 	return NULL;
 }
-*/
 
+
 static struct yahoo_input_data * find_input_by_id_and_webcam_user(int id, const char * who)
 {
 	YList *l;
@@ -795,19 +795,6 @@
 	return ret;
 }
 
-void yahoo_close(int id) 
-{
-	struct yahoo_data *yd = find_conn_by_id(id);
-	if(!yd)
-		return;
-
-	del_from_list(yd);
-
-	yahoo_free_data(yd);
-	if(id == last_id)
-		last_id--;
-}
-
 static void yahoo_input_close(struct yahoo_input_data *yid) 
 {
 	inputs = y_list_remove(inputs, yid);
@@ -835,6 +822,26 @@
 	FREE(yid);
 }
 
+void yahoo_close(int id) 
+{
+	struct yahoo_input_data *yid = NULL;
+	struct yahoo_data *yd = find_conn_by_id(id);
+	if(!yd)
+		return;
+
+	del_from_list(yd);
+
+	while((yid = find_input_by_id(id)) != NULL)
+	{
+		yahoo_input_close(yid);
+	}
+	
+	yahoo_free_data(yd);
+
+	if(id == last_id)
+		last_id--;
+}
+
 static int is_same_bud(const void * a, const void * b) {
 	const struct yahoo_buddy *subject = a;
 	const struct yahoo_buddy *object = b;
@@ -3612,10 +3619,6 @@
 	}
 
 	
-/*	do {
-		yahoo_input_close(yid);
-	} while((yid = find_input_by_id(id)));*/
-	
 }
 
 void yahoo_get_list(int id)
-------- Patch Ends --------


-- 
Craig West         Ph: (416) 666-1645	|  It's not a bug,
[email protected]              	|  It's a feature...