Re: [evolution-patches] Exchange : Plugins



Hi,

Please ignore the earlier patch. This should be much better.

Thanks
-- Sarfraaz

On Tue, 2005-08-02 at 14:41 +0530, Sarfraaz Ahmed wrote:
> Hi,
> 
> While reading through the code i came across places that might cause
> crashes because of missing NULL checks. Please review.
> 
> Thanks
> -- Sarfraaz
> _______________________________________________
> evolution-patches mailing list
> evolution-patches lists ximian com
> http://lists.ximian.com/mailman/listinfo/evolution-patches
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/ChangeLog,v
retrieving revision 1.37
diff -u -p -u -p -r1.37 ChangeLog
--- ChangeLog	1 Aug 2005 06:46:30 -0000	1.37
+++ ChangeLog	2 Aug 2005 10:59:04 -0000
@@ -1,4 +1,12 @@
+2005-08-02  Sarfraaz Ahmed <asarfraaz novell com>
+
+	* exchange-calendar.c : Check for NULL target
+	* exchange-contacts.c : Similar
+	* exchange-folder-permission.c : Similar
+	* exchange-folder.c : Similar
+
 2005-08-01  Praveen Kumar  <kpraveen novell com>
+
 	* exchnage-config-listener.c 
 	(exchange_add_autocompletion_folders) : Added new
 	(add_defaults_for_account) : Added a call to the newly added function
