source: branches/corba/gsdl/src/colservr/collectset.cpp@ 1736

Last change on this file since 1736 was 1736, checked in by davidb, 23 years ago

Added gsdlhome to configuratin of cserver

  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1/**********************************************************************
2 *
3 * collectset.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: collectset.cpp 1736 2000-12-04 00:50:18Z davidb $
25 *
26 *********************************************************************/
27
28
29#include "collectserver.h"
30#include "filter.h"
31#include "browsefilter.h"
32#include "queryfilter.h"
33#include "infodbclass.h"
34#include "mgsearch.h"
35#include "mggdbmsource.h"
36#include "fileutil.h"
37#include <assert.h>
38
39#include "colservrconfig.h"
40#include "recptconfig.h"
41
42#include "collectset.h"
43
44collectset::collectset (text_t &gsdlhome) {
45
46 text_tarray collections;
47
48 // get gsdlhome (if we fail the error will be picked up later -- in
49 // cgiwrapper)
50 if (site_cfg_read (gsdlhome,httpdomain,httpprefix)) {
51 text_t collectdir = filename_cat (gsdlhome, "collect");
52 if (!read_dir (collectdir, collections)) {
53 cerr << "couldn't read collect directory - make sure gsdlhome field is correct in gsdlsite.cfg\n";
54 exit (1);
55 }
56 }
57
58 text_tarray::const_iterator thiscol = collections.begin();
59 text_tarray::const_iterator endcol = collections.end();
60
61 while (thiscol != endcol) {
62
63 // ignore the modelcol
64 if (*thiscol == "modelcol") {
65 thiscol ++;
66 continue;
67 }
68
69 // this memory is created but never destroyed
70 // we're also not doing any error checking to make sure we didn't
71 // run out of memory
72 collectserver *cserver = new collectserver();
73 gdbmclass *gdbmhandler = new gdbmclass();
74 mgsearchclass *mgsearch = new mgsearchclass();
75
76 // add a null filter
77 filterclass *filter = new filterclass ();
78 cserver->add_filter (filter);
79
80 // add a browse filter
81 browsefilterclass *browsefilter = new browsefilterclass();
82 browsefilter->set_gdbmptr (gdbmhandler);
83 cserver->add_filter (browsefilter);
84
85 // add a query filter
86 queryfilterclass *queryfilter = new queryfilterclass();
87 queryfilter->set_gdbmptr (gdbmhandler);
88 queryfilter->set_mgsearchptr (mgsearch);
89 cserver->add_filter (queryfilter);
90
91 // add a mg and gdbm source
92 mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass ();
93 mggdbmsource->set_gdbmptr (gdbmhandler);
94 mggdbmsource->set_mgsearchptr (mgsearch);
95 cserver->add_source (mggdbmsource);
96
97 // inform collection server and everything it contains about its
98 // collection name
99 cserver->configure ("collection", *thiscol);
100 // AZIZ: added on 10/10/00
101 // the cserver object does not have a reference to gsdlhome
102 cserver->configure ("gsdlhome", gsdlhome);
103
104 // GRB: removed proto.add_collectserver (cserver);
105 // GRB: added to build our own cservers list
106 cservers.addcollectserver (cserver);
107
108 thiscol ++;
109 }
110}
111
112collectset::~collectset () {
113}
114
115bool collectset::init (ostream &logout) {
116 collectservermapclass::iterator here = cservers.begin();
117 collectservermapclass::iterator end = cservers.end();
118
119 while (here != end) {
120 assert ((*here).second.c != NULL);
121 if ((*here).second.c != NULL) {
122 const colservrconf &configinfo = (*here).second.c->get_configinfo ();
123
124 // configure this collection server
125
126 // note that we read build.cfg before collect.cfg so that the indexmaps
127 // are available to decode defaultindex, defaultsubcollection, and
128 // defaultlanguage
129
130 if (!build_cfg_read (*((*here).second.c), configinfo.gsdlhome,
131 configinfo.collection)) {
132 outconvertclass text_t2ascii;
133 logout << text_t2ascii
134 << "Warning: couldn't read build.cfg file for collection \""
135 << configinfo.collection << "\", gsdlhome=\""
136 << configinfo.gsdlhome << "\"\n";
137 here ++;
138 continue;
139 }
140
141 if (!collect_cfg_read (*((*here).second.c), configinfo.gsdlhome,
142 configinfo.collection)) {
143 outconvertclass text_t2ascii;
144 logout << text_t2ascii
145 << "Warning: couldn't read collect.cfg file for collection \""
146 << configinfo.collection << "\", gsdlhome=\""
147 << configinfo.gsdlhome << "\"\n";
148 here ++;
149 continue;
150 }
151
152 if (!(*here).second.c->init (logout)) return false;
153
154 (*here).second.c->configure("httpdomain",httpdomain);
155 (*here).second.c->configure("httpprefix",httpprefix);
156 }
157 here++;
158 }
159
160 return true;
161}
162
163collectservermapclass collectset::servers()
164{ return cservers;
165}
166
167void collectset::configure(const text_t &key, const text_tarray &cfgline)
168{
169 if (key == "collection" || key == "collectdir") return;
170
171 collectservermapclass::iterator here = cservers.begin();
172 collectservermapclass::iterator end = cservers.end();
173
174 while (here != end) {
175 assert ((*here).second.c != NULL);
176 if ((*here).second.c != NULL) {
177 if (key == "collectinfo") {
178 if ((*here).first == cfgline[0]) {
179 (*here).second.c->configure ("gsdlhome", cfgline[1]);
180 (*here).second.c->configure ("gdbmhome", cfgline[2]);
181 }
182 } else {
183 // cout << "*** Passing on key = " << key << " = " << cfgline[0] << endl; // ****
184 (*here).second.c->configure (key, cfgline);
185 }
186 }
187
188 here++;
189 }
190}
191
192void collectset::getCollectionList (text_tarray &collist)
193{
194 collist.erase(collist.begin(),collist.end());
195
196 collectservermapclass::iterator here = cservers.begin();
197 collectservermapclass::iterator end = cservers.end();
198 while (here != end) {
199 assert ((*here).second.c != NULL);
200 if ((*here).second.c != NULL) {
201 collist.push_back ((*here).second.c->get_collection_name());
202 }
203 here++;
204 }
205}
206
Note: See TracBrowser for help on using the repository browser.