evolution-mapi r40 - in trunk: . src/addressbook src/camel



Author: mcrha
Date: Fri Dec 19 12:14:36 2008
New Revision: 40
URL: http://svn.gnome.org/viewvc/evolution-mapi?rev=40&view=rev

Log:
2008-12-19  Milan Crha  <mcrha redhat com>

	** Fix for bug #564899

	* configure.in: Define HANDLE_LIBICAL_MEMORY.
	* src/addressbook/e-book-backend-mapi.c: (emapidump_contact):
	* src/camel/camel-mapi-folder.c: (struct fetch_items_data), (fetch_items_cb),
	(mapi_refresh_folder):
	Compiler warnings and memory leaks fix.



Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/src/addressbook/ChangeLog
   trunk/src/addressbook/e-book-backend-mapi.c
   trunk/src/camel/ChangeLog
   trunk/src/camel/camel-mapi-folder.c

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Fri Dec 19 12:14:36 2008
@@ -35,6 +35,7 @@
 AC_PROG_MAKE_SET
 
 AC_DEFINE(_GNU_SOURCE, 1, [Use GNU extensions])
+AC_DEFINE(HANDLE_LIBICAL_MEMORY, 1, [Define it once memory returned by libical is freed properly])
 
 dnl ************
 dnl i18n stuff

Modified: trunk/src/addressbook/e-book-backend-mapi.c
==============================================================================
--- trunk/src/addressbook/e-book-backend-mapi.c	(original)
+++ trunk/src/addressbook/e-book-backend-mapi.c	Fri Dec 19 12:14:36 2008
@@ -1033,8 +1033,8 @@
 	for (i=1; i<maplen; i++) {
 		gpointer value;
 
-		/* XXX Casting away return value const'ness. */
-		value = find_mapi_SPropValue_data (properties, mappings[i].mapi_id);
+		/* can cast it, no writing to the value; and it'll be freed not before the end of this function */
+		value = (gpointer) find_mapi_SPropValue_data (properties, mappings[i].mapi_id);
 		if (mappings[i].element_type == PT_STRING8 && mappings[i].contact_type == ELEMENT_TYPE_SIMPLE) {
 			if (value)
 				e_contact_set (contact, mappings[i].field_id, value);
@@ -1043,28 +1043,22 @@
 				struct FILETIME *t = value;
 				time_t time;
 				NTTIME nt;
-				char *tmp;
+				char buff[129];
+
 				nt = t->dwHighDateTime;
 				nt = nt << 32;
 				nt |= t->dwLowDateTime;
 				time = nt_time_to_unix (nt);
-				tmp = ctime (&time);
-				e_contact_set (contact, mappings[i].field_id, tmp);
-				//g_free (tmp);
+				e_contact_set (contact, mappings[i].field_id, ctime_r (&time, buff));
 			} else
 				printf("Nothing is printed\n");
 		} else if (mappings[i].contact_type == ELEMENT_TYPE_COMPLEX) {
 			if (mappings[i].field_id == E_CONTACT_IM_AIM) {
-				GList *list = NULL;
-				EVCardAttribute *attr;
-				
-				attr = e_vcard_attribute_new ("", e_contact_vcard_attribute(E_CONTACT_IM_AIM));
-//				e_vcard_attribute_add_param_with_value (attr, e_vcard_attribute_param_new (EVC_TYPE), "AIM");
-				e_vcard_attribute_add_value (attr, value);
-				list = g_list_append (list, value);
-				//printf("%s -----\n", value);
+				GList *list = g_list_append (NULL, value);
+
 				e_contact_set (contact, mappings[i].field_id, list);
-				//FIXME: FREE them
+
+				g_list_free (list);
 			} else if (mappings[i].field_id == E_CONTACT_BIRTH_DATE
 				   || mappings[i].field_id == E_CONTACT_ANNIVERSARY) {
 				struct FILETIME *t = value;
@@ -1072,46 +1066,44 @@
 				NTTIME nt;
 				struct tm * tmtime;
 				if (value) {
-					EContactDate *date = g_new (EContactDate, 1);
+					EContactDate date = {0};
 					nt = t->dwHighDateTime;
 					nt = nt << 32;
 					nt |= t->dwLowDateTime;
 					time = nt_time_to_unix (nt);
 					tmtime = gmtime (&time);
 					//FIXME: Move to new libmapi api to get string dates.
-					date->day = tmtime->tm_mday + 1;
-					date->month = tmtime->tm_mon + 1;
-					date->year = tmtime->tm_year + 1900;
-					e_contact_set (contact, mappings[i].field_id, date);
-					
+					date.day = tmtime->tm_mday + 1;
+					date.month = tmtime->tm_mon + 1;
+					date.year = tmtime->tm_year + 1900;
+					e_contact_set (contact, mappings[i].field_id, &date);
 				}
 				
 			} else if (mappings[i].field_id == E_CONTACT_ADDRESS_WORK
 				   || mappings[i].field_id == E_CONTACT_ADDRESS_HOME) {
-				EContactAddress *contact_addr;
+				EContactAddress contact_addr = { 0 };
 
-				contact_addr = g_new0(EContactAddress, 1);
+				/* type-casting below to not allocate memory twice; e_contact_set will copy values itself. */
 				if (mappings[i].field_id == E_CONTACT_ADDRESS_HOME) {
-						contact_addr->address_format = NULL;
-						contact_addr->po = NULL;
-						contact_addr->street = value;
-						contact_addr->ext = find_mapi_SPropValue_data (properties, PR_HOME_ADDRESS_POST_OFFICE_BOX);
-						contact_addr->locality = find_mapi_SPropValue_data (properties, PR_HOME_ADDRESS_CITY);
-						contact_addr->region = find_mapi_SPropValue_data (properties, PR_HOME_ADDRESS_STATE_OR_PROVINCE);
-						contact_addr->code = find_mapi_SPropValue_data (properties, PR_HOME_ADDRESS_POSTAL_CODE);
-						contact_addr->country = find_mapi_SPropValue_data (properties, PR_HOME_ADDRESS_COUNTRY);
+					contact_addr.address_format = NULL;
+					contact_addr.po = NULL;
+					contact_addr.street = (char *)value;
+					contact_addr.ext = (char *)find_mapi_SPropValue_data (properties, PR_HOME_ADDRESS_POST_OFFICE_BOX);
+					contact_addr.locality = (char *)find_mapi_SPropValue_data (properties, PR_HOME_ADDRESS_CITY);
+					contact_addr.region = (char *)find_mapi_SPropValue_data (properties, PR_HOME_ADDRESS_STATE_OR_PROVINCE);
+					contact_addr.code = (char *)find_mapi_SPropValue_data (properties, PR_HOME_ADDRESS_POSTAL_CODE);
+					contact_addr.country = (char *)find_mapi_SPropValue_data (properties, PR_HOME_ADDRESS_COUNTRY);
 				} else {
-						contact_addr->address_format = NULL;
-						contact_addr->po = NULL;
-						contact_addr->street = value;
-						contact_addr->ext = find_mapi_SPropValue_data (properties, PR_POST_OFFICE_BOX);
-						contact_addr->locality = find_mapi_SPropValue_data (properties, PR_LOCALITY);
-						contact_addr->region = find_mapi_SPropValue_data (properties, PR_STATE_OR_PROVINCE);
-						contact_addr->code = find_mapi_SPropValue_data (properties, PR_POSTAL_CODE);
-						contact_addr->country = find_mapi_SPropValue_data (properties, PR_COUNTRY);
+					contact_addr.address_format = NULL;
+					contact_addr.po = NULL;
+					contact_addr.street = (char *)value;
+					contact_addr.ext = (char *)find_mapi_SPropValue_data (properties, PR_POST_OFFICE_BOX);
+					contact_addr.locality = (char *)find_mapi_SPropValue_data (properties, PR_LOCALITY);
+					contact_addr.region = (char *)find_mapi_SPropValue_data (properties, PR_STATE_OR_PROVINCE);
+					contact_addr.code = (char *)find_mapi_SPropValue_data (properties, PR_POSTAL_CODE);
+					contact_addr.country = (char *)find_mapi_SPropValue_data (properties, PR_COUNTRY);
 				}
-				e_contact_set (contact, mappings[i].field_id, contact_addr);
-				//FIXME: Free everything.
+				e_contact_set (contact, mappings[i].field_id, &contact_addr);
 			}
 		}
 	}

