]> code.citadel.org Git - citadel.git/blobdiff - webcit/rss.c
Created ctdl_iconv_open() wrapper around iconv_open()
[citadel.git] / webcit / rss.c
index e479eb7a718ae8aa1607fa32f8426051fd83978d..6a962559a27b9b6f95ead77cc68ac6dd9096f76b 100644 (file)
@@ -1,29 +1,61 @@
 /*
  * $Id$
- *
- * Generate some RSS for our rooms.
  */
-
+/**
+ * \defgroup RssRooms Generate some RSS for our rooms.
+ * \ingroup WebcitHttpServerRSS
+ */
+/*@{*/
 #include "webcit.h"
 #include "webserver.h"
 
 
-time_t if_modified_since;
+time_t if_modified_since;    /**< the last modified stamp */
+
+/**
+ * \brief view rss Config menu
+ * \param reply_to the original author
+ * \param subject the subject of the feed
+ */
+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(const char *roomname)
+/**
+ * \brief print the feed to the subscriber
+ * \param roomname the room we sould print out as rss 
+ * \param request_method the way the rss is requested????
+ */
+void display_rss(char *roomname, char *request_method)
 {
        int nummsgs;
        int a, b;
        int bq = 0;
        time_t now = 0L;
        struct tm now_tm;
+#ifdef HAVE_ICONV
        iconv_t ic = (iconv_t)(-1) ;
-       char *ibuf;                   /* Buffer of characters to be converted */
-       char *obuf;                   /* Buffer for converted characters      */
-       size_t ibuflen;               /* Length of input buffer               */
-       size_t obuflen;               /* Length of output buffer              */
-       char *osav;                   /* Saved pointer to output buffer       */
+       char *ibuf;                   /**< Buffer of characters to be converted */
+       char *obuf;                   /**< Buffer for converted characters      */
+       size_t ibuflen;               /**< Length of input buffer               */
+       size_t obuflen;               /**< Length of output buffer              */
+       char *osav;                   /**< Saved pointer to output buffer       */
+#endif
        char buf[SIZ];
        char date[30];
        char from[256];
@@ -38,28 +70,30 @@ 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|50", 0);
+       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;
        }
 
-       /* Read time of last message immediately */
+       /** Read time of last message immediately */
        serv_printf("MSG4 %ld", WC->msgarr[nummsgs - 1]);
        serv_getln(buf, sizeof buf);
        if (buf[0] == '1') {
@@ -75,9 +109,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 +123,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");
@@ -107,7 +142,7 @@ void display_rss(const char *roomname)
        escputs(roomname);
        wprintf("</link>\n");
        wprintf("   <description>");
-       /* Get room info for description */
+       /** Get room info for description */
        serv_puts("RINF");
        serv_getln(buf, sizeof buf);
        if (buf[0] == '1') {
@@ -115,7 +150,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");
@@ -126,9 +161,9 @@ void display_rss(const char *roomname)
        wprintf("   <docs>http://blogs.law.harvard.edu/tech/rss</docs>\n");
        wprintf("   <ttl>30</ttl>\n");
 
-       /* Read all messages and output as RSS items */
+       /** Read all messages and output as RSS items */
        for (a = 0; a < nummsgs; ++a) {
-               /* Read message and output each as RSS item */
+               /** Read message and output each as RSS item */
                serv_printf("MSG4 %ld", WC->msgarr[a]);
                serv_getln(buf, sizeof buf);
                if (buf[0] != '1') continue;
@@ -144,7 +179,7 @@ void display_rss(const char *roomname)
 
                while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
                        if (!strcmp(buf, "000")) {
-                               goto ENDITEM;   /* screw it */
+                               goto ENDITEM;   /** screw it */
                        } else if (!strncasecmp(buf, "from=", 5)) {
                                strcpy(from, &buf[5]);
 #ifdef HAVE_ICONV
@@ -187,7 +222,7 @@ void display_rss(const char *roomname)
                        wprintf("      <pubDate>%s</pubDate>\n", date);
                }
                wprintf("      <guid isPermaLink=\"false\">%s</guid>\n", msgn);
-               /* Now the hard part, the message itself */
+               /** Now the hard part, the message itself */
                strcpy(content_type, "text/plain");
                while (serv_getln(buf, sizeof buf), strlen(buf) > 0) {
                        if (!strcmp(buf, "000")) {
@@ -208,18 +243,19 @@ void display_rss(const char *roomname)
                        }
                }
 
-               /* Set up a character set conversion if we need to */
+               /** Set up a character set conversion if we need to */
 #ifdef HAVE_ICONV
-               if (strcasecmp(charset, "us-ascii") && strcasecmp(charset, "utf-8")) {
-                       ic = iconv_open("UTF-8", charset);
+               if (strcasecmp(charset, "us-ascii") && strcasecmp(charset, "utf-8") && strcasecmp(charset, "") ) {
+                       ic = ctdl_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;
                        }
                }
 #endif
 
-               /* Messages in legacy Citadel variformat get handled thusly... */
+               /** Messages in legacy Citadel variformat get handled thusly... */
                if (!strcasecmp(content_type, "text/x-citadel-variformat")) {
                        int intext = 0;
 
@@ -247,9 +283,10 @@ 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... */
+               /** Boring old 80-column fixed format text gets handled this way... */
                else if (!strcasecmp(content_type, "text/plain")) {
                        wprintf("      <description><![CDATA[");
                        while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
@@ -286,12 +323,13 @@ 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 */
+               /** HTML is fun, but we've got to strip it first */
                else if (!strcasecmp(content_type, "text/html")) {
                        wprintf("      <description><![CDATA[");
-                       output_html(charset);
+                       output_html(charset, 0);
                        wprintf("]]></description>\n");
                }
 
@@ -301,8 +339,11 @@ ENDITEM:
                now = 0L;
        }
 
-       /* Do RSS footer */
+       /** Do RSS footer */
        wprintf("   </channel>\n");
        wprintf("</rss>\n");
        wDumpContent(0);
 }
+
+
+/*@}*/