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

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

Fixed a couple of little bugs in the collector - bugs only showed up
when using a persistent version of the library (i.e. the local library
or fastcgi)

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