changeset 26993:5ff1d66e6aef

Convert zephyr to use purple_find_buddies. This code had no hope of compiling previously on win32, but might be able to now.
author Paul Aurich <paul@darkrain42.org>
date Mon, 01 Jun 2009 03:34:02 +0000
parents a9f5afce8f39
children 1fcd09c34fee
files libpurple/protocols/zephyr/zephyr.c
diffstat 1 files changed, 56 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/zephyr/zephyr.c	Mon Jun 01 02:28:39 2009 +0000
+++ b/libpurple/protocols/zephyr/zephyr.c	Mon Jun 01 03:34:02 2009 +0000
@@ -1254,45 +1254,32 @@
 
 #ifdef WIN32
 
-static gint check_loc(gpointer_data)
+static gint check_loc(gpointer data)
 {
-	PurpleBlistNode *gnode, *cnode, *bnode;
+	GSList *buddies;
 	ZLocations_t locations;
+	PurpleConnection *gc = data;
+	zephyr_account *zephyr = gc->proto_data;
+	PurpleAccount *account = purple_connection_get_account(gc);
 	int numlocs;
 	int one = 1;
 
-	for (gnode = purple_blist_get_root(); gnode;
-			gnode = purple_blist_node_get_sibling_next(gnode)) {
-		if (!PURPLE_BLIST_NODE_IS_GROUP(gnode))
-			continue;
-		for (cnode = purple_blist_node_get_first_child(gnode);
-				cnode;
-				cnode = purple_blist_node_get_sibling_next(cnode)) {
-			if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
-				continue;
-			for (bnode = purple_blist_node_get_first_child(cnode);
-					bnode;
-					bnode = purple_blist_node_get_sibling_next(bnode)) {
-				PurpleBuddy *b = (PurpleBuddy *) bnode;
-
-				if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
-					continue;
-				if (purple_buddy_get_account(b)->gc == zgc) {
-					char *chk;
-					const char *bname = purple_buddy_get_name(b);
-					chk = local_zephyr_normalize(bname);
-					ZLocateUser(chk,&numlocs, ZAUTH);
-					if (numlocs) {
-						int i;
-						for(i=0;i<numlocs;i++) {
-							ZGetLocations(&locations,&one);
-							serv_got_update(zgc,bname,1,0,0,0,0);
-						}
-					}
-				}
+	for (buddies = purple_find_buddies(account, NULL); buddies;
+			buddies = g_slist_delete_link(buddies, buddies)) {
+		PurpleBuddy *b = buddies->data;
+		char *chk;
+		const char *bname = purple_buddy_get_name(b);
+		chk = local_zephyr_normalize(bname);
+		ZLocateUser(chk,&numlocs, ZAUTH);
+		if (numlocs) {
+			int i;
+			for(i=0;i<numlocs;i++) {
+				ZGetLocations(&locations,&one);
+				serv_got_update(zgc,bname,1,0,0,0,0);
 			}
 		}
 	}
+
 	return TRUE;
 }
 
@@ -1300,7 +1287,7 @@
 
 static gint check_loc(gpointer data)
 {
-	PurpleBlistNode *gnode, *cnode, *bnode;
+	GSList *buddies;
 	ZAsyncLocateData_t ald;
 	PurpleConnection *gc = (PurpleConnection *)data;
 	zephyr_account *zephyr = gc->proto_data;
@@ -1312,65 +1299,49 @@
 		ald.version = NULL;
 	}
 
-	for (gnode = purple_blist_get_root(); gnode;
-			gnode = purple_blist_node_get_sibling_next(gnode)) {
-		if (!PURPLE_BLIST_NODE_IS_GROUP(gnode))
-			continue;
-		for (cnode = purple_blist_node_get_first_child(gnode);
-				cnode;
-				cnode = purple_blist_node_get_sibling_next(cnode)) {
-			if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
-				continue;
-			for (bnode = purple_blist_node_get_first_child(cnode);
-					bnode;
-					bnode = purple_blist_node_get_sibling_next(bnode)) {
-				PurpleBuddy *b = (PurpleBuddy *) bnode;
+	for (buddies = purple_find_buddies(account, NULL); buddies;
+			buddies = g_slist_delete_link(buddies, buddies)) {
+		PurpleBuddy *b = buddies->data;
 
-				if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode))
-					continue;
-				if (purple_buddy_get_account(b) == account) {
-					const char *chk;
-					const char *name = purple_buddy_get_name(b);
+		const char *chk;
+		const char *name = purple_buddy_get_name(b);
 
-					chk = local_zephyr_normalize(zephyr,name);
-					purple_debug_info("zephyr","chk: %s b->name %s\n",chk,name);
-					/* XXX add real error reporting */
-					/* doesn't matter if this fails or not; we'll just move on to the next one */
-					if (use_zeph02(zephyr)) {
+		chk = local_zephyr_normalize(zephyr,name);
+		purple_debug_info("zephyr","chk: %s b->name %s\n",chk,name);
+		/* XXX add real error reporting */
+		/* doesn't matter if this fails or not; we'll just move on to the next one */
+		if (use_zeph02(zephyr)) {
 #ifdef WIN32
-						int numlocs;
-						int one=1;
-						ZLocateUser(chk,&numlocs,ZAUTH);
-						if (numlocs) {
-							int i;
-							for(i=0;i<numlocs;i++) {
-								ZGetLocations(&locations,&one);
-								if (nlocs>0) 
-									purple_prpl_got_user_status(account,name,"available",NULL);
-								else 
-									purple_prpl_got_user_status(account,name,"offline",NULL);
-							}
-						}
-#else
-						ZRequestLocations(chk, &ald, UNACKED, ZAUTH);
-						g_free(ald.user);
-						g_free(ald.version);
-#endif /* WIN32 */
-					} else 
-						if (use_tzc(zephyr)) {
-							gchar *zlocstr = g_strdup_printf("((tzcfodder . zlocate) \"%s\")\n",chk);
-							size_t len = strlen(zlocstr);
-							size_t result = write(zephyr->totzc[ZEPHYR_FD_WRITE],zlocstr,len);
-							if (result != len) {
-								purple_debug_error("zephyr", "Unable to write a message: %s\n", g_strerror(errno));
-							}
-							g_free(zlocstr);
-						}
+			int numlocs;
+			int one=1;
+			ZLocateUser(chk,&numlocs,ZAUTH);
+			if (numlocs) {
+				int i;
+				for(i=0;i<numlocs;i++) {
+					ZGetLocations(&locations,&one);
+					if (nlocs>0) 
+						purple_prpl_got_user_status(account,name,"available",NULL);
+					else 
+						purple_prpl_got_user_status(account,name,"offline",NULL);
 				}
 			}
-		}
+#else
+			ZRequestLocations(chk, &ald, UNACKED, ZAUTH);
+			g_free(ald.user);
+			g_free(ald.version);
+#endif /* WIN32 */
+		} else 
+			if (use_tzc(zephyr)) {
+				gchar *zlocstr = g_strdup_printf("((tzcfodder . zlocate) \"%s\")\n",chk);
+				size_t len = strlen(zlocstr);
+				size_t result = write(zephyr->totzc[ZEPHYR_FD_WRITE],zlocstr,len);
+				if (result != len) {
+					purple_debug_error("zephyr", "Unable to write a message: %s\n", g_strerror(errno));
+				}
+				g_free(zlocstr);
+			}
 	}
-	
+
 	return TRUE;
 }