X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Frssclient%2Fserv_rssclient.c;h=b991b4df13b2c372e794d36fcd98378d3af3ffb5;hb=4a8abab15d6662f2bca504e496013a42d7a65efd;hp=9d08b50e836890a67661d994cabc1ff46c64bb28;hpb=f78f1d57b74695140d54397d9263782a6495ba3c;p=citadel.git diff --git a/citadel/modules/rssclient/serv_rssclient.c b/citadel/modules/rssclient/serv_rssclient.c index 9d08b50e8..b991b4df1 100644 --- a/citadel/modules/rssclient/serv_rssclient.c +++ b/citadel/modules/rssclient/serv_rssclient.c @@ -374,7 +374,7 @@ int LookupUrl(StrBuf *ShorterUrlStr) curl_easy_setopt(curl, CURLOPT_INTERFACE, config.c_ip_addr); } - if (CtdlThreadCheckStop()) + if (server_shutting_down) goto shutdown ; rc = curl_easy_perform(curl); @@ -386,6 +386,7 @@ int LookupUrl(StrBuf *ShorterUrlStr) rc = 1; shutdown: + FreeStrBuf(&Answer); curl_easy_cleanup(curl); return rc; @@ -458,7 +459,7 @@ void ExpandShortUrls(StrBuf *Message) { StrBuf *ShorterUrlStr; HashPos *Pos; - const char *Key; + const char *RetrKey; void *pv; long len; @@ -470,7 +471,7 @@ void ExpandShortUrls(StrBuf *Message) 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; @@ -632,7 +633,10 @@ void rss_save_item(rss_item *ri) 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); @@ -670,8 +674,13 @@ void rss_save_item(rss_item *ri) 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)); @@ -679,7 +688,10 @@ void rss_save_item(rss_item *ri) } 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)); @@ -1299,13 +1311,13 @@ void rss_do_fetching(rssnetcfg *Cfg) { 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); @@ -1313,7 +1325,7 @@ void rss_do_fetching(rssnetcfg *Cfg) { syslog(LOG_ALERT, "libcurl error %d: %s\n", res, errmsg); } - if (CtdlThreadCheckStop()) + if (server_shutting_down) goto shutdown ; @@ -1407,7 +1419,7 @@ void rssclient_scan_room(struct ctdlroom *qrbuf, void *data) 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 */ @@ -1416,7 +1428,7 @@ void rssclient_scan_room(struct ctdlroom *qrbuf, void *data) 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); @@ -1480,6 +1492,11 @@ void rssclient_scan(void) { 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 @@ -1492,7 +1509,7 @@ void rssclient_scan(void) { 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;