2 * RSS feed generator (could be adapted in the future to feed both RSS and Atom)
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")) {
48 else if (!strncasecmp(buf, "subj=", 5)) {
51 wc_printf("</title>");
54 else if (!strncasecmp(buf, "exti=", 5)) {
59 else if (!strncasecmp(buf, "time=", 5)) {
60 http_datestring(pubdate, sizeof pubdate, atol(&buf[5]));
61 wc_printf("<pubDate>%s</pubDate>", pubdate);
63 else if (!strncasecmp(buf, "text", 4)) {
65 wc_printf("<title>Message #%ld</title>", msgnum);
67 wc_printf("<description>");
73 wc_printf("</description>");
80 * RSS feed generator -- go through the message list
82 void feed_rss_do_messages(void) {
86 SharedMessageStatus Stat;
87 message_summary *Msg = NULL;
89 memset(&Stat, 0, sizeof Stat);
90 Stat.maxload = INT_MAX;
91 Stat.lowest_found = (-1);
92 Stat.highest_found = (-1);
93 num_msgs = load_msg_ptrs("MSGS ALL", &Stat, NULL);
94 if (num_msgs < 1) return;
96 i = num_msgs; /* convention is to feed newest-to-oldest */
98 Msg = GetMessagePtrAt(i-1, WCC->summ);
100 feed_rss_one_message(Msg->msgnum);
108 * Entry point for RSS feed generator
110 void feed_rss(void) {
113 output_headers(0, 0, 0, 0, 1, 0);
114 hprintf("Content-type: text/xml\r\n");
116 "Server: %s / %s\r\n"
117 "Connection: close\r\n"
119 PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software)
123 wc_printf("<?xml version=\"1.0\"?>"
124 "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">"
128 wc_printf("<title>");
129 escputs(ChrPtr(WC->CurRoom.name));
130 wc_printf("</title>");
133 urlescputs(ChrPtr(site_prefix));
134 wc_printf("</link>");
137 serv_getln(buf, sizeof buf);
139 wc_printf("<description>\r\n");
140 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
144 wc_printf("</description>");
147 wc_printf("<image><title>");
148 escputs(ChrPtr(WC->CurRoom.name));
149 wc_printf("</title><url>");
150 urlescputs(ChrPtr(site_prefix));
151 wc_printf("/image?name=_roompic_?gotofirst=");
152 urlescputs(ChrPtr(WC->CurRoom.name));
153 wc_printf("</url><link>");
154 urlescputs(ChrPtr(site_prefix));
155 wc_printf("</link></image>\r\n");
157 feed_rss_do_messages();
159 wc_printf("</channel>"
169 * Offer the RSS feed meta tag for this room
171 void tmplput_rssmeta(StrBuf *Target, WCTemplputParams *TP)
174 char feed_link[1024];
175 char encoded_link[1024];
177 strcpy(feed_link, "/feed_rss?gotofirst=");
178 urlesc(&feed_link[20], sizeof(feed_link) - 20, (char *)ChrPtr(WCC->CurRoom.name) );
179 CtdlEncodeBase64(encoded_link, feed_link, strlen(feed_link), 0);
181 StrBufAppendPrintf(Target,
182 "<link rel=\"alternate\" title=\"RSS\" href=\"/B64%s\" type=\"application/rss+xml\">",
189 * Offer the RSS feed button for this room
191 void tmplput_rssbutton(StrBuf *Target, WCTemplputParams *TP)
194 char feed_link[1024];
195 char encoded_link[1024];
197 strcpy(feed_link, "/feed_rss?gotofirst=");
198 urlesc(&feed_link[20], sizeof(feed_link) - 20, (char *)ChrPtr(WCC->CurRoom.name) );
199 CtdlEncodeBase64(encoded_link, feed_link, strlen(feed_link), 0);
201 StrBufAppendPrintf(Target, "<a type-\"application/rss+xml\" href=\"/B64%s\">", encoded_link);
202 StrBufAppendPrintf(Target, "<img border=\"0\" src=\"static/rss_16x.png\">");
203 StrBufAppendPrintf(Target, "</a>");
211 WebcitAddUrlHandler(HKEY("feed_rss"), "", 0, feed_rss, ANONYMOUS|COOKIEUNNEEDED);
212 RegisterNamespace("THISROOM:FEED:RSS", 0, 0, tmplput_rssbutton, NULL, CTX_NONE);
213 RegisterNamespace("THISROOM:FEED:RSSMETA", 0, 0, tmplput_rssmeta, NULL, CTX_NONE);