Modified: trunk/src/camel/camel-mapi-folder.c
==============================================================================
--- trunk/src/camel/camel-mapi-folder.c	(original)
+++ trunk/src/camel/camel-mapi-folder.c	Fri Dec 19 12:14:36 2008
@@ -74,7 +74,7 @@
 /*For collecting summary info from server*/
 typedef struct {
 	GSList *items_list;
-	GTimeVal *last_modification_time;
+	GTimeVal last_modification_time;
 }fetch_items_data;
 
 static CamelMimeMessage *mapi_folder_item_to_msg( CamelFolder *folder, MapiItem *item, CamelException *ex );
@@ -189,8 +189,8 @@
 	long *flags;
 	struct FILETIME *delivery_date = NULL;
 	struct FILETIME *last_modification_time = NULL;
-	struct timeval *item_modification_time = NULL;
-	struct timeval fi_data_mod_time;
+	struct timeval item_modification_time = { 0 };
+	struct timeval fi_data_mod_time = { 0 };
 	guint32 j = 0;
 	NTTIME ntdate;
 
@@ -258,16 +258,15 @@
 		ntdate = last_modification_time->dwHighDateTime;
 		ntdate = ntdate << 32;
 		ntdate |= last_modification_time->dwLowDateTime;
-		item_modification_time = g_new0 (struct timeval, 1);
-		nttime_to_timeval(item_modification_time, ntdate);
+		nttime_to_timeval (&item_modification_time, ntdate);
 	}
 
