source: gsdl/trunk/src/recpt/receptionist.h@ 16310

Last change on this file since 16310 was 16310, checked in by davidb, 16 years ago

Introduction of 'collecthome' which parallels 'gsdlhome' to allow the toplevel collect folder to be outside of the gsdlhome area

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