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

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

minor modifications to get web library compiling under VC++ 6.0

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