+ return eSendMore;
+}
+
+void UpdateLastKnownGood(pRSSConfig *pCfg, time_t now)
+{
+ OneRoomNetCfg *pRNCfg;
+ begin_critical_section(S_NETCONFIGS);
+ pRNCfg = CtdlGetNetCfgForRoom(pCfg->QRnumber);
+ if (pRNCfg != NULL)
+ {
+ RSSCfgLine *RSSCfg = (RSSCfgLine *)pRNCfg->NetConfigs[rssclient];
+
+ while (RSSCfg != NULL)
+ {
+ if (RSSCfg == pCfg->pCfg)
+ break;
+
+ RSSCfg = RSSCfg->next;
+ }
+ if (RSSCfg != NULL)
+ {
+ RSSCfg->last_known_good = now;
+ }
+ }
+ SaveRoomNetConfigFile(pRNCfg, pCfg->QRnumber);
+ FreeRoomNetworkStruct(&pRNCfg);
+ end_critical_section(S_NETCONFIGS);
+}
+
+eNextState RSSAggregator_AnalyseReply(AsyncIO *IO)
+{
+ HashPos *it = NULL;
+ long len;
+ const char *Key;
+ pRSSConfig *pCfg;
+ u_char rawdigest[MD5_DIGEST_LEN];
+ struct MD5Context md5context;
+ StrBuf *guid;
+ rss_aggregator *Ctx = (rss_aggregator *) IO->Data;
+
+
+ if ((IO->HttpReq.httpcode >= 300) && (IO->HttpReq.httpcode < 400) && (Ctx->RedirectUrl != NULL))
+ {
+ StrBuf *ErrMsg;
+ long lens[2];
+ const char *strs[2];
+
+ SetRSSState(IO, eRSSFailure);
+ ErrMsg = NewStrBuf();
+ if (IO) {
+ syslog(LOG_INFO, "need a 200, got a %ld !", IO->HttpReq.httpcode);
+ }
+ strs[0] = ChrPtr(Ctx->Url);
+ lens[0] = StrLength(Ctx->Url);
+
+ strs[1] = ChrPtr(Ctx->rooms);
+ lens[1] = StrLength(Ctx->rooms);
+
+ if (IO->HttpReq.CurlError == NULL)
+ IO->HttpReq.CurlError = "";
+
+ StrBufPrintf(ErrMsg,
+ "Error while RSS-Aggregation Run of %s\n"
+ " need a 200, got a %ld !\n"
+ " Curl Error message: \n%s / %s\n"
+ " Redirect header points to: %s\n"
+ " Response text was: \n"
+ " \n %s\n",
+ ChrPtr(Ctx->Url),
+ IO->HttpReq.httpcode,
+ IO->HttpReq.errdesc,
+ IO->HttpReq.CurlError,
+ ChrPtr(Ctx->RedirectUrl),
+ ChrPtr(IO->HttpReq.ReplyData)
+ );
+
+ CtdlAideFPMessage(
+ ChrPtr(ErrMsg),
+ "RSS Aggregation run failure",
+ 2, strs, (long*) &lens,
+ CCID,
+ IO->ID,
+ EvGetNow(IO));
+
+ FreeStrBuf(&ErrMsg);
+ syslog(LOG_DEBUG,
+ "RSS feed returned an invalid http status code. <%s><HTTP %ld>",
+ ChrPtr(Ctx->Url),
+ IO->HttpReq.httpcode
+ );
+ return eAbort;
+ }
+ else if (IO->HttpReq.httpcode != 200)
+ {
+ StrBuf *ErrMsg;
+ long lens[2];
+ const char *strs[2];
+
+ SetRSSState(IO, eRSSFailure);
+ ErrMsg = NewStrBuf();
+ if (IO) {
+ syslog(LOG_INFO, "need a 200, got a %ld !", IO->HttpReq.httpcode);
+ }
+ strs[0] = ChrPtr(Ctx->Url);
+ lens[0] = StrLength(Ctx->Url);
+
+ strs[1] = ChrPtr(Ctx->rooms);
+ lens[1] = StrLength(Ctx->rooms);
+
+ if (IO->HttpReq.CurlError == NULL)
+ IO->HttpReq.CurlError = "";
+
+ StrBufPrintf(ErrMsg,
+ "Error while RSS-Aggregation Run of %s\n"
+ " need a 200, got a %ld !\n"
+ " Curl Error message: \n%s / %s\n"
+ " Response text was: \n"
+ " \n %s\n",
+ ChrPtr(Ctx->Url),
+ IO->HttpReq.httpcode,
+ IO->HttpReq.errdesc,
+ IO->HttpReq.CurlError,
+ ChrPtr(IO->HttpReq.ReplyData)
+ );
+
+ CtdlAideFPMessage(
+ ChrPtr(ErrMsg),
+ "RSS Aggregation run failure",
+ 2, strs, (long*) &lens,
+ CCID,
+ IO->ID,
+ EvGetNow(IO));
+
+ FreeStrBuf(&ErrMsg);
+ syslog(LOG_DEBUG,
+ "RSS feed returned an invalid http status code. <%s><HTTP %ld>",
+ ChrPtr(Ctx->Url),
+ IO->HttpReq.httpcode
+ );
+ return eAbort;
+ }
+
+ pCfg = &Ctx->Cfg;
+
+ while (pCfg != NULL)
+ {
+ UpdateLastKnownGood (pCfg, EvGetNow(IO));
+ if ((Ctx->roomlist_parts > 1) &&
+ (it == NULL))
+ {
+ it = GetNewHashPos(RSSFetchUrls, 0);
+ }
+ if (it != NULL)
+ {
+ void *vptr;
+ if (GetNextHashPos(Ctx->OtherQRnumbers, it, &len, &Key, &vptr))
+ pCfg = vptr;
+ else
+ pCfg = NULL;
+ }
+ else
+ pCfg = NULL;
+ }
+ DeleteHashPos (&it);
+
+ SetRSSState(IO, eRSSUT);
+
+ MD5Init(&md5context);
+
+ MD5Update(&md5context,
+ (const unsigned char*)SKEY(IO->HttpReq.ReplyData));
+
+ MD5Update(&md5context,
+ (const unsigned char*)SKEY(Ctx->Url));
+
+ MD5Final(rawdigest, &md5context);
+ guid = NewStrBufPlain(NULL,
+ MD5_DIGEST_LEN * 2 + 12 /* _rss2ctdl*/);
+ StrBufHexEscAppend(guid, NULL, rawdigest, MD5_DIGEST_LEN);
+ StrBufAppendBufPlain(guid, HKEY("_rssFM"), 0);
+ if (StrLength(guid) > 40)
+ StrBufCutAt(guid, 40, NULL);
+ /* Find out if we've already seen this item */
+
+#ifndef DEBUG_RSS
+
+ if (CheckIfAlreadySeen("RSS Whole",
+ guid,
+ EvGetNow(IO),
+ EvGetNow(IO) - USETABLE_ANTIEXPIRE,
+ eUpdate,
+ CCID, IO->ID)
+ != 0)
+ {
+ FreeStrBuf(&guid);
+
+ syslog(LOG_DEBUG, "RSS feed already seen. <%s>", ChrPtr(Ctx->Url));
+ return eAbort;
+ }
+ FreeStrBuf(&guid);
+#endif
+ SetRSSState(IO, eRSSParsing);
+ return RSSAggregator_ParseReply(IO);
+}
+
+eNextState RSSAggregator_FinishHttp(AsyncIO *IO)
+{
+ return CurlQueueDBOperation(IO, RSSAggregator_AnalyseReply);