00001
00002
00003
00009 #include "webcit.h"
00010 #include "webserver.h"
00011
00012
00013 time_t if_modified_since;
00020 void display_rss_control(char *reply_to, char *subject)
00021 {
00022 wprintf("<div style=\"align: right;\"><p>\n");
00023 wprintf("<a href=\"display_enter?recp=");
00024 urlescputs(reply_to);
00025 wprintf("&subject=");
00026 if (strncasecmp(subject, "Re: ", 3)) wprintf("Re:%20");
00027 urlescputs(subject);
00028 wprintf("\">[%s]</a> \n", _("Reply"));
00029 wprintf("<a href=\"display_enter?recp=");
00030 urlescputs(reply_to);
00031 wprintf("&force_room=_MAIL_&subject=");
00032 if (strncasecmp(subject, "Re: ", 3)) wprintf("Re:%20");
00033 urlescputs(subject);
00034 wprintf("\">[%s]</a>\n", _("Email"));
00035 wprintf("</p></div>\n");
00036 }
00037
00038
00044 void display_rss(char *roomname, char *request_method)
00045 {
00046 int nummsgs;
00047 int a, b;
00048 int bq = 0;
00049 time_t now = 0L;
00050 struct tm now_tm;
00051 #ifdef HAVE_ICONV
00052 iconv_t ic = (iconv_t)(-1) ;
00053 char *ibuf;
00054 char *obuf;
00055 size_t ibuflen;
00056 size_t obuflen;
00057 char *osav;
00058 #endif
00059 char buf[SIZ];
00060 char date[30];
00061 char from[256];
00062 char subj[256];
00063 char node[256];
00064 char hnod[256];
00065 char room[256];
00066 char rfca[256];
00067 char rcpt[256];
00068 char msgn[256];
00069 char content_type[256];
00070 char charset[256];
00071
00072 if (!WC->logged_in) {
00073 authorization_required(_("Not logged in"));
00074 return;
00075 }
00076
00077 if (gotoroom((char *)roomname)) {
00078 lprintf(3, "RSS: Can't goto requested room\n");
00079 wprintf("HTTP/1.1 404 Not Found\r\n");
00080 wprintf("Content-Type: text/html\r\n");
00081 wprintf("\r\n");
00082 wprintf("Error retrieving RSS feed: couldn't find room\n");
00083 return;
00084 }
00085
00086 nummsgs = load_msg_ptrs("MSGS LAST|15", 0);
00087 if (nummsgs == 0) {
00088 lprintf(3, "RSS: No messages found\n");
00089 wprintf("HTTP/1.1 404 Not Found\r\n");
00090 wprintf("Content-Type: text/html\r\n");
00091 wprintf("\r\n");
00092 wprintf(_("Error retrieving RSS feed: couldn't find messages\n"));
00093 return;
00094 }
00095
00097 serv_printf("MSG4 %ld", WC->msgarr[nummsgs - 1]);
00098 serv_getln(buf, sizeof buf);
00099 if (buf[0] == '1') {
00100 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "000")) {
00101 if (!strncasecmp(buf, "msgn=", 5)) {
00102 strcpy(msgn, &buf[5]);
00103 }
00104 if (!strncasecmp(buf, "time=", 5)) {
00105 now = atol(&buf[5]);
00106 gmtime_r(&now, &now_tm);
00107 strftime(date, sizeof date, "%a, %d %b %Y %H:%M:%S GMT", &now_tm);
00108 }
00109 }
00110 }
00111
00112 if (if_modified_since > 0 && if_modified_since > now) {
00113 lprintf(3, "RSS: Feed not updated since the last time you looked\n");
00114 wprintf("HTTP/1.1 304 Not Modified\r\n");
00115 wprintf("Last-Modified: %s\r\n", date);
00116 now = time(NULL);
00117 gmtime_r(&now, &now_tm);
00118 strftime(date, sizeof date, "%a, %d %b %Y %H:%M:%S GMT", &now_tm);
00119 wprintf("Date: %s\r\n", date);
00120
00121 wDumpContent(0);
00122 return;
00123 }
00124
00125
00126 lprintf(3, "RSS: Yum yum! This feed is tasty!\n");
00127 wprintf("HTTP/1.1 200 OK\r\n");
00128 wprintf("Last-Modified: %s\r\n", date);
00129
00130 wprintf("Content-Type: application/rss+xml\r\n");
00131 wprintf("$erver: %s\r\n", SERVER);
00132 wprintf("Connection: close\r\n");
00133 wprintf("\r\n");
00134 if (!strcasecmp(request_method, "HEAD"))
00135 return;
00136
00137 wprintf("<?xml version=\"1.0\"?>\n");
00138 wprintf("<rss version=\"2.0\">\n");
00139 wprintf(" <channel>\n");
00140 wprintf(" <title>%s - %s</title>\n", WC->wc_roomname, serv_info.serv_humannode);
00141 wprintf(" <link>%s://%s:%d/dotgoto?room=", (is_https ? "https" : "http"), WC->http_host, PORT_NUM);
00142 escputs(roomname);
00143 wprintf("</link>\n");
00144 wprintf(" <description>");
00146 serv_puts("RINF");
00147 serv_getln(buf, sizeof buf);
00148 if (buf[0] == '1') {
00149 while (1) {
00150 serv_getln(buf, sizeof buf);
00151 if (!strcmp(buf, "000"))
00152 break;
00153 wprintf("%s\n", buf);
00154 }
00155 }
00156 wprintf("</description>\n");
00157 if (now) {
00158 wprintf(" <pubDate>%s</pubDate>\n", date);
00159 }
00160 wprintf(" <generator>%s</generator>\n", SERVER);
00161 wprintf(" <docs>http://blogs.law.harvard.edu/tech/rss</docs>\n");
00162 wprintf(" <ttl>30</ttl>\n");
00163
00165 for (a = 0; a < nummsgs; ++a) {
00167 serv_printf("MSG4 %ld", WC->msgarr[a]);
00168 serv_getln(buf, sizeof buf);
00169 if (buf[0] != '1') continue;
00170
00171 now = 0L;
00172 strcpy(subj, "");
00173 strcpy(hnod, "");
00174 strcpy(node, "");
00175 strcpy(room, "");
00176 strcpy(rfca, "");
00177 strcpy(rcpt, "");
00178 strcpy(msgn, "");
00179
00180 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
00181 if (!strcmp(buf, "000")) {
00182 goto ENDITEM;
00183 } else if (!strncasecmp(buf, "from=", 5)) {
00184 strcpy(from, &buf[5]);
00185 #ifdef HAVE_ICONV
00186 utf8ify_rfc822_string(from);
00187 #endif
00188 } else if (!strncasecmp(buf, "subj=", 5)) {
00189 strcpy(subj, &buf[5]);
00190 #ifdef HAVE_ICONV
00191 utf8ify_rfc822_string(subj);
00192 #endif
00193 } else if (!strncasecmp(buf, "hnod=", 5)) {
00194 strcpy(node, &buf[5]);
00195 } else if (!strncasecmp(buf, "room=", 5)) {
00196 strcpy(room, &buf[5]);
00197 } else if (!strncasecmp(buf, "rfca=", 5)) {
00198 strcpy(rfca, &buf[5]);
00199 } else if (!strncasecmp(buf, "rcpt=", 5)) {
00200 strcpy(rcpt, &buf[5]);
00201 } else if (!strncasecmp(buf, "msgn=", 5)) {
00202 strcpy(msgn, &buf[5]);
00203 } else if (!strncasecmp(buf, "time=", 5)) {
00204 now = atol(&buf[5]);
00205 gmtime_r(&now, &now_tm);
00206 strftime(date, sizeof date, "%a, %d %b %Y %H:%M:%S GMT", &now_tm);
00207 }
00208 }
00209 wprintf(" <item>\n");
00210 if (subj[0]) {
00211 wprintf(" <title>%s from", subj);
00212 } else {
00213 wprintf(" <title>From");
00214 }
00215 wprintf(" %s", from);
00216 wprintf(" in %s", room);
00217 if (strcmp(hnod, serv_info.serv_humannode) && strlen(hnod) > 0) {
00218 wprintf(" on %s", hnod);
00219 }
00220 wprintf("</title>\n");
00221 if (now) {
00222 wprintf(" <pubDate>%s</pubDate>\n", date);
00223 }
00224 wprintf(" <guid isPermaLink=\"false\">%s</guid>\n", msgn);
00226 strcpy(content_type, "text/plain");
00227 while (serv_getln(buf, sizeof buf), strlen(buf) > 0) {
00228 if (!strcmp(buf, "000")) {
00229 goto ENDBODY;
00230 }
00231 if (!strncasecmp(buf, "Content-type: ", 14)) {
00232 safestrncpy(content_type, &buf[14], sizeof content_type);
00233 for (b = 0; b < strlen(content_type); ++b) {
00234 if (!strncasecmp(&content_type[b], "charset=", 8)) {
00235 safestrncpy(charset, &content_type[b + 8], sizeof charset);
00236 }
00237 }
00238 for (b = 0; b < strlen(content_type); ++b) {
00239 if (content_type[b] == ';') {
00240 content_type[b] = 0;
00241 }
00242 }
00243 }
00244 }
00245
00247 #ifdef HAVE_ICONV
00248 if (strcasecmp(charset, "us-ascii") && strcasecmp(charset, "utf-8") && strcasecmp(charset, "") ) {
00249 ic = ctdl_iconv_open("UTF-8", charset);
00250 if (ic == (iconv_t)(-1)) {
00251 lprintf(5, "%s:%d iconv_open() failed: %s\n",
00252 __FILE__, __LINE__, strerror(errno));
00253 goto ENDBODY;
00254 }
00255 }
00256 #endif
00257
00259 if (!strcasecmp(content_type, "text/x-citadel-variformat")) {
00260 int intext = 0;
00261
00262 wprintf(" <description><![CDATA[");
00263 while (1) {
00264 serv_getln(buf, sizeof buf);
00265 if (!strcmp(buf, "000")) {
00266 if (bq == 1)
00267 wprintf("</blockquote>");
00268 wprintf("\n");
00269 break;
00270 }
00271 if (intext == 1 && isspace(buf[0])) {
00272 wprintf("<br/>");
00273 }
00274 intext = 1;
00275 if (bq == 0 && !strncmp(buf, " >", 2)) {
00276 wprintf("<blockquote>");
00277 bq = 1;
00278 } else if (bq == 1 && strncmp(buf, " >", 2)) {
00279 wprintf("</blockquote>");
00280 bq = 0;
00281 }
00282 url(buf);
00283 escputs(buf);
00284 wprintf("\n");
00285 }
00286 display_rss_control(from, subj);
00287 wprintf("]]></description>\n");
00288 }
00290 else if (!strcasecmp(content_type, "text/plain")) {
00291 wprintf(" <description><![CDATA[");
00292 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
00293 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
00294 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
00295
00296 #ifdef HAVE_ICONV
00297 if (ic != (iconv_t)(-1) ) {
00298 ibuf = buf;
00299 ibuflen = strlen(ibuf);
00300 obuflen = SIZ;
00301 obuf = (char *) malloc(obuflen);
00302 osav = obuf;
00303 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
00304 osav[SIZ-obuflen] = 0;
00305 safestrncpy(buf, osav, sizeof buf);
00306 free(osav);
00307 }
00308 #endif
00309
00310 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
00311 buf[strlen(buf) - 1] = 0;
00312 if ((bq == 0) &&
00313 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
00314 wprintf("<blockquote>");
00315 bq = 1;
00316 } else if ((bq == 1) &&
00317 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
00318 wprintf("</blockquote>");
00319 bq = 0;
00320 }
00321 wprintf("<tt>");
00322 url(buf);
00323 escputs(buf);
00324 wprintf("</tt><br />\n");
00325 }
00326 display_rss_control(from, subj);
00327 wprintf("]]></description>\n");
00328 }
00330 else if (!strcasecmp(content_type, "text/html")) {
00331 wprintf(" <description><![CDATA[");
00332 output_html(charset, 0);
00333 wprintf("]]></description>\n");
00334 }
00335
00336 ENDBODY:
00337 wprintf(" </item>\n");
00338 ENDITEM:
00339 now = 0L;
00340 }
00341
00343 wprintf(" </channel>\n");
00344 wprintf("</rss>\n");
00345 wDumpContent(0);
00346 }
00347
00348