/********************************************************************** * * recptconfig.cpp -- * Copyright (C) 1999 The New Zealand Digital Library Project * * A component of the Greenstone digital library software * from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *********************************************************************/ #include "recptconfig.h" #include "fileutil.h" #include "cfgread.h" #if defined(GSDL_USE_OBJECTSPACE) # include # include #elif defined(GSDL_USE_IOS_H) # include # include #else # include # include #endif // reads site configuration file returning true on success // also sets gsdlhome and maxrequests // gsdlsite.cfg should be in same directory as library executable bool site_cfg_read (receptionist &recpt, text_t &gsdlhome, int &maxrequests) { gsdlhome.clear(); // Look for gsdlsite.cfg in same directory that executable is in. text_tarray cfgline; text_t key; #ifdef GSDL_USE_IOS_H ifstream confin ("gsdlsite.cfg", ios::in | ios::nocreate); #else ifstream confin ("gsdlsite.cfg", ios::in); #endif if (confin) { while (read_cfg_line(confin, cfgline) >= 0) { if (cfgline.size () >= 2) { key = cfgline[0]; cfgline.erase(cfgline.begin()); if (key == "maxrequests") { maxrequests = cfgline[0].getint(); if (maxrequests < 1) maxrequests = 1; } if (key == "gsdlhome") gsdlhome = cfgline[0]; // configure the receptionist recpt.configure (key, cfgline); } } confin.close (); return true; } return false; } // this version just grabs gsdlhome, returning true // unless unable to read gsdlsite.cfg bool site_cfg_read (text_t &gsdlhome) { gsdlhome.clear(); // Look for gsdlsite.cfg in same directory that executable is in. text_tarray cfgline; text_t key; #ifdef GSDL_USE_IOS_H ifstream confin ("gsdlsite.cfg", ios::in | ios::nocreate); #else ifstream confin ("gsdlsite.cfg", ios::in); #endif if (confin) { while (read_cfg_line(confin, cfgline) >= 0) { if (cfgline.size () >= 2) { if (cfgline[0] == "gsdlhome") { gsdlhome = cfgline[1]; break; } } } return true; confin.close (); } return false; } // main_cfg_read reads both main.cfg and collect.cfg. It attempts // to read main.cfg first so values in collect.cfg override those // set earlier by main.cfg bool main_cfg_read (receptionist &recpt, const text_t &gsdlhome, const text_t &collection) { // read in the main configuration file bool rv = false; text_t key, filename; text_tarray cfgline; filename = filename_cat (gsdlhome, "etc"); filename = filename_cat (filename, "main.cfg"); if (file_exists (filename)) { char *cstr = filename.getcstr(); #ifdef GSDL_USE_IOS_H ifstream confin (cstr, ios::in | ios::nocreate); #else ifstream confin (cstr, ios::in); #endif delete cstr; if (confin) { while (read_cfg_line(confin, cfgline) >= 0) { if (cfgline.size () >= 2) { key = cfgline[0]; cfgline.erase(cfgline.begin()); // configure the receptionist recpt.configure (key, cfgline); } } confin.close (); rv = true; } } // Look for collect.cfg in GSDLHOME/collect/collection-name/etc directory // (if this is for a particular collection), and then GSDLHOME/etc. if (!collection.empty()) { filename = filename_cat (gsdlhome, "collect"); filename = filename_cat (filename, collection); filename = filename_cat (filename, "etc"); filename = filename_cat (filename, "collect.cfg"); if (!file_exists (filename)) { filename = filename_cat (gsdlhome, "etc"); filename = filename_cat (filename, "collect.cfg"); if (!file_exists (filename)) filename.clear(); } if (!filename.empty()) { char *cstr = filename.getcstr(); #ifdef GSDL_USE_IOS_H ifstream confin (cstr, ios::in | ios::nocreate); #else ifstream confin (cstr, ios::in); #endif delete cstr; if (confin) { while (read_cfg_line(confin, cfgline) >= 0) { if (cfgline.size () >= 2) { key = cfgline[0]; cfgline.erase(cfgline.begin()); // configure the receptionist recpt.configure (key, cfgline); } } confin.close (); rv = true; } } } return rv; }