* More changes required to be able to do embedded message/rfc822 and still be
[citadel.git] / webcit / rss.c
index 0d131873c28f3850f873d5dd637bd4119cec5622..fe4a5d7a01306348c076761e7c21c33c1f364cbd 100644 (file)
 time_t if_modified_since;
 
 
-void display_rss(const char *roomname)
+void display_rss_control(char *reply_to, char *subject)
+{
+       wprintf("<div style=\"align: right;\"><p>\n");
+       wprintf("<a href=\"/display_enter?recp=");
+       urlescputs(reply_to);
+       wprintf("&subject=");
+       if (strncasecmp(subject, "Re: ", 3)) wprintf("Re:%20");
+       urlescputs(subject);
+       wprintf("\">[%s]</a> \n", _("Reply"));
+       wprintf("<a href=\"/display_enter?recp=");
+       urlescputs(reply_to);
+       wprintf("&force_room=_MAIL_&subject=");
+       if (strncasecmp(subject, "Re: ", 3)) wprintf("Re:%20");
+       urlescputs(subject);
+       wprintf("\">[%s]</a>\n", _("Email"));
+       wprintf("</p></div>\n");
+}
+
+
+void display_rss(char *roomname, char *request_method)
 {
        int nummsgs;
        int a, b;
@@ -38,24 +57,26 @@ void display_rss(const char *roomname)
        char charset[256];
 
        if (!WC->logged_in) {
-               authorization_required("Not logged in");
+               authorization_required(_("Not logged in"));
                return;
        }
 
-       if (gotoroom(roomname)) {
-               wprintf("HTTP/1.0 404 Not Found\r\n");
+       if (gotoroom((char *)roomname)) {
+               lprintf(3, "RSS: Can't goto requested room\n");
+               wprintf("HTTP/1.1 404 Not Found\r\n");
                wprintf("Content-Type: text/html\r\n");
                wprintf("\r\n");
-               wprintf("Error retrieving RSS feed: couldn't find room or messages\n");
+               wprintf("Error retrieving RSS feed: couldn't find room\n");
                return;
        }
 
        nummsgs = load_msg_ptrs("MSGS LAST|15", 0);
        if (nummsgs == 0) {
-               wprintf("HTTP/1.0 404 Not Found\r\n");
+               lprintf(3, "RSS: No messages found\n");
+               wprintf("HTTP/1.1 404 Not Found\r\n");
                wprintf("Content-Type: text/html\r\n");
                wprintf("\r\n");
-               wprintf("Error retrieving RSS feed: couldn't find room or messages\n");
+               wprintf(_("Error retrieving RSS feed: couldn't find messages\n"));
                return;
        }
 
@@ -75,9 +96,9 @@ void display_rss(const char *roomname)
                }
        }
 
-       lprintf(3, "If modified since %ld Last modified %ld\n", if_modified_since, now);
        if (if_modified_since > 0 && if_modified_since > now) {
-               wprintf("HTTP/1.0 304 Not Modified\r\n");
+               lprintf(3, "RSS: Feed not updated since the last time you looked\n");
+               wprintf("HTTP/1.1 304 Not Modified\r\n");
                wprintf("Last-Modified: %s\r\n", date);
                now = time(NULL);
                gmtime_r(&now, &now_tm);
@@ -89,7 +110,8 @@ void display_rss(const char *roomname)
        }
 
        /* Do RSS header */
-       wprintf("HTTP/1.0 200 OK\r\n");
+       lprintf(3, "RSS: Yum yum! This feed is tasty!\n");
+       wprintf("HTTP/1.1 200 OK\r\n");
        wprintf("Last-Modified: %s\r\n", date);
 /*     if (*msgn) wprintf("ETag: %s\r\n\r\n", msgn); */
        wprintf("Content-Type: application/rss+xml\r\n");
@@ -115,7 +137,7 @@ void display_rss(const char *roomname)
                        serv_getln(buf, sizeof buf);
                        if (!strcmp(buf, "000"))
                                break;
-                       wprintf("%s", buf);
+                       wprintf("%s\n", buf);
                }
        }
        wprintf("</description>\n");
@@ -210,10 +232,10 @@ void display_rss(const char *roomname)
 
                /* Set up a character set conversion if we need to */
 #ifdef HAVE_ICONV
-               if (strcasecmp(charset, "us-ascii") && strcasecmp(charset, "utf-8")) {
+               if (strcasecmp(charset, "us-ascii") && strcasecmp(charset, "utf-8") && strcasecmp(charset, "") ) {
                        ic = iconv_open("UTF-8", charset);
                        if (ic == (iconv_t)(-1)) {
-                               lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
+                               lprintf(5, "%s:%d iconv_open() failed: %s\n", __FILE__, __LINE__, strerror(errno));
                                goto ENDBODY;
                        }
                }
@@ -247,6 +269,7 @@ void display_rss(const char *roomname)
                                escputs(buf);
                                wprintf("\n");
                        }
+                       display_rss_control(from, subj);
                        wprintf("]]></description>\n");
                }
                /* Boring old 80-column fixed format text gets handled this way... */
@@ -286,6 +309,7 @@ void display_rss(const char *roomname)
                                escputs(buf);
                                wprintf("</tt><br />\n");
                        }
+                       display_rss_control(from, subj);
                        wprintf("]]></description>\n");
                }
                /* HTML is fun, but we've got to strip it first */