/********************************************************************** * * gsdlsitecfg.cpp -- * Copyright (C) 2008 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 "gsdlsitecfg.h" #if defined(GSDL_USE_OBJECTSPACE) # include # include #elif defined(GSDL_USE_IOS_H) # include # include #else # include # include #endif class __site_configuration : public configurable { private: text_t *gsdlhome; text_t *httpdomain; text_t *httpprefix; text_t *collection; text_tset *actions; text_tset *browsers; int *maxrequests; public: __site_configuration (text_t *_gsdlhome, int *_maxrequests) { gsdlhome = _gsdlhome; httpdomain = NULL; httpprefix = NULL; collection = NULL; actions = NULL; browsers = NULL; maxrequests = _maxrequests; } __site_configuration (text_t *_gsdlhome, text_t *_httpdomain, text_t *_httpprefix) { gsdlhome = _gsdlhome; httpdomain = _httpdomain; httpprefix = _httpprefix; collection = NULL; actions = NULL; browsers = NULL; maxrequests = NULL; } __site_configuration (text_t *_gsdlhome, text_t *_httpdomain, text_t *_httpprefix, text_t *_collection) { gsdlhome = _gsdlhome; httpdomain = _httpdomain; httpprefix = _httpprefix; collection = _collection; actions = NULL; browsers = NULL; maxrequests = NULL; } __site_configuration (text_t *_httpprefix, text_tset *_actions, text_tset *_browsers) { gsdlhome = NULL; httpdomain = NULL; httpprefix = _httpprefix; collection = NULL; actions = _actions; browsers = _browsers; maxrequests = NULL; } inline void configure (const text_t &key, const text_tarray &cfgline) { if (gsdlhome != NULL && key == "gsdlhome") { *gsdlhome = cfgline[0]; } if (httpprefix != NULL && key == "httpprefix") { *httpprefix = cfgline[0]; } if (httpdomain != NULL && key == "httpdomain") { *httpdomain = cfgline[0]; } if (collection != NULL && key == "collection") { *collection = cfgline[0]; } if (actions != NULL && key == "actions") { actions->clear(); text_tarray::const_iterator thisAction = cfgline.begin(); text_tarray::const_iterator endAction = cfgline.end(); while (thisAction != endAction) { actions->insert(*thisAction); ++thisAction; } } if (browsers != NULL && key == "browsers") { browsers->clear(); text_tarray::const_iterator thisBrowser = cfgline.begin(); text_tarray::const_iterator endBrowser = cfgline.end(); while (thisBrowser != endBrowser) { browsers->insert(*thisBrowser); ++thisBrowser; } } if (maxrequests != NULL && key == "maxrequests") { *maxrequests = cfgline[0].getint(); if ((*maxrequests) < 1) { *maxrequests = 1; } } } }; // 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 (configurator gsdlconfigurator, text_t &gsdlhome, int &maxrequests) { __site_configuration sitecfg(&gsdlhome, &maxrequests); gsdlconfigurator.add_configurable(&sitecfg); // blank the gsdl home text gsdlhome.clear(); if (gsdlconfigurator.configure("gsdlsite.cfg")) { return true; } return false; } // this version grabs gsdlhome, httpdomain and httpprefix, // returns false if it can't find all of them bool site_cfg_read (text_t &gsdlhome, text_t &httpdomain, text_t &httpprefix) { // get gsdlhome etc __site_configuration sitecfg(&gsdlhome, &httpdomain, &httpprefix); configurator gsdlconfigurator(&sitecfg); gsdlhome.clear(); httpdomain.clear(); httpprefix.clear(); if (gsdlconfigurator.configure("gsdlsite.cfg")) { return true; } return false; } // this version grabs gsdlhome, httpdomain, httpprefix, collection, // returns false if it can't find gsdlhome, httpdomain and httpprefix bool site_cfg_read (text_t &gsdlhome, text_t &httpdomain, text_t &httpprefix, text_t &collection) { // get gsdlhome etc __site_configuration sitecfg(&gsdlhome, &httpdomain, &httpprefix, &collection); configurator gsdlconfigurator(&sitecfg); gsdlhome.clear(); httpdomain.clear(); httpprefix.clear(); collection.clear(); if (gsdlconfigurator.configure("gsdlsite.cfg") && !gsdlhome.empty() && !httpdomain.empty() && !httpprefix.empty()) { return true; } return false; }