aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ephy-node-db.c
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2003-09-18 06:04:47 +0800
committerChristian Persch <chpe@src.gnome.org>2003-09-18 06:04:47 +0800
commit6d93635b94a93ff3188e88a46393083fbca7e603 (patch)
treeec38e729d6ce9251ad0ce2f737168e483ff979d9 /lib/ephy-node-db.c
parentff09416c7a185b6774c5f1e04c9673c9f0d86f71 (diff)
downloadgsoc2013-epiphany-6d93635b94a93ff3188e88a46393083fbca7e603.tar
gsoc2013-epiphany-6d93635b94a93ff3188e88a46393083fbca7e603.tar.gz
gsoc2013-epiphany-6d93635b94a93ff3188e88a46393083fbca7e603.tar.bz2
gsoc2013-epiphany-6d93635b94a93ff3188e88a46393083fbca7e603.tar.lz
gsoc2013-epiphany-6d93635b94a93ff3188e88a46393083fbca7e603.tar.xz
gsoc2013-epiphany-6d93635b94a93ff3188e88a46393083fbca7e603.tar.zst
gsoc2013-epiphany-6d93635b94a93ff3188e88a46393083fbca7e603.zip
Refactor node db loading functions into a common one in ephy-node-db.
2003-09-18 Christian Persch <chpe@cvs.gnome.org> * embed/ephy-favicon-cache.c: (ephy_favicon_cache_init): * embed/ephy-history.c: (ephy_history_init): * lib/ephy-node-db.c: (ephy_node_db_load_from_file): * lib/ephy-node-db.h: * lib/ephy-state.c: (ensure_states): * src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_init): Refactor node db loading functions into a common one in ephy-node-db. Switch to using xmlReader api.
Diffstat (limited to 'lib/ephy-node-db.c')
-rw-r--r--lib/ephy-node-db.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/lib/ephy-node-db.c b/lib/ephy-node-db.c
index c6d084bed..58ca3fe91 100644
--- a/lib/ephy-node-db.c
+++ b/lib/ephy-node-db.c
@@ -19,6 +19,9 @@
*/
#include "ephy-node-db.h"
+#include "ephy-debug.h"
+
+#include <libxml/xmlreader.h>
static void ephy_node_db_class_init (EphyNodeDbClass *klass);
static void ephy_node_db_init (EphyNodeDb *node);
@@ -291,3 +294,84 @@ _ephy_node_db_remove_id (EphyNodeDb *db,
g_static_rw_lock_writer_unlock (db->priv->id_to_node_lock);
}
+
+gboolean
+ephy_node_db_load_from_file (EphyNodeDb *db,
+ const char *xml_file,
+ const xmlChar *xml_root,
+ const xmlChar *xml_version)
+{
+ xmlTextReaderPtr reader;
+ gboolean success = TRUE;
+ int ret;
+
+ LOG ("ephy_node_db_load_from_file %s", xml_file)
+
+ START_PROFILER ("loading node db")
+
+ if (g_file_test (xml_file, G_FILE_TEST_EXISTS) == FALSE)
+ {
+ return FALSE;
+ }
+
+ reader = xmlNewTextReaderFilename (xml_file);
+ if (reader == NULL)
+ {
+ return FALSE;
+ }
+
+ ret = xmlTextReaderRead (reader);
+ while (ret == 1)
+ {
+ xmlChar *name;
+ xmlReaderTypes type;
+ gboolean skip = FALSE;
+
+ name = xmlTextReaderName (reader);
+ type = xmlTextReaderNodeType (reader);
+
+ if (xmlStrEqual (name, "node")
+ && type == XML_READER_TYPE_ELEMENT)
+ {
+ xmlNodePtr subtree;
+ EphyNode *node;
+
+ /* grow the subtree and load the node from it */
+ subtree = xmlTextReaderExpand (reader);
+
+ node = ephy_node_new_from_xml (db, subtree);
+
+ skip = TRUE;
+ }
+ else if (xmlStrEqual (name, xml_root)
+ && type == XML_READER_TYPE_ELEMENT)
+ {
+ xmlChar *version;
+
+ /* check version info */
+ version = xmlTextReaderGetAttribute (reader, "version");
+ if (xmlStrEqual (version, xml_version) == FALSE)
+ {
+ success = FALSE;
+ xmlFree (version);
+ xmlFree (name);
+
+ break;
+ }
+
+ xmlFree (version);
+ }
+
+ xmlFree (name);
+
+ /* next one, please */
+ ret = skip ? xmlTextReaderNext (reader)
+ : xmlTextReaderRead (reader);
+ }
+
+ xmlFreeTextReader (reader);
+
+ STOP_PROFILER ("loading node db")
+
+ return (success && ret == 0);
+}