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

Last change on this file since 533 was 533, checked in by sjboddie, 25 years ago

added GPL notice

  • 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 * $Id: recptconfig.cpp 533 1999-09-07 04:57:01Z sjboddie $
25 *
26 *********************************************************************/
27
28/*
29 $Log$
30 Revision 1.5 1999/09/07 04:56:59 sjboddie
31 added GPL notice
32
33 Revision 1.4 1999/09/07 00:09:31 sjboddie
34 now reads in both main.cfg and collect.cfg always
35
36 Revision 1.3 1999/02/21 22:33:57 rjmcnab
37
38 Lots of stuff :-)
39
40 Revision 1.2 1999/02/08 01:28:04 rjmcnab
41
42 Got the receptionist producing something using the statusaction.
43
44 Revision 1.1 1999/02/05 06:50:32 rjmcnab
45
46 Initial revision.
47
48 */
49
50
51#include "recptconfig.h"
52#include "fileutil.h"
53#include "cfgread.h"
54
55
56#if defined(GSDL_USE_OBJECTSPACE)
57# include <ospace/std/iostream>
58# include <ospace/std/fstream>
59#elif defined(GSDL_USE_IOS_H)
60# include <iostream.h>
61# include <fstream.h>
62#else
63# include <iostream>
64# include <fstream>
65#endif
66
67
68// reads site configuration file returning true on success
69bool site_cfg_read (receptionist &recpt, const text_t &gsdlhome,
70 const text_t &collection, int &maxrequests) {
71
72 maxrequests = 10000; // a reasonable default
73
74 // Look for site.cfg in GSDLHOME/collect/collection-name/etc directory
75 // (if this is for a particular collection), and then GSDLHOME/etc.
76 text_t filename;
77 if (!collection.empty()) {
78 filename = filename_cat (gsdlhome, "collect");
79 filename = filename_cat (filename, collection);
80 filename = filename_cat (filename, "etc");
81 filename = filename_cat (filename, "site.cfg");
82 if (!file_exists (filename)) filename.clear();
83 }
84 if (filename.empty()) {
85 filename = filename_cat (gsdlhome, "etc");
86 filename = filename_cat (filename, "site.cfg");
87 if (!file_exists (filename)) return false;
88 }
89
90 // read in the site configuration file
91 text_tarray cfgline;
92 text_t key;
93 char *cstr = filename.getcstr();
94 ifstream confin (cstr);
95 delete cstr;
96
97 if (confin) {
98 while (read_cfg_line(confin, cfgline) >= 0) {
99 if (cfgline.size () >= 2) {
100 key = cfgline[0];
101 cfgline.erase(cfgline.begin());
102
103 if (key == "maxrequests") {
104 maxrequests = cfgline[0].getint();
105 if (maxrequests < 1) maxrequests = 1;
106 }
107
108 // configure the receptionist
109 recpt.configure (key, cfgline);
110 }
111 }
112 confin.close ();
113 return true;
114 }
115 return false;
116}
117
118
119// main_cfg_read reads both main.cfg and collect.cfg. It attempts
120// to read main.cfg first so values in collect.cfg override those
121// set earlier by main.cfg
122bool main_cfg_read (receptionist &recpt, const text_t &gsdlhome,
123 const text_t &collection) {
124
125 // read in the main configuration file
126 bool rv = false;
127 text_t key, filename;
128 text_tarray cfgline;
129 filename = filename_cat (gsdlhome, "etc");
130 filename = filename_cat (filename, "main.cfg");
131 if (file_exists (filename)) {
132 char *cstr = filename.getcstr();
133 ifstream confin (cstr);
134 delete cstr;
135
136 if (confin) {
137 while (read_cfg_line(confin, cfgline) >= 0) {
138 if (cfgline.size () >= 2) {
139 key = cfgline[0];
140 cfgline.erase(cfgline.begin());
141
142 // configure the receptionist
143 recpt.configure (key, cfgline);
144 }
145 }
146 confin.close ();
147 rv = true;
148 }
149 }
150
151 // Look for collect.cfg in GSDLHOME/collect/collection-name/etc directory
152 // (if this is for a particular collection), and then GSDLHOME/etc.
153 if (!collection.empty()) {
154 filename = filename_cat (gsdlhome, "collect");
155 filename = filename_cat (filename, collection);
156 filename = filename_cat (filename, "etc");
157 filename = filename_cat (filename, "collect.cfg");
158 if (!file_exists (filename)) {
159 filename = filename_cat (gsdlhome, "etc");
160 filename = filename_cat (filename, "collect.cfg");
161 if (!file_exists (filename)) filename.clear();
162 }
163
164 if (!filename.empty()) {
165 char *cstr = filename.getcstr();
166 ifstream confin (cstr);
167 delete cstr;
168
169 if (confin) {
170 while (read_cfg_line(confin, cfgline) >= 0) {
171 if (cfgline.size () >= 2) {
172 key = cfgline[0];
173 cfgline.erase(cfgline.begin());
174
175 // configure the receptionist
176 recpt.configure (key, cfgline);
177 }
178 }
179 confin.close ();
180 rv = true;
181 }
182 }
183 }
184 return rv;
185}
Note: See TracBrowser for help on using the repository browser.