totem-pl-parser r47 - in trunk: . plparse



Author: hadess
Date: Thu Feb  7 12:48:23 2008
New Revision: 47
URL: http://svn.gnome.org/viewvc/totem-pl-parser?rev=47&view=rev

Log:
2008-02-07  Bastien Nocera  <hadess hadess net>

	* plparse/totem-pl-parser-wm.c: (totem_pl_parser_is_asx):
	Also look for "<Asx" as a magic in ASX files
	* plparse/totem-pl-parser.c: (my_gnome_vfs_get_mime_type_with_data),
	(my_gnome_vfs_get_mime_type_for_data),
	(totem_pl_parser_can_parse_from_data): When parsing from data,
	fall-back to looking for a mime-type ourselves if all else
	fails (Closes: #505398)



Modified:
   trunk/ChangeLog
   trunk/plparse/totem-pl-parser-wm.c
   trunk/plparse/totem-pl-parser.c

Modified: trunk/plparse/totem-pl-parser-wm.c
==============================================================================
--- trunk/plparse/totem-pl-parser-wm.c	(original)
+++ trunk/plparse/totem-pl-parser-wm.c	Thu Feb  7 12:48:23 2008
@@ -44,6 +44,7 @@
 
 #define ASX_NEEDLE "<ASX"
 #define ASX_NEEDLE2 "<asx"
+#define ASX_NEEDLE3 "<Asx"
 
 const char *
 totem_pl_parser_is_asx (const char *data, gsize len)
@@ -60,6 +61,9 @@
 	if (memmem (data, len,
 		    ASX_NEEDLE2, strlen (ASX_NEEDLE2)) != NULL)
 		return ASX_MIME_TYPE;
+	if (memmem (data, len,
+		    ASX_NEEDLE3, strlen (ASX_NEEDLE3)) != NULL)
+		return ASX_MIME_TYPE;
 
 	return FALSE;
 }

Modified: trunk/plparse/totem-pl-parser.c
==============================================================================
--- trunk/plparse/totem-pl-parser.c	(original)
+++ trunk/plparse/totem-pl-parser.c	Thu Feb  7 12:48:23 2008
@@ -206,6 +206,8 @@
 	PLAYLIST_TYPE2 ("application/xml", totem_pl_parser_add_xml_feed, totem_pl_parser_is_xml_feed),
 };
 
+static char *my_gnome_vfs_get_mime_type_for_data (gconstpointer data, int len);
+
 #ifndef TOTEM_PL_PARSER_MINI
 
 static void totem_pl_parser_set_property (GObject *object,
@@ -615,7 +617,6 @@
 	GnomeVFSResult result;
 	GnomeVFSHandle *handle;
 	char *buffer;
-	const char *mimetype;
 	GnomeVFSFileSize total_bytes_read;
 	GnomeVFSFileSize bytes_read;
 
@@ -692,27 +693,7 @@
 	buffer[total_bytes_read] = '\0';
 	*data = buffer;
 
-	mimetype = gnome_vfs_get_mime_type_for_data (*data, total_bytes_read);
-
-	if (mimetype != NULL && strcmp (mimetype, "text/plain") == 0) {
-		PlaylistIdenCallback func;
-		guint i;
-
-		func = NULL;
-
-		for (i = 0; i < G_N_ELEMENTS(dual_types); i++) {
-			const char *res;
-
-			if (func == dual_types[i].iden)
-				continue;
-			func = dual_types[i].iden;
-			res = func (*data, total_bytes_read);
-			if (res != NULL)
-				return g_strdup (res);
-		}
-	}
-
-	return g_strdup (mimetype);
+	return my_gnome_vfs_get_mime_type_for_data (*data, total_bytes_read);
 }
 
 /**
@@ -1816,6 +1797,34 @@
 
 #endif /* !TOTEM_PL_PARSER_MINI */
 
+static char *
+my_gnome_vfs_get_mime_type_for_data (gconstpointer data, int len)
+{
+	const char *mimetype;
+
+	mimetype = gnome_vfs_get_mime_type_for_data (data, len);
+
+	if (mimetype != NULL && strcmp (mimetype, "text/plain") == 0) {
+		PlaylistIdenCallback func;
+		guint i;
+
+		func = NULL;
+
+		for (i = 0; i < G_N_ELEMENTS(dual_types); i++) {
+			const char *res;
+
+			if (func == dual_types[i].iden)
+				continue;
+			func = dual_types[i].iden;
+			res = func (data, len);
+			if (res != NULL)
+				return g_strdup (res);
+		}
+	}
+
+	return g_strdup (mimetype);
+}
+
 /**
  * totem_pl_parser_can_parse_from_data:
  * @data: the data to check for parsability
@@ -1832,13 +1841,13 @@
 				     gsize len,
 				     gboolean debug)
 {
-	const char *mimetype;
+	char *mimetype;
 	guint i;
 
 	g_return_val_if_fail (data != NULL, FALSE);
 
 	/* Bad cast! */
-	mimetype = gnome_vfs_get_mime_type_for_data ((gpointer) data, (int) len);
+	mimetype = my_gnome_vfs_get_mime_type_for_data ((gpointer) data, (int) len);
 
 	if (mimetype == NULL || strcmp (GNOME_VFS_MIME_TYPE_UNKNOWN, mimetype) == 0) {
 		D(g_message ("totem_pl_parser_can_parse_from_data couldn't get mimetype"));
@@ -1858,7 +1867,7 @@
 			if (dual_types[i].iden != NULL) {
 				gboolean retval = ((* dual_types[i].iden) (data, len) != NULL);
 				D(g_message ("%s dual type '%s'",
-							retval ? "Is" : "Is not", mimetype));
+					     retval ? "Is" : "Is not", mimetype));
 				return retval;
 			}
 			return FALSE;



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