source: trunk/gsdl/src/recpt/action.cpp@ 540

Last change on this file since 540 was 540, checked in by rjmcnab, 25 years ago

got rid of some compiler warnings

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 KB
Line 
1/**********************************************************************
2 *
3 * action.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 * $Id: action.cpp 540 1999-09-07 23:04:03Z rjmcnab $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
30 Revision 1.17 1999/09/07 23:04:03 rjmcnab
31 got rid of some compiler warnings
32
33 Revision 1.16 1999/09/07 04:56:51 sjboddie
34 added GPL notice
35
36 Revision 1.15 1999/09/03 09:51:47 rjmcnab
37 removed the argdefault configuration option (it should now be
38 done with cgiarg)
39
40 Revision 1.14 1999/09/02 00:22:42 rjmcnab
41 Changes to get it compiling on AIX
42
43 Revision 1.13 1999/07/30 02:24:43 sjboddie
44 added collectinfo argument to some functions
45
46 Revision 1.12 1999/07/10 22:15:30 rjmcnab
47 Added function check_external_cgiargs so that actions that
48 are not being called can override cgi arguments.
49
50 Revision 1.11 1999/06/08 04:29:41 sjboddie
51 added argsinfo to the call to check_cgiargs to make it easy to set
52 args to their default if they're found to be screwed up
53
54 Revision 1.10 1999/03/25 03:06:44 sjboddie
55
56 altered receptionist slightly so it now passes *collectproto to
57 define_internal_macros and define_external_macros - need it
58 for browseaction
59
60 Revision 1.9 1999/02/28 23:16:00 rjmcnab
61
62 Fixed a compiler warning.
63
64 Revision 1.8 1999/02/28 20:00:11 rjmcnab
65
66
67 Fixed a few things.
68
69 Revision 1.7 1999/02/25 21:58:58 rjmcnab
70
71 Merged sources.
72
73 Revision 1.6 1999/02/21 22:33:52 rjmcnab
74
75 Lots of stuff :-)
76
77 Revision 1.5 1999/02/11 01:24:04 rjmcnab
78
79 Fixed a few compiler warnings.
80
81 Revision 1.4 1999/02/08 01:27:59 rjmcnab
82
83 Got the receptionist producing something using the statusaction.
84
85 Revision 1.3 1999/02/05 10:42:41 rjmcnab
86
87 Continued working on receptionist
88
89 Revision 1.2 1999/02/04 10:00:53 rjmcnab
90
91 Developed the idea of an "action" and having them define the cgi arguments
92 which they need and how those cgi arguments function.
93
94 Revision 1.1 1999/01/08 08:40:52 rjmcnab
95
96 Moved from lib directory.
97
98 Revision 1.1 1999/01/08 03:57:44 rjmcnab
99
100 Initial revision
101
102 */
103
104
105#include "action.h"
106#include <assert.h>
107
108
109// define all the macros which are related to pages generated
110// by this action
111void action::define_internal_macros (const ColInfoResponse_t &/*collectinfo*/, displayclass &/*disp*/,
112 cgiargsclass &/*args*/, recptproto * /*collectproto*/,
113 ostream &/*logout*/) {
114}
115
116action::action () {
117}
118
119action::~action () {
120}
121
122// configure should be called once for each configuration line
123// the default version does nothing
124void action::configure (const text_t &/*key*/, const text_tarray &/*cfgline*/) {
125}
126
127// init should be called after all the configuration is done but
128// before any other methods are called
129bool action::init (ostream &/*logout*/) {
130 return true;
131}
132
133// returns the "a" argument value that will specify this action
134// this name should be short but does not have to be one character
135// long
136text_t action::get_action_name () {
137 return "nzdl";
138}
139
140// check_cgiargs should be called before get_cgihead_info,
141// define_external_macros, and do_action. If an error is found
142// a message will be written to logout, if the error is severe
143// then the function will return false and no page content
144// should be produced based on the arguments.
145bool action::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
146 ostream &/*logout*/) {
147 return true;
148}
149
150// check_external_cgiargs should be called after check_cgiargs
151// for all actions. It should only be used to override some other
152// normal behaviour, for example, producing a login page when
153// the requested page needs authentication.
154bool action::check_external_cgiargs (cgiargsinfoclass &/*argsinfo*/,
155 cgiargsclass &/*args*/,
156 outconvertclass &/*outconvert*/,
157 const text_t &/*saveconf*/,
158 ostream &/*logout*/) {
159 return true;
160}
161
162// get_cgihead_info determines the cgi header information for
163// a set of cgi arguments. If response contains location then
164// response_data contains the redirect address. If reponse
165// contains content then reponse_data contains the content-type.
166// Note that images can now be produced by the receptionist.
167void action::get_cgihead_info (cgiargsclass &/*args*/, response_t &response,
168 text_t &response_data, ostream &/*logout*/) {
169 response = location;
170 response_data = "http://www.nzdl.org";
171}
172
173// uses_display should return true if the receptionist should return
174// true if the display class is needed to output the page content
175// The default is to return true.
176bool action::uses_display (cgiargsclass &/*args*/) {
177 return true;
178}
179
180
181// define all the macros which might be used by other actions
182// to produce pages. These macros should be well documented.
183void action::define_external_macros (const ColInfoResponse_t &/*collectinfo*/, displayclass &/*disp*/,
184 cgiargsclass &/*args*/, recptproto * /*collectproto*/,
185 ostream &/*logout*/) {
186}
187
188// returns false if there was an error which prevented the action
189// from outputing anything.
190bool action::do_action (cgiargsclass &/*args*/, const ColInfoResponse_t &/*collectinfo*/,
191 recptproto * /*collectproto*/, displayclass &/*disp*/,
192 outconvertclass &/*outconvert*/, ostream &/*textout*/,
193 ostream &/*logout*/) {
194 return true;
195}
196
197
198bool operator==(const actionptr &x, const actionptr &y) {
199 return (x.a == y.a);
200}
201
202bool operator<(const actionptr &x, const actionptr &y) {
203 return (x.a < y.a);
204}
205
206
207// theaction remains the property of the calling code but
208// should not be deleted until it is removed from this list.
209void actionmapclass::addaction (action *theaction) {
210 // can't add a null action
211 assert (theaction != NULL);
212 if (theaction == NULL) return;
213
214 // can't add an action with no name
215 assert (!(theaction->get_action_name()).empty());
216 if ((theaction->get_action_name()).empty()) return;
217
218 actionptr aptr;
219 aptr.a = theaction;
220 actionptrs[theaction->get_action_name()] = aptr;
221}
222
223// getaction will return NULL if the action could not be found
224action *actionmapclass::getaction (const text_t &key) {
225 // can't find an action with no name
226 assert (!key.empty());
227 if (key.empty()) return NULL;
228
229 iterator here = actionptrs.find (key);
230 if (here == actionptrs.end()) return NULL;
231
232 return (*here).second.a;
233}
234
Note: See TracBrowser for help on using the repository browser.