source: trunk/gsdl/src/recpt/librarymain.cpp@ 1860

Last change on this file since 1860 was 1860, checked in by cs025, 23 years ago

Included CORBA branch for first time

  • Property svn:keywords set to Author Date Id Revision
File size: 12.3 KB
Line 
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#include "collectserver.h"
33#include "filter.h"
34#include "browsefilter.h"
35#include "mgqueryfilter.h"
36#include "mgppqueryfilter.h"
37#include "infodbclass.h"
38#include "mggdbmsource.h"
39#include "mgsearch.h"
40#include "mgppsearch.h"
41#include "fileutil.h"
42#include "collectset.h"
43#include <assert.h>
44
45#include "action.h"
46#include "statusaction.h"
47#include "pageaction.h"
48#include "pingaction.h"
49#include "queryaction.h"
50#include "documentaction.h"
51#include "authenaction.h"
52#include "usersaction.h"
53#include "extlinkaction.h"
54#include "delhistoryaction.h"
55#include "tipaction.h"
56#include "collectoraction.h"
57
58#include "browserclass.h"
59#include "vlistbrowserclass.h"
60#include "hlistbrowserclass.h"
61#include "datelistbrowserclass.h"
62#include "invbrowserclass.h"
63#include "pagedbrowserclass.h"
64#include "htmlbrowserclass.h"
65#include "phindbrowserclass.h"
66
67#include "recptconfig.h"
68
69int main () {
70 receptionist recpt;
71 nullproto nproto;
72 collectset *cservers;
73#ifndef __WIN32__
74 z3950proto zproto;
75#endif
76 text_t gsdlhome;
77
78 cservers = new collectset(gsdlhome);
79
80 // GRB: removed 7/9/2000; perhaps needs to be here!site_cfg_read (gsdlhome);
81
82 // set up the null protocol
83 nproto.set_collectset(cservers);
84
85 // configure the receptionist server list
86 cservers->setReceptionistServers(recpt, gsdlhome);
87
88
89 /*
90 text_t collectdir = filename_cat (gsdlhome, "collect");
91 text_tarray collections;
92 read_dir (collectdir, collections);
93
94 text_tarray::const_iterator thiscol = collections.begin();
95 text_tarray::const_iterator endcol = collections.end();
96
97 while (thiscol != endcol) {
98
99 // ignore the modelcol
100 if (*thiscol == "modelcol") {
101 thiscol ++;
102 continue;
103 }
104
105 // create collection server and add to null protocol
106 nproto.add_collection (*thiscol, &recpt, gsdlhome, gsdlhome);
107
108 confin.close();
109// #endif ? does this tie in with a WIN32 ifdef?
110
111 collectserver *cserver = new collectserver();
112 gdbmclass *gdbmhandler = new gdbmclass();
113
114 // add a null filter
115 filterclass *filter = new filterclass ();
116 cserver->add_filter (filter);
117
118 // add a browse filter
119 browsefilterclass *browsefilter = new browsefilterclass();
120 browsefilter->set_gdbmptr (gdbmhandler);
121
122 cserver->add_filter (browsefilter);
123
124 if (buildtype == "mg") {
125 mgsearchclass *mgsearch = new mgsearchclass();
126
127 // add a query filter
128 mgqueryfilterclass *queryfilter = new mgqueryfilterclass();
129 queryfilter->set_gdbmptr (gdbmhandler);
130 queryfilter->set_mgsearchptr (mgsearch);
131 cserver->add_filter (queryfilter);
132
133 // add a mg and gdbm source
134 mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass ();
135 mggdbmsource->set_gdbmptr (gdbmhandler);
136 mggdbmsource->set_mgsearchptr (mgsearch);
137 cserver->add_source (mggdbmsource);
138 }
139#ifndef __WIN32__
140
141 else if (buildtype == "mgpp") {
142
143 mgppsearchclass *mgsearch = new mgppsearchclass();
144
145 // add a query filter
146 mgppqueryfilterclass *queryfilter = new mgppqueryfilterclass();
147 queryfilter->set_gdbmptr (gdbmhandler);
148 queryfilter->set_mgsearchptr (mgsearch);
149 cserver->add_filter (queryfilter);
150
151 // add a mg and gdbm source
152 mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass ();
153 mggdbmsource->set_gdbmptr (gdbmhandler);
154 mggdbmsource->set_mgsearchptr (mgsearch);
155 cserver->add_source (mggdbmsource);
156
157 }
158#endif
159
160 // inform collection server and everything it contains about its
161 // collection name
162 cserver->configure ("collection", *thiscol);
163
164 // configure receptionist's collectinfo structure
165 text_tarray colinfo;
166 colinfo.push_back (*thiscol);
167 colinfo.push_back (gsdlhome);
168 colinfo.push_back (gsdlhome);
169 recpt.configure ("collectinfo", colinfo);
170
171 nproto.add_collectserver (cserver);
172 thiscol ++;
173 }
174 */
175
176 // add the protocol to the receptionist
177 recpt.add_protocol (&nproto);
178
179 // z39.50 stuff - johnmcp
180
181 // z39.50 stuff - johnmcp
182#ifndef __WIN32__
183 // add the z39.50 server information. Read in the file
184 // etc/recpt/z3950.cfg for list of servers and their databases.
185 text_t z3950cfg = filename_cat (gsdlhome, "etc");
186 z3950cfg = filename_cat (z3950cfg, "recpt");
187 z3950cfg = filename_cat (z3950cfg, "z3950.cfg");
188#ifdef USE_FASTCGI
189 // currently can't use z39.50 if fastcgi is in use
190 if (0) {
191#else
192 if (file_exists(z3950cfg)) {
193#endif
194 text_t z3950err = filename_cat (gsdlhome, "etc", "z3950log.txt");
195 zproto.read_config_file(z3950cfg,z3950err);
196 // only add this protocol if we have any servers configured.
197 if (zproto.getServerCount()>0)
198 recpt.add_protocol (&zproto);
199 }
200#endif
201
202 // Read main.cfg to get all the "Encoding" lines and add corresponding converters.
203 // It might be possible to move this to somewhere like receptionist::configure, depending
204 // on whether we need the converters before then (I don't think we do).
205 text_tarray cfgline;
206 text_t maincfg = filename_cat (gsdlhome, "etc", "main.cfg");
207 if (file_exists (maincfg)) {
208 char *maincfgc = maincfg.getcstr();
209#ifdef GSDL_USE_IOS_H
210 ifstream confin (maincfgc, ios::in | ios::nocreate);
211#else
212 ifstream confin (maincfgc, ios::in);
213#endif
214 delete maincfgc;
215
216 if (confin) {
217 text_t subkey, subvalue, shortname;
218 text_tset saved;
219 text_tmap tmp;
220 text_t::const_iterator cfglinesub_here;
221 text_tarray::const_iterator cfgline_here;
222 text_tarray::const_iterator cfgline_end;
223 while (read_cfg_line(confin, cfgline) >= 0) {
224 if (cfgline.size () >= 4 && cfgline[0] == "Encoding") {
225 tmp.erase(tmp.begin(), tmp.end());
226 cfgline_here = cfgline.begin();
227 cfgline_end = cfgline.end();
228 while (cfgline_here != cfgline_end) {
229 cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
230 (*cfgline_here).end(), '=', subkey);
231 if (subkey == "shortname") {
232 shortname = substr (cfglinesub_here, (*cfgline_here).end());
233 } else {
234 tmp[subkey] = substr (cfglinesub_here, (*cfgline_here).end());
235 }
236 cfgline_here++;
237 }
238 // we just use the saved set to prevent multiple encodings being added
239 // that use the same shortname (i.e. any encodings after the first with
240 // the same name will be ignored).
241 if (!shortname.empty() && saved.find(shortname) == saved.end()) {
242 saved.insert(shortname);
243
244 if (tmp["type"] == "UTF8") {
245 utf8inconvertclass *utf8inconvert = new utf8inconvertclass();
246 utf8outconvertclass *utf8outconvert = new utf8outconvertclass();
247 recpt.add_converter (shortname, utf8inconvert, utf8outconvert);
248
249 } else if (tmp["type"] == "GB") {
250 mapinconvertclass *gbinconvert = new mapinconvertclass();
251 gbinconvert->setmapfile (gsdlhome, "gbku", 0x25a1);
252 mapoutconvertclass *gboutconvert = new mapoutconvertclass();
253 gboutconvert->setmapfile (gsdlhome, "ugbk", 0xa1f5);
254 recpt.add_converter (shortname, gbinconvert, gboutconvert);
255
256 } else {
257 if (!tmp["mapfile"].empty()) {
258
259 if (tmp["type"] == "ISO_8859" && tmp["mapfile"] == "1.TXT") {
260 // iso-8859-1 is a special case as it'll always be
261 // supported by the standard converter class and
262 // therefore doesn't need to use its mapping file
263 inconvertclass *inconvert = new inconvertclass();
264 rzwsoutconvertclass *outconvert = new rzwsoutconvertclass();
265 recpt.add_converter (shortname, inconvert, outconvert);
266
267 } else {
268 text_t mapfile = filename_cat (gsdlhome, "unicode", "MAPPINGS", tmp["type"], tmp["mapfile"]);
269 if (file_exists (mapfile)) {
270 simplemapinconvertclass *inconvert = new simplemapinconvertclass();
271 inconvert->setmapfile (mapfile);
272 simplemapoutconvertclass *outconvert = new simplemapoutconvertclass();
273 outconvert->setmapfile (mapfile);
274 recpt.add_converter (shortname, inconvert, outconvert);
275 }
276 }
277 }
278 }
279 }
280 }
281 }
282 confin.close ();
283 }
284 }
285
286
287 // add other converters
288 // utf8inconvertclass utf8inconvert;
289 // utf8outconvertclass utf8outconvert;
290 // recpt.add_converter ("u", &utf8inconvert, &utf8outconvert);
291
292 // mapinconvertclass gbinconvert;
293 // gbinconvert.setmapfile (gsdlhome, "gbku", 0x25a1);
294 // mapoutconvertclass gboutconvert;
295 // gboutconvert.setmapfile (gsdlhome, "ugbk", 0xa1f5);
296 // recpt.add_converter ("g", &gbinconvert, &gboutconvert);
297
298 // arabic
299 // text_t mapfile = filename_cat (gsdlhome, "unicode", "MAPPINGS");
300 // mapfile = filename_cat (mapfile, "WINDOWS", "1256.TXT");
301 // simplemapinconvertclass arinconvert;
302 // arinconvert.setmapfile (mapfile);
303 // simplemapoutconvertclass aroutconvert;
304 // aroutconvert.setmapfile (mapfile);
305 // recpt.add_converter ("a", &arinconvert, &aroutconvert);
306
307 // cyrillic
308 // mapfile = filename_cat (gsdlhome, "unicode", "MAPPINGS");
309 // mapfile = filename_cat (mapfile, "WINDOWS", "1251.TXT");
310 // simplemapinconvertclass cyinconvert;
311 // cyinconvert.setmapfile (mapfile);
312 // simplemapoutconvertclass cyoutconvert;
313 // cyoutconvert.setmapfile (mapfile);
314 // recpt.add_converter ("c", &cyinconvert, &cyoutconvert);
315
316 // hindi
317// armapfile = filename_cat (gsdlhome, "unicode", "MAPPINGS");
318// armapfile = filename_cat (armapfile, "ISCII", "Devanagari.txt");
319// simplemapinconvertclass arinconvert;
320// arinconvert.setmapfile (armapfile);
321// simplemapoutconvertclass aroutconvert;
322// aroutconvert.setmapfile (armapfile);
323// recpt.add_converter ("a", &arinconvert, &aroutconvert);
324
325
326 // the list of actions. Note: these actions will become invalid
327 // at the end of this function.
328 tipaction atipaction;
329 recpt.add_action (&atipaction);
330
331 statusaction astatusaction;
332 astatusaction.set_receptionist (&recpt);
333 recpt.add_action (&astatusaction);
334
335 pageaction apageaction;
336 apageaction.set_receptionist (&recpt);
337 recpt.add_action (&apageaction);
338
339 pingaction apingaction;
340 recpt.add_action (&apingaction);
341
342 queryaction aqueryaction;
343 aqueryaction.set_receptionist (&recpt);
344 recpt.add_action (&aqueryaction);
345
346 documentaction adocumentaction;
347 adocumentaction.set_receptionist (&recpt);
348 recpt.add_action (&adocumentaction);
349
350 usersaction ausersaction;
351 recpt.add_action (&ausersaction);
352
353 extlinkaction anextlinkaction;
354 recpt.add_action (&anextlinkaction);
355
356 authenaction aauthenaction;
357 aauthenaction.set_receptionist(&recpt);
358 recpt.add_action (&aauthenaction);
359
360 delhistoryaction adelhistoryaction;
361 recpt.add_action(&adelhistoryaction);
362
363 collectoraction acollectoraction;
364 acollectoraction.set_receptionist (&recpt);
365 recpt.add_action(&acollectoraction);
366
367 // list of browsers
368 vlistbrowserclass avlistbrowserclass;
369 recpt.add_browser (&avlistbrowserclass);
370 recpt.setdefaultbrowser ("VList");
371
372 hlistbrowserclass ahlistbrowserclass;
373 recpt.add_browser (&ahlistbrowserclass);
374
375 datelistbrowserclass adatelistbrowserclass;
376 recpt.add_browser (&adatelistbrowserclass);
377
378 invbrowserclass ainvbrowserclass;
379 recpt.add_browser (&ainvbrowserclass);
380
381 pagedbrowserclass apagedbrowserclass;
382 recpt.add_browser (&apagedbrowserclass);
383
384 htmlbrowserclass ahtmlbrowserclass;
385 recpt.add_browser (&ahtmlbrowserclass);
386
387 phindbrowserclass aphindbrowserclass;
388 recpt.add_browser (&aphindbrowserclass);
389
390 cgiwrapper (recpt, "");
391 delete cservers;
392 return 0;
393}
394
Note: See TracBrowser for help on using the repository browser.