source: main/tags/2.27/gsdl/src/recpt/nullproto.cpp

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

Tidied up collectoraction some more and created an add_collection
function in nullproto that does all the work of setting up a
local collection server

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 9.5 KB
Line 
1/**********************************************************************
2 *
3 * nullproto.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 "nullproto.h"
27#include "colservrconfig.h"
28#include <assert.h>
29
30#include "filter.h"
31#include "browsefilter.h"
32#include "mgqueryfilter.h"
33#include "mgppqueryfilter.h"
34#include "infodbclass.h"
35#include "mggdbmsource.h"
36#include "mgsearch.h"
37#include "mgppsearch.h"
38#include "fileutil.h"
39
40
41nullproto::~nullproto() {
42 collectservermapclass::iterator here = cservers.begin();
43 collectservermapclass::iterator end = cservers.end();
44
45 while (here != end) {
46 if ((*here).second.c != NULL) {
47 delete (*here).second.c;
48 }
49 here ++;
50 }
51 cservers.clear();
52}
53
54// add_collection sets up the collectionserver and calls
55// add_collectserver
56void nullproto::add_collection (const text_t &collection, void *recpt,
57 const text_t &gsdlhome, const text_t &gdbmhome) {
58
59 // read config file to see if built with mg or mgpp
60 // -- we can rely on the collection (and therefore the build.cfg)
61 // being here since this is the null protocol - a nicer way to
62 // do this would be preferable though - Stefan.
63 text_t buildtype = "mg"; // mg is default
64 // (for now we'll just ignore mgpp if on windows)
65#ifndef __WIN32__
66 text_tarray cfgline;
67 text_t key;
68 text_t build_cfg = filename_cat(gsdlhome, "collect", collection, "index", "build.cfg");
69 char *build_cfgc = build_cfg.getcstr();
70 ifstream confin(build_cfgc);
71
72 if (confin) {
73 while (read_cfg_line(confin, cfgline) >= 0) {
74 if (cfgline.size() == 2) {
75 key = cfgline[0];
76 cfgline.erase(cfgline.begin());
77 if (key == "buildtype") {
78 buildtype = cfgline[0];
79 break;
80 }
81 }
82 }
83 confin.close();
84 }
85 delete build_cfgc;
86#endif
87
88 collectserver *cserver = new collectserver();
89 gdbmclass *gdbmhandler = new gdbmclass();
90
91 // add a null filter
92 filterclass *filter = new filterclass ();
93 cserver->add_filter (filter);
94
95 // add a browse filter
96 browsefilterclass *browsefilter = new browsefilterclass();
97 browsefilter->set_gdbmptr (gdbmhandler);
98
99 cserver->add_filter (browsefilter);
100
101 if (buildtype == "mg") {
102 mgsearchclass *mgsearch = new mgsearchclass();
103
104 // add a query filter
105 mgqueryfilterclass *queryfilter = new mgqueryfilterclass();
106 queryfilter->set_gdbmptr (gdbmhandler);
107 queryfilter->set_mgsearchptr (mgsearch);
108 cserver->add_filter (queryfilter);
109
110 // add a mg and gdbm source
111 mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass ();
112 mggdbmsource->set_gdbmptr (gdbmhandler);
113 mggdbmsource->set_mgsearchptr (mgsearch);
114 cserver->add_source (mggdbmsource);
115 }
116
117#ifndef __WIN32__
118
119 else if (buildtype == "mgpp") {
120
121 mgppsearchclass *mgsearch = new mgppsearchclass();
122
123 // add a query filter
124 mgppqueryfilterclass *queryfilter = new mgppqueryfilterclass();
125 queryfilter->set_gdbmptr (gdbmhandler);
126 queryfilter->set_mgsearchptr (mgsearch);
127 cserver->add_filter (queryfilter);
128
129 // add a mg and gdbm source
130 mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass ();
131 mggdbmsource->set_gdbmptr (gdbmhandler);
132 mggdbmsource->set_mgsearchptr (mgsearch);
133 cserver->add_source (mggdbmsource);
134
135 }
136#endif
137
138 // inform collection server and everything it contains about its
139 // collection name
140 cserver->configure ("collection", collection);
141
142 // configure receptionist's collectinfo structure
143 text_tarray colinfo;
144 colinfo.push_back (collection);
145 colinfo.push_back (gsdlhome);
146 colinfo.push_back (gdbmhome);
147 receptionist *rcp = (receptionist *)recpt;
148 rcp->configure ("collectinfo", colinfo);
149
150 add_collectserver (cserver);
151}
152
153// this configure will configure each of the collection servers
154void nullproto::configure (const text_t &key, const text_tarray &cfgline) {
155 // the naming of the collection should not be done here,
156 // it should be done just after the collection server has been
157 // created
158 if (key == "collection" || key == "collectdir") return;
159
160 collectservermapclass::iterator here = cservers.begin();
161 collectservermapclass::iterator end = cservers.end();
162
163 while (here != end) {
164 assert ((*here).second.c != NULL);
165 if ((*here).second.c != NULL) {
166 if (key == "collectinfo") {
167 if ((*here).first == cfgline[0]) {
168 (*here).second.c->configure ("gsdlhome", cfgline[1]);
169 (*here).second.c->configure ("gdbmhome", cfgline[2]);
170 }
171 } else {
172 (*here).second.c->configure (key, cfgline);
173 }
174 }
175
176 here++;
177 }
178}
179
180// this init will configure and init each of the collection servers
181bool nullproto::init (ostream &logout) {
182 collectservermapclass::iterator here = cservers.begin();
183 collectservermapclass::iterator end = cservers.end();
184
185 while (here != end) {
186 assert ((*here).second.c != NULL);
187 if ((*here).second.c != NULL) {
188 const colservrconf &configinfo = (*here).second.c->get_configinfo ();
189 bool failed = false;
190
191 // configure this collection server
192
193 // note that we read build.cfg before collect.cfg so that the indexmaps
194 // are available to decode defaultindex, defaultsubcollection, and
195 // defaultlanguage
196 if (!build_cfg_read (*((*here).second.c), configinfo.gsdlhome,
197 configinfo.collection)) {
198 outconvertclass text_t2ascii;
199 logout << text_t2ascii
200 << "Warning: couldn't read build.cfg file for collection \"" //****
201 << configinfo.collection << "\", gsdlhome=\""
202 << configinfo.gsdlhome << "\"\n";
203 failed = true;
204 }
205
206 if (!collect_cfg_read (*((*here).second.c), configinfo.gsdlhome,
207 configinfo.collection)) {
208 outconvertclass text_t2ascii;
209 logout << text_t2ascii
210 << "Warning: couldn't read collect.cfg file for collection \""
211 << configinfo.collection << "\", gsdlhome=\""
212 << configinfo.gsdlhome << "\"\n";
213 failed = true;
214 }
215
216 // don't bother initializing if one of the config files
217 // wasn't read correctly
218 if (!failed) {
219 if (!(*here).second.c->init (logout)) return false;
220 }
221 }
222 here++;
223 }
224
225 return true;
226}
227
228text_t nullproto::get_protocol_name () {
229 return "nullproto";
230}
231
232
233void nullproto::get_collection_list (text_tarray &collist, comerror_t &err,
234 ostream &/*logout*/) {
235 collist.erase(collist.begin(),collist.end());
236 err = noError;
237
238 collectservermapclass::iterator here = cservers.begin();
239 collectservermapclass::iterator end = cservers.end();
240 while (here != end) {
241 assert ((*here).second.c != NULL);
242 if ((*here).second.c != NULL) {
243 collist.push_back ((*here).second.c->get_collection_name());
244 }
245 here++;
246 }
247}
248
249void nullproto::has_collection (const text_t &collection, bool &hascollection,
250 comerror_t &err, ostream &/*logout*/) {
251 hascollection = (cservers.getcollectserver(collection) != NULL);
252 err = noError;
253}
254
255void nullproto::ping (const text_t &collection, bool &wassuccess,
256 comerror_t &err, ostream &/*logout*/) {
257 wassuccess = (cservers.getcollectserver(collection) != NULL);
258 err = noError;
259}
260
261void nullproto::get_collectinfo (const text_t &collection,
262 ColInfoResponse_t &collectinfo,
263 comerror_t &err, ostream &logout) {
264 collectserver *cserver = cservers.getcollectserver (collection);
265 if (cserver != NULL) cserver->get_collectinfo (collectinfo, err, logout);
266 else err = protocolError;
267}
268
269
270void nullproto::get_filterinfo (const text_t &collection,
271 InfoFiltersResponse_t &response,
272 comerror_t &err, ostream &logout) {
273 collectserver *cserver = cservers.getcollectserver (collection);
274 if (cserver != NULL) cserver->get_filterinfo (response, err, logout);
275 else err = protocolError;
276}
277
278void nullproto::get_filteroptions (const text_t &collection,
279 const InfoFilterOptionsRequest_t &request,
280 InfoFilterOptionsResponse_t &response,
281 comerror_t &err, ostream &logout) {
282 collectserver *cserver = cservers.getcollectserver (collection);
283 if (cserver != NULL) cserver->get_filteroptions (request, response, err, logout);
284 else err = protocolError;
285}
286
287void nullproto::filter (const text_t &collection,
288 FilterRequest_t &request,
289 FilterResponse_t &response,
290 comerror_t &err, ostream &logout) {
291 collectserver *cserver = cservers.getcollectserver (collection);
292 if (cserver != NULL) cserver->filter (request, response, err, logout);
293 else err = protocolError;
294}
295
296void nullproto::get_document (const text_t &collection,
297 const DocumentRequest_t &request,
298 DocumentResponse_t &response,
299 comerror_t &err, ostream &logout) {
300 collectserver *cserver = cservers.getcollectserver (collection);
301 if (cserver != NULL) cserver->get_document (request, response, err, logout);
302 else err = protocolError;
303}
Note: See TracBrowser for help on using the repository browser.