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 "converter.h"
|
---|
35 | #include "cfgread.h"
|
---|
36 | #include "action.h"
|
---|
37 | #include "cnfgable.h"
|
---|
38 |
|
---|
39 | // the MACROPRECEDENCE macro is used as a default. override
|
---|
40 | // it using something like:
|
---|
41 | //
|
---|
42 | // macroprecedence c,l
|
---|
43 | //
|
---|
44 | // in your configuration file
|
---|
45 | #ifndef MACROPRECEDENCE
|
---|
46 | #define MACROPRECEDENCE "l"
|
---|
47 | #endif
|
---|
48 |
|
---|
49 | struct languageinfo_t {
|
---|
50 | void clear();
|
---|
51 | languageinfo_t () {clear();}
|
---|
52 |
|
---|
53 | text_t longname;
|
---|
54 | text_t defaultencoding;
|
---|
55 | };
|
---|
56 |
|
---|
57 | typedef map<text_t, languageinfo_t, lttext_t> languageinfo_tmap;
|
---|
58 | enum ldformat_t {LocalTime, UTCTime, Absolute};
|
---|
59 |
|
---|
60 | struct recptconf {
|
---|
61 | text_t gsdlhome;
|
---|
62 | text_t gdbmhome; // will equal gsdlhome if not set
|
---|
63 | text_t httpprefix;
|
---|
64 | text_t httpimg; // will equal /images if not set
|
---|
65 | text_t gwcgi;
|
---|
66 | text_tset macrofiles;
|
---|
67 | text_t saveconf;
|
---|
68 | bool usecookies; // true if we want cookies set
|
---|
69 | bool logcgiargs; // true if we want to log cgi arguments
|
---|
70 |
|
---|
71 | ldformat_t LogDateFormat;
|
---|
72 |
|
---|
73 | text_tmap pageparams;
|
---|
74 | text_t macroprecedence;
|
---|
75 |
|
---|
76 | languageinfo_tmap languages;
|
---|
77 | text_tmap encodings;
|
---|
78 |
|
---|
79 | void clear ();
|
---|
80 | recptconf () {clear();}
|
---|
81 | };
|
---|
82 |
|
---|
83 | class receptionist : public configurable {
|
---|
84 | protected:
|
---|
85 |
|
---|
86 | recptconf configinfo;
|
---|
87 |
|
---|
88 | cgiargsinfoclass argsinfo;
|
---|
89 | actionmapclass actions;
|
---|
90 | displayclass disp;
|
---|
91 | convertinfoclass converters;
|
---|
92 |
|
---|
93 | virtual void prepare_page (action *a, cgiargsclass &args,
|
---|
94 | outconvertclass &outconvert,
|
---|
95 | ostream &logout);
|
---|
96 |
|
---|
97 | bool get_cookie (text_t &cookie);
|
---|
98 | bool get_cookie ();
|
---|
99 |
|
---|
100 | // get the default encoding for the given language - if it fails for any
|
---|
101 | // reason, return ""
|
---|
102 | text_t get_default_encoding (const text_t &language);
|
---|
103 |
|
---|
104 | virtual void define_general_macros (cgiargsclass &args, outconvertclass &outconvert,
|
---|
105 | ostream &logout);
|
---|
106 |
|
---|
107 | bool append_logstr (const text_t &filename, const text_t &logstr,
|
---|
108 | ostream &logout);
|
---|
109 |
|
---|
110 | virtual void configure_encoding (const text_tarray &cfgline);
|
---|
111 |
|
---|
112 | public:
|
---|
113 | receptionist ();
|
---|
114 | virtual ~receptionist() {}
|
---|
115 |
|
---|
116 | // add_action makes another action available to the receptionist
|
---|
117 | // the action remains the property of the calling code and that
|
---|
118 | // code should destroy the action after the recptionist has been
|
---|
119 | // destroyed.
|
---|
120 | void add_action (action *theaction);
|
---|
121 | actionmapclass *get_actionmap_ptr () {return &actions;}
|
---|
122 |
|
---|
123 | // add_converter makes another converter available to the receptionist.
|
---|
124 | // Converters are needed to display pages using different encodings.
|
---|
125 | // The converters remain the property of the calling code.
|
---|
126 | void add_converter (const text_t &name, inconvertclass *inconverter,
|
---|
127 | rzwsoutconvertclass *outconverter) {
|
---|
128 | converters.add_converter(name, inconverter, outconverter);}
|
---|
129 | convertinfoclass *get_convertinfo_ptr () {return &converters;}
|
---|
130 |
|
---|
131 |
|
---|
132 | // configure should be called for each line in the
|
---|
133 | // configuration files to configure the receptionist and everything
|
---|
134 | // it contains. The configuration should take place after everything
|
---|
135 | // has been added but before the initialisation.
|
---|
136 | void configure (const text_t &key, const text_tarray &cfgline);
|
---|
137 | virtual void configure (const text_t &key, const text_t &value);
|
---|
138 | const recptconf &get_configinfo () const {return configinfo;}
|
---|
139 | cgiargsinfoclass *get_cgiargsinfo_ptr () {return &argsinfo;}
|
---|
140 |
|
---|
141 | virtual bool init (ostream &logout);
|
---|
142 |
|
---|
143 | virtual bool parse_cgi_args (const text_t &argstr, cgiargsclass &args,
|
---|
144 | ostream &logout);
|
---|
145 |
|
---|
146 | virtual bool log_cgi_args (cgiargsclass &args, ostream &logout);
|
---|
147 |
|
---|
148 | text_t expandmacros (const text_t &astring, cgiargsclass &args,
|
---|
149 | ostream &logout);
|
---|
150 |
|
---|
151 | // produce_cgi_page will call get_cgihead_info and
|
---|
152 | // produce_content in the appropriate way to output a cgi header and
|
---|
153 | // the page content (if needed). If a page could not be created it
|
---|
154 | // will return false
|
---|
155 | virtual bool produce_cgi_page (cgiargsclass &args, ostream &contentout,
|
---|
156 | ostream &logout);
|
---|
157 |
|
---|
158 | // get_cgihead_info determines the cgi header information for
|
---|
159 | // a set of cgi arguments. If response contains location then
|
---|
160 | // response_data contains the redirect address. If reponse
|
---|
161 | // contains content then reponse_data contains the content-type.
|
---|
162 | // Note that images can now be produced by the receptionist.
|
---|
163 | virtual void get_cgihead_info (cgiargsclass &args, response_t &response,
|
---|
164 | text_t &response_data, ostream &logout);
|
---|
165 |
|
---|
166 | // produce the page content
|
---|
167 | virtual bool produce_content (cgiargsclass &args, ostream &contentout,
|
---|
168 | ostream &logout);
|
---|
169 |
|
---|
170 | // returns the compressed argument ("e") corresponding to the argument
|
---|
171 | // list. This can be used to save preferences between sessions.
|
---|
172 | virtual text_t get_compressed_arg (cgiargsclass &args, ostream &logout);
|
---|
173 |
|
---|
174 | protected:
|
---|
175 | // will read in all the macro files. If one is not found an
|
---|
176 | // error message will be written to logout and the method will
|
---|
177 | // return false.
|
---|
178 | virtual bool read_macrofiles (ostream &logout);
|
---|
179 |
|
---|
180 | };
|
---|
181 |
|
---|
182 |
|
---|
183 | #endif
|
---|