source: trunk/gsdl/src/recpt/recptconfig.cpp@ 1860

Last change on this file since 1860 was 1860, checked in by cs025, 23 years ago

Included CORBA branch for first time

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/**********************************************************************
2 *
3 * recptconfig.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 *********************************************************************/
25
26#include "recptconfig.h"
27#include "fileutil.h"
28#include "cfgread.h"
29#include "cnfgator.h"
30
31
32#if defined(GSDL_USE_OBJECTSPACE)
33# include <ospace/std/iostream>
34# include <ospace/std/fstream>
35#elif defined(GSDL_USE_IOS_H)
36# include <iostream.h>
37# include <fstream.h>
38#else
39# include <iostream>
40# include <fstream>
41#endif
42
43class __site_configuration : public configurable {
44private:
45 text_t *gsdlhome;
46 text_t *httpdomain;
47 text_t *httpprefix;
48 int *maxrequests;
49public:
50 __site_configuration (text_t *_gsdlhome, int *_maxrequests) {
51 gsdlhome = _gsdlhome;
52 httpdomain = NULL;
53 httpprefix = NULL;
54 maxrequests = _maxrequests;
55 }
56
57 __site_configuration (text_t *_gsdlhome, text_t *_httpdomain,
58 text_t *_httpprefix) {
59 gsdlhome = _gsdlhome;
60 httpdomain = _httpdomain;
61 httpprefix = _httpprefix;
62 maxrequests = NULL;
63 }
64
65 inline void configure (const text_t &key, const text_tarray &cfgline) {
66 if (key == "gsdlhome") {
67 *gsdlhome = cfgline[0];
68 }
69
70 if (key == "httpprefix" &&
71 httpprefix != NULL) {
72 *httpprefix = cfgline[0];
73 }
74
75 if (key == "httpdomain" &&
76 httpdomain != NULL) {
77 *httpdomain = cfgline[0];
78 }
79
80 if (key == "maxrequests" &&
81 maxrequests != NULL) {
82 *maxrequests = cfgline[0].getint();
83 if ((*maxrequests) < 1) {
84 *maxrequests = 1;
85 }
86 }
87 }
88};
89
90
91// reads site configuration file returning true on success
92// also sets gsdlhome and maxrequests
93// gsdlsite.cfg should be in same directory as library executable
94bool site_cfg_read (receptionist &recpt, text_t &gsdlhome, int &maxrequests) {
95 // initialise configurator, etc.
96 __site_configuration sitecfg (&gsdlhome, &maxrequests);
97 configurator gsdlconfigurator(&recpt);
98
99 gsdlconfigurator.add_configurable(&sitecfg);
100
101 // blank the gsdl home text
102 gsdlhome.clear();
103
104 if (gsdlconfigurator.configure("gsdlsite.cfg")) {
105 return true;
106 }
107 return false;
108}
109
110// this version grabs gsdlhome, httpdomain and httpprefix,
111// returns false if it can't find all of them
112bool site_cfg_read (text_t &gsdlhome, text_t &httpdomain,
113 text_t &httpprefix) {
114 // get gsdlhome etc
115 __site_configuration sitecfg(&gsdlhome, &httpdomain, &httpprefix);
116 configurator gsdlconfigurator(&sitecfg);
117
118 gsdlhome.clear();
119 httpdomain.clear();
120 httpprefix.clear();
121
122 if (gsdlconfigurator.configure("gsdlsite.cfg") &&
123 !gsdlhome.empty() && !httpdomain.empty() && !httpprefix.empty()) {
124 return true;
125 }
126
127 return true;
128
129 return false;
130}
131
132// main_cfg_read reads both main.cfg and collect.cfg. It attempts
133// to read main.cfg first so values in collect.cfg override those
134// set earlier by main.cfg
135bool main_cfg_read (receptionist &recpt, const text_t &gsdlhome,
136 const text_t &collection) {
137
138 // read in the main configuration file
139 bool rv = false;
140
141 text_t key, filename;
142 text_tarray cfgline;
143 filename = filename_cat (gsdlhome, "etc");
144 filename = filename_cat (filename, "main.cfg");
145 if (file_exists (filename)) {
146 rv = recpt.read_configfile(filename);
147 }
148
149 // Look for collect.cfg in GSDLHOME/collect/collection-name/etc directory
150 // (if this is for a particular collection), and then GSDLHOME/etc.
151 if (!collection.empty()) {
152 filename = filename_cat (gsdlhome, "collect");
153 filename = filename_cat (filename, collection);
154 filename = filename_cat (filename, "etc");
155 filename = filename_cat (filename, "collect.cfg");
156 if (!file_exists (filename)) {
157 filename = filename_cat (gsdlhome, "etc");
158 filename = filename_cat (filename, "collect.cfg");
159 if (!file_exists (filename)) filename.clear();
160 }
161
162 if (!filename.empty()) {
163 rv |= recpt.read_configfile(filename);
164 }
165 }
166 return rv;
167}
Note: See TracBrowser for help on using the repository browser.