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 CtdlLogPrintf(0, "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 CtdlLogPrintf(0, "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 CtdlLogPrintf(0, "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 CtdlLogPrintf(CTDL_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 (CtdlThreadCheckStop())
380 rc = curl_easy_perform(curl);
382 CtdlLogPrintf(CTDL_ALERT, "libcurl error %d: %s\n", rc, errmsg);
389 curl_easy_cleanup(curl);
397 void CrawlMessageForShorterUrls(HashList *pUrls, StrBuf *Message)
406 while (GetHash(UrlShorteners, IKEY(nShorter), &pv))
409 pch = ChrPtr(Message);
410 pUrl = strstr(pch, ChrPtr((StrBuf*)pv));
411 while ((pUrl != NULL) && (nHits < 99))
413 pCUrl = malloc(sizeof(ConstStr));
416 pch = pUrl + StrLength((StrBuf*)pv);
417 while (isalnum(*pch)||(*pch == '-')||(*pch == '/'))
419 pCUrl->len = pch - pCUrl->Key;
421 Put(pUrls, IKEY(nHits), pCUrl, NULL);
423 pUrl = strstr(pch, ChrPtr((StrBuf*)pv));
428 int SortConstStrByPosition(const void *Item1, const void *Item2)
430 const ConstStr *p1, *p2;
431 p1 = (const ConstStr*) Item1;
432 p2 = (const ConstStr*) Item2;
433 if (p1->Key == p2->Key)
435 if (p1->Key > p2->Key)
440 void ExpandShortUrls(StrBuf *Message)
448 /* we just suspect URL shorteners to be inside of feeds from twitter
449 * or other short content messages, so don't crawl through real blogs.
451 if (StrLength(Message) > 500)
454 pUrls = NewHash(1, Flathash);
455 CrawlMessageForShorterUrls(pUrls, Message);
457 if (GetCount(pUrls) > 0)
459 StrBuf *ShorterUrlStr;
465 Shadow = NewStrBufPlain(NULL, StrLength(Message));
466 SortByPayload (pUrls, SortConstStrByPosition);
468 ShorterUrlStr = NewStrBufPlain(NULL, StrLength(Message));
470 pch = ChrPtr(Message);
471 pche = pch + StrLength(Message);
472 Pos = GetNewHashPos(pUrls, 1);
473 while (GetNextHashPos(pUrls, Pos, &len, &Key, &pv))
475 pCUrl = (ConstStr*) pv;
477 if (pch != pCUrl->Key)
478 StrBufAppendBufPlain(Shadow, pch, pCUrl->Key - pch, 0);
480 StrBufPlain(ShorterUrlStr, CKEY(*pCUrl));
481 if (LookupUrl(ShorterUrlStr))
483 StrBufAppendBufPlain(Shadow, HKEY("<a href=\""), 0);
484 StrBufAppendBuf(Shadow, ShorterUrlStr, 0);
485 StrBufAppendBufPlain(Shadow, HKEY("\">"), 0);
486 StrBufAppendBuf(Shadow, ShorterUrlStr, 0);
487 StrBufAppendBufPlain(Shadow, HKEY("["), 0);
488 StrBufAppendBufPlain(Shadow, pCUrl->Key, pCUrl->len, 0);
489 StrBufAppendBufPlain(Shadow, HKEY("]</a>"), 0);
493 StrBufAppendBufPlain(Shadow, HKEY("<a href=\""), 0);
494 StrBufAppendBufPlain(Shadow, pCUrl->Key, pCUrl->len, 0);
495 StrBufAppendBufPlain(Shadow, HKEY("\">"), 0);
496 StrBufAppendBufPlain(Shadow, pCUrl->Key, pCUrl->len, 0);
497 StrBufAppendBufPlain(Shadow, HKEY("</a>"), 0);
499 pch = pCUrl->Key + pCUrl->len + 1;
503 StrBufAppendBufPlain(Shadow, pch, pche - pch, 0);
504 FlushStrBuf(Message);
505 StrBufAppendBuf(Message, Shadow, 0);
507 FreeStrBuf(&ShorterUrlStr);
516 void AppendLink(StrBuf *Message, StrBuf *link, StrBuf *LinkTitle, const char *Title)
518 if (StrLength(link) > 0)
520 StrBufAppendBufPlain(Message, HKEY("<a href=\""), 0);
521 StrBufAppendBuf(Message, link, 0);
522 StrBufAppendBufPlain(Message, HKEY("\">"), 0);
523 if (StrLength(LinkTitle) > 0)
524 StrBufAppendBuf(Message, LinkTitle, 0);
525 else if ((Title != NULL) && !IsEmptyStr(Title))
526 StrBufAppendBufPlain(Message, Title, -1, 0);
528 StrBufAppendBuf(Message, link, 0);
529 StrBufAppendBufPlain(Message, HKEY("</a><br>\n"), 0);
533 * Commit a fetched and parsed RSS item to disk
535 void rss_save_item(rss_item *ri)
538 struct MD5Context md5context;
539 u_char rawdigest[MD5_DIGEST_LEN];
542 struct cdbdata *cdbut;
544 struct CtdlMessage *msg;
545 struct recptypes *recp = NULL;
549 recp = (struct recptypes *) malloc(sizeof(struct recptypes));
550 if (recp == NULL) return;
551 memset(recp, 0, sizeof(struct recptypes));
552 memset(&ut, 0, sizeof(struct UseTable));
553 recp->recp_room = strdup(ri->roomlist);
554 recp->num_room = num_tokens(ri->roomlist, '|');
555 recp->recptypes_magic = RECPTYPES_MAGIC;
557 /* Construct a GUID to use in the S_USETABLE table.
558 * If one is not present in the item itself, make one up.
560 if (ri->guid != NULL) {
561 StrBufSpaceToBlank(ri->guid);
562 StrBufTrim(ri->guid);
563 snprintf(utmsgid, sizeof utmsgid, "rss/%s", ChrPtr(ri->guid));
566 MD5Init(&md5context);
567 if (ri->title != NULL) {
568 MD5Update(&md5context, (const unsigned char*)ChrPtr(ri->title), StrLength(ri->title));
570 if (ri->link != NULL) {
571 MD5Update(&md5context, (const unsigned char*)ChrPtr(ri->link), StrLength(ri->link));
573 MD5Final(rawdigest, &md5context);
574 for (i=0; i<MD5_DIGEST_LEN; i++) {
575 sprintf(&utmsgid[i*2], "%02X", (unsigned char) (rawdigest[i] & 0xff));
576 utmsgid[i*2] = tolower(utmsgid[i*2]);
577 utmsgid[(i*2)+1] = tolower(utmsgid[(i*2)+1]);
579 strcat(utmsgid, "_rss2ctdl");
582 /* Find out if we've already seen this item */
584 cdbut = cdb_fetch(CDB_USETABLE, utmsgid, strlen(utmsgid));
587 /* Item has already been seen */
588 CtdlLogPrintf(CTDL_DEBUG, "%s has already been seen\n", utmsgid);
591 /* rewrite the record anyway, to update the timestamp */
592 strcpy(ut.ut_msgid, utmsgid);
593 ut.ut_timestamp = time(NULL);
594 cdb_store(CDB_USETABLE, utmsgid, strlen(utmsgid), &ut, sizeof(struct UseTable) );
599 /* Item has not been seen, so save it. */
600 CtdlLogPrintf(CTDL_DEBUG, "RSS: saving item...\n");
601 if (ri->description == NULL) ri->description = NewStrBufPlain(HKEY(""));
602 StrBufSpaceToBlank(ri->description);
603 msg = malloc(sizeof(struct CtdlMessage));
604 memset(msg, 0, sizeof(struct CtdlMessage));
605 msg->cm_magic = CTDLMESSAGE_MAGIC;
606 msg->cm_anon_type = MES_NORMAL;
607 msg->cm_format_type = FMT_RFC822;
609 if (ri->guid != NULL) {
610 msg->cm_fields['E'] = strdup(ChrPtr(ri->guid));
613 if (ri->author_or_creator != NULL) {
615 StrBuf *Encoded = NULL;
618 From = html_to_ascii(ChrPtr(ri->author_or_creator),
619 StrLength(ri->author_or_creator),
621 StrBufPlain(ri->author_or_creator, From, -1);
622 StrBufTrim(ri->author_or_creator);
625 FromAt = strchr(ChrPtr(ri->author_or_creator), '@') != NULL;
626 if (!FromAt && StrLength (ri->author_email) > 0)
628 StrBufRFC2047encode(&Encoded, ri->author_or_creator);
629 msg->cm_fields['A'] = SmashStrBuf(&Encoded);
630 msg->cm_fields['P'] = SmashStrBuf(&ri->author_email);
635 msg->cm_fields['P'] = SmashStrBuf(&ri->author_or_creator);
638 StrBufRFC2047encode(&Encoded, ri->author_or_creator);
639 msg->cm_fields['A'] = SmashStrBuf(&Encoded);
640 msg->cm_fields['P'] = strdup("rss@localhost");
645 msg->cm_fields['A'] = strdup("rss");
648 msg->cm_fields['N'] = strdup(NODENAME);
649 if (ri->title != NULL) {
652 StrBuf *Encoded, *QPEncoded;
655 StrBufSpaceToBlank(ri->title);
656 len = StrLength(ri->title);
657 Sbj = html_to_ascii(ChrPtr(ri->title), len, 512, 0);
659 if (Sbj[len - 1] == '\n')
664 Encoded = NewStrBufPlain(Sbj, len);
668 StrBufRFC2047encode(&QPEncoded, Encoded);
670 msg->cm_fields['U'] = SmashStrBuf(&QPEncoded);
671 FreeStrBuf(&Encoded);
673 msg->cm_fields['T'] = malloc(64);
674 snprintf(msg->cm_fields['T'], 64, "%ld", ri->pubdate);
675 if (ri->channel_title != NULL) {
676 if (StrLength(ri->channel_title) > 0) {
677 msg->cm_fields['O'] = strdup(ChrPtr(ri->channel_title));
680 if (ri->link == NULL)
681 ri->link = NewStrBufPlain(HKEY(""));
682 ExpandShortUrls(ri->description);
683 msglen += 1024 + StrLength(ri->link) + StrLength(ri->description) ;
685 Message = NewStrBufPlain(NULL, StrLength(ri->description));
687 StrBufPlain(Message, HKEY(
688 "Content-type: text/html; charset=\"UTF-8\"\r\n\r\n"
691 StrBufAppendBuf(Message, ri->description, 0);
692 StrBufAppendBufPlain(Message, HKEY("<br><br>\n"), 0);
694 AppendLink(Message, ri->link, ri->linkTitle, NULL);
695 AppendLink(Message, ri->reLink, ri->reLinkTitle, "Reply to this");
696 StrBufAppendBufPlain(Message, HKEY("</body></html>\n"), 0);
698 msg->cm_fields['M'] = SmashStrBuf(&Message);
700 CtdlSubmitMsg(msg, recp, NULL, 0);
701 CtdlFreeMessage(msg);
703 /* write the uidl to the use table so we don't store this item again */
704 strcpy(ut.ut_msgid, utmsgid);
705 ut.ut_timestamp = time(NULL);
706 cdb_store(CDB_USETABLE, utmsgid, strlen(utmsgid), &ut, sizeof(struct UseTable) );
708 free_recipients(recp);
714 * Convert an RDF/RSS datestamp into a time_t
716 time_t rdf_parsedate(const char *p)
722 if (strlen(p) < 10) return 0L;
724 memset(&tm, 0, sizeof tm);
727 * If the timestamp appears to be in W3C datetime format, try to
728 * parse it. See also: http://www.w3.org/TR/NOTE-datetime
730 * This code, along with parsedate.c, is a potential candidate for
731 * moving into libcitadel.
733 if ( (p[4] == '-') && (p[7] == '-') ) {
734 tm.tm_year = atoi(&p[0]) - 1900;
735 tm.tm_mon = atoi(&p[5]) - 1;
736 tm.tm_mday = atoi(&p[8]);
737 if ( (p[10] == 'T') && (p[13] == ':') ) {
738 tm.tm_hour = atoi(&p[11]);
739 tm.tm_min = atoi(&p[14]);
744 /* hmm... try RFC822 date stamp format */
747 if (t > 0) return(t);
749 /* yeesh. ok, just return the current date and time. */
753 void flush_rss_item(rss_item *ri)
755 /* Initialize the feed item data structure */
756 FreeStrBuf(&ri->guid);
757 FreeStrBuf(&ri->title);
758 FreeStrBuf(&ri->link);
759 FreeStrBuf(&ri->author_or_creator);
760 FreeStrBuf(&ri->author_email);
761 FreeStrBuf(&ri->author_url);
762 FreeStrBuf(&ri->description);
765 void rss_xml_start(void *data, const char *supplied_el, const char **attr)
768 rsscollection *rssc = (rsscollection*) data;
769 rssnetcfg *Cfg = rssc->Cfg;
770 rss_item *ri = rssc->Item;
775 /* Axe the namespace, we don't care about it */
776 /// CtdlLogPrintf(0, "RSS: supplied el %d: %s...\n", rssc->Cfg->ItemType, supplied_el);
778 while (sep = strchr(pel, ':'), sep) {
782 if (pel != supplied_el)
786 if (!GetHash(KnownNameSpaces,
788 pel - supplied_el - 1,
792 CtdlLogPrintf(0, "RSS: START ignoring because of wrong namespace [%s] = [%s]\n",
799 StrBufPlain(rssc->Key, pel, -1);
800 StrBufLowerCase(rssc->Key);
801 if (GetHash(StartHandlers, SKEY(rssc->Key), &pv))
803 rssc->Current = h = (rss_xml_handler*) pv;
805 if (((h->Flags & RSS_UNSET) != 0) &&
806 (Cfg->ItemType == RSS_UNSET))
808 h->Handler(rssc->CData, ri, Cfg, attr);
810 else if (((h->Flags & RSS_RSS) != 0) &&
811 (Cfg->ItemType == RSS_RSS))
813 h->Handler(rssc->CData, ri, Cfg, attr);
815 else if (((h->Flags & RSS_ATOM) != 0) &&
816 (Cfg->ItemType == RSS_ATOM))
818 h->Handler(rssc->CData, ri, Cfg, attr);
822 CtdlLogPrintf(0, "RSS: START unhandled: [%s] [%s]...\n", pel, supplied_el);
827 CtdlLogPrintf(0, "RSS: START unhandled: [%s] [%s]...\n", pel, supplied_el);
831 void rss_xml_end(void *data, const char *supplied_el)
834 rsscollection *rssc = (rsscollection*) data;
835 rssnetcfg *Cfg = rssc->Cfg;
836 rss_item *ri = rssc->Item;
841 /* Axe the namespace, we don't care about it */
843 while (sep = strchr(pel, ':'), sep) {
846 // CtdlLogPrintf(0, "RSS: END %s...\n", el);
847 if (pel != supplied_el)
851 if (!GetHash(KnownNameSpaces,
853 pel - supplied_el - 1,
857 CtdlLogPrintf(0, "RSS: END ignoring because of wrong namespace [%s] = [%s]\n",
858 supplied_el, ChrPtr(rssc->CData));
860 FlushStrBuf(rssc->CData);
865 StrBufPlain(rssc->Key, pel, -1);
866 StrBufLowerCase(rssc->Key);
867 if (GetHash(EndHandlers, SKEY(rssc->Key), &pv))
869 h = (rss_xml_handler*) pv;
871 if (((h->Flags & RSS_UNSET) != 0) &&
872 (Cfg->ItemType == RSS_UNSET))
874 h->Handler(rssc->CData, ri, Cfg, NULL);
876 else if (((h->Flags & RSS_RSS) != 0) &&
877 (Cfg->ItemType == RSS_RSS))
879 h->Handler(rssc->CData, ri, Cfg, NULL);
881 else if (((h->Flags & RSS_ATOM) != 0) &&
882 (Cfg->ItemType == RSS_ATOM))
884 h->Handler(rssc->CData, ri, Cfg, NULL);
888 CtdlLogPrintf(0, "RSS: END unhandled: [%s] [%s] = [%s]...\n", pel, supplied_el, ChrPtr(rssc->CData));
893 CtdlLogPrintf(0, "RSS: END unhandled: [%s] [%s] = [%s]...\n", pel, supplied_el, ChrPtr(rssc->CData));
895 FlushStrBuf(rssc->CData);
896 rssc->Current = NULL;
903 void RSS_item_rss_start (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
905 CtdlLogPrintf(CTDL_DEBUG, "RSS: This is an RSS feed.\n");
906 Cfg->ItemType = RSS_RSS;
909 void RSS_item_rdf_start(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
911 CtdlLogPrintf(CTDL_DEBUG, "RSS: This is an RDF feed.\n");
912 Cfg->ItemType = RSS_RSS;
915 void ATOM_item_feed_start(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
917 CtdlLogPrintf(CTDL_DEBUG, "RSS: This is an ATOM feed.\n");
918 Cfg->ItemType = RSS_ATOM;
922 void RSS_item_item_start(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
924 ri->item_tag_nesting ++;
928 void ATOM_item_entry_start(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
931 ri->item_tag_nesting ++;
935 void ATOM_item_link_start (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
938 const char *pHref = NULL;
939 const char *pType = NULL;
940 const char *pRel = NULL;
941 const char *pTitle = NULL;
943 for (i = 0; Attr[i] != NULL; i+=2)
945 if (!strcmp(Attr[i], "href"))
949 else if (!strcmp(Attr[i], "rel"))
953 else if (!strcmp(Attr[i], "type"))
957 else if (!strcmp(Attr[i], "title"))
963 return; /* WHUT? Pointing... where? */
964 if ((pType != NULL) && !strcasecmp(pType, "application/atom+xml"))
965 return; /* these just point to other rss resources, we're not interested in them. */
968 if (!strcasecmp (pRel, "replies"))
970 NewStrBufDupAppendFlush(&ri->reLink, NULL, pHref, -1);
971 StrBufTrim(ri->link);
972 NewStrBufDupAppendFlush(&ri->reLinkTitle, NULL, pTitle, -1);
974 else if (!strcasecmp(pRel, "alternate")) /* Alternative representation of this Item... */
976 NewStrBufDupAppendFlush(&ri->link, NULL, pHref, -1);
977 StrBufTrim(ri->link);
978 NewStrBufDupAppendFlush(&ri->linkTitle, NULL, pTitle, -1);
981 #if 0 /* these are also defined, but dunno what to do with them.. */
982 else if (!strcasecmp(pRel, "related"))
985 else if (!strcasecmp(pRel, "self"))
988 else if (!strcasecmp(pRel, "enclosure"))
989 {/* this reference can get big, and is probably the full article... */
991 else if (!strcasecmp(pRel, "via"))
992 {/* this article was provided via... */
996 else if (StrLength(ri->link) == 0)
998 NewStrBufDupAppendFlush(&ri->link, NULL, pHref, -1);
999 StrBufTrim(ri->link);
1000 NewStrBufDupAppendFlush(&ri->linkTitle, NULL, pTitle, -1);
1007 void ATOMRSS_item_title_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1009 if ((ri->item_tag_nesting == 0) && (StrLength(CData) > 0)) {
1010 NewStrBufDupAppendFlush(&ri->channel_title, CData, NULL, 0);
1011 StrBufTrim(ri->channel_title);
1015 void RSS_item_guid_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1017 if (StrLength(CData) > 0) {
1018 NewStrBufDupAppendFlush(&ri->guid, CData, NULL, 0);
1022 void ATOM_item_id_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1024 if (StrLength(CData) > 0) {
1025 NewStrBufDupAppendFlush(&ri->guid, CData, NULL, 0);
1030 void RSS_item_link_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1032 if (StrLength(CData) > 0) {
1033 NewStrBufDupAppendFlush(&ri->link, CData, NULL, 0);
1034 StrBufTrim(ri->link);
1037 void RSS_item_relink_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1039 if (StrLength(CData) > 0) {
1040 NewStrBufDupAppendFlush(&ri->reLink, CData, NULL, 0);
1041 StrBufTrim(ri->reLink);
1045 void RSSATOM_item_title_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1047 if (StrLength(CData) > 0) {
1048 NewStrBufDupAppendFlush(&ri->title, CData, NULL, 0);
1049 StrBufTrim(ri->title);
1053 void ATOM_item_content_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1055 long olen = StrLength (ri->description);
1056 long clen = StrLength (CData);
1060 NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
1061 StrBufTrim(ri->description);
1063 else if (olen < clen) {
1064 FlushStrBuf(ri->description);
1065 NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
1066 StrBufTrim(ri->description);
1070 void ATOM_item_summary_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1072 /* this can contain an abstract of the article. but we don't want to verwrite a full document if we already have it. */
1073 if ((StrLength(CData) > 0) && (StrLength(ri->description) == 0))
1075 NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
1076 StrBufTrim(ri->description);
1080 void RSS_item_description_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1082 long olen = StrLength (ri->description);
1083 long clen = StrLength (CData);
1087 NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
1088 StrBufTrim(ri->description);
1090 else if (olen < clen) {
1091 FlushStrBuf(ri->description);
1092 NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
1093 StrBufTrim(ri->description);
1098 void ATOM_item_published_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1100 if (StrLength(CData) > 0) {
1102 ri->pubdate = rdf_parsedate(ChrPtr(CData));
1106 void ATOM_item_updated_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1108 if (StrLength(CData) > 0) {
1110 ri->pubdate = rdf_parsedate(ChrPtr(CData));
1114 void RSS_item_pubdate_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1116 if (StrLength(CData) > 0) {
1118 ri->pubdate = rdf_parsedate(ChrPtr(CData));
1123 void RSS_item_date_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1125 if (StrLength(CData) > 0) {
1127 ri->pubdate = rdf_parsedate(ChrPtr(CData));
1133 void RSS_item_author_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1135 if (StrLength(CData) > 0) {
1136 NewStrBufDupAppendFlush(&ri->author_or_creator, CData, NULL, 0);
1137 StrBufTrim(ri->author_or_creator);
1142 void ATOM_item_name_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1144 if (StrLength(CData) > 0) {
1145 NewStrBufDupAppendFlush(&ri->author_or_creator, CData, NULL, 0);
1146 StrBufTrim(ri->author_or_creator);
1150 void ATOM_item_email_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1152 if (StrLength(CData) > 0) {
1153 NewStrBufDupAppendFlush(&ri->author_email, CData, NULL, 0);
1154 StrBufTrim(ri->author_email);
1158 void RSS_item_creator_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1160 if ((StrLength(CData) > 0) &&
1161 (StrLength(ri->author_or_creator) == 0))
1163 NewStrBufDupAppendFlush(&ri->author_or_creator, CData, NULL, 0);
1164 StrBufTrim(ri->author_or_creator);
1169 void ATOM_item_uri_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1171 if (StrLength(CData) > 0) {
1172 NewStrBufDupAppendFlush(&ri->author_url, CData, NULL, 0);
1173 StrBufTrim(ri->author_url);
1177 void RSS_item_item_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1179 --ri->item_tag_nesting;
1184 void ATOM_item_entry_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1186 --ri->item_tag_nesting;
1190 void RSS_item_rss_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1192 // CtdlLogPrintf(CTDL_DEBUG, "End of feed detected. Closing parser.\n");
1193 ri->done_parsing = 1;
1196 void RSS_item_rdf_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1198 // CtdlLogPrintf(CTDL_DEBUG, "End of feed detected. Closing parser.\n");
1199 ri->done_parsing = 1;
1203 void RSSATOM_item_ignore(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1210 * This callback stores up the data which appears in between tags.
1212 void rss_xml_cdata_start(void *data)
1214 rsscollection *rssc = (rsscollection*) data;
1216 FlushStrBuf(rssc->CData);
1219 void rss_xml_cdata_end(void *data)
1222 void rss_xml_chardata(void *data, const XML_Char *s, int len)
1224 rsscollection *rssc = (rsscollection*) data;
1226 StrBufAppendBufPlain (rssc->CData, s, len, 0);
1230 * Callback function for passing libcurl's output to expat for parsing
1232 size_t rss_libcurl_callback(void *ptr, size_t size, size_t nmemb, void *stream)
1234 XML_Parse((XML_Parser)stream, ptr, (size * nmemb), 0);
1235 return (size*nmemb);
1241 * Begin a feed parse
1243 void rss_do_fetching(rssnetcfg *Cfg) {
1246 XML_Parser xp = NULL;
1251 char errmsg[1024] = "";
1260 if ((Cfg->next_poll != 0) && (now < Cfg->next_poll))
1262 memset(&ri, 0, sizeof(rss_item));
1266 CtdlLogPrintf(CTDL_DEBUG, "Fetching RSS feed <%s>\n", Cfg->url);
1268 curl = curl_easy_init();
1270 CtdlLogPrintf(CTDL_ALERT, "Unable to initialize libcurl.\n");
1273 Answer = NewStrBufPlain(NULL, SIZ);
1275 curl_easy_setopt(curl, CURLOPT_URL, Cfg->url);
1276 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
1277 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
1278 curl_easy_setopt(curl, CURLOPT_WRITEDATA, Answer);
1279 // curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, rss_libcurl_callback);
1280 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlFillStrBuf_callback);
1281 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errmsg);
1282 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
1283 #ifdef CURLOPT_HTTP_CONTENT_DECODING
1284 curl_easy_setopt(curl, CURLOPT_HTTP_CONTENT_DECODING, 1);
1285 curl_easy_setopt(curl, CURLOPT_ENCODING, "");
1287 curl_easy_setopt(curl, CURLOPT_USERAGENT, CITADEL);
1288 curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180); /* die after 180 seconds */
1290 (!IsEmptyStr(config.c_ip_addr))
1291 && (strcmp(config.c_ip_addr, "*"))
1292 && (strcmp(config.c_ip_addr, "::"))
1293 && (strcmp(config.c_ip_addr, "0.0.0.0"))
1295 curl_easy_setopt(curl, CURLOPT_INTERFACE, config.c_ip_addr);
1298 if (CtdlThreadCheckStop())
1300 curl_easy_cleanup(curl);
1304 if (CtdlThreadCheckStop())
1307 res = curl_easy_perform(curl);
1309 CtdlLogPrintf(CTDL_ALERT, "libcurl error %d: %s\n", res, errmsg);
1312 if (CtdlThreadCheckStop())
1318 memset(&ri, 0, sizeof(rss_item));
1319 ri.roomlist = Cfg->rooms;
1320 rssc.CData = NewStrBufPlain(NULL, SIZ);
1321 rssc.Key = NewStrBuf();
1323 StrBufSipLine(rssc.Key, Answer, &at);
1326 #define encoding "encoding=\""
1327 ptr = strstr(ChrPtr(rssc.Key), encoding);
1332 ptr += sizeof (encoding) - 1;
1333 pche = strchr(ptr, '"');
1335 StrBufCutAt(rssc.Key, -1, pche);
1343 xp = XML_ParserCreateNS(ptr, ':');
1345 CtdlLogPrintf(CTDL_ALERT, "Cannot create XML parser!\n");
1348 FlushStrBuf(rssc.Key);
1351 XML_SetUnknownEncodingHandler(xp,
1352 handle_unknown_xml_encoding,
1356 XML_SetElementHandler(xp, rss_xml_start, rss_xml_end);
1357 XML_SetCharacterDataHandler(xp, rss_xml_chardata);
1358 XML_SetUserData(xp, &rssc);
1359 XML_SetCdataSectionHandler(xp,
1360 rss_xml_cdata_start,
1364 len = StrLength(Answer);
1365 ptr = SmashStrBuf(&Answer);
1366 XML_Parse(xp, ptr, len, 0);
1368 if (ri.done_parsing == 0)
1369 XML_Parse(xp, "", 0, 1);
1372 CtdlLogPrintf(CTDL_ALERT, "RSS: XML Status [%s] \n",
1374 XML_GetErrorCode(xp)));
1377 curl_easy_cleanup(curl);
1380 flush_rss_item(&ri);
1381 FreeStrBuf(&rssc.CData);
1382 FreeStrBuf(&rssc.Key);
1384 Cfg->next_poll = time(NULL) + config.c_net_freq;
1389 * Scan a room's netconfig to determine whether it is requesting any RSS feeds
1391 void rssclient_scan_room(struct ctdlroom *qrbuf, void *data)
1393 char filename[PATH_MAX];
1398 rssnetcfg *rncptr = NULL;
1399 rssnetcfg *use_this_rncptr = NULL;
1403 assoc_file_name(filename, sizeof filename, qrbuf, ctdl_netcfg_dir);
1405 if (CtdlThreadCheckStop())
1408 /* Only do net processing for rooms that have netconfigs */
1409 fp = fopen(filename, "r");
1414 while (fgets(buf, sizeof buf, fp) != NULL && !CtdlThreadCheckStop()) {
1415 buf[strlen(buf)-1] = 0;
1417 extract_token(instr, buf, 0, '|', sizeof instr);
1418 if (!strcasecmp(instr, "rssclient")) {
1420 use_this_rncptr = NULL;
1422 extract_token(feedurl, buf, 1, '|', sizeof feedurl);
1424 /* If any other rooms have requested the same feed, then we will just add this
1425 * room to the target list for that client request.
1427 for (rncptr=rnclist; rncptr!=NULL; rncptr=rncptr->next) {
1428 if (!strcmp(rncptr->url, feedurl)) {
1429 use_this_rncptr = rncptr;
1433 /* Otherwise create a new client request */
1434 if (use_this_rncptr == NULL) {
1435 rncptr = (rssnetcfg *) malloc(sizeof(rssnetcfg));
1436 memset(rncptr, 0, sizeof(rssnetcfg));
1437 rncptr->ItemType = RSS_UNSET;
1438 if (rncptr != NULL) {
1439 rncptr->next = rnclist;
1440 safestrncpy(rncptr->url, feedurl, sizeof rncptr->url);
1441 rncptr->rooms = NULL;
1443 use_this_rncptr = rncptr;
1447 /* Add the room name to the request */
1448 if (use_this_rncptr != NULL) {
1449 if (use_this_rncptr->rooms == NULL) {
1450 rncptr->rooms = strdup(qrbuf->QRname);
1453 len = strlen(use_this_rncptr->rooms) + strlen(qrbuf->QRname) + 5;
1454 ptr = realloc(use_this_rncptr->rooms, len);
1457 strcat(ptr, qrbuf->QRname);
1458 use_this_rncptr->rooms = ptr;
1471 * Scan for rooms that have RSS client requests configured
1473 void rssclient_scan(void) {
1474 static time_t last_run = 0L;
1475 static int doing_rssclient = 0;
1476 rssnetcfg *rptr = NULL;
1479 * This is a simple concurrency check to make sure only one rssclient run
1480 * is done at a time. We could do this with a mutex, but since we
1481 * don't really require extremely fine granularity here, we'll do it
1482 * with a static variable instead.
1484 if (doing_rssclient) return;
1485 doing_rssclient = 1;
1487 CtdlLogPrintf(CTDL_DEBUG, "rssclient started\n");
1488 CtdlForEachRoom(rssclient_scan_room, NULL);
1490 while (rnclist != NULL && !CtdlThreadCheckStop()) {
1491 rss_do_fetching(rnclist);
1493 rnclist = rnclist->next;
1494 if (rptr->rooms != NULL) free(rptr->rooms);
1498 CtdlLogPrintf(CTDL_DEBUG, "rssclient ended\n");
1499 last_run = time(NULL);
1500 doing_rssclient = 0;
1504 void LoadUrlShorteners(void)
1508 const char *POS = NULL;
1509 const char *Err = NULL;
1510 StrBuf *Content, *Line;
1513 UrlShorteners = NewHash(0, Flathash);
1515 fd = open(file_citadel_urlshorteners, 0);
1519 Content = NewStrBufPlain(NULL, SIZ);
1521 while (POS != StrBufNOTNULL)
1523 StrBufTCP_read_buffered_line_fast (Line, Content, &POS, &fd, 1, 1, &Err);
1525 if ((*ChrPtr(Line) != '#') && (StrLength(Line) > 0))
1527 Put(UrlShorteners, IKEY(i), Line, HFreeStrBuf);
1534 POS = StrBufNOTNULL;
1537 FreeStrBuf(&Content);
1542 CTDL_MODULE_INIT(rssclient)
1546 CtdlLogPrintf(CTDL_INFO, "%s\n", curl_version());
1547 CtdlRegisterSessionHook(rssclient_scan, EVT_TIMER);
1551 LoadUrlShorteners ();
1553 StartHandlers = NewHash(1, NULL);
1554 EndHandlers = NewHash(1, NULL);
1556 AddRSSStartHandler(RSS_item_rss_start, RSS_UNSET, HKEY("rss"));
1557 AddRSSStartHandler(RSS_item_rdf_start, RSS_UNSET, HKEY("rdf"));
1558 AddRSSStartHandler(ATOM_item_feed_start, RSS_UNSET, HKEY("feed"));
1559 AddRSSStartHandler(RSS_item_item_start, RSS_RSS, HKEY("item"));
1560 AddRSSStartHandler(ATOM_item_entry_start, RSS_ATOM, HKEY("entry"));
1561 AddRSSStartHandler(ATOM_item_link_start, RSS_ATOM, HKEY("link"));
1563 AddRSSEndHandler(ATOMRSS_item_title_end, RSS_ATOM|RSS_RSS|RSS_REQUIRE_BUF, HKEY("title"));
1564 AddRSSEndHandler(RSS_item_guid_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("guid"));
1565 AddRSSEndHandler(ATOM_item_id_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("id"));
1566 AddRSSEndHandler(RSS_item_link_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("link"));
1568 // hm, rss to the comments of that blog, might be interesting in future, but...
1569 AddRSSEndHandler(RSS_item_relink_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("commentrss"));
1571 AddRSSEndHandler(RSS_item_relink_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("comments"));
1573 AddRSSEndHandler(RSSATOM_item_title_end, RSS_ATOM|RSS_RSS|RSS_REQUIRE_BUF, HKEY("title"));
1574 AddRSSEndHandler(ATOM_item_content_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("content"));
1575 AddRSSEndHandler(RSS_item_description_end, RSS_RSS|RSS_ATOM|RSS_REQUIRE_BUF, HKEY("encoded"));
1576 AddRSSEndHandler(ATOM_item_summary_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("summary"));
1577 AddRSSEndHandler(RSS_item_description_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("description"));
1578 AddRSSEndHandler(ATOM_item_published_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("published"));
1579 AddRSSEndHandler(ATOM_item_updated_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("updated"));
1580 AddRSSEndHandler(RSS_item_pubdate_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("pubdate"));
1581 AddRSSEndHandler(RSS_item_date_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("date"));
1582 AddRSSEndHandler(RSS_item_author_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("author"));
1583 AddRSSEndHandler(RSS_item_creator_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("creator"));
1585 AddRSSEndHandler(ATOM_item_email_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("email"));
1586 AddRSSEndHandler(ATOM_item_name_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("name"));
1587 AddRSSEndHandler(ATOM_item_uri_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("uri"));
1589 AddRSSEndHandler(RSS_item_item_end, RSS_RSS, HKEY("item"));
1590 AddRSSEndHandler(RSS_item_rss_end, RSS_RSS, HKEY("rss"));
1591 AddRSSEndHandler(RSS_item_rdf_end, RSS_RSS, HKEY("rdf"));
1592 AddRSSEndHandler(ATOM_item_entry_end, RSS_ATOM, HKEY("entry"));
1595 /* at the start of atoms: <seq> <li>link to resource</li></seq> ignore them. */
1596 AddRSSStartHandler(RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("seq"));
1597 AddRSSEndHandler (RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("seq"));
1598 AddRSSStartHandler(RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("li"));
1599 AddRSSEndHandler (RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("li"));
1601 /* links to other feed generators... */
1602 AddRSSStartHandler(RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("feedflare"));
1603 AddRSSEndHandler (RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("feedflare"));
1604 AddRSSStartHandler(RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("browserfriendly"));
1605 AddRSSEndHandler (RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("browserfriendly"));
1607 KnownNameSpaces = NewHash(1, NULL);
1608 Put(KnownNameSpaces, HKEY("http://a9.com/-/spec/opensearch/1.1/"), NULL, reference_free_handler);
1609 Put(KnownNameSpaces, HKEY("http://a9.com/-/spec/opensearchrss/1.0/"), NULL, reference_free_handler);
1610 Put(KnownNameSpaces, HKEY("http://backend.userland.com/creativeCommonsRssModule"), NULL, reference_free_handler);
1611 Put(KnownNameSpaces, HKEY("http://purl.org/atom/ns#"), NULL, reference_free_handler);
1612 Put(KnownNameSpaces, HKEY("http://purl.org/dc/elements/1.1/"), NULL, reference_free_handler);
1613 Put(KnownNameSpaces, HKEY("http://purl.org/rss/1.0/"), NULL, reference_free_handler);
1614 Put(KnownNameSpaces, HKEY("http://purl.org/rss/1.0/modules/content/"), NULL, reference_free_handler);
1615 Put(KnownNameSpaces, HKEY("http://purl.org/rss/1.0/modules/slash/"), NULL, reference_free_handler);
1616 Put(KnownNameSpaces, HKEY("http://purl.org/rss/1.0/modules/syndication/"), NULL, reference_free_handler);
1617 Put(KnownNameSpaces, HKEY("http://purl.org/rss/1.0/"), NULL, reference_free_handler);
1618 Put(KnownNameSpaces, HKEY("http://purl.org/syndication/thread/1.0"), NULL, reference_free_handler);
1619 Put(KnownNameSpaces, HKEY("http://rssnamespace.org/feedburner/ext/1.0"), NULL, reference_free_handler);
1620 Put(KnownNameSpaces, HKEY("http://schemas.google.com/g/2005"), NULL, reference_free_handler);
1621 Put(KnownNameSpaces, HKEY("http://webns.net/mvcb/"), NULL, reference_free_handler);
1622 Put(KnownNameSpaces, HKEY("http://web.resource.org/cc/"), NULL, reference_free_handler);
1623 Put(KnownNameSpaces, HKEY("http://wellformedweb.org/CommentAPI/"), NULL, reference_free_handler);
1624 Put(KnownNameSpaces, HKEY("http://www.georss.org/georss"), NULL, reference_free_handler);
1625 Put(KnownNameSpaces, HKEY("http://www.w3.org/1999/xhtml"), NULL, reference_free_handler);
1626 Put(KnownNameSpaces, HKEY("http://www.w3.org/1999/02/22-rdf-syntax-ns#"), NULL, reference_free_handler);
1627 Put(KnownNameSpaces, HKEY("http://www.w3.org/1999/02/22-rdf-syntax-ns#"), NULL, reference_free_handler);
1628 Put(KnownNameSpaces, HKEY("http://www.w3.org/2003/01/geo/wgs84_pos#"), NULL, reference_free_handler);
1629 Put(KnownNameSpaces, HKEY("http://www.w3.org/2005/Atom"), NULL, reference_free_handler);
1630 Put(KnownNameSpaces, HKEY("urn:flickr:"), NULL, reference_free_handler);
1632 /* we don't like these namespaces because of they shadow our usefull parameters. */
1633 Put(KnownNameSpaces, HKEY("http://search.yahoo.com/mrss/"), NULL, reference_free_handler);