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

Last change on this file since 1355 was 1355, checked in by jrm21, 24 years ago

Fixed up parsing of z39.50 config file, so that errors go to file instead
of stderr, which screws up the cgi headers and page...
Errors goes to etc/recpt/z3950err.txt

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