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