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

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

Added function check_external_cgiargs so that actions that
are not being called can override cgi arguments.

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