* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
+#include "config.h"
+#include "prss.h"
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
-#include "prss.h"
-#include "config.h"
#ifndef PARSE_OPTIONS
#define PARSE_OPTIONS 0
res->title = res->link = res->description = NULL;
for (; data; data = data->next) {
+ xmlNodePtr child;
+ const char *name;
+
if (data->type != XML_ELEMENT_NODE) {
continue;
}
- xmlNodePtr child = data->children;
+ child = data->children;
if (!child) {
continue;
}
- if (!strcasecmp((char *) data->name, "title")) {
+ name = (const char *)data->name;
+ if (!strcasecmp(name, "title")) {
res->title = (char *) child->content;
- } else if (!strcasecmp((char *) data->name, "link")) {
+ } else if (!strcasecmp(name, "link")) {
res->link = (char *) child->content;
- } else if (!strcasecmp((char *) data->name, "description")) {
+ } else if (!strcasecmp(name, "description")) {
res->description = (char *) child->content;
- } else if (!strcasecmp((char *) data->name, "category")) {
+ } else if (!strcasecmp(name, "category")) {
res->category = (char *) child->content;
- } else if (!strcasecmp((char *) data->name, "pubDate")) {
+ } else if (!strcasecmp(name, "pubDate")) {
res->pubdate = (char *) child->content;
- } else if (!strcasecmp((char *) data->name, "guid")) {
+ } else if (!strcasecmp(name, "guid")) {
res->guid = (char *) child->content;
}
}
}
static inline void read_element(PRSS *res, xmlNodePtr n)
{
+ xmlNodePtr child;
+ const char *name;
+
if (n->type != XML_ELEMENT_NODE) {
return;
}
- xmlNodePtr child = n->children;
+ child = n->children;
if (!child) {
return;
}
- if (!strcasecmp((char *) n->name, "title")) {
+ name = (const char *)n->name;
+ if (!strcasecmp(name, "title")) {
res->title = (char *) child->content;
- } else if (!strcasecmp((char *) n->name, "link")) {
+ } else if (!strcasecmp(name, "link")) {
res->link = (char *) child->content;
- } else if (!strcasecmp((char *) n->name, "description")) {
+ } else if (!strcasecmp(name, "description")) {
res->description = (char *) child->content;
- } else if (!strcasecmp((char *) n->name, "language")) {
+ } else if (!strcasecmp(name, "language")) {
res->language = (char *) child->content;
- } else if (!strcasecmp((char *) n->name, "pubDate")) {
+ } else if (!strcasecmp(name, "pubDate")) {
res->pubdate = (char *) child->content;
- } else if (!strcasecmp((char *) n->name, "lastBuildDate")) {
+ } else if (!strcasecmp(name, "lastBuildDate")) {
res->lastbuilddate = (char *) child->content;
- } else if (!strcasecmp((char *) n->name, "generator")) {
+ } else if (!strcasecmp(name, "generator")) {
res->generator = (char *) child->content;
- } else if (!strcasecmp((char *) n->name, "docs")) {
+ } else if (!strcasecmp(name, "docs")) {
res->docs = (char *) child->content;
- } else if (!strcasecmp((char *) n->name, "managingEditor")) {
+ } else if (!strcasecmp(name, "managingEditor")) {
res->managingeditor = (char *) child->content;
- } else if (!strcasecmp((char *) n->name, "webMaster")) {
+ } else if (!strcasecmp(name, "webMaster")) {
res->webmaster = (char *) child->content;
- } else if (!strcasecmp((char *) n->name, "copyright")) {
+ } else if (!strcasecmp(name, "copyright")) {
res->copyright = (char *) child->content;
- } else if (!strcasecmp((char *) n->name, "ttl")) {
+ } else if (!strcasecmp(name, "ttl")) {
res->ttl = (char *) child->content;
- } else if (!strcasecmp((char *) n->name, "item")) {
+ } else if (!strcasecmp(name, "item")) {
read_item(&res->items[res->item_count++], n->children);
}
}
static inline int parse_rss_2_0(PRSS *res, xmlNodePtr root)
{
xmlNodePtr channel = root->children;
+ xmlNodePtr n;
+ int items = 0;
while (channel && (channel->type != XML_ELEMENT_NODE
- || strcmp((char *) channel->name, "channel"))) {
+ || strcmp((const char *) channel->name, "channel"))) {
channel = channel->next;
}
if (!channel) {
return 0;
}
- int items = 0;
- xmlNodePtr n;
-
for (n = channel->children; n; n = n->next) {
- if (n->type == XML_ELEMENT_NODE && !strcmp((char *) n->name, "item")) {
+ if (n->type == XML_ELEMENT_NODE &&
+ !strcmp((const char *) n->name, "item")) {
++items;
}
}
- res->version = strdup("2.0");
+ res->version = strndup("2.0", text_buffer_size);
res->items = malloc(items * sizeof(PRSS_Item));
res->item_count = 0;
for (n = root->children; n; n = n->next) {
if (n->type == XML_ELEMENT_NODE) {
- if (!strcmp((char *) n->name, "item")) {
+ if (!strcmp((const char *) n->name, "item")) {
++items;
- } else if (!strcmp((char *) n->name, "channel")) {
+ } else if (!strcmp((const char *) n->name, "channel")) {
xmlNodePtr i;
for (i = n->children; i; i = i->next) {
}
}
- res->version = strdup("1.0");
+ res->version = strndup("1.0", text_buffer_size);
res->items = malloc(items * sizeof(PRSS_Item));
res->item_count = 0;
for (n = root->children; n; n = n->next) {
- if (n->type == XML_ELEMENT_NODE && !strcmp((char *) n->name, "item")) {
+ if (n->type == XML_ELEMENT_NODE &&
+ !strcmp((const char *) n->name, "item")) {
read_item(&res->items[res->item_count++], n->children);
}
}
result->_data = doc;
do {
if (root->type == XML_ELEMENT_NODE) {
- if (!strcmp((char *) root->name, "RDF")) {
+ if (!strcmp((const char *) root->name, "RDF")) {
// RSS 1.0 document
if (!parse_rss_1_0(result, root)) {
free(result);
return NULL;
}
return result;
- } else if (!strcmp((char *) root->name, "rss")) {
+ } else if (!strcmp((const char *) root->name, "rss")) {
// RSS 2.0 or <1.0 document
if (!parse_rss_2_0(result, root)) {
free(result);