X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Frssclient%2Fserv_rssclient.c;h=11ffb905f138de66eb3b8525ab89b543155867a6;hb=c71df26b9d35c07eb9c1322a7e83caa86337ad82;hp=3435eb4dd213aa42b598195113db1697e80e49a7;hpb=071e4147f7ecb35864e14a433428d5980f911725;p=citadel.git
diff --git a/citadel/modules/rssclient/serv_rssclient.c b/citadel/modules/rssclient/serv_rssclient.c
index 3435eb4dd..11ffb905f 100644
--- a/citadel/modules/rssclient/serv_rssclient.c
+++ b/citadel/modules/rssclient/serv_rssclient.c
@@ -1,7 +1,9 @@
/*
- * 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-2018 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.
@@ -48,6 +50,7 @@
#include "citadel_dirs.h"
#include "md5.h"
#include "context.h"
+#include "internet_addressing.h"
struct rssroom {
struct rssroom *next;
@@ -63,29 +66,22 @@ struct rssurl {
struct rssparser {
StrBuf *CData;
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)
{
struct rssparser *r = (struct rssparser *)data;
+ int i;
if (
(!strcasecmp(el, "entry"))
@@ -102,6 +98,19 @@ void rss_start_element(void *data, const char *el, const char **attribute)
r->msg->cm_anon_type = MES_NORMAL;
r->msg->cm_format_type = FMT_RFC822;
}
+
+ else if (!strcasecmp(el, "link")) { // atom feeds have the link as an attribute
+ for(i = 0; attribute[i]; i += 2) {
+ if (!strcasecmp(attribute[i], "href")) {
+ if (r->link != NULL) {
+ free(r->link);
+ r->link = NULL;
+ }
+ r->link = strdup(attribute[i+1]);
+ striplt(r->link);
+ }
+ }
+ }
}
@@ -116,33 +125,151 @@ void rss_end_element(void *data, const char *el)
|| (!strcasecmp(el, "item"))
) {
- // FIXME check the use table
+ if (r->msg != NULL) { // Save the message to the rooms
- if (r->msg != NULL) {
- // FIXME WRITE IT TO THE ROOMS HERE, DUMMEH
+ // 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);
+ }
+
+ // 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"
+ "