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

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

z39.50 protocol is not used if USE_FASTCGI defined. (Note it will still
be compiled and (attempted to) link).

  • Property svn:keywords set to Author Date Id Revision
File size: 8.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 "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#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");
195 z3950err = filename_cat (z3950err, "recpt");
196 z3950err = filename_cat (z3950err, "z3950log.txt");
197 zproto.read_config_file(z3950cfg,z3950err);
198 // only add this protocol if we have any servers configured.
199 if (zproto.getServerCount()>0)
200 recpt.add_protocol (&zproto);
201 }
202
203
204 // add other converters
205 utf8inconvertclass utf8inconvert;
206 utf8outconvertclass utf8outconvert;
207 recpt.add_converter ("u", &utf8inconvert, &utf8outconvert);
208
209 mapinconvertclass gbinconvert;
210 gbinconvert.setmapfile (gsdlhome, "gbku", 0x25a1);
211 mapoutconvertclass gboutconvert;
212 gboutconvert.setmapfile (gsdlhome, "ugbk", 0xa1f5);
213 recpt.add_converter ("g", &gbinconvert, &gboutconvert);
214
215 text_t armapfile = filename_cat (gsdlhome, "unicode", "MAPPINGS");
216 armapfile = filename_cat (armapfile, "WINDOWS", "1256.TXT");
217 simplemapinconvertclass arinconvert;
218 arinconvert.setmapfile (armapfile);
219 simplemapoutconvertclass aroutconvert;
220 aroutconvert.setmapfile (armapfile);
221 recpt.add_converter ("a", &arinconvert, &aroutconvert);
222
223
224 // the list of actions. Note: these actions will become invalid
225 // at the end of this function.
226 statusaction astatusaction;
227 astatusaction.set_receptionist (&recpt);
228 recpt.add_action (&astatusaction);
229
230 pageaction apageaction;
231 apageaction.set_receptionist (&recpt);
232 recpt.add_action (&apageaction);
233
234 pingaction apingaction;
235 recpt.add_action (&apingaction);
236
237 queryaction aqueryaction;
238 aqueryaction.set_receptionist (&recpt);
239 recpt.add_action (&aqueryaction);
240
241 documentaction adocumentaction;
242 adocumentaction.set_receptionist (&recpt);
243 recpt.add_action (&adocumentaction);
244
245 usersaction ausersaction;
246 recpt.add_action (&ausersaction);
247
248 extlinkaction anextlinkaction;
249 recpt.add_action (&anextlinkaction);
250
251 buildaction abuildaction;
252 abuildaction.set_receptionist (&recpt);
253 recpt.add_action (&abuildaction);
254
255 authenaction aauthenaction;
256 aauthenaction.set_receptionist(&recpt);
257 recpt.add_action (&aauthenaction);
258
259 delhistoryaction adelhistoryaction;
260 recpt.add_action(&adelhistoryaction);
261
262 // list of browsers
263 vlistbrowserclass avlistbrowserclass;
264 recpt.add_browser (&avlistbrowserclass);
265 recpt.setdefaultbrowser ("VList");
266
267 hlistbrowserclass ahlistbrowserclass;
268 recpt.add_browser (&ahlistbrowserclass);
269
270 datelistbrowserclass adatelistbrowserclass;
271 recpt.add_browser (&adatelistbrowserclass);
272
273 invbrowserclass ainvbrowserclass;
274 recpt.add_browser (&ainvbrowserclass);
275
276 pagedbrowserclass apagedbrowserclass;
277 recpt.add_browser (&apagedbrowserclass);
278
279 htmlbrowserclass ahtmlbrowserclass;
280 recpt.add_browser (&ahtmlbrowserclass);
281
282 cgiwrapper (recpt, "");
283 return 0;
284}
Note: See TracBrowser for help on using the repository browser.