From 1d82485e0277efce7a74c579584a588f681c7c89 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 7 Jun 2011 00:15:52 -0400 Subject: [PATCH] feed generator: read entire message into memory first. This will allow us to do decision making before output begins. --- webcit/feed_generator.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/webcit/feed_generator.c b/webcit/feed_generator.c index 25af56e71..648309cc4 100644 --- a/webcit/feed_generator.c +++ b/webcit/feed_generator.c @@ -26,26 +26,34 @@ * RSS feed generator -- do one message */ void feed_rss_one_message(long msgnum) { - char buf[1024]; int in_body = 0; int in_messagetext = 0; int found_title = 0; int found_guid = 0; char pubdate[128]; StrBuf *messagetext = NULL; + int is_top_level_post = 1; + const char *BufPtr = NULL; + StrBuf *Line = NewStrBufPlain(NULL, 1024); + char buf[1024]; /* FIXME if this is a blog room we only want to include top-level messages */ serv_printf("MSG4 %ld", msgnum); serv_getln(buf, sizeof buf); if (buf[0] != '1') return; + StrBuf *ServerResponse = NewStrBuf(); + while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { + StrBufAppendPrintf(ServerResponse, "%s\n", buf); + } wc_printf(""); wc_printf("%s/readfwd?go=", ChrPtr(site_prefix)); urlescputs(ChrPtr(WC->CurRoom.name)); wc_printf("?start_reading_at=%ld", msgnum); - while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { + while (StrBufSipLine(Line, ServerResponse, &BufPtr), ((BufPtr!=StrBufNOTNULL)&&(BufPtr!=NULL)) ) { + safestrncpy(buf, ChrPtr(Line), sizeof buf); if (in_body) { if (in_messagetext) { StrBufAppendBufPlain(messagetext, buf, -1, 0); @@ -71,6 +79,9 @@ void feed_rss_one_message(long msgnum) { http_datestring(pubdate, sizeof pubdate, atol(&buf[5])); wc_printf("%s", pubdate); } + else if (!strncasecmp(buf, "wefw=", 5)) { + is_top_level_post = 0; /* presence of references means it's a reply/comment */ + } else if (!strncasecmp(buf, "text", 4)) { if (!found_title) { wc_printf("Message #%ld", msgnum); @@ -94,6 +105,9 @@ void feed_rss_one_message(long msgnum) { } wc_printf(""); + FreeStrBuf(&Line); + FreeStrBuf(&ServerResponse); + return; } /* -- 2.39.2