/********************************************************************** * * recptconfig.cpp -- * Copyright (C) 1999 The New Zealand Digital Library Project * * PUT COPYRIGHT NOTICE HERE * * $Id: recptconfig.cpp 165 1999-02-21 22:33:58Z rjmcnab $ * *********************************************************************/ /* $Log$ Revision 1.3 1999/02/21 22:33:57 rjmcnab Lots of stuff :-) Revision 1.2 1999/02/08 01:28:04 rjmcnab Got the receptionist producing something using the statusaction. Revision 1.1 1999/02/05 06:50:32 rjmcnab Initial revision. */ #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 bool site_cfg_read (receptionist &recpt, const text_t &gsdlhome, const text_t &collection, int &maxrequests) { maxrequests = 10000; // a reasonable default // Look for site.cfg in GSDLHOME/collect/collection-name/etc directory // (if this is for a particular collection), and then GSDLHOME/etc. text_t filename; if (!collection.empty()) { filename = filename_cat (gsdlhome, "collect"); filename = filename_cat (filename, collection); filename = filename_cat (filename, "etc"); filename = filename_cat (filename, "site.cfg"); if (!file_exists (filename)) filename.clear(); } if (filename.empty()) { filename = filename_cat (gsdlhome, "etc"); filename = filename_cat (filename, "site.cfg"); if (!file_exists (filename)) return false; } // read in the site configuration file text_tarray cfgline; text_t key; char *cstr = filename.getcstr(); ifstream confin (cstr); delete cstr; 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; } // configure the receptionist recpt.configure (key, cfgline); } } confin.close (); return true; } return false; } // main_cfg_read reads either collect.cfg or main.cfg and returning // true on success. It attempts to read collect.cfg first if a // collection is specified and then it tries to read in main.cfg bool main_cfg_read (receptionist &recpt, const text_t &gsdlhome, const text_t &collection) { // Look for site.cfg in GSDLHOME/collect/collection-name/etc directory // (if this is for a particular collection), and then GSDLHOME/etc. text_t filename; 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()) { filename = filename_cat (gsdlhome, "etc"); filename = filename_cat (filename, "main.cfg"); if (!file_exists (filename)) return false; } // read in the main configuration file text_t key; text_tarray cfgline; char *cstr = filename.getcstr(); ifstream confin (cstr); 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 (); return true; } return false; }