talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 9056a51ccd598060bb52d4ef0354410e0c30b58e
parent 401c6cdb985141d007cafc5c372e42d23add13bb
Author: Andrej Kacian <ticho@claws-mail.org>
Date:   Mon, 15 May 2017 22:22:13 +0200

RSSyl: Stop earlier when an invalid feed is encountered.

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.

Diffstat:
Msrc/plugins/rssyl/libfeed/feed.c | 6+++++-
Msrc/plugins/rssyl/libfeed/feed.h | 1+
Msrc/plugins/rssyl/libfeed/parser.c | 11+++++++++++
Msrc/plugins/rssyl/rssyl_update_feed.c | 2+-
4 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/plugins/rssyl/libfeed/feed.c b/src/plugins/rssyl/libfeed/feed.c @@ -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); diff --git a/src/plugins/rssyl/libfeed/feed.h b/src/plugins/rssyl/libfeed/feed.h @@ -46,6 +46,7 @@ struct _FeedAuth { struct _Feed { gchar *url; FeedAuth *auth; + gboolean is_valid; gchar *title; gchar *description; gchar *language; diff --git a/src/plugins/rssyl/libfeed/parser.c b/src/plugins/rssyl/libfeed/parser.c @@ -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; diff --git a/src/plugins/rssyl/rssyl_update_feed.c b/src/plugins/rssyl/rssyl_update_feed.c @@ -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>"),