changeset 6245:9083f92e0d58

[gaim-migrate @ 6739] this should really fix the infinite looping in server.c that KingAnt tried to fix. gaim_find_buddy() behaves like it used to now, and gaim_find_buddies() must be used to get all matching buddies committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sun, 20 Jul 2003 16:19:31 +0000
parents 519028f52516
children 2cb2a49f4bbe
files src/blist.c src/blist.h src/server.c src/session.c
diffstat 4 files changed, 50 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/src/blist.c	Sun Jul 20 14:11:43 2003 +0000
+++ b/src/blist.c	Sun Jul 20 16:19:31 2003 +0000
@@ -798,36 +798,53 @@
 
 struct buddy *gaim_find_buddy(GaimAccount *account, const char *name)
 {
-	static struct buddy *buddy = NULL;
+	struct buddy *buddy;
 	struct _gaim_hbuddy hb;
 	GaimBlistNode *group;
-	const char *n = NULL;
 
 	if (!gaimbuddylist)
 		return NULL;
-	
-	if (!name && !buddy)
+
+	if (!name)
 		return NULL;
 
-	if (name) {
-		group = gaimbuddylist->root;
-		n = name;
-	} else {
-		group = ((GaimBlistNode*)buddy)->parent->next;
-		n = buddy->name;
-	}
+	hb.name = normalize(name);
+	hb.account = account;
 
-	while (group) {
-		hb.name = normalize(n);
-		hb.account = account;
+	for(group = gaimbuddylist->root; group; group = group->next) {
 		hb.group = group;
 		if ((buddy = g_hash_table_lookup(gaimbuddylist->buddies, &hb)) != NULL)
 			return buddy;
-		group = ((GaimBlistNode*)group)->next;
 	}
+
 	return NULL;
 }
 
+GSList *gaim_find_buddies(GaimAccount *account, const char *name)
+{
+	struct buddy *buddy;
+	struct _gaim_hbuddy hb;
+	GaimBlistNode *group;
+	GSList *ret = NULL;
+
+	if (!gaimbuddylist)
+		return NULL;
+
+	if (!name)
+		return NULL;
+
+	hb.name = normalize(name);
+	hb.account = account;
+
+	for(group = gaimbuddylist->root; group; group = group->next) {
+		hb.group = group;
+		if ((buddy = g_hash_table_lookup(gaimbuddylist->buddies, &hb)) != NULL)
+			ret = g_slist_append(ret, buddy);
+	}
+
+	return ret;
+}
+
 struct group *gaim_find_group(const char *name)
 {
 	GaimBlistNode *node;
--- a/src/blist.h	Sun Jul 20 14:11:43 2003 +0000
+++ b/src/blist.h	Sun Jul 20 16:19:31 2003 +0000
@@ -411,7 +411,18 @@
  * @param account The account this buddy belongs to
  * @return        The buddy or NULL if the buddy does not exist
  */
-struct buddy *gaim_find_buddy(GaimAccount *account, const char *name);   
+struct buddy *gaim_find_buddy(GaimAccount *account, const char *name);
+
+/**
+ * Finds all buddies struct given a screenname and an account
+ *
+ * @param name    The buddy's screenname
+ * @param account The account this buddy belongs to
+ *
+ * @return        A GSList of buddies (which must be freed), or NULL if the buddy doesn't exist
+ */
+GSList *gaim_find_buddies(GaimAccount *account, const char *name);
+
 
 /**
  * Finds a group by name
--- a/src/server.c	Sun Jul 20 14:11:43 2003 +0000
+++ b/src/server.c	Sun Jul 20 16:19:31 2003 +0000
@@ -1019,6 +1019,7 @@
 {
 	GaimAccount *account;
 	struct buddy *b;
+	GSList *buddies;
 
 	account = gaim_connection_get_account(gc);
 	b = gaim_find_buddy(account, name);
@@ -1129,21 +1130,12 @@
 			gaim_pounce_execute(gc->account, b->name, GAIM_POUNCE_SIGNOFF);
 			system_log(log_signoff, gc, b, OPT_LOG_BUDDY_SIGNON);
 		}
-	}	
-	
+	}
+
 	gaim_blist_update_buddy_presence(b, loggedin);
 
-	/*
-	 * Now, update the rest of the buddies in the list.  This is weird, by 
-	 * the way.  Basically we call gaim_find_buddy() until it returns null.  
-	 * Calling gaim_find_buddy() with a name sets a static variable.  Then 
-	 * calling it without a name uses that static reference to return other 
-	 * stuff.  We can't be sure that the above code didn't call 
-	 * gaim_find_buddy() again with another buddy name, so we "reseed" the 
-	 * function here.
-	 */
-	b = gaim_find_buddy(account, name);
-	while ((b = gaim_find_buddy(gc->account, NULL)) != NULL) {
+	for (buddies = gaim_find_buddies(account, name); buddies; buddies = g_slist_remove(buddies, buddies->data)) {
+		b = buddies->data;
 		gaim_blist_update_buddy_presence(b, loggedin);
 		gaim_blist_update_buddy_idle(b, idle);
 		gaim_blist_update_buddy_evil(b, evil);
--- a/src/session.c	Sun Jul 20 14:11:43 2003 +0000
+++ b/src/session.c	Sun Jul 20 16:19:31 2003 +0000
@@ -24,6 +24,7 @@
  */
 #include "internal.h"
 
+#include "core.h"
 #include "debug.h"
 
 extern char *opt_rcfile_arg;