diff options
Diffstat (limited to 'sfeed.c')
-rw-r--r-- | sfeed.c | 144 |
1 files changed, 72 insertions, 72 deletions
@@ -432,29 +432,56 @@ isattr(const char *name, size_t len, const char *name2, size_t len2) return (len == len2 && !strcasecmp(name, name2)); } -/* NOTE: this handler can be called multiple times if the data in this - * block is bigger than the buffer. */ static void -xml_handler_data(XMLParser *p, const char *s, size_t len) +xml_handler_attr(XMLParser *p, const char *tag, size_t taglen, + const char *name, size_t namelen, const char *value, + size_t valuelen) { - if (!ctx.field) + (void)tag; + (void)taglen; + + /* handles transforming inline XML to data */ + if (ISINCONTENT(ctx)) { + xml_handler_data(p, value, valuelen); return; + } - /* add only data from <name> inside <author> tag - * or any other non-<author> tag */ - if (ctx.tagid != AtomTagAuthor || !strcmp(p->tag, "name")) - string_append(ctx.field, s, len); + if (ctx.item.feedtype == FeedTypeAtom) { + if (ISCONTENTTAG(ctx)) { + if (isattr(name, namelen, STRP("type")) && + (isattr(value, valuelen, STRP("xhtml")) || + isattr(value, valuelen, STRP("text/xhtml")) || + isattr(value, valuelen, STRP("html")) || + isattr(value, valuelen, STRP("text/html")))) + { + ctx.item.contenttype = ContentTypeHTML; + p->xmlattrstart = xml_handler_attr_start; + p->xmlattrend = xml_handler_attr_end; + } + } else if (ctx.tagid == AtomTagLink && + isattr(name, namelen, STRP("href"))) + { + /* link href attribute */ + string_append(&ctx.item.link, value, valuelen); + } + } } static void -xml_handler_cdata(XMLParser *p, const char *s, size_t len) +xml_handler_attr_end(XMLParser *p, const char *tag, size_t taglen, + const char *name, size_t namelen) { - (void)p; + (void)tag; + (void)taglen; + (void)name; + (void)namelen; - if (!ctx.field) + if (!ISINCONTENT(ctx)) return; - string_append(ctx.field, s, len); + /* handles transforming inline XML to data */ + xml_handler_data(p, "\"", 1); + ctx.attrcount = 0; } static void @@ -476,55 +503,50 @@ xml_handler_attr_start(XMLParser *p, const char *tag, size_t taglen, } static void -xml_handler_attr_end(XMLParser *p, const char *tag, size_t taglen, - const char *name, size_t namelen) +xml_handler_cdata(XMLParser *p, const char *s, size_t len) { - (void)tag; - (void)taglen; - (void)name; - (void)namelen; + (void)p; - if (!ISINCONTENT(ctx)) + if (!ctx.field) return; - /* handles transforming inline XML to data */ - xml_handler_data(p, "\"", 1); - ctx.attrcount = 0; + string_append(ctx.field, s, len); } +/* NOTE: this handler can be called multiple times if the data in this + * block is bigger than the buffer. */ static void -xml_handler_attr(XMLParser *p, const char *tag, size_t taglen, - const char *name, size_t namelen, const char *value, - size_t valuelen) +xml_handler_data(XMLParser *p, const char *s, size_t len) { - (void)tag; - (void)taglen; + if (!ctx.field) + return; - /* handles transforming inline XML to data */ - if (ISINCONTENT(ctx)) { - xml_handler_data(p, value, valuelen); + /* add only data from <name> inside <author> tag + * or any other non-<author> tag */ + if (ctx.tagid != AtomTagAuthor || !strcmp(p->tag, "name")) + string_append(ctx.field, s, len); +} + +static void +xml_handler_data_entity(XMLParser *p, const char *data, size_t datalen) +{ + char buffer[16]; + int len; + + if (!ctx.field) return; - } - if (ctx.item.feedtype == FeedTypeAtom) { - if (ISCONTENTTAG(ctx)) { - if (isattr(name, namelen, STRP("type")) && - (isattr(value, valuelen, STRP("xhtml")) || - isattr(value, valuelen, STRP("text/xhtml")) || - isattr(value, valuelen, STRP("html")) || - isattr(value, valuelen, STRP("text/html")))) - { - ctx.item.contenttype = ContentTypeHTML; - p->xmlattrstart = xml_handler_attr_start; - p->xmlattrend = xml_handler_attr_end; - } - } else if (ctx.tagid == AtomTagLink && - isattr(name, namelen, STRP("href"))) - { - /* link href attribute */ - string_append(&ctx.item.link, value, valuelen); - } - } + /* try to translate entity, else just pass as data to + * xml_data_handler */ + len = xml_entitytostr(data, buffer, sizeof(buffer)); + /* this should never happen (buffer too small) */ + if (len < 0) + return; + + if (len > 0) + xml_handler_data(p, buffer, (size_t)len); + else + xml_handler_data(p, data, datalen); } static void @@ -646,28 +668,6 @@ xml_handler_start_el_parsed(XMLParser *p, const char *tag, size_t taglen, } static void -xml_handler_data_entity(XMLParser *p, const char *data, size_t datalen) -{ - char buffer[16]; - int len; - - if (!ctx.field) - return; - - /* try to translate entity, else just pass as data to - * xml_data_handler */ - len = xml_entitytostr(data, buffer, sizeof(buffer)); - /* this should never happen (buffer too small) */ - if (len < 0) - return; - - if (len > 0) - xml_handler_data(p, buffer, (size_t)len); - else - xml_handler_data(p, data, datalen); -} - -static void xml_handler_end_el(XMLParser *p, const char *name, size_t namelen, int isshort) { if (ctx.item.feedtype == FeedTypeNone) |