source: main/trunk/greenstone2/runtime-src/src/recpt/rssaction.cpp@ 28899

Last change on this file since 28899 was 28899, checked in by ak19, 10 years ago

Third commit for security, for ensuring cgiargs macros are websafe. This time all the changes to the runtime action classes.

  • Property svn:executable set to *
File size: 5.4 KB
Line 
1/**********************************************************************
2 *
3 * rssaction.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 *********************************************************************/
25
26#include "gsdl_modules_cfg.h"
27#ifdef USE_RSS
28
29#include "fileutil.h"
30
31#include "rssaction.h"
32
33rssaction::rssaction () {
34 // this action uses cgi variable "a"
35 cgiarginfo arg_ainfo;
36 arg_ainfo.shortname = "a";
37 arg_ainfo.longname = "action";
38 arg_ainfo.multiplechar = true;
39 arg_ainfo.multiplevalue = false;
40 arg_ainfo.defaultstatus = cgiarginfo::weak;
41 arg_ainfo.argdefault = "rss";
42 arg_ainfo.savedarginfo = cgiarginfo::must;
43
44 argsinfo.addarginfo (NULL, arg_ainfo);
45
46}
47
48void rssaction::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
49 response_t &response, text_t &response_data,
50 ostream &/*logout*/) {
51 response = content;
52 response_data = "application/rdf+xml";
53}
54
55void rssaction::generate_rss_header( displayclass &disp,
56 outconvertclass &outconvert, ostream &textout,
57 ostream &logout)
58{
59 textout << outconvert << disp
60 << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
61 << "<rss version=\"2.0\"\n"
62 << "xmlns:content=\"http://purl.org/rss/1.0/modules/content/\"\n"
63 << " xmlns:taxo=\"http://purl.org/rss/1.0/modules/taxonomy/\"\n"
64 << " xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"
65 << " xmlns:syn=\"http://purl.org/rss/1.0/modules/syndication/\"\n"
66 << " xmlns:admin=\"http://webns.net/mvcb/\">\n"
67
68 << "<channel>\n"
69 << " <title>_collectionname_</title>\n"
70 << " <link>_httpdomain__httppageabout_</link>\n"
71 << " <description>_collectionextra_</description>\n"
72 << " <language>_cgiarglHtmlsafe_</language>\n"
73 << " <pubDate>Thu, 23 Aug 1999 07:00:00 GMT</pubDate>\n"
74 << " <lastBuildDate>Thu, 23 Aug 1999 16:20:26 GMT</lastBuildDate>\n"
75 << " <managingEditor>_creator_</managingEditor>\n"
76 << " <webMaster>_maintainer_</webMaster>\n"
77
78 << "<image>\n"
79 << " <title>_collectionname_</title>\n"
80 << " <url>_iconcollection_</url>\n"
81 << " <link>_httpdomain__httppageabout_</link>\n"
82 << " <description>_collectionextra_</description>\n"
83 << "</image>\n";
84}
85
86void rssaction::generate_rss_content(text_t& rss_items, displayclass &disp,
87 outconvertclass &outconvert, ostream &textout,
88 ostream &logout)
89{
90 textout << outconvert << disp << rss_items;
91}
92
93void rssaction::generate_rss_footer( displayclass &disp,
94 outconvertclass &outconvert, ostream &textout,
95 ostream &logout)
96{
97
98 textout << outconvert << disp
99 << " </channel>\n"
100 << "</rss>\n";
101}
102
103
104bool rssaction::do_action (cgiargsclass &args, recptprotolistclass *protos,
105 browsermapclass * /*browsers*/, displayclass& disp,
106 outconvertclass &outconvert, ostream &textout,
107 ostream &logout) {
108 text_t rss_items;
109 bool success = false;
110 comerror_t err;
111
112 text_t &arg_c = args["c"];
113
114
115 // Before resolving the _httpdomain_ macro
116 // 1. Check if _httpdomain_ was defined by user in macros (packages rssfeed of rss.dm and Global).
117 // E.g. user could have defined it in package Global of zextra.dm
118 // If none found, try to get it from the cgiargs hostname= (set using javascript),
119 // and set as macro for the desired package (e.g. package rss). Setting httpdomain in package Global.
120 // If the httpdomain macro needs to be in package rss, then need to mention this macro as
121 // "_rss:httpdomain_" not "_httpdomain_" throughout rss-items.
122 // If ever adding a custom macro file like rss.dm that mentions the package, need to list rss.dm in etc/main.cfg
123
124 if(disp.havemacro("Global", "httpdomain") == 0) { // if using rss package, will check rss and Global packages in order. And if not found:
125
126 if(!args["hostname"].empty()) {
127 disp.setmacro("httpdomain", "Global", "http://" + encodeForURL(args["hostname"]));
128 }
129 else { // we shouldn't have to get here
130 disp.setmacro("httpdomain", "Global", "http://localhost:8282"); // the default used in zextra.dm. (Could perhaps default this to localhost too)
131 }
132 }
133
134
135 if (!args["c"].empty()) {
136 recptproto* collectproto = protos->getrecptproto (arg_c, logout);
137 if (collectproto != NULL) {
138 collectproto->get_rss_items (arg_c, gsdlhome, rss_items, err, logout);
139 if (err == noError) success = true;
140 // else a communication error
141 }
142 }
143
144 generate_rss_header(disp,outconvert,textout,logout);
145 if(success) {
146 generate_rss_content(rss_items,disp,outconvert,textout,logout);
147 }
148 generate_rss_footer(disp,outconvert,textout,logout);
149
150 return success;
151};
152
153#endif //USE_RSS
Note: See TracBrowser for help on using the repository browser.