/*
* Bring external RSS feeds into rooms.
*
- * Copyright (c) 2007-2010 by the citadel.org team
+ * Copyright (c) 2007-2012 by the citadel.org team
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
+ * 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.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
*/
#include <stdlib.h>
HashList *RSSFetchUrls = NULL; /*->rss_aggregator;->RefCount access locked*/
eNextState RSSAggregator_Terminate(AsyncIO *IO);
+eNextState RSSAggregator_TerminateDB(AsyncIO *IO);
eNextState RSSAggregator_ShutdownAbort(AsyncIO *IO);
struct CitContext rss_CC;
{
HashPos *At;
+ pthread_mutex_lock(&RSSQueueMutex);
UnlinkRooms(Cfg);
At = GetNewHashPos(RSSFetchUrls, 0);
}
DeleteHashPos(&At);
last_run = time(NULL);
+ pthread_mutex_unlock(&RSSQueueMutex);
}
void DeleteRssCfg(void *vptr)
return eAbort;
}
+eNextState RSSAggregator_TerminateDB(AsyncIO *IO)
+{
+ rss_aggregator *RSSAggr = (rss_aggregator *)IO->Data;
+
+ EVM_syslog(LOG_DEBUG, "RSS: Terminating.\n");
+
+
+ UnlinkRSSAggregator(RSSAggr);
+ return eAbort;
+}
+
eNextState RSSAggregator_ShutdownAbort(AsyncIO *IO)
{
const char *pUrl;
"Citadel RSS Client",
RSSAggregator_ParseReply,
RSSAggregator_Terminate,
+ RSSAggregator_TerminateDB,
RSSAggregator_ShutdownAbort))
{
syslog(LOG_ALERT, "Unable to initialize libcurl.\n");
* Scan for rooms that have RSS client requests configured
*/
void rssclient_scan(void) {
+ int RSSRoomCount, RSSCount;
rss_aggregator *rptr = NULL;
void *vrptr = NULL;
HashPos *it;
/* 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",
+ ((now - last_run) / 60),
+ ((now - last_run) % 60)
+ );
return;
}
/*
* This is a simple concurrency check to make sure only one rssclient
- * run is done at a time.We could do this with a mutex, but since we
- * don't really require extremely fine granularity here, we'll do it
- * with a static variable instead.
+ * run is done at a time.
*/
+ pthread_mutex_lock(&RSSQueueMutex);
+ RSSCount = GetCount(RSSFetchUrls);
+ RSSRoomCount = GetCount(RSSQueueRooms);
+ pthread_mutex_unlock(&RSSQueueMutex);
- if ((GetCount(RSSQueueRooms) > 0) || (GetCount(RSSFetchUrls) > 0))
+ if ((RSSRoomCount > 0) || (RSSCount > 0)) {
+ syslog(LOG_DEBUG,
+ "rssclient: concurrency check failed; %d rooms and %d url's are queued",
+ RSSRoomCount, RSSCount
+ );
return;
+ }
become_session(&rss_CC);
syslog(LOG_DEBUG, "rssclient started\n");
RSSFetchUrls = NewHash(1, NULL);
syslog(LOG_INFO, "%s\n", curl_version());
CtdlRegisterSessionHook(rssclient_scan, EVT_TIMER);
- CtdlRegisterCleanupHook(rss_cleanup);
+ CtdlRegisterEVCleanupHook(rss_cleanup);
}
return "rssclient";
}