From: Art Cancro Date: Fri, 2 Nov 2007 19:11:10 +0000 (+0000) Subject: Use RSS feed title as room name for saved messages X-Git-Tag: v7.86~2862 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=ab2bf34b5f3dc69497ffef8ad5a6e1004d543fbe;p=citadel.git Use RSS feed title as room name for saved messages --- diff --git a/citadel/modules/rssclient/serv_rssclient.c b/citadel/modules/rssclient/serv_rssclient.c index 80fe3908c..abb3e02f1 100644 --- a/citadel/modules/rssclient/serv_rssclient.c +++ b/citadel/modules/rssclient/serv_rssclient.c @@ -59,6 +59,9 @@ struct rss_item { char *link; char *description; time_t pubdate; + int channel_tag_nesting; + char channel_title[256]; + int item_tag_nesting; }; struct rssnetcfg *rnclist = NULL; @@ -140,6 +143,9 @@ void rss_save_item(struct rss_item *ri) { msg->cm_fields['U'] = strdup(ri->title); msg->cm_fields['T'] = malloc(64); snprintf(msg->cm_fields['T'], 64, "%ld", ri->pubdate); + if (!IsEmptyStr(ri->channel_title)) { + msg->cm_fields['O'] = strdup(ri->channel_title); + } msglen = 1024 + strlen(ri->link) + strlen(ri->description) ; msg->cm_fields['M'] = malloc(msglen); @@ -203,7 +209,12 @@ time_t rdf_parsedate(char *p) void rss_xml_start(void *data, const char *el, const char **attr) { struct rss_item *ri = (struct rss_item *) data; + if (!strcasecmp(el, "channel")) { + ++ri->channel_tag_nesting; + } + if (!strcasecmp(el, "item")) { + ++ri->item_tag_nesting; /* Initialize the feed item data structure */ if (ri->guid != NULL) free(ri->guid); @@ -234,12 +245,20 @@ void rss_xml_end(void *data, const char *supplied_el) { /* Axe the namespace, we don't care about it */ - safestrncpy(el, supplied_el, sizeof el); while (sep = strchr(el, ':'), sep) { strcpy(el, ++sep); } + if (!strcasecmp(el, "channel")) { + --ri->channel_tag_nesting; + } + + if ( (!strcasecmp(el, "title")) && (ri->channel_tag_nesting > 0) && (ri->item_tag_nesting == 0) ) { + safestrncpy(ri->channel_title, ri->chardata, sizeof ri->channel_title); + striplt(ri->channel_title); + } + if (!strcasecmp(el, "guid")) { if (ri->guid != NULL) free(ri->guid); striplt(ri->chardata); @@ -269,6 +288,7 @@ void rss_xml_end(void *data, const char *supplied_el) { } if (!strcasecmp(el, "item")) { + --ri->item_tag_nesting; rss_save_item(ri); }