-/*
- * 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-2022 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 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
- * GNU General Public License for more details.
- */
+// 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-2023 by the citadel.org team
+//
+// This program is open source software. Use, duplication, or disclosure
+// is subject to the terms of the GNU General Public License, version 3.
#include <stdlib.h>
#include <unistd.h>
// 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;
r->link = NULL;
}
r->link = strdup(attribute[i+1]);
- striplt(r->link);
+ string_trim(r->link);
}
}
}
// This handler is called whenever an XML tag closes.
-//
void rss_end_element(void *data, const char *el) {
struct rssparser *r = (struct rssparser *)data;
StrBuf *encoded_field;
if (already_seen == 0) {
// Compose the message text
+ // FIXME ajc 2023jan06 - this can create lines longer than 1024 characters which chokes the client message parsers
StrBuf *TheMessage = NewStrBuf();
StrBufAppendPrintf(TheMessage,
"Content-type: text/html\n\n"
"\n\n"
"<html><head></head><body>"
);
-
+
if (r->description != NULL) {
StrBufAppendPrintf(TheMessage, "%s<br><br>\r\n", r->description);
free(r->description);
r->description = NULL;
}
-
+
if (r->link != NULL) {
StrBufAppendPrintf(TheMessage, "<a href=\"%s\">%s</a>\r\n", r->link, r->link);
free(r->link);
r->link = NULL;
}
-
+
StrBufAppendPrintf(TheMessage, "</body></html>\r\n");
CM_SetField(r->msg, eMesageText, ChrPtr(TheMessage), StrLength(TheMessage));
FreeStrBuf(&TheMessage);
-
+
if (CM_IsEmpty(r->msg, eAuthor)) {
CM_SetField(r->msg, eAuthor, HKEY("rss"));
}
-
+
if (CM_IsEmpty(r->msg, eTimestamp)) {
CM_SetFieldLONG(r->msg, eTimestamp, time(NULL));
}
-
+
// Save it to the room(s)
struct rssroom *rr = NULL;
long msgnum = (-1);
else {
syslog(LOG_DEBUG, "rssclient: already seen %s", r->item_id);
}
-
+
CM_Free(r->msg);
r->msg = NULL;
}
// This handler is called whenever data appears between opening and closing tags.
-//
-void rss_handle_data(void *data, const char *content, int length)
-{
+void rss_handle_data(void *data, const char *content, int length) {
struct rssparser *r = (struct rssparser *)data;
if (r->CData == NULL) {
// Feed has been downloaded, now parse it.
-//
-void rss_parse_feed(StrBuf *Feed, struct rssroom *rooms)
-{
+void rss_parse_feed(StrBuf *Feed, struct rssroom *rooms) {
struct rssparser r;
memset(&r, 0, sizeof r);
// Add a feed/room pair into the todo list
-//
-void rssclient_push_todo(char *rssurl, char *roomname)
-{
+void rssclient_push_todo(char *rssurl, char *roomname) {
struct rssurl *r = NULL;
struct rssurl *thisone = NULL;
struct rssroom *newroom = NULL;
// pull one feed (possibly multiple rooms)
-//
-void rss_pull_one_feed(struct rssurl *url)
-{
+void rss_pull_one_feed(struct rssurl *url) {
CURL *curl;
CURLcode res;
StrBuf *Downloaded = NULL;
// We have a list, now download the feeds
-//
-void rss_pull_feeds(void)
-{
+void rss_pull_feeds(void) {
struct rssurl *r;
struct rssroom *rr;
// Scan a room's netconfig looking for RSS feed parsing requests
-//
-void rssclient_scan_room(struct ctdlroom *qrbuf, void *data)
-{
+void rssclient_scan_room(struct ctdlroom *qrbuf, void *data) {
char *serialized_config = NULL;
int num_configs = 0;
char cfgline[SIZ];
}
-/*
- * Scan for rooms that have RSS client requests configured
- */
+// Scan for rooms that have RSS client requests configured
void rssclient_scan(void) {
time_t now = time(NULL);
- /* Run no more than once every 15 minutes. */
+ // Run no more than once every 15 minutes.
if ((now - last_run) < 900) {
syslog(LOG_DEBUG,
"rssclient: polling interval not yet reached; last run was %ldm%lds ago",
}
+// Initialization function, called from modules_init.c
char *ctdl_module_init_rssclient(void) {
if (!threading) {
syslog(LOG_INFO, "rssclient: using %s", curl_version());