[108] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * action.h --
|
---|
| 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 |
|
---|
| 27 | #ifndef ACTION_H
|
---|
| 28 | #define ACTION_H
|
---|
| 29 |
|
---|
[146] | 30 | #include "gsdlconf.h"
|
---|
| 31 | #include "text_t.h"
|
---|
| 32 | #include "cgiargs.h"
|
---|
[155] | 33 | #include "display.h"
|
---|
[165] | 34 | #include "recptproto.h"
|
---|
[754] | 35 | #include "browserclass.h"
|
---|
[108] | 36 |
|
---|
[146] | 37 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
| 38 | # include <ospace\std\iostream>
|
---|
| 39 | #elif defined(GSDL_USE_IOS_H)
|
---|
| 40 | # include <iostream.h>
|
---|
| 41 | #else
|
---|
| 42 | # include <iostream>
|
---|
| 43 | #endif
|
---|
[108] | 44 |
|
---|
| 45 |
|
---|
[146] | 46 | class action {
|
---|
| 47 | protected:
|
---|
| 48 | cgiargsinfoclass argsinfo;
|
---|
[962] | 49 | text_t gsdlhome;
|
---|
[2212] | 50 | text_t gdbmhome;
|
---|
[146] | 51 |
|
---|
| 52 | public:
|
---|
| 53 | action ();
|
---|
| 54 | virtual ~action ();
|
---|
| 55 |
|
---|
[165] | 56 | // configure should be called once for each configuration line
|
---|
| 57 | virtual void configure (const text_t &key, const text_tarray &cfgline);
|
---|
| 58 |
|
---|
| 59 | // init should be called after all the configuration is done but
|
---|
| 60 | // before any other methods are called
|
---|
| 61 | virtual bool init (ostream &logout);
|
---|
| 62 |
|
---|
[146] | 63 | // returns the "a" argument value that will specify this action
|
---|
| 64 | // this name should be short but does not have to be one character
|
---|
| 65 | // long
|
---|
| 66 | virtual text_t get_action_name ();
|
---|
| 67 |
|
---|
[155] | 68 | // check_cgiargs should be called before get_cgihead_info,
|
---|
| 69 | // define_external_macros, and do_action. If an error is found
|
---|
| 70 | // a message will be written to logout, if the error is severe
|
---|
| 71 | // then the function will return false and no page content
|
---|
| 72 | // should be produced based on the arguments.
|
---|
[261] | 73 | virtual bool check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
|
---|
[3546] | 74 | recptprotolistclass *protos, ostream &logout);
|
---|
[146] | 75 |
|
---|
[361] | 76 | // check_external_cgiargs should be called after check_cgiargs
|
---|
| 77 | // for all actions. It should only be used to override some other
|
---|
| 78 | // normal behaviour, for example, producing a login page when
|
---|
| 79 | // the requested page needs authentication.
|
---|
| 80 | virtual bool check_external_cgiargs (cgiargsinfoclass &argsinfo,
|
---|
| 81 | cgiargsclass &args,
|
---|
| 82 | outconvertclass &outconvert,
|
---|
| 83 | const text_t &saveconf,
|
---|
| 84 | ostream &logout);
|
---|
| 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 | virtual void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
|
---|
| 92 | response_t &response, text_t &response_data,
|
---|
| 93 | ostream &logout);
|
---|
[146] | 94 |
|
---|
[173] | 95 | // uses_display should return true if the receptionist should return
|
---|
| 96 | // true if the display class is needed to output the page content.
|
---|
| 97 | // The default is to return true.
|
---|
| 98 | virtual bool uses_display (cgiargsclass &args);
|
---|
| 99 |
|
---|
| 100 | // define all the macros which are related to pages generated
|
---|
| 101 | // by this action
|
---|
[754] | 102 | virtual void define_internal_macros (displayclass &disp, cgiargsclass &args,
|
---|
| 103 | recptprotolistclass *protos, ostream &logout);
|
---|
[173] | 104 |
|
---|
[155] | 105 | // define all the macros which might be used by other actions
|
---|
| 106 | // to produce pages. These macros should be well documented.
|
---|
[754] | 107 | virtual void define_external_macros (displayclass &disp, cgiargsclass &args,
|
---|
| 108 | recptprotolistclass *protos, ostream &logout);
|
---|
[155] | 109 |
|
---|
[146] | 110 | // returns false if there was an error which prevented the action
|
---|
| 111 | // from outputing anything.
|
---|
[754] | 112 | virtual bool do_action (cgiargsclass &args, recptprotolistclass *protos,
|
---|
| 113 | browsermapclass *browsers, displayclass &disp,
|
---|
[421] | 114 | outconvertclass &outconvert, ostream &textout,
|
---|
| 115 | ostream &logout);
|
---|
[165] | 116 |
|
---|
[146] | 117 | // getargsinfo should be called after all configuration files
|
---|
| 118 | // have been read
|
---|
| 119 | cgiargsinfoclass getargsinfo () {return argsinfo;};
|
---|
| 120 | };
|
---|
| 121 |
|
---|
| 122 |
|
---|
[165] | 123 | // The actionptr function does not 'own' the action. The
|
---|
| 124 | // action should be deleted by the code which created it.
|
---|
[146] | 125 | class actionptr {
|
---|
| 126 | public:
|
---|
| 127 | action *a;
|
---|
| 128 |
|
---|
| 129 | actionptr () {a=NULL;}
|
---|
| 130 | };
|
---|
| 131 |
|
---|
[506] | 132 | bool operator==(const actionptr &x, const actionptr &y);
|
---|
| 133 | bool operator<(const actionptr &x, const actionptr &y);
|
---|
| 134 |
|
---|
[146] | 135 | typedef map<text_t, actionptr, lttext_t> actionptrmap;
|
---|
| 136 |
|
---|
| 137 | // contains a list of actions indexed by their name
|
---|
| 138 | class actionmapclass {
|
---|
| 139 | protected:
|
---|
| 140 | actionptrmap actionptrs;
|
---|
| 141 |
|
---|
| 142 | public:
|
---|
| 143 | // type support for actionptrmap
|
---|
| 144 | typedef actionptrmap::iterator iterator;
|
---|
| 145 | typedef actionptrmap::const_iterator const_iterator;
|
---|
| 146 | typedef actionptrmap::reference reference;
|
---|
| 147 | typedef actionptrmap::const_reference const_reference;
|
---|
| 148 | typedef actionptrmap::size_type size_type;
|
---|
| 149 |
|
---|
| 150 | typedef actionptrmap::difference_type difference_type;
|
---|
| 151 | typedef actionptrmap::const_reverse_iterator const_reverse_iterator;
|
---|
| 152 | typedef actionptrmap::reverse_iterator reverse_iterator;
|
---|
| 153 |
|
---|
| 154 | // basic container support
|
---|
| 155 | iterator begin () {return actionptrs.begin();}
|
---|
| 156 | const_iterator begin () const {return actionptrs.begin();}
|
---|
| 157 | iterator end () {return actionptrs.end();}
|
---|
| 158 | const_iterator end () const {return actionptrs.end();}
|
---|
| 159 |
|
---|
| 160 | void erase(iterator pos) {actionptrs.erase(pos);}
|
---|
| 161 | void erase(iterator first, iterator last) {actionptrs.erase(first, last);}
|
---|
| 162 | actionmapclass &operator=(const actionmapclass &x) {actionptrs=x.actionptrs;return *this;}
|
---|
| 163 |
|
---|
| 164 | bool empty () const {return actionptrs.empty();}
|
---|
| 165 | size_type size() const {return actionptrs.size();}
|
---|
| 166 |
|
---|
| 167 |
|
---|
| 168 | // added functionality
|
---|
| 169 | void clear () {actionptrs.erase(actionptrs.begin(),actionptrs.end());}
|
---|
| 170 |
|
---|
[165] | 171 | // theaction remains the property of the calling code but
|
---|
| 172 | // should not be deleted until it is removed from this list.
|
---|
[146] | 173 | void addaction (action *theaction);
|
---|
| 174 |
|
---|
| 175 | // getaction will return NULL if the action could not be found
|
---|
| 176 | action *getaction (const text_t &key);
|
---|
| 177 | };
|
---|
| 178 |
|
---|
| 179 |
|
---|
[108] | 180 | #endif
|
---|