[evolution-rss] don't try to parse feeds that have wrong content types



commit c2747a027df1d6560062bc352303640f8ba4dc8f
Author: Lucian Langa <lucilanga gnome org>
Date:   Sun Jun 13 11:08:15 2010 +0300

    don't try to parse feeds that have wrong content types

 TODO         |    2 +-
 src/parser.c |   76 ++++++++++++++++++++++++++++-----------------------------
 src/rss.c    |    2 +-
 3 files changed, 39 insertions(+), 41 deletions(-)
---
diff --git a/TODO b/TODO
index e84032f..00bea56 100644
--- a/TODO
+++ b/TODO
@@ -37,6 +37,6 @@
 	* split rss feed
 	* possibly completely disable messagefiltering at setup_feed
 	* delete of articles not present does not work when no deletion option selected
-	* add select all for feed list or perhaps delete all - manually select each record and pressing delete is a pain on a 10000 feed list
+	* add select all for feed list or perhaps delete all - manually select each record and pressing delete is a pain on a 10000 feed list - abitily to select just for deletion
 	* check key->session big memleak ?
 	* markup fail perhaps in web auth dialog
diff --git a/src/parser.c b/src/parser.c
index 76c7e7d..83287b6 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -45,7 +45,6 @@ extern int rss_verbose_debug;
 /************ RDF Parser *******************/
 
 guint rsserror = FALSE;
-gchar *rssstrerror = NULL;
 extern rssfeed *rf;
 extern gboolean feed_new;
 
@@ -164,7 +163,6 @@ static void
 my_xml_perror_handler (void *ctx, const char *msg, ...)
 {
 	rsserror = TRUE;
-//	rssstrerror
 	g_print("xml_parse_sux(): ERROR:%s\n", msg);
 }
 
@@ -179,54 +177,54 @@ xml_parse_sux (const char *buf, int len)
 {
 	static xmlSAXHandler *sax;
 	xmlParserCtxtPtr ctxt;
-	xmlDoc *doc;
+	xmlDoc *doc = NULL;
+	gchar *mime_type;
+
 	rsserror = FALSE;
-	rssstrerror = NULL;
 
 	g_return_val_if_fail (buf != NULL, NULL);
+	mime_type = g_content_type_guess(NULL, (guchar *)buf, len, NULL);
+	//feeding parsed anything other than xml results in blocking delays
+	//it's possible we can relax parser by using xmlErrorFunc
+	if (!g_ascii_strncasecmp (mime_type, "application/", 12)) {
+		if (!sax) {
+			xmlInitParser();
+			sax = xmlMalloc (sizeof (xmlSAXHandler));
+			xmlSAXVersion (sax, 2);
+			sax->warning = my_xml_parser_error_handler;
+			sax->error = my_xml_perror_handler;
+		}
 
-	if (!sax) {
-		xmlInitParser();
-		sax = xmlMalloc (sizeof (xmlSAXHandler));
-//#if LIBXML_VERSION > 20600 
-		xmlSAXVersion (sax, 2);
-//#else
-//              memcpy (sax, &xmlDefaultSAXHandler, sizeof (xmlSAXHandler));
-//#endif
-		sax->warning = my_xml_parser_error_handler;
-		sax->error = my_xml_perror_handler;
-	}
+		if (len == -1)
+			len = strlen (buf);
+		ctxt = xmlCreateMemoryParserCtxt (buf, len);
+		if (!ctxt)
+			return NULL;
 
-	if (len == -1)
-		len = strlen (buf);
-	ctxt = xmlCreateMemoryParserCtxt (buf, len);
-	if (!ctxt)
-		return NULL;
+		xmlFree (ctxt->sax);
+		ctxt->sax = sax;
+		ctxt->sax2 = 1;
+		ctxt->str_xml = xmlDictLookup (ctxt->dict, BAD_CAST "xml", 3);
+		ctxt->str_xmlns = xmlDictLookup (ctxt->dict, BAD_CAST "xmlns", 5);
+		ctxt->str_xml_ns = xmlDictLookup (ctxt->dict, XML_XML_NAMESPACE, 36);
 
-	xmlFree (ctxt->sax);
-	ctxt->sax = sax;
-//#if LIBXML_VERSION > 20600
-	ctxt->sax2 = 1;
-	ctxt->str_xml = xmlDictLookup (ctxt->dict, BAD_CAST "xml", 3);
-	ctxt->str_xmlns = xmlDictLookup (ctxt->dict, BAD_CAST "xmlns", 5);
-	ctxt->str_xml_ns = xmlDictLookup (ctxt->dict, XML_XML_NAMESPACE, 36);
-//#endif
-
-	ctxt->recovery = TRUE;
-	ctxt->vctxt.error = my_xml_parser_error_handler;
-	ctxt->vctxt.warning = my_xml_parser_error_handler;
-
-	xmlCtxtUseOptions(ctxt, XML_PARSE_DTDLOAD
-				| XML_PARSE_NOENT);
+		ctxt->recovery = TRUE;
+		ctxt->vctxt.error = my_xml_parser_error_handler;
+		ctxt->vctxt.warning = my_xml_parser_error_handler;
 
-//                                | XML_PARSE_NOCDATA);
 
-	xmlParseDocument (ctxt);
+		xmlCtxtUseOptions(ctxt, XML_PARSE_DTDLOAD
+				| XML_PARSE_NOENT);
 
-	doc = ctxt->myDoc;
-	ctxt->sax = NULL;
-	xmlFreeParserCtxt (ctxt);
+		xmlParseDocument (ctxt);
 
+		doc = ctxt->myDoc;
+		ctxt->sax = NULL;
+		xmlFreeParserCtxt (ctxt);
+	} else {
+		rsserror = TRUE;
+	}
+	g_free(mime_type);
 	return doc;
 }
 
diff --git a/src/rss.c b/src/rss.c
index 960d009..329817f 100644
--- a/src/rss.c
+++ b/src/rss.c
@@ -3405,7 +3405,7 @@ generic_finish_feed(rfMessage *msg, gpointer user_data)
 		xmlError *err = xmlGetLastError();
 		gchar *tmsg = g_strdup_printf("\n%s\nInvalid feed: %s",
 				(gchar *)user_data,
-				err->message);
+				err ? err->message : _("illegal content type!"));
 		rss_error(user_data,
 			NULL,
 			_("Error while parsing feed."),



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