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