[1860] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * collectset.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 | * $Id: collectset.cpp 1886 2001-01-31 02:03:30Z sjboddie $
|
---|
| 25 | *
|
---|
| 26 | *********************************************************************/
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | #include "collectserver.h"
|
---|
| 30 | #include "filter.h"
|
---|
| 31 | #include "browsefilter.h"
|
---|
| 32 | #include "queryfilter.h"
|
---|
| 33 | #include "infodbclass.h"
|
---|
| 34 | #include "mgqueryfilter.h"
|
---|
| 35 | #include "mgppqueryfilter.h"
|
---|
| 36 | #include "mgsearch.h"
|
---|
| 37 | #include "mgppsearch.h"
|
---|
| 38 | #include "mggdbmsource.h"
|
---|
| 39 | #include "fileutil.h"
|
---|
| 40 | #include <assert.h>
|
---|
| 41 |
|
---|
| 42 | #include "colservrconfig.h"
|
---|
| 43 | #include "recptconfig.h"
|
---|
| 44 |
|
---|
| 45 | #include "collectset.h"
|
---|
| 46 |
|
---|
| 47 | collectset::collectset (text_t &gsdlhome) {
|
---|
| 48 |
|
---|
| 49 | text_tarray collections;
|
---|
| 50 | text_t collectdir;
|
---|
| 51 |
|
---|
| 52 | // get gsdlhome (if we fail the error will be picked up later -- in
|
---|
| 53 | // cgiwrapper)
|
---|
| 54 | if (site_cfg_read (gsdlhome, httpdomain, httpprefix)) {
|
---|
| 55 | collectdir = filename_cat (gsdlhome, "collect");
|
---|
| 56 |
|
---|
| 57 | if (!read_dir (collectdir, collections)) {
|
---|
| 58 | cerr << "couldn't read collect directory - make sure gsdlhome field is correct in gsdlsite.cfg\n";
|
---|
| 59 | exit (1);
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | text_tarray::const_iterator thiscol = collections.begin();
|
---|
| 64 | text_tarray::const_iterator endcol = collections.end();
|
---|
| 65 |
|
---|
| 66 | while (thiscol != endcol) {
|
---|
| 67 | // ignore the modelcol
|
---|
| 68 | if (*thiscol == "modelcol") {
|
---|
| 69 | thiscol ++;
|
---|
| 70 | continue;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | // Dummy call to add collection added 24/11/2000;
|
---|
| 74 | // we already do this ourselves!
|
---|
| 75 | // this->add_collection(*thiscol, &recpt, gsdlghome, gsdlhome);
|
---|
| 76 |
|
---|
| 77 | // read config file to see if built with mg or mgpp
|
---|
| 78 | text_t buildtype = "mg"; // mg is default
|
---|
| 79 | text_tarray cfgline;
|
---|
| 80 | text_t key;
|
---|
[1886] | 81 | text_t filename = filename_cat(collectdir, *thiscol, "index" , "build.cfg");
|
---|
[1860] | 82 | ifstream confin(filename.getcstr());
|
---|
| 83 |
|
---|
| 84 | if (confin) {
|
---|
| 85 | while (read_cfg_line(confin, cfgline) >= 0) {
|
---|
| 86 | if (cfgline.size() ==2 ) {
|
---|
| 87 | key = cfgline[0];
|
---|
| 88 | cfgline.erase(cfgline.begin());
|
---|
| 89 | if (key =="buildtype") {
|
---|
| 90 | buildtype = cfgline[0];
|
---|
| 91 | break;
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | confin.close();
|
---|
| 98 |
|
---|
| 99 | // this memory is created but never destroyed
|
---|
| 100 | // we're also not doing any error checking to make sure we didn't
|
---|
| 101 | // run out of memory
|
---|
| 102 | collectserver *cserver = new collectserver();
|
---|
| 103 | gdbmclass *gdbmhandler = new gdbmclass();
|
---|
| 104 |
|
---|
| 105 | // add a null filter
|
---|
| 106 | filterclass *filter = new filterclass ();
|
---|
| 107 | cserver->add_filter (filter);
|
---|
| 108 |
|
---|
| 109 | // add a browse filter
|
---|
| 110 | browsefilterclass *browsefilter = new browsefilterclass();
|
---|
| 111 | browsefilter->set_gdbmptr (gdbmhandler);
|
---|
| 112 | cserver->add_filter (browsefilter);
|
---|
| 113 |
|
---|
| 114 | if (buildtype == "mg") {
|
---|
| 115 | mgsearchclass *mgsearch = new mgsearchclass();
|
---|
| 116 |
|
---|
| 117 | // add a query filter
|
---|
| 118 | mgqueryfilterclass *queryfilter = new mgqueryfilterclass();
|
---|
| 119 | queryfilter->set_gdbmptr (gdbmhandler);
|
---|
| 120 | queryfilter->set_mgsearchptr (mgsearch);
|
---|
| 121 | cserver->add_filter (queryfilter);
|
---|
| 122 |
|
---|
| 123 | // add a mg and gdbm source
|
---|
| 124 | mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass ();
|
---|
| 125 | mggdbmsource->set_gdbmptr (gdbmhandler);
|
---|
| 126 | mggdbmsource->set_mgsearchptr (mgsearch);
|
---|
| 127 | cserver->add_source (mggdbmsource);
|
---|
| 128 | }
|
---|
| 129 | #ifndef __WIN32__
|
---|
| 130 |
|
---|
| 131 | else if (buildtype == "mgpp") {
|
---|
| 132 |
|
---|
| 133 | mgppsearchclass *mgsearch = new mgppsearchclass();
|
---|
| 134 |
|
---|
| 135 | // add a query filter
|
---|
| 136 | mgppqueryfilterclass *queryfilter = new mgppqueryfilterclass();
|
---|
| 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 | #endif
|
---|
| 148 |
|
---|
| 149 | // inform collection server and everything it contains about its
|
---|
| 150 | // collection name
|
---|
| 151 | cserver->configure ("collection", *thiscol);
|
---|
| 152 | // AZIZ: added on 10/10/00
|
---|
| 153 | // the cserver object does not have a reference to gsdlhome
|
---|
| 154 | cserver->configure ("gsdlhome", gsdlhome);
|
---|
| 155 |
|
---|
| 156 | // GRB: removed proto.add_collectserver (cserver);
|
---|
| 157 | // GRB: added to build our own cservers list
|
---|
| 158 | cservers.addcollectserver (cserver);
|
---|
| 159 |
|
---|
| 160 | thiscol ++;
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | collectset::~collectset () {
|
---|
| 165 | collectservermapclass::iterator here = cservers.begin();
|
---|
| 166 | collectservermapclass::iterator end = cservers.end();
|
---|
| 167 |
|
---|
| 168 | while (here != end) {
|
---|
| 169 | if ((*here).second.c != NULL) {
|
---|
| 170 | delete (*here).second.c;
|
---|
| 171 | }
|
---|
| 172 | here ++;
|
---|
| 173 | }
|
---|
| 174 | cservers.clear();
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | bool collectset::init (ostream &logout) {
|
---|
| 178 | collectservermapclass::iterator here = cservers.begin();
|
---|
| 179 | collectservermapclass::iterator end = cservers.end();
|
---|
| 180 |
|
---|
| 181 | while (here != end) {
|
---|
| 182 | assert ((*here).second.c != NULL);
|
---|
| 183 | if ((*here).second.c != NULL) {
|
---|
| 184 | const colservrconf &configinfo = (*here).second.c->get_configinfo ();
|
---|
| 185 |
|
---|
| 186 | // configure this collection server
|
---|
| 187 |
|
---|
| 188 | // note that we read build.cfg before collect.cfg so that the indexmaps
|
---|
| 189 | // are available to decode defaultindex, defaultsubcollection, and
|
---|
| 190 | // defaultlanguage
|
---|
| 191 | if (!build_cfg_read (*((*here).second.c), configinfo.gsdlhome,
|
---|
| 192 | configinfo.collection)) {
|
---|
| 193 | outconvertclass text_t2ascii;
|
---|
| 194 | logout << text_t2ascii
|
---|
| 195 | << "Warning: couldn't read build.cfg file for collection \"" //****
|
---|
| 196 | << configinfo.collection << "\", gsdlhome=\""
|
---|
| 197 | << configinfo.gsdlhome << "\"\n";
|
---|
| 198 | here ++;
|
---|
| 199 | continue;
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | if (!collect_cfg_read (*((*here).second.c), configinfo.gsdlhome,
|
---|
| 203 | configinfo.collection)) {
|
---|
| 204 | outconvertclass text_t2ascii;
|
---|
| 205 | logout << text_t2ascii
|
---|
| 206 | << "Warning: couldn't read collect.cfg file for collection \""
|
---|
| 207 | << configinfo.collection << "\", gsdlhome=\""
|
---|
| 208 | << configinfo.gsdlhome << "\"\n";
|
---|
| 209 | here ++;
|
---|
| 210 | continue;
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | if (!(*here).second.c->init (logout)) return false;
|
---|
| 214 |
|
---|
| 215 | (*here).second.c->configure("httpdomain",httpdomain);
|
---|
| 216 | (*here).second.c->configure("httpprefix",httpprefix);
|
---|
| 217 | }
|
---|
| 218 | here++;
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | return true;
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | collectservermapclass collectset::servers()
|
---|
| 225 | { return cservers;
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | // add_collection sets up the collectionserver and calls
|
---|
| 229 | // add_collectserver
|
---|
| 230 | void collectset::add_collection (const text_t &collection, void *recpt,
|
---|
| 231 | const text_t &gsdlhome, const text_t &gdbmhome) {
|
---|
| 232 |
|
---|
| 233 | // read config file to see if built with mg or mgpp
|
---|
| 234 | // -- we can rely on the collection (and therefore the build.cfg)
|
---|
| 235 | // being here since this is the null protocol - a nicer way to
|
---|
| 236 | // do this would be preferable though - Stefan.
|
---|
| 237 | text_t buildtype = "mg"; // mg is default
|
---|
| 238 | // (for now we'll just ignore mgpp if on windows)
|
---|
| 239 | #ifndef __WIN32__
|
---|
| 240 | text_tarray cfgline;
|
---|
| 241 | text_t key;
|
---|
| 242 | text_t build_cfg = filename_cat(gsdlhome, "collect", collection, "index", "build.cfg");
|
---|
| 243 | char *build_cfgc = build_cfg.getcstr();
|
---|
| 244 | ifstream confin(build_cfgc);
|
---|
| 245 |
|
---|
| 246 | if (confin) {
|
---|
| 247 | while (read_cfg_line(confin, cfgline) >= 0) {
|
---|
| 248 | if (cfgline.size() == 2) {
|
---|
| 249 | key = cfgline[0];
|
---|
| 250 | cfgline.erase(cfgline.begin());
|
---|
| 251 | if (key == "buildtype") {
|
---|
| 252 | buildtype = cfgline[0];
|
---|
| 253 | break;
|
---|
| 254 | }
|
---|
| 255 | }
|
---|
| 256 | }
|
---|
| 257 | confin.close();
|
---|
| 258 | }
|
---|
| 259 | delete build_cfgc;
|
---|
| 260 | #endif
|
---|
| 261 |
|
---|
| 262 | collectserver *cserver = new collectserver();
|
---|
| 263 | gdbmclass *gdbmhandler = new gdbmclass();
|
---|
| 264 |
|
---|
| 265 | // add a null filter
|
---|
| 266 | filterclass *filter = new filterclass ();
|
---|
| 267 | cserver->add_filter (filter);
|
---|
| 268 |
|
---|
| 269 | // add a browse filter
|
---|
| 270 | browsefilterclass *browsefilter = new browsefilterclass();
|
---|
| 271 | browsefilter->set_gdbmptr (gdbmhandler);
|
---|
| 272 |
|
---|
| 273 | cserver->add_filter (browsefilter);
|
---|
| 274 |
|
---|
| 275 | if (buildtype == "mg") {
|
---|
| 276 | mgsearchclass *mgsearch = new mgsearchclass();
|
---|
| 277 |
|
---|
| 278 | // add a query filter
|
---|
| 279 | mgqueryfilterclass *queryfilter = new mgqueryfilterclass();
|
---|
| 280 | queryfilter->set_gdbmptr (gdbmhandler);
|
---|
| 281 | queryfilter->set_mgsearchptr (mgsearch);
|
---|
| 282 | cserver->add_filter (queryfilter);
|
---|
| 283 |
|
---|
| 284 | // add a mg and gdbm source
|
---|
| 285 | mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass ();
|
---|
| 286 | mggdbmsource->set_gdbmptr (gdbmhandler);
|
---|
| 287 | mggdbmsource->set_mgsearchptr (mgsearch);
|
---|
| 288 | cserver->add_source (mggdbmsource);
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | #ifndef __WIN32__
|
---|
| 292 |
|
---|
| 293 | else if (buildtype == "mgpp") {
|
---|
| 294 |
|
---|
| 295 | mgppsearchclass *mgsearch = new mgppsearchclass();
|
---|
| 296 |
|
---|
| 297 | // add a query filter
|
---|
| 298 | mgppqueryfilterclass *queryfilter = new mgppqueryfilterclass();
|
---|
| 299 | queryfilter->set_gdbmptr (gdbmhandler);
|
---|
| 300 | queryfilter->set_mgsearchptr (mgsearch);
|
---|
| 301 | cserver->add_filter (queryfilter);
|
---|
| 302 |
|
---|
| 303 | // add a mg and gdbm source
|
---|
| 304 | mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass ();
|
---|
| 305 | mggdbmsource->set_gdbmptr (gdbmhandler);
|
---|
| 306 | mggdbmsource->set_mgsearchptr (mgsearch);
|
---|
| 307 | cserver->add_source (mggdbmsource);
|
---|
| 308 |
|
---|
| 309 | }
|
---|
| 310 | #endif
|
---|
| 311 |
|
---|
| 312 | // inform collection server and everything it contains about its
|
---|
| 313 | // collection name
|
---|
| 314 | cserver->configure ("collection", collection);
|
---|
| 315 |
|
---|
| 316 | /* Removed from add_collection 24/11/2000; already done elsewhere in collectset.
|
---|
| 317 | // configure receptionist's collectinfo structure
|
---|
| 318 | text_tarray colinfo;
|
---|
| 319 | colinfo.push_back (collection);
|
---|
| 320 | colinfo.push_back (gsdlhome);
|
---|
| 321 | colinfo.push_back (gdbmhome);
|
---|
| 322 | */
|
---|
| 323 | cservers.addcollectserver (cserver);
|
---|
| 324 | }
|
---|
| 325 |
|
---|
| 326 | // remove_collection deletes the collection server of collection.
|
---|
| 327 | // This only needs to be called if a collectionserver is to be
|
---|
| 328 | // removed while the library is running. The destructor function
|
---|
| 329 | // cleans up all collectservers when the program exits.
|
---|
| 330 | void collectset::remove_collection (const text_t &collection, ostream &logout) {
|
---|
| 331 | collectservermapclass::iterator here = cservers.begin();
|
---|
| 332 | collectservermapclass::iterator end = cservers.end();
|
---|
| 333 |
|
---|
| 334 | while (here != end) {
|
---|
| 335 | if ((*here).second.c != NULL && (*here).first == collection) {
|
---|
| 336 | delete (*here).second.c;
|
---|
| 337 | cservers.erase (here);
|
---|
| 338 | return;
|
---|
| 339 | }
|
---|
| 340 | here ++;
|
---|
| 341 | }
|
---|
| 342 | outconvertclass text_t2ascii;
|
---|
| 343 | logout << text_t2ascii << "nullproto::remove_collection: failed to remove collectserver for "
|
---|
| 344 | << collection << "\n";
|
---|
| 345 | }
|
---|
| 346 |
|
---|
| 347 | void collectset::configure(const text_t &key, const text_tarray &cfgline)
|
---|
| 348 | {
|
---|
| 349 | if (key == "collection" || key == "collectdir") return;
|
---|
| 350 |
|
---|
| 351 | collectservermapclass::iterator here = cservers.begin();
|
---|
| 352 | collectservermapclass::iterator end = cservers.end();
|
---|
| 353 |
|
---|
| 354 | while (here != end) {
|
---|
| 355 | assert ((*here).second.c != NULL);
|
---|
| 356 | if ((*here).second.c != NULL) {
|
---|
| 357 | if (key == "collectinfo") {
|
---|
| 358 | if ((*here).first == cfgline[0]) {
|
---|
| 359 | (*here).second.c->configure ("gsdlhome", cfgline[1]);
|
---|
| 360 | (*here).second.c->configure ("gdbmhome", cfgline[2]);
|
---|
| 361 | }
|
---|
| 362 | } else {
|
---|
| 363 | (*here).second.c->configure (key, cfgline);
|
---|
| 364 | }
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 | here++;
|
---|
| 368 | }
|
---|
| 369 | }
|
---|
| 370 |
|
---|
| 371 | void collectset::getCollectionList (text_tarray &collist)
|
---|
| 372 | {
|
---|
| 373 | collist.erase(collist.begin(),collist.end());
|
---|
| 374 |
|
---|
| 375 | collectservermapclass::iterator here = cservers.begin();
|
---|
| 376 | collectservermapclass::iterator end = cservers.end();
|
---|
| 377 | while (here != end) {
|
---|
| 378 | assert ((*here).second.c != NULL);
|
---|
| 379 | if ((*here).second.c != NULL) {
|
---|
| 380 | collist.push_back ((*here).second.c->get_collection_name());
|
---|
| 381 | }
|
---|
| 382 | here++;
|
---|
| 383 | }
|
---|
| 384 | }
|
---|
| 385 |
|
---|
| 386 | void collectset::setReceptionistServers(receptionist &recpt, text_t &gsdlhome)
|
---|
| 387 | {
|
---|
| 388 | collectservermapclass::iterator here = cservers.begin();
|
---|
| 389 | collectservermapclass::iterator end = cservers.end();
|
---|
| 390 | while (here != end) {
|
---|
| 391 | assert ((*here).second.c != NULL);
|
---|
| 392 |
|
---|
| 393 | text_tarray colinfo;
|
---|
| 394 | colinfo.push_back((*here).second.c->get_collection_name());
|
---|
| 395 | colinfo.push_back(gsdlhome);
|
---|
| 396 | colinfo.push_back(gsdlhome);
|
---|
| 397 | recpt.configure("collectinfo", colinfo);
|
---|
| 398 |
|
---|
| 399 | here++;
|
---|
| 400 | }
|
---|
| 401 | }
|
---|