evolution-data-server r9634 - in branches/gnome-2-24: . libedataserver



Author: msuman
Date: Wed Oct  1 10:50:11 2008
New Revision: 9634
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=9634&view=rev

Log:
Fix for bug #554540 - Don't compare XML data of ESource* literally. Instead, compare them semantically.

Modified:
   branches/gnome-2-24/ChangeLog
   branches/gnome-2-24/libedataserver/e-source-group.c
   branches/gnome-2-24/libedataserver/e-source-group.h
   branches/gnome-2-24/libedataserver/e-source-list.c
   branches/gnome-2-24/libedataserver/e-source.c
   branches/gnome-2-24/libedataserver/e-source.h

Modified: branches/gnome-2-24/libedataserver/e-source-group.c
==============================================================================
--- branches/gnome-2-24/libedataserver/e-source-group.c	(original)
+++ branches/gnome-2-24/libedataserver/e-source-group.c	Wed Oct  1 10:50:11 2008
@@ -794,6 +794,103 @@
 	return returned_buffer;
 }
 
+static gint 
+find_esource_from_uid (gconstpointer a, gconstpointer b)
+{
+	return g_ascii_strcasecmp (e_source_peek_uid ((ESource *)(a)), (gchar *)(b));
+}
+
+static gboolean 
+compare_source_lists (GSList *a, GSList *b)
+{
+	gboolean retval = TRUE; 
+	GSList *l; 
+
+	if (g_slist_length(a) != g_slist_length(b))
+		return FALSE; 
+
+	for (l = a; l != NULL && retval; l = l->next) {
+		GSList *elem = g_slist_find_custom (b, e_source_peek_uid ((ESource *)(l->data)), (GCompareFunc) find_esource_from_uid);
+
+		if (!elem || !e_source_equal ((ESource *)(l->data), (ESource *)(elem->data))) 
+			retval = FALSE; 
+	}
+
+	return retval; 
+}
+
+/**
+ * e_source_group_equal:
+ * @a: An ESourceGroup
+ * @b: Another ESourceGroup
+ *
+ * Compares if @a is equivalent to @b.
+ *
+ * Return value: %TRUE if @a is equivalent to @b, 
+ * %FALSE otherwise.
+ **/
+gboolean 
+e_source_group_equal (ESourceGroup *a, ESourceGroup *b)
+{
+	g_return_val_if_fail (E_IS_SOURCE_GROUP (a), FALSE); 
+	g_return_val_if_fail (E_IS_SOURCE_GROUP (b), FALSE); 
+
+	/* Compare group stuff */
+	if (a->priv->uid 
+	 && b->priv->uid 
+	 && g_ascii_strcasecmp (a->priv->uid, b->priv->uid))
+		return FALSE; 
+
+	if (a->priv->name 
+	 && b->priv->name 
+	 && g_ascii_strcasecmp (a->priv->name, b->priv->name))
+		return FALSE; 
+
+	if (a->priv->base_uri 
+	 && b->priv->base_uri 
+	 && g_ascii_strcasecmp (a->priv->base_uri, b->priv->base_uri))
+		return FALSE; 
+
+	if (a->priv->readonly != b->priv->readonly)
+		return FALSE; 
+
+	if (!compare_str_hashes (a->priv->properties, b->priv->properties))
+		return FALSE; 
+
+	/* Compare ESources in the groups */
+	if (!compare_source_lists (a->priv->sources, b->priv->sources))
+		return FALSE; 
+
+	return TRUE; 
+}
+
+/**
+ * e_source_group_xmlstr_equal:
+ * @a: XML representation of an ESourceGroup
+ * @b: XML representation of another ESourceGroup
+ *
+ * Compares if @a is equivalent to @b.
+ *
+ * Return value: %TRUE if @a is equivalent to @b, 
+ * %FALSE otherwise.
+ **/
+gboolean 
+e_source_group_xmlstr_equal (const gchar *a, const gchar *b)
+{
+	ESourceGroup *grpa, *grpb; 
+	gboolean retval; 
+
+	grpa = e_source_group_new_from_xml (a); 
+	grpb = e_source_group_new_from_xml (b); 
+
+	retval = e_source_group_equal (grpa, grpb); 
+
+	g_object_unref (grpa); 
+	g_object_unref (grpb); 
+
+	return retval; 
+}
+
 gchar *
 e_source_group_get_property (ESourceGroup *source_group,
 		             const gchar *property)

Modified: branches/gnome-2-24/libedataserver/e-source-group.h
==============================================================================
--- branches/gnome-2-24/libedataserver/e-source-group.h	(original)
+++ branches/gnome-2-24/libedataserver/e-source-group.h	Wed Oct  1 10:50:11 2008
@@ -113,6 +113,9 @@
 
 char *e_source_group_to_xml (ESourceGroup *group);
 
+gboolean e_source_group_equal (ESourceGroup *a, ESourceGroup *b); 
+gboolean e_source_group_xmlstr_equal (const gchar *a, const gchar *b); 
+
 G_END_DECLS
 
 #endif /* _E_SOURCE_GROUP_H_ */

