sfeed

Simple RSS and Atom feed parser
git clone https://git.sinitax.com/codemadness/sfeed
Log | Files | Refs | README | LICENSE | Upstream | sfeed.txt

commit ff283804e0dc61f2e6e7ad3de072f354df74effe
parent bc594605418654a6304ae86902e999f9dda35c57
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 20 Mar 2016 13:07:53 +0100

code cleanup: put table of parsed tagid at top (near reverse table)

Diffstat:
Msfeed.c | 64++++++++++++++++++++++++++++++++++------------------------------
1 file changed, 34 insertions(+), 30 deletions(-)

diff --git a/sfeed.c b/sfeed.c @@ -110,7 +110,38 @@ static void xml_handler_start_el(XMLParser *, const char *, size_t); static void xml_handler_start_el_parsed(XMLParser *, const char *, size_t, int); -/* map tag type to field */ +/* map tag name to tagid */ +/* RSS, alphabetical order */ +static FeedTag rsstags[] = { + { STRP("author"), RSSTagAuthor }, + { STRP("content:encoded"), RSSTagContentEncoded }, + { STRP("dc:creator"), RSSTagDccreator }, + { STRP("dc:date"), RSSTagDcdate }, + { STRP("description"), RSSTagDescription }, + { STRP("guid"), RSSTagGuid }, + { STRP("link"), RSSTagLink }, + { STRP("media:description"), RSSTagMediaDescription }, + { STRP("pubdate"), RSSTagPubdate }, + { STRP("title"), RSSTagTitle }, + { NULL, 0, -1 } +}; +/* Atom, alphabetical order */ +static FeedTag atomtags[] = { + /* <author><name></name></author> */ + { STRP("author"), AtomTagAuthor }, + { STRP("content"), AtomTagContent }, + { STRP("id"), AtomTagId }, + /* <link href="" /> */ + { STRP("link"), AtomTagLink }, + { STRP("media:description"), AtomTagMediaDescription }, + { STRP("published"), AtomTagPublished }, + { STRP("summary"), AtomTagSummary }, + { STRP("title"), AtomTagTitle }, + { STRP("updated"), AtomTagUpdated }, + { NULL, 0, -1 } +}; + +/* map tagid type to RSS/Atom field */ static int fieldmap[TagLast] = { /* RSS */ [RSSTagDcdate] = FeedFieldTime, @@ -141,39 +172,12 @@ static const char *baseurl = ""; static FeedContext ctx; static XMLParser parser; /* XML parser state */ -/* Unique id for parsed tag. */ +/* Unique tagid for parsed tag name. */ static enum TagId gettag(enum FeedType feedtype, const char *name, size_t namelen) { - /* RSS, alphabetical order */ - static FeedTag rsstags[] = { - { STRP("author"), RSSTagAuthor }, - { STRP("content:encoded"), RSSTagContentEncoded }, - { STRP("dc:creator"), RSSTagDccreator }, - { STRP("dc:date"), RSSTagDcdate }, - { STRP("description"), RSSTagDescription }, - { STRP("guid"), RSSTagGuid }, - { STRP("link"), RSSTagLink }, - { STRP("media:description"), RSSTagMediaDescription }, - { STRP("pubdate"), RSSTagPubdate }, - { STRP("title"), RSSTagTitle }, - { NULL, 0, -1 } - }; - /* Atom, alphabetical order */ - static FeedTag atomtags[] = { - { STRP("author"), AtomTagAuthor }, - { STRP("content"), AtomTagContent }, - { STRP("id"), AtomTagId }, - { STRP("link"), AtomTagLink }, - { STRP("media:description"), AtomTagMediaDescription }, - { STRP("published"), AtomTagPublished }, - { STRP("summary"), AtomTagSummary }, - { STRP("title"), AtomTagTitle }, - { STRP("updated"), AtomTagUpdated }, - { NULL, 0, -1 } - }; const FeedTag *tags; - int i; + size_t i; /* optimization: these are always non-matching */ if (namelen < 2 || namelen > 17)