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

Last change on this file since 1856 was 1856, checked in by sjboddie, 23 years ago

Added Encoding and Language options to main.cfg configuration file so
it's now hopefully a little easier to add new languages and encodings
to the interface. Each interface language also now has a default encoding
so that changing languages from the preferences page causes the encoding
to change to a value reasonable for the selected language.

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