fix conditions where several rooms read the same RSS feed
authorWilfried Goesgens <dothebart@citadel.org>
Sun, 3 Jul 2011 22:35:27 +0000 (22:35 +0000)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 3 Jul 2011 22:35:27 +0000 (22:35 +0000)
citadel/modules/rssclient/rss_atom_parser.c
citadel/modules/rssclient/rss_atom_parser.h
citadel/modules/rssclient/serv_rssclient.c

index 9747fb87b6f5b47ae4ea164f52943b51366d1177..9bd7cf362470c3829d6464dec89e2f2f707aa501 100644 (file)
@@ -617,6 +617,8 @@ eNextState ParseRSSReply(AsyncIO *IO)
 
        rssc = IO->Data;
        ri = rssc->Item;
+       ri->roomlist_parts = rssc->Cfg->roomlist_parts;
+       ri->roomlist = rssc->Cfg->rooms;
        rssc->CData = NewStrBufPlain(NULL, SIZ);
        rssc->Key = NewStrBuf();
        at = NULL;
index 208bbc0bf126df2b0e553eb735dd5dac764a362f..e2f6e4d094a5c89aafa9373833a8223184f3e47b 100644 (file)
 #define RSS_REQUIRE_BUF (1<<3)
 
 typedef struct _rss_item {
-       char *roomlist;
-       int done_parsing;
+       int     done_parsing;
+       int     item_tag_nesting;
+       int     roomlist_parts;
+       time_t  pubdate;
+       StrBuf *roomlist;
        StrBuf *guid;
        StrBuf *title;
        StrBuf *link;
@@ -34,25 +37,21 @@ typedef struct _rss_item {
        StrBuf *reLink;
        StrBuf *reLinkTitle;
        StrBuf *description;
-       time_t pubdate;
        StrBuf *channel_title;
-       int item_tag_nesting;
        StrBuf *author_or_creator;
        StrBuf *author_url;
        StrBuf *author_email;
 }rss_item;
 
-
-typedef struct rssnetcfg rssnetcfg;
-struct rssnetcfg {
-       int Attached;
-       rssnetcfg *next;
-       StrBuf* Url;
-       char *rooms;
-       time_t last_error_when;
-       int ItemType;
-       time_t next_poll;
-};
+typedef struct __rssnetcfg {
+       int     Attached;
+       int     ItemType;
+       int     roomlist_parts;
+       time_t  last_error_when;
+       time_t  next_poll;
+       StrBuf *Url;
+       StrBuf *rooms;
+}rssnetcfg;
 
 typedef void (*rss_handler_func)(StrBuf *CData, 
                                 rss_item *ri, 
@@ -60,19 +59,19 @@ typedef void (*rss_handler_func)(StrBuf *CData,
                                 const char** Attr);
 
 typedef struct __rss_xml_handler {
-       int Flags;
+       int              Flags;
        rss_handler_func Handler;
 }rss_xml_handler;
 
 typedef struct _rsscollection {
-       AsyncIO IO;
-       XML_Parser xp;
-
-       StrBuf *CData;
-       StrBuf *Key;
-
-       rss_item *Item;
-       rssnetcfg *Cfg;
+       AsyncIO          IO;
+       XML_Parser       xp;
+                       
+       StrBuf          *CData;
+       StrBuf          *Key;
+                       
+       rss_item        *Item;
+       rssnetcfg       *Cfg;
        
        rss_xml_handler *Current;
 } rsscollection;
index 74f1992cbba458f3f4b1dacfbe9c0f8b3e086846..a51cac413698e41d4cabc52989a9e3cf0b69d7f7 100644 (file)
@@ -182,12 +182,14 @@ void rss_save_item(rss_item *ri)
        int msglen = 0;
        StrBuf *Message;
        StrBuf *guid;
+       StrBuf *Buf;
 
        recp = (struct recptypes *) malloc(sizeof(struct recptypes));
        if (recp == NULL) return;
        memset(recp, 0, sizeof(struct recptypes));
-       recp->recp_room = strdup(ri->roomlist);
-       recp->num_room = num_tokens(ri->roomlist, '|');
+       Buf = NewStrBufDup(ri->roomlist);
+       recp->recp_room = SmashStrBuf(&Buf);
+       recp->num_room = ri->roomlist_parts;
        recp->recptypes_magic = RECPTYPES_MAGIC;
    
        /* Construct a GUID to use in the S_USETABLE table.
@@ -437,7 +439,7 @@ void DeleteRssCfg(void *vptr)
        rssnetcfg *rncptr = (rssnetcfg *)vptr;
 
        FreeStrBuf(&rncptr->Url);
-       if (rncptr->rooms != NULL) free(rncptr->rooms);
+       FreeStrBuf(&rncptr->rooms);
        free(rncptr);
 }
 
@@ -528,6 +530,7 @@ void rssclient_scan_room(struct ctdlroom *qrbuf, void *data)
                    Count->count ++;
                    rncptr = (rssnetcfg *) malloc(sizeof(rssnetcfg));
                    memset (rncptr, 0, sizeof(rssnetcfg));
+                   rncptr->roomlist_parts = 1;
                    rncptr->Url = NewStrBuf();
                    StrBufExtract_NextToken(rncptr->Url, Line, &lPtr, '|');
 
@@ -545,7 +548,10 @@ void rssclient_scan_room(struct ctdlroom *qrbuf, void *data)
                        }
                        else 
                        {
-                           /* TODO: hook us into the otherone here. */
+                               StrBufAppendBufPlain(use_this_rncptr->rooms, 
+                                                    qrbuf->QRname, 
+                                                    -1, 0);
+                               use_this_rncptr->roomlist_parts++;
                        }
 
                        continue;
@@ -553,8 +559,7 @@ void rssclient_scan_room(struct ctdlroom *qrbuf, void *data)
 
                    rncptr->ItemType = RSS_UNSET;
                                
-                   rncptr->rooms = NULL;
-                   rncptr->rooms = strdup(qrbuf->QRname);
+                   rncptr->rooms = NewStrBufPlain(qrbuf->QRname, -1);
 
                    citthread_mutex_lock(&RSSQueueMutex);
                    Put(RSSFetchUrls, SKEY(rncptr->Url), rncptr, DeleteRssCfg);