2 * Bring external RSS feeds into rooms.
4 * Copyright (c) 2007-2010 by the citadel.org team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #if TIME_WITH_SYS_TIME
26 # include <sys/time.h>
30 # include <sys/time.h>
39 #include <sys/types.h>
42 #include <curl/curl.h>
43 #include <libcitadel.h>
46 #include "citserver.h"
50 #include "ctdl_module.h"
51 #include "clientsocket.h"
53 #include "parsedate.h"
55 #include "citadel_dirs.h"
59 typedef struct rssnetcfg rssnetcfg;
65 time_t last_error_when;
73 typedef struct _rss_item {
83 char channel_title[256];
85 char *author_or_creator;
91 typedef struct _rsscollection {
98 struct rssnetcfg *rnclist = NULL;
107 * dug this out of the trashcan of the midgard project, lets see if it works for us.
108 * original code by Alexander Bokovoy <bokovoy@avilink.ne> distributed under GPL V2 or later
112 >= 0 - successfull, 0 means conversion doesn't use multibyte sequences
113 -1 - error during iconv_open call
114 -2 - error during iconv_close call
115 ----------------------------------
116 This function expects that multibyte encoding in 'charset' wouldn't have
117 characters with more than 3 bytes. It is not intended to convert UTF-8 because
118 we'll never receive UTF-8 in our handler (it is handled by Exat itself).
121 fill_encoding_info (const char *charset, XML_Encoding * info)
123 iconv_t cd = (iconv_t)(-1);
125 CtdlLogPrintf(0, "RSS: fill encoding info ...\n");
127 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
128 cd = iconv_open ("UCS-2LE", charset);
130 cd = iconv_open ("UCS-2BE", charset);
133 if (cd == (iconv_t) (-1))
140 unsigned char buf[4];
141 unsigned int i0, i1, i2;
144 for (i0 = 0; i0 < 0x100; i0++)
148 //result = try (cd, buf, 1, &out);
158 for (i1 = 0; i1 < 0x100; i1++)
161 ///result = try (cd, buf, 2, &out);
172 for (i2 = 0; i2 < 0x100; i2++)
175 ////result = try (cd, buf, 3, &out);
191 if (iconv_close (cd) < 0)
199 iconv_convertor (void *data, const char *s)
201 XML_Encoding *info = data;
203 CtdlLogPrintf(0, "RSS: Converting ...\n");
209 result = g_byte_array_new ();
210 if (process_block (info->data, (char *) s, strlen (s), result) == 0)
212 res = *(result->data);
213 g_byte_array_free (result, TRUE);
216 g_byte_array_free (result, TRUE);
222 my_release (void *data)
224 iconv_t cd = (iconv_t) data;
225 if (iconv_close (cd) != 0)
227 /// TODO: uh no. exit (1);
231 handle_unknown_xml_encoding (void *encodingHandleData,
232 const XML_Char * name,
236 CtdlLogPrintf(0, "RSS: unknown encoding ...\n");
237 result = fill_encoding_info (name, info);
241 Special case: client asked for reverse conversion, we'll provide him with
242 iconv descriptor which handles it. Client should release it by himself.
244 if(encodingHandleData != NULL)
245 *((iconv_t *)encodingHandleData) = iconv_open(name, "UTF-8");
247 Optimization: we do not need conversion function if encoding is one-to-one,
248 info->map table will be enough
253 info->convert = NULL;
254 info->release = NULL;
258 We do need conversion function because this encoding uses multibyte sequences
260 info->data = (void *) iconv_open ("UTF-8", name);
261 if ((int)info->data == -1)
263 info->convert = iconv_convertor;
264 info->release = my_release;
267 if(encodingHandleData != NULL)
268 *(iconv_t *)encodingHandleData = NULL;
276 * Commit a fetched and parsed RSS item to disk
278 void rss_save_item(rsscollection *rssc) {
280 struct MD5Context md5context;
281 u_char rawdigest[MD5_DIGEST_LEN];
284 struct cdbdata *cdbut;
286 struct CtdlMessage *msg;
287 struct recptypes *recp = NULL;
289 rss_item *ri = rssc->Item;
291 recp = (struct recptypes *) malloc(sizeof(struct recptypes));
292 if (recp == NULL) return;
293 memset(recp, 0, sizeof(struct recptypes));
294 memset(&ut, 0, sizeof(struct UseTable));
295 recp->recp_room = strdup(ri->roomlist);
296 recp->num_room = num_tokens(ri->roomlist, '|');
297 recp->recptypes_magic = RECPTYPES_MAGIC;
299 /* Construct a GUID to use in the S_USETABLE table.
300 * If one is not present in the item itself, make one up.
302 if (ri->guid != NULL) {
303 snprintf(utmsgid, sizeof utmsgid, "rss/%s", ri->guid);
306 MD5Init(&md5context);
307 if (ri->title != NULL) {
308 MD5Update(&md5context, (unsigned char*)ri->title, strlen(ri->title));
310 if (ri->link != NULL) {
311 MD5Update(&md5context, (unsigned char*)ri->link, strlen(ri->link));
313 MD5Final(rawdigest, &md5context);
314 for (i=0; i<MD5_DIGEST_LEN; i++) {
315 sprintf(&utmsgid[i*2], "%02X", (unsigned char) (rawdigest[i] & 0xff));
316 utmsgid[i*2] = tolower(utmsgid[i*2]);
317 utmsgid[(i*2)+1] = tolower(utmsgid[(i*2)+1]);
319 strcat(utmsgid, "_rss2ctdl");
322 /* Find out if we've already seen this item */
324 cdbut = cdb_fetch(CDB_USETABLE, utmsgid, strlen(utmsgid));
326 /* Item has already been seen */
327 CtdlLogPrintf(CTDL_DEBUG, "%s has already been seen\n", utmsgid);
330 /* rewrite the record anyway, to update the timestamp */
331 strcpy(ut.ut_msgid, utmsgid);
332 ut.ut_timestamp = time(NULL);
333 cdb_store(CDB_USETABLE, utmsgid, strlen(utmsgid), &ut, sizeof(struct UseTable) );
336 /* Item has not been seen, so save it. */
337 CtdlLogPrintf(CTDL_DEBUG, "RSS: saving item...\n");
338 if (ri->description == NULL) ri->description = strdup("");
339 for (i=strlen(ri->description); i>=0; --i) {
340 if (isspace(ri->description[i])) {
341 ri->description[i] = ' ';
345 msg = malloc(sizeof(struct CtdlMessage));
346 memset(msg, 0, sizeof(struct CtdlMessage));
347 msg->cm_magic = CTDLMESSAGE_MAGIC;
348 msg->cm_anon_type = MES_NORMAL;
349 msg->cm_format_type = FMT_RFC822;
351 if (ri->guid != NULL) {
352 msg->cm_fields['E'] = strdup(ri->guid);
355 if (ri->author_or_creator != NULL) {
357 StrBuf *Encoded, *QPEncoded;
359 StrBuf *EmailAddress;
362 UserName = NewStrBuf();
363 EmailAddress = NewStrBuf();
364 EncBuf = NewStrBuf();
366 From = html_to_ascii(ri->author_or_creator,
367 strlen(ri->author_or_creator),
370 Encoded = NewStrBufPlain(From, -1);
373 QPEncoded = StrBufSanitizeEmailRecipientVector(Encoded, UserName, EmailAddress, EncBuf);
374 msg->cm_fields['A'] = SmashStrBuf(&QPEncoded);
376 FreeStrBuf(&Encoded);
377 FreeStrBuf(&UserName);
378 FreeStrBuf(&EmailAddress);
383 msg->cm_fields['A'] = strdup("rss");
386 msg->cm_fields['N'] = strdup(NODENAME);
387 if (ri->title != NULL) {
390 StrBuf *Encoded, *QPEncoded;
393 len = strlen(ri->title);
394 Sbj = html_to_ascii(ri->title, len, 512, 0);
395 Encoded = NewStrBufPlain(Sbj, -1);
399 StrBufRFC2047encode(&QPEncoded, Encoded);
401 msg->cm_fields['U'] = SmashStrBuf(&QPEncoded);
402 FreeStrBuf(&Encoded);
404 msg->cm_fields['T'] = malloc(64);
405 snprintf(msg->cm_fields['T'], 64, "%ld", ri->pubdate);
406 if (ri->channel_title != NULL) {
407 if (!IsEmptyStr(ri->channel_title)) {
408 msg->cm_fields['O'] = strdup(ri->channel_title);
411 if (ri->link == NULL)
412 ri->link = strdup("");
413 msglen += 1024 + strlen(ri->link) + strlen(ri->description) ;
414 msg->cm_fields['M'] = malloc(msglen);
415 snprintf(msg->cm_fields['M'], msglen,
416 "Content-type: text/html; charset=\"UTF-8\"\r\n\r\n"
419 "<a href=\"%s\">%s</a>\n"
426 CtdlSubmitMsg(msg, recp, NULL, 0);
427 CtdlFreeMessage(msg);
429 /* write the uidl to the use table so we don't store this item again */
430 strcpy(ut.ut_msgid, utmsgid);
431 ut.ut_timestamp = time(NULL);
432 cdb_store(CDB_USETABLE, utmsgid, strlen(utmsgid), &ut, sizeof(struct UseTable) );
434 free_recipients(recp);
440 * Convert an RDF/RSS datestamp into a time_t
442 time_t rdf_parsedate(char *p)
448 if (strlen(p) < 10) return 0L;
450 memset(&tm, 0, sizeof tm);
453 * If the timestamp appears to be in W3C datetime format, try to
454 * parse it. See also: http://www.w3.org/TR/NOTE-datetime
456 * This code, along with parsedate.c, is a potential candidate for
457 * moving into libcitadel.
459 if ( (p[4] == '-') && (p[7] == '-') ) {
460 tm.tm_year = atoi(&p[0]) - 1900;
461 tm.tm_mon = atoi(&p[5]) - 1;
462 tm.tm_mday = atoi(&p[8]);
463 if ( (p[10] == 'T') && (p[13] == ':') ) {
464 tm.tm_hour = atoi(&p[11]);
465 tm.tm_min = atoi(&p[14]);
470 /* hmm... try RFC822 date stamp format */
473 if (t > 0) return(t);
475 /* yeesh. ok, just return the current date and time. */
483 void flush_rss_ite(rss_item *ri)
485 /* Initialize the feed item data structure */
486 if (ri->guid != NULL) free(ri->guid);
488 if (ri->title != NULL) free(ri->title);
490 if (ri->link != NULL) free(ri->link);
492 if (ri->author_or_creator != NULL) free(ri->author_or_creator);
493 ri->author_or_creator = NULL;
494 if (ri->author_url != NULL) free(ri->author_url);
495 ri->author_url = NULL;
496 if (ri->description != NULL) free(ri->description);
497 ri->description = NULL;
498 /* Throw away any existing character data */
499 if (ri->chardata_len > 0) {
502 ri->chardata_len = 0;
504 FreeStrBuf(&ri->CData);
507 void rss_xml_start(void *data, const char *supplied_el, const char **attr) {
508 rsscollection *rssc = (rsscollection*) data;
509 rss_item *ri = rssc->Item;
513 /* Axe the namespace, we don't care about it */
514 /// CtdlLogPrintf(0, "RSS: supplied el %d: %s...\n", rssc->Cfg->ItemType, supplied_el);
515 safestrncpy(el, supplied_el, sizeof el);
516 while (sep = strchr(el, ':'), sep) {
520 if ((rssc->Cfg->ItemType == RSS_UNSET) && !strcasecmp(el, "rss"))
522 CtdlLogPrintf(9, "RSS: This is an RSS feed.\n");
523 rssc->Cfg->ItemType = RSS_RSS;
525 if ((rssc->Cfg->ItemType == RSS_UNSET) && !strcasecmp(el, "rdf"))
527 CtdlLogPrintf(9, "RSS: This is an RDF feed.\n");
528 rssc->Cfg->ItemType = RSS_RSS;
530 else if ((rssc->Cfg->ItemType == RSS_UNSET) && !strcasecmp(el, "feed"))
532 CtdlLogPrintf(9, "RSS: This is an ATOM feed.\n");
533 rssc->Cfg->ItemType = RSS_ATOM;
535 else if ((rssc->Cfg->ItemType == RSS_RSS) &&
536 !strcasecmp(el, "item"))
538 ri->item_tag_nesting ++ ;
541 else if ( (rssc->Cfg->ItemType == RSS_ATOM) &&
542 !strcasecmp(el, "entry"))
544 ++ri->item_tag_nesting;
547 else if ((rssc->Cfg->ItemType == RSS_ATOM) &&
548 !strcasecmp(el, "link"))
553 for (found = 0, i = 0;!found && attr[i] != NULL; i+=2)
555 if (!strcmp(attr[i], "href"))
558 if (ri->link != NULL)
560 ri->link = strdup(attr[i+1]);
569 void rss_xml_end(void *data, const char *supplied_el) {
570 rsscollection *rssc = (rsscollection*) data;
571 rss_item *ri = rssc->Item;
575 /* Axe the namespace, we don't care about it */
576 safestrncpy(el, supplied_el, sizeof el);
577 while (sep = strchr(el, ':'), sep) {
580 // CtdlLogPrintf(0, "RSS: END %s...\n", el);
582 if ( (!strcasecmp(el, "title")) && (ri->item_tag_nesting == 0) && (ri->chardata != NULL) ) {
583 safestrncpy(ri->channel_title, ri->chardata, sizeof ri->channel_title);
584 striplt(ri->channel_title);
587 if ( (rssc->Cfg->ItemType == RSS_RSS) &&
588 (!strcasecmp(el, "guid")) && (ri->chardata != NULL) ) {
589 if (ri->guid != NULL) free(ri->guid);
590 striplt(ri->chardata);
591 ri->guid = strdup(ri->chardata);
593 else if ( (rssc->Cfg->ItemType == RSS_ATOM) &&
594 (!strcasecmp(el, "id")) && (ri->chardata != NULL) ) {
595 if (ri->guid != NULL) free(ri->guid);
596 striplt(ri->chardata);
597 ri->guid = strdup(ri->chardata);
600 else if ( (rssc->Cfg->ItemType == RSS_RSS) && (!strcasecmp(el, "link")) && (ri->chardata != NULL) ) {
601 if (ri->link != NULL) free(ri->link);
602 striplt(ri->chardata);
603 ri->link = strdup(ri->chardata);
606 else if ( (!strcasecmp(el, "title")) && (ri->chardata != NULL) ) {
607 if (ri->title != NULL) free(ri->title);
608 striplt(ri->chardata);
609 ri->title = strdup(ri->chardata);
612 else if ((rssc->Cfg->ItemType == RSS_ATOM) &&
613 (!strcasecmp(el, "content")) &&
614 (ri->chardata != NULL) ) {
615 if (ri->description != NULL) free(ri->description);
616 ri->description = strdup(ri->chardata);
618 else if ( (rssc->Cfg->ItemType == RSS_RSS) &&
619 (!strcasecmp(el, "description")) &&
620 (ri->chardata != NULL) ) {
621 if (ri->description != NULL) free(ri->description);
622 ri->description = strdup(ri->chardata);
625 else if ((rssc->Cfg->ItemType == RSS_ATOM) &&
626 ((!strcasecmp(el, "published")) ||
627 (!strcasecmp(el, "updated"))) &&
628 (ri->chardata != NULL) ) {
629 striplt(ri->chardata);
630 ri->pubdate = rdf_parsedate(ri->chardata);
634 else if ((rssc->Cfg->ItemType == RSS_RSS) &&
635 ((!strcasecmp(el, "pubdate")) ||
636 (!strcasecmp(el, "date"))) &&
637 (ri->chardata != NULL) ) {
638 striplt(ri->chardata);
639 ri->pubdate = rdf_parsedate(ri->chardata);
642 else if ((rssc->Cfg->ItemType == RSS_RSS) &&
643 ((!strcasecmp(el, "author")) ||
644 (!strcasecmp(el, "creator"))) &&
645 (ri->chardata != NULL) ) {
646 if (ri->author_or_creator != NULL) free(ri->author_or_creator);
647 striplt(ri->chardata);
648 ri->author_or_creator = strdup(ri->chardata);
651 else if ((rssc->Cfg->ItemType == RSS_ATOM) &&
652 (!strcasecmp(el, "name")) &&
653 (ri->chardata != NULL) ) {
654 if (ri->author_or_creator != NULL) free(ri->author_or_creator);
655 striplt(ri->chardata);
656 ri->author_or_creator = strdup(ri->chardata);
658 else if ((rssc->Cfg->ItemType == RSS_ATOM) &&
659 (!strcasecmp(el, "uri")) &&
660 (ri->chardata != NULL) ) {
661 if (ri->author_url != NULL) free(ri->author_url);
662 striplt(ri->chardata);
663 ri->author_url = strdup(ri->chardata);
666 else if ((rssc->Cfg->ItemType == RSS_RSS) &&
667 !strcasecmp(el, "item")) {
668 --ri->item_tag_nesting;
671 else if ((rssc->Cfg->ItemType == RSS_ATOM) &&
672 !strcasecmp(el, "entry")) {
673 --ri->item_tag_nesting;
677 else if ( (!strcasecmp(el, "rss")) ||
678 (!strcasecmp(el, "rdf")) ) {
679 // CtdlLogPrintf(CTDL_DEBUG, "End of feed detected. Closing parser.\n");
680 ri->done_parsing = 1;
683 if (ri->chardata_len > 0) {
686 ri->chardata_len = 0;
693 * This callback stores up the data which appears in between tags.
695 void rss_xml_cdata_start(void *data) {
696 rsscollection *rssc = (rsscollection*) data;
697 rss_item *ri = rssc->Item;
699 ri->CData = NewStrBuf();
702 void rss_xml_cdata_end(void *data) {
703 rsscollection *rssc = (rsscollection*) data;
704 rss_item *ri = rssc->Item;
706 ri->description = SmashStrBuf(&ri->CData);
708 void rss_xml_chardata(void *data, const XML_Char *s, int len) {
709 rsscollection *rssc = (rsscollection*) data;
710 rss_item *ri = rssc->Item;
715 if (ri->CData != NULL) {
716 StrBufAppendBufPlain (ri->CData, s, len, 0);
718 old_len = ri->chardata_len;
719 new_len = old_len + len;
720 new_buffer = realloc(ri->chardata, new_len + 1);
721 if (new_buffer != NULL) {
722 memcpy(&new_buffer[old_len], s, len);
723 new_buffer[new_len] = 0;
724 ri->chardata = new_buffer;
725 ri->chardata_len = new_len;
731 * Callback function for passing libcurl's output to expat for parsing
733 size_t rss_libcurl_callback(void *ptr, size_t size, size_t nmemb, void *stream)
735 XML_Parse((XML_Parser)stream, ptr, (size * nmemb), 0);
744 void rss_do_fetching(rssnetcfg *Cfg) {
751 char errmsg[1024] = "";
756 CtdlLogPrintf(CTDL_DEBUG, "Fetching RSS feed <%s>\n", Cfg->url);
758 curl = curl_easy_init();
760 CtdlLogPrintf(CTDL_ALERT, "Unable to initialize libcurl.\n");
764 xp = XML_ParserCreateNS("UTF-8", ':');
766 CtdlLogPrintf(CTDL_ALERT, "Cannot create XML parser!\n");
767 curl_easy_cleanup(curl);
771 curl_easy_setopt(curl, CURLOPT_URL, Cfg->url);
772 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
773 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
774 curl_easy_setopt(curl, CURLOPT_WRITEDATA, xp);
775 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, rss_libcurl_callback);
776 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errmsg);
777 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
778 #ifdef CURLOPT_HTTP_CONTENT_DECODING
779 curl_easy_setopt(curl, CURLOPT_HTTP_CONTENT_DECODING, 1);
780 curl_easy_setopt(curl, CURLOPT_ENCODING, "");
782 curl_easy_setopt(curl, CURLOPT_USERAGENT, CITADEL);
783 curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180); /* die after 180 seconds */
785 (!IsEmptyStr(config.c_ip_addr))
786 && (strcmp(config.c_ip_addr, "*"))
787 && (strcmp(config.c_ip_addr, "::"))
788 && (strcmp(config.c_ip_addr, "0.0.0.0"))
790 curl_easy_setopt(curl, CURLOPT_INTERFACE, config.c_ip_addr);
793 memset(&ri, 0, sizeof(rss_item));
794 ri.roomlist = Cfg->rooms;
797 XML_SetUnknownEncodingHandler(xp,
798 handle_unknown_xml_encoding,
802 XML_SetElementHandler(xp, rss_xml_start, rss_xml_end);
803 XML_SetCharacterDataHandler(xp, rss_xml_chardata);
804 XML_SetUserData(xp, &rssc);
805 XML_SetCdataSectionHandler(xp,
808 if (CtdlThreadCheckStop())
811 curl_easy_cleanup(curl);
815 if (CtdlThreadCheckStop())
818 res = curl_easy_perform(curl);
820 CtdlLogPrintf(CTDL_ALERT, "libcurl error %d: %s\n", res, errmsg);
823 if (CtdlThreadCheckStop())
826 if (ri.done_parsing == 0)
827 XML_Parse(xp, "", 0, 1);
830 CtdlLogPrintf(CTDL_ALERT, "RSS: XML Status [%s] \n",
832 XML_GetErrorCode(xp)));
835 curl_easy_cleanup(curl);
843 * Scan a room's netconfig to determine whether it is requesting any RSS feeds
845 void rssclient_scan_room(struct ctdlroom *qrbuf, void *data)
847 char filename[PATH_MAX];
852 rssnetcfg *rncptr = NULL;
853 rssnetcfg *use_this_rncptr = NULL;
857 assoc_file_name(filename, sizeof filename, qrbuf, ctdl_netcfg_dir);
859 if (CtdlThreadCheckStop())
862 /* Only do net processing for rooms that have netconfigs */
863 fp = fopen(filename, "r");
868 while (fgets(buf, sizeof buf, fp) != NULL && !CtdlThreadCheckStop()) {
869 buf[strlen(buf)-1] = 0;
871 extract_token(instr, buf, 0, '|', sizeof instr);
872 if (!strcasecmp(instr, "rssclient")) {
874 use_this_rncptr = NULL;
876 extract_token(feedurl, buf, 1, '|', sizeof feedurl);
878 /* If any other rooms have requested the same feed, then we will just add this
879 * room to the target list for that client request.
881 for (rncptr=rnclist; rncptr!=NULL; rncptr=rncptr->next) {
882 if (!strcmp(rncptr->url, feedurl)) {
883 use_this_rncptr = rncptr;
887 /* Otherwise create a new client request */
888 if (use_this_rncptr == NULL) {
889 rncptr = (rssnetcfg *) malloc(sizeof(rssnetcfg));
890 rncptr->ItemType = RSS_UNSET;
891 if (rncptr != NULL) {
892 rncptr->next = rnclist;
893 safestrncpy(rncptr->url, feedurl, sizeof rncptr->url);
894 rncptr->rooms = NULL;
896 use_this_rncptr = rncptr;
900 /* Add the room name to the request */
901 if (use_this_rncptr != NULL) {
902 if (use_this_rncptr->rooms == NULL) {
903 rncptr->rooms = strdup(qrbuf->QRname);
906 len = strlen(use_this_rncptr->rooms) + strlen(qrbuf->QRname) + 5;
907 ptr = realloc(use_this_rncptr->rooms, len);
910 strcat(ptr, qrbuf->QRname);
911 use_this_rncptr->rooms = ptr;
924 * Scan for rooms that have RSS client requests configured
926 void *rssclient_scan(void *args) {
927 static time_t last_run = 0L;
928 static int doing_rssclient = 0;
929 rssnetcfg *rptr = NULL;
930 CitContext rssclientCC;
932 /* Give this thread its own private CitContext */
933 CtdlFillSystemContext(&rssclientCC, "rssclient");
934 citthread_setspecific(MyConKey, (void *)&rssclientCC );
937 * This is a simple concurrency check to make sure only one rssclient run
938 * is done at a time. We could do this with a mutex, but since we
939 * don't really require extremely fine granularity here, we'll do it
940 * with a static variable instead.
942 if (doing_rssclient) return NULL;
945 CtdlLogPrintf(CTDL_DEBUG, "rssclient started\n");
946 CtdlForEachRoom(rssclient_scan_room, NULL);
948 while (rnclist != NULL && !CtdlThreadCheckStop()) {
949 rss_do_fetching(rnclist);
951 rnclist = rnclist->next;
952 if (rptr->rooms != NULL) free(rptr->rooms);
956 CtdlLogPrintf(CTDL_DEBUG, "rssclient ended\n");
957 last_run = time(NULL);
959 if (!CtdlThreadCheckStop())
960 CtdlThreadSchedule ("RSS Client", CTDLTHREAD_BIGSTACK, rssclient_scan, NULL, last_run + config.c_net_freq);
962 CtdlLogPrintf(CTDL_DEBUG, "rssclient: Task STOPPED.\n");
963 CtdlClearSystemContext();
968 CTDL_MODULE_INIT(rssclient)
972 CtdlLogPrintf(CTDL_INFO, "%s\n", curl_version());
973 CtdlThreadSchedule ("RSS Client", CTDLTHREAD_BIGSTACK, rssclient_scan, NULL, 0);
975 /* return our Subversion id for the Log */