source: main/trunk/greenstone2/runtime-src/src/recpt/receptionist.h

Last change on this file was 39000, checked in by kjdon, 6 weeks ago

the usecookies option has been renamed to usecookiesForUID to better reflect what it means. A new option usecookiesForE is added. If this is set to true (the default), then the e arg will be saved as a cookie, instead of being set into the various compressedoptions macros (which will now be empty). nzdl.org is getting hammered by bots, and one theory is that the e arg changes everytime so looks like a new page when its not.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 10.5 KB
Line 
1/**********************************************************************
2 *
3 * receptionist.h -- a web interface for the gsdl
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
27#ifndef RECEPTIONIST_H
28#define RECEPTIONIST_H
29
30#include "gsdlconf.h"
31#include "text_t.h"
32#include "cgiargs.h"
33#include "display.h"
34#include "browserclass.h"
35#include "recptproto.h"
36#include "converter.h"
37#include "cfgread.h"
38#include "action.h"
39#include "cnfgable.h"
40
41// the MACROPRECEDENCE macro is used as a default. override
42// it using something like:
43//
44// macroprecedence c,l
45//
46// in your configuration file
47#ifndef MACROPRECEDENCE
48#define MACROPRECEDENCE "c,l"
49#endif
50
51
52struct collectioninfo_t {
53 void clear ();
54 collectioninfo_t () {clear();}
55
56 text_t gsdl_gsdlhome;
57 text_t gsdl_collecthome;
58 text_t gsdl_dbhome;
59
60 bool info_loaded;
61 ColInfoResponse_t info;
62};
63
64struct languageinfo_t {
65 void clear();
66 languageinfo_t () {clear();}
67
68 text_t longname;
69 text_t defaultencoding;
70};
71
72typedef map<text_t, collectioninfo_t, lttext_t> colinfo_tmap;
73typedef map<text_t, languageinfo_t, lttext_t> languageinfo_tmap;
74
75enum events_t {Disabled, CollectorEvents, AllEvents};
76enum ldformat_t {LocalTime, UTCTime, Absolute};
77
78struct recptconf {
79 text_t gsdlhome;
80 text_t collecthome;
81 text_t dbhome; // will equal gsdlhome if not set
82 text_t collection; // will equal "" in 'general' mode
83 text_t collectdir; // will equal gsdlhome in 'general' mode
84 colinfo_tmap collectinfo;
85 text_t httpprefix;
86 text_t httpweb; // will be set to httpprefix/web if not set
87 text_t gwcgi;
88 text_tset macrofiles;
89 text_t saveconf;
90 bool usecookiesForUID; // true if we want to save user id as a cookie
91 bool usecookiesForE; // true if want to save the e arg as a cookie instead of passing it round as an arg
92 bool logcgiargs; // true if we want to log cgi arguments
93
94 ldformat_t LogDateFormat;
95
96 text_t maintainer; // email address of maintainer
97 text_t MailServer; // SMTP mail server to use when sending event messages by email
98 // defaults to mail.maintainer-domain
99 events_t LogEvents;
100 events_t EmailEvents;
101 bool EmailUserEvents;
102
103 bool site_auth; // Complete site authentication, useful to lockout site for example.
104 text_t site_group; // Similar to the auth_groups functionality, infact exactly the same
105
106 text_t HomePageType;
107 int HomePageCols;
108
109 text_tmap pageparams;
110 text_t macroprecedence;
111
112 languageinfo_tmap languages;
113
114 // encodings is just a simple mapping from encoding longnames to
115 // shortnames. It's useful for now for creating the pulldown menu of
116 // encodings on the preferences page but isn't intended to be permanent.
117 text_tmap encodings;
118
119 void clear ();
120 recptconf () {clear();}
121
122};
123
124class receptionist : public configurable {
125protected:
126
127 recptconf configinfo;
128
129 cgiargsinfoclass argsinfo;
130 actionmapclass actions;
131 browsermapclass browsers;
132 recptprotolistclass protocols;
133 displayclass disp;
134 convertinfoclass converters;
135 ColInfoResponse_t collectinfo;
136
137 // prepare_page sets up page parameters, sets display macros
138 // and opens the page ready for output
139 virtual void prepare_page (action *a, cgiargsclass &args,
140 outconvertclass &outconvert,
141 ostream &logout);
142
143 virtual void translate_OIDs (cgiargsclass &args, recptproto *collectproto,
144 ostream &logout);
145
146 bool get_uid_cookie (text_t &cookie, text_tmap &fcgienv);
147 bool has_uid_cookie (text_tmap &fcgienv);
148 bool get_named_cookie (text_t &cookie, const text_t cookie_name, text_tmap &fcgienv);
149
150 // get the default encoding for the given language - if it fails for any
151 // reason, return ""
152 text_t get_default_encoding (const text_t &language);
153
154 virtual void define_general_macros (cgiargsclass &args, outconvertclass &outconvert,
155 ostream &logout);
156
157 virtual bool append_logstr (const text_t &filename, const text_t &logstr,
158 ostream &logout);
159
160 virtual void configure_encoding (const text_tarray &cfgline);
161
162 public:
163 receptionist ();
164 virtual ~receptionist() {}
165
166#ifdef _APACHE_MOD
167 bool loaded;
168#endif
169 // add_action makes another action available to the receptionist
170 // the action remains the property of the calling code and that
171 // code should destroy the action after the recptionist has been
172 // destroyed.
173 void add_action (action *theaction);
174 actionmapclass *get_actionmap_ptr () {return &actions;}
175
176 // add_browser makes another browser available to the receptionist
177 // the browser remains the property of the calling code and that
178 // code should destroy it after the recptionist has been
179 // destroyed.
180 void add_browser (browserclass *thebrowser);
181 browsermapclass *get_browsermap_ptr () {return &browsers;}
182 void setdefaultbrowser (const text_t &browsername);
183
184 // add_protocol makes another protocol available to the receptionist
185 // without any protocols, no collections will be available. The
186 // protocols remain the property of the calling code.
187 void add_protocol (recptproto *theprotocol) {protocols.addrecptproto(theprotocol);}
188 recptprotolistclass *get_recptprotolist_ptr () {return &protocols;}
189
190 // add_converter makes another converter available to the receptionist.
191 // Converters are needed to display pages using different encodings.
192 // The converters remain the property of the calling code.
193 void add_converter (const text_t &name, inconvertclass *inconverter,
194 rzwsoutconvertclass *outconverter) {
195 converters.add_converter(name, inconverter, outconverter);}
196 convertinfoclass *get_convertinfo_ptr () {return &converters;}
197
198
199 // configure should be called for each line in the
200 // configuration files to configure the receptionist and everything
201 // it contains. The configuration should take place after everything
202 // has been added but before the initialisation.
203 virtual void configure (const text_t &key, const text_tarray &cfgline);
204 virtual void configure (const text_t &key, const text_t &value);
205 const recptconf &get_configinfo () const {return configinfo;}
206 cgiargsinfoclass *get_cgiargsinfo_ptr () {return &argsinfo;}
207
208
209 // init should be called after all the actions, protocols, and
210 // converters have been added to the receptionist and after everything
211 // has been configured but before any pages are created.
212 // It returns true on success and false on failure. If false is
213 // returned getpage should not be called (without producing
214 // meaningless output), instead an error page should be
215 // produced by the calling code.
216 virtual bool init (ostream &logout);
217
218 // There are two ways to produce a page. You can either call parse_cgi_args,
219 // get_cgihead_info, and produce_content or you can just call parse_cgi_args and
220 // produce_cgi_page (which will be satisfactory in most cases). You might want to call
221 // parse_cgi_args, get_cgihead_info, and produce_content when you want to
222 // interface directly with a web server for which the standard header is inappropriate.
223
224 // parse_cgi_args parses cgi arguments into an argument class.
225 // This function should be called for each page request. It returns false
226 // if there was a major problem with the cgi arguments.
227 virtual bool parse_cgi_args (const text_t &argstr,
228 fileupload_tmap &fileuploads,
229 cgiargsclass &args,
230 ostream &logout, text_tmap &fcgienv);
231
232 virtual bool log_cgi_args (cgiargsclass &args, ostream &logout, text_tmap &fcgienv);
233
234 text_t expandmacros (const text_t &astring, cgiargsclass &args,
235 ostream &logout);
236
237 // produce_cgi_page will call get_cgihead_info and
238 // produce_content in the appropriate way to output a cgi header and
239 // the page content (if needed). If a page could not be created it
240 // will return false
241 virtual bool produce_cgi_page (cgiargsclass &args, ostream &contentout,
242 ostream &logout, text_tmap &fcgienv);
243
244 // get_cgihead_info determines the cgi header information for
245 // a set of cgi arguments. If response contains location then
246 // response_data contains the redirect address. If reponse
247 // contains content then reponse_data contains the content-type.
248 // Note that images can now be produced by the receptionist.
249 virtual void get_cgihead_info (cgiargsclass &args, response_t &response,
250 text_t &response_data, ostream &logout,
251 text_tmap &fcgienv);
252 virtual void get_cgihead_info (cgiargsclass &args, text_tmap &headers,
253 ostream &logout, text_tmap &fcgienv);
254
255 // produce the page content
256 virtual bool produce_content (cgiargsclass &args, ostream &contentout,
257 ostream &logout);
258
259 // returns the compressed argument ("e") corresponding to the argument
260 // list. This can be used to save preferences between sessions.
261 virtual text_t get_compressed_arg (cgiargsclass &args, ostream &logout);
262
263 // gets collection info from cache if found or
264 // calls collection server (and updates cache)
265 // returns NULL if there's an error
266 ColInfoResponse_t *get_collectinfo_ptr (recptproto *collectproto,
267 const text_t &collection,
268 ostream &logout);
269
270 void uncache_collection (const text_t &collection);
271
272protected:
273 // will read in all the macro files. If one is not found an
274 // error message will be written to logout and the method will
275 // return false.
276 virtual bool read_macrofiles (ostream &logout);
277
278 virtual void read_collection_macrofiles (const text_t& collection, ostream &logout);
279
280 // check_mainargs will check all the main arguments. If a major
281 // error is found it will return false and no cgi page should
282 // be created using the arguments.
283 virtual bool check_mainargs (cgiargsclass &args, ostream &logout);
284};
285
286
287#endif
Note: See TracBrowser for help on using the repository browser.