aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-pilot-map.c
diff options
context:
space:
mode:
authorJP Rosevear <jpr@ximian.com>2001-11-14 03:24:55 +0800
committerJP Rosevear <jpr@src.gnome.org>2001-11-14 03:24:55 +0800
commit541cb80af5a1dd9f0005ab15827d79acb01e29fb (patch)
tree9f571e2b3b90e336d8bcaad3458fcbc0a665943c /e-util/e-pilot-map.c
parentc132868844b7a10288949b41a3d3e9b5a82430e2 (diff)
downloadgsoc2013-evolution-541cb80af5a1dd9f0005ab15827d79acb01e29fb.tar
gsoc2013-evolution-541cb80af5a1dd9f0005ab15827d79acb01e29fb.tar.gz
gsoc2013-evolution-541cb80af5a1dd9f0005ab15827d79acb01e29fb.tar.bz2
gsoc2013-evolution-541cb80af5a1dd9f0005ab15827d79acb01e29fb.tar.lz
gsoc2013-evolution-541cb80af5a1dd9f0005ab15827d79acb01e29fb.tar.xz
gsoc2013-evolution-541cb80af5a1dd9f0005ab15827d79acb01e29fb.tar.zst
gsoc2013-evolution-541cb80af5a1dd9f0005ab15827d79acb01e29fb.zip
only insert non-0 pids into the pid map (e_pilot_map_insert): remove and
2001-11-13 JP Rosevear <jpr@ximian.com> * e-pilot-map.c (real_e_pilot_map_insert): only insert non-0 pids into the pid map (e_pilot_map_insert): remove and free old keys/values here - including possibly orphaned keys (e_pilot_map_remove_by_uid): only free things if they should have been found svn path=/trunk/; revision=14687
Diffstat (limited to 'e-util/e-pilot-map.c')
-rw-r--r--e-util/e-pilot-map.c86
1 files changed, 60 insertions, 26 deletions
diff --git a/e-util/e-pilot-map.c b/e-util/e-pilot-map.c
index b1b4e80052..93ec68c050 100644
--- a/e-util/e-pilot-map.c
+++ b/e-util/e-pilot-map.c
@@ -56,21 +56,25 @@ real_e_pilot_map_insert (EPilotMap *map, guint32 pid, const char *uid, gboolean
guint32 *new_pid;
EPilotMapPidNode *pnode;
EPilotMapUidNode *unode;
- gpointer key, value;
g_return_if_fail (map != NULL);
g_return_if_fail (uid != NULL);
- new_pid = g_new (guint32, 1);
- *new_pid = pid;
-
+ /* Keys */
+ if (pid != 0) {
+ new_pid = g_new (guint32, 1);
+ *new_pid = pid;
+ }
new_uid = g_strdup (uid);
- pnode = g_new0 (EPilotMapPidNode, 1);
- pnode->uid = new_uid;
- pnode->archived = archived;
- if (touch)
- pnode->touched = TRUE;
+ /* Values */
+ if (pid != 0) {
+ pnode = g_new0 (EPilotMapPidNode, 1);
+ pnode->uid = new_uid;
+ pnode->archived = archived;
+ if (touch)
+ pnode->touched = TRUE;
+ }
unode = g_new0 (EPilotMapUidNode, 1);
unode->pid = pid;
@@ -78,18 +82,9 @@ real_e_pilot_map_insert (EPilotMap *map, guint32 pid, const char *uid, gboolean
if (touch)
unode->touched = TRUE;
- if (g_hash_table_lookup_extended (map->pid_map, new_pid, &key, &value)) {
- g_hash_table_remove (map->pid_map, new_pid);
- g_free (key);
- g_free (value);
- }
- if (g_hash_table_lookup_extended (map->uid_map, new_uid, &key, &value)) {
- g_hash_table_remove (map->uid_map, new_uid);
- g_free (key);
- g_free (value);
- }
-
- g_hash_table_insert (map->pid_map, new_pid, pnode);
+ /* Insertion */
+ if (pid != 0)
+ g_hash_table_insert (map->pid_map, new_pid, pnode);
g_hash_table_insert (map->uid_map, new_uid, unode);
}
@@ -210,6 +205,41 @@ e_pilot_map_uid_is_archived (EPilotMap *map, const char *uid)
void
e_pilot_map_insert (EPilotMap *map, guint32 pid, const char *uid, gboolean archived)
{
+ gpointer key, value;
+
+ if (g_hash_table_lookup_extended (map->pid_map, &pid, &key, &value)) {
+ EPilotMapPidNode *pnode = value;
+ gpointer other_key, other_value;
+
+ g_hash_table_remove (map->pid_map, &pid);
+
+ /* In case the pid<->uid mapping is not the same anymore */
+ if (g_hash_table_lookup_extended (map->uid_map, pnode->uid, &other_key, &other_value)) {
+ g_hash_table_remove (map->uid_map, pnode->uid);
+ g_free (other_key);
+ g_free (other_value);
+ }
+
+ g_free (key);
+ g_free (value);
+ }
+ if (g_hash_table_lookup_extended (map->uid_map, uid, &key, &value)) {
+ EPilotMapUidNode *unode = value;
+ gpointer other_key, other_value;
+
+ g_hash_table_remove (map->uid_map, uid);
+
+ /* In case the pid<->uid mapping is not the same anymore */
+ if (g_hash_table_lookup_extended (map->pid_map, &unode->pid, &other_key, &other_value)) {
+ g_hash_table_remove (map->pid_map, &unode->pid);
+ g_free (other_key);
+ g_free (other_value);
+ }
+
+ g_free (key);
+ g_free (value);
+ }
+
real_e_pilot_map_insert (map, pid, uid, archived, TRUE);
}
@@ -242,24 +272,28 @@ e_pilot_map_remove_by_pid (EPilotMap *map, guint32 pid)
void
e_pilot_map_remove_by_uid (EPilotMap *map, const char *uid)
{
- EPilotMapPidNode *pnode;
- EPilotMapUidNode *unode;
+ EPilotMapPidNode *pnode = NULL;
+ EPilotMapUidNode *unode = NULL;
gpointer pkey, ukey;
+ gboolean found;
g_return_if_fail (map != NULL);
g_return_if_fail (uid != NULL);
if (!g_hash_table_lookup_extended (map->uid_map, uid, &ukey, (gpointer *)&unode))
return;
-
+
g_hash_table_lookup_extended (map->pid_map, &unode->pid, &pkey, (gpointer *)&pnode);
g_hash_table_remove (map->uid_map, uid);
g_hash_table_remove (map->pid_map, &unode->pid);
- g_free (pkey);
+ if (unode->pid != 0)
+ g_free (pkey);
g_free (ukey);
- g_free (pnode);
+
+ if (unode->pid != 0)
+ g_free (pnode);
g_free (unode);
}