root/trunk/gsdl/src/recpt/librarymain.cpp @ 1471

Revision 1471, 8.4 KB (checked in by sjboddie, 20 years ago)

*** empty log message ***

  • Property svn:keywords set to Author Date Id Revision
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    collectserver *cserver = new collectserver();
120    gdbmclass *gdbmhandler = new gdbmclass();
121
122    // add a null filter
123    filterclass *filter = new filterclass ();
124    cserver->add_filter (filter);
125     
126    // add a browse filter
127    browsefilterclass *browsefilter = new browsefilterclass();
128    browsefilter->set_gdbmptr (gdbmhandler);
129
130    cserver->add_filter (browsefilter); 
131 
132    if (buildtype == "mg") {
133       mgsearchclass *mgsearch = new mgsearchclass();
134 
135       // add a query filter
136       mgqueryfilterclass *queryfilter = new mgqueryfilterclass();
137       queryfilter->set_gdbmptr (gdbmhandler);
138       queryfilter->set_mgsearchptr (mgsearch);
139       cserver->add_filter (queryfilter);
140       
141       // add a mg and gdbm source
142       mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass ();
143       mggdbmsource->set_gdbmptr (gdbmhandler);
144       mggdbmsource->set_mgsearchptr (mgsearch);
145       cserver->add_source (mggdbmsource);
146    }
147#ifndef __WIN32__
148
149    else if (buildtype == "mgpp") {
150     
151      mgppsearchclass *mgsearch = new mgppsearchclass();
152
153      // add a query filter
154      mgppqueryfilterclass *queryfilter = new mgppqueryfilterclass();
155      queryfilter->set_gdbmptr (gdbmhandler);
156      queryfilter->set_mgsearchptr (mgsearch);
157      cserver->add_filter (queryfilter);
158     
159      // add a mg and gdbm source
160      mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass ();
161      mggdbmsource->set_gdbmptr (gdbmhandler);
162      mggdbmsource->set_mgsearchptr (mgsearch);
163      cserver->add_source (mggdbmsource);
164   
165    }
166#endif   
167
168    // inform collection server and everything it contains about its
169    // collection name
170    cserver->configure ("collection", *thiscol);
171 
172    // configure receptionist's collectinfo structure
173    text_tarray colinfo;
174    colinfo.push_back (*thiscol);
175    colinfo.push_back (gsdlhome);
176    colinfo.push_back (gsdlhome);
177    recpt.configure ("collectinfo", colinfo);
178   
179    nproto.add_collectserver (cserver);
180    thiscol ++;
181  }
182 
183  // add the protocol to the receptionist
184  recpt.add_protocol (&nproto);
185 
186
187
188  // z39.50 stuff - johnmcp
189#ifndef __WIN32__
190  // add the z39.50 server information. Read in the file
191  // etc/recpt/z3950.cfg for list of servers and their databases.
192  text_t z3950cfg = filename_cat (gsdlhome, "etc");
193  z3950cfg = filename_cat (z3950cfg, "recpt");
194  z3950cfg = filename_cat (z3950cfg, "z3950.cfg");
195#ifdef USE_FASTCGI
196  // currently can't use z39.50 if fastcgi is in use
197  if (0) {
198#else
199  if (file_exists(z3950cfg)) {
200#endif
201    text_t z3950err = filename_cat (gsdlhome, "etc", "z3950log.txt");
202    zproto.read_config_file(z3950cfg,z3950err);
203    // only add this protocol if we have any servers configured.
204    if (zproto.getServerCount()>0)
205      recpt.add_protocol (&zproto);
206  }
207#endif
208
209  // add other converters
210  utf8inconvertclass utf8inconvert;
211  utf8outconvertclass utf8outconvert;
212  recpt.add_converter ("u", &utf8inconvert, &utf8outconvert);
213
214  mapinconvertclass gbinconvert;
215  gbinconvert.setmapfile (gsdlhome, "gbku", 0x25a1);
216  mapoutconvertclass gboutconvert;
217  gboutconvert.setmapfile (gsdlhome, "ugbk", 0xa1f5);
218  recpt.add_converter ("g", &gbinconvert, &gboutconvert);
219
220  text_t armapfile = filename_cat (gsdlhome, "unicode", "MAPPINGS");
221  armapfile = filename_cat (armapfile, "WINDOWS", "1256.TXT");
222  simplemapinconvertclass arinconvert;
223  arinconvert.setmapfile (armapfile);
224  simplemapoutconvertclass aroutconvert;
225  aroutconvert.setmapfile (armapfile);
226  recpt.add_converter ("a", &arinconvert, &aroutconvert); 
227
228
229  // the list of actions. Note: these actions will become invalid
230  // at the end of this function.
231  tipaction atipaction;
232  recpt.add_action (&atipaction);
233
234  statusaction astatusaction;
235  astatusaction.set_receptionist (&recpt);
236  recpt.add_action (&astatusaction);
237
238  pageaction apageaction;
239  apageaction.set_receptionist (&recpt);
240  recpt.add_action (&apageaction);
241
242  pingaction apingaction;
243  recpt.add_action (&apingaction);
244
245  queryaction aqueryaction;
246  aqueryaction.set_receptionist (&recpt);
247  recpt.add_action (&aqueryaction);
248
249  documentaction adocumentaction;
250  adocumentaction.set_receptionist (&recpt);
251  recpt.add_action (&adocumentaction);
252
253  usersaction ausersaction;
254  recpt.add_action (&ausersaction);
255
256  extlinkaction anextlinkaction;
257  recpt.add_action (&anextlinkaction);
258
259  buildaction abuildaction;
260  abuildaction.set_receptionist (&recpt);
261  recpt.add_action (&abuildaction);
262
263  authenaction aauthenaction;
264  aauthenaction.set_receptionist(&recpt);
265  recpt.add_action (&aauthenaction);
266
267  delhistoryaction adelhistoryaction;
268  recpt.add_action(&adelhistoryaction);
269
270  collectoraction acollectoraction;
271  acollectoraction.set_receptionist (&recpt);
272  recpt.add_action(&acollectoraction);
273
274  // list of browsers
275  vlistbrowserclass avlistbrowserclass;
276  recpt.add_browser (&avlistbrowserclass);
277  recpt.setdefaultbrowser ("VList");
278
279  hlistbrowserclass ahlistbrowserclass;
280  recpt.add_browser (&ahlistbrowserclass);
281
282  datelistbrowserclass adatelistbrowserclass;
283  recpt.add_browser (&adatelistbrowserclass);
284
285  invbrowserclass ainvbrowserclass;
286  recpt.add_browser (&ainvbrowserclass);
287
288  pagedbrowserclass apagedbrowserclass;
289  recpt.add_browser (&apagedbrowserclass);
290
291  htmlbrowserclass ahtmlbrowserclass;
292  recpt.add_browser (&ahtmlbrowserclass);
293
294  cgiwrapper (recpt, "");
295  return 0;
296}
Note: See TracBrowser for help on using the browser.