source: branches/New_Config_Format-branch/gsdl/src/recpt/recptconfig.cpp@ 1279

Last change on this file since 1279 was 1279, checked in by sjboddie, 24 years ago

merged changes to trunk into New_Config_Format branch

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 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 * $Id: recptconfig.cpp 1279 2000-07-12 22:21:53Z sjboddie $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
30 Revision 1.6.4.1 2000/07/12 22:21:45 sjboddie
31 merged changes to trunk into New_Config_Format branch
32
33 Revision 1.9 2000/05/12 03:09:24 sjboddie
34 minor modifications to get web library compiling under VC++ 6.0
35
36 Revision 1.8 2000/04/14 03:10:35 sjboddie
37 tidied up a few issues concerning the new debug info which showed
38 up on windows
39
40 Revision 1.7 2000/04/14 02:52:06 sjboddie
41 tidied up error messaging and set up some debugging info to be output
42 when running library from command line
43
44 Revision 1.6 2000/02/21 21:55:33 sjboddie
45 gsdlhome now comes from gsdlsite.cfg
46
47 Revision 1.5 1999/09/07 04:56:59 sjboddie
48 added GPL notice
49
50 Revision 1.4 1999/09/07 00:09:31 sjboddie
51 now reads in both main.cfg and collect.cfg always
52
53 Revision 1.3 1999/02/21 22:33:57 rjmcnab
54
55 Lots of stuff :-)
56
57 Revision 1.2 1999/02/08 01:28:04 rjmcnab
58
59 Got the receptionist producing something using the statusaction.
60
61 Revision 1.1 1999/02/05 06:50:32 rjmcnab
62
63 Initial revision.
64
65 */
66
67
68#include "recptconfig.h"
69#include "fileutil.h"
70#include "cfgread.h"
71
72
73#if defined(GSDL_USE_OBJECTSPACE)
74# include <ospace/std/iostream>
75# include <ospace/std/fstream>
76#elif defined(GSDL_USE_IOS_H)
77# include <iostream.h>
78# include <fstream.h>
79#else
80# include <iostream>
81# include <fstream>
82#endif
83
84
85// reads site configuration file returning true on success
86// also sets gsdlhome and maxrequests
87// gsdlsite.cfg should be in same directory as library executable
88bool site_cfg_read (receptionist &recpt, text_t &gsdlhome, int &maxrequests) {
89
90 gsdlhome.clear();
91
92 // Look for gsdlsite.cfg in same directory that executable is in.
93 text_tarray cfgline;
94 text_t key;
95
96#ifdef GSDL_USE_IOS_H
97 ifstream confin ("gsdlsite.cfg", ios::in | ios::nocreate);
98#else
99 ifstream confin ("gsdlsite.cfg", ios::in);
100#endif
101
102 if (confin) {
103 while (read_cfg_line(confin, cfgline) >= 0) {
104 if (cfgline.size () >= 2) {
105 key = cfgline[0];
106 cfgline.erase(cfgline.begin());
107
108 if (key == "maxrequests") {
109 maxrequests = cfgline[0].getint();
110 if (maxrequests < 1) maxrequests = 1;
111 }
112
113 if (key == "gsdlhome")
114 gsdlhome = cfgline[0];
115
116 // configure the receptionist
117 recpt.configure (key, cfgline);
118 }
119 }
120 confin.close ();
121 return true;
122 }
123 return false;
124}
125
126// this version just grabs gsdlhome, returning true
127// unless unable to read gsdlsite.cfg
128bool site_cfg_read (text_t &gsdlhome) {
129
130 gsdlhome.clear();
131
132 // Look for gsdlsite.cfg in same directory that executable is in.
133 text_tarray cfgline;
134 text_t key;
135
136#ifdef GSDL_USE_IOS_H
137 ifstream confin ("gsdlsite.cfg", ios::in | ios::nocreate);
138#else
139 ifstream confin ("gsdlsite.cfg", ios::in);
140#endif
141
142 if (confin) {
143 while (read_cfg_line(confin, cfgline) >= 0) {
144 if (cfgline.size () >= 2) {
145 if (cfgline[0] == "gsdlhome") {
146 gsdlhome = cfgline[1];
147 break;
148 }
149 }
150 }
151 return true;
152 confin.close ();
153 }
154 return false;
155}
156
157// main_cfg_read reads both main.cfg and collect.cfg. It attempts
158// to read main.cfg first so values in collect.cfg override those
159// set earlier by main.cfg
160bool main_cfg_read (receptionist &recpt, const text_t &gsdlhome,
161 const text_t &collection) {
162
163 // read in the main configuration file
164 bool rv = false;
165 text_t key, filename;
166 text_tarray cfgline;
167 filename = filename_cat (gsdlhome, "etc");
168 filename = filename_cat (filename, "main.cfg");
169 if (file_exists (filename)) {
170 char *cstr = filename.getcstr();
171
172#ifdef GSDL_USE_IOS_H
173 ifstream confin (cstr, ios::in | ios::nocreate);
174#else
175 ifstream confin (cstr, ios::in);
176#endif
177
178 delete cstr;
179
180 if (confin) {
181 while (read_cfg_line(confin, cfgline) >= 0) {
182 if (cfgline.size () >= 2) {
183 key = cfgline[0];
184 cfgline.erase(cfgline.begin());
185
186 // configure the receptionist
187 recpt.configure (key, cfgline);
188 }
189 }
190 confin.close ();
191 rv = true;
192 }
193 }
194
195 // Look for collect.cfg in GSDLHOME/collect/collection-name/etc directory
196 // (if this is for a particular collection), and then GSDLHOME/etc.
197 if (!collection.empty()) {
198 filename = filename_cat (gsdlhome, "collect");
199 filename = filename_cat (filename, collection);
200 filename = filename_cat (filename, "etc");
201 filename = filename_cat (filename, "collect.cfg");
202 if (!file_exists (filename)) {
203 filename = filename_cat (gsdlhome, "etc");
204 filename = filename_cat (filename, "collect.cfg");
205 if (!file_exists (filename)) filename.clear();
206 }
207
208 if (!filename.empty()) {
209 char *cstr = filename.getcstr();
210
211#ifdef GSDL_USE_IOS_H
212 ifstream confin (cstr, ios::in | ios::nocreate);
213#else
214 ifstream confin (cstr, ios::in);
215#endif
216
217 delete cstr;
218
219 if (confin) {
220 while (read_cfg_line(confin, cfgline) >= 0) {
221 if (cfgline.size () >= 2) {
222 key = cfgline[0];
223 cfgline.erase(cfgline.begin());
224
225 // configure the receptionist
226 recpt.configure (key, cfgline);
227 }
228 }
229 confin.close ();
230 rv = true;
231 }
232 }
233 }
234 return rv;
235}
Note: See TracBrowser for help on using the repository browser.