[totem-pl-parser] Fix parsing of dual-types after sniffing



commit 12316e257478b6e144186427eb92b0c1ab2d1c42
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Apr 7 17:55:07 2010 +0100

    Fix parsing of dual-types after sniffing
    
    After getting the data type of a playlist through the actual data,
    we should check again if it matches the parser we want to use,
    otherwise we'll end up trying to parse video files that were
    masquerading as dual-type playlists.
    
    Test file included
    
    https://bugzilla.gnome.org/show_bug.cgi?id=610471

 plparse/tests/Makefile.am             |    3 ++-
 plparse/tests/asf-with-asx-suffix.asx |  Bin 0 -> 94230 bytes
 plparse/tests/parser.c                |   12 ++++++++++++
 plparse/totem-pl-parser.c             |   19 +++++++++++++++++++
 4 files changed, 33 insertions(+), 1 deletions(-)
---
diff --git a/plparse/tests/Makefile.am b/plparse/tests/Makefile.am
index c617b7a..e9b111d 100644
--- a/plparse/tests/Makefile.am
+++ b/plparse/tests/Makefile.am
@@ -51,4 +51,5 @@ EXTRA_DIST =			\
 	602127.qtl		\
 	live-streaming.m3u	\
 	single-line.qtl		\
-	pukas.wax
+	pukas.wax		\
+	asf-with-asx-suffix.asx
diff --git a/plparse/tests/asf-with-asx-suffix.asx b/plparse/tests/asf-with-asx-suffix.asx
new file mode 100644
index 0000000..7372fcd
Binary files /dev/null and b/plparse/tests/asf-with-asx-suffix.asx differ
diff --git a/plparse/tests/parser.c b/plparse/tests/parser.c
index 145b5b5..8cc8e7b 100644
--- a/plparse/tests/parser.c
+++ b/plparse/tests/parser.c
@@ -443,6 +443,17 @@ test_parsing_xml_mixed_cdata (void)
 	g_free (uri);
 }
 
+static void
+test_parsing_not_asx_playlist (void)
+{
+	char *uri;
+	g_test_bug ("610471");
+	/* File from https://bugzilla.gnome.org/show_bug.cgi?id=610471#c0 */
+	uri = get_relative_uri (TEST_SRCDIR "asf-with-asx-suffix.asx");
+	g_assert (simple_parser_test (uri) == TOTEM_PL_PARSER_RESULT_SUCCESS);
+	g_free (uri);
+}
+
 #define MAX_DESCRIPTION_LEN 128
 #define DATE_BUFSIZE 512
 #define PRINT_DATE_FORMAT "%Y-%m-%dT%H:%M:%SZ"
@@ -608,6 +619,7 @@ main (int argc, char *argv[])
 		g_test_add_func ("/parser/parsing/single_line_rtsptext", test_parsing_rtsp_text);
 		g_test_add_func ("/parser/parsing/live_streaming", test_parsing_live_streaming);
 		g_test_add_func ("/parser/parsing/xml_mixed_cdata", test_parsing_xml_mixed_cdata);
+		g_test_add_func ("/parser/parsing/not_asx_playlist", test_parsing_not_asx_playlist);
 
 		return g_test_run ();
 	}
diff --git a/plparse/totem-pl-parser.c b/plparse/totem-pl-parser.c
index cfb2752..96ed739 100644
--- a/plparse/totem-pl-parser.c
+++ b/plparse/totem-pl-parser.c
@@ -1852,6 +1852,8 @@ totem_pl_parser_parse_internal (TotemPlParser *parser,
 
 		for (i = 0; i < G_N_ELEMENTS(dual_types) && found == FALSE; i++) {
 			if (strcmp (dual_types[i].mimetype, mimetype) == 0) {
+				int j, new_i;
+
 				DEBUG(file, g_print ("URI '%s' is dual type '%s'\n", uri, mimetype));
 				if (data == NULL) {
 					g_free (mimetype);
@@ -1865,6 +1867,23 @@ totem_pl_parser_parse_internal (TotemPlParser *parser,
 					mimetype = NULL;
 					break;
 				}
+				/* Now look for the proper function to use */
+				new_i = -1;
+				for (j = 0; i < G_N_ELEMENTS(dual_types) && mimetype != NULL; j++) {
+					if (strcmp (dual_types[j].mimetype, mimetype) == 0) {
+						new_i = j;
+						break;
+					}
+				}
+				if (new_i == -1 && mimetype != NULL) {
+					DEBUG(file, g_print ("Ignoring URI '%s' because we couldn't find a dual-type parser for '%s'\n", uri, mimetype));
+					ret = TOTEM_PL_PARSER_RESULT_IGNORED;
+					g_free (mimetype);
+					mimetype = NULL;
+					break;
+				} else if (new_i != -1) {
+					i = new_i;
+				}
 
 				if (base_file == NULL)
 					base_file = g_file_get_parent (file);



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