sfeed

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

commit 3946a701c0d409dd235f2bcb564b5701beb7d775
parent 42a1ceb58acc58ade796fa66eeed4bd8fd5901ec
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun, 16 Aug 2015 19:31:46 +0200

code-style, wrap some lines, etc

Diffstat:
Msfeed.c | 33+++++++++++++++++++++------------
Msfeed_frames.c | 15++++++++-------
Msfeed_mbox.c | 3++-
Msfeed_web.c | 17++++++++++-------
Mutil.c | 10++++++----
5 files changed, 47 insertions(+), 31 deletions(-)

diff --git a/sfeed.c b/sfeed.c @@ -16,10 +16,18 @@ /* string and size */ #define STRP(s) s,sizeof(s)-1 -enum FeedType { FeedTypeNone = 0, FeedTypeRSS = 1, FeedTypeAtom = 2 }; +enum FeedType { + FeedTypeNone = 0, + FeedTypeRSS = 1, + FeedTypeAtom = 2 +}; static const char *feedtypes[] = { "", "rss", "atom" }; -enum ContentType { ContentTypeNone = 0, ContentTypePlain = 1, ContentTypeHTML = 2 }; +enum ContentType { + ContentTypeNone = 0, + ContentTypePlain = 1, + ContentTypeHTML = 2 +}; static const char *contenttypes[] = { "", "plain", "html" }; static const int FieldSeparator = '\t'; /* output field seperator character */ @@ -46,14 +54,14 @@ typedef struct string { /* Feed item */ typedef struct feeditem { - String timestamp; - String title; - String link; - String content; - int contenttype; /* ContentTypePlain or ContentTypeHTML */ - String id; - String author; - int feedtype; /* FeedTypeRSS or FeedTypeAtom */ + String timestamp; + String title; + String link; + String content; + enum ContentType contenttype; + String id; + String author; + enum FeedType feedtype; } FeedItem; typedef struct feedtag { @@ -552,7 +560,7 @@ xml_handler_data_entity(XMLParser *p, const char *data, size_t datalen) static void xml_handler_start_el(XMLParser *p, const char *name, size_t namelen) { - int tagid; + enum TagId tagid; if (ISINCONTENT(ctx)) { ctx.attrcount = 0; @@ -703,7 +711,8 @@ xml_handler_end_el(XMLParser *p, const char *name, size_t namelen, int isshort) ctx.item.feedtype = FeedTypeNone; ctx.item.contenttype = ContentTypeNone; - } else if (!ctx.tagid || gettag(ctx.item.feedtype, name, namelen) != ctx.tagid) { + } else if (!ctx.tagid || + gettag(ctx.item.feedtype, name, namelen) != ctx.tagid) { /* not end of field */ return; } diff --git a/sfeed_frames.c b/sfeed_frames.c @@ -148,21 +148,22 @@ printfeed(FILE *fpitems, FILE *fpin, struct feed *f) if (r == -1 || (size_t)r >= sizeof(filepath)) errx(1, "snprintf: path truncation"); - /* file doesn't exist yet and has write access */ + /* content file doesn't exist yet and has write access */ if (access(filepath, F_OK) != 0) { if (!(fpcontent = fopen(filepath, "w+b"))) err(1, "fopen: %s", filepath); - fputs("<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"../../style.css\" />" - "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head>\n" - "<body class=\"frame\"><div class=\"content\">" - "<h2><a href=\"", fpcontent); + fputs("<html><head>" + "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../style.css\" />" + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />" + "</head>\n<body class=\"frame\">" + "<div class=\"content\"><h2><a href=\"", fpcontent); xmlencode(fields[FieldLink], fpcontent); fputs("\">", fpcontent); xmlencode(fields[FieldTitle], fpcontent); fputs("</a></h2>", fpcontent); /* NOTE: this prints the raw HTML of the feed, this is - * potentially dangerous, it is up to the user / browser - * to trust a feed it's HTML content. */ + * potentially dangerous, it is left up to the + * user / browser to trust a feed it's HTML content. */ if (!strcmp(fields[FieldContentType], "html")) { printcontent(fields[FieldContent], fpcontent); } else { diff --git a/sfeed_mbox.c b/sfeed_mbox.c @@ -101,7 +101,8 @@ printfeed(FILE *fp, const char *feedname) if (!gmtime_r(&parsedtime, &tm) || !strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M +0000", &tm)) - strlcpy(timebuf, "Thu, 01 Jan 1970 00:00 +0000", sizeof(timebuf)); + strlcpy(timebuf, "Thu, 01 Jan 1970 00:00 +0000", + sizeof(timebuf)); /* mbox + mail header */ printf("From MAILER-DAEMON %s\n" diff --git a/sfeed_web.c b/sfeed_web.c @@ -9,6 +9,9 @@ #include "util.h" #include "xml.h" +/* string and size */ +#define STRP(s) s,sizeof(s)-1 + static XMLParser parser; static unsigned int isbase, islink, isfeedlink, found; static char abslink[4096], feedlink[4096], basehref[4096], feedtype[256]; @@ -31,9 +34,9 @@ xmltagstart(XMLParser *p, const char *tag, size_t taglen) if (taglen != 4) /* optimization */ return; - if (!strncasecmp(tag, "base", taglen)) + if (!strcasecmp(tag, "base")) isbase = 1; - else if (!strncasecmp(tag, "link", taglen)) + else if (!strcasecmp(tag, "link")) islink = 1; } @@ -68,13 +71,13 @@ xmlattr(XMLParser *p, const char *tag, size_t taglen, const char *name, if (namelen != 4) /* optimization */ return; if (isbase) { - if (!strncasecmp(name, "href", namelen)) + if (!strcasecmp(name, "href")) strlcpy(basehref, value, sizeof(basehref)); } else if (islink) { - if (!strncasecmp(name, "type", namelen)) { - if (!strncasecmp(value, "application/atom", strlen("application/atom")) || - !strncasecmp(value, "application/xml", strlen("application/xml")) || - !strncasecmp(value, "application/rss", strlen("application/rss"))) { + if (!strcasecmp(name, "type")) { + if (!strncasecmp(value, STRP("application/atom")) || + !strncasecmp(value, STRP("application/xml")) || + !strncasecmp(value, STRP("application/rss"))) { isfeedlink = 1; strlcpy(feedtype, value, sizeof(feedtype)); } diff --git a/util.c b/util.c @@ -71,7 +71,9 @@ readpath: return -1; } /* treat truncation as an error */ - return strlcat(u->path, p, sizeof(u->path)) >= sizeof(u->path) ? -1 : 0; + if (strlcat(u->path, p, sizeof(u->path)) >= sizeof(u->path)) + return -1; + return 0; } /* Get absolute uri; if `link` is relative use `base` to make it absolute. @@ -115,9 +117,9 @@ absuri(const char *link, const char *base, char *buf, size_t bufsiz) if (i >= sizeof(tmp)) return -1; } - } else { - if (strlcat(tmp, ubase.path, sizeof(tmp)) >= sizeof(tmp)) - return -1; + } else if (strlcat(tmp, ubase.path, sizeof(tmp)) >= + sizeof(tmp)) { + return -1; } } if (strlcat(tmp, ulink.path, sizeof(tmp)) >= sizeof(tmp))