evolution r34795 - trunk/plugins/bbdb



Author: mcrha
Date: Thu Jan 10 18:19:51 2008
New Revision: 34795
URL: http://svn.gnome.org/viewvc/evolution?rev=34795&view=rev

Log:
2008-01-10  Milan Crha  <mcrha redhat com>

	** Fix for bug #496402

	* gaimbuddies.c: (parse_buddy_group), (get_all_blocked),
	(bbdb_get_gaim_buddy_list), (free_gaim_body), (free_buddy_list),
	(parse_buddy_group): Do not synchronize blocked bodies from pidgin.



Modified:
   trunk/plugins/bbdb/ChangeLog
   trunk/plugins/bbdb/gaimbuddies.c

Modified: trunk/plugins/bbdb/gaimbuddies.c
==============================================================================
--- trunk/plugins/bbdb/gaimbuddies.c	(original)
+++ trunk/plugins/bbdb/gaimbuddies.c	Thu Jan 10 18:19:51 2008
@@ -69,9 +69,8 @@
 static GList *bbdb_get_gaim_buddy_list (void);
 static char *get_node_text (xmlNodePtr node);
 static char *get_buddy_icon_from_setting (xmlNodePtr setting);
-static char *get_node_text (xmlNodePtr node);
 static void free_buddy_list (GList *blist);
-static void parse_buddy_group (xmlNodePtr group, GList **buddies);
+static void parse_buddy_group (xmlNodePtr group, GList **buddies, GSList *blocked);
 static EContactField proto_to_contact_field (const char *proto);
 
 void
@@ -293,6 +292,27 @@
 	return E_CONTACT_IM_AIM;
 }
 
+static void
+get_all_blocked (xmlNodePtr node, GSList **blocked)
+{
+	xmlNodePtr child;
+
+	if (!node || !blocked)
+		return;
+
+	for (child = node->children; child; child = child->next) {
+		if (child->children)
+			get_all_blocked (child, blocked);
+
+		if (!strcmp ((const char *)child->name, "block")) {
+			char *name = get_node_text (child);
+
+			if (name)
+				*blocked = g_slist_prepend (*blocked, name);
+		}
+	}
+}
+
 static GList *
 bbdb_get_gaim_buddy_list (void)
 {
@@ -300,6 +320,7 @@
 	xmlDocPtr buddy_xml;
 	xmlNodePtr root, child, blist;
 	GList *buddies = NULL;
+	GSList *blocked = NULL;
 
 	blist_path = g_build_path ("/", getenv ("HOME"), ".purple/blist.xml", NULL);
 
@@ -317,6 +338,13 @@
 		return NULL;
 	}
 
+	for (child = root->children; child != NULL; child = child->next) {
+		if (! strcmp ((const char *)child->name, "privacy")) {
+			get_all_blocked (child, &blocked);
+			break;
+		}
+	}
+
 	blist = NULL;
 	for (child = root->children; child != NULL; child = child->next) {
 		if (! strcmp ((const char *)child->name, "blist")) {
@@ -332,30 +360,35 @@
 
 	for (child = blist->children; child != NULL; child = child->next) {
 		if (! strcmp ((const char *)child->name, "group"))
-			parse_buddy_group (child, &buddies);
+			parse_buddy_group (child, &buddies, blocked);
 	}
 
 	xmlFreeDoc (buddy_xml);
 
+	g_slist_foreach (blocked, (GFunc)g_free, NULL);
+	g_slist_free (blocked);
+
 	return buddies;
 }
 
 static void
-free_buddy_list (GList *blist)
+free_gaim_body (GaimBuddy *gb)
 {
-	GList *l;
-
-	for (l = blist; l != NULL; l = l->next) {
-		GaimBuddy *gb = l->data;
+	if (!gb)
+		return;
 
-		g_free (gb->icon);
-		g_free (gb->alias);
-		g_free (gb->account_name);
-		g_free (gb->proto);
-		g_free (gb);
-	}
+	g_free (gb->icon);
+	g_free (gb->alias);
+	g_free (gb->account_name);
+	g_free (gb->proto);
+	g_free (gb);
+}
 
-	g_list_free (l);
+static void
+free_buddy_list (GList *blist)
+{
+	g_list_foreach (blist, (GFunc)free_gaim_body, NULL);
+	g_list_free (blist);
 }
 
 static char *
@@ -387,11 +420,12 @@
 }
 
 static void
-parse_contact (xmlNodePtr contact, GList **buddies)
+parse_contact (xmlNodePtr contact, GList **buddies, GSList *blocked)
 {
 	xmlNodePtr  child;
 	xmlNodePtr  buddy = NULL;
 	GaimBuddy  *gb;
+	gboolean    is_blocked = FALSE;
 
 	for (child = contact->children; child != NULL; child = child->next) {
 		if (! strcmp ((const char *)child->name, "buddy")) {
@@ -409,7 +443,7 @@
 
 	gb->proto = e_xml_get_string_prop_by_name (buddy, (const unsigned char *)"proto");
 
-	for (child = buddy->children; child != NULL; child = child->next) {
+	for (child = buddy->children; child != NULL && !is_blocked; child = child->next) {
 		if (! strcmp ((const char *)child->name, "setting")) {
 			char *setting_type;
 			setting_type = e_xml_get_string_prop_by_name (child, (const unsigned char *)"name");
@@ -418,18 +452,22 @@
 				gb->icon = get_buddy_icon_from_setting (child);
 
 			g_free (setting_type);
-		} else if (! strcmp ((const char *)child->name, "name"))
+		} else if (! strcmp ((const char *)child->name, "name")) {
 			gb->account_name = get_node_text (child);
-		else if (! strcmp ((const char *)child->name, "alias"))
+			is_blocked = g_slist_find_custom (blocked, gb->account_name, (GCompareFunc)strcmp) != NULL;
+		} else if (! strcmp ((const char *)child->name, "alias"))
 			gb->alias = get_node_text (child);
 
 	}
 
-	*buddies = g_list_prepend (*buddies, gb);
+	if (is_blocked) 
+		free_gaim_body (gb);
+	else
+		*buddies = g_list_prepend (*buddies, gb);
 }
 
 static void
-parse_buddy_group (xmlNodePtr group, GList **buddies)
+parse_buddy_group (xmlNodePtr group, GList **buddies, GSList *blocked)
 {
 	xmlNodePtr child;
 
@@ -437,6 +475,6 @@
 		if (strcmp ((const char *)child->name, "contact"))
 			continue;
 
-		parse_contact (child, buddies);
+		parse_contact (child, buddies, blocked);
 	}
 }



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