[166] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * librarymain.cpp --
|
---|
| 4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
[533] | 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.
|
---|
[166] | 9 | *
|
---|
[533] | 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 | *
|
---|
[166] | 24 | *********************************************************************/
|
---|
| 25 |
|
---|
| 26 | #include "receptionist.h"
|
---|
| 27 | #include "cgiwrapper.h"
|
---|
| 28 | #include "nullproto.h"
|
---|
[1347] | 29 | // z39.50 stuff - johnmcp
|
---|
| 30 | #include "z3950proto.h"
|
---|
[166] | 31 | #include "collectserver.h"
|
---|
[226] | 32 | #include "filter.h"
|
---|
| 33 | #include "browsefilter.h"
|
---|
[1327] | 34 | #include "mgqueryfilter.h"
|
---|
| 35 | #include "mgppqueryfilter.h"
|
---|
[226] | 36 | #include "infodbclass.h"
|
---|
[1327] | 37 | #include "mggdbmsource.h"
|
---|
[226] | 38 | #include "mgsearch.h"
|
---|
[1327] | 39 | #include "mgppsearch.h"
|
---|
[746] | 40 | #include "fileutil.h"
|
---|
[166] | 41 | #include <assert.h>
|
---|
| 42 |
|
---|
[390] | 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"
|
---|
[722] | 51 | #include "extlinkaction.h"
|
---|
| 52 | #include "buildaction.h"
|
---|
[928] | 53 | #include "delhistoryaction.h"
|
---|
[390] | 54 |
|
---|
[649] | 55 | #include "browserclass.h"
|
---|
| 56 | #include "vlistbrowserclass.h"
|
---|
| 57 | #include "hlistbrowserclass.h"
|
---|
| 58 | #include "datelistbrowserclass.h"
|
---|
| 59 | #include "invbrowserclass.h"
|
---|
[672] | 60 | #include "pagedbrowserclass.h"
|
---|
[713] | 61 | #include "htmlbrowserclass.h"
|
---|
[649] | 62 |
|
---|
[963] | 63 | #include "recptconfig.h"
|
---|
[390] | 64 |
|
---|
[166] | 65 | int main () {
|
---|
| 66 | receptionist recpt;
|
---|
| 67 | nullproto nproto;
|
---|
[1347] | 68 | z3950proto zproto;
|
---|
[1327] | 69 |
|
---|
[268] | 70 | text_tarray collections;
|
---|
[226] | 71 |
|
---|
[1089] | 72 | // get gsdlhome
|
---|
[963] | 73 | text_t gsdlhome;
|
---|
[1089] | 74 | site_cfg_read (gsdlhome);
|
---|
| 75 | text_t collectdir = filename_cat (gsdlhome, "collect");
|
---|
| 76 | read_dir (collectdir, collections);
|
---|
[1327] | 77 |
|
---|
[268] | 78 | text_tarray::const_iterator thiscol = collections.begin();
|
---|
| 79 | text_tarray::const_iterator endcol = collections.end();
|
---|
[963] | 80 |
|
---|
[268] | 81 | while (thiscol != endcol) {
|
---|
[963] | 82 |
|
---|
[746] | 83 | // ignore the modelcol
|
---|
[1327] | 84 |
|
---|
| 85 | if (*thiscol == "modelcol") {
|
---|
| 86 | thiscol ++;
|
---|
| 87 | continue;
|
---|
| 88 | }
|
---|
[963] | 89 |
|
---|
[1327] | 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 |
|
---|
[268] | 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();
|
---|
[1327] | 117 |
|
---|
[257] | 118 | // add a null filter
|
---|
[268] | 119 | filterclass *filter = new filterclass ();
|
---|
| 120 | cserver->add_filter (filter);
|
---|
[963] | 121 |
|
---|
[257] | 122 | // add a browse filter
|
---|
[268] | 123 | browsefilterclass *browsefilter = new browsefilterclass();
|
---|
| 124 | browsefilter->set_gdbmptr (gdbmhandler);
|
---|
[1347] | 125 |
|
---|
[1327] | 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 | }
|
---|
[257] | 160 |
|
---|
| 161 | // inform collection server and everything it contains about its
|
---|
| 162 | // collection name
|
---|
[268] | 163 | cserver->configure ("collection", *thiscol);
|
---|
[1089] | 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);
|
---|
[1347] | 171 |
|
---|
[268] | 172 | nproto.add_collectserver (cserver);
|
---|
| 173 | thiscol ++;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
[166] | 176 | // add the protocol to the receptionist
|
---|
| 177 | recpt.add_protocol (&nproto);
|
---|
[963] | 178 |
|
---|
[1347] | 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");
|
---|
[1366] | 188 | #ifdef USE_FASTCGI
|
---|
| 189 | // currently can't use z39.50 if fastcgi is in use
|
---|
| 190 | if (0) {
|
---|
| 191 | #else
|
---|
[1347] | 192 | if (file_exists(z3950cfg)) {
|
---|
[1366] | 193 | #endif
|
---|
[1355] | 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);
|
---|
[1347] | 198 | // only add this protocol if we have any servers configured.
|
---|
| 199 | if (zproto.getServerCount()>0)
|
---|
| 200 | recpt.add_protocol (&zproto);
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 |
|
---|
[586] | 204 | // add other converters
|
---|
| 205 | utf8inconvertclass utf8inconvert;
|
---|
| 206 | utf8outconvertclass utf8outconvert;
|
---|
| 207 | recpt.add_converter ("u", &utf8inconvert, &utf8outconvert);
|
---|
| 208 |
|
---|
[1194] | 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);
|
---|
[596] | 214 |
|
---|
[1233] | 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 |
|
---|
[390] | 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;
|
---|
[1270] | 231 | apageaction.set_receptionist (&recpt);
|
---|
[390] | 232 | recpt.add_action (&apageaction);
|
---|
| 233 |
|
---|
| 234 | pingaction apingaction;
|
---|
| 235 | recpt.add_action (&apingaction);
|
---|
| 236 |
|
---|
| 237 | queryaction aqueryaction;
|
---|
[1270] | 238 | aqueryaction.set_receptionist (&recpt);
|
---|
[390] | 239 | recpt.add_action (&aqueryaction);
|
---|
| 240 |
|
---|
| 241 | documentaction adocumentaction;
|
---|
[1270] | 242 | adocumentaction.set_receptionist (&recpt);
|
---|
[390] | 243 | recpt.add_action (&adocumentaction);
|
---|
| 244 |
|
---|
| 245 | usersaction ausersaction;
|
---|
| 246 | recpt.add_action (&ausersaction);
|
---|
| 247 |
|
---|
[722] | 248 | extlinkaction anextlinkaction;
|
---|
| 249 | recpt.add_action (&anextlinkaction);
|
---|
| 250 |
|
---|
| 251 | buildaction abuildaction;
|
---|
[826] | 252 | abuildaction.set_receptionist (&recpt);
|
---|
[722] | 253 | recpt.add_action (&abuildaction);
|
---|
| 254 |
|
---|
[390] | 255 | authenaction aauthenaction;
|
---|
| 256 | aauthenaction.set_receptionist(&recpt);
|
---|
| 257 | recpt.add_action (&aauthenaction);
|
---|
| 258 |
|
---|
[928] | 259 | delhistoryaction adelhistoryaction;
|
---|
| 260 | recpt.add_action(&adelhistoryaction);
|
---|
| 261 |
|
---|
[649] | 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 |
|
---|
[672] | 276 | pagedbrowserclass apagedbrowserclass;
|
---|
| 277 | recpt.add_browser (&apagedbrowserclass);
|
---|
| 278 |
|
---|
[713] | 279 | htmlbrowserclass ahtmlbrowserclass;
|
---|
| 280 | recpt.add_browser (&ahtmlbrowserclass);
|
---|
| 281 |
|
---|
[268] | 282 | cgiwrapper (recpt, "");
|
---|
[166] | 283 | return 0;
|
---|
| 284 | }
|
---|