feed generator: read entire message into memory first. This will allow us to do...
authorArt Cancro <ajc@uncensored.citadel.org>
Tue, 7 Jun 2011 04:15:52 +0000 (00:15 -0400)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 4 Sep 2011 20:59:20 +0000 (20:59 +0000)
webcit/feed_generator.c

index 25af56e716174a3c69243b21b88eeea29b49eeba..648309cc4551d54dc95212497bd2f5af50588046 100644 (file)
  * 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("<item>");
        wc_printf("<link>%s/readfwd?go=", ChrPtr(site_prefix));
        urlescputs(ChrPtr(WC->CurRoom.name));
        wc_printf("?start_reading_at=%ld</link>", 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("<pubDate>%s</pubDate>", 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("<title>Message #%ld</title>", msgnum);
@@ -94,6 +105,9 @@ void feed_rss_one_message(long msgnum) {
        }
 
        wc_printf("</item>");
+       FreeStrBuf(&Line);
+       FreeStrBuf(&ServerResponse);
+       return;
 }
 
 /*