Use RSS feed title as room name for saved messages
authorArt Cancro <ajc@citadel.org>
Fri, 2 Nov 2007 19:11:10 +0000 (19:11 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 2 Nov 2007 19:11:10 +0000 (19:11 +0000)
citadel/modules/rssclient/serv_rssclient.c

index 80fe3908c9f4e9501d2973d5fd79aaeda5d4600b..abb3e02f12aac03206369726e1a133d5eeae5223 100644 (file)
@@ -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);
        }