Re: EbQt: Yahoo buddies online not showing up

"A. Craig West" <[email protected]> Mon, 16 Feb 2004 00:38:09 -0500 (EST)
Newsgroups gmane.network.everybuddy.user
Message-ID <[email protected]>
On Sun, 15 Feb 2004, Meredydd wrote:

> Craig, have you taken a look at this yet? I thought we'd sorted out what 
> was most probably the problem.

Conveniently enough, I have a patch that clears up a bunch of yahoo issues.
Unfortunately for your reviewing pleasure, I also reformatted a bunch of stuff
to make it readable (by me, that is :-) ). This patch should fix up the problem
where yahoo buddies don't show status properly on interfaces that are open
when yahoo is connected, and fixes logging in and out of yahoo.

----------Patch Begins--------------------
Index: yahoo.c
===================================================================
--- yahoo.c	(revision 260)
+++ yahoo.c	(working copy)
@@ -42,7 +42,8 @@
 #include "yahoo2_callbacks.h"
 #include "yahoo_util.h"
 
-typedef struct _eb_ylad {
+typedef struct _eb_ylad
+{
   int id;
   int upcoming;
   int invisible;
@@ -56,16 +57,38 @@
 int yahoo_plugin_init(void);
 int yahoo_plugin_finish(void);
 
-eb_plugin_info yahoo_LTX_plugin_info = {"Yahoo! messenger", "Philip Tellis's libyahoo2", "(alpha)", "2003-11-11", yahoo_plugin_init, yahoo_plugin_finish};
-eb_service yahoo_service={"Yahoo", "Philip Tellis's libyahoo2", &yahoo_callbacks, SERVICE_CAN_OFFLINE, "#de9400", NULL, NULL, NULL, NULL};
+eb_plugin_info yahoo_LTX_plugin_info =
+{
+  "Yahoo! messenger",
+  "Philip Tellis's libyahoo2",
+  "(alpha)", "2003-11-11",
+  yahoo_plugin_init,
+  yahoo_plugin_finish
+};
 
+eb_service yahoo_service =
+{
+  "Yahoo",
+  "Philip Tellis's libyahoo2",
+  &yahoo_callbacks,
+  SERVICE_CAN_OFFLINE,
+  "#de9400",
+  NULL,
+  NULL,
+  NULL,
+  NULL
+};
+
 static eb_local_account * get_local(int id)
 {
   EList * n;
-  for(n=local_accounts; n!=NULL; n=n->next)
+  for (n = local_accounts; n != NULL; n = n->next)
   {
-    eb_local_account * la=(eb_local_account *)n->data;
-    if(la->service==&yahoo_service && GET_LAD(la)->id==id) { return la; }
+    eb_local_account * la = (eb_local_account *)n->data;
+    if (la->service == &yahoo_service && GET_LAD(la)->id == id)
+	{
+	  return la;
+	}
   }
   return NULL;
 }
@@ -74,126 +97,192 @@
 
 static void login(eb_local_account * la)
 {
-  int inv=(eb_get_value(la->config_key, "yahoo/login_invisible")[0]=='1');
-  set_current_state(la, inv?"Invisible":"Online");
+  la->connected = 1;
+  la->ready = 0;
+  eb_local_account_update(la);
+
+  eb_ylad * lad = GET_LAD(la);
+  if (lad->id != -1)
+  {
+    yahoo_close(lad->id);
+	lad->id = -1;
+  }
+  lad->id = yahoo_init(la->handle, eb_get_value(la->config_key, "password"));
+
+  lad->invisible = (eb_get_value(la->config_key, "yahoo/login_invisible")[0] == '1');
+  int istate = (lad->invisible) ? (YAHOO_STATUS_INVISIBLE) : (YAHOO_STATUS_AVAILABLE);
+  yahoo_login(lad->id, istate);
+
+  set_current_state(la, (lad->invisible) ? "Invisible" : "Online");
 }
 
 static void logout(eb_local_account * la)
 {
-  eb_ylad * lad=GET_LAD(la);
-  if(lad->id!=-1) { yahoo_close(lad->id); lad->id=-1; }
+  eb_ylad * lad = GET_LAD(la);
+  if (!la->connected)
+  {
+    return; // already done
+  }
+
   free(la->status_string);
-  la->status_string=strdup("Offline");
-  la->ready=la->connected=0;
+  la->status_string = strdup("Offline");
+  la->ready = la->connected = 0;
   eb_local_account_update(la);
+  if (lad->id != -1)
+  {
+    yahoo_logoff(lad->id);
+    yahoo_close(lad->id);
+	lad->id = -1;
+  }
 }
 
 static void set_current_state(eb_local_account * la, char * state)
 {
-  eb_ylad * lad=GET_LAD(la);
+  eb_ylad * lad = GET_LAD(la);
   int st_id;
-  char * st_str=NULL;
+  char * st_str = NULL;
   
-  if(!strcmp(state, "Online"))
-  {
-    st_id=YAHOO_STATUS_AVAILABLE;
-  } else if(!strcmp(state, "BRB")) {
-    st_id=YAHOO_STATUS_BRB;
-  } else if(!strcmp(state, "Busy")) {
-    st_id=YAHOO_STATUS_BUSY;
-  } else if(!strcmp(state, "Not at Home")) {
-    st_id=YAHOO_STATUS_NOTATHOME;
-  } else if(!strcmp(state, "Not at Desk")) {
-    st_id=YAHOO_STATUS_NOTATDESK;
-  } else if(!strcmp(state, "Not in Office")) {
-    st_id=YAHOO_STATUS_NOTINOFFICE;
-  } else if(!strcmp(state, "Phone")) {
-    st_id=YAHOO_STATUS_ONPHONE;
-  } else if(!strcmp(state, "Vacation")) {
-    st_id=YAHOO_STATUS_ONVACATION;
-  } else if(!strcmp(state, "Lunch")) {
-    st_id=YAHOO_STATUS_OUTTOLUNCH;
-  } else if(!strcmp(state, "Stepped Out")) {
-    st_id=YAHOO_STATUS_STEPPEDOUT;
-  } else if(!strcmp(state, "Invisible")) {
-    st_id=YAHOO_STATUS_INVISIBLE;
-  } else if(!strcmp(state, "Idle")) {
-    st_id=YAHOO_STATUS_IDLE;
-  } else if(!strcmp(state, "Offline")) {
+  if (!strcmp(state, "Offline")) {
     logout(la);
     return;
-  } else {
-    st_id=YAHOO_STATUS_CUSTOM;
-    st_str=state;
   }
-  
-  if(lad->id==-1)
+  else
   {
-    int istate;
-    lad->invisible=eb_get_value(la->config_key, "yahoo/login_invisible")[0]=='1';
-    istate=(lad->invisible)?(YAHOO_STATUS_INVISIBLE):(YAHOO_STATUS_AVAILABLE);
-    
-    lad->id=yahoo_init(la->handle, eb_get_value(la->config_key, "password"));
-    yahoo_login(lad->id, istate);
-    la->connected=1;
-    la->ready=0;
-    eb_local_account_update(la);
-  } else if(la->ready) {
-    yahoo_set_away(lad->id, st_id, st_str, away_msg!=NULL);
-    free(la->status_string);
-    la->status_string=strdup(state);
-    lad->invisible=(st_id==YAHOO_STATUS_INVISIBLE);
+	// Check if we are connected yet
+  	if (!la->connected)
+	{
+	  // connect to the server
+	  login(la);
+	}
+
+	if (!strcmp(state, "Online"))
+	{
+	  st_id = YAHOO_STATUS_AVAILABLE;
+	}
+	else if (!strcmp(state, "BRB"))
+	{
+	  st_id = YAHOO_STATUS_BRB;
+	}
+	else if (!strcmp(state, "Busy"))
+	{
+	  st_id = YAHOO_STATUS_BUSY;
+	}
+	else if (!strcmp(state, "Not at Home"))
+	{
+	  st_id = YAHOO_STATUS_NOTATHOME;
+	}
+	else if (!strcmp(state, "Not at Desk"))
+	{
+	  st_id = YAHOO_STATUS_NOTATDESK;
+	}
+	else if (!strcmp(state, "Not in Office"))
+	{
+	  st_id = YAHOO_STATUS_NOTINOFFICE;
+	}
+	else if (!strcmp(state, "Phone"))
+	{
+	  st_id = YAHOO_STATUS_ONPHONE;
+	}
+	else if (!strcmp(state, "Vacation"))
+	{
+	  st_id = YAHOO_STATUS_ONVACATION;
+	}
+	else if (!strcmp(state, "Lunch"))
+	{
+	  st_id = YAHOO_STATUS_OUTTOLUNCH;
+	}
+	else if (!strcmp(state, "Stepped Out"))
+	{
+	  st_id = YAHOO_STATUS_STEPPEDOUT;
+	}
+	else if (!strcmp(state, "Invisible"))
+	{
+	  st_id = YAHOO_STATUS_INVISIBLE;
+	  lad->invisible = 1;
+	}
+	else if (!strcmp(state, "Idle"))
+	{
+	  st_id = YAHOO_STATUS_IDLE;
+	}
+	else
+	{
+	  st_id = YAHOO_STATUS_CUSTOM;
+	  st_str = state;
+	}
+	
+	if (la->ready)
+	{
+	  // Only set the away message if the connection is ready
+	  yahoo_set_away(lad->id, st_id, st_str, away_msg != NULL);
+	  free(la->status_string);
+	  la->status_string = strdup(state);
+	}
   }
 }
 
 static void set_away(eb_local_account * la, char * shortmsg, char * longmsg)
 {
-  char * st=shortmsg;
-  char * lwr=strdup(longmsg);
+  char * st = shortmsg;
+  char * lwr = strdup(longmsg);
   int a;
-  for(a=0; lwr[a]!='\0'; a++) { lwr[a]=tolower(lwr[a]); }
+  for (a = 0; lwr[a] != '\0'; a++)
+  {
+    lwr[a] = tolower(lwr[a]);
+  }
   
-  if(strstr(lwr, "busy"))
+  if (strstr(lwr, "busy"))
   {
-    st="Busy";
-  } else if(strstr(lwr, "brb") || strstr(lwr, "be right back")) {
-    st="BRB";
-  } else if(strstr(lwr, "phone")) {
-    st="Phone";
-  } else if(strstr(lwr, "eat") || strstr(lwr, "lunch") || strstr(lwr, "tea")
-    || strstr(lwr, "supper") || strstr(lwr, "dinner")) {
-    st="Lunch";
+    st = "Busy";
   }
+  else if (strstr(lwr, "brb") || strstr(lwr, "be right back"))
+  {
+    st = "BRB";
+  }
+  else if (strstr(lwr, "phone"))
+  {
+    st = "Phone";
+  }
+  else if (strstr(lwr, "eat") || strstr(lwr, "lunch") || strstr(lwr, "tea")
+    || strstr(lwr, "supper") || strstr(lwr, "dinner"))
+  {
+    st = "Lunch";
+  }
   
-  if(!GET_LAD(la)->invisible)
-  { set_current_state(la, st); }
+  if (!GET_LAD(la)->invisible)
+  {
+    set_current_state(la, st);
+  }
   
   free(lwr);
 }
 
 static void unset_away(eb_local_account * la)
 {
-  if(!GET_LAD(la)->invisible)
-  { yahoo_set_away(GET_LAD(la)->id, YAHOO_STATUS_AVAILABLE, NULL, 0); free(la->status_string); la->status_string=strdup("Online"); }
+  if (!GET_LAD(la)->invisible)
+  {
+    yahoo_set_away(GET_LAD(la)->id, YAHOO_STATUS_AVAILABLE, NULL, 0);
+	free(la->status_string);
+	la->status_string = strdup("Online");
+  }
 }
 
 static void setup_local_account(eb_local_account * la)
 {
   char * buf1;
   char * buf2;
-  eb_ylad * lad=(eb_ylad *)malloc(sizeof(eb_ylad));
+  eb_ylad * lad = (eb_ylad *)malloc(sizeof(eb_ylad));
   
-  la->protocol_data=lad;
+  la->protocol_data = lad;
   
-  lad->id=-1;
-  lad->upcoming=0;
-  lad->invisible=0;
+  lad->id = -1;
+  lad->upcoming = 0;
+  lad->invisible = 0;
 
-  buf1=(char *)malloc(strlen(la->handle)+strlen(la->service_name)+2);
+  buf1 = (char *)malloc(strlen(la->handle) + strlen(la->service_name) + 2);
   sprintf(buf1, "%s_%s", la->handle, la->service_name);
-  buf2=(char *)malloc(strlen(la->handle)+strlen(la->service_name)+4);
+  buf2 = (char *)malloc(strlen(la->handle) + strlen(la->service_name) + 4);
   sprintf(buf2, "%s (%s)", la->handle, la->service_name);
-  lad->prefpage=eb_make_pref_page(account_prefs, buf1, buf2);
+  lad->prefpage = eb_make_pref_page(account_prefs, buf1, buf2);
   free(buf1);
   free(buf2);
   
@@ -203,7 +292,7 @@
 
 static void release_local_account(eb_local_account * la)
 {
-  eb_ylad * lad=GET_LAD(la);
+  eb_ylad * lad = GET_LAD(la);
   eb_destroy_pref_page(lad->prefpage);
   free(lad);
 }
@@ -217,11 +306,13 @@
 static void del_user(eb_account * acc)
 {
   const YList * n;
-  for(n=yahoo_get_buddylist(GET_LAD(acc->buddy_of)->id); n!=NULL; n=n->next)
+  for (n = yahoo_get_buddylist(GET_LAD(acc->buddy_of)->id); n != NULL; n = n->next)
   {
-    struct yahoo_buddy * yb=(struct yahoo_buddy *)n->data;
-    if(!strcmp(yb->id, acc->handle))
-    { yahoo_remove_buddy(GET_LAD(acc->buddy_of)->id, yb->id, yb->group); }
+    struct yahoo_buddy * yb = (struct yahoo_buddy *)n->data;
+    if (!strcmp(yb->id, acc->handle))
+    {
+	  yahoo_remove_buddy(GET_LAD(acc->buddy_of)->id, yb->id, yb->group);
+	}
   }
   
   eb_del_account(acc);
@@ -230,17 +321,19 @@
 static void change_group(eb_account * acc, char * new_group)
 {
   const YList * n;
-  int done=0;
-  for(n=yahoo_get_buddylist(GET_LAD(acc->buddy_of)->id); n!=NULL; n=n->next)
+  int done = 0;
+  for (n = yahoo_get_buddylist(GET_LAD(acc->buddy_of)->id); n != NULL; n = n->next)
   {
-    struct yahoo_buddy * yb=(struct yahoo_buddy *)n->data;
-    if(!strcmp(yb->id, acc->handle))
+    struct yahoo_buddy * yb = (struct yahoo_buddy *)n->data;
+    if (!strcmp(yb->id, acc->handle))
     {
-      if(!done)
+      if (!done)
       {
-        done=1;
+        done = 1;
         yahoo_change_buddy_group(GET_LAD(acc->buddy_of)->id, yb->id, yb->group, new_group);
-      } else {
+      }
+	  else
+	  {
         yahoo_remove_buddy(GET_LAD(acc->buddy_of)->id, yb->id, yb->group);
       }
     }
@@ -254,11 +347,18 @@
   
   eb_ylad * lad=GET_LAD(to->buddy_of);
   
-  rbuf=eb_filter_string(EB_PREFILTER_OUT, msg, to);
-  if(rbuf==NULL) { return NULL; }
+  rbuf = eb_filter_string(EB_PREFILTER_OUT, msg, to);
+  if (rbuf == NULL)
+  {
+    return NULL;
+  }
   
-  sbuf=eb_filter_string(EB_POSTFILTER_OUT, strdup(rbuf), to);
-  if(sbuf==NULL) { free(rbuf); return NULL; }
+  sbuf = eb_filter_string(EB_POSTFILTER_OUT, strdup(rbuf), to);
+  if (sbuf == NULL)
+  {
+    free(rbuf);
+	return NULL;
+  }
   
   yahoo_send_im(lad->id, NULL, to->handle, sbuf, 1);
   
@@ -269,37 +369,37 @@
 
 int yahoo_plugin_init(void)
 {
-  EList * states=NULL;
+  EList * states = NULL;
   printf("Hi-ho, hi-ho, Yahoo here we go!\n");
 
   memset(&yahoo_callbacks, 0, sizeof(yahoo_callbacks));
   
-  yahoo_callbacks.login=login;
-  yahoo_callbacks.logout=logout;
-  yahoo_callbacks.set_current_state=set_current_state;
-  yahoo_callbacks.set_away=set_away;
-  yahoo_callbacks.unset_away=unset_away;
-  yahoo_callbacks.setup_local_account=setup_local_account;
-  yahoo_callbacks.release_local_account=release_local_account;
-  yahoo_callbacks.add_user=add_user;
-  yahoo_callbacks.del_user=del_user;
-  yahoo_callbacks.change_group=change_group;
-  yahoo_callbacks.send_im=send_im;
+  yahoo_callbacks.login = login;
+  yahoo_callbacks.logout = logout;
+  yahoo_callbacks.set_current_state = set_current_state;
+  yahoo_callbacks.set_away = set_away;
+  yahoo_callbacks.unset_away = unset_away;
+  yahoo_callbacks.setup_local_account = setup_local_account;
+  yahoo_callbacks.release_local_account = release_local_account;
+  yahoo_callbacks.add_user = add_user;
+  yahoo_callbacks.del_user = del_user;
+  yahoo_callbacks.change_group = change_group;
+  yahoo_callbacks.send_im = send_im;
   
-  states=e_list_append(states, strdup("Online"));
-  states=e_list_append(states, strdup("BRB"));
-  states=e_list_append(states, strdup("Busy"));
-  states=e_list_append(states, strdup("Not at Home"));
-  states=e_list_append(states, strdup("Not at Desk"));
-  states=e_list_append(states, strdup("Not in Office"));
-  states=e_list_append(states, strdup("Phone"));
-  states=e_list_append(states, strdup("Vacation"));
-  states=e_list_append(states, strdup("Lunch"));
-  states=e_list_append(states, strdup("Stepped Out"));
-  states=e_list_append(states, strdup("Invisible"));
-  states=e_list_append(states, strdup("Idle"));
-  states=e_list_append(states, strdup("Offline"));
-  yahoo_service.states=states;
+  states = e_list_append(states, strdup("Online"));
+  states = e_list_append(states, strdup("BRB"));
+  states = e_list_append(states, strdup("Busy"));
+  states = e_list_append(states, strdup("Not at Home"));
+  states = e_list_append(states, strdup("Not at Desk"));
+  states = e_list_append(states, strdup("Not in Office"));
+  states = e_list_append(states, strdup("Phone"));
+  states = e_list_append(states, strdup("Vacation"));
+  states = e_list_append(states, strdup("Lunch"));
+  states = e_list_append(states, strdup("Stepped Out"));
+  states = e_list_append(states, strdup("Invisible"));
+  states = e_list_append(states, strdup("Idle"));
+  states = e_list_append(states, strdup("Offline"));
+  yahoo_service.states = states;
   
   eb_load_service(&yahoo_service);
 
@@ -325,24 +425,31 @@
  */
 void ext_yahoo_login_response(int id, int succ, char *url)
 {
-  eb_local_account * la=get_local(id);
-  if(la==NULL) { printf("Martian Yahoo connection\n"); return; }
-  switch(succ)
+  eb_local_account * la = get_local(id);
+  if (la == NULL)
   {
-    case(YAHOO_LOGIN_OK) : {
-      la->ready=1;
+    printf("Martian Yahoo connection\n");
+	return;
+  }
+
+  switch (succ)
+  {
+    case YAHOO_LOGIN_OK:
+	{
+      la->ready = 1;
       free(la->status_string);
-      la->status_string=strdup(GET_LAD(la)->invisible?"Invisible":"Online");
+      la->status_string = strdup(GET_LAD(la)->invisible ? "Invisible" : "Online");
       break;
     }
-    default : {
+    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;
+      la->ready = la->connected = 0;
 	  free(la->status_string);
-      la->status_string=strdup("Offline");
+      la->status_string = strdup("Offline");
       printf("Login error for %s (Yahoo id %d)\n", la->handle, id);
     }
   }
@@ -361,38 +468,49 @@
  */
 void ext_yahoo_got_buddies(int id, YList * buds)
 {
-  eb_local_account * la=get_local(id);
+  eb_local_account * la = get_local(id);
   YList * n;
   EList * en;
-  int p=0;
+  int p = 0;
   
-  if(la==NULL) { printf("Got buddies on a martian account!\n"); return; }
+  if (la == NULL)
+  {
+    printf("Got buddies on a martian account!\n");
+	return;
+  }
   
-  for(en=la->buddies; en!=NULL; en=en->next)
+  for (en = la->buddies; en != NULL; en = en->next)
   {
-    eb_account * acc=(eb_account *)en->data;
-    acc->protocol_data=NULL;
+    eb_account * acc = (eb_account *)en->data;
+    acc->protocol_data = NULL;
   }
 
-  for(n=buds; n!=NULL; n=n->next)
+  for (n = buds; n != NULL; n = n->next)
   {
-    struct yahoo_buddy * yb=(struct yahoo_buddy *)n->data;
-    eb_account * acc=eb_get_account(la->handle, "Yahoo", yb->id);
-    if(acc==NULL)
-    { acc=eb_add_account_plus(yb->group, (yb->real_name!=NULL)?(yb->real_name):(yb->id), la, yb->id); }
-    acc->protocol_data=&p;
+    struct yahoo_buddy * yb = (struct yahoo_buddy *)n->data;
+    eb_account * acc = eb_get_account(la->handle, "Yahoo", yb->id);
+    if (acc == NULL)
+    {
+	  acc = eb_add_account_plus(yb->group, (yb->real_name != NULL) ? (yb->real_name) : (yb->id), la, yb->id); }
+    acc->protocol_data = &p;
   }
 
-  for(en=la->buddies; en!=NULL; en=en->next)
+  for (en = la->buddies; en != NULL; en = en->next)
   {
-    eb_account * acc=(eb_account *)en->data;
+    eb_account * acc = (eb_account *)en->data;
     
-    if(acc->protocol_data==NULL) // wasn't on the list
-    { p=1; free(acc->status_string); acc->status_string=strdup("???"); }
+    if (acc->protocol_data == NULL) // wasn't on the list
+    {
+	  p = 1;
+	  free(acc->status_string);
+	  acc->status_string = strdup("???");
+	}
   }
   
-  if(p)
-  { eb_show_error("Yahoo! Buddy list reverse mismatch: You have one or more buddies on your buddy list but not on the Yahoo server.", "Warning"); }
+  if (p)
+  {
+    eb_show_error("Yahoo! Buddy list reverse mismatch: You have one or more buddies on your buddy list but not on the Yahoo server.", "Warning");
+  }
 }
 
 
@@ -457,44 +575,103 @@
  */
 void ext_yahoo_status_changed(int id, char *who, int stat, char *msg, int away)
 {
-  eb_local_account * la=get_local(id);
+  eb_local_account * la = get_local(id);
   eb_account * acc;
-  if(la==NULL) { printf("Martian Yahoo connection\n"); return; }
-  acc=eb_get_account(la->handle, "Yahoo", who);
-  if(acc==NULL)
-  { acc=eb_add_account_plus("Unknown", who, la, who); }
+  int do_login = 0;
+  if (la == NULL)
+  {
+    printf("Martian Yahoo connection\n");
+	return;
+  }
+  acc = eb_get_account(la->handle, "Yahoo", who);
+  if (acc == NULL)
+  {
+    acc = eb_add_account_plus("Unknown", who, la, who);
+  }
   
+  if (acc->status == EB_ACCOUNT_OFFLINE)
+  {
+    do_login = 1;
+  }
   free(acc->status_string);
-  acc->status=EB_ACCOUNT_AWAY;
-  switch(stat)
+  acc->status = EB_ACCOUNT_AWAY;
+  switch (stat)
   {
-    case(YAHOO_STATUS_AVAILABLE) : {
-      acc->status=EB_ACCOUNT_ONLINE;
-      acc->status_string=strdup("");
+    case YAHOO_STATUS_AVAILABLE:
+	{
+      acc->status = EB_ACCOUNT_ONLINE;
+      acc->status_string = strdup("");
       break;
     }
-    case(YAHOO_STATUS_BRB) : { acc->status_string=strdup("BRB"); break; }
-    case(YAHOO_STATUS_BUSY) : { acc->status_string=strdup("Busy"); break; }
-    case(YAHOO_STATUS_NOTATHOME) : { acc->status_string=strdup("Not at Home"); break; }
-    case(YAHOO_STATUS_NOTATDESK) : { acc->status_string=strdup("Not at Desk"); break; }
-    case(YAHOO_STATUS_NOTINOFFICE) : { acc->status_string=strdup("Not in Office"); break; }
-    case(YAHOO_STATUS_ONPHONE) : { acc->status_string=strdup("Phone"); break; }
-    case(YAHOO_STATUS_ONVACATION) : { acc->status_string=strdup("On Vacation"); break; }
-    case(YAHOO_STATUS_OUTTOLUNCH) : { acc->status_string=strdup("Lunch"); break; }
-    case(YAHOO_STATUS_STEPPEDOUT) : { acc->status_string=strdup("Stepped Out"); break; }
-    case(YAHOO_STATUS_IDLE) : { acc->status_string=strdup("Idle"); break; }
-
-    case(YAHOO_STATUS_OFFLINE) : {
-      acc->status=EB_ACCOUNT_OFFLINE;
-      acc->status_string=strdup("Offline");
+    case YAHOO_STATUS_BRB:
+	{
+	  acc->status_string = strdup("BRB");
+	  break;
+	}
+    case YAHOO_STATUS_BUSY:
+	{
+	  acc->status_string = strdup("Busy");
+	  break;
+	}
+    case YAHOO_STATUS_NOTATHOME:
+	{
+	  acc->status_string = strdup("Not at Home");
+	  break;
+	}
+    case YAHOO_STATUS_NOTATDESK:
+	{
+	  acc->status_string = strdup("Not at Desk");
+	  break;
+	}
+    case YAHOO_STATUS_NOTINOFFICE:
+	{
+	  acc->status_string = strdup("Not in Office");
+	  break;
+	}
+    case YAHOO_STATUS_ONPHONE:
+	{
+	  acc->status_string = strdup("Phone");
+	  break;
+	}
+    case YAHOO_STATUS_ONVACATION:
+	{
+	  acc->status_string = strdup("On Vacation");
+	  break;
+	}
+    case YAHOO_STATUS_OUTTOLUNCH:
+	{
+	  acc->status_string = strdup("Lunch");
+	  break;
+	}
+    case YAHOO_STATUS_STEPPEDOUT:
+	{
+	  acc->status_string = strdup("Stepped Out");
+	  break;
+	}
+    case YAHOO_STATUS_IDLE:
+	{
+	  acc->status_string = strdup("Idle");
+	  break;
+	}
+    case YAHOO_STATUS_OFFLINE:
+	{
+	  do_login = 0;
+      acc->status = EB_ACCOUNT_OFFLINE;
+      acc->status_string = strdup("Offline");
       break;
     }
-    
-    default : {
-      acc->status=away?EB_ACCOUNT_AWAY:EB_ACCOUNT_ONLINE;
-      acc->status_string=strdup(msg);
+    default:
+	{
+      acc->status = away ? EB_ACCOUNT_AWAY : EB_ACCOUNT_ONLINE;
+      acc->status_string = strdup(msg);
     }
   }
+
+  if (do_login)
+  {
+    eb_buddy_login(acc);
+  }
+  eb_buddy_update_status(acc);
 }
 
 
@@ -516,24 +693,30 @@
  */
 void ext_yahoo_got_im(int id, char *who, char *msg, long tm, int stat, int utf8)
 {
-  eb_local_account * la=get_local(id);
+  eb_local_account * la = get_local(id);
   eb_account * acc;
-  if(la==NULL) { printf("Martian Yahoo connection\n"); return; }
-  acc=eb_get_account(la->handle, "Yahoo", who);
-  if(acc==NULL)
+  if (la == NULL)
   {
-    acc=eb_add_account_plus("Unknown", who, la, who);
-    acc->status=EB_ACCOUNT_AWAY;
+    printf("Martian Yahoo connection\n");
+	return;
+  }
+  acc = eb_get_account(la->handle, "Yahoo", who);
+  if (acc == NULL)
+  {
+    acc = eb_add_account_plus("Unknown", who, la, who);
+    acc->status = EB_ACCOUNT_AWAY;
     free(acc->status_string);
-    acc->status_string=strdup("???");
+    acc->status_string = strdup("???");
   }
   
-  if(stat==2)
+  if (stat == 2)
   {
     eb_notify_3rdperson(acc->contact, "<font color=red><i><b>Error</b>: Failed to send your last message</i></font>");
-  } else {
-    eb_incoming_message(acc, (utf8)?(strdup(msg)):(y_str_to_utf8(msg)));
   }
+  else
+  {
+    eb_incoming_message(acc, (utf8) ? (strdup(msg)) : (y_str_to_utf8(msg)));
+  }
 }
 
 
@@ -754,7 +937,7 @@
  */
 void ext_yahoo_rejected(int id, char *who, char *msg)
 {
-  char * buf=(char *)malloc(strlen(who)+128);
+  char * buf = (char *)malloc(strlen(who) + 128);
   sprintf(buf, "The user \"%s\" has refused to allow you to see their status. They will therefore appear permanently offline.", who);
   eb_show_error(buf, "Buddy list rejection");
   free(buf);
@@ -772,7 +955,7 @@
  */
 void ext_yahoo_typing_notify(int id, char *who, int stat)
 {
-  printf("%s has %sed typing\n", who, stat?"start":"stop");
+  printf("%s has %sed typing\n", who, stat ? "start" : "stop");
 }
 
 
@@ -803,17 +986,27 @@
  */
 void ext_yahoo_mail_notify(int id, char *from, char *subj, int cnt)
 {
-  eb_local_account * la=get_local(id);
-  if(la==NULL) { printf("Martian Yahoo connection\n"); return; }
-  if(eb_get_value(la->config_key, "mail_notify")[0]=='0') { return; }
+  eb_local_account * la = get_local(id);
+  if (la == NULL)
+  {
+    printf("Martian Yahoo connection\n");
+	return;
+  }
+
+  if (eb_get_value(la->config_key, "mail_notify")[0] == '0')
+  {
+    return;
+  }
   
-  if(cnt==0)
+  if (cnt == 0)
   {
-    char * buf=(char *)malloc(strlen(from)+strlen(subj)+128);
+    char * buf = (char *)malloc(strlen(from) + strlen(subj) + 128);
     sprintf(buf, "You have new mail in your inbox.\nFrom: %s\nSubject: %s", from, subj);
     eb_show_error(buf, "New mail");
     free(buf);
-  } else {
+  }
+  else
+  {
     char buf[512];
     sprintf(buf, "Your inbox contains %d messages", cnt);
     eb_show_error(buf, "Yahoo mail");
@@ -897,7 +1090,7 @@
  */
 void ext_yahoo_webcam_invite_reply(int id, char *from, int accept)
 {
-  printf("%s has %sed your webcam request\n", from, accept?"accept":"reject");
+  printf("%s has %sed your webcam request\n", from, accept ? "accept" : "reject");
 }
 
 
@@ -949,20 +1142,24 @@
 void ext_yahoo_error(int id, char *err, int fatal)
 {
   char * buf;
-  eb_local_account * la=get_local(id);
-  if(la==NULL) { printf("Error on martian Yahoo acct\n"); return; }
+  eb_local_account * la = get_local(id);
+  if (la == NULL)
+  {
+    printf("Error on martian Yahoo acct\n");
+	return;
+  }
 
-  buf=(char *)malloc(strlen(err)+strlen(la->handle)+128);
+  buf = (char *)malloc(strlen(err) + strlen(la->handle) + 128);
   sprintf(buf, "An error has occurred on the local account \"%s\":\n%s%s",
-    la->handle, err, fatal?"This error is fatal, and the connection will now terminate.":"");
+    la->handle, err, fatal ? "This error is fatal, and the connection will now terminate." : "");
   eb_show_error(buf, "Yahoo error");
   free(buf);
   
-  if(fatal)
+  if (fatal)
   {
-    la->connected=la->ready=0;
+    la->connected = la->ready = 0;
     free(la->status_string);
-    la->status_string=strdup("Offline");
+    la->status_string = strdup("Offline");
     eb_local_account_update(la);
   }
 }
@@ -1020,24 +1217,25 @@
 
 
 
-typedef struct _fd_data {
+typedef struct _fd_data
+{
   int id;
   int fd;
   int tag;
   void * moredata;
 } fd_data;
 
-EList * fds=NULL;
+EList * fds = NULL;
 
 static void rd_cb(void * data, int src, int conditions)
 {
-  fd_data * d=(fd_data *)data;
+  fd_data * d = (fd_data *)data;
   yahoo_read_ready(d->id, src, d->moredata);
 }
 
 static void wr_cb(void * data, int src, int conditions)
 {
-  fd_data * d=(fd_data *)data;
+  fd_data * d = (fd_data *)data;
   yahoo_write_ready(d->id, src, d->moredata);
 }
 
@@ -1056,17 +1254,19 @@
  */
 int ext_yahoo_add_handler(int id, int fd, yahoo_input_condition cond, void *data)
 {
-  fd_data * d=(fd_data *)malloc(sizeof(fd_data));
-  d->id=id;
-  d->fd=fd;
-  d->moredata=data;  
-  if(cond&YAHOO_INPUT_WRITE)
+  fd_data * d = (fd_data *)malloc(sizeof(fd_data));
+  d->id = id;
+  d->fd = fd;
+  d->moredata = data;  
+  if (cond & YAHOO_INPUT_WRITE)
   {
-    d->tag=eb_input_add(fd, EB_INPUT_WRITE, wr_cb, d);
-  } else {
-    d->tag=eb_input_add(fd, EB_INPUT_READ, rd_cb, d);
+    d->tag = eb_input_add(fd, EB_INPUT_WRITE, wr_cb, d);
   }
-  fds=e_list_append(fds, d);
+  else
+  {
+    d->tag = eb_input_add(fd, EB_INPUT_READ, rd_cb, d);
+  }
+  fds = e_list_append(fds, d);
   return d->tag;
 }
 
@@ -1083,14 +1283,14 @@
 void ext_yahoo_remove_handler(int id, int tag)
 {
   EList * n;
-  for(n=fds; n!=NULL; n=n->next)
+  for (n = fds; n != NULL; n = n->next)
   {
-    fd_data * d=(fd_data *)n->data;
-    if(d->id==id && d->tag==tag)
+    fd_data * d = (fd_data *)n->data;
+    if (d->id == id && d->tag == tag)
     {
       eb_input_remove(d->tag);
     
-      fds=e_list_remove_link(fds, n);
+      fds = e_list_remove_link(fds, n);
       e_list_free_1(n);
       free(d);
       
@@ -1121,15 +1321,16 @@
 
 
 
-typedef struct _conn_cb_data {
+typedef struct _conn_cb_data
+{
   yahoo_connect_callback cb;
   void * data;
 } 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);
+  conn_cb_data * d = (conn_cb_data *)data;
+  d->cb(fd, (fd >= 0) ? (0) : (errno), d->data);
   free(d);
 }
 
@@ -1154,9 +1355,9 @@
 int ext_yahoo_connect_async(int id, char *host, int port, 
 		yahoo_connect_callback callback, void *callback_data)
 {
-  conn_cb_data * d=(conn_cb_data *)malloc(sizeof(conn_cb_data));
-  d->cb=callback;
-  d->data=callback_data;
+  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);
 }
 
----------Patch Ends----------------------

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