]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/rssclient/serv_rssclient.c
* check for syscall.h
[citadel.git] / citadel / modules / rssclient / serv_rssclient.c
index b6517242b23eab2aa93e9d598c0afbad2d24a62f..39fdd7bb39d91d1436f1c332e8ed3f4a13757d68 100644 (file)
@@ -289,10 +289,10 @@ void rss_save_item(rsscollection *rssc) {
        int msglen = 0;
        rss_item *ri = rssc->Item;
 
-       CtdlLogPrintf(0, "RSS: saving item...\n");
        recp = (struct recptypes *) malloc(sizeof(struct recptypes));
        if (recp == NULL) return;
        memset(recp, 0, sizeof(struct recptypes));
+       memset(&ut, 0, sizeof(struct UseTable));
        recp->recp_room = strdup(ri->roomlist);
        recp->num_room = num_tokens(ri->roomlist, '|');
        recp->recptypes_magic = RECPTYPES_MAGIC;
@@ -334,7 +334,7 @@ void rss_save_item(rsscollection *rssc) {
        }
        else {
                /* Item has not been seen, so save it. */
-
+               CtdlLogPrintf(CTDL_DEBUG, "RSS: saving item...\n");
                if (ri->description == NULL) ri->description = strdup("");
                for (i=strlen(ri->description); i>=0; --i) {
                        if (isspace(ri->description[i])) {
@@ -348,6 +348,10 @@ void rss_save_item(rsscollection *rssc) {
                msg->cm_anon_type = MES_NORMAL;
                msg->cm_format_type = FMT_RFC822;
 
+               if (ri->guid != NULL) {
+                       msg->cm_fields['E'] = strdup(ri->guid);
+               }
+
                if (ri->author_or_creator != NULL) {
                        msg->cm_fields['A'] = html_to_ascii(ri->author_or_creator,
                                strlen(ri->author_or_creator), 512, 0);
@@ -410,7 +414,12 @@ time_t rdf_parsedate(char *p)
 
        memset(&tm, 0, sizeof tm);
 
-       /* YYYY-MM-DDTHH:MM format...
+       /*
+        * If the timestamp appears to be in W3C datetime format, try to
+        * parse it.  See also: http://www.w3.org/TR/NOTE-datetime
+        *
+        * This code, along with parsedate.c, is a potential candidate for
+        * moving into libcitadel.
         */
        if ( (p[4] == '-') && (p[7] == '-') ) {
                tm.tm_year = atoi(&p[0]) - 1900;
@@ -447,6 +456,8 @@ void flush_rss_ite(rss_item *ri)
        ri->link = NULL;
        if (ri->author_or_creator != NULL) free(ri->author_or_creator);
        ri->author_or_creator = NULL;
+       if (ri->author_url != NULL) free(ri->author_url);
+       ri->author_url = NULL;
        if (ri->description != NULL) free(ri->description);
        ri->description = NULL;
        /* Throw away any existing character data */
@@ -470,20 +481,31 @@ void rss_xml_start(void *data, const char *supplied_el, const char **attr) {
                strcpy(el, ++sep);
        }
 
-       if (((rssc->Cfg->ItemType == RSS_UNSET) || 
-            (rssc->Cfg->ItemType == RSS_RSS)) &&
+       if ((rssc->Cfg->ItemType == RSS_UNSET) && !strcasecmp(el, "rss")) 
+       {
+               CtdlLogPrintf(9, "RSS: This is an RSS feed.\n");
+               rssc->Cfg->ItemType = RSS_RSS;
+       }
+       if ((rssc->Cfg->ItemType == RSS_UNSET) && !strcasecmp(el, "rdf")) 
+       {
+               CtdlLogPrintf(9, "RSS: This is an RDF feed.\n");
+               rssc->Cfg->ItemType = RSS_RSS;
+       }
+       else if ((rssc->Cfg->ItemType == RSS_UNSET) && !strcasecmp(el, "feed")) 
+       {
+               CtdlLogPrintf(9, "RSS: This is an ATOM feed.\n");
+               rssc->Cfg->ItemType = RSS_ATOM;
+       }
+       else if ((rssc->Cfg->ItemType == RSS_RSS) &&
            !strcasecmp(el, "item")) 
        {
                ri->item_tag_nesting ++ ;
-               rssc->Cfg->ItemType = RSS_RSS;
                flush_rss_ite(ri);
        }
-       else if (((rssc->Cfg->ItemType == RSS_UNSET) || 
-                 (rssc->Cfg->ItemType == RSS_ATOM)) &&
-                !strcasecmp(el, "entry")) { /* Atom feed... */
-               CtdlLogPrintf(0, "RSS: found atom...\n");
+       else if ( (rssc->Cfg->ItemType == RSS_ATOM) &&
+                !strcasecmp(el, "entry")) 
+       { /* Atom feed... */
                ++ri->item_tag_nesting;
-               rssc->Cfg->ItemType = RSS_ATOM;
                flush_rss_ite(ri);
        }
        else if ((rssc->Cfg->ItemType == RSS_ATOM) &&
@@ -852,8 +874,6 @@ void *rssclient_scan(void *args) {
        CtdlFillSystemContext(&rssclientCC, "rssclient");
        citthread_setspecific(MyConKey, (void *)&rssclientCC );
 
-       CtdlThreadAllocTSD();
-
        /*
         * This is a simple concurrency check to make sure only one rssclient run
         * is done at a time.  We could do this with a mutex, but since we
@@ -881,6 +901,7 @@ void *rssclient_scan(void *args) {
                CtdlThreadSchedule ("RSS Client", CTDLTHREAD_BIGSTACK, rssclient_scan, NULL, last_run + config.c_net_freq);
        else
                CtdlLogPrintf(CTDL_DEBUG, "rssclient: Task STOPPED.\n");
+       CtdlClearSystemContext();
        return NULL;
 }