RSSyl: Stop earlier when an invalid feed is encountered.
authorAndrej Kacian <ticho@claws-mail.org>
Mon, 15 May 2017 20:22:13 +0000 (22:22 +0200)
committerAndrej Kacian <ticho@claws-mail.org>
Mon, 15 May 2017 20:22:13 +0000 (22:22 +0200)
This fixes a bug where feeds get renamed to "Untitled feed"
if their URL starts serving e.g. a HTML document instead
of proper content.

src/plugins/rssyl/libfeed/feed.c
src/plugins/rssyl/libfeed/feed.h
src/plugins/rssyl/libfeed/parser.c
src/plugins/rssyl/rssyl_update_feed.c

index 10f0a76ae14530480e7450e7434c995101eabf5e..c88f87bd92869b69d7c42b5f8cdd22004fc5e698 100644 (file)
@@ -38,6 +38,7 @@ Feed *feed_new(gchar *url)
        feed = malloc( sizeof(Feed) );
        g_return_val_if_fail(feed != NULL, NULL);
 
+       feed->is_valid = TRUE;
        feed->timeout = FEED_DEFAULT_TIMEOUT;
        feed->url = g_strdup(url);
        feed->auth = NULL;
@@ -339,8 +340,11 @@ guint feed_update(Feed *feed, time_t last_update)
        if( res != CURLE_OK ) {
                feed->fetcherr = g_strdup(curl_easy_strerror(res));
                response_code = FEED_ERR_FETCH;
-       } else
+       } else if (!feed->is_valid) {
+               response_code = FEED_ERR_NOFEED;
+       } else {
                curl_easy_getinfo(eh, CURLINFO_RESPONSE_CODE, &response_code);
+       }
 
 cleanup:
        curl_easy_cleanup(eh);
index f8df922db82c390788acc3e66a2bc8320f26cef2..c62f462eb799d6a3a42de2cde0ca904686f3c148 100644 (file)
@@ -46,6 +46,7 @@ struct _FeedAuth {
 struct _Feed {
        gchar *url;
        FeedAuth *auth;
+       gboolean is_valid;
        gchar *title;
        gchar *description;
        gchar *language;
index 68694abd370e43f34f08e935612c6aecd071fc88..be9458ce9e3b8e18734244643160d36fe729675e 100644 (file)
@@ -93,6 +93,9 @@ static void _elparse_start_chooser(void *data,
                                feedtype = FEED_TYPE_ATOM_10;
                        else
                                feedtype = FEED_TYPE_ATOM_03;
+               } else {
+                       /* Not a known feed type */
+                       ctx->feed->is_valid = FALSE;
                }
        }
 
@@ -164,11 +167,19 @@ size_t feed_writefunc(void *ptr, size_t size, size_t nmemb, void *data)
        FeedParserCtx *ctx = (FeedParserCtx *)data;
        gint status, err;
 
+       if (!ctx->feed->is_valid) {
+               /* We already know that the feed is not valid, so we won't
+                * try parsing it. Just return correct number so libcurl is
+                * happy. */
+               return len;
+       }
+
        status = XML_Parse(ctx->parser, ptr, len, FALSE);
 
        if( status == XML_STATUS_ERROR ) {
                err = XML_GetErrorCode(ctx->parser);
                printf("\nExpat: --- %s\n\n", XML_ErrorString(err));
+               ctx->feed->is_valid = FALSE;
        }
 
        return len;
index a9d1129ab8726a378f6201a76ed1a8a07b242602..e74045c99e650ae970cf246b9d1709b2f90b1f0e 100644 (file)
@@ -134,7 +134,7 @@ void rssyl_fetch_feed(RFetchCtx *ctx, RSSylVerboseFlags verbose)
 
                ctx->success = FALSE;
        } else {
-               if( ctx->feed == NULL ) {
+               if( ctx->feed == NULL || ctx->response_code == FEED_ERR_NOFEED) {
                        if( verbose & RSSYL_SHOW_ERRORS) {
                                gchar *msg = g_markup_printf_escaped(
                                                (const char *) _("No valid feed found at\n<b>%s</b>"),