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 10f0a76..c88f87b 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 f8df922..c62f462 100644 (file)
@@ -46,6 +46,7 @@ struct _FeedAuth {
 struct _Feed {
        gchar *url;
        FeedAuth *auth;
+       gboolean is_valid;
        gchar *title;
        gchar *description;
        gchar *language;
index 68694ab..be9458c 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 a9d1129..e74045c 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>"),