1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * librarymain.cpp --
|
---|
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 | #include "receptionist.h"
|
---|
27 | #include "cgiwrapper.h"
|
---|
28 | #include "fileutil.h"
|
---|
29 | #include "nullproto.h"
|
---|
30 | // z39.50 stuff - johnmcp
|
---|
31 | #include "z3950proto.h"
|
---|
32 |
|
---|
33 | #include "action.h"
|
---|
34 | #include "statusaction.h"
|
---|
35 | #include "pageaction.h"
|
---|
36 | #include "pingaction.h"
|
---|
37 | #include "queryaction.h"
|
---|
38 | #include "documentaction.h"
|
---|
39 | #include "authenaction.h"
|
---|
40 | #include "usersaction.h"
|
---|
41 | #include "extlinkaction.h"
|
---|
42 | #include "delhistoryaction.h"
|
---|
43 | #include "tipaction.h"
|
---|
44 | #include "collectoraction.h"
|
---|
45 |
|
---|
46 | #include "browserclass.h"
|
---|
47 | #include "vlistbrowserclass.h"
|
---|
48 | #include "hlistbrowserclass.h"
|
---|
49 | #include "datelistbrowserclass.h"
|
---|
50 | #include "invbrowserclass.h"
|
---|
51 | #include "pagedbrowserclass.h"
|
---|
52 | #include "htmlbrowserclass.h"
|
---|
53 | #include "phindbrowserclass.h"
|
---|
54 |
|
---|
55 | #include "recptconfig.h"
|
---|
56 |
|
---|
57 | int main () {
|
---|
58 | receptionist recpt;
|
---|
59 | nullproto nproto;
|
---|
60 | #ifndef __WIN32__
|
---|
61 | z3950proto zproto;
|
---|
62 | #endif
|
---|
63 |
|
---|
64 | text_tarray collections;
|
---|
65 |
|
---|
66 | // get gsdlhome
|
---|
67 | text_t gsdlhome;
|
---|
68 | site_cfg_read (gsdlhome);
|
---|
69 | text_t collectdir = filename_cat (gsdlhome, "collect");
|
---|
70 | read_dir (collectdir, collections);
|
---|
71 |
|
---|
72 | text_tarray::const_iterator thiscol = collections.begin();
|
---|
73 | text_tarray::const_iterator endcol = collections.end();
|
---|
74 |
|
---|
75 | while (thiscol != endcol) {
|
---|
76 |
|
---|
77 | // ignore the modelcol
|
---|
78 | if (*thiscol == "modelcol") {
|
---|
79 | thiscol ++;
|
---|
80 | continue;
|
---|
81 | }
|
---|
82 |
|
---|
83 | // create collection server and add to null protocol
|
---|
84 | nproto.add_collection (*thiscol, &recpt, gsdlhome, gsdlhome);
|
---|
85 |
|
---|
86 | thiscol ++;
|
---|
87 | }
|
---|
88 |
|
---|
89 | // add the protocol to the receptionist
|
---|
90 | recpt.add_protocol (&nproto);
|
---|
91 |
|
---|
92 | // z39.50 stuff - johnmcp
|
---|
93 | #ifndef __WIN32__
|
---|
94 | // add the z39.50 server information. Read in the file
|
---|
95 | // etc/recpt/z3950.cfg for list of servers and their databases.
|
---|
96 | text_t z3950cfg = filename_cat (gsdlhome, "etc");
|
---|
97 | z3950cfg = filename_cat (z3950cfg, "recpt");
|
---|
98 | z3950cfg = filename_cat (z3950cfg, "z3950.cfg");
|
---|
99 | #ifdef USE_FASTCGI
|
---|
100 | // currently can't use z39.50 if fastcgi is in use
|
---|
101 | if (0) {
|
---|
102 | #else
|
---|
103 | if (file_exists(z3950cfg)) {
|
---|
104 | #endif
|
---|
105 | text_t z3950err = filename_cat (gsdlhome, "etc", "z3950log.txt");
|
---|
106 | zproto.read_config_file(z3950cfg,z3950err);
|
---|
107 | // only add this protocol if we have any servers configured.
|
---|
108 | if (zproto.getServerCount()>0)
|
---|
109 | recpt.add_protocol (&zproto);
|
---|
110 | }
|
---|
111 | #endif
|
---|
112 |
|
---|
113 | // Read main.cfg to get all the "Encoding" lines and add corresponding converters.
|
---|
114 | // It might be possible to move this to somewhere like receptionist::configure, depending
|
---|
115 | // on whether we need the converters before then (I don't think we do).
|
---|
116 | text_tarray cfgline;
|
---|
117 | text_t maincfg = filename_cat (gsdlhome, "etc", "main.cfg");
|
---|
118 | if (file_exists (maincfg)) {
|
---|
119 | char *maincfgc = maincfg.getcstr();
|
---|
120 | #ifdef GSDL_USE_IOS_H
|
---|
121 | ifstream confin (maincfgc, ios::in | ios::nocreate);
|
---|
122 | #else
|
---|
123 | ifstream confin (maincfgc, ios::in);
|
---|
124 | #endif
|
---|
125 | delete maincfgc;
|
---|
126 |
|
---|
127 | if (confin) {
|
---|
128 | text_t subkey, subvalue, shortname;
|
---|
129 | text_tset saved;
|
---|
130 | text_tmap tmp;
|
---|
131 | text_t::const_iterator cfglinesub_here;
|
---|
132 | text_tarray::const_iterator cfgline_here;
|
---|
133 | text_tarray::const_iterator cfgline_end;
|
---|
134 | while (read_cfg_line(confin, cfgline) >= 0) {
|
---|
135 | if (cfgline.size () >= 4 && cfgline[0] == "Encoding") {
|
---|
136 | tmp.erase(tmp.begin(), tmp.end());
|
---|
137 | cfgline_here = cfgline.begin();
|
---|
138 | cfgline_end = cfgline.end();
|
---|
139 | while (cfgline_here != cfgline_end) {
|
---|
140 | cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
|
---|
141 | (*cfgline_here).end(), '=', subkey);
|
---|
142 | if (subkey == "shortname") {
|
---|
143 | shortname = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
144 | } else {
|
---|
145 | tmp[subkey] = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
146 | }
|
---|
147 | cfgline_here++;
|
---|
148 | }
|
---|
149 | // we just use the saved set to prevent multiple encodings being added
|
---|
150 | // that use the same shortname (i.e. any encodings after the first with
|
---|
151 | // the same name will be ignored).
|
---|
152 | if (!shortname.empty() && saved.find(shortname) == saved.end()) {
|
---|
153 | saved.insert(shortname);
|
---|
154 |
|
---|
155 | if (tmp["type"] == "UTF8") {
|
---|
156 | utf8inconvertclass *utf8inconvert = new utf8inconvertclass();
|
---|
157 | utf8outconvertclass *utf8outconvert = new utf8outconvertclass();
|
---|
158 | recpt.add_converter (shortname, utf8inconvert, utf8outconvert);
|
---|
159 |
|
---|
160 | } else if (tmp["type"] == "GB") {
|
---|
161 | mapinconvertclass *gbinconvert = new mapinconvertclass();
|
---|
162 | gbinconvert->setmapfile (gsdlhome, "gbku", 0x25a1);
|
---|
163 | mapoutconvertclass *gboutconvert = new mapoutconvertclass();
|
---|
164 | gboutconvert->setmapfile (gsdlhome, "ugbk", 0xa1f5);
|
---|
165 | recpt.add_converter (shortname, gbinconvert, gboutconvert);
|
---|
166 |
|
---|
167 | } else {
|
---|
168 | if (!tmp["mapfile"].empty()) {
|
---|
169 |
|
---|
170 | if (tmp["type"] == "ISO_8859" && tmp["mapfile"] == "1.TXT") {
|
---|
171 | // iso-8859-1 is a special case as it'll always be
|
---|
172 | // supported by the standard converter class and
|
---|
173 | // therefore doesn't need to use its mapping file
|
---|
174 | inconvertclass *inconvert = new inconvertclass();
|
---|
175 | rzwsoutconvertclass *outconvert = new rzwsoutconvertclass();
|
---|
176 | recpt.add_converter (shortname, inconvert, outconvert);
|
---|
177 |
|
---|
178 | } else {
|
---|
179 | text_t mapfile = filename_cat (gsdlhome, "unicode", "MAPPINGS", tmp["type"], tmp["mapfile"]);
|
---|
180 | if (file_exists (mapfile)) {
|
---|
181 | simplemapinconvertclass *inconvert = new simplemapinconvertclass();
|
---|
182 | inconvert->setmapfile (mapfile);
|
---|
183 | simplemapoutconvertclass *outconvert = new simplemapoutconvertclass();
|
---|
184 | outconvert->setmapfile (mapfile);
|
---|
185 | recpt.add_converter (shortname, inconvert, outconvert);
|
---|
186 | }
|
---|
187 | }
|
---|
188 | }
|
---|
189 | }
|
---|
190 | }
|
---|
191 | }
|
---|
192 | }
|
---|
193 | confin.close ();
|
---|
194 | }
|
---|
195 | }
|
---|
196 |
|
---|
197 |
|
---|
198 | // add other converters
|
---|
199 | // utf8inconvertclass utf8inconvert;
|
---|
200 | // utf8outconvertclass utf8outconvert;
|
---|
201 | // recpt.add_converter ("u", &utf8inconvert, &utf8outconvert);
|
---|
202 |
|
---|
203 | // mapinconvertclass gbinconvert;
|
---|
204 | // gbinconvert.setmapfile (gsdlhome, "gbku", 0x25a1);
|
---|
205 | // mapoutconvertclass gboutconvert;
|
---|
206 | // gboutconvert.setmapfile (gsdlhome, "ugbk", 0xa1f5);
|
---|
207 | // recpt.add_converter ("g", &gbinconvert, &gboutconvert);
|
---|
208 |
|
---|
209 | // arabic
|
---|
210 | // text_t mapfile = filename_cat (gsdlhome, "unicode", "MAPPINGS");
|
---|
211 | // mapfile = filename_cat (mapfile, "WINDOWS", "1256.TXT");
|
---|
212 | // simplemapinconvertclass arinconvert;
|
---|
213 | // arinconvert.setmapfile (mapfile);
|
---|
214 | // simplemapoutconvertclass aroutconvert;
|
---|
215 | // aroutconvert.setmapfile (mapfile);
|
---|
216 | // recpt.add_converter ("a", &arinconvert, &aroutconvert);
|
---|
217 |
|
---|
218 | // cyrillic
|
---|
219 | // mapfile = filename_cat (gsdlhome, "unicode", "MAPPINGS");
|
---|
220 | // mapfile = filename_cat (mapfile, "WINDOWS", "1251.TXT");
|
---|
221 | // simplemapinconvertclass cyinconvert;
|
---|
222 | // cyinconvert.setmapfile (mapfile);
|
---|
223 | // simplemapoutconvertclass cyoutconvert;
|
---|
224 | // cyoutconvert.setmapfile (mapfile);
|
---|
225 | // recpt.add_converter ("c", &cyinconvert, &cyoutconvert);
|
---|
226 |
|
---|
227 | // hindi
|
---|
228 | // armapfile = filename_cat (gsdlhome, "unicode", "MAPPINGS");
|
---|
229 | // armapfile = filename_cat (armapfile, "ISCII", "Devanagari.txt");
|
---|
230 | // simplemapinconvertclass arinconvert;
|
---|
231 | // arinconvert.setmapfile (armapfile);
|
---|
232 | // simplemapoutconvertclass aroutconvert;
|
---|
233 | // aroutconvert.setmapfile (armapfile);
|
---|
234 | // recpt.add_converter ("a", &arinconvert, &aroutconvert);
|
---|
235 |
|
---|
236 |
|
---|
237 | // the list of actions. Note: these actions will become invalid
|
---|
238 | // at the end of this function.
|
---|
239 | tipaction atipaction;
|
---|
240 | recpt.add_action (&atipaction);
|
---|
241 |
|
---|
242 | statusaction astatusaction;
|
---|
243 | astatusaction.set_receptionist (&recpt);
|
---|
244 | recpt.add_action (&astatusaction);
|
---|
245 |
|
---|
246 | pageaction apageaction;
|
---|
247 | apageaction.set_receptionist (&recpt);
|
---|
248 | recpt.add_action (&apageaction);
|
---|
249 |
|
---|
250 | pingaction apingaction;
|
---|
251 | recpt.add_action (&apingaction);
|
---|
252 |
|
---|
253 | queryaction aqueryaction;
|
---|
254 | aqueryaction.set_receptionist (&recpt);
|
---|
255 | recpt.add_action (&aqueryaction);
|
---|
256 |
|
---|
257 | documentaction adocumentaction;
|
---|
258 | adocumentaction.set_receptionist (&recpt);
|
---|
259 | recpt.add_action (&adocumentaction);
|
---|
260 |
|
---|
261 | usersaction ausersaction;
|
---|
262 | recpt.add_action (&ausersaction);
|
---|
263 |
|
---|
264 | extlinkaction anextlinkaction;
|
---|
265 | recpt.add_action (&anextlinkaction);
|
---|
266 |
|
---|
267 | authenaction aauthenaction;
|
---|
268 | aauthenaction.set_receptionist(&recpt);
|
---|
269 | recpt.add_action (&aauthenaction);
|
---|
270 |
|
---|
271 | delhistoryaction adelhistoryaction;
|
---|
272 | recpt.add_action(&adelhistoryaction);
|
---|
273 |
|
---|
274 | collectoraction acollectoraction;
|
---|
275 | acollectoraction.set_receptionist (&recpt);
|
---|
276 | recpt.add_action(&acollectoraction);
|
---|
277 |
|
---|
278 | // list of browsers
|
---|
279 | vlistbrowserclass avlistbrowserclass;
|
---|
280 | recpt.add_browser (&avlistbrowserclass);
|
---|
281 | recpt.setdefaultbrowser ("VList");
|
---|
282 |
|
---|
283 | hlistbrowserclass ahlistbrowserclass;
|
---|
284 | recpt.add_browser (&ahlistbrowserclass);
|
---|
285 |
|
---|
286 | datelistbrowserclass adatelistbrowserclass;
|
---|
287 | recpt.add_browser (&adatelistbrowserclass);
|
---|
288 |
|
---|
289 | invbrowserclass ainvbrowserclass;
|
---|
290 | recpt.add_browser (&ainvbrowserclass);
|
---|
291 |
|
---|
292 | pagedbrowserclass apagedbrowserclass;
|
---|
293 | recpt.add_browser (&apagedbrowserclass);
|
---|
294 |
|
---|
295 | htmlbrowserclass ahtmlbrowserclass;
|
---|
296 | recpt.add_browser (&ahtmlbrowserclass);
|
---|
297 |
|
---|
298 | phindbrowserclass aphindbrowserclass;
|
---|
299 | recpt.add_browser (&aphindbrowserclass);
|
---|
300 |
|
---|
301 | cgiwrapper (recpt, "");
|
---|
302 | return 0;
|
---|
303 | }
|
---|
304 |
|
---|