source: branches/New_Config_Format-branch/gsdl/src/recpt/receptionist.h@ 1279

Last change on this file since 1279 was 1279, checked in by sjboddie, 24 years ago

merged changes to trunk into New_Config_Format branch

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