[totem-pl-parser] Fix parsing of pukas.wax



commit 58be46c568c9fb582ca8f99c1cbed31d450eec6c
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Mar 2 16:50:58 2010 +0000

    Fix parsing of pukas.wax
    
    The playlist-started signal would happen after we parsed the first
    entry, which means that Rhythmbox would be ignoring it.
    
    Reported at:
    http://thread.gmane.org/gmane.comp.gnome.apps.rhythmbox.devel/10810

 plparse/tests/parser.c       |   58 ++++++++++++++++++++++++++++++++++++++++++
 plparse/tests/pukas.wax      |   15 +++++++++++
 plparse/totem-pl-parser-wm.c |    9 ++++++-
 3 files changed, 81 insertions(+), 1 deletions(-)
---
diff --git a/plparse/tests/parser.c b/plparse/tests/parser.c
index 6dcc5ed..145b5b5 100644
--- a/plparse/tests/parser.c
+++ b/plparse/tests/parser.c
@@ -271,6 +271,50 @@ parser_test_get_parse_result (const char *uri)
 	return ret;
 }
 
+static void
+playlist_started_order (TotemPlParser *parser,
+			const char *uri,
+			GHashTable *metadata,
+			gboolean *ret)
+{
+	*ret = TRUE;
+}
+
+static void
+entry_parsed_cb_order (TotemPlParser *parser,
+		       const char *uri,
+		       GHashTable *metadata,
+		       gboolean *ret)
+{
+	/* Check that the playlist started happened before the entry appeared */
+	g_assert (*ret != FALSE);
+}
+
+static gboolean
+parser_test_get_order_result (const char *uri)
+{
+	TotemPlParserResult retval;
+	gboolean pl_started;
+	TotemPlParser *pl = totem_pl_parser_new ();
+
+	g_object_set (pl, "recurse", !option_no_recurse,
+			  "debug", option_debug,
+			  "force", option_force,
+			  "disable-unsafe", option_disable_unsafe,
+			  NULL);
+	g_signal_connect (G_OBJECT (pl), "playlist-started",
+			  G_CALLBACK (playlist_started_order), &pl_started);
+	g_signal_connect (G_OBJECT (pl), "entry-parsed",
+			  G_CALLBACK (entry_parsed_cb_order), &pl_started);
+
+	pl_started = FALSE;
+	retval = totem_pl_parser_parse_with_base (pl, uri, option_base_uri, FALSE);
+	g_test_message ("Got retval %d for uri '%s'", retval, uri);
+	g_object_unref (pl);
+
+	return pl_started;
+}
+
 static TotemPlParserResult
 simple_parser_test (const char *uri)
 {
@@ -338,6 +382,19 @@ test_parsing_broken_asx (void)
 }
 
 static void
+test_parsing_out_of_order_asx (void)
+{
+	char *uri;
+	gboolean result;
+
+	/* From http://82.135.234.195/pukas.wax */
+	uri = get_relative_uri (TEST_SRCDIR "pukas.wax");
+	result = parser_test_get_order_result (uri);
+	g_free (uri);
+	g_assert (result != FALSE);
+}
+
+static void
 test_parsing_404_error (void)
 {
 	g_test_bug ("158052");
@@ -544,6 +601,7 @@ main (int argc, char *argv[])
 		g_test_add_func ("/parser/parsing/nonexistent_files", test_parsing_nonexistent_files);
 		g_test_add_func ("/parser/parsing/broken_asx", test_parsing_broken_asx);
 		g_test_add_func ("/parser/parsing/404_error", test_parsing_404_error);
+		g_test_add_func ("/parser/parsing/out_of_order_asx", test_parsing_out_of_order_asx);
 		g_test_add_func ("/parser/parsing/xml_head_comments", test_parsing_xml_head_comments);
 		g_test_add_func ("/parser/parsing/xml_comment_whitespace", test_parsing_xml_comment_whitespace);
 		g_test_add_func ("/parser/parsing/multi_line_rtsptext", test_parsing_rtsp_text_multi);
diff --git a/plparse/tests/pukas.wax b/plparse/tests/pukas.wax
new file mode 100644
index 0000000..46749ce
--- /dev/null
+++ b/plparse/tests/pukas.wax
@@ -0,0 +1,15 @@
+<asx version = "3.0">
+  <entry>
+    <ref href = "mms://82.135.234.195/Pukas"/>
+    <ref href = "http://82.135.234.199/Pukas"/>
+  <Title>Pukas</Title>
+  <Author>www.pukas.lt</Author>
+  <Copyright>UAB Pukas</Copyright>
+  <Banner href="http://82.135.234.195/images/pukas_teo_logo.jpg";></Banner>
+  </entry>
+  <Title>Pukas</Title>
+  <Author>www.pukas.lt</Author>
+  <Copyright>UAB Pukas</Copyright>
+  <Banner href="http://82.135.234.195/images/pukas_teo_logo.jpg";></Banner>
+  <LogURL href = ""/>
+</asx>
diff --git a/plparse/totem-pl-parser-wm.c b/plparse/totem-pl-parser-wm.c
index 3a544c2..6950f2a 100644
--- a/plparse/totem-pl-parser-wm.c
+++ b/plparse/totem-pl-parser-wm.c
@@ -319,10 +319,10 @@ parse_asx_entries (TotemPlParser *parser, const char *uri, GFile *base_file, xml
 
 	new_base = NULL;
 
+	/* Loop to look for playlist information first */
 	for (node = parent->child; node != NULL; node = node->next) {
 		if (node->name == NULL)
 			continue;
-
 		if (g_ascii_strcasecmp (node->name, "title") == 0) {
 			g_free (title);
 			title = g_strdup (node->data);
@@ -341,6 +341,13 @@ parse_asx_entries (TotemPlParser *parser, const char *uri, GFile *base_file, xml
 				new_base = g_file_new_for_uri (str);
 			}
 		}
+	}
+
+	/* Restart for the entries now */
+	for (node = parent->child; node != NULL; node = node->next) {
+		if (node->name == NULL)
+			continue;
+
 		if (g_ascii_strcasecmp (node->name, "entry") == 0) {
 			/* Whee! found an entry here, find the REF and TITLE */
 			if (parse_asx_entry (parser, new_base ? new_base : base_file, node, parse_data) != FALSE)



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