X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Frssclient%2Fserv_rssclient.c;h=ca05dd62d5067d619f77e030bf797b11a9b450a4;hb=0387f48886a9395d89eaca01cd40ab751610426f;hp=4a2c4f6471e5614cb09631271484eaa81bc7dee5;hpb=57741a679f45ad92aaead204023c266e32675580;p=citadel.git
diff --git a/citadel/modules/rssclient/serv_rssclient.c b/citadel/modules/rssclient/serv_rssclient.c
index 4a2c4f647..ca05dd62d 100644
--- a/citadel/modules/rssclient/serv_rssclient.c
+++ b/citadel/modules/rssclient/serv_rssclient.c
@@ -1,14 +1,16 @@
/*
- * Bring external RSS feeds into rooms.
+ * Bring external RSS and/or Atom feeds into rooms. This module implements a
+ * very loose parser that scrapes both kinds of feeds and is not picky about
+ * the standards compliance of the source data.
*
- * Copyright (c) 2007-2017 by the citadel.org team
+ * Copyright (c) 2007-2020 by the citadel.org team
*
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3.
+ * This program is open source software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
@@ -46,8 +48,8 @@
#include "parsedate.h"
#include "database.h"
#include "citadel_dirs.h"
-#include "md5.h"
#include "context.h"
+#include "internet_addressing.h"
struct rssroom {
struct rssroom *next;
@@ -65,25 +67,14 @@ struct rssparser {
struct CtdlMessage *msg;
char *link;
char *description;
+ char *item_id;
struct rssroom *rooms;
};
time_t last_run = 0L;
-struct CitContext rss_CC;
struct rssurl *rsstodo = NULL;
-// This is what RSS probably looks like
-//
-//
-//
-// http://video.foxnews.com/v/5336254459001/
-// foxnewsonline@foxnews.com (Fox News Online)
-//
-// Sat, 25 Feb 2017 14:28:01 EST
-//
-
-
// This handler is called whenever an XML tag opens.
//
void rss_start_element(void *data, const char *el, const char **attribute)
@@ -127,74 +118,130 @@ void rss_start_element(void *data, const char *el, const char **attribute)
void rss_end_element(void *data, const char *el)
{
struct rssparser *r = (struct rssparser *)data;
+ StrBuf *encoded_field;
+
+ if (StrLength(r->CData) > 0) { // strip leading/trailing whitespace from field
+ StrBufTrim(r->CData);
+ }
if ( // end of a new item(rss) or entry(atom)
(!strcasecmp(el, "entry"))
|| (!strcasecmp(el, "item"))
) {
-
if (r->msg != NULL) { // Save the message to the rooms
- // FIXME check the use table
+ // use the link as an item id if nothing else is available
+ if ((r->item_id == NULL) && (r->link != NULL)) {
+ r->item_id = strdup(r->link);
+ }
- StrBuf *TheMessage = NewStrBuf();
- StrBufAppendPrintf(TheMessage,
- "Content-type: text/html\n\n"
- "\n\n"
- "
"
- );
+ // check the use table
+ StrBuf *u = NewStrBuf();
+ StrBufAppendPrintf(u, "rss/%s", r->item_id);
+ int already_seen = CheckIfAlreadySeen(u);
+ FreeStrBuf(&u);
+
+ if (already_seen == 0) {
+
+ // Compose the message text
+ StrBuf *TheMessage = NewStrBuf();
+ StrBufAppendPrintf(TheMessage,
+ "Content-type: text/html\n\n"
+ "\n\n"
+ ""
+ );
+
+ if (r->description != NULL) {
+ StrBufAppendPrintf(TheMessage, "%s