{
iconv_t cd = (iconv_t)(-1);
int flag;
- CtdlLogPrintf(0, "RSS: fill encoding info ...\n");
+ syslog(LOG_EMERG, "RSS: fill encoding info ...\n");
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
cd = iconv_open ("UCS-2LE", charset);
{
XML_Encoding *info = data;
int res;
- CtdlLogPrintf(0, "RSS: Converting ...\n");
+ syslog(LOG_EMERG, "RSS: Converting ...\n");
if (s == NULL)
return -1;
XML_Encoding * info)
{
int result;
- CtdlLogPrintf(0, "RSS: unknown encoding ...\n");
+ syslog(LOG_EMERG, "RSS: unknown encoding ...\n");
result = fill_encoding_info (name, info);
if (result >= 0)
{
curl = curl_easy_init();
if (!curl) {
- CtdlLogPrintf(CTDL_ALERT, "Unable to initialize libcurl.\n");
+ syslog(LOG_ALERT, "Unable to initialize libcurl.\n");
return 0;
}
Answer = NewStrBufPlain(NULL, SIZ);
curl_easy_setopt(curl, CURLOPT_INTERFACE, config.c_ip_addr);
}
- if (CtdlThreadCheckStop())
+ if (server_shutting_down)
goto shutdown ;
rc = curl_easy_perform(curl);
if (rc) {
- CtdlLogPrintf(CTDL_ALERT, "libcurl error %d: %s\n", rc, errmsg);
+ syslog(LOG_ALERT, "libcurl error %d: %s\n", rc, errmsg);
rc = 0;
}
else
rc = 1;
shutdown:
+ FreeStrBuf(&Answer);
curl_easy_cleanup(curl);
return rc;
{
StrBuf *ShorterUrlStr;
HashPos *Pos;
- const char *Key;
+ const char *RetrKey;
void *pv;
long len;
pch = ChrPtr(Message);
pche = pch + StrLength(Message);
Pos = GetNewHashPos(pUrls, 1);
- while (GetNextHashPos(pUrls, Pos, &len, &Key, &pv))
+ while (GetNextHashPos(pUrls, Pos, &len, &RetrKey, &pv))
{
pCUrl = (ConstStr*) pv;
#ifndef DEBUG_RSS
if (cdbut != NULL) {
/* Item has already been seen */
- CtdlLogPrintf(CTDL_DEBUG, "%s has already been seen\n", utmsgid);
+ syslog(LOG_DEBUG, "%s has already been seen\n", utmsgid);
cdb_free(cdbut);
/* rewrite the record anyway, to update the timestamp */
#endif
{
/* Item has not been seen, so save it. */
- CtdlLogPrintf(CTDL_DEBUG, "RSS: saving item...\n");
+ syslog(LOG_DEBUG, "RSS: saving item...\n");
if (ri->description == NULL) ri->description = NewStrBufPlain(HKEY(""));
StrBufSpaceToBlank(ri->description);
msg = malloc(sizeof(struct CtdlMessage));
else
{
if (FromAt)
- msg->cm_fields['P'] = SmashStrBuf(&ri->author_or_creator);
+ {
+ msg->cm_fields['A'] = SmashStrBuf(&ri->author_or_creator);
+ msg->cm_fields['P'] = strdup(msg->cm_fields['A']);
+ }
else
{
StrBufRFC2047encode(&Encoded, ri->author_or_creator);
msg->cm_fields['U'] = SmashStrBuf(&QPEncoded);
FreeStrBuf(&Encoded);
}
+
+ if (ri->pubdate <= 0) {
+ ri->pubdate = time(NULL);
+ }
msg->cm_fields['T'] = malloc(64);
snprintf(msg->cm_fields['T'], 64, "%ld", ri->pubdate);
+
if (ri->channel_title != NULL) {
if (StrLength(ri->channel_title) > 0) {
msg->cm_fields['O'] = strdup(ChrPtr(ri->channel_title));
}
if (ri->link == NULL)
ri->link = NewStrBufPlain(HKEY(""));
+#ifdef EXPERIMENTAL_SHORTER_URLS
+/* its rather hard to implement this libevent compatible, so we don't ship it. */
ExpandShortUrls(ri->description);
+#endif
msglen += 1024 + StrLength(ri->link) + StrLength(ri->description) ;
Message = NewStrBufPlain(NULL, StrLength(ri->description));
FreeStrBuf(&ri->guid);
FreeStrBuf(&ri->title);
FreeStrBuf(&ri->link);
+ FreeStrBuf(&ri->linkTitle);
+ FreeStrBuf(&ri->reLink);
+ FreeStrBuf(&ri->reLinkTitle);
+ FreeStrBuf(&ri->description);
+ FreeStrBuf(&ri->channel_title);
FreeStrBuf(&ri->author_or_creator);
- FreeStrBuf(&ri->author_email);
FreeStrBuf(&ri->author_url);
- FreeStrBuf(&ri->description);
+ FreeStrBuf(&ri->author_email);
}
void rss_xml_start(void *data, const char *supplied_el, const char **attr)
char *sep = NULL;
/* Axe the namespace, we don't care about it */
-/// CtdlLogPrintf(0, "RSS: supplied el %d: %s...\n", rssc->Cfg->ItemType, supplied_el);
+/// syslog(LOG_EMERG, "RSS: supplied el %d: %s...\n", rssc->Cfg->ItemType, supplied_el);
pel = supplied_el;
while (sep = strchr(pel, ':'), sep) {
pel = sep + 1;
&v))
{
#ifdef DEBUG_RSS
- CtdlLogPrintf(0, "RSS: START ignoring because of wrong namespace [%s] = [%s]\n",
+ syslog(LOG_EMERG, "RSS: START ignoring because of wrong namespace [%s] = [%s]\n",
supplied_el);
#endif
return;
}
#ifdef DEBUG_RSS
else
- CtdlLogPrintf(0, "RSS: START unhandled: [%s] [%s]...\n", pel, supplied_el);
+ syslog(LOG_EMERG, "RSS: START unhandled: [%s] [%s]...\n", pel, supplied_el);
#endif
}
#ifdef DEBUG_RSS
else
- CtdlLogPrintf(0, "RSS: START unhandled: [%s] [%s]...\n", pel, supplied_el);
+ syslog(LOG_EMERG, "RSS: START unhandled: [%s] [%s]...\n", pel, supplied_el);
#endif
}
while (sep = strchr(pel, ':'), sep) {
pel = sep + 1;
}
-// CtdlLogPrintf(0, "RSS: END %s...\n", el);
+// syslog(LOG_EMERG, "RSS: END %s...\n", el);
if (pel != supplied_el)
{
void *v;
&v))
{
#ifdef DEBUG_RSS
- CtdlLogPrintf(0, "RSS: END ignoring because of wrong namespace [%s] = [%s]\n",
+ syslog(LOG_EMERG, "RSS: END ignoring because of wrong namespace [%s] = [%s]\n",
supplied_el, ChrPtr(rssc->CData));
#endif
FlushStrBuf(rssc->CData);
}
#ifdef DEBUG_RSS
else
- CtdlLogPrintf(0, "RSS: END unhandled: [%s] [%s] = [%s]...\n", pel, supplied_el, ChrPtr(rssc->CData));
+ syslog(LOG_EMERG, "RSS: END unhandled: [%s] [%s] = [%s]...\n", pel, supplied_el, ChrPtr(rssc->CData));
#endif
}
#ifdef DEBUG_RSS
else
- CtdlLogPrintf(0, "RSS: END unhandled: [%s] [%s] = [%s]...\n", pel, supplied_el, ChrPtr(rssc->CData));
+ syslog(LOG_EMERG, "RSS: END unhandled: [%s] [%s] = [%s]...\n", pel, supplied_el, ChrPtr(rssc->CData));
#endif
FlushStrBuf(rssc->CData);
rssc->Current = NULL;
void RSS_item_rss_start (StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
{
- CtdlLogPrintf(CTDL_DEBUG, "RSS: This is an RSS feed.\n");
+ syslog(LOG_DEBUG, "RSS: This is an RSS feed.\n");
Cfg->ItemType = RSS_RSS;
}
void RSS_item_rdf_start(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
{
- CtdlLogPrintf(CTDL_DEBUG, "RSS: This is an RDF feed.\n");
+ syslog(LOG_DEBUG, "RSS: This is an RDF feed.\n");
Cfg->ItemType = RSS_RSS;
}
void ATOM_item_feed_start(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
{
- CtdlLogPrintf(CTDL_DEBUG, "RSS: This is an ATOM feed.\n");
+ syslog(LOG_DEBUG, "RSS: This is an ATOM feed.\n");
Cfg->ItemType = RSS_ATOM;
}
void RSS_item_rss_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
{
-// CtdlLogPrintf(CTDL_DEBUG, "End of feed detected. Closing parser.\n");
+// syslog(LOG_DEBUG, "End of feed detected. Closing parser.\n");
ri->done_parsing = 1;
}
void RSS_item_rdf_end(StrBuf *CData, rss_item *ri, rssnetcfg *Cfg, const char** Attr)
{
-// CtdlLogPrintf(CTDL_DEBUG, "End of feed detected. Closing parser.\n");
+// syslog(LOG_DEBUG, "End of feed detected. Closing parser.\n");
ri->done_parsing = 1;
}
rssc.Item = &ri;
rssc.Cfg = Cfg;
- CtdlLogPrintf(CTDL_DEBUG, "Fetching RSS feed <%s>\n", Cfg->url);
+ syslog(LOG_DEBUG, "Fetching RSS feed <%s>\n", Cfg->url);
curl = curl_easy_init();
if (!curl) {
- CtdlLogPrintf(CTDL_ALERT, "Unable to initialize libcurl.\n");
+ syslog(LOG_ALERT, "Unable to initialize libcurl.\n");
return;
}
Answer = NewStrBufPlain(NULL, SIZ);
curl_easy_setopt(curl, CURLOPT_INTERFACE, config.c_ip_addr);
}
- if (CtdlThreadCheckStop())
+ if (server_shutting_down)
{
curl_easy_cleanup(curl);
return;
}
- if (CtdlThreadCheckStop())
+ if (server_shutting_down)
goto shutdown ;
res = curl_easy_perform(curl);
if (res) {
- CtdlLogPrintf(CTDL_ALERT, "libcurl error %d: %s\n", res, errmsg);
+ syslog(LOG_ALERT, "libcurl error %d: %s\n", res, errmsg);
}
- if (CtdlThreadCheckStop())
+ if (server_shutting_down)
goto shutdown ;
xp = XML_ParserCreateNS(ptr, ':');
if (!xp) {
- CtdlLogPrintf(CTDL_ALERT, "Cannot create XML parser!\n");
+ syslog(LOG_ALERT, "Cannot create XML parser!\n");
goto shutdown;
}
FlushStrBuf(rssc.Key);
XML_Parse(xp, "", 0, 1);
- CtdlLogPrintf(CTDL_ALERT, "RSS: XML Status [%s] \n",
+ syslog(LOG_ALERT, "RSS: XML Status [%s] \n",
XML_ErrorString(
XML_GetErrorCode(xp)));
shutdown:
+ FreeStrBuf(&Answer);
curl_easy_cleanup(curl);
XML_ParserFree(xp);
assoc_file_name(filename, sizeof filename, qrbuf, ctdl_netcfg_dir);
- if (CtdlThreadCheckStop())
+ if (server_shutting_down)
return;
/* Only do net processing for rooms that have netconfigs */
return;
}
- while (fgets(buf, sizeof buf, fp) != NULL && !CtdlThreadCheckStop()) {
+ while (fgets(buf, sizeof buf, fp) != NULL && !server_shutting_down) {
buf[strlen(buf)-1] = 0;
extract_token(instr, buf, 0, '|', sizeof instr);
static int doing_rssclient = 0;
rssnetcfg *rptr = NULL;
+ /* Run no more than once every 15 minutes. */
+ if ((time(NULL) - last_run) < 900) {
+ 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
if (doing_rssclient) return;
doing_rssclient = 1;
- CtdlLogPrintf(CTDL_DEBUG, "rssclient started\n");
+ syslog(LOG_DEBUG, "rssclient started\n");
CtdlForEachRoom(rssclient_scan_room, NULL);
- while (rnclist != NULL && !CtdlThreadCheckStop()) {
+ while (rnclist != NULL && !server_shutting_down) {
rss_do_fetching(rnclist);
rptr = rnclist;
rnclist = rnclist->next;
free(rptr);
}
- CtdlLogPrintf(CTDL_DEBUG, "rssclient ended\n");
+ syslog(LOG_DEBUG, "rssclient ended\n");
last_run = time(NULL);
doing_rssclient = 0;
return;
close(fd);
}
+void rss_cleanup(void)
+{
+ DeleteHash(&StartHandlers);
+ DeleteHash(&EndHandlers);
+ DeleteHash(&UrlShorteners);
+ DeleteHash(&KnownNameSpaces);
+}
+
CTDL_MODULE_INIT(rssclient)
{
if (threading)
{
- CtdlLogPrintf(CTDL_INFO, "%s\n", curl_version());
+ syslog(LOG_INFO, "%s\n", curl_version());
CtdlRegisterSessionHook(rssclient_scan, EVT_TIMER);
}
else
/* we don't like these namespaces because of they shadow our usefull parameters. */
Put(KnownNameSpaces, HKEY("http://search.yahoo.com/mrss/"), NULL, reference_free_handler);
#endif
+ CtdlRegisterCleanupHook(rss_cleanup);
}
return "rssclient";
}