[totem-pl-parser] lib: Split out XSPF parsing from data



commit 447209886ae9c8eacdc9066327d75a088a427275
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Feb 20 01:29:44 2012 +0100

    lib: Split out XSPF parsing from data

 plparse/totem-pl-parser-xspf.c |   50 +++++++++++++++++++++++++++++++++++----
 plparse/totem-pl-parser-xspf.h |    5 ++++
 2 files changed, 49 insertions(+), 6 deletions(-)
---
diff --git a/plparse/totem-pl-parser-xspf.c b/plparse/totem-pl-parser-xspf.c
index 23a60c2..7fb264d 100644
--- a/plparse/totem-pl-parser-xspf.c
+++ b/plparse/totem-pl-parser-xspf.c
@@ -380,6 +380,49 @@ parse_xspf_entries (TotemPlParser *parser, GFile *base_file, xmlDocPtr doc,
 	return retval;
 }
 
+static gboolean
+is_xspf_doc (xmlDocPtr doc)
+{
+	/* If the document has no root, or no name */
+	if(!doc ||
+	   !doc->children ||
+	   !doc->children->name ||
+	   g_ascii_strcasecmp ((char *)doc->children->name, "playlist") != 0) {
+		return FALSE;
+	}
+	return TRUE;
+}
+
+TotemPlParserResult
+totem_pl_parser_add_xspf_with_contents (TotemPlParser *parser,
+					GFile *file,
+					GFile *base_file,
+					const char *contents,
+					TotemPlParseData *parse_data)
+{
+	xmlDocPtr doc;
+	xmlNodePtr node;
+	TotemPlParserResult retval = TOTEM_PL_PARSER_RESULT_UNHANDLED;
+
+	doc = xmlParseMemory (contents, strlen (contents));
+	if (doc == NULL)
+		doc = xmlRecoverMemory (contents, strlen (contents));
+
+	if (is_xspf_doc (doc) == FALSE) {
+		if (doc != NULL)
+			xmlFreeDoc(doc);
+		return TOTEM_PL_PARSER_RESULT_ERROR;
+	}
+
+	for (node = doc->children; node != NULL; node = node->next) {
+		if (parse_xspf_entries (parser, base_file, doc, node) != FALSE)
+			retval = TOTEM_PL_PARSER_RESULT_SUCCESS;
+	}
+
+	xmlFreeDoc(doc);
+	return retval;
+}
+
 TotemPlParserResult
 totem_pl_parser_add_xspf (TotemPlParser *parser,
 			  GFile *file,
@@ -392,12 +435,7 @@ totem_pl_parser_add_xspf (TotemPlParser *parser,
 	TotemPlParserResult retval = TOTEM_PL_PARSER_RESULT_UNHANDLED;
 
 	doc = totem_pl_parser_parse_xml_file (file);
-
-	/* If the document has no root, or no name */
-	if(!doc || !doc->children
-			|| !doc->children->name
-			|| g_ascii_strcasecmp ((char *)doc->children->name,
-				"playlist") != 0) {
+	if (is_xspf_doc (doc) == FALSE) {
 		if (doc != NULL)
 			xmlFreeDoc(doc);
 		return TOTEM_PL_PARSER_RESULT_ERROR;
diff --git a/plparse/totem-pl-parser-xspf.h b/plparse/totem-pl-parser-xspf.h
index c8e3695..64039cd 100644
--- a/plparse/totem-pl-parser-xspf.h
+++ b/plparse/totem-pl-parser-xspf.h
@@ -39,6 +39,11 @@ gboolean totem_pl_parser_save_xspf (TotemPlParser *parser,
                                     const char *title,
                                     GError **error);
 
+TotemPlParserResult totem_pl_parser_add_xspf_with_contents (TotemPlParser *parser,
+							    GFile *file,
+							    GFile *base_file,
+							    const char *contents,
+							    TotemPlParseData *parse_data);
 
 TotemPlParserResult totem_pl_parser_add_xspf (TotemPlParser *parser,
 					      GFile *file,



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