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

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

tidied up a few issues concerning the new debug info which showed
up on windows

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