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"
60 typedef struct rssnetcfg rssnetcfg;
65 time_t last_error_when;
70 #define RSS_UNSET (1<<0)
71 #define RSS_RSS (1<<1)
72 #define RSS_ATOM (1<<2)
73 #define RSS_REQUIRE_BUF (1<<3)
75 typedef struct _rss_item {
86 StrBuf *channel_title;
88 StrBuf *author_or_creator;
94 typedef void (*rss_handler_func)(StrBuf *CData,
99 typedef struct __rss_xml_handler {
101 rss_handler_func Handler;
105 typedef struct _rsscollection {
112 rss_xml_handler *Current;
115 struct rssnetcfg *rnclist = NULL;
116 HashList *StartHandlers = NULL;
117 HashList *EndHandlers = NULL;
118 HashList *KnownNameSpaces = NULL;
119 HashList *UrlShorteners = NULL;
120 void AddRSSStartHandler(rss_handler_func Handler, int Flags, const char *key, long len)
123 h = (rss_xml_handler*) malloc(sizeof (rss_xml_handler));
125 h->Handler = Handler;
126 Put(StartHandlers, key, len, h, NULL);
128 void AddRSSEndHandler(rss_handler_func Handler, int Flags, const char *key, long len)
131 h = (rss_xml_handler*) malloc(sizeof (rss_xml_handler));
133 h->Handler = Handler;
134 Put(EndHandlers, key, len, h, NULL);
143 * dug this out of the trashcan of the midgard project, lets see if it works for us.
144 * original code by Alexander Bokovoy <bokovoy@avilink.ne> distributed under GPL V2 or later
148 >= 0 - successfull, 0 means conversion doesn't use multibyte sequences
149 -1 - error during iconv_open call
150 -2 - error during iconv_close call
151 ----------------------------------
152 This function expects that multibyte encoding in 'charset' wouldn't have
153 characters with more than 3 bytes. It is not intended to convert UTF-8 because
154 we'll never receive UTF-8 in our handler (it is handled by Exat itself).
157 fill_encoding_info (const char *charset, XML_Encoding * info)
159 iconv_t cd = (iconv_t)(-1);
161 syslog(LOG_EMERG, "RSS: fill encoding info ...\n");
163 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
164 cd = iconv_open ("UCS-2LE", charset);
166 cd = iconv_open ("UCS-2BE", charset);
169 if (cd == (iconv_t) (-1))
175 unsigned short out = 0;
176 unsigned char buf[4];
177 unsigned int i0, i1, i2;
180 for (i0 = 0; i0 < 0x100; i0++)
184 //result = try (cd, buf, 1, &out);
194 for (i1 = 0; i1 < 0x100; i1++)
197 ///result = try (cd, buf, 2, &out);
208 for (i2 = 0; i2 < 0x100; i2++)
211 ////result = try (cd, buf, 3, &out);
227 if (iconv_close (cd) < 0)
235 iconv_convertor (void *data, const char *s)
237 XML_Encoding *info = data;
239 syslog(LOG_EMERG, "RSS: Converting ...\n");
245 result = g_byte_array_new ();
246 if (process_block (info->data, (char *) s, strlen (s), result) == 0)
248 res = *(result->data);
249 g_byte_array_free (result, TRUE);
252 g_byte_array_free (result, TRUE);
258 my_release (void *data)
260 iconv_t cd = (iconv_t) data;
261 if (iconv_close (cd) != 0)
263 /// TODO: uh no. exit (1);
267 handle_unknown_xml_encoding (void *encodingHandleData,
268 const XML_Char * name,
272 syslog(LOG_EMERG, "RSS: unknown encoding ...\n");
273 result = fill_encoding_info (name, info);
277 Special case: client asked for reverse conversion, we'll provide him with
278 iconv descriptor which handles it. Client should release it by himself.
280 if(encodingHandleData != NULL)
281 *((iconv_t *)encodingHandleData) = iconv_open(name, "UTF-8");
283 Optimization: we do not need conversion function if encoding is one-to-one,
284 info->map table will be enough
289 info->convert = NULL;
290 info->release = NULL;
294 We do need conversion function because this encoding uses multibyte sequences
296 info->data = (void *) iconv_open ("UTF-8", name);
297 if ((int)info->data == -1)
299 info->convert = iconv_convertor;
300 info->release = my_release;
303 if(encodingHandleData != NULL)
304 *(iconv_t *)encodingHandleData = NULL;
310 size_t GetLocationString( void *ptr, size_t size, size_t nmemb, void *userdata)
312 #define LOCATION "location"
313 if (strncasecmp((char*)ptr, LOCATION, sizeof(LOCATION) - 1) == 0)
315 StrBuf *pURL = (StrBuf*) userdata;
316 char *pch = (char*) ptr;
319 pche = pch + (size * nmemb);
320 pch += sizeof(LOCATION);
322 while (isspace(*pch) || (*pch == ':'))
325 while (isspace(*pche) || (*pche == '\0'))
329 StrBufPlain(pURL, pch, pche - pch + 1);
334 int LookupUrl(StrBuf *ShorterUrlStr)
337 char errmsg[1024] = "";
341 curl = curl_easy_init();
343 syslog(LOG_ALERT, "Unable to initialize libcurl.\n");
346 Answer = NewStrBufPlain(NULL, SIZ);
348 curl_easy_setopt(curl, CURLOPT_URL, ChrPtr(ShorterUrlStr));
349 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
350 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
351 curl_easy_setopt(curl, CURLOPT_WRITEDATA, Answer);
352 // curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, rss_libcurl_callback);
353 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlFillStrBuf_callback);
354 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errmsg);
355 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
356 #ifdef CURLOPT_HTTP_CONTENT_DECODING
357 curl_easy_setopt(curl, CURLOPT_HTTP_CONTENT_DECODING, 1);
358 curl_easy_setopt(curl, CURLOPT_ENCODING, "");
360 curl_easy_setopt(curl, CURLOPT_USERAGENT, CITADEL);
361 curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180); /* die after 180 seconds */
362 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0);
364 curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION , GetLocationString);
365 curl_easy_setopt(curl, CURLOPT_WRITEHEADER, ShorterUrlStr);
369 (!IsEmptyStr(config.c_ip_addr))
370 && (strcmp(config.c_ip_addr, "*"))
371 && (strcmp(config.c_ip_addr, "::"))
372 && (strcmp(config.c_ip_addr, "0.0.0.0"))
374 curl_easy_setopt(curl, CURLOPT_INTERFACE, config.c_ip_addr);
377 if (server_shutting_down)
380 rc = curl_easy_perform(curl);
382 syslog(LOG_ALERT, "libcurl error %d: %s\n", rc, errmsg);
390 curl_easy_cleanup(curl);
398 void CrawlMessageForShorterUrls(HashList *pUrls, StrBuf *Message)
407 while (GetHash(UrlShorteners, IKEY(nShorter), &pv))
410 pch = ChrPtr(Message);
411 pUrl = strstr(pch, ChrPtr((StrBuf*)pv));
412 while ((pUrl != NULL) && (nHits < 99))
414 pCUrl = malloc(sizeof(ConstStr));
417 pch = pUrl + StrLength((StrBuf*)pv);
418 while (isalnum(*pch)||(*pch == '-')||(*pch == '/'))
420 pCUrl->len = pch - pCUrl->Key;
422 Put(pUrls, IKEY(nHits), pCUrl, NULL);
424 pUrl = strstr(pch, ChrPtr((StrBuf*)pv));
429 int SortConstStrByPosition(const void *Item1, const void *Item2)
431 const ConstStr *p1, *p2;
432 p1 = (const ConstStr*) Item1;
433 p2 = (const ConstStr*) Item2;
434 if (p1->Key == p2->Key)
436 if (p1->Key > p2->Key)
441 void ExpandShortUrls(StrBuf *Message)
449 /* we just suspect URL shorteners to be inside of feeds from twitter
450 * or other short content messages, so don't crawl through real blogs.
452 if (StrLength(Message) > 500)
455 pUrls = NewHash(1, Flathash);
456 CrawlMessageForShorterUrls(pUrls, Message);
458 if (GetCount(pUrls) > 0)
460 StrBuf *ShorterUrlStr;
466 Shadow = NewStrBufPlain(NULL, StrLength(Message));
467 SortByPayload (pUrls, SortConstStrByPosition);
469 ShorterUrlStr = NewStrBufPlain(NULL, StrLength(Message));
471 pch = ChrPtr(Message);
472 pche = pch + StrLength(Message);
473 Pos = GetNewHashPos(pUrls, 1);
474 while (GetNextHashPos(pUrls, Pos, &len, &RetrKey, &pv))
476 pCUrl = (ConstStr*) pv;
478 if (pch != pCUrl->Key)
479 StrBufAppendBufPlain(Shadow, pch, pCUrl->Key - pch, 0);
481 StrBufPlain(ShorterUrlStr, CKEY(*pCUrl));
482 if (LookupUrl(ShorterUrlStr))
484 StrBufAppendBufPlain(Shadow, HKEY("<a href=\""), 0);
485 StrBufAppendBuf(Shadow, ShorterUrlStr, 0);
486 StrBufAppendBufPlain(Shadow, HKEY("\">"), 0);
487 StrBufAppendBuf(Shadow, ShorterUrlStr, 0);
488 StrBufAppendBufPlain(Shadow, HKEY("["), 0);
489 StrBufAppendBufPlain(Shadow, pCUrl->Key, pCUrl->len, 0);
490 StrBufAppendBufPlain(Shadow, HKEY("]</a>"), 0);
494 StrBufAppendBufPlain(Shadow, HKEY("<a href=\""), 0);
495 StrBufAppendBufPlain(Shadow, pCUrl->Key, pCUrl->len, 0);
496 StrBufAppendBufPlain(Shadow, HKEY("\">"), 0);
497 StrBufAppendBufPlain(Shadow, pCUrl->Key, pCUrl->len, 0);
498 StrBufAppendBufPlain(Shadow, HKEY("</a>"), 0);
500 pch = pCUrl->Key + pCUrl->len + 1;
504 StrBufAppendBufPlain(Shadow, pch, pche - pch, 0);
505 FlushStrBuf(Message);
506 StrBufAppendBuf(Message, Shadow, 0);
508 FreeStrBuf(&ShorterUrlStr);
517 void AppendLink(StrBuf *Message, StrBuf *link, StrBuf *LinkTitle, const char *Title)
519 if (StrLength(link) > 0)
521 StrBufAppendBufPlain(Message, HKEY("<a href=\""), 0);
522 StrBufAppendBuf(Message, link, 0);
523 StrBufAppendBufPlain(Message, HKEY("\">"), 0);
524 if (StrLength(LinkTitle) > 0)
525 StrBufAppendBuf(Message, LinkTitle, 0);
526 else if ((Title != NULL) && !IsEmptyStr(Title))
527 StrBufAppendBufPlain(Message, Title, -1, 0);
529 StrBufAppendBuf(Message, link, 0);
530 StrBufAppendBufPlain(Message, HKEY("</a><br>\n"), 0);
534 * Commit a fetched and parsed RSS item to disk
536 void rss_save_item(rss_item *ri)
539 struct MD5Context md5context;
540 u_char rawdigest[MD5_DIGEST_LEN];
543 struct cdbdata *cdbut;
545 struct CtdlMessage *msg;
546 struct recptypes *recp = NULL;
550 recp = (struct recptypes *) malloc(sizeof(struct recptypes));
551 if (recp == NULL) return;
552 memset(recp, 0, sizeof(struct recptypes));
553 memset(&ut, 0, sizeof(struct UseTable));
554 recp->recp_room = strdup(ri->roomlist);
555 recp->num_room = num_tokens(ri->roomlist, '|');
556 recp->recptypes_magic = RECPTYPES_MAGIC;
558 /* Construct a GUID to use in the S_USETABLE table.
559 * If one is not present in the item itself, make one up.
561 if (ri->guid != NULL) {
562 StrBufSpaceToBlank(ri->guid);
563 StrBufTrim(ri->guid);
564 snprintf(utmsgid, sizeof utmsgid, "rss/%s", ChrPtr(ri->guid));
567 MD5Init(&md5context);
568 if (ri->title != NULL) {
569 MD5Update(&md5context, (const unsigned char*)ChrPtr(ri->title), StrLength(ri->title));
571 if (ri->link != NULL) {
572 MD5Update(&md5context, (const unsigned char*)ChrPtr(ri->link), StrLength(ri->link));
574 MD5Final(rawdigest, &md5context);
575 for (i=0; i<MD5_DIGEST_LEN; i++) {
576 sprintf(&utmsgid[i*2], "%02X", (unsigned char) (rawdigest[i] & 0xff));
577 utmsgid[i*2] = tolower(utmsgid[i*2]);
578 utmsgid[(i*2)+1] = tolower(utmsgid[(i*2)+1]);
580 strcat(utmsgid, "_rss2ctdl");
583 /* Find out if we've already seen this item */
585 cdbut = cdb_fetch(CDB_USETABLE, utmsgid, strlen(utmsgid));
588 /* Item has already been seen */
589 syslog(LOG_DEBUG, "%s has already been seen\n", utmsgid);
592 /* rewrite the record anyway, to update the timestamp */
593 strcpy(ut.ut_msgid, utmsgid);
594 ut.ut_timestamp = time(NULL);
595 cdb_store(CDB_USETABLE, utmsgid, strlen(utmsgid), &ut, sizeof(struct UseTable) );
600 /* Item has not been seen, so save it. */
601 syslog(LOG_DEBUG, "RSS: saving item...\n");
602 if (ri->description == NULL) ri->description = NewStrBufPlain(HKEY(""));
603 StrBufSpaceToBlank(ri->description);
604 msg = malloc(sizeof(struct CtdlMessage));
605 memset(msg, 0, sizeof(struct CtdlMessage));
606 msg->cm_magic = CTDLMESSAGE_MAGIC;
607 msg->cm_anon_type = MES_NORMAL;
608 msg->cm_format_type = FMT_RFC822;
610 if (ri->guid != NULL) {
611 msg->cm_fields['E'] = strdup(ChrPtr(ri->guid));
614 if (ri->author_or_creator != NULL) {
616 StrBuf *Encoded = NULL;
619 From = html_to_ascii(ChrPtr(ri->author_or_creator),
620 StrLength(ri->author_or_creator),
622 StrBufPlain(ri->author_or_creator, From, -1);
623 StrBufTrim(ri->author_or_creator);
626 FromAt = strchr(ChrPtr(ri->author_or_creator), '@') != NULL;
627 if (!FromAt && StrLength (ri->author_email) > 0)
629 StrBufRFC2047encode(&Encoded, ri->author_or_creator);
630 msg->cm_fields['A'] = SmashStrBuf(&Encoded);
631 msg->cm_fields['P'] = SmashStrBuf(&ri->author_email);
637 msg->cm_fields['A'] = SmashStrBuf(&ri->author_or_creator);
638 msg->cm_fields['P'] = strdup(msg->cm_fields['A']);
642 StrBufRFC2047encode(&Encoded, ri->author_or_creator);
643 msg->cm_fields['A'] = SmashStrBuf(&Encoded);
644 msg->cm_fields['P'] = strdup("rss@localhost");
649 msg->cm_fields['A'] = strdup("rss");
652 msg->cm_fields['N'] = strdup(NODENAME);
653 if (ri->title != NULL) {
656 StrBuf *Encoded, *QPEncoded;
659 StrBufSpaceToBlank(ri->title);
660 len = StrLength(ri->title);
661 Sbj = html_to_ascii(ChrPtr(ri->title), len, 512, 0);
663 if (Sbj[len - 1] == '\n')
668 Encoded = NewStrBufPlain(Sbj, len);
672 StrBufRFC2047encode(&QPEncoded, Encoded);
674 msg->cm_fields['U'] = SmashStrBuf(&QPEncoded);
675 FreeStrBuf(&Encoded);
678 if (ri->pubdate <= 0) {
679 ri->pubdate = time(NULL);
681 msg->cm_fields['T'] = malloc(64);
682 snprintf(msg->cm_fields['T'], 64, "%ld", ri->pubdate);
684 if (ri->channel_title != NULL) {
685 if (StrLength(ri->channel_title) > 0) {
686 msg->cm_fields['O'] = strdup(ChrPtr(ri->channel_title));
689 if (ri->link == NULL)
690 ri->link = NewStrBufPlain(HKEY(""));
691 #ifdef EXPERIMENTAL_SHORTER_URLS
692 /* its rather hard to implement this libevent compatible, so we don't ship it. */
693 ExpandShortUrls(ri->description);
695 msglen += 1024 + StrLength(ri->link) + StrLength(ri->description) ;
697 Message = NewStrBufPlain(NULL, StrLength(ri->description));
699 StrBufPlain(Message, HKEY(
700 "Content-type: text/html; charset=\"UTF-8\"\r\n\r\n"
703 StrBufAppendBuf(Message, ri->description, 0);
704 StrBufAppendBufPlain(Message, HKEY("<br><br>\n"), 0);
706 AppendLink(Message, ri->link, ri->linkTitle, NULL);
707 AppendLink(Message, ri->reLink, ri->reLinkTitle, "Reply to this");
708 StrBufAppendBufPlain(Message, HKEY("</body></html>\n"), 0);
710 msg->cm_fields['M'] = SmashStrBuf(&Message);
712 CtdlSubmitMsg(msg, recp, NULL, 0);
713 CtdlFreeMessage(msg);
715 /* write the uidl to the use table so we don't store this item again */
716 strcpy(ut.ut_msgid, utmsgid);
717 ut.ut_timestamp = time(NULL);
718 cdb_store(CDB_USETABLE, utmsgid, strlen(utmsgid), &ut, sizeof(struct UseTable) );
720 free_recipients(recp);
726 * Convert an RDF/RSS datestamp into a time_t
728 time_t rdf_parsedate(const char *p)
734 if (strlen(p) < 10) return 0L;
736 memset(&tm, 0, sizeof tm);
739 * If the timestamp appears to be in W3C datetime format, try to
740 * parse it. See also: http://www.w3.org/TR/NOTE-datetime
742 * This code, along with parsedate.c, is a potential candidate for
743 * moving into libcitadel.
745 if ( (p[4] == '-') && (p[7] == '-') ) {
746 tm.tm_year = atoi(&p[0]) - 1900;
747 tm.tm_mon = atoi(&p[5]) - 1;
748 tm.tm_mday = atoi(&p[8]);
749 if ( (p[10] == 'T') && (p[13] == ':') ) {
750 tm.tm_hour = atoi(&p[11]);
751 tm.tm_min = atoi(&p[14]);
756 /* hmm... try RFC822 date stamp format */
759 if (t > 0) return(t);
761 /* yeesh. ok, just return the current date and time. */
765 void flush_rss_item(rss_item *ri)
767 /* Initialize the feed item data structure */
768 FreeStrBuf(&ri->guid);
769 FreeStrBuf(&ri->title);
770 FreeStrBuf(&ri->link);
771 FreeStrBuf(&ri->linkTitle);
772 FreeStrBuf(&ri->reLink);
773 FreeStrBuf(&ri->reLinkTitle);
774 FreeStrBuf(&ri->description);
775 FreeStrBuf(&ri->channel_title);
776 FreeStrBuf(&ri->author_or_creator);
777 FreeStrBuf(&ri->author_url);
778 FreeStrBuf(&ri->author_email);
781 void rss_xml_start(void *data, const char *supplied_el, const char **attr)
784 rsscollection *rssc = (rsscollection*) data;
785 rssnetcfg *Cfg = rssc->Cfg;
786 rss_item *ri = rssc->Item;
791 /* Axe the namespace, we don't care about it */
792 /// syslog(LOG_EMERG, "RSS: supplied el %d: %s...\n", rssc->Cfg->ItemType, supplied_el);
794 while (sep = strchr(pel, ':'), sep) {
798 if (pel != supplied_el)
802 if (!GetHash(KnownNameSpaces,
804 pel - supplied_el - 1,
808 syslog(LOG_EMERG, "RSS: START ignoring because of wrong namespace [%s] = [%s]\n",
815 StrBufPlain(rssc->Key, pel, -1);
816 StrBufLowerCase(rssc->Key);
817 if (GetHash(StartHandlers, SKEY(rssc->Key), &pv))
819 rssc->Current = h = (rss_xml_handler*) pv;
821 if (((h->Flags & RSS_UNSET) != 0) &&
822 (Cfg->ItemType == RSS_UNSET))
824 h->Handler(rssc->CData, ri, Cfg, attr);
826 else if (((h->Flags & RSS_RSS) != 0) &&
827 (Cfg->ItemType == RSS_RSS))
829 h->Handler(rssc->CData, ri, Cfg, attr);
831 else if (((h->Flags & RSS_ATOM) != 0) &&
832 (Cfg->ItemType == RSS_ATOM))
834 h->Handler(rssc->CData, ri, Cfg, attr);
838 syslog(LOG_EMERG, "RSS: START unhandled: [%s] [%s]...\n", pel, supplied_el);
843 syslog(LOG_EMERG, "RSS: START unhandled: [%s] [%s]...\n", pel, supplied_el);
847 void rss_xml_end(void *data, const char *supplied_el)
850 rsscollection *rssc = (rsscollection*) data;
851 rssnetcfg *Cfg = rssc->Cfg;
852 rss_item *ri = rssc->Item;
857 /* Axe the namespace, we don't care about it */
859 while (sep = strchr(pel, ':'), sep) {
862 // syslog(LOG_EMERG, "RSS: END %s...\n", el);
863 if (pel != supplied_el)
867 if (!GetHash(KnownNameSpaces,
869 pel - supplied_el - 1,
873 syslog(LOG_EMERG, "RSS: END ignoring because of wrong namespace [%s] = [%s]\n",
874 supplied_el, ChrPtr(rssc->CData));
876 FlushStrBuf(rssc->CData);
881 StrBufPlain(rssc->Key, pel, -1);
882 StrBufLowerCase(rssc->Key);
883 if (GetHash(EndHandlers, SKEY(rssc->Key), &pv))
885 h = (rss_xml_handler*) pv;
887 if (((h->Flags & RSS_UNSET) != 0) &&
888 (Cfg->ItemType == RSS_UNSET))
890 h->Handler(rssc->CData, ri, Cfg, NULL);
892 else if (((h->Flags & RSS_RSS) != 0) &&
893 (Cfg->ItemType == RSS_RSS))
895 h->Handler(rssc->CData, ri, Cfg, NULL);
897 else if (((h->Flags & RSS_ATOM) != 0) &&
898 (Cfg->ItemType == RSS_ATOM))
900 h->Handler(rssc->CData, ri, Cfg, NULL);
904 syslog(LOG_EMERG, "RSS: END unhandled: [%s] [%s] = [%s]...\n", pel, supplied_el, ChrPtr(rssc->CData));
909 syslog(LOG_EMERG, "RSS: END unhandled: [%s] [%s] = [%s]...\n", pel, supplied_el, ChrPtr(rssc->CData));
911 FlushStrBuf(rssc->CData);
912 rssc->Current = NULL;
919 void RSS_item_rss_start (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
921 syslog(LOG_DEBUG, "RSS: This is an RSS feed.\n");
922 Cfg->ItemType = RSS_RSS;
925 void RSS_item_rdf_start(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
927 syslog(LOG_DEBUG, "RSS: This is an RDF feed.\n");
928 Cfg->ItemType = RSS_RSS;
931 void ATOM_item_feed_start(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
933 syslog(LOG_DEBUG, "RSS: This is an ATOM feed.\n");
934 Cfg->ItemType = RSS_ATOM;
938 void RSS_item_item_start(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
940 ri->item_tag_nesting ++;
944 void ATOM_item_entry_start(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
947 ri->item_tag_nesting ++;
951 void ATOM_item_link_start (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
954 const char *pHref = NULL;
955 const char *pType = NULL;
956 const char *pRel = NULL;
957 const char *pTitle = NULL;
959 for (i = 0; Attr[i] != NULL; i+=2)
961 if (!strcmp(Attr[i], "href"))
965 else if (!strcmp(Attr[i], "rel"))
969 else if (!strcmp(Attr[i], "type"))
973 else if (!strcmp(Attr[i], "title"))
979 return; /* WHUT? Pointing... where? */
980 if ((pType != NULL) && !strcasecmp(pType, "application/atom+xml"))
981 return; /* these just point to other rss resources, we're not interested in them. */
984 if (!strcasecmp (pRel, "replies"))
986 NewStrBufDupAppendFlush(&ri->reLink, NULL, pHref, -1);
987 StrBufTrim(ri->link);
988 NewStrBufDupAppendFlush(&ri->reLinkTitle, NULL, pTitle, -1);
990 else if (!strcasecmp(pRel, "alternate")) /* Alternative representation of this Item... */
992 NewStrBufDupAppendFlush(&ri->link, NULL, pHref, -1);
993 StrBufTrim(ri->link);
994 NewStrBufDupAppendFlush(&ri->linkTitle, NULL, pTitle, -1);
997 #if 0 /* these are also defined, but dunno what to do with them.. */
998 else if (!strcasecmp(pRel, "related"))
1001 else if (!strcasecmp(pRel, "self"))
1004 else if (!strcasecmp(pRel, "enclosure"))
1005 {/* this reference can get big, and is probably the full article... */
1007 else if (!strcasecmp(pRel, "via"))
1008 {/* this article was provided via... */
1012 else if (StrLength(ri->link) == 0)
1014 NewStrBufDupAppendFlush(&ri->link, NULL, pHref, -1);
1015 StrBufTrim(ri->link);
1016 NewStrBufDupAppendFlush(&ri->linkTitle, NULL, pTitle, -1);
1023 void ATOMRSS_item_title_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1025 if ((ri->item_tag_nesting == 0) && (StrLength(CData) > 0)) {
1026 NewStrBufDupAppendFlush(&ri->channel_title, CData, NULL, 0);
1027 StrBufTrim(ri->channel_title);
1031 void RSS_item_guid_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1033 if (StrLength(CData) > 0) {
1034 NewStrBufDupAppendFlush(&ri->guid, CData, NULL, 0);
1038 void ATOM_item_id_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1040 if (StrLength(CData) > 0) {
1041 NewStrBufDupAppendFlush(&ri->guid, CData, NULL, 0);
1046 void RSS_item_link_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1048 if (StrLength(CData) > 0) {
1049 NewStrBufDupAppendFlush(&ri->link, CData, NULL, 0);
1050 StrBufTrim(ri->link);
1053 void RSS_item_relink_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1055 if (StrLength(CData) > 0) {
1056 NewStrBufDupAppendFlush(&ri->reLink, CData, NULL, 0);
1057 StrBufTrim(ri->reLink);
1061 void RSSATOM_item_title_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1063 if (StrLength(CData) > 0) {
1064 NewStrBufDupAppendFlush(&ri->title, CData, NULL, 0);
1065 StrBufTrim(ri->title);
1069 void ATOM_item_content_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1071 long olen = StrLength (ri->description);
1072 long clen = StrLength (CData);
1076 NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
1077 StrBufTrim(ri->description);
1079 else if (olen < clen) {
1080 FlushStrBuf(ri->description);
1081 NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
1082 StrBufTrim(ri->description);
1086 void ATOM_item_summary_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1088 /* this can contain an abstract of the article. but we don't want to verwrite a full document if we already have it. */
1089 if ((StrLength(CData) > 0) && (StrLength(ri->description) == 0))
1091 NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
1092 StrBufTrim(ri->description);
1096 void RSS_item_description_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1098 long olen = StrLength (ri->description);
1099 long clen = StrLength (CData);
1103 NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
1104 StrBufTrim(ri->description);
1106 else if (olen < clen) {
1107 FlushStrBuf(ri->description);
1108 NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
1109 StrBufTrim(ri->description);
1114 void ATOM_item_published_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1116 if (StrLength(CData) > 0) {
1118 ri->pubdate = rdf_parsedate(ChrPtr(CData));
1122 void ATOM_item_updated_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1124 if (StrLength(CData) > 0) {
1126 ri->pubdate = rdf_parsedate(ChrPtr(CData));
1130 void RSS_item_pubdate_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1132 if (StrLength(CData) > 0) {
1134 ri->pubdate = rdf_parsedate(ChrPtr(CData));
1139 void RSS_item_date_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1141 if (StrLength(CData) > 0) {
1143 ri->pubdate = rdf_parsedate(ChrPtr(CData));
1149 void RSS_item_author_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1151 if (StrLength(CData) > 0) {
1152 NewStrBufDupAppendFlush(&ri->author_or_creator, CData, NULL, 0);
1153 StrBufTrim(ri->author_or_creator);
1158 void ATOM_item_name_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1160 if (StrLength(CData) > 0) {
1161 NewStrBufDupAppendFlush(&ri->author_or_creator, CData, NULL, 0);
1162 StrBufTrim(ri->author_or_creator);
1166 void ATOM_item_email_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1168 if (StrLength(CData) > 0) {
1169 NewStrBufDupAppendFlush(&ri->author_email, CData, NULL, 0);
1170 StrBufTrim(ri->author_email);
1174 void RSS_item_creator_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1176 if ((StrLength(CData) > 0) &&
1177 (StrLength(ri->author_or_creator) == 0))
1179 NewStrBufDupAppendFlush(&ri->author_or_creator, CData, NULL, 0);
1180 StrBufTrim(ri->author_or_creator);
1185 void ATOM_item_uri_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1187 if (StrLength(CData) > 0) {
1188 NewStrBufDupAppendFlush(&ri->author_url, CData, NULL, 0);
1189 StrBufTrim(ri->author_url);
1193 void RSS_item_item_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1195 --ri->item_tag_nesting;
1200 void ATOM_item_entry_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1202 --ri->item_tag_nesting;
1206 void RSS_item_rss_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1208 // syslog(LOG_DEBUG, "End of feed detected. Closing parser.\n");
1209 ri->done_parsing = 1;
1212 void RSS_item_rdf_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1214 // syslog(LOG_DEBUG, "End of feed detected. Closing parser.\n");
1215 ri->done_parsing = 1;
1219 void RSSATOM_item_ignore(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1226 * This callback stores up the data which appears in between tags.
1228 void rss_xml_cdata_start(void *data)
1230 rsscollection *rssc = (rsscollection*) data;
1232 FlushStrBuf(rssc->CData);
1235 void rss_xml_cdata_end(void *data)
1238 void rss_xml_chardata(void *data, const XML_Char *s, int len)
1240 rsscollection *rssc = (rsscollection*) data;
1242 StrBufAppendBufPlain (rssc->CData, s, len, 0);
1246 * Callback function for passing libcurl's output to expat for parsing
1248 size_t rss_libcurl_callback(void *ptr, size_t size, size_t nmemb, void *stream)
1250 XML_Parse((XML_Parser)stream, ptr, (size * nmemb), 0);
1251 return (size*nmemb);
1257 * Begin a feed parse
1259 void rss_do_fetching(rssnetcfg *Cfg) {
1262 XML_Parser xp = NULL;
1267 char errmsg[1024] = "";
1276 if ((Cfg->next_poll != 0) && (now < Cfg->next_poll))
1278 memset(&ri, 0, sizeof(rss_item));
1282 syslog(LOG_DEBUG, "Fetching RSS feed <%s>\n", Cfg->url);
1284 curl = curl_easy_init();
1286 syslog(LOG_ALERT, "Unable to initialize libcurl.\n");
1289 Answer = NewStrBufPlain(NULL, SIZ);
1291 curl_easy_setopt(curl, CURLOPT_URL, Cfg->url);
1292 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
1293 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
1294 curl_easy_setopt(curl, CURLOPT_WRITEDATA, Answer);
1295 // curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, rss_libcurl_callback);
1296 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlFillStrBuf_callback);
1297 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errmsg);
1298 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
1299 #ifdef CURLOPT_HTTP_CONTENT_DECODING
1300 curl_easy_setopt(curl, CURLOPT_HTTP_CONTENT_DECODING, 1);
1301 curl_easy_setopt(curl, CURLOPT_ENCODING, "");
1303 curl_easy_setopt(curl, CURLOPT_USERAGENT, CITADEL);
1304 curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180); /* die after 180 seconds */
1306 (!IsEmptyStr(config.c_ip_addr))
1307 && (strcmp(config.c_ip_addr, "*"))
1308 && (strcmp(config.c_ip_addr, "::"))
1309 && (strcmp(config.c_ip_addr, "0.0.0.0"))
1311 curl_easy_setopt(curl, CURLOPT_INTERFACE, config.c_ip_addr);
1314 if (server_shutting_down)
1316 curl_easy_cleanup(curl);
1320 if (server_shutting_down)
1323 res = curl_easy_perform(curl);
1325 syslog(LOG_ALERT, "libcurl error %d: %s\n", res, errmsg);
1328 if (server_shutting_down)
1334 memset(&ri, 0, sizeof(rss_item));
1335 ri.roomlist = Cfg->rooms;
1336 rssc.CData = NewStrBufPlain(NULL, SIZ);
1337 rssc.Key = NewStrBuf();
1339 StrBufSipLine(rssc.Key, Answer, &at);
1342 #define encoding "encoding=\""
1343 ptr = strstr(ChrPtr(rssc.Key), encoding);
1348 ptr += sizeof (encoding) - 1;
1349 pche = strchr(ptr, '"');
1351 StrBufCutAt(rssc.Key, -1, pche);
1359 xp = XML_ParserCreateNS(ptr, ':');
1361 syslog(LOG_ALERT, "Cannot create XML parser!\n");
1364 FlushStrBuf(rssc.Key);
1367 XML_SetUnknownEncodingHandler(xp,
1368 handle_unknown_xml_encoding,
1372 XML_SetElementHandler(xp, rss_xml_start, rss_xml_end);
1373 XML_SetCharacterDataHandler(xp, rss_xml_chardata);
1374 XML_SetUserData(xp, &rssc);
1375 XML_SetCdataSectionHandler(xp,
1376 rss_xml_cdata_start,
1380 len = StrLength(Answer);
1381 ptr = SmashStrBuf(&Answer);
1382 XML_Parse(xp, ptr, len, 0);
1384 if (ri.done_parsing == 0)
1385 XML_Parse(xp, "", 0, 1);
1388 syslog(LOG_ALERT, "RSS: XML Status [%s] \n",
1390 XML_GetErrorCode(xp)));
1393 FreeStrBuf(&Answer);
1394 curl_easy_cleanup(curl);
1397 flush_rss_item(&ri);
1398 FreeStrBuf(&rssc.CData);
1399 FreeStrBuf(&rssc.Key);
1401 Cfg->next_poll = time(NULL) + config.c_net_freq;
1406 * Scan a room's netconfig to determine whether it is requesting any RSS feeds
1408 void rssclient_scan_room(struct ctdlroom *qrbuf, void *data)
1410 char filename[PATH_MAX];
1415 rssnetcfg *rncptr = NULL;
1416 rssnetcfg *use_this_rncptr = NULL;
1420 assoc_file_name(filename, sizeof filename, qrbuf, ctdl_netcfg_dir);
1422 if (server_shutting_down)
1425 /* Only do net processing for rooms that have netconfigs */
1426 fp = fopen(filename, "r");
1431 while (fgets(buf, sizeof buf, fp) != NULL && !server_shutting_down) {
1432 buf[strlen(buf)-1] = 0;
1434 extract_token(instr, buf, 0, '|', sizeof instr);
1435 if (!strcasecmp(instr, "rssclient")) {
1437 use_this_rncptr = NULL;
1439 extract_token(feedurl, buf, 1, '|', sizeof feedurl);
1441 /* If any other rooms have requested the same feed, then we will just add this
1442 * room to the target list for that client request.
1444 for (rncptr=rnclist; rncptr!=NULL; rncptr=rncptr->next) {
1445 if (!strcmp(rncptr->url, feedurl)) {
1446 use_this_rncptr = rncptr;
1450 /* Otherwise create a new client request */
1451 if (use_this_rncptr == NULL) {
1452 rncptr = (rssnetcfg *) malloc(sizeof(rssnetcfg));
1453 memset(rncptr, 0, sizeof(rssnetcfg));
1454 rncptr->ItemType = RSS_UNSET;
1455 if (rncptr != NULL) {
1456 rncptr->next = rnclist;
1457 safestrncpy(rncptr->url, feedurl, sizeof rncptr->url);
1458 rncptr->rooms = NULL;
1460 use_this_rncptr = rncptr;
1464 /* Add the room name to the request */
1465 if (use_this_rncptr != NULL) {
1466 if (use_this_rncptr->rooms == NULL) {
1467 rncptr->rooms = strdup(qrbuf->QRname);
1470 len = strlen(use_this_rncptr->rooms) + strlen(qrbuf->QRname) + 5;
1471 ptr = realloc(use_this_rncptr->rooms, len);
1474 strcat(ptr, qrbuf->QRname);
1475 use_this_rncptr->rooms = ptr;
1488 * Scan for rooms that have RSS client requests configured
1490 void rssclient_scan(void) {
1491 static time_t last_run = 0L;
1492 static int doing_rssclient = 0;
1493 rssnetcfg *rptr = NULL;
1495 /* Run no more than once every 15 minutes. */
1496 if ((time(NULL) - last_run) < 900) {
1501 * This is a simple concurrency check to make sure only one rssclient run
1502 * is done at a time. We could do this with a mutex, but since we
1503 * don't really require extremely fine granularity here, we'll do it
1504 * with a static variable instead.
1506 if (doing_rssclient) return;
1507 doing_rssclient = 1;
1509 syslog(LOG_DEBUG, "rssclient started\n");
1510 CtdlForEachRoom(rssclient_scan_room, NULL);
1512 while (rnclist != NULL && !server_shutting_down) {
1513 rss_do_fetching(rnclist);
1515 rnclist = rnclist->next;
1516 if (rptr->rooms != NULL) free(rptr->rooms);
1520 syslog(LOG_DEBUG, "rssclient ended\n");
1521 last_run = time(NULL);
1522 doing_rssclient = 0;
1526 void LoadUrlShorteners(void)
1530 const char *POS = NULL;
1531 const char *Err = NULL;
1532 StrBuf *Content, *Line;
1535 UrlShorteners = NewHash(0, Flathash);
1537 fd = open(file_citadel_urlshorteners, 0);
1541 Content = NewStrBufPlain(NULL, SIZ);
1543 while (POS != StrBufNOTNULL)
1545 StrBufTCP_read_buffered_line_fast (Line, Content, &POS, &fd, 1, 1, &Err);
1547 if ((*ChrPtr(Line) != '#') && (StrLength(Line) > 0))
1549 Put(UrlShorteners, IKEY(i), Line, HFreeStrBuf);
1556 POS = StrBufNOTNULL;
1559 FreeStrBuf(&Content);
1564 void rss_cleanup(void)
1566 DeleteHash(&StartHandlers);
1567 DeleteHash(&EndHandlers);
1568 DeleteHash(&UrlShorteners);
1569 DeleteHash(&KnownNameSpaces);
1572 CTDL_MODULE_INIT(rssclient)
1576 syslog(LOG_INFO, "%s\n", curl_version());
1577 CtdlRegisterSessionHook(rssclient_scan, EVT_TIMER);
1581 LoadUrlShorteners ();
1583 StartHandlers = NewHash(1, NULL);
1584 EndHandlers = NewHash(1, NULL);
1586 AddRSSStartHandler(RSS_item_rss_start, RSS_UNSET, HKEY("rss"));
1587 AddRSSStartHandler(RSS_item_rdf_start, RSS_UNSET, HKEY("rdf"));
1588 AddRSSStartHandler(ATOM_item_feed_start, RSS_UNSET, HKEY("feed"));
1589 AddRSSStartHandler(RSS_item_item_start, RSS_RSS, HKEY("item"));
1590 AddRSSStartHandler(ATOM_item_entry_start, RSS_ATOM, HKEY("entry"));
1591 AddRSSStartHandler(ATOM_item_link_start, RSS_ATOM, HKEY("link"));
1593 AddRSSEndHandler(ATOMRSS_item_title_end, RSS_ATOM|RSS_RSS|RSS_REQUIRE_BUF, HKEY("title"));
1594 AddRSSEndHandler(RSS_item_guid_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("guid"));
1595 AddRSSEndHandler(ATOM_item_id_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("id"));
1596 AddRSSEndHandler(RSS_item_link_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("link"));
1598 // hm, rss to the comments of that blog, might be interesting in future, but...
1599 AddRSSEndHandler(RSS_item_relink_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("commentrss"));
1601 AddRSSEndHandler(RSS_item_relink_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("comments"));
1603 AddRSSEndHandler(RSSATOM_item_title_end, RSS_ATOM|RSS_RSS|RSS_REQUIRE_BUF, HKEY("title"));
1604 AddRSSEndHandler(ATOM_item_content_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("content"));
1605 AddRSSEndHandler(RSS_item_description_end, RSS_RSS|RSS_ATOM|RSS_REQUIRE_BUF, HKEY("encoded"));
1606 AddRSSEndHandler(ATOM_item_summary_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("summary"));
1607 AddRSSEndHandler(RSS_item_description_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("description"));
1608 AddRSSEndHandler(ATOM_item_published_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("published"));
1609 AddRSSEndHandler(ATOM_item_updated_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("updated"));
1610 AddRSSEndHandler(RSS_item_pubdate_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("pubdate"));
1611 AddRSSEndHandler(RSS_item_date_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("date"));
1612 AddRSSEndHandler(RSS_item_author_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("author"));
1613 AddRSSEndHandler(RSS_item_creator_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("creator"));
1615 AddRSSEndHandler(ATOM_item_email_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("email"));
1616 AddRSSEndHandler(ATOM_item_name_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("name"));
1617 AddRSSEndHandler(ATOM_item_uri_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("uri"));
1619 AddRSSEndHandler(RSS_item_item_end, RSS_RSS, HKEY("item"));
1620 AddRSSEndHandler(RSS_item_rss_end, RSS_RSS, HKEY("rss"));
1621 AddRSSEndHandler(RSS_item_rdf_end, RSS_RSS, HKEY("rdf"));
1622 AddRSSEndHandler(ATOM_item_entry_end, RSS_ATOM, HKEY("entry"));
1625 /* at the start of atoms: <seq> <li>link to resource</li></seq> ignore them. */
1626 AddRSSStartHandler(RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("seq"));
1627 AddRSSEndHandler (RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("seq"));
1628 AddRSSStartHandler(RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("li"));
1629 AddRSSEndHandler (RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("li"));
1631 /* links to other feed generators... */
1632 AddRSSStartHandler(RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("feedflare"));
1633 AddRSSEndHandler (RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("feedflare"));
1634 AddRSSStartHandler(RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("browserfriendly"));
1635 AddRSSEndHandler (RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("browserfriendly"));
1637 KnownNameSpaces = NewHash(1, NULL);
1638 Put(KnownNameSpaces, HKEY("http://a9.com/-/spec/opensearch/1.1/"), NULL, reference_free_handler);
1639 Put(KnownNameSpaces, HKEY("http://a9.com/-/spec/opensearchrss/1.0/"), NULL, reference_free_handler);
1640 Put(KnownNameSpaces, HKEY("http://backend.userland.com/creativeCommonsRssModule"), NULL, reference_free_handler);
1641 Put(KnownNameSpaces, HKEY("http://purl.org/atom/ns#"), NULL, reference_free_handler);
1642 Put(KnownNameSpaces, HKEY("http://purl.org/dc/elements/1.1/"), NULL, reference_free_handler);
1643 Put(KnownNameSpaces, HKEY("http://purl.org/rss/1.0/"), NULL, reference_free_handler);
1644 Put(KnownNameSpaces, HKEY("http://purl.org/rss/1.0/modules/content/"), NULL, reference_free_handler);
1645 Put(KnownNameSpaces, HKEY("http://purl.org/rss/1.0/modules/slash/"), NULL, reference_free_handler);
1646 Put(KnownNameSpaces, HKEY("http://purl.org/rss/1.0/modules/syndication/"), NULL, reference_free_handler);
1647 Put(KnownNameSpaces, HKEY("http://purl.org/rss/1.0/"), NULL, reference_free_handler);
1648 Put(KnownNameSpaces, HKEY("http://purl.org/syndication/thread/1.0"), NULL, reference_free_handler);
1649 Put(KnownNameSpaces, HKEY("http://rssnamespace.org/feedburner/ext/1.0"), NULL, reference_free_handler);
1650 Put(KnownNameSpaces, HKEY("http://schemas.google.com/g/2005"), NULL, reference_free_handler);
1651 Put(KnownNameSpaces, HKEY("http://webns.net/mvcb/"), NULL, reference_free_handler);
1652 Put(KnownNameSpaces, HKEY("http://web.resource.org/cc/"), NULL, reference_free_handler);
1653 Put(KnownNameSpaces, HKEY("http://wellformedweb.org/CommentAPI/"), NULL, reference_free_handler);
1654 Put(KnownNameSpaces, HKEY("http://www.georss.org/georss"), NULL, reference_free_handler);
1655 Put(KnownNameSpaces, HKEY("http://www.w3.org/1999/xhtml"), NULL, reference_free_handler);
1656 Put(KnownNameSpaces, HKEY("http://www.w3.org/1999/02/22-rdf-syntax-ns#"), NULL, reference_free_handler);
1657 Put(KnownNameSpaces, HKEY("http://www.w3.org/1999/02/22-rdf-syntax-ns#"), NULL, reference_free_handler);
1658 Put(KnownNameSpaces, HKEY("http://www.w3.org/2003/01/geo/wgs84_pos#"), NULL, reference_free_handler);
1659 Put(KnownNameSpaces, HKEY("http://www.w3.org/2005/Atom"), NULL, reference_free_handler);
1660 Put(KnownNameSpaces, HKEY("urn:flickr:"), NULL, reference_free_handler);
1662 /* we don't like these namespaces because of they shadow our usefull parameters. */
1663 Put(KnownNameSpaces, HKEY("http://search.yahoo.com/mrss/"), NULL, reference_free_handler);
1665 CtdlRegisterCleanupHook(rss_cleanup);