summaryrefslogtreecommitdiff
blob: 0b74e4fa092605ad364892353743aaa7b8c8f43e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
** Fix for GNOME bug #501295, Gentoo bug #201824

Create locks around the cache so that the file is protected well not to crash.

--- a/addressbook/e-book-backend-exchange.c.orig	2007-10-12 09:05:18.000000000 +0200
+++ b/addressbook/e-book-backend-exchange.c	2008-01-21 11:02:48.000000000 +0100
@@ -84,12 +84,15 @@
 	gboolean is_cache_ready;
 	gboolean marked_for_offline;
 
-	GMutex *create_mutex;
+	GMutex *cache_lock;
 
 	EBookBackendSummary *summary;
 	EBookBackendCache *cache;
 };
 
+#define LOCK(x) g_mutex_lock (x->cache_lock)
+#define UNLOCK(x) g_mutex_unlock (x->cache_lock)
+
 typedef struct PropMapping PropMapping;
 
 static void subscription_notify (E2kContext *ctx, const char *uri, E2kContextChangeType type, gpointer user_data);
@@ -477,6 +480,7 @@
 				       field_names, n_field_names,
 				       bepriv->base_rn, NULL, TRUE);
 
+	LOCK (bepriv);
 	e_file_cache_freeze_changes (E_FILE_CACHE (bepriv->cache));
 	while ((result = e2k_result_iter_next (iter))) {
 		contact = e_contact_from_props (be, result);
@@ -488,6 +492,7 @@
 	e_book_backend_cache_set_populated (bepriv->cache);
 	bepriv->is_cache_ready=TRUE;
 	e_file_cache_thaw_changes (E_FILE_CACHE (bepriv->cache));
+	UNLOCK (bepriv);
 	return NULL;
 }
 
@@ -520,6 +525,7 @@
 				       field_names, n_field_names,
 				       bepriv->base_rn, NULL, TRUE);
 
+	LOCK (bepriv);
 	e_file_cache_freeze_changes (E_FILE_CACHE (bepriv->cache));
 	while ((result = e2k_result_iter_next (iter))) {
 		contact = e_contact_from_props (be, result);
@@ -531,7 +537,7 @@
 	e_book_backend_cache_set_populated (bepriv->cache);
 	bepriv->is_cache_ready=TRUE;
 	e_file_cache_thaw_changes (E_FILE_CACHE (bepriv->cache));
-
+	UNLOCK (bepriv);
 	return TRUE;
 }
 
@@ -1319,13 +1325,13 @@
 
 	d(printf("ebbe_create_contact(%p, %p, %s)\n", backend, book, vcard));
 
-	g_mutex_lock (bepriv->create_mutex);
+	LOCK (bepriv);
 
 	switch (bepriv->mode) {
 
 	case GNOME_Evolution_Addressbook_MODE_LOCAL:
 		*contact = NULL;
-		g_mutex_unlock (bepriv->create_mutex);
+		UNLOCK (bepriv);
 		return GNOME_Evolution_Addressbook_RepositoryOffline;
 	
 	case GNOME_Evolution_Addressbook_MODE_REMOTE:	
@@ -1346,6 +1353,7 @@
 			state = e_book_backend_exchange_connect (be);
 			if ( state != GNOME_Evolution_Addressbook_Success) {
 				d(printf("Returning status %d while creating contact\n", state));
+				UNLOCK (bepriv);
 				return state;
 			}
 		}
@@ -1375,18 +1383,18 @@
 			e_book_backend_summary_add_contact (bepriv->summary,
 							    *contact);
 			e_book_backend_cache_add_contact (bepriv->cache, *contact);
-			g_mutex_unlock (bepriv->create_mutex);
+			UNLOCK (bepriv);
 			return GNOME_Evolution_Addressbook_Success;
 		} else {
 			g_object_unref (*contact);
 			*contact = NULL;
-			g_mutex_unlock (bepriv->create_mutex);
+			UNLOCK (bepriv);
 			return http_status_to_pas (status);
 		}
 	default:
 		break;
 	}
-	g_mutex_unlock (bepriv->create_mutex);
+	UNLOCK (bepriv);
 	return GNOME_Evolution_Addressbook_Success;
 }
 
@@ -1501,13 +1509,14 @@
 			e2k_results_free (results, nresults);
 
 		if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status)) {
+ 			LOCK (bepriv);
 			e_book_backend_summary_remove_contact (bepriv->summary,
 							       uri);
 			e_book_backend_summary_add_contact (bepriv->summary,
 							    *contact);
 			e_book_backend_cache_remove_contact (bepriv->cache, uri);
 			e_book_backend_cache_add_contact (bepriv->cache, *contact);
-			
+ 			UNLOCK (bepriv);			
 			return GNOME_Evolution_Addressbook_Success;
 		} else {
 			g_object_unref (*contact);
@@ -1550,11 +1559,13 @@
 			uri = l->data;
 			status = e2k_context_delete (bepriv->ctx, NULL, uri);
 			if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status)) {
+ 				LOCK (bepriv);
 				e_book_backend_summary_remove_contact (
 							bepriv->summary, uri);
 				e_book_backend_cache_remove_contact (bepriv->cache, uri);
 				*removed_ids = g_list_append (
 						*removed_ids, g_strdup (uri));
+				UNLOCK (bepriv);
 			} else 
 				ret_status = http_status_to_pas (status);
 		}
@@ -2537,8 +2548,8 @@
 		if (be->priv->cache)
 			g_object_unref (be->priv->cache);
 
-		if (be->priv->create_mutex)
-			g_mutex_free (be->priv->create_mutex);
+		if (be->priv->cache_lock)
+			g_mutex_free (be->priv->cache_lock);
 			
 
 		g_free (be->priv);
@@ -2608,7 +2619,7 @@
 	priv->original_uri 	= NULL;
 	priv->is_writable 	= TRUE;
 
-	priv->create_mutex      = g_mutex_new ();
+	priv->cache_lock      = g_mutex_new ();
 
 	backend->priv 		= priv;
 }