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