source: main/trunk/greenstone2/runtime-src/src/recpt/action.cpp@ 28760

Last change on this file since 28760 was 22231, checked in by mdewsnip, 14 years ago

Fix assert() failure that looks like a segmentation fault when users enter "a=" (without any action name).

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