[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 | *********************************************************************/
|
---|
| 25 |
|
---|
| 26 | #include "action.h"
|
---|
[146] | 27 | #include <assert.h>
|
---|
[108] | 28 |
|
---|
| 29 |
|
---|
[155] | 30 | // define all the macros which are related to pages generated
|
---|
| 31 | // by this action
|
---|
[754] | 32 | void action::define_internal_macros (displayclass &/*disp*/, cgiargsclass &/*args*/,
|
---|
| 33 | recptprotolistclass * /*protos*/, ostream &/*logout*/) {
|
---|
[155] | 34 | }
|
---|
| 35 |
|
---|
[146] | 36 | action::action () {
|
---|
| 37 | }
|
---|
[108] | 38 |
|
---|
[146] | 39 | action::~action () {
|
---|
| 40 | }
|
---|
[108] | 41 |
|
---|
[165] | 42 | // configure should be called once for each configuration line
|
---|
[962] | 43 | void action::configure (const text_t &key, const text_tarray &cfgline) {
|
---|
[2212] | 44 | if (key == "gsdlhome") {
|
---|
| 45 | gsdlhome = cfgline[0];
|
---|
[15589] | 46 | if (dbhome.empty()) dbhome = cfgline[0];
|
---|
[2212] | 47 | }
|
---|
[15589] | 48 | if (key == "gdbmhome") {dbhome = cfgline[0];}
|
---|
[165] | 49 | }
|
---|
| 50 |
|
---|
| 51 | // init should be called after all the configuration is done but
|
---|
| 52 | // before any other methods are called
|
---|
| 53 | bool action::init (ostream &/*logout*/) {
|
---|
| 54 | return true;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
[146] | 57 | // returns the "a" argument value that will specify this action
|
---|
| 58 | // this name should be short but does not have to be one character
|
---|
| 59 | // long
|
---|
| 60 | text_t action::get_action_name () {
|
---|
| 61 | return "nzdl";
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[155] | 64 | // check_cgiargs should be called before get_cgihead_info,
|
---|
| 65 | // define_external_macros, and do_action. If an error is found
|
---|
| 66 | // a message will be written to logout, if the error is severe
|
---|
| 67 | // then the function will return false and no page content
|
---|
| 68 | // should be produced based on the arguments.
|
---|
[261] | 69 | bool action::check_cgiargs (cgiargsinfoclass &/*argsinfo*/, cgiargsclass &/*args*/,
|
---|
[3546] | 70 | recptprotolistclass * /*protos*/, ostream &/*logout*/) {
|
---|
[155] | 71 | return true;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[361] | 74 | // check_external_cgiargs should be called after check_cgiargs
|
---|
| 75 | // for all actions. It should only be used to override some other
|
---|
| 76 | // normal behaviour, for example, producing a login page when
|
---|
| 77 | // the requested page needs authentication.
|
---|
| 78 | bool action::check_external_cgiargs (cgiargsinfoclass &/*argsinfo*/,
|
---|
| 79 | cgiargsclass &/*args*/,
|
---|
| 80 | outconvertclass &/*outconvert*/,
|
---|
[7432] | 81 | const text_t &/*saveconf*/,
|
---|
[361] | 82 | ostream &/*logout*/) {
|
---|
| 83 | return true;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[146] | 86 | // get_cgihead_info determines the cgi header information for
|
---|
| 87 | // a set of cgi arguments. If response contains location then
|
---|
| 88 | // response_data contains the redirect address. If reponse
|
---|
| 89 | // contains content then reponse_data contains the content-type.
|
---|
| 90 | // Note that images can now be produced by the receptionist.
|
---|
[754] | 91 | void action::get_cgihead_info (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
|
---|
| 92 | response_t &response, text_t &response_data,
|
---|
| 93 | ostream &/*logout*/) {
|
---|
[146] | 94 | response = location;
|
---|
| 95 | response_data = "http://www.nzdl.org";
|
---|
| 96 | }
|
---|
| 97 |
|
---|
[173] | 98 | // uses_display should return true if the receptionist should return
|
---|
| 99 | // true if the display class is needed to output the page content
|
---|
| 100 | // The default is to return true.
|
---|
[177] | 101 | bool action::uses_display (cgiargsclass &/*args*/) {
|
---|
[173] | 102 | return true;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 |
|
---|
[155] | 106 | // define all the macros which might be used by other actions
|
---|
| 107 | // to produce pages. These macros should be well documented.
|
---|
[754] | 108 | void action::define_external_macros (displayclass &/*disp*/, cgiargsclass &/*args*/,
|
---|
| 109 | recptprotolistclass * /*protos*/, ostream &/*logout*/) {
|
---|
[155] | 110 | }
|
---|
| 111 |
|
---|
[146] | 112 | // returns false if there was an error which prevented the action
|
---|
| 113 | // from outputing anything.
|
---|
[754] | 114 | bool action::do_action (cgiargsclass &/*args*/, recptprotolistclass * /*protos*/,
|
---|
| 115 | browsermapclass * /*browsers*/, displayclass &/*disp*/,
|
---|
[421] | 116 | outconvertclass &/*outconvert*/, ostream &/*textout*/,
|
---|
| 117 | ostream &/*logout*/) {
|
---|
[146] | 118 | return true;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 |
|
---|
[506] | 122 | bool operator==(const actionptr &x, const actionptr &y) {
|
---|
| 123 | return (x.a == y.a);
|
---|
| 124 | }
|
---|
[146] | 125 |
|
---|
[506] | 126 | bool operator<(const actionptr &x, const actionptr &y) {
|
---|
| 127 | return (x.a < y.a);
|
---|
| 128 | }
|
---|
[172] | 129 |
|
---|
[506] | 130 |
|
---|
[165] | 131 | // theaction remains the property of the calling code but
|
---|
| 132 | // should not be deleted until it is removed from this list.
|
---|
[146] | 133 | void actionmapclass::addaction (action *theaction) {
|
---|
| 134 | // can't add a null action
|
---|
| 135 | assert (theaction != NULL);
|
---|
| 136 | if (theaction == NULL) return;
|
---|
| 137 |
|
---|
| 138 | // can't add an action with no name
|
---|
| 139 | assert (!(theaction->get_action_name()).empty());
|
---|
| 140 | if ((theaction->get_action_name()).empty()) return;
|
---|
| 141 |
|
---|
| 142 | actionptr aptr;
|
---|
| 143 | aptr.a = theaction;
|
---|
| 144 | actionptrs[theaction->get_action_name()] = aptr;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | // getaction will return NULL if the action could not be found
|
---|
| 148 | action *actionmapclass::getaction (const text_t &key) {
|
---|
[165] | 149 | // can't find an action with no name
|
---|
| 150 | assert (!key.empty());
|
---|
| 151 | if (key.empty()) return NULL;
|
---|
| 152 |
|
---|
[146] | 153 | iterator here = actionptrs.find (key);
|
---|
| 154 | if (here == actionptrs.end()) return NULL;
|
---|
| 155 |
|
---|
| 156 | return (*here).second.a;
|
---|
| 157 | }
|
---|