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

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

Made windows ignore the existence of mgpp until it has been ported
properly

  • Property svn:keywords set to Author Date Id Revision
File size: 8.6 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 "nullproto.h"
29// z39.50 stuff - johnmcp
30#include "z3950proto.h"
31#include "collectserver.h"
32#include "filter.h"
33#include "browsefilter.h"
34#include "mgqueryfilter.h"
35#include "mgppqueryfilter.h"
36#include "infodbclass.h"
37#include "mggdbmsource.h"
38#include "mgsearch.h"
39#include "mgppsearch.h"
40#include "fileutil.h"
41#include <assert.h>
42
43#include "action.h"
44#include "statusaction.h"
45#include "pageaction.h"
46#include "pingaction.h"
47#include "queryaction.h"
48#include "documentaction.h"
49#include "authenaction.h"
50#include "usersaction.h"
51#include "extlinkaction.h"
52#include "buildaction.h"
53#include "delhistoryaction.h"
54#include "tipaction.h"
55#include "collectoraction.h"
56
57#include "browserclass.h"
58#include "vlistbrowserclass.h"
59#include "hlistbrowserclass.h"
60#include "datelistbrowserclass.h"
61#include "invbrowserclass.h"
62#include "pagedbrowserclass.h"
63#include "htmlbrowserclass.h"
64
65#include "recptconfig.h"
66
67int main () {
68 receptionist recpt;
69 nullproto nproto;
70#ifndef __WIN32__
71 z3950proto zproto;
72#endif
73
74 text_tarray collections;
75
76 // get gsdlhome
77 text_t gsdlhome;
78 site_cfg_read (gsdlhome);
79 text_t collectdir = filename_cat (gsdlhome, "collect");
80 read_dir (collectdir, collections);
81
82 text_tarray::const_iterator thiscol = collections.begin();
83 text_tarray::const_iterator endcol = collections.end();
84
85 while (thiscol != endcol) {
86
87 // ignore the modelcol
88
89 if (*thiscol == "modelcol") {
90 thiscol ++;
91 continue;
92 }
93
94 // read config file to see if built with mg or mgpp
95 // (for now we'll just ignore mgpp if on windows)
96 text_t buildtype = "mg"; // mg is default
97#ifndef __WIN32__
98 text_tarray cfgline;
99 text_t key;
100 text_t filename = filename_cat(collectdir, *thiscol, "index/build.cfg");
101 ifstream confin(filename.getcstr());
102
103 if (confin) {
104 while (read_cfg_line(confin, cfgline) >= 0) {
105 if (cfgline.size() ==2 ) {
106 key = cfgline[0];
107 cfgline.erase(cfgline.begin());
108 if (key =="buildtype") {
109 buildtype = cfgline[0];
110 break;
111 }
112 }
113 }
114 }
115
116 confin.close();
117#endif
118
119 // this memory is created but never destroyed
120 // we're also not doing any error checking to make sure we didn't
121 // run out of memory
122 collectserver *cserver = new collectserver();
123 gdbmclass *gdbmhandler = new gdbmclass();
124
125 // add a null filter
126 filterclass *filter = new filterclass ();
127 cserver->add_filter (filter);
128
129 // add a browse filter
130 browsefilterclass *browsefilter = new browsefilterclass();
131 browsefilter->set_gdbmptr (gdbmhandler);
132
133 cserver->add_filter (browsefilter);
134
135 if (buildtype == "mg") {
136 mgsearchclass *mgsearch = new mgsearchclass();
137
138 // add a query filter
139 mgqueryfilterclass *queryfilter = new mgqueryfilterclass();
140 queryfilter->set_gdbmptr (gdbmhandler);
141 queryfilter->set_mgsearchptr (mgsearch);
142 cserver->add_filter (queryfilter);
143
144 // add a mg and gdbm source
145 mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass ();
146 mggdbmsource->set_gdbmptr (gdbmhandler);
147 mggdbmsource->set_mgsearchptr (mgsearch);
148 cserver->add_source (mggdbmsource);
149 }
150#ifndef __WIN32__
151
152 else if (buildtype == "mgpp") {
153
154 mgppsearchclass *mgsearch = new mgppsearchclass();
155
156 // add a query filter
157 mgppqueryfilterclass *queryfilter = new mgppqueryfilterclass();
158 queryfilter->set_gdbmptr (gdbmhandler);
159 queryfilter->set_mgsearchptr (mgsearch);
160 cserver->add_filter (queryfilter);
161
162 // add a mg and gdbm source
163 mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass ();
164 mggdbmsource->set_gdbmptr (gdbmhandler);
165 mggdbmsource->set_mgsearchptr (mgsearch);
166 cserver->add_source (mggdbmsource);
167
168 }
169#endif
170
171 // inform collection server and everything it contains about its
172 // collection name
173 cserver->configure ("collection", *thiscol);
174
175 // configure receptionist's collectinfo structure
176 text_tarray colinfo;
177 colinfo.push_back (*thiscol);
178 colinfo.push_back (gsdlhome);
179 colinfo.push_back (gsdlhome);
180 recpt.configure ("collectinfo", colinfo);
181
182 nproto.add_collectserver (cserver);
183 thiscol ++;
184 }
185
186 // add the protocol to the receptionist
187 recpt.add_protocol (&nproto);
188
189
190
191 // z39.50 stuff - johnmcp
192#ifndef __WIN32__
193 // add the z39.50 server information. Read in the file
194 // etc/recpt/z3950.cfg for list of servers and their databases.
195 text_t z3950cfg = filename_cat (gsdlhome, "etc");
196 z3950cfg = filename_cat (z3950cfg, "recpt");
197 z3950cfg = filename_cat (z3950cfg, "z3950.cfg");
198#ifdef USE_FASTCGI
199 // currently can't use z39.50 if fastcgi is in use
200 if (0) {
201#else
202 if (file_exists(z3950cfg)) {
203#endif
204 text_t z3950err = filename_cat (gsdlhome, "etc");
205 z3950err = filename_cat (z3950err, "recpt");
206 z3950err = filename_cat (z3950err, "z3950log.txt");
207 zproto.read_config_file(z3950cfg,z3950err);
208 // only add this protocol if we have any servers configured.
209 if (zproto.getServerCount()>0)
210 recpt.add_protocol (&zproto);
211 }
212#endif
213
214 // add other converters
215 utf8inconvertclass utf8inconvert;
216 utf8outconvertclass utf8outconvert;
217 recpt.add_converter ("u", &utf8inconvert, &utf8outconvert);
218
219 mapinconvertclass gbinconvert;
220 gbinconvert.setmapfile (gsdlhome, "gbku", 0x25a1);
221 mapoutconvertclass gboutconvert;
222 gboutconvert.setmapfile (gsdlhome, "ugbk", 0xa1f5);
223 recpt.add_converter ("g", &gbinconvert, &gboutconvert);
224
225 text_t armapfile = filename_cat (gsdlhome, "unicode", "MAPPINGS");
226 armapfile = filename_cat (armapfile, "WINDOWS", "1256.TXT");
227 simplemapinconvertclass arinconvert;
228 arinconvert.setmapfile (armapfile);
229 simplemapoutconvertclass aroutconvert;
230 aroutconvert.setmapfile (armapfile);
231 recpt.add_converter ("a", &arinconvert, &aroutconvert);
232
233
234 // the list of actions. Note: these actions will become invalid
235 // at the end of this function.
236 tipaction atipaction;
237 recpt.add_action (&atipaction);
238
239 statusaction astatusaction;
240 astatusaction.set_receptionist (&recpt);
241 recpt.add_action (&astatusaction);
242
243 pageaction apageaction;
244 apageaction.set_receptionist (&recpt);
245 recpt.add_action (&apageaction);
246
247 pingaction apingaction;
248 recpt.add_action (&apingaction);
249
250 queryaction aqueryaction;
251 aqueryaction.set_receptionist (&recpt);
252 recpt.add_action (&aqueryaction);
253
254 documentaction adocumentaction;
255 adocumentaction.set_receptionist (&recpt);
256 recpt.add_action (&adocumentaction);
257
258 usersaction ausersaction;
259 recpt.add_action (&ausersaction);
260
261 extlinkaction anextlinkaction;
262 recpt.add_action (&anextlinkaction);
263
264 buildaction abuildaction;
265 abuildaction.set_receptionist (&recpt);
266 recpt.add_action (&abuildaction);
267
268 authenaction aauthenaction;
269 aauthenaction.set_receptionist(&recpt);
270 recpt.add_action (&aauthenaction);
271
272 delhistoryaction adelhistoryaction;
273 recpt.add_action(&adelhistoryaction);
274
275 collectoraction acollectoraction;
276 acollectoraction.set_receptionist (&recpt);
277 recpt.add_action(&acollectoraction);
278
279 // list of browsers
280 vlistbrowserclass avlistbrowserclass;
281 recpt.add_browser (&avlistbrowserclass);
282 recpt.setdefaultbrowser ("VList");
283
284 hlistbrowserclass ahlistbrowserclass;
285 recpt.add_browser (&ahlistbrowserclass);
286
287 datelistbrowserclass adatelistbrowserclass;
288 recpt.add_browser (&adatelistbrowserclass);
289
290 invbrowserclass ainvbrowserclass;
291 recpt.add_browser (&ainvbrowserclass);
292
293 pagedbrowserclass apagedbrowserclass;
294 recpt.add_browser (&apagedbrowserclass);
295
296 htmlbrowserclass ahtmlbrowserclass;
297 recpt.add_browser (&ahtmlbrowserclass);
298
299 cgiwrapper (recpt, "");
300 return 0;
301}
Note: See TracBrowser for help on using the repository browser.