-void RSSQueueSaveMessage(struct CtdlMessage *Msg, struct recptypes *recp, StrBuf *MsgGUID, StrBuf *MessageBody, rss_aggregator *Cfg)
-{
- networker_save_message *Ctx;
-
- Ctx = (networker_save_message *) malloc(sizeof(networker_save_message));
- memset(Ctx, 0, sizeof(networker_save_message));
-
- Ctx->MsgGUID = MsgGUID;
- Ctx->Message = MessageBody;
- Ctx->Msg = Msg;
- Ctx->Cfg = Cfg;
- Ctx->recp = recp;
- Ctx->IO.Data = Ctx;
- Ctx->IO.CitContext = CloneContext(CC);
- Ctx->IO.Terminate = FreeNetworkSaveMessage;
- Ctx->IO.ShutdownAbort = AbortNetworkSaveMessage;
- QueueDBOperation(&Ctx->IO, RSS_FetchNetworkUsetableEntry);
-}
-
-
-/*
- * Commit a fetched and parsed RSS item to disk
- */
-void rss_save_item(rss_item *ri, rss_aggregator *Cfg)
-{
-
- struct MD5Context md5context;
- u_char rawdigest[MD5_DIGEST_LEN];
- struct CtdlMessage *msg;
- struct recptypes *recp = NULL;
- int msglen = 0;
- StrBuf *Message;
- StrBuf *guid;
- StrBuf *Buf;
-
- recp = (struct recptypes *) malloc(sizeof(struct recptypes));
- if (recp == NULL) return;
- memset(recp, 0, sizeof(struct recptypes));
- Buf = NewStrBufDup(Cfg->rooms);
- recp->recp_room = SmashStrBuf(&Buf);
- recp->num_room = Cfg->roomlist_parts;
- recp->recptypes_magic = RECPTYPES_MAGIC;
-
- Cfg->RefCount ++;
- /* Construct a GUID to use in the S_USETABLE table.
- * If one is not present in the item itself, make one up.
- */
- if (ri->guid != NULL) {
- StrBufSpaceToBlank(ri->guid);
- StrBufTrim(ri->guid);
- guid = NewStrBufPlain(HKEY("rss/"));
- StrBufAppendBuf(guid, ri->guid, 0);
- }
- else {
- MD5Init(&md5context);
- if (ri->title != NULL) {
- MD5Update(&md5context, (const unsigned char*)ChrPtr(ri->title), StrLength(ri->title));
- }
- if (ri->link != NULL) {
- MD5Update(&md5context, (const unsigned char*)ChrPtr(ri->link), StrLength(ri->link));
- }
- MD5Final(rawdigest, &md5context);
- guid = NewStrBufPlain(NULL, MD5_DIGEST_LEN * 2 + 12 /* _rss2ctdl*/);
- StrBufHexEscAppend(guid, NULL, rawdigest, MD5_DIGEST_LEN);
- StrBufAppendBufPlain(guid, HKEY("_rss2ctdl"), 0);
- }
-
- /* translate Item into message. */
- syslog(LOG_DEBUG, "RSS: translating item...\n");
- if (ri->description == NULL) ri->description = NewStrBufPlain(HKEY(""));
- StrBufSpaceToBlank(ri->description);
- msg = malloc(sizeof(struct CtdlMessage));
- memset(msg, 0, sizeof(struct CtdlMessage));
- msg->cm_magic = CTDLMESSAGE_MAGIC;
- msg->cm_anon_type = MES_NORMAL;
- msg->cm_format_type = FMT_RFC822;
-
- if (ri->guid != NULL) {
- msg->cm_fields['E'] = strdup(ChrPtr(ri->guid));
- }
-
- if (ri->author_or_creator != NULL) {
- char *From;
- StrBuf *Encoded = NULL;
- int FromAt;
-
- From = html_to_ascii(ChrPtr(ri->author_or_creator),
- StrLength(ri->author_or_creator),
- 512, 0);
- StrBufPlain(ri->author_or_creator, From, -1);
- StrBufTrim(ri->author_or_creator);
- free(From);
-
- FromAt = strchr(ChrPtr(ri->author_or_creator), '@') != NULL;
- if (!FromAt && StrLength (ri->author_email) > 0)
- {
- StrBufRFC2047encode(&Encoded, ri->author_or_creator);
- msg->cm_fields['A'] = SmashStrBuf(&Encoded);
- msg->cm_fields['P'] = SmashStrBuf(&ri->author_email);
- }
- else
- {
- if (FromAt)
- {
- 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['A'] = SmashStrBuf(&Encoded);
- msg->cm_fields['P'] = strdup("rss@localhost");
-
- }
- if (ri->pubdate <= 0) {
- ri->pubdate = time(NULL);
- }
- }
- }
- else {
- msg->cm_fields['A'] = strdup("rss");
- }
-
- msg->cm_fields['N'] = strdup(NODENAME);
- if (ri->title != NULL) {
- long len;
- char *Sbj;
- StrBuf *Encoded, *QPEncoded;
-
- QPEncoded = NULL;
- StrBufSpaceToBlank(ri->title);
- len = StrLength(ri->title);
- Sbj = html_to_ascii(ChrPtr(ri->title), len, 512, 0);
- len = strlen(Sbj);
- if (Sbj[len - 1] == '\n')
- {
- len --;
- Sbj[len] = '\0';
- }
- Encoded = NewStrBufPlain(Sbj, len);
- free(Sbj);
-
- StrBufTrim(Encoded);
- StrBufRFC2047encode(&QPEncoded, Encoded);
-
- msg->cm_fields['U'] = SmashStrBuf(&QPEncoded);
- FreeStrBuf(&Encoded);
- }
- 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(""));
-
-#if 0 /* temporarily disable shorter urls. */
- msg->cm_fields[TMP_SHORTER_URLS] = GetShorterUrls(ri->description);
-#endif
-
- msglen += 1024 + StrLength(ri->link) + StrLength(ri->description) ;
-
- Message = NewStrBufPlain(NULL, StrLength(ri->description));
-
- StrBufPlain(Message, HKEY(
- "Content-type: text/html; charset=\"UTF-8\"\r\n\r\n"
- "<html><body>\n"));
-#if 0 /* disable shorter url for now. */
- msg->cm_fields[TMP_SHORTER_URL_OFFSET] = StrLength(Message);
-#endif
- StrBufAppendBuf(Message, ri->description, 0);
- StrBufAppendBufPlain(Message, HKEY("<br><br>\n"), 0);
-
- AppendLink(Message, ri->link, ri->linkTitle, NULL);
- AppendLink(Message, ri->reLink, ri->reLinkTitle, "Reply to this");
- StrBufAppendBufPlain(Message, HKEY("</body></html>\n"), 0);
-
- RSSQueueSaveMessage(msg, recp, guid, Message, Cfg);
-}
-
-