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

Revision 1391, 8.3 KB (checked in by say1, 20 years ago)

now actually calling tipaction code

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