2 * RSS/Atom feed generator
4 * Copyright (c) 2010 by the citadel.org team
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "webserver.h"
26 * RSS feed generator -- do one message
28 void feed_rss_one_message(long msgnum) {
34 serv_printf("MSG0 %ld", msgnum); /* FIXME we want msg4 eventually */
35 serv_getln(buf, sizeof buf);
36 if (buf[0] != '1') return;
39 wc_printf("<link>%s/readfwd?gotofirst=", ChrPtr(site_prefix));
40 urlescputs(ChrPtr(WC->CurRoom.name));
41 wc_printf("?start_reading_at=%ld</link>", msgnum);
43 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
47 else if (!strncasecmp(buf, "subj=", 5)) {
50 wc_printf("</title>");
53 else if (!strncasecmp(buf, "exti=", 5)) {
58 else if (!strncasecmp(buf, "time=", 5)) {
59 http_datestring(pubdate, sizeof pubdate, atol(&buf[5]));
60 wc_printf("<pubDate>%s</pubDate>", pubdate);
62 else if (!strncasecmp(buf, "text", 4)) {
64 wc_printf("<title>Message #%ld</title>", msgnum);
66 wc_printf("<description>");
72 wc_printf("</description>");
79 * RSS feed generator -- go through the message list
81 void feed_rss_do_messages(void) {
85 int num_msgs_alloc = 0;
88 serv_puts("MSGP text/html|text/plain"); /* identify our preferred mime types */
89 serv_getln(buf, sizeof buf); /* don't care about the result */
91 serv_puts("MSGS ALL"); /* ask for all messages in the room */
92 serv_getln(buf, sizeof buf);
93 if (buf[0] != '1') return;
95 while (serv_getln(buf, sizeof buf), strcmp(buf, "000"))
97 if (num_msgs >= num_msgs_alloc) {
98 num_msgs_alloc += 1024;
99 msgs = realloc(msgs, num_msgs_alloc*sizeof(long) );
101 msgs[num_msgs++] = atol(buf);
104 i = num_msgs; /* convention is to feed newest-to-oldest */
106 feed_rss_one_message(msgs[i-1]);
115 * Entry point for RSS feed generator
117 void feed_rss(void) {
119 output_headers(0, 0, 0, 1, 1, 0);
120 hprintf("Content-type: text/xml\r\n");
122 "Server: %s / %s\r\n"
123 "Connection: close\r\n"
125 PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software)
129 wc_printf("<?xml version=\"1.0\"?>"
130 "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">"
134 wc_printf("<title>");
135 escputs(ChrPtr(WC->CurRoom.name));
136 wc_printf("</title>");
139 urlescputs(ChrPtr(site_prefix));
140 wc_printf("</link>");
142 // <language>en-us</language>
143 // <description>Linux Today News Service</description>
144 // <atom:link href="http://linuxtoday.com/biglt.rss" rel="self" type="application/rss+xml" />
147 // <title>Linux Today</title>
148 // <url>http://linuxtoday.com/pics/ltnet.png</url>
149 // <link>http://linuxtoday.com</link>
152 feed_rss_do_messages();
154 wc_printf("</channel>"
160 end_webcit_session();
168 WebcitAddUrlHandler(HKEY("feed_rss"), "", 0, feed_rss, ANONYMOUS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);