Modified: branches/gnome-2-24/libedataserver/e-source-list.c
==============================================================================
--- branches/gnome-2-24/libedataserver/e-source-list.c	(original)
+++ branches/gnome-2-24/libedataserver/e-source-list.c	Wed Oct  1 10:50:11 2008
@@ -635,7 +635,7 @@
 
 		if (group) {
 			source_group_xml = e_source_group_to_xml (group);
-			if (!strcmp (gconf_xml, source_group_xml)) {
+			if (e_source_group_xmlstr_equal (gconf_xml, source_group_xml)) {
 				g_free (source_group_xml);
 				continue;
 			}
@@ -671,7 +671,7 @@
 
 		for (temp = conf_list; temp != NULL; temp = temp->next) {
 			gconf_xml = (char *)temp->data;
-			if (strcmp (gconf_xml, source_group_xml))
+			if (!e_source_group_xmlstr_equal (gconf_xml, source_group_xml))
 				continue;
 			else
 				break;

Modified: branches/gnome-2-24/libedataserver/e-source.c
==============================================================================
--- branches/gnome-2-24/libedataserver/e-source.c	(original)
+++ branches/gnome-2-24/libedataserver/e-source.c	Wed Oct  1 10:50:11 2008
@@ -218,33 +218,6 @@
 	return NULL;
 }
 
-gboolean
-e_source_equal (ESource *source_1, ESource *source_2)
-{
-	gboolean equal = FALSE;
-
-	g_return_val_if_fail (E_IS_SOURCE (source_1), FALSE);
-	g_return_val_if_fail (E_IS_SOURCE (source_2), FALSE);
-
-	if (source_1->priv->uid && source_2->priv->uid &&
-	    !strcmp (source_1->priv->uid, source_2->priv->uid)) {
-		equal = TRUE;
-	} else {
-		gchar *uri_1, *uri_2;
-
-		uri_1 = e_source_get_uri (source_1);
-		uri_2 = e_source_get_uri (source_2);
-
-		if (uri_1 && uri_2 && !strcmp (uri_1, uri_2))
-			equal = TRUE;
-
-		g_free (uri_1);
-		g_free (uri_2);
-	}
-
-	return equal;
-}
-
 static void
 import_properties (ESource *source,
 		   xmlNodePtr prop_root)
@@ -817,6 +790,83 @@
 	return returned_buffer;
 }
 
+/**
+ * e_source_compare:
+ * @a: An ESource
+ * @b: Another ESource
+ *
+ * Compares if @a is equivalent to @b.
+ *
+ * Return value: %TRUE if @a is equivalent to @b, 
+ * %FALSE otherwise.
+ **/
+gboolean 
+e_source_equal (ESource *a, ESource *b)
+{
+	g_return_val_if_fail (E_IS_SOURCE (a), FALSE); 
+	g_return_val_if_fail (E_IS_SOURCE (b), FALSE); 
+
+	/* Compare source stuff */
+	if (a->priv->uid 
+	 && b->priv->uid 
+	 && g_ascii_strcasecmp (a->priv->uid, b->priv->uid))
+		return FALSE; 
+
+	if (a->priv->name 
+	 && b->priv->name 
+	 && g_ascii_strcasecmp (a->priv->name, b->priv->name))
+		return FALSE; 
+
+	if (a->priv->relative_uri 
+	 && b->priv->relative_uri 
+	 && g_ascii_strcasecmp (a->priv->relative_uri, b->priv->relative_uri))
+		return FALSE; 
+
+	if (a->priv->absolute_uri 
+	 && b->priv->absolute_uri 
+	 && g_ascii_strcasecmp (a->priv->absolute_uri, b->priv->absolute_uri))
+		return FALSE; 
+
+	if (a->priv->color_spec 
+	 && b->priv->color_spec 
+	 && g_ascii_strcasecmp (a->priv->color_spec, b->priv->color_spec))
+		return FALSE; 
+
+	if (a->priv->readonly != b->priv->readonly)
+		return FALSE; 
+
+	if (!compare_str_hashes (a->priv->properties, b->priv->properties))
+		return FALSE; 
+
+	return TRUE; 
+}
+
+/**
+ * e_source_xmlstr_equal:
+ * @a: XML representation of an ESource
+ * @b: XML representation of another ESource
+ *
+ * Compares if @a is equivalent to @b.
+ *
+ * Return value: %TRUE if @a is equivalent to @b, 
+ * %FALSE otherwise.
+ **/
+gboolean 
+e_source_xmlstr_equal (const gchar *a, const gchar *b)
+{
+	ESource *srca, *srcb; 
+	gboolean retval; 
+
+	srca = e_source_new_from_standalone_xml (a); 
+	srcb = e_source_new_from_standalone_xml (b); 
+
+	retval = e_source_equal (srca, srcb); 
+
+	g_object_unref (srca); 
+	g_object_unref (srcb); 
+
+	return retval; 
+}
 
 ESource *
 e_source_new_from_standalone_xml (const char *xml)

Modified: branches/gnome-2-24/libedataserver/e-source.h
==============================================================================
--- branches/gnome-2-24/libedataserver/e-source.h	(original)
+++ branches/gnome-2-24/libedataserver/e-source.h	Wed Oct  1 10:50:11 2008
@@ -66,8 +66,6 @@
 
 ESource *e_source_copy (ESource *source);
 
-gboolean e_source_equal (ESource *source_1, ESource *source_2);
-
 gboolean  e_source_update_from_xml_node  (ESource    *source,
 					  xmlNodePtr  node,
 					  gboolean   *changed_return);
@@ -122,6 +120,9 @@
 char *e_source_get_duped_property (ESource *source, const char *property);
 char *e_source_build_absolute_uri (ESource *source);
 
+gboolean e_source_equal (ESource *a, ESource *b); 
+gboolean e_source_xmlstr_equal (const gchar *a, const gchar *b);
+
 G_END_DECLS
 
 #endif /* _E_SOURCE_H_ */



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