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

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

Removed CVS logging information from source files

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