-	fi_data_mod_time.tv_sec = fi_data->last_modification_time->tv_sec;
-	fi_data_mod_time.tv_usec = fi_data->last_modification_time->tv_usec;
+	fi_data_mod_time.tv_sec = fi_data->last_modification_time.tv_sec;
+	fi_data_mod_time.tv_usec = fi_data->last_modification_time.tv_usec;
 
-	if (timeval_compare (item_modification_time, &fi_data_mod_time) == 1) {
-			fi_data->last_modification_time->tv_sec = item_modification_time->tv_sec;
-			fi_data->last_modification_time->tv_usec = item_modification_time->tv_usec;
+	if (timeval_compare (&item_modification_time, &fi_data_mod_time) == 1) {
+			fi_data->last_modification_time.tv_sec = item_modification_time.tv_sec;
+			fi_data->last_modification_time.tv_usec = item_modification_time.tv_usec;
 	}
 
 	if ((*flags & MSGFLAG_READ) != 0)
@@ -555,7 +554,7 @@
 	CamelMapiFolder *mapi_folder = CAMEL_MAPI_FOLDER (folder);
 	CamelMapiSummary *mapi_summary = CAMEL_MAPI_SUMMARY (folder->summary);
 	gboolean is_proxy = folder->parent_store->flags & CAMEL_STORE_PROXY;
-	gboolean is_locked = TRUE;
+	gboolean is_locked = FALSE;
 	gboolean status;
 
 	struct mapi_SRestriction *res = NULL;
@@ -576,8 +575,8 @@
 		PR_DISPLAY_BCC
 	};
 
-	if (((CamelOfflineStore *) mapi_store)->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL) 
-		return;
+	if (((CamelOfflineStore *) mapi_store)->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL)
+		goto end1;
 
 	/* Sync-up the (un)read changes before getting updates,
 	so that the getFolderList will reflect the most recent changes too */
@@ -587,7 +586,7 @@
 	folder_id = camel_mapi_store_folder_id_lookup (mapi_store, folder->full_name);
 	if (!folder_id) {
 		d(printf ("\nERROR - Folder id not present. Cannot refresh info for %s\n", folder->full_name));
-		return;
+		goto end1;
 	}
 
 	if (camel_folder_is_frozen (folder) ) {
@@ -595,6 +594,7 @@
 	}
 
 	CAMEL_SERVICE_REC_LOCK (mapi_store, connect_lock);
+	is_locked = TRUE;
 
 	if (!camel_mapi_store_connected (mapi_store, ex))
 		goto end1;
@@ -604,10 +604,8 @@
 		mapi_id_t temp_folder_id;
 		guint32 options = 0;
 
-		fetch_data->last_modification_time = g_new0 (GTimeVal, 1); /*First Sync*/
-
 		if (mapi_summary->sync_time_stamp && *mapi_summary->sync_time_stamp &&
-		    g_time_val_from_iso8601 (mapi_summary->sync_time_stamp, fetch_data->last_modification_time)) {
+		    g_time_val_from_iso8601 (mapi_summary->sync_time_stamp, &fetch_data->last_modification_time)) {
 			struct SPropValue sprop;
 			struct timeval t;
 
@@ -617,8 +615,8 @@
 			res->res.resProperty.relop = RELOP_GE;
 			res->res.resProperty.ulPropTag = PR_LAST_MODIFICATION_TIME;
 
-			t.tv_sec = fetch_data->last_modification_time->tv_sec;
-			t.tv_usec = fetch_data->last_modification_time->tv_usec;
+			t.tv_sec = fetch_data->last_modification_time.tv_sec;
+			t.tv_usec = fetch_data->last_modification_time.tv_usec;
 
 			//Creation time ? 
 			set_SPropValue_proptag_date_timeval (&sprop, PR_LAST_MODIFICATION_TIME, &t);
@@ -660,7 +658,7 @@
 		}
 
 		/*Preserve last_modification_time from this fetch for later use with restrictions.*/
-		mapi_summary->sync_time_stamp = g_time_val_to_iso8601 (fetch_data->last_modification_time);
+		mapi_summary->sync_time_stamp = g_time_val_to_iso8601 (&fetch_data->last_modification_time);
 
 		camel_folder_summary_touch (folder->summary);
 		mapi_sync_summary (folder, ex);
@@ -673,15 +671,15 @@
 	CAMEL_SERVICE_REC_UNLOCK (mapi_store, connect_lock);
 	is_locked = FALSE;
 
-	g_slist_foreach (fetch_data->items_list, (GFunc) mapi_item_free, NULL);
-	g_slist_free (fetch_data->items_list);
 end2:
 	//TODO:
 end1:
 	if (is_locked)
 		CAMEL_SERVICE_REC_UNLOCK (mapi_store, connect_lock);
-	return;
 
+	g_slist_foreach (fetch_data->items_list, (GFunc) mapi_item_free, NULL);
+	g_slist_free (fetch_data->items_list);
+	g_free (fetch_data);
 }
 
 static const uint32_t camel_GetPropsList[] = {



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