sfeed

simple feed reader - forked from git.codemadness.org/sfeed
git clone git://src.gearsix.net/sfeed
Log | Files | Refs | Atom | README | LICENSE

commit 7b2463c8bd13b2dc0dc8c127e810cf2623e251e6
parent 0e100930ceee6e7fa93693f45bcae9b6a5af2696
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Thu,  8 May 2014 14:02:01 +0000

sfeed: cleanup

remove a few levels of indentation, simplify

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>

Diffstat:
Msfeed.c | 114++++++++++++++++++++++++++++++++++++++++---------------------------------------
1 file changed, 58 insertions(+), 56 deletions(-)

diff --git a/sfeed.c b/sfeed.c @@ -525,62 +525,9 @@ xml_handler_start_element(XMLParser *p, const char *name, size_t namelen) { /* TODO: cleanup, merge with code below ?, return function if FeedTypeNone */ /* ctx.iscontenttag = 0;*/ - if(ctx.item.feedtype != FeedTypeNone) { /* in item */ - if(ctx.tag[0] == '\0') { /* set tag if not already set. */ - if(namelen >= sizeof(ctx.tag) - 2) /* check overflow */ - return; - memcpy(ctx.tag, name, namelen + 1); /* copy including nul byte */ - ctx.taglen = namelen; - ctx.tagid = gettag(ctx.item.feedtype, ctx.tag, ctx.taglen); - if(ctx.item.feedtype == FeedTypeRSS) { - if(ctx.tagid == TagUnknown) - ctx.field = NULL; - else if(ctx.tagid == RSSTagPubdate || ctx.tagid == RSSTagDcdate) - ctx.field = &ctx.item.timestamp; - else if(ctx.tagid == RSSTagTitle) - ctx.field = &ctx.item.title; - else if(ctx.tagid == RSSTagLink) - ctx.field = &ctx.item.link; - else if(ctx.tagid == RSSTagDescription || - ctx.tagid == RSSTagContentencoded) { - /* clear previous summary, assumes previous content was not a summary text */ - if(ctx.tagid == RSSTagContentencoded && ctx.item.content.len) - string_clear(&ctx.item.content); - /* ignore, prefer content:encoded over description */ - if(!(ctx.tagid == RSSTagDescription && ctx.item.content.len)) { - ctx.iscontenttag = 1; - ctx.field = &ctx.item.content; - } - } else if(ctx.tagid == RSSTagGuid) - ctx.field = &ctx.item.id; - else if(ctx.tagid == RSSTagAuthor || ctx.tagid == RSSTagDccreator) - ctx.field = &ctx.item.author; - } else if(ctx.item.feedtype == FeedTypeAtom) { - if(ctx.tagid == TagUnknown) - ctx.field = NULL; - else if(ctx.tagid == AtomTagPublished || ctx.tagid == AtomTagUpdated) - ctx.field = &ctx.item.timestamp; - else if(ctx.tagid == AtomTagTitle) - ctx.field = &ctx.item.title; - else if(ctx.tagid == AtomTagSummary || ctx.tagid == AtomTagContent) { - /* clear previous summary, assumes previous content was not a summary text */ - if(ctx.tagid == AtomTagContent && ctx.item.content.len) - string_clear(&ctx.item.content); - /* ignore, prefer content:encoded over description */ - if(!(ctx.tagid == AtomTagSummary && ctx.item.content.len)) { - ctx.iscontenttag = 1; - ctx.field = &ctx.item.content; - } - } else if(ctx.tagid == AtomTagId) - ctx.field = &ctx.item.id; - else if(ctx.tagid == AtomTagLink) - ctx.field = &ctx.item.link; - else if(ctx.tagid == AtomTagAuthor) - ctx.field = &ctx.item.author; - } - /* TODO: prefer content encoded over content? test */ - } - } else { /* start of RSS or Atom item / entry */ + + /* start of RSS or Atom item / entry */ + if(ctx.item.feedtype == FeedTypeNone) { if(istag(name, namelen, "entry", strlen("entry"))) { /* Atom */ ctx.item.feedtype = FeedTypeAtom; ctx.item.contenttype = ContentTypePlain; /* Default content type */ @@ -590,6 +537,61 @@ xml_handler_start_element(XMLParser *p, const char *name, size_t namelen) { ctx.item.contenttype = ContentTypeHTML; /* Default content type */ ctx.field = NULL; /* XXX: optimization */ } + return; + } + + /* tag already set: return */ + if(ctx.tag[0] != '\0') + return; + /* in item */ + if(namelen >= sizeof(ctx.tag) - 2) /* check overflow */ + return; + memcpy(ctx.tag, name, namelen + 1); /* copy including nul byte */ + ctx.taglen = namelen; + ctx.tagid = gettag(ctx.item.feedtype, ctx.tag, ctx.taglen); + if(ctx.tagid == TagUnknown) + ctx.field = NULL; + if(ctx.item.feedtype == FeedTypeRSS) { + if(ctx.tagid == RSSTagPubdate || ctx.tagid == RSSTagDcdate) + ctx.field = &ctx.item.timestamp; + else if(ctx.tagid == RSSTagTitle) + ctx.field = &ctx.item.title; + else if(ctx.tagid == RSSTagLink) + ctx.field = &ctx.item.link; + else if(ctx.tagid == RSSTagDescription || + ctx.tagid == RSSTagContentencoded) { + /* clear content, assumes previous content was not a summary text */ + if(ctx.tagid == RSSTagContentencoded && ctx.item.content.len) + string_clear(&ctx.item.content); + /* ignore, prefer content:encoded over description */ + if(!(ctx.tagid == RSSTagDescription && ctx.item.content.len)) { + ctx.iscontenttag = 1; + ctx.field = &ctx.item.content; + } + } else if(ctx.tagid == RSSTagGuid) + ctx.field = &ctx.item.id; + else if(ctx.tagid == RSSTagAuthor || ctx.tagid == RSSTagDccreator) + ctx.field = &ctx.item.author; + } else if(ctx.item.feedtype == FeedTypeAtom) { + if(ctx.tagid == AtomTagPublished || ctx.tagid == AtomTagUpdated) + ctx.field = &ctx.item.timestamp; + else if(ctx.tagid == AtomTagTitle) + ctx.field = &ctx.item.title; + else if(ctx.tagid == AtomTagSummary || ctx.tagid == AtomTagContent) { + /* clear content, assumes previous content was not a summary text */ + if(ctx.tagid == AtomTagContent && ctx.item.content.len) + string_clear(&ctx.item.content); + /* ignore, prefer content:encoded over description */ + if(!(ctx.tagid == AtomTagSummary && ctx.item.content.len)) { + ctx.iscontenttag = 1; + ctx.field = &ctx.item.content; + } + } else if(ctx.tagid == AtomTagId) + ctx.field = &ctx.item.id; + else if(ctx.tagid == AtomTagLink) + ctx.field = &ctx.item.link; + else if(ctx.tagid == AtomTagAuthor) + ctx.field = &ctx.item.author; } }