5 * \defgroup RssRooms Generate some RSS for our rooms.
12 time_t if_modified_since; /**< the last modified stamp */
15 * \brief view rss Config menu
16 * \param reply_to the original author
17 * \param subject the subject of the feed
19 void display_rss_control(char *reply_to, char *subject)
21 wprintf("<div style=\"align: right;\"><p>\n");
22 wprintf("<a href=\"display_enter?recp=");
25 if (strncasecmp(subject, "Re: ", 3)) wprintf("Re:%20");
27 wprintf("\">[%s]</a> \n", _("Reply"));
28 wprintf("<a href=\"display_enter?recp=");
30 wprintf("&force_room=_MAIL_&subject=");
31 if (strncasecmp(subject, "Re: ", 3)) wprintf("Re:%20");
33 wprintf("\">[%s]</a>\n", _("Email"));
34 wprintf("</p></div>\n");
39 * \brief print the feed to the subscriber
40 * \param roomname the room we sould print out as rss
41 * \param request_method the way the rss is requested????
43 void display_rss(char *roomname, char *request_method)
51 iconv_t ic = (iconv_t)(-1) ;
52 char *ibuf; /**< Buffer of characters to be converted */
53 char *obuf; /**< Buffer for converted characters */
54 size_t ibuflen; /**< Length of input buffer */
55 size_t obuflen; /**< Length of output buffer */
56 char *osav; /**< Saved pointer to output buffer */
68 char content_type[256];
72 authorization_required(_("Not logged in"));
76 if (gotoroom((char *)roomname)) {
77 lprintf(3, "RSS: Can't goto requested room\n");
78 wprintf("HTTP/1.1 404 Not Found\r\n");
79 wprintf("Content-Type: text/html\r\n");
81 wprintf("Error retrieving RSS feed: couldn't find room\n");
85 nummsgs = load_msg_ptrs("MSGS LAST|15", 0);
87 lprintf(3, "RSS: No messages found\n");
88 wprintf("HTTP/1.1 404 Not Found\r\n");
89 wprintf("Content-Type: text/html\r\n");
91 wprintf(_("Error retrieving RSS feed: couldn't find messages\n"));
95 /** Read time of last message immediately */
96 serv_printf("MSG4 %ld", WC->msgarr[nummsgs - 1]);
97 serv_getln(buf, sizeof buf);
99 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "000")) {
100 if (!strncasecmp(buf, "msgn=", 5)) {
101 strcpy(msgn, &buf[5]);
103 if (!strncasecmp(buf, "time=", 5)) {
105 gmtime_r(&now, &now_tm);
106 strftime(date, sizeof date, "%a, %d %b %Y %H:%M:%S GMT", &now_tm);
111 if (if_modified_since > 0 && if_modified_since > now) {
112 lprintf(3, "RSS: Feed not updated since the last time you looked\n");
113 wprintf("HTTP/1.1 304 Not Modified\r\n");
114 wprintf("Last-Modified: %s\r\n", date);
116 gmtime_r(&now, &now_tm);
117 strftime(date, sizeof date, "%a, %d %b %Y %H:%M:%S GMT", &now_tm);
118 wprintf("Date: %s\r\n", date);
119 /* if (*msgn) wprintf("ETag: %s\r\n\r\n", msgn); */
125 lprintf(3, "RSS: Yum yum! This feed is tasty!\n");
126 wprintf("HTTP/1.1 200 OK\r\n");
127 wprintf("Last-Modified: %s\r\n", date);
128 /* if (*msgn) wprintf("ETag: %s\r\n\r\n", msgn); */
129 wprintf("Content-Type: application/rss+xml\r\n");
130 wprintf("$erver: %s\r\n", SERVER);
131 wprintf("Connection: close\r\n");
133 if (!strcasecmp(request_method, "HEAD"))
136 wprintf("<?xml version=\"1.0\"?>\n");
137 wprintf("<rss version=\"2.0\">\n");
138 wprintf(" <channel>\n");
139 wprintf(" <title>%s - %s</title>\n", WC->wc_roomname, serv_info.serv_humannode);
140 wprintf(" <link>%s://%s:%d/dotgoto?room=", (is_https ? "https" : "http"), WC->http_host, PORT_NUM);
142 wprintf("</link>\n");
143 wprintf(" <description>");
144 /** Get room info for description */
146 serv_getln(buf, sizeof buf);
149 serv_getln(buf, sizeof buf);
150 if (!strcmp(buf, "000"))
152 wprintf("%s\n", buf);
155 wprintf("</description>\n");
157 wprintf(" <pubDate>%s</pubDate>\n", date);
159 wprintf(" <generator>%s</generator>\n", SERVER);
160 wprintf(" <docs>http://blogs.law.harvard.edu/tech/rss</docs>\n");
161 wprintf(" <ttl>30</ttl>\n");
163 /** Read all messages and output as RSS items */
164 for (a = 0; a < nummsgs; ++a) {
165 /** Read message and output each as RSS item */
166 serv_printf("MSG4 %ld", WC->msgarr[a]);
167 serv_getln(buf, sizeof buf);
168 if (buf[0] != '1') continue;
179 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
180 if (!strcmp(buf, "000")) {
181 goto ENDITEM; /** screw it */
182 } else if (!strncasecmp(buf, "from=", 5)) {
183 strcpy(from, &buf[5]);
185 utf8ify_rfc822_string(from);
187 } else if (!strncasecmp(buf, "subj=", 5)) {
188 strcpy(subj, &buf[5]);
190 utf8ify_rfc822_string(subj);
192 } else if (!strncasecmp(buf, "hnod=", 5)) {
193 strcpy(node, &buf[5]);
194 } else if (!strncasecmp(buf, "room=", 5)) {
195 strcpy(room, &buf[5]);
196 } else if (!strncasecmp(buf, "rfca=", 5)) {
197 strcpy(rfca, &buf[5]);
198 } else if (!strncasecmp(buf, "rcpt=", 5)) {
199 strcpy(rcpt, &buf[5]);
200 } else if (!strncasecmp(buf, "msgn=", 5)) {
201 strcpy(msgn, &buf[5]);
202 } else if (!strncasecmp(buf, "time=", 5)) {
204 gmtime_r(&now, &now_tm);
205 strftime(date, sizeof date, "%a, %d %b %Y %H:%M:%S GMT", &now_tm);
208 wprintf(" <item>\n");
210 wprintf(" <title>%s from", subj);
212 wprintf(" <title>From");
214 wprintf(" %s", from);
215 wprintf(" in %s", room);
216 if (strcmp(hnod, serv_info.serv_humannode) && strlen(hnod) > 0) {
217 wprintf(" on %s", hnod);
219 wprintf("</title>\n");
221 wprintf(" <pubDate>%s</pubDate>\n", date);
223 wprintf(" <guid isPermaLink=\"false\">%s</guid>\n", msgn);
224 /** Now the hard part, the message itself */
225 strcpy(content_type, "text/plain");
226 while (serv_getln(buf, sizeof buf), strlen(buf) > 0) {
227 if (!strcmp(buf, "000")) {
230 if (!strncasecmp(buf, "Content-type: ", 14)) {
231 safestrncpy(content_type, &buf[14], sizeof content_type);
232 for (b = 0; b < strlen(content_type); ++b) {
233 if (!strncasecmp(&content_type[b], "charset=", 8)) {
234 safestrncpy(charset, &content_type[b + 8], sizeof charset);
237 for (b = 0; b < strlen(content_type); ++b) {
238 if (content_type[b] == ';') {
245 /** Set up a character set conversion if we need to */
247 if (strcasecmp(charset, "us-ascii") && strcasecmp(charset, "utf-8") && strcasecmp(charset, "") ) {
248 ic = iconv_open("UTF-8", charset);
249 if (ic == (iconv_t)(-1)) {
250 lprintf(5, "%s:%d iconv_open() failed: %s\n",
251 __FILE__, __LINE__, strerror(errno));
257 /** Messages in legacy Citadel variformat get handled thusly... */
258 if (!strcasecmp(content_type, "text/x-citadel-variformat")) {
261 wprintf(" <description><![CDATA[");
263 serv_getln(buf, sizeof buf);
264 if (!strcmp(buf, "000")) {
266 wprintf("</blockquote>");
270 if (intext == 1 && isspace(buf[0])) {
274 if (bq == 0 && !strncmp(buf, " >", 2)) {
275 wprintf("<blockquote>");
277 } else if (bq == 1 && strncmp(buf, " >", 2)) {
278 wprintf("</blockquote>");
285 display_rss_control(from, subj);
286 wprintf("]]></description>\n");
288 /** Boring old 80-column fixed format text gets handled this way... */
289 else if (!strcasecmp(content_type, "text/plain")) {
290 wprintf(" <description><![CDATA[");
291 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
292 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
293 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
296 if (ic != (iconv_t)(-1) ) {
298 ibuflen = strlen(ibuf);
300 obuf = (char *) malloc(obuflen);
302 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
303 osav[SIZ-obuflen] = 0;
304 safestrncpy(buf, osav, sizeof buf);
309 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
310 buf[strlen(buf) - 1] = 0;
312 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
313 wprintf("<blockquote>");
315 } else if ((bq == 1) &&
316 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
317 wprintf("</blockquote>");
323 wprintf("</tt><br />\n");
325 display_rss_control(from, subj);
326 wprintf("]]></description>\n");
328 /** HTML is fun, but we've got to strip it first */
329 else if (!strcasecmp(content_type, "text/html")) {
330 wprintf(" <description><![CDATA[");
331 output_html(charset, 0);
332 wprintf("]]></description>\n");
336 wprintf(" </item>\n");
342 wprintf(" </channel>\n");