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;
69 #define RSS_UNSET (1<<0)
70 #define RSS_RSS (1<<1)
71 #define RSS_ATOM (1<<2)
72 #define RSS_REQUIRE_BUF (1<<3)
74 typedef struct _rss_item {
85 StrBuf *channel_title;
87 StrBuf *author_or_creator;
93 typedef void (*rss_handler_func)(StrBuf *CData,
98 typedef struct __rss_xml_handler {
100 rss_handler_func Handler;
104 typedef struct _rsscollection {
111 rss_xml_handler *Current;
114 struct rssnetcfg *rnclist = NULL;
115 HashList *StartHandlers = NULL;
116 HashList *EndHandlers = NULL;
117 HashList *KnownNameSpaces = NULL;
118 HashList *UrlShorteners = NULL;
119 void AddRSSStartHandler(rss_handler_func Handler, int Flags, const char *key, long len)
122 h = (rss_xml_handler*) malloc(sizeof (rss_xml_handler));
124 h->Handler = Handler;
125 Put(StartHandlers, key, len, h, NULL);
127 void AddRSSEndHandler(rss_handler_func Handler, int Flags, const char *key, long len)
130 h = (rss_xml_handler*) malloc(sizeof (rss_xml_handler));
132 h->Handler = Handler;
133 Put(EndHandlers, key, len, h, NULL);
142 * dug this out of the trashcan of the midgard project, lets see if it works for us.
143 * original code by Alexander Bokovoy <bokovoy@avilink.ne> distributed under GPL V2 or later
147 >= 0 - successfull, 0 means conversion doesn't use multibyte sequences
148 -1 - error during iconv_open call
149 -2 - error during iconv_close call
150 ----------------------------------
151 This function expects that multibyte encoding in 'charset' wouldn't have
152 characters with more than 3 bytes. It is not intended to convert UTF-8 because
153 we'll never receive UTF-8 in our handler (it is handled by Exat itself).
156 fill_encoding_info (const char *charset, XML_Encoding * info)
158 iconv_t cd = (iconv_t)(-1);
160 CtdlLogPrintf(0, "RSS: fill encoding info ...\n");
162 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
163 cd = iconv_open ("UCS-2LE", charset);
165 cd = iconv_open ("UCS-2BE", charset);
168 if (cd == (iconv_t) (-1))
174 unsigned short out = 0;
175 unsigned char buf[4];
176 unsigned int i0, i1, i2;
179 for (i0 = 0; i0 < 0x100; i0++)
183 //result = try (cd, buf, 1, &out);
193 for (i1 = 0; i1 < 0x100; i1++)
196 ///result = try (cd, buf, 2, &out);
207 for (i2 = 0; i2 < 0x100; i2++)
210 ////result = try (cd, buf, 3, &out);
226 if (iconv_close (cd) < 0)
234 iconv_convertor (void *data, const char *s)
236 XML_Encoding *info = data;
238 CtdlLogPrintf(0, "RSS: Converting ...\n");
244 result = g_byte_array_new ();
245 if (process_block (info->data, (char *) s, strlen (s), result) == 0)
247 res = *(result->data);
248 g_byte_array_free (result, TRUE);
251 g_byte_array_free (result, TRUE);
257 my_release (void *data)
259 iconv_t cd = (iconv_t) data;
260 if (iconv_close (cd) != 0)
262 /// TODO: uh no. exit (1);
266 handle_unknown_xml_encoding (void *encodingHandleData,
267 const XML_Char * name,
271 CtdlLogPrintf(0, "RSS: unknown encoding ...\n");
272 result = fill_encoding_info (name, info);
276 Special case: client asked for reverse conversion, we'll provide him with
277 iconv descriptor which handles it. Client should release it by himself.
279 if(encodingHandleData != NULL)
280 *((iconv_t *)encodingHandleData) = iconv_open(name, "UTF-8");
282 Optimization: we do not need conversion function if encoding is one-to-one,
283 info->map table will be enough
288 info->convert = NULL;
289 info->release = NULL;
293 We do need conversion function because this encoding uses multibyte sequences
295 info->data = (void *) iconv_open ("UTF-8", name);
296 if ((int)info->data == -1)
298 info->convert = iconv_convertor;
299 info->release = my_release;
302 if(encodingHandleData != NULL)
303 *(iconv_t *)encodingHandleData = NULL;
309 size_t GetLocationString( void *ptr, size_t size, size_t nmemb, void *userdata)
311 #define LOCATION "location"
312 if (strncasecmp((char*)ptr, LOCATION, sizeof(LOCATION) - 1) == 0)
314 StrBuf *pURL = (StrBuf*) userdata;
315 char *pch = (char*) ptr;
318 pche = pch + (size * nmemb);
319 pch += sizeof(LOCATION);
321 while (isspace(*pch) || (*pch == ':'))
324 while (isspace(*pche) || (*pche == '\0'))
328 StrBufPlain(pURL, pch, pche - pch + 1);
333 int LookupUrl(StrBuf *ShorterUrlStr)
336 char errmsg[1024] = "";
340 curl = curl_easy_init();
342 CtdlLogPrintf(CTDL_ALERT, "Unable to initialize libcurl.\n");
345 Answer = NewStrBufPlain(NULL, SIZ);
347 curl_easy_setopt(curl, CURLOPT_URL, ChrPtr(ShorterUrlStr));
348 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
349 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
350 curl_easy_setopt(curl, CURLOPT_WRITEDATA, Answer);
351 // curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, rss_libcurl_callback);
352 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlFillStrBuf_callback);
353 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errmsg);
354 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
355 #ifdef CURLOPT_HTTP_CONTENT_DECODING
356 curl_easy_setopt(curl, CURLOPT_HTTP_CONTENT_DECODING, 1);
357 curl_easy_setopt(curl, CURLOPT_ENCODING, "");
359 curl_easy_setopt(curl, CURLOPT_USERAGENT, CITADEL);
360 curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180); /* die after 180 seconds */
361 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0);
363 curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION , GetLocationString);
364 curl_easy_setopt(curl, CURLOPT_WRITEHEADER, ShorterUrlStr);
368 (!IsEmptyStr(config.c_ip_addr))
369 && (strcmp(config.c_ip_addr, "*"))
370 && (strcmp(config.c_ip_addr, "::"))
371 && (strcmp(config.c_ip_addr, "0.0.0.0"))
373 curl_easy_setopt(curl, CURLOPT_INTERFACE, config.c_ip_addr);
376 if (CtdlThreadCheckStop())
379 rc = curl_easy_perform(curl);
381 CtdlLogPrintf(CTDL_ALERT, "libcurl error %d: %s\n", rc, errmsg);
388 curl_easy_cleanup(curl);
396 void CrawlMessageForShorterUrls(HashList *pUrls, StrBuf *Message)
405 while (GetHash(UrlShorteners, IKEY(nShorter), &pv))
408 pch = ChrPtr(Message);
409 pUrl = strstr(pch, ChrPtr((StrBuf*)pv));
410 while ((pUrl != NULL) && (nHits < 99))
412 pCUrl = malloc(sizeof(ConstStr));
415 pch = pUrl + StrLength((StrBuf*)pv);
416 while (isalnum(*pch)||(*pch == '-')||(*pch == '/'))
418 pCUrl->len = pch - pCUrl->Key;
420 Put(pUrls, IKEY(nHits), pCUrl, NULL);
422 pUrl = strstr(pch, ChrPtr((StrBuf*)pv));
427 int SortConstStrByPosition(const void *Item1, const void *Item2)
429 const ConstStr *p1, *p2;
430 p1 = (const ConstStr*) Item1;
431 p2 = (const ConstStr*) Item2;
432 if (p1->Key == p2->Key)
434 if (p1->Key > p2->Key)
439 void ExpandShortUrls(StrBuf *Message)
447 /* we just suspect URL shorteners to be inside of feeds from twitter
448 * or other short content messages, so don't crawl through real blogs.
450 if (StrLength(Message) > 500)
453 pUrls = NewHash(1, Flathash);
454 CrawlMessageForShorterUrls(pUrls, Message);
456 if (GetCount(pUrls) > 0)
458 StrBuf *ShorterUrlStr;
464 Shadow = NewStrBufPlain(NULL, StrLength(Message));
465 SortByPayload (pUrls, SortConstStrByPosition);
467 ShorterUrlStr = NewStrBufPlain(NULL, StrLength(Message));
469 pch = ChrPtr(Message);
470 pche = pch + StrLength(Message);
471 Pos = GetNewHashPos(pUrls, 1);
472 while (GetNextHashPos(pUrls, Pos, &len, &Key, &pv))
474 pCUrl = (ConstStr*) pv;
476 if (pch != pCUrl->Key)
477 StrBufAppendBufPlain(Shadow, pch, pCUrl->Key - pch, 0);
479 StrBufPlain(ShorterUrlStr, CKEY(*pCUrl));
480 if (LookupUrl(ShorterUrlStr))
482 StrBufAppendBufPlain(Shadow, HKEY("<a href=\""), 0);
483 StrBufAppendBuf(Shadow, ShorterUrlStr, 0);
484 StrBufAppendBufPlain(Shadow, HKEY("\">"), 0);
485 StrBufAppendBuf(Shadow, ShorterUrlStr, 0);
486 StrBufAppendBufPlain(Shadow, HKEY("["), 0);
487 StrBufAppendBufPlain(Shadow, pCUrl->Key, pCUrl->len, 0);
488 StrBufAppendBufPlain(Shadow, HKEY("]</a>"), 0);
492 StrBufAppendBufPlain(Shadow, HKEY("<a href=\""), 0);
493 StrBufAppendBufPlain(Shadow, pCUrl->Key, pCUrl->len, 0);
494 StrBufAppendBufPlain(Shadow, HKEY("\">"), 0);
495 StrBufAppendBufPlain(Shadow, pCUrl->Key, pCUrl->len, 0);
496 StrBufAppendBufPlain(Shadow, HKEY("</a>"), 0);
498 pch = pCUrl->Key + pCUrl->len + 1;
502 StrBufAppendBufPlain(Shadow, pch, pche - pch, 0);
503 FlushStrBuf(Message);
504 StrBufAppendBuf(Message, Shadow, 0);
506 FreeStrBuf(&ShorterUrlStr);
515 void AppendLink(StrBuf *Message, StrBuf *link, StrBuf *LinkTitle, const char *Title)
517 if (StrLength(link) > 0)
519 StrBufAppendBufPlain(Message, HKEY("<a href=\""), 0);
520 StrBufAppendBuf(Message, link, 0);
521 StrBufAppendBufPlain(Message, HKEY("\">"), 0);
522 if (StrLength(LinkTitle) > 0)
523 StrBufAppendBuf(Message, LinkTitle, 0);
524 else if ((Title != NULL) && !IsEmptyStr(Title))
525 StrBufAppendBufPlain(Message, Title, -1, 0);
527 StrBufAppendBuf(Message, link, 0);
528 StrBufAppendBufPlain(Message, HKEY("</a><br>\n"), 0);
532 * Commit a fetched and parsed RSS item to disk
534 void rss_save_item(rss_item *ri)
537 struct MD5Context md5context;
538 u_char rawdigest[MD5_DIGEST_LEN];
541 struct cdbdata *cdbut;
543 struct CtdlMessage *msg;
544 struct recptypes *recp = NULL;
548 recp = (struct recptypes *) malloc(sizeof(struct recptypes));
549 if (recp == NULL) return;
550 memset(recp, 0, sizeof(struct recptypes));
551 memset(&ut, 0, sizeof(struct UseTable));
552 recp->recp_room = strdup(ri->roomlist);
553 recp->num_room = num_tokens(ri->roomlist, '|');
554 recp->recptypes_magic = RECPTYPES_MAGIC;
556 /* Construct a GUID to use in the S_USETABLE table.
557 * If one is not present in the item itself, make one up.
559 if (ri->guid != NULL) {
560 StrBufSpaceToBlank(ri->guid);
561 StrBufTrim(ri->guid);
562 snprintf(utmsgid, sizeof utmsgid, "rss/%s", ChrPtr(ri->guid));
565 MD5Init(&md5context);
566 if (ri->title != NULL) {
567 MD5Update(&md5context, (const unsigned char*)ChrPtr(ri->title), StrLength(ri->title));
569 if (ri->link != NULL) {
570 MD5Update(&md5context, (const unsigned char*)ChrPtr(ri->link), StrLength(ri->link));
572 MD5Final(rawdigest, &md5context);
573 for (i=0; i<MD5_DIGEST_LEN; i++) {
574 sprintf(&utmsgid[i*2], "%02X", (unsigned char) (rawdigest[i] & 0xff));
575 utmsgid[i*2] = tolower(utmsgid[i*2]);
576 utmsgid[(i*2)+1] = tolower(utmsgid[(i*2)+1]);
578 strcat(utmsgid, "_rss2ctdl");
581 /* Find out if we've already seen this item */
583 cdbut = cdb_fetch(CDB_USETABLE, utmsgid, strlen(utmsgid));
586 /* Item has already been seen */
587 CtdlLogPrintf(CTDL_DEBUG, "%s has already been seen\n", utmsgid);
590 /* rewrite the record anyway, to update the timestamp */
591 strcpy(ut.ut_msgid, utmsgid);
592 ut.ut_timestamp = time(NULL);
593 cdb_store(CDB_USETABLE, utmsgid, strlen(utmsgid), &ut, sizeof(struct UseTable) );
598 /* Item has not been seen, so save it. */
599 CtdlLogPrintf(CTDL_DEBUG, "RSS: saving item...\n");
600 if (ri->description == NULL) ri->description = NewStrBufPlain(HKEY(""));
601 StrBufSpaceToBlank(ri->description);
602 msg = malloc(sizeof(struct CtdlMessage));
603 memset(msg, 0, sizeof(struct CtdlMessage));
604 msg->cm_magic = CTDLMESSAGE_MAGIC;
605 msg->cm_anon_type = MES_NORMAL;
606 msg->cm_format_type = FMT_RFC822;
608 if (ri->guid != NULL) {
609 msg->cm_fields['E'] = strdup(ChrPtr(ri->guid));
612 if (ri->author_or_creator != NULL) {
614 StrBuf *Encoded = NULL;
617 From = html_to_ascii(ChrPtr(ri->author_or_creator),
618 StrLength(ri->author_or_creator),
620 StrBufPlain(ri->author_or_creator, From, -1);
621 StrBufTrim(ri->author_or_creator);
624 FromAt = strchr(ChrPtr(ri->author_or_creator), '@') != NULL;
625 if (!FromAt && StrLength (ri->author_email) > 0)
627 StrBufRFC2047encode(&Encoded, ri->author_or_creator);
628 msg->cm_fields['A'] = SmashStrBuf(&Encoded);
629 msg->cm_fields['P'] = SmashStrBuf(&ri->author_email);
634 msg->cm_fields['P'] = SmashStrBuf(&ri->author_or_creator);
637 StrBufRFC2047encode(&Encoded, ri->author_or_creator);
638 msg->cm_fields['A'] = SmashStrBuf(&Encoded);
639 msg->cm_fields['P'] = strdup("rss@localhost");
644 msg->cm_fields['A'] = strdup("rss");
647 msg->cm_fields['N'] = strdup(NODENAME);
648 if (ri->title != NULL) {
651 StrBuf *Encoded, *QPEncoded;
654 StrBufSpaceToBlank(ri->title);
655 len = StrLength(ri->title);
656 Sbj = html_to_ascii(ChrPtr(ri->title), len, 512, 0);
658 if (Sbj[len - 1] == '\n')
663 Encoded = NewStrBufPlain(Sbj, len);
667 StrBufRFC2047encode(&QPEncoded, Encoded);
669 msg->cm_fields['U'] = SmashStrBuf(&QPEncoded);
670 FreeStrBuf(&Encoded);
672 msg->cm_fields['T'] = malloc(64);
673 snprintf(msg->cm_fields['T'], 64, "%ld", ri->pubdate);
674 if (ri->channel_title != NULL) {
675 if (StrLength(ri->channel_title) > 0) {
676 msg->cm_fields['O'] = strdup(ChrPtr(ri->channel_title));
679 if (ri->link == NULL)
680 ri->link = NewStrBufPlain(HKEY(""));
681 ExpandShortUrls(ri->description);
682 msglen += 1024 + StrLength(ri->link) + StrLength(ri->description) ;
684 Message = NewStrBufPlain(NULL, StrLength(ri->description));
686 StrBufPlain(Message, HKEY(
687 "Content-type: text/html; charset=\"UTF-8\"\r\n\r\n"
690 StrBufAppendBuf(Message, ri->description, 0);
691 StrBufAppendBufPlain(Message, HKEY("<br><br>\n"), 0);
693 AppendLink(Message, ri->link, ri->linkTitle, NULL);
694 AppendLink(Message, ri->reLink, ri->reLinkTitle, "Reply to this");
695 StrBufAppendBufPlain(Message, HKEY("</body></html>\n"), 0);
697 msg->cm_fields['M'] = SmashStrBuf(&Message);
699 CtdlSubmitMsg(msg, recp, NULL, 0);
700 CtdlFreeMessage(msg);
702 /* write the uidl to the use table so we don't store this item again */
703 strcpy(ut.ut_msgid, utmsgid);
704 ut.ut_timestamp = time(NULL);
705 cdb_store(CDB_USETABLE, utmsgid, strlen(utmsgid), &ut, sizeof(struct UseTable) );
707 free_recipients(recp);
713 * Convert an RDF/RSS datestamp into a time_t
715 time_t rdf_parsedate(const char *p)
721 if (strlen(p) < 10) return 0L;
723 memset(&tm, 0, sizeof tm);
726 * If the timestamp appears to be in W3C datetime format, try to
727 * parse it. See also: http://www.w3.org/TR/NOTE-datetime
729 * This code, along with parsedate.c, is a potential candidate for
730 * moving into libcitadel.
732 if ( (p[4] == '-') && (p[7] == '-') ) {
733 tm.tm_year = atoi(&p[0]) - 1900;
734 tm.tm_mon = atoi(&p[5]) - 1;
735 tm.tm_mday = atoi(&p[8]);
736 if ( (p[10] == 'T') && (p[13] == ':') ) {
737 tm.tm_hour = atoi(&p[11]);
738 tm.tm_min = atoi(&p[14]);
743 /* hmm... try RFC822 date stamp format */
746 if (t > 0) return(t);
748 /* yeesh. ok, just return the current date and time. */
752 void flush_rss_item(rss_item *ri)
754 /* Initialize the feed item data structure */
755 FreeStrBuf(&ri->guid);
756 FreeStrBuf(&ri->title);
757 FreeStrBuf(&ri->link);
758 FreeStrBuf(&ri->author_or_creator);
759 FreeStrBuf(&ri->author_email);
760 FreeStrBuf(&ri->author_url);
761 FreeStrBuf(&ri->description);
764 void rss_xml_start(void *data, const char *supplied_el, const char **attr)
767 rsscollection *rssc = (rsscollection*) data;
768 rssnetcfg *Cfg = rssc->Cfg;
769 rss_item *ri = rssc->Item;
774 /* Axe the namespace, we don't care about it */
775 /// CtdlLogPrintf(0, "RSS: supplied el %d: %s...\n", rssc->Cfg->ItemType, supplied_el);
777 while (sep = strchr(pel, ':'), sep) {
781 if (pel != supplied_el)
785 if (!GetHash(KnownNameSpaces,
787 pel - supplied_el - 1,
791 CtdlLogPrintf(0, "RSS: START ignoring because of wrong namespace [%s] = [%s]\n",
798 StrBufPlain(rssc->Key, pel, -1);
799 StrBufLowerCase(rssc->Key);
800 if (GetHash(StartHandlers, SKEY(rssc->Key), &pv))
802 rssc->Current = h = (rss_xml_handler*) pv;
804 if (((h->Flags & RSS_UNSET) != 0) &&
805 (Cfg->ItemType == RSS_UNSET))
807 h->Handler(rssc->CData, ri, Cfg, attr);
809 else if (((h->Flags & RSS_RSS) != 0) &&
810 (Cfg->ItemType == RSS_RSS))
812 h->Handler(rssc->CData, ri, Cfg, attr);
814 else if (((h->Flags & RSS_ATOM) != 0) &&
815 (Cfg->ItemType == RSS_ATOM))
817 h->Handler(rssc->CData, ri, Cfg, attr);
821 CtdlLogPrintf(0, "RSS: START unhandled: [%s] [%s]...\n", pel, supplied_el);
826 CtdlLogPrintf(0, "RSS: START unhandled: [%s] [%s]...\n", pel, supplied_el);
830 void rss_xml_end(void *data, const char *supplied_el)
833 rsscollection *rssc = (rsscollection*) data;
834 rssnetcfg *Cfg = rssc->Cfg;
835 rss_item *ri = rssc->Item;
840 /* Axe the namespace, we don't care about it */
842 while (sep = strchr(pel, ':'), sep) {
845 // CtdlLogPrintf(0, "RSS: END %s...\n", el);
846 if (pel != supplied_el)
850 if (!GetHash(KnownNameSpaces,
852 pel - supplied_el - 1,
856 CtdlLogPrintf(0, "RSS: END ignoring because of wrong namespace [%s] = [%s]\n",
857 supplied_el, ChrPtr(rssc->CData));
859 FlushStrBuf(rssc->CData);
864 StrBufPlain(rssc->Key, pel, -1);
865 StrBufLowerCase(rssc->Key);
866 if (GetHash(EndHandlers, SKEY(rssc->Key), &pv))
868 h = (rss_xml_handler*) pv;
870 if (((h->Flags & RSS_UNSET) != 0) &&
871 (Cfg->ItemType == RSS_UNSET))
873 h->Handler(rssc->CData, ri, Cfg, NULL);
875 else if (((h->Flags & RSS_RSS) != 0) &&
876 (Cfg->ItemType == RSS_RSS))
878 h->Handler(rssc->CData, ri, Cfg, NULL);
880 else if (((h->Flags & RSS_ATOM) != 0) &&
881 (Cfg->ItemType == RSS_ATOM))
883 h->Handler(rssc->CData, ri, Cfg, NULL);
887 CtdlLogPrintf(0, "RSS: END unhandled: [%s] [%s] = [%s]...\n", pel, supplied_el, ChrPtr(rssc->CData));
892 CtdlLogPrintf(0, "RSS: END unhandled: [%s] [%s] = [%s]...\n", pel, supplied_el, ChrPtr(rssc->CData));
894 FlushStrBuf(rssc->CData);
895 rssc->Current = NULL;
902 void RSS_item_rss_start (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
904 CtdlLogPrintf(CTDL_DEBUG, "RSS: This is an RSS feed.\n");
905 Cfg->ItemType = RSS_RSS;
908 void RSS_item_rdf_start(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
910 CtdlLogPrintf(CTDL_DEBUG, "RSS: This is an RDF feed.\n");
911 Cfg->ItemType = RSS_RSS;
914 void ATOM_item_feed_start(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
916 CtdlLogPrintf(CTDL_DEBUG, "RSS: This is an ATOM feed.\n");
917 Cfg->ItemType = RSS_ATOM;
921 void RSS_item_item_start(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
923 ri->item_tag_nesting ++;
927 void ATOM_item_entry_start(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
930 ri->item_tag_nesting ++;
934 void ATOM_item_link_start (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
937 const char *pHref = NULL;
938 const char *pType = NULL;
939 const char *pRel = NULL;
940 const char *pTitle = NULL;
942 for (i = 0; Attr[i] != NULL; i+=2)
944 if (!strcmp(Attr[i], "href"))
948 else if (!strcmp(Attr[i], "rel"))
952 else if (!strcmp(Attr[i], "type"))
956 else if (!strcmp(Attr[i], "title"))
962 return; /* WHUT? Pointing... where? */
963 if ((pType != NULL) && !strcasecmp(pType, "application/atom+xml"))
964 return; /* these just point to other rss resources, we're not interested in them. */
967 if (!strcasecmp (pRel, "replies"))
969 NewStrBufDupAppendFlush(&ri->reLink, NULL, pHref, -1);
970 StrBufTrim(ri->link);
971 NewStrBufDupAppendFlush(&ri->reLinkTitle, NULL, pTitle, -1);
973 else if (!strcasecmp(pRel, "alternate")) /* Alternative representation of this Item... */
975 NewStrBufDupAppendFlush(&ri->link, NULL, pHref, -1);
976 StrBufTrim(ri->link);
977 NewStrBufDupAppendFlush(&ri->linkTitle, NULL, pTitle, -1);
980 #if 0 /* these are also defined, but dunno what to do with them.. */
981 else if (!strcasecmp(pRel, "related"))
984 else if (!strcasecmp(pRel, "self"))
987 else if (!strcasecmp(pRel, "enclosure"))
988 {/* this reference can get big, and is probably the full article... */
990 else if (!strcasecmp(pRel, "via"))
991 {/* this article was provided via... */
995 else if (StrLength(ri->link) == 0)
997 NewStrBufDupAppendFlush(&ri->link, NULL, pHref, -1);
998 StrBufTrim(ri->link);
999 NewStrBufDupAppendFlush(&ri->linkTitle, NULL, pTitle, -1);
1006 void ATOMRSS_item_title_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1008 if ((ri->item_tag_nesting == 0) && (StrLength(CData) > 0)) {
1009 NewStrBufDupAppendFlush(&ri->channel_title, CData, NULL, 0);
1010 StrBufTrim(ri->channel_title);
1014 void RSS_item_guid_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1016 if (StrLength(CData) > 0) {
1017 NewStrBufDupAppendFlush(&ri->guid, CData, NULL, 0);
1021 void ATOM_item_id_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1023 if (StrLength(CData) > 0) {
1024 NewStrBufDupAppendFlush(&ri->guid, CData, NULL, 0);
1029 void RSS_item_link_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1031 if (StrLength(CData) > 0) {
1032 NewStrBufDupAppendFlush(&ri->link, CData, NULL, 0);
1033 StrBufTrim(ri->link);
1036 void RSS_item_relink_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1038 if (StrLength(CData) > 0) {
1039 NewStrBufDupAppendFlush(&ri->reLink, CData, NULL, 0);
1040 StrBufTrim(ri->reLink);
1044 void RSSATOM_item_title_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1046 if (StrLength(CData) > 0) {
1047 NewStrBufDupAppendFlush(&ri->title, CData, NULL, 0);
1048 StrBufTrim(ri->title);
1052 void ATOM_item_content_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1054 long olen = StrLength (ri->description);
1055 long clen = StrLength (CData);
1059 NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
1060 StrBufTrim(ri->description);
1062 else if (olen < clen) {
1063 FlushStrBuf(ri->description);
1064 NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
1065 StrBufTrim(ri->description);
1069 void ATOM_item_summary_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1071 /* this can contain an abstract of the article. but we don't want to verwrite a full document if we already have it. */
1072 if ((StrLength(CData) > 0) && (StrLength(ri->description) == 0))
1074 NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
1075 StrBufTrim(ri->description);
1079 void RSS_item_description_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1081 long olen = StrLength (ri->description);
1082 long clen = StrLength (CData);
1086 NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
1087 StrBufTrim(ri->description);
1089 else if (olen < clen) {
1090 FlushStrBuf(ri->description);
1091 NewStrBufDupAppendFlush(&ri->description, CData, NULL, 0);
1092 StrBufTrim(ri->description);
1097 void ATOM_item_published_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1099 if (StrLength(CData) > 0) {
1101 ri->pubdate = rdf_parsedate(ChrPtr(CData));
1105 void ATOM_item_updated_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1107 if (StrLength(CData) > 0) {
1109 ri->pubdate = rdf_parsedate(ChrPtr(CData));
1113 void RSS_item_pubdate_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1115 if (StrLength(CData) > 0) {
1117 ri->pubdate = rdf_parsedate(ChrPtr(CData));
1122 void RSS_item_date_end (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1124 if (StrLength(CData) > 0) {
1126 ri->pubdate = rdf_parsedate(ChrPtr(CData));
1132 void RSS_item_author_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1134 if (StrLength(CData) > 0) {
1135 NewStrBufDupAppendFlush(&ri->author_or_creator, CData, NULL, 0);
1136 StrBufTrim(ri->author_or_creator);
1141 void ATOM_item_name_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1143 if (StrLength(CData) > 0) {
1144 NewStrBufDupAppendFlush(&ri->author_or_creator, CData, NULL, 0);
1145 StrBufTrim(ri->author_or_creator);
1149 void ATOM_item_email_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1151 if (StrLength(CData) > 0) {
1152 NewStrBufDupAppendFlush(&ri->author_email, CData, NULL, 0);
1153 StrBufTrim(ri->author_email);
1157 void RSS_item_creator_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1159 if ((StrLength(CData) > 0) &&
1160 (StrLength(ri->author_or_creator) == 0))
1162 NewStrBufDupAppendFlush(&ri->author_or_creator, CData, NULL, 0);
1163 StrBufTrim(ri->author_or_creator);
1168 void ATOM_item_uri_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1170 if (StrLength(CData) > 0) {
1171 NewStrBufDupAppendFlush(&ri->author_url, CData, NULL, 0);
1172 StrBufTrim(ri->author_url);
1176 void RSS_item_item_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1178 --ri->item_tag_nesting;
1183 void ATOM_item_entry_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1185 --ri->item_tag_nesting;
1189 void RSS_item_rss_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1191 // CtdlLogPrintf(CTDL_DEBUG, "End of feed detected. Closing parser.\n");
1192 ri->done_parsing = 1;
1195 void RSS_item_rdf_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1197 // CtdlLogPrintf(CTDL_DEBUG, "End of feed detected. Closing parser.\n");
1198 ri->done_parsing = 1;
1202 void RSSATOM_item_ignore(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
1209 * This callback stores up the data which appears in between tags.
1211 void rss_xml_cdata_start(void *data)
1213 rsscollection *rssc = (rsscollection*) data;
1215 FlushStrBuf(rssc->CData);
1218 void rss_xml_cdata_end(void *data)
1221 void rss_xml_chardata(void *data, const XML_Char *s, int len)
1223 rsscollection *rssc = (rsscollection*) data;
1225 StrBufAppendBufPlain (rssc->CData, s, len, 0);
1229 * Callback function for passing libcurl's output to expat for parsing
1231 size_t rss_libcurl_callback(void *ptr, size_t size, size_t nmemb, void *stream)
1233 XML_Parse((XML_Parser)stream, ptr, (size * nmemb), 0);
1234 return (size*nmemb);
1240 * Begin a feed parse
1242 void rss_do_fetching(rssnetcfg *Cfg) {
1245 XML_Parser xp = NULL;
1250 char errmsg[1024] = "";
1255 memset(&ri, 0, sizeof(rss_item));
1259 CtdlLogPrintf(CTDL_DEBUG, "Fetching RSS feed <%s>\n", Cfg->url);
1261 curl = curl_easy_init();
1263 CtdlLogPrintf(CTDL_ALERT, "Unable to initialize libcurl.\n");
1266 Answer = NewStrBufPlain(NULL, SIZ);
1268 curl_easy_setopt(curl, CURLOPT_URL, Cfg->url);
1269 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
1270 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
1271 curl_easy_setopt(curl, CURLOPT_WRITEDATA, Answer);
1272 // curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, rss_libcurl_callback);
1273 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlFillStrBuf_callback);
1274 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errmsg);
1275 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
1276 #ifdef CURLOPT_HTTP_CONTENT_DECODING
1277 curl_easy_setopt(curl, CURLOPT_HTTP_CONTENT_DECODING, 1);
1278 curl_easy_setopt(curl, CURLOPT_ENCODING, "");
1280 curl_easy_setopt(curl, CURLOPT_USERAGENT, CITADEL);
1281 curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180); /* die after 180 seconds */
1283 (!IsEmptyStr(config.c_ip_addr))
1284 && (strcmp(config.c_ip_addr, "*"))
1285 && (strcmp(config.c_ip_addr, "::"))
1286 && (strcmp(config.c_ip_addr, "0.0.0.0"))
1288 curl_easy_setopt(curl, CURLOPT_INTERFACE, config.c_ip_addr);
1291 if (CtdlThreadCheckStop())
1293 curl_easy_cleanup(curl);
1297 if (CtdlThreadCheckStop())
1300 res = curl_easy_perform(curl);
1302 CtdlLogPrintf(CTDL_ALERT, "libcurl error %d: %s\n", res, errmsg);
1305 if (CtdlThreadCheckStop())
1311 memset(&ri, 0, sizeof(rss_item));
1312 ri.roomlist = Cfg->rooms;
1313 rssc.CData = NewStrBufPlain(NULL, SIZ);
1314 rssc.Key = NewStrBuf();
1316 StrBufSipLine(rssc.Key, Answer, &at);
1319 #define encoding "encoding=\""
1320 ptr = strstr(ChrPtr(rssc.Key), encoding);
1325 ptr += sizeof (encoding) - 1;
1326 pche = strchr(ptr, '"');
1328 StrBufCutAt(rssc.Key, -1, pche);
1336 xp = XML_ParserCreateNS(ptr, ':');
1338 CtdlLogPrintf(CTDL_ALERT, "Cannot create XML parser!\n");
1341 FlushStrBuf(rssc.Key);
1344 XML_SetUnknownEncodingHandler(xp,
1345 handle_unknown_xml_encoding,
1349 XML_SetElementHandler(xp, rss_xml_start, rss_xml_end);
1350 XML_SetCharacterDataHandler(xp, rss_xml_chardata);
1351 XML_SetUserData(xp, &rssc);
1352 XML_SetCdataSectionHandler(xp,
1353 rss_xml_cdata_start,
1357 len = StrLength(Answer);
1358 ptr = SmashStrBuf(&Answer);
1359 XML_Parse(xp, ptr, len, 0);
1361 if (ri.done_parsing == 0)
1362 XML_Parse(xp, "", 0, 1);
1365 CtdlLogPrintf(CTDL_ALERT, "RSS: XML Status [%s] \n",
1367 XML_GetErrorCode(xp)));
1370 curl_easy_cleanup(curl);
1373 flush_rss_item(&ri);
1374 FreeStrBuf(&rssc.CData);
1375 FreeStrBuf(&rssc.Key);
1380 * Scan a room's netconfig to determine whether it is requesting any RSS feeds
1382 void rssclient_scan_room(struct ctdlroom *qrbuf, void *data)
1384 char filename[PATH_MAX];
1389 rssnetcfg *rncptr = NULL;
1390 rssnetcfg *use_this_rncptr = NULL;
1394 assoc_file_name(filename, sizeof filename, qrbuf, ctdl_netcfg_dir);
1396 if (CtdlThreadCheckStop())
1399 /* Only do net processing for rooms that have netconfigs */
1400 fp = fopen(filename, "r");
1405 while (fgets(buf, sizeof buf, fp) != NULL && !CtdlThreadCheckStop()) {
1406 buf[strlen(buf)-1] = 0;
1408 extract_token(instr, buf, 0, '|', sizeof instr);
1409 if (!strcasecmp(instr, "rssclient")) {
1411 use_this_rncptr = NULL;
1413 extract_token(feedurl, buf, 1, '|', sizeof feedurl);
1415 /* If any other rooms have requested the same feed, then we will just add this
1416 * room to the target list for that client request.
1418 for (rncptr=rnclist; rncptr!=NULL; rncptr=rncptr->next) {
1419 if (!strcmp(rncptr->url, feedurl)) {
1420 use_this_rncptr = rncptr;
1424 /* Otherwise create a new client request */
1425 if (use_this_rncptr == NULL) {
1426 rncptr = (rssnetcfg *) malloc(sizeof(rssnetcfg));
1427 rncptr->ItemType = RSS_UNSET;
1428 if (rncptr != NULL) {
1429 rncptr->next = rnclist;
1430 safestrncpy(rncptr->url, feedurl, sizeof rncptr->url);
1431 rncptr->rooms = NULL;
1433 use_this_rncptr = rncptr;
1437 /* Add the room name to the request */
1438 if (use_this_rncptr != NULL) {
1439 if (use_this_rncptr->rooms == NULL) {
1440 rncptr->rooms = strdup(qrbuf->QRname);
1443 len = strlen(use_this_rncptr->rooms) + strlen(qrbuf->QRname) + 5;
1444 ptr = realloc(use_this_rncptr->rooms, len);
1447 strcat(ptr, qrbuf->QRname);
1448 use_this_rncptr->rooms = ptr;
1461 * Scan for rooms that have RSS client requests configured
1463 void rssclient_scan(void) {
1464 static time_t last_run = 0L;
1465 static int doing_rssclient = 0;
1466 rssnetcfg *rptr = NULL;
1469 * This is a simple concurrency check to make sure only one rssclient run
1470 * is done at a time. We could do this with a mutex, but since we
1471 * don't really require extremely fine granularity here, we'll do it
1472 * with a static variable instead.
1474 if (doing_rssclient) return;
1475 doing_rssclient = 1;
1477 CtdlLogPrintf(CTDL_DEBUG, "rssclient started\n");
1478 CtdlForEachRoom(rssclient_scan_room, NULL);
1480 while (rnclist != NULL && !CtdlThreadCheckStop()) {
1481 rss_do_fetching(rnclist);
1483 rnclist = rnclist->next;
1484 if (rptr->rooms != NULL) free(rptr->rooms);
1488 CtdlLogPrintf(CTDL_DEBUG, "rssclient ended\n");
1489 last_run = time(NULL);
1490 doing_rssclient = 0;
1494 void LoadUrlShorteners(void)
1498 const char *POS = NULL;
1499 const char *Err = NULL;
1500 StrBuf *Content, *Line;
1503 UrlShorteners = NewHash(0, Flathash);
1505 fd = open(file_citadel_urlshorteners, 0);
1509 Content = NewStrBufPlain(NULL, SIZ);
1511 while (POS != StrBufNOTNULL)
1513 StrBufTCP_read_buffered_line_fast (Line, Content, &POS, &fd, 1, 1, &Err);
1515 if ((*ChrPtr(Line) != '#') && (StrLength(Line) > 0))
1517 Put(UrlShorteners, IKEY(i), Line, HFreeStrBuf);
1524 POS = StrBufNOTNULL;
1527 FreeStrBuf(&Content);
1532 CTDL_MODULE_INIT(rssclient)
1536 CtdlLogPrintf(CTDL_INFO, "%s\n", curl_version());
1537 CtdlRegisterSessionHook(rssclient_scan, EVT_TIMER);
1541 LoadUrlShorteners ();
1543 StartHandlers = NewHash(1, NULL);
1544 EndHandlers = NewHash(1, NULL);
1546 AddRSSStartHandler(RSS_item_rss_start, RSS_UNSET, HKEY("rss"));
1547 AddRSSStartHandler(RSS_item_rdf_start, RSS_UNSET, HKEY("rdf"));
1548 AddRSSStartHandler(ATOM_item_feed_start, RSS_UNSET, HKEY("feed"));
1549 AddRSSStartHandler(RSS_item_item_start, RSS_RSS, HKEY("item"));
1550 AddRSSStartHandler(ATOM_item_entry_start, RSS_ATOM, HKEY("entry"));
1551 AddRSSStartHandler(ATOM_item_link_start, RSS_ATOM, HKEY("link"));
1553 AddRSSEndHandler(ATOMRSS_item_title_end, RSS_ATOM|RSS_RSS|RSS_REQUIRE_BUF, HKEY("title"));
1554 AddRSSEndHandler(RSS_item_guid_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("guid"));
1555 AddRSSEndHandler(ATOM_item_id_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("id"));
1556 AddRSSEndHandler(RSS_item_link_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("link"));
1558 // hm, rss to the comments of that blog, might be interesting in future, but...
1559 AddRSSEndHandler(RSS_item_relink_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("commentrss"));
1561 AddRSSEndHandler(RSS_item_relink_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("comments"));
1563 AddRSSEndHandler(RSSATOM_item_title_end, RSS_ATOM|RSS_RSS|RSS_REQUIRE_BUF, HKEY("title"));
1564 AddRSSEndHandler(ATOM_item_content_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("content"));
1565 AddRSSEndHandler(RSS_item_description_end, RSS_RSS|RSS_ATOM|RSS_REQUIRE_BUF, HKEY("encoded"));
1566 AddRSSEndHandler(ATOM_item_summary_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("summary"));
1567 AddRSSEndHandler(RSS_item_description_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("description"));
1568 AddRSSEndHandler(ATOM_item_published_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("published"));
1569 AddRSSEndHandler(ATOM_item_updated_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("updated"));
1570 AddRSSEndHandler(RSS_item_pubdate_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("pubdate"));
1571 AddRSSEndHandler(RSS_item_date_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("date"));
1572 AddRSSEndHandler(RSS_item_author_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("author"));
1573 AddRSSEndHandler(RSS_item_creator_end, RSS_RSS|RSS_REQUIRE_BUF, HKEY("creator"));
1575 AddRSSEndHandler(ATOM_item_email_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("email"));
1576 AddRSSEndHandler(ATOM_item_name_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("name"));
1577 AddRSSEndHandler(ATOM_item_uri_end, RSS_ATOM|RSS_REQUIRE_BUF, HKEY("uri"));
1579 AddRSSEndHandler(RSS_item_item_end, RSS_RSS, HKEY("item"));
1580 AddRSSEndHandler(RSS_item_rss_end, RSS_RSS, HKEY("rss"));
1581 AddRSSEndHandler(RSS_item_rdf_end, RSS_RSS, HKEY("rdf"));
1582 AddRSSEndHandler(ATOM_item_entry_end, RSS_ATOM, HKEY("entry"));
1585 /* at the start of atoms: <seq> <li>link to resource</li></seq> ignore them. */
1586 AddRSSStartHandler(RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("seq"));
1587 AddRSSEndHandler (RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("seq"));
1588 AddRSSStartHandler(RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("li"));
1589 AddRSSEndHandler (RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("li"));
1591 /* links to other feed generators... */
1592 AddRSSStartHandler(RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("feedflare"));
1593 AddRSSEndHandler (RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("feedflare"));
1594 AddRSSStartHandler(RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("browserfriendly"));
1595 AddRSSEndHandler (RSSATOM_item_ignore, RSS_RSS|RSS_ATOM, HKEY("browserfriendly"));
1597 KnownNameSpaces = NewHash(1, NULL);
1598 Put(KnownNameSpaces, HKEY("http://a9.com/-/spec/opensearch/1.1/"), NULL, reference_free_handler);
1599 Put(KnownNameSpaces, HKEY("http://a9.com/-/spec/opensearchrss/1.0/"), NULL, reference_free_handler);
1600 Put(KnownNameSpaces, HKEY("http://backend.userland.com/creativeCommonsRssModule"), NULL, reference_free_handler);
1601 Put(KnownNameSpaces, HKEY("http://purl.org/atom/ns#"), NULL, reference_free_handler);
1602 Put(KnownNameSpaces, HKEY("http://purl.org/dc/elements/1.1/"), NULL, reference_free_handler);
1603 Put(KnownNameSpaces, HKEY("http://purl.org/rss/1.0/"), NULL, reference_free_handler);
1604 Put(KnownNameSpaces, HKEY("http://purl.org/rss/1.0/modules/content/"), NULL, reference_free_handler);
1605 Put(KnownNameSpaces, HKEY("http://purl.org/rss/1.0/modules/slash/"), NULL, reference_free_handler);
1606 Put(KnownNameSpaces, HKEY("http://purl.org/rss/1.0/modules/syndication/"), NULL, reference_free_handler);
1607 Put(KnownNameSpaces, HKEY("http://purl.org/rss/1.0/"), NULL, reference_free_handler);
1608 Put(KnownNameSpaces, HKEY("http://purl.org/syndication/thread/1.0"), NULL, reference_free_handler);
1609 Put(KnownNameSpaces, HKEY("http://rssnamespace.org/feedburner/ext/1.0"), NULL, reference_free_handler);
1610 Put(KnownNameSpaces, HKEY("http://schemas.google.com/g/2005"), NULL, reference_free_handler);
1611 Put(KnownNameSpaces, HKEY("http://webns.net/mvcb/"), NULL, reference_free_handler);
1612 Put(KnownNameSpaces, HKEY("http://web.resource.org/cc/"), NULL, reference_free_handler);
1613 Put(KnownNameSpaces, HKEY("http://wellformedweb.org/CommentAPI/"), NULL, reference_free_handler);
1614 Put(KnownNameSpaces, HKEY("http://www.georss.org/georss"), NULL, reference_free_handler);
1615 Put(KnownNameSpaces, HKEY("http://www.w3.org/1999/xhtml"), NULL, reference_free_handler);
1616 Put(KnownNameSpaces, HKEY("http://www.w3.org/1999/02/22-rdf-syntax-ns#"), NULL, reference_free_handler);
1617 Put(KnownNameSpaces, HKEY("http://www.w3.org/1999/02/22-rdf-syntax-ns#"), NULL, reference_free_handler);
1618 Put(KnownNameSpaces, HKEY("http://www.w3.org/2003/01/geo/wgs84_pos#"), NULL, reference_free_handler);
1619 Put(KnownNameSpaces, HKEY("http://www.w3.org/2005/Atom"), NULL, reference_free_handler);
1620 Put(KnownNameSpaces, HKEY("urn:flickr:"), NULL, reference_free_handler);
1622 /* we don't like these namespaces because of they shadow our usefull parameters. */
1623 Put(KnownNameSpaces, HKEY("http://search.yahoo.com/mrss/"), NULL, reference_free_handler);