[15402] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * gsdlsitecfg.cpp --
|
---|
| 4 | * Copyright (C) 2008 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 | *********************************************************************/
|
---|
| 25 |
|
---|
[16310] | 26 | #include "fileutil.h"
|
---|
[15402] | 27 | #include "gsdlsitecfg.h"
|
---|
| 28 |
|
---|
| 29 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
| 30 | # include <ospace/std/iostream>
|
---|
| 31 | # include <ospace/std/fstream>
|
---|
| 32 | #elif defined(GSDL_USE_IOS_H)
|
---|
| 33 | # include <iostream.h>
|
---|
| 34 | # include <fstream.h>
|
---|
| 35 | #else
|
---|
| 36 | # include <iostream>
|
---|
| 37 | # include <fstream>
|
---|
| 38 | #endif
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 | class __site_configuration : public configurable {
|
---|
| 42 | private:
|
---|
| 43 | text_t *gsdlhome;
|
---|
[16310] | 44 | text_t *collecthome;
|
---|
[15402] | 45 | text_t *httpdomain;
|
---|
| 46 | text_t *httpprefix;
|
---|
| 47 | text_t *collection;
|
---|
| 48 | text_tset *actions;
|
---|
| 49 | text_tset *browsers;
|
---|
| 50 | int *maxrequests;
|
---|
| 51 | public:
|
---|
[16310] | 52 | __site_configuration (text_t *_gsdlhome, text_t* _collecthome, int *_maxrequests) {
|
---|
[15402] | 53 | gsdlhome = _gsdlhome;
|
---|
[16310] | 54 | collecthome = _collecthome;
|
---|
[15402] | 55 | httpdomain = NULL;
|
---|
| 56 | httpprefix = NULL;
|
---|
| 57 | collection = NULL;
|
---|
| 58 | actions = NULL;
|
---|
| 59 | browsers = NULL;
|
---|
| 60 | maxrequests = _maxrequests;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[16310] | 63 | __site_configuration (text_t *_gsdlhome, text_t* _collecthome,
|
---|
| 64 | text_t *_httpdomain, text_t *_httpprefix) {
|
---|
[15402] | 65 | gsdlhome = _gsdlhome;
|
---|
[16310] | 66 | collecthome = _collecthome;
|
---|
[15402] | 67 | httpdomain = _httpdomain;
|
---|
| 68 | httpprefix = _httpprefix;
|
---|
| 69 | collection = NULL;
|
---|
| 70 | actions = NULL;
|
---|
| 71 | browsers = NULL;
|
---|
| 72 | maxrequests = NULL;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[16310] | 75 | __site_configuration (text_t *_gsdlhome, text_t* _collecthome,
|
---|
| 76 | text_t *_httpdomain,
|
---|
[15402] | 77 | text_t *_httpprefix, text_t *_collection) {
|
---|
| 78 | gsdlhome = _gsdlhome;
|
---|
[16310] | 79 | collecthome = _collecthome;
|
---|
[15402] | 80 | httpdomain = _httpdomain;
|
---|
| 81 | httpprefix = _httpprefix;
|
---|
| 82 | collection = _collection;
|
---|
| 83 | actions = NULL;
|
---|
| 84 | browsers = NULL;
|
---|
| 85 | maxrequests = NULL;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | __site_configuration (text_t *_httpprefix, text_tset *_actions, text_tset *_browsers) {
|
---|
| 89 | gsdlhome = NULL;
|
---|
[16310] | 90 | collecthome = NULL;
|
---|
[15402] | 91 | httpdomain = NULL;
|
---|
| 92 | httpprefix = _httpprefix;
|
---|
| 93 | collection = NULL;
|
---|
| 94 | actions = _actions;
|
---|
| 95 | browsers = _browsers;
|
---|
| 96 | maxrequests = NULL;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | inline void configure (const text_t &key, const text_tarray &cfgline) {
|
---|
| 100 | if (gsdlhome != NULL && key == "gsdlhome") {
|
---|
| 101 | *gsdlhome = cfgline[0];
|
---|
[16310] | 102 |
|
---|
| 103 | if ((collecthome != NULL) && (collecthome->empty())) {
|
---|
| 104 | // defaults to <gsdlhome>/collect
|
---|
| 105 | *collecthome = filename_cat(*gsdlhome,"collect");
|
---|
| 106 | }
|
---|
[15402] | 107 | }
|
---|
| 108 |
|
---|
[16310] | 109 | if (collecthome != NULL && key == "collecthome") {
|
---|
| 110 | if (!collecthome->empty()) {
|
---|
| 111 | // if it has been previously set to default, free and then reassign
|
---|
| 112 | collecthome->clear();
|
---|
| 113 | }
|
---|
| 114 | *collecthome = cfgline[0];
|
---|
| 115 | }
|
---|
| 116 |
|
---|
[15402] | 117 | if (httpprefix != NULL && key == "httpprefix") {
|
---|
| 118 | *httpprefix = cfgline[0];
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | if (httpdomain != NULL && key == "httpdomain") {
|
---|
| 122 | *httpdomain = cfgline[0];
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | if (collection != NULL && key == "collection") {
|
---|
| 126 | *collection = cfgline[0];
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | if (actions != NULL && key == "actions") {
|
---|
| 130 | actions->clear();
|
---|
| 131 | text_tarray::const_iterator thisAction = cfgline.begin();
|
---|
| 132 | text_tarray::const_iterator endAction = cfgline.end();
|
---|
| 133 | while (thisAction != endAction) {
|
---|
| 134 | actions->insert(*thisAction);
|
---|
| 135 | ++thisAction;
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | if (browsers != NULL && key == "browsers") {
|
---|
| 140 | browsers->clear();
|
---|
| 141 | text_tarray::const_iterator thisBrowser = cfgline.begin();
|
---|
| 142 | text_tarray::const_iterator endBrowser = cfgline.end();
|
---|
| 143 | while (thisBrowser != endBrowser) {
|
---|
| 144 | browsers->insert(*thisBrowser);
|
---|
| 145 | ++thisBrowser;
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | if (maxrequests != NULL && key == "maxrequests") {
|
---|
| 150 | *maxrequests = cfgline[0].getint();
|
---|
| 151 | if ((*maxrequests) < 1) {
|
---|
| 152 | *maxrequests = 1;
|
---|
| 153 | }
|
---|
| 154 | }
|
---|
| 155 | }
|
---|
| 156 | };
|
---|
| 157 |
|
---|
| 158 |
|
---|
| 159 | // reads site configuration file returning true on success
|
---|
| 160 | // also sets gsdlhome and maxrequests
|
---|
| 161 | // gsdlsite.cfg should be in same directory as library executable
|
---|
[16310] | 162 | bool site_cfg_read (configurator gsdlconfigurator, text_t &gsdlhome,
|
---|
| 163 | text_t& collecthome, int &maxrequests)
|
---|
[15402] | 164 | {
|
---|
[16310] | 165 | __site_configuration sitecfg(&gsdlhome, &collecthome, &maxrequests);
|
---|
[15402] | 166 | gsdlconfigurator.add_configurable(&sitecfg);
|
---|
| 167 |
|
---|
[16310] | 168 | // blank the gsdlhome and collecthome text
|
---|
[15402] | 169 | gsdlhome.clear();
|
---|
[16310] | 170 | collecthome.clear();
|
---|
[15402] | 171 |
|
---|
| 172 | if (gsdlconfigurator.configure("gsdlsite.cfg"))
|
---|
| 173 | {
|
---|
| 174 | return true;
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | return false;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 |
|
---|
[16310] | 181 | // this version grabs gsdlhome, collecthome, httpdomain and httpprefix,
|
---|
[15402] | 182 | // returns false if it can't find all of them
|
---|
[16310] | 183 | bool site_cfg_read (text_t &gsdlhome, text_t& collecthome, text_t &httpdomain,
|
---|
[15402] | 184 | text_t &httpprefix)
|
---|
| 185 | {
|
---|
| 186 | // get gsdlhome etc
|
---|
[16310] | 187 | __site_configuration sitecfg(&gsdlhome, &collecthome, &httpdomain, &httpprefix);
|
---|
[15402] | 188 | configurator gsdlconfigurator(&sitecfg);
|
---|
| 189 |
|
---|
| 190 | gsdlhome.clear();
|
---|
[16310] | 191 | collecthome.clear();
|
---|
[15402] | 192 | httpdomain.clear();
|
---|
| 193 | httpprefix.clear();
|
---|
| 194 |
|
---|
| 195 | if (gsdlconfigurator.configure("gsdlsite.cfg"))
|
---|
| 196 | {
|
---|
| 197 | return true;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | return false;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 |
|
---|
[16310] | 204 | // this version grabs gsdlhome, collecthome, httpdomain, httpprefix, collection,
|
---|
[15402] | 205 | // returns false if it can't find gsdlhome, httpdomain and httpprefix
|
---|
[16310] | 206 | bool site_cfg_read (text_t &gsdlhome, text_t& collecthome, text_t &httpdomain,
|
---|
[15402] | 207 | text_t &httpprefix, text_t &collection)
|
---|
| 208 | {
|
---|
| 209 | // get gsdlhome etc
|
---|
[16310] | 210 | __site_configuration sitecfg(&gsdlhome, &collecthome, &httpdomain, &httpprefix, &collection);
|
---|
[15402] | 211 | configurator gsdlconfigurator(&sitecfg);
|
---|
| 212 |
|
---|
| 213 | gsdlhome.clear();
|
---|
[16310] | 214 | collecthome.clear();
|
---|
[15402] | 215 | httpdomain.clear();
|
---|
| 216 | httpprefix.clear();
|
---|
| 217 | collection.clear();
|
---|
| 218 |
|
---|
| 219 | if (gsdlconfigurator.configure("gsdlsite.cfg") &&
|
---|
[16310] | 220 | !gsdlhome.empty() && !collecthome.empty()
|
---|
| 221 | && !httpdomain.empty() && !httpprefix.empty())
|
---|
[15402] | 222 | {
|
---|
| 223 | return true;
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | return false;
|
---|
| 227 | }
|
---|