4 * Generate some RSS for our rooms.
11 time_t if_modified_since;
14 void display_rss(const char *roomname)
21 iconv_t ic = (iconv_t)(-1) ;
22 char *ibuf; /* Buffer of characters to be converted */
23 char *obuf; /* Buffer for converted characters */
24 size_t ibuflen; /* Length of input buffer */
25 size_t obuflen; /* Length of output buffer */
26 char *osav; /* Saved pointer to output buffer */
37 char content_type[256];
41 authorization_required("Not logged in");
45 if (gotoroom(roomname)) {
46 wprintf("HTTP/1.0 404 Not Found\r\n");
47 wprintf("Content-Type: text/html\r\n");
49 wprintf("Error retrieving RSS feed: couldn't find room or messages\n");
53 nummsgs = load_msg_ptrs("MSGS LAST|15", 0);
55 wprintf("HTTP/1.0 404 Not Found\r\n");
56 wprintf("Content-Type: text/html\r\n");
58 wprintf("Error retrieving RSS feed: couldn't find room or messages\n");
62 /* Read time of last message immediately */
63 serv_printf("MSG4 %ld", WC->msgarr[nummsgs - 1]);
64 serv_getln(buf, sizeof buf);
66 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "000")) {
67 if (!strncasecmp(buf, "msgn=", 5)) {
68 strcpy(msgn, &buf[5]);
70 if (!strncasecmp(buf, "time=", 5)) {
72 gmtime_r(&now, &now_tm);
73 strftime(date, sizeof date, "%a, %d %b %Y %H:%M:%S GMT", &now_tm);
78 lprintf(3, "If modified since %ld Last modified %ld\n", if_modified_since, now);
79 if (if_modified_since > 0 && if_modified_since > now) {
80 wprintf("HTTP/1.0 304 Not Modified\r\n");
81 wprintf("Last-Modified: %s\r\n", date);
83 gmtime_r(&now, &now_tm);
84 strftime(date, sizeof date, "%a, %d %b %Y %H:%M:%S GMT", &now_tm);
85 wprintf("Date: %s\r\n", date);
86 /* if (*msgn) wprintf("ETag: %s\r\n\r\n", msgn); */
92 wprintf("HTTP/1.0 200 OK\r\n");
93 wprintf("Last-Modified: %s\r\n", date);
94 /* if (*msgn) wprintf("ETag: %s\r\n\r\n", msgn); */
95 wprintf("Content-Type: application/rss+xml\r\n");
96 wprintf("$erver: %s\r\n", SERVER);
97 wprintf("Connection: close\r\n");
99 if (!strcasecmp(request_method, "HEAD"))
102 wprintf("<?xml version=\"1.0\"?>\n");
103 wprintf("<rss version=\"2.0\">\n");
104 wprintf(" <channel>\n");
105 wprintf(" <title>%s - %s</title>\n", WC->wc_roomname, serv_info.serv_humannode);
106 wprintf(" <link>%s://%s:%d/dotgoto?room=", (is_https ? "https" : "http"), WC->http_host, PORT_NUM);
108 wprintf("</link>\n");
109 wprintf(" <description>");
110 /* Get room info for description */
112 serv_getln(buf, sizeof buf);
115 serv_getln(buf, sizeof buf);
116 if (!strcmp(buf, "000"))
121 wprintf("</description>\n");
123 wprintf(" <pubDate>%s</pubDate>\n", date);
125 wprintf(" <generator>%s</generator>\n", SERVER);
126 wprintf(" <docs>http://blogs.law.harvard.edu/tech/rss</docs>\n");
127 wprintf(" <ttl>30</ttl>\n");
129 /* Read all messages and output as RSS items */
130 for (a = 0; a < nummsgs; ++a) {
131 /* Read message and output each as RSS item */
132 serv_printf("MSG4 %ld", WC->msgarr[a]);
133 serv_getln(buf, sizeof buf);
134 if (buf[0] != '1') continue;
145 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
146 if (!strcmp(buf, "000")) {
147 goto ENDITEM; /* screw it */
148 } else if (!strncasecmp(buf, "from=", 5)) {
149 strcpy(from, &buf[5]);
151 utf8ify_rfc822_string(from);
153 } else if (!strncasecmp(buf, "subj=", 5)) {
154 strcpy(subj, &buf[5]);
156 utf8ify_rfc822_string(subj);
158 } else if (!strncasecmp(buf, "hnod=", 5)) {
159 strcpy(node, &buf[5]);
160 } else if (!strncasecmp(buf, "room=", 5)) {
161 strcpy(room, &buf[5]);
162 } else if (!strncasecmp(buf, "rfca=", 5)) {
163 strcpy(rfca, &buf[5]);
164 } else if (!strncasecmp(buf, "rcpt=", 5)) {
165 strcpy(rcpt, &buf[5]);
166 } else if (!strncasecmp(buf, "msgn=", 5)) {
167 strcpy(msgn, &buf[5]);
168 } else if (!strncasecmp(buf, "time=", 5)) {
170 gmtime_r(&now, &now_tm);
171 strftime(date, sizeof date, "%a, %d %b %Y %H:%M:%S GMT", &now_tm);
174 wprintf(" <item>\n");
176 wprintf(" <title>%s from", subj);
178 wprintf(" <title>From");
180 wprintf(" %s", from);
181 wprintf(" in %s", room);
182 if (strcmp(hnod, serv_info.serv_humannode) && strlen(hnod) > 0) {
183 wprintf(" on %s", hnod);
185 wprintf("</title>\n");
187 wprintf(" <pubDate>%s</pubDate>\n", date);
189 wprintf(" <guid isPermaLink=\"false\">%s</guid>\n", msgn);
190 /* Now the hard part, the message itself */
191 strcpy(content_type, "text/plain");
192 while (serv_getln(buf, sizeof buf), strlen(buf) > 0) {
193 if (!strcmp(buf, "000")) {
196 if (!strncasecmp(buf, "Content-type: ", 14)) {
197 safestrncpy(content_type, &buf[14], sizeof content_type);
198 for (b = 0; b < strlen(content_type); ++b) {
199 if (!strncasecmp(&content_type[b], "charset=", 8)) {
200 safestrncpy(charset, &content_type[b + 8], sizeof charset);
203 for (b = 0; b < strlen(content_type); ++b) {
204 if (content_type[b] == ';') {
211 /* Set up a character set conversion if we need to */
213 if (strcasecmp(charset, "us-ascii") && strcasecmp(charset, "utf-8")) {
214 ic = iconv_open("UTF-8", charset);
215 if (ic == (iconv_t)(-1)) {
216 lprintf(5, "iconv_open() failed: %s\n", strerror(errno));
222 /* Messages in legacy Citadel variformat get handled thusly... */
223 if (!strcasecmp(content_type, "text/x-citadel-variformat")) {
226 wprintf(" <description><![CDATA[");
228 serv_getln(buf, sizeof buf);
229 if (!strcmp(buf, "000")) {
231 wprintf("</blockquote>");
235 if (intext == 1 && isspace(buf[0])) {
239 if (bq == 0 && !strncmp(buf, " >", 2)) {
240 wprintf("<blockquote>");
242 } else if (bq == 1 && strncmp(buf, " >", 2)) {
243 wprintf("</blockquote>");
250 wprintf("]]></description>\n");
252 /* Boring old 80-column fixed format text gets handled this way... */
253 else if (!strcasecmp(content_type, "text/plain")) {
254 wprintf(" <description><![CDATA[");
255 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
256 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
257 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
260 if (ic != (iconv_t)(-1) ) {
262 ibuflen = strlen(ibuf);
264 obuf = (char *) malloc(obuflen);
266 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
267 osav[SIZ-obuflen] = 0;
268 safestrncpy(buf, osav, sizeof buf);
273 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
274 buf[strlen(buf) - 1] = 0;
276 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
277 wprintf("<blockquote>");
279 } else if ((bq == 1) &&
280 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
281 wprintf("</blockquote>");
287 wprintf("</tt><br />\n");
289 wprintf("]]></description>\n");
291 /* HTML is fun, but we've got to strip it first */
292 else if (!strcasecmp(content_type, "text/html")) {
293 wprintf(" <description><![CDATA[");
294 output_html(charset);
295 wprintf("]]></description>\n");
299 wprintf(" </item>\n");
305 wprintf(" </channel>\n");