Index: exchange-calendar.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-calendar.c,v
retrieving revision 1.7
diff -u -p -u -p -r1.7 exchange-calendar.c
--- exchange-calendar.c	25 Jul 2005 08:40:00 -0000	1.7
+++ exchange-calendar.c	2 Aug 2005 10:59:04 -0000
@@ -150,8 +150,10 @@ e_exchange_calendar_pcalendar (EPlugin *
         gchar *uri_text;
 	gchar *cal_name;
 	char *folder_size;
+	const char *rel_uri;
 	int row, i;
 
+
 	if (!hidden)
 		hidden = gtk_label_new ("");
 
@@ -165,7 +167,7 @@ e_exchange_calendar_pcalendar (EPlugin *
 	uri_text = e_source_get_uri (t->source);
 	uri = e_uri_new (uri_text);
 
-	if (strcmp (uri->protocol, "exchange")) {
+	if (uri && strcmp (uri->protocol, "exchange")) {
 		e_uri_free (uri);
                 g_free (uri_text);
 		return hidden;
@@ -174,10 +176,11 @@ e_exchange_calendar_pcalendar (EPlugin *
 	e_uri_free (uri);
 	g_free (uri_text);
 
-	if (strlen (e_source_peek_relative_uri (t->source))) {
+	rel_uri = e_source_peek_relative_uri (t->source);
+	if (rel_uri && strlen (rel_uri)) {
 		calendar_src_exists = TRUE;
 		g_free (calendar_old_source_uri);
-		calendar_old_source_uri = g_strdup (e_source_peek_relative_uri (t->source));
+		calendar_old_source_uri = g_strdup (rel_uri);
 	}
 	else {
 		calendar_src_exists = FALSE;
@@ -249,7 +252,7 @@ e_exchange_calendar_pcalendar (EPlugin *
 		uri_prefix = g_strconcat (account->account_filename, "/", NULL);
 		prefix_len = strlen (uri_prefix);
 		
-		tmpruri = (gchar*) e_source_peek_relative_uri (t->source);
+		tmpruri = rel_uri;
 
 		if (g_str_has_prefix (tmpruri, uri_prefix)) {
 			sruri = g_strdup (tmpruri+prefix_len);
@@ -274,10 +277,15 @@ e_exchange_calendar_check (EPlugin *epl,
 {
 	/* FIXME - check pageid */
 	ECalConfigTargetSource *t = (ECalConfigTargetSource *) data->target;
-	ESourceGroup *group = e_source_peek_group (t->source);
-
-	if (!strncmp (e_source_group_peek_base_uri (group), "exchange", 8)) {
-		if (!strlen (e_source_peek_relative_uri (t->source))) {
+	ESourceGroup *group;
+	const char *base_uri;
+	const char *rel_uri;
+
+	rel_uri = e_source_peek_relative_uri (t->source);
+	group = e_source_peek_group (t->source);
+	base_uri = e_source_group_peek_base_uri (group);
+	if (base_uri && !strncmp (base_uri, "exchange", 8)) {
+		if (rel_uri && !strlen (rel_uri)) {
 			return FALSE;
 		}
 	}
@@ -292,12 +300,11 @@ e_exchange_calendar_commit (EPlugin *epl
 	ESource *source = t->source;
 	gchar *uri_text, *gruri, *gname, *ruri, *ftype, *path, *path_prefix, *oldpath=NULL;
 	int prefix_len;
-
 	ExchangeAccount *account;
 	ExchangeAccountFolderResult result;
 		
 	uri_text = e_source_get_uri (source);
-	if (strncmp (uri_text, "exchange", 8)) {
+	if (uri_text && strncmp (uri_text, "exchange", 8)) {
 		g_free (uri_text);
 		return ;
 	}	
@@ -340,7 +347,7 @@ e_exchange_calendar_commit (EPlugin *epl
 		/* Create the new folder */
 		result = exchange_account_create_folder (account, path, ftype);
 	}
-	else if (strcmp (e_source_peek_relative_uri (source), calendar_old_source_uri)) {
+	else if (gruri && strcmp (gruri, calendar_old_source_uri)) {
 		/* Rename the folder */
 		oldpath = g_strdup_printf ("/%s", calendar_old_source_uri+prefix_len);
 		result = exchange_account_xfer_folder (account, oldpath, path, TRUE);
Index: exchange-contacts.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-contacts.c,v
retrieving revision 1.6
diff -u -p -u -p -r1.6 exchange-contacts.c
--- exchange-contacts.c	25 Jul 2005 08:40:00 -0000	1.6
+++ exchange-contacts.c	2 Aug 2005 10:59:04 -0000
@@ -131,6 +131,8 @@ e_exchange_contacts_pcontacts (EPlugin *
 
 	int i;
 	char *folder_size, *abook_name;
+	const char *rel_uri;
+	const char *uid;
 
 	EABConfigTargetSource *t = (EABConfigTargetSource *) data->target;
 	ESource *source = t->source;
@@ -140,19 +142,19 @@ e_exchange_contacts_pcontacts (EPlugin *
 	}
 
         uri_text = e_source_get_uri (source);
-	if (strncmp (uri_text, "exchange", 8)) {
+	if (uri_text && strncmp (uri_text, "exchange", 8)) {
 		g_free (uri_text);		
 		return NULL;
 	}
 
 	g_free (uri_text);
 
-	if (e_source_peek_relative_uri (source) &&
-		e_source_peek_uid (source) &&
-		(strcmp (e_source_peek_relative_uri (source), e_source_peek_uid (source)))) {
+	rel_uri = e_source_peek_relative_uri (source);
+	uid = e_source_peek_uid (source);
+	if (rel_uri && uid && (strcmp (rel_uri, uid))) {
 		contacts_src_exists = TRUE;
 		g_free (contacts_old_src_uri);
-		contacts_old_src_uri = g_strdup (e_source_peek_relative_uri (source));
+		contacts_old_src_uri = g_strdup (rel_uri);
 	}
 	else {
 		contacts_src_exists = FALSE;
@@ -226,7 +228,7 @@ e_exchange_contacts_pcontacts (EPlugin *
 		int prefix_len;
 		GtkTreeSelection *selection;
 
-		tmpruri = (gchar*)e_source_peek_relative_uri (t->source);
+		tmpruri = rel_uri;
 		uri_prefix = g_strconcat (account->account_filename, "/", NULL);
 		prefix_len = strlen (uri_prefix);
 		
@@ -258,10 +260,15 @@ e_exchange_contacts_check (EPlugin *epl,
 {
 	/* FIXME - check pageid */
 	EABConfigTargetSource *t = (EABConfigTargetSource *) data->target;
-	ESourceGroup *group = e_source_peek_group (t->source);
-
-	if (!strncmp (e_source_group_peek_base_uri (group), "exchange", 8)) {
-		if (!strlen (e_source_peek_relative_uri (t->source))) {
+	ESourceGroup *group;
+	const char *base_uri;
+	const char *rel_uri;
+
+	rel_uri = e_source_peek_relative_uri (t->source);
+	group = e_source_peek_group (t->source);
+	base_uri = e_source_group_peek_base_uri (group);
+	if (base_uri && !strncmp (base_uri, "exchange", 8)) {
+		if (rel_uri && !strlen (rel_uri)) {
 			return FALSE;
 		}
 	}
@@ -276,12 +283,11 @@ e_exchange_contacts_commit (EPlugin *epl
 	ESource *source = t->source;
 	gchar *uri_text, *gname, *gruri, *ruri, *path, *path_prefix, *oldpath=NULL;
 	int prefix_len;
-
 	ExchangeAccount *account;
 	ExchangeAccountFolderResult result;
 		
 	uri_text = e_source_get_uri (source);
-	if (strncmp (uri_text, "exchange", 8)) {
+	if (uri_text && strncmp (uri_text, "exchange", 8)) {
 		g_free (uri_text);
 		return ;
 	}	
@@ -313,7 +319,7 @@ e_exchange_contacts_commit (EPlugin *epl
 		/* Create the new folder */
 		result = exchange_account_create_folder (account, path, "contacts");
 	}
-	else if (strcmp (e_source_peek_relative_uri (source), contacts_old_src_uri)) {
+	else if (strcmp (gruri, contacts_old_src_uri)) {
 		/* Rename the folder */
 		oldpath = g_strdup_printf ("/%s", contacts_old_src_uri+prefix_len);
 		result = exchange_account_xfer_folder (account, oldpath, path, TRUE);
Index: exchange-folder-permission.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-folder-permission.c,v
retrieving revision 1.5
diff -u -p -u -p -r1.5 exchange-folder-permission.c
--- exchange-folder-permission.c	25 Jul 2005 07:37:03 -0000	1.5
+++ exchange-folder-permission.c	2 Aug 2005 10:59:04 -0000
@@ -70,25 +70,22 @@ org_gnome_exchange_calendar_permissions 
 	int i = 0;
 	static int first =0;
 	ExchangeAccount *account = NULL;
-	EFolder *folder = NULL;
 	ESource *source = NULL;
 	gchar *uri = NULL;
 
-	source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (target->selector));
-	uri = (gchar *) e_source_get_uri (source);
-
-	if (! g_strrstr (uri, "exchange://"))	{
-		return ;
-	}
-
 	account = exchange_operations_get_exchange_account ();
 
 	if (!account)
 		return;
 
-	folder = exchange_account_get_folder (account, uri);
+	source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (target->selector));
+	uri = (gchar *) e_source_get_uri (source);
 
-	if (!folder)
+	if (uri && ! g_strrstr (uri, "exchange://"))	{
+		return;
+	}
+
+	if (!exchange_account_get_folder (account, uri))
 		return;
 
 	selected_exchange_folder_uri = uri;
@@ -114,28 +111,22 @@ org_gnome_exchange_addressbook_permissio
 	int i = 0;
 	static int first =0;
 	ExchangeAccount *account = NULL;
-	EFolder *folder = NULL;
 	ESource *source = NULL;
 	gchar *uri = NULL;
 
-	source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (target->selector));
-	uri = (gchar *) e_source_get_uri (source);
-
-	if (! g_strrstr (uri, "exchange://"))	{
-		return ;
-	}
-
 	account = exchange_operations_get_exchange_account ();
 
 	if (!account)
 		return;
 
+	source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (target->selector));
+	uri = (gchar *) e_source_get_uri (source);
 
-	folder = exchange_account_get_folder (account, uri);
+	if (!g_strrstr (uri, "exchange://"))
+		return;
 
-	if (!folder) {
+	if (!exchange_account_get_folder (account, uri))
 		return;
-	}
 
 	selected_exchange_folder_uri = uri;
 
@@ -152,29 +143,18 @@ org_gnome_exchange_addressbook_permissio
 }
 
 void
-org_gnome_exchange_folder_permissions (EPlugin *ep, EMPopupTargetFolder *t)
+org_gnome_exchange_folder_permissions (EPlugin *ep, EMPopupTargetFolder *target)
 {
 	GSList *menus = NULL;
 	int i = 0;
 	static int first =0;
-	ExchangeAccount *account = NULL;
-	EFolder *folder = NULL;
+	ExchangeAccount *account = exchange_operations_get_exchange_account ();
 
-	if (! g_strrstr (t->uri, "exchange://"))
+	if (!account || ! g_strrstr (target->uri, "exchange://") ||
+		!exchange_account_get_folder (account, target->uri))
 		return ;
 
-	account = exchange_operations_get_exchange_account ();
-
-	if (!account)
-		return;
-
-	folder = exchange_account_get_folder (account, t->uri);
-
-
-	if (!folder)
-		return;
-
-	selected_exchange_folder_uri = t->uri;
+	selected_exchange_folder_uri = target->uri;
 	/* for translation*/
 	if (!first) {
 		popup_items[0].label =  _(popup_items[0].label);
@@ -184,7 +164,7 @@ org_gnome_exchange_folder_permissions (E
 	for (i = 0; i < sizeof (popup_items) / sizeof (popup_items[0]); i++)
 		menus = g_slist_prepend (menus, &popup_items[i]);
 
-	e_popup_add_items (t->target.popup, menus, NULL, popup_free, NULL);
+	e_popup_add_items (target->target.popup, menus, NULL, popup_free, NULL);
 
 }
 
@@ -210,9 +190,6 @@ org_gnome_exchange_menu_folder_permissio
 {
 	ExchangeAccount *account = NULL;
 	EFolder *folder = NULL;
-
-	if (target == NULL)
-		return;
 
 	account = exchange_operations_get_exchange_account ();
 
Index: exchange-folder.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/exchange-operations/exchange-folder.c,v
retrieving revision 1.6
diff -u -p -u -p -r1.6 exchange-folder.c
--- exchange-folder.c	28 Jul 2005 18:05:12 -0000	1.6
+++ exchange-folder.c	2 Aug 2005 10:59:04 -0000
@@ -125,6 +125,7 @@ org_gnome_exchange_check_address_book_su
 	gchar *uri = NULL;
 	gchar *path = NULL;
 	char *sub_folder = NULL;
+	const char *base_uri;
 	ExchangeAccount *account = NULL;
 	ESourceGroup *group;
 
@@ -135,7 +136,8 @@ org_gnome_exchange_check_address_book_su
 
 	source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (target->selector));
 	group = e_source_peek_group (source);
-	if (!group || strcmp (e_source_group_peek_base_uri (group), "exchange://"))
+	base_uri = e_source_group_peek_base_uri (group);
+	if (!base_uri || strcmp (base_uri, "exchange://"))
 		return;
 
 	uri = e_source_get_uri (source);
@@ -164,6 +166,7 @@ org_gnome_exchange_check_subscribed (EPl
 	gchar *ruri = NULL;
 	gchar *path = NULL;
 	char *sub_folder = NULL;
+	const char *base_uri;
 	ExchangeAccount *account = NULL;
 	ESourceGroup *group;
 
@@ -174,7 +177,8 @@ org_gnome_exchange_check_subscribed (EPl
 
 	source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (target->selector));
 	group = e_source_peek_group (source);
-	if (!group || strcmp (e_source_group_peek_base_uri (group), "exchange://"))
+	base_uri = e_source_group_peek_base_uri (group);
+	if (!basu_uri || strcmp (base_uri, "exchange://"))
 		return;
 
 	ruri = (gchar *) e_source_peek_relative_uri (source);


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