add archived records with pilot id of 0 (map_write_foreach): use the uid
2001-10-26 JP Rosevear <jpr@ximian.com> * e-pilot-map.c (map_sax_start_element): add archived records with pilot id of 0 (map_write_foreach): use the uid map for writing (e_pilot_map_write): write using the uid map svn path=/trunk/; revision=14147
This commit is contained in:
@ -1,3 +1,10 @@
|
|||||||
|
2001-10-26 JP Rosevear <jpr@ximian.com>
|
||||||
|
|
||||||
|
* e-pilot-map.c (map_sax_start_element): add archived records
|
||||||
|
with pilot id of 0
|
||||||
|
(map_write_foreach): use the uid map for writing
|
||||||
|
(e_pilot_map_write): write using the uid map
|
||||||
|
|
||||||
2001-10-26 JP Rosevear <jpr@ximian.com>
|
2001-10-26 JP Rosevear <jpr@ximian.com>
|
||||||
|
|
||||||
* e-pilot-map.c (e_pilot_map_insert): free up old memory first
|
* e-pilot-map.c (e_pilot_map_insert): free up old memory first
|
||||||
|
@ -90,9 +90,11 @@ map_sax_start_element (void *data, const xmlChar *name,
|
|||||||
|
|
||||||
attrs = ++val;
|
attrs = ++val;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uid && pid != 0)
|
g_assert (uid != NULL);
|
||||||
e_pilot_map_insert (map, pid, uid, archived);
|
g_assert (pid != 0 || archived);
|
||||||
|
|
||||||
|
e_pilot_map_insert (map, pid, uid, archived);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,28 +103,30 @@ map_write_foreach (gpointer key, gpointer value, gpointer data)
|
|||||||
{
|
{
|
||||||
xmlNodePtr root = data;
|
xmlNodePtr root = data;
|
||||||
xmlNodePtr mnode;
|
xmlNodePtr mnode;
|
||||||
unsigned long *pid = key;
|
char *uid = key;
|
||||||
EPilotMapPidNode *pnode = value;
|
EPilotMapUidNode *unode = value;
|
||||||
char *pidstr;
|
char *pidstr;
|
||||||
|
|
||||||
mnode = xmlNewChild (root, NULL, "map", NULL);
|
mnode = xmlNewChild (root, NULL, "map", NULL);
|
||||||
|
|
||||||
pidstr = g_strdup_printf ("%lu", *pid);
|
|
||||||
xmlSetProp (mnode, "pilot_id", pidstr);
|
|
||||||
g_free (pidstr);
|
|
||||||
|
|
||||||
xmlSetProp (mnode, "uid", pnode->uid);
|
xmlSetProp (mnode, "uid", uid);
|
||||||
|
|
||||||
if (pnode->archived)
|
if (unode->archived) {
|
||||||
xmlSetProp (mnode, "archived", "1");
|
xmlSetProp (mnode, "archived", "1");
|
||||||
else
|
} else {
|
||||||
|
pidstr = g_strdup_printf ("%d", unode->pid);
|
||||||
|
xmlSetProp (mnode, "pilot_id", pidstr);
|
||||||
|
g_free (pidstr);
|
||||||
xmlSetProp (mnode, "archived", "0");
|
xmlSetProp (mnode, "archived", "0");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
e_pilot_map_pid_is_archived (EPilotMap *map, guint32 pid)
|
e_pilot_map_pid_is_archived (EPilotMap *map, guint32 pid)
|
||||||
{
|
{
|
||||||
EPilotMapPidNode *pnode;
|
EPilotMapPidNode *pnode;
|
||||||
|
|
||||||
|
g_return_val_if_fail (map != NULL, FALSE);
|
||||||
|
|
||||||
pnode = g_hash_table_lookup (map->pid_map, &pid);
|
pnode = g_hash_table_lookup (map->pid_map, &pid);
|
||||||
|
|
||||||
@ -136,6 +140,9 @@ gboolean
|
|||||||
e_pilot_map_uid_is_archived (EPilotMap *map, const char *uid)
|
e_pilot_map_uid_is_archived (EPilotMap *map, const char *uid)
|
||||||
{
|
{
|
||||||
EPilotMapUidNode *unode;
|
EPilotMapUidNode *unode;
|
||||||
|
|
||||||
|
g_return_val_if_fail (map != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (uid != NULL, FALSE);
|
||||||
|
|
||||||
unode = g_hash_table_lookup (map->uid_map, uid);
|
unode = g_hash_table_lookup (map->uid_map, uid);
|
||||||
|
|
||||||
@ -149,17 +156,24 @@ void
|
|||||||
e_pilot_map_insert (EPilotMap *map, guint32 pid, const char *uid, gboolean archived)
|
e_pilot_map_insert (EPilotMap *map, guint32 pid, const char *uid, gboolean archived)
|
||||||
{
|
{
|
||||||
char *new_uid;
|
char *new_uid;
|
||||||
guint32 *new_pid = g_new (guint32, 1);
|
guint32 *new_pid;
|
||||||
EPilotMapPidNode *pnode = g_new0 (EPilotMapPidNode, 1);
|
EPilotMapPidNode *pnode;
|
||||||
EPilotMapUidNode *unode = g_new0 (EPilotMapUidNode, 1);
|
EPilotMapUidNode *unode;
|
||||||
gpointer key, value;
|
gpointer key, value;
|
||||||
|
|
||||||
|
g_return_if_fail (map != NULL);
|
||||||
|
g_return_if_fail (uid != NULL);
|
||||||
|
|
||||||
|
new_pid = g_new (guint32, 1);
|
||||||
*new_pid = pid;
|
*new_pid = pid;
|
||||||
|
|
||||||
new_uid = g_strdup (uid);
|
new_uid = g_strdup (uid);
|
||||||
|
|
||||||
|
pnode = g_new0 (EPilotMapPidNode, 1);
|
||||||
pnode->uid = new_uid;
|
pnode->uid = new_uid;
|
||||||
pnode->archived = archived;
|
pnode->archived = archived;
|
||||||
|
|
||||||
|
unode = g_new0 (EPilotMapUidNode, 1);
|
||||||
unode->pid = pid;
|
unode->pid = pid;
|
||||||
unode->archived = archived;
|
unode->archived = archived;
|
||||||
|
|
||||||
@ -180,10 +194,12 @@ e_pilot_map_insert (EPilotMap *map, guint32 pid, const char *uid, gboolean archi
|
|||||||
|
|
||||||
void
|
void
|
||||||
e_pilot_map_remove_by_pid (EPilotMap *map, guint32 pid)
|
e_pilot_map_remove_by_pid (EPilotMap *map, guint32 pid)
|
||||||
{
|
{
|
||||||
EPilotMapPidNode *pnode;
|
EPilotMapPidNode *pnode;
|
||||||
EPilotMapUidNode *unode;
|
EPilotMapUidNode *unode;
|
||||||
|
|
||||||
|
g_return_if_fail (map != NULL);
|
||||||
|
|
||||||
pnode = g_hash_table_lookup (map->pid_map, &pid);
|
pnode = g_hash_table_lookup (map->pid_map, &pid);
|
||||||
if (!pnode)
|
if (!pnode)
|
||||||
return;
|
return;
|
||||||
@ -203,6 +219,9 @@ e_pilot_map_remove_by_uid (EPilotMap *map, const char *uid)
|
|||||||
EPilotMapPidNode *pnode;
|
EPilotMapPidNode *pnode;
|
||||||
EPilotMapUidNode *unode;
|
EPilotMapUidNode *unode;
|
||||||
|
|
||||||
|
g_return_if_fail (map != NULL);
|
||||||
|
g_return_if_fail (uid != NULL);
|
||||||
|
|
||||||
unode = g_hash_table_lookup (map->uid_map, uid);
|
unode = g_hash_table_lookup (map->uid_map, uid);
|
||||||
if (!unode)
|
if (!unode)
|
||||||
return;
|
return;
|
||||||
@ -221,6 +240,9 @@ guint32
|
|||||||
e_pilot_map_lookup_pid (EPilotMap *map, const char *uid)
|
e_pilot_map_lookup_pid (EPilotMap *map, const char *uid)
|
||||||
{
|
{
|
||||||
EPilotMapUidNode *unode = NULL;
|
EPilotMapUidNode *unode = NULL;
|
||||||
|
|
||||||
|
g_return_val_if_fail (map != NULL, 0);
|
||||||
|
g_return_val_if_fail (uid != NULL, 0);
|
||||||
|
|
||||||
unode = g_hash_table_lookup (map->uid_map, uid);
|
unode = g_hash_table_lookup (map->uid_map, uid);
|
||||||
|
|
||||||
@ -234,6 +256,8 @@ const char *
|
|||||||
e_pilot_map_lookup_uid (EPilotMap *map, guint32 pid)
|
e_pilot_map_lookup_uid (EPilotMap *map, guint32 pid)
|
||||||
{
|
{
|
||||||
EPilotMapPidNode *pnode = NULL;
|
EPilotMapPidNode *pnode = NULL;
|
||||||
|
|
||||||
|
g_return_val_if_fail (map != NULL, NULL);
|
||||||
|
|
||||||
pnode = g_hash_table_lookup (map->pid_map, &pid);
|
pnode = g_hash_table_lookup (map->pid_map, &pid);
|
||||||
|
|
||||||
@ -247,10 +271,14 @@ int
|
|||||||
e_pilot_map_read (const char *filename, EPilotMap **map)
|
e_pilot_map_read (const char *filename, EPilotMap **map)
|
||||||
{
|
{
|
||||||
xmlSAXHandler handler;
|
xmlSAXHandler handler;
|
||||||
EPilotMap *new_map = g_new0 (EPilotMap, 1);
|
EPilotMap *new_map;
|
||||||
|
|
||||||
|
g_return_val_if_fail (filename != NULL, -1);
|
||||||
|
g_return_val_if_fail (map != NULL, -1);
|
||||||
|
|
||||||
*map = NULL;
|
*map = NULL;
|
||||||
|
new_map = g_new0 (EPilotMap, 1);
|
||||||
|
|
||||||
memset (&handler, 0, sizeof (xmlSAXHandler));
|
memset (&handler, 0, sizeof (xmlSAXHandler));
|
||||||
handler.startElement = map_sax_start_element;
|
handler.startElement = map_sax_start_element;
|
||||||
|
|
||||||
@ -274,7 +302,8 @@ e_pilot_map_write (const char *filename, EPilotMap *map)
|
|||||||
{
|
{
|
||||||
xmlDocPtr doc;
|
xmlDocPtr doc;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
g_return_val_if_fail (filename != NULL, -1);
|
||||||
g_return_val_if_fail (map != NULL, -1);
|
g_return_val_if_fail (map != NULL, -1);
|
||||||
|
|
||||||
doc = xmlNewDoc ("1.0");
|
doc = xmlNewDoc ("1.0");
|
||||||
@ -286,7 +315,7 @@ e_pilot_map_write (const char *filename, EPilotMap *map)
|
|||||||
map->since = time (NULL);
|
map->since = time (NULL);
|
||||||
map_set_node_timet (doc->root, "timestamp", map->since);
|
map_set_node_timet (doc->root, "timestamp", map->since);
|
||||||
|
|
||||||
g_hash_table_foreach (map->pid_map, map_write_foreach, doc->root);
|
g_hash_table_foreach (map->uid_map, map_write_foreach, doc->root);
|
||||||
|
|
||||||
/* Write the file */
|
/* Write the file */
|
||||||
xmlSetDocCompressMode (doc, 0);
|
xmlSetDocCompressMode (doc, 0);
|
||||||
@ -313,6 +342,8 @@ foreach_remove (gpointer key, gpointer value, gpointer data)
|
|||||||
void
|
void
|
||||||
e_pilot_map_destroy (EPilotMap *map)
|
e_pilot_map_destroy (EPilotMap *map)
|
||||||
{
|
{
|
||||||
|
g_return_if_fail (map != NULL);
|
||||||
|
|
||||||
g_hash_table_foreach_remove (map->pid_map, foreach_remove, NULL);
|
g_hash_table_foreach_remove (map->pid_map, foreach_remove, NULL);
|
||||||
g_hash_table_foreach_remove (map->uid_map, foreach_remove, NULL);
|
g_hash_table_foreach_remove (map->uid_map, foreach_remove, NULL);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user