[226] | 1 |
|
---|
[166] | 2 | /**********************************************************************
|
---|
| 3 | *
|
---|
| 4 | * collectserver.cpp --
|
---|
| 5 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 6 | *
|
---|
[534] | 7 | * A component of the Greenstone digital library software
|
---|
| 8 | * from the New Zealand Digital Library Project at the
|
---|
| 9 | * University of Waikato, New Zealand.
|
---|
[166] | 10 | *
|
---|
[534] | 11 | * This program is free software; you can redistribute it and/or modify
|
---|
| 12 | * it under the terms of the GNU General Public License as published by
|
---|
| 13 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 14 | * (at your option) any later version.
|
---|
| 15 | *
|
---|
| 16 | * This program is distributed in the hope that it will be useful,
|
---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | * GNU General Public License for more details.
|
---|
| 20 | *
|
---|
| 21 | * You should have received a copy of the GNU General Public License
|
---|
| 22 | * along with this program; if not, write to the Free Software
|
---|
| 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 24 | *
|
---|
[166] | 25 | *********************************************************************/
|
---|
| 26 |
|
---|
| 27 | #include "collectserver.h"
|
---|
[249] | 28 | #include "infodbclass.h"
|
---|
| 29 | #include "OIDtools.h"
|
---|
[166] | 30 | #include <assert.h>
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | collectserver::collectserver () {
|
---|
| 34 | configinfo.collection = "null";
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | collectserver::~collectserver () {
|
---|
[1459] | 38 |
|
---|
| 39 | // clean up the sources
|
---|
| 40 | sourcelistclass::iterator source_here = sources.begin();
|
---|
| 41 | sourcelistclass::iterator source_end = sources.end();
|
---|
| 42 | while (source_here != source_end) {
|
---|
| 43 | if ((*source_here).s != NULL)
|
---|
| 44 | delete (*source_here).s;
|
---|
| 45 | source_here++;
|
---|
| 46 | }
|
---|
| 47 | sources.clear();
|
---|
| 48 |
|
---|
| 49 | // clean up the filters
|
---|
| 50 | filtermapclass::iterator filter_here = filters.begin();
|
---|
| 51 | filtermapclass::iterator filter_end = filters.end();
|
---|
| 52 | while (filter_here != filter_end) {
|
---|
| 53 | if ((*filter_here).second.f != NULL)
|
---|
| 54 | delete (*filter_here).second.f;
|
---|
| 55 | filter_here++;
|
---|
| 56 | }
|
---|
| 57 | filters.clear();
|
---|
[166] | 58 | }
|
---|
| 59 |
|
---|
| 60 | // configure should be called for each line in the
|
---|
| 61 | // configuration files to configure the collection server and everything
|
---|
| 62 | // it contains. The configuration should take place just before initialisation.
|
---|
| 63 | void collectserver::configure (const text_t &key, const text_tarray &cfgline) {
|
---|
[226] | 64 | if (cfgline.size() >= 1) {
|
---|
[166] | 65 | const text_t &value = cfgline[0];
|
---|
| 66 | if (key == "gsdlhome") configinfo.gsdlhome = value;
|
---|
[804] | 67 | else if (key == "gdbmhome") configinfo.gdbmhome = value;
|
---|
[166] | 68 | else if (key == "collection") {
|
---|
| 69 | configinfo.collection = value;
|
---|
| 70 | collectinfo.shortInfo.name = value;
|
---|
| 71 | } else if (key == "collectdir") configinfo.collectdir = value;
|
---|
| 72 | else if (key == "host") collectinfo.shortInfo.host = value;
|
---|
| 73 | else if (key == "port") collectinfo.shortInfo.port = value.getint();
|
---|
| 74 | else if (key == "public") {
|
---|
| 75 | if (value == "true") collectinfo.isPublic = true;
|
---|
| 76 | else collectinfo.isPublic = false;
|
---|
| 77 | } else if (key == "beta") {
|
---|
| 78 | if (value == "true") collectinfo.isBeta = true;
|
---|
| 79 | else collectinfo.isBeta = false;
|
---|
[830] | 80 | } else if (key == "ccscols") collectinfo.ccsCols = cfgline;
|
---|
| 81 | else if (key == "builddate") collectinfo.buildDate = value.getint();
|
---|
[166] | 82 | else if (key == "languages") collectinfo.languages = cfgline;
|
---|
| 83 | else if (key == "numdocs") collectinfo.numDocs = value.getint();
|
---|
[1253] | 84 | else if (key == "numsections") collectinfo.numSections = value.getint();
|
---|
[166] | 85 | else if (key == "numwords") collectinfo.numWords = value.getint();
|
---|
| 86 | else if (key == "numbytes") collectinfo.numBytes = value.getint();
|
---|
[722] | 87 | else if (key == "collectionmeta" && cfgline.size() == 2)
|
---|
| 88 | collectinfo.collectionmeta[cfgline[0]] = cfgline[1];
|
---|
[352] | 89 | else if (key == "format" && cfgline.size() == 2)
|
---|
| 90 | collectinfo.format[cfgline[0]] = cfgline[1];
|
---|
[722] | 91 | else if (key == "building" && cfgline.size() == 2)
|
---|
| 92 | collectinfo.building[cfgline[0]] = cfgline[1];
|
---|
[1860] | 93 | else if (key == "httpdomain") collectinfo.httpdomain = value;
|
---|
| 94 | else if (key == "httpprefix") collectinfo.httpprefix = value;
|
---|
[432] | 95 | else if (key == "receptionist") collectinfo.receptionist = value;
|
---|
[1318] | 96 | else if (key == "buildtype") collectinfo.buildType = value;
|
---|
[226] | 97 | }
|
---|
[191] | 98 |
|
---|
[226] | 99 | // configure the filters
|
---|
| 100 | filtermapclass::iterator filter_here = filters.begin();
|
---|
| 101 | filtermapclass::iterator filter_end = filters.end();
|
---|
| 102 | while (filter_here != filter_end) {
|
---|
| 103 | assert ((*filter_here).second.f != NULL);
|
---|
| 104 | if ((*filter_here).second.f != NULL)
|
---|
| 105 | (*filter_here).second.f->configure(key, cfgline);
|
---|
[191] | 106 |
|
---|
[226] | 107 | filter_here++;
|
---|
[166] | 108 | }
|
---|
[226] | 109 |
|
---|
| 110 | // configure the sources
|
---|
| 111 | sourcelistclass::iterator source_here = sources.begin();
|
---|
| 112 | sourcelistclass::iterator source_end = sources.end();
|
---|
| 113 | while (source_here != source_end) {
|
---|
| 114 | assert ((*source_here).s != NULL);
|
---|
| 115 | if ((*source_here).s != NULL)
|
---|
| 116 | (*source_here).s->configure(key, cfgline);
|
---|
| 117 |
|
---|
| 118 | source_here++;
|
---|
| 119 | }
|
---|
[166] | 120 | }
|
---|
| 121 |
|
---|
| 122 | void collectserver::configure (const text_t &key, const text_t &value) {
|
---|
| 123 | text_tarray cfgline;
|
---|
| 124 | cfgline.push_back (value);
|
---|
| 125 | configure(key, cfgline);
|
---|
| 126 | }
|
---|
| 127 |
|
---|
[2173] | 128 | void collectserver::ping (bool &wasSuccess, comerror_t &error, ostream &logout) {
|
---|
| 129 | // if we've not been properly configured, then it is a foregone
|
---|
| 130 | // conclusion that we cannot be active
|
---|
| 131 | if (this->configinfo.collection == "null")
|
---|
| 132 | {
|
---|
| 133 | wasSuccess = false;
|
---|
| 134 | }
|
---|
| 135 | // if no build date exists, then the collection was probably not built;
|
---|
| 136 | // ditto if the number of documents is zero, then something is pretty
|
---|
| 137 | // wrong
|
---|
| 138 | else if (this->collectinfo.buildDate == 0 ||
|
---|
| 139 | this->collectinfo.numDocs == 0)
|
---|
| 140 | {
|
---|
| 141 | wasSuccess = false;
|
---|
| 142 | }
|
---|
| 143 | // it is probably okay
|
---|
| 144 | else
|
---|
| 145 | wasSuccess = true;
|
---|
| 146 | }
|
---|
[166] | 147 |
|
---|
[2173] | 148 |
|
---|
[226] | 149 | bool collectserver::init (ostream &logout) {
|
---|
| 150 | // init the filters
|
---|
| 151 | filtermapclass::iterator filter_here = filters.begin();
|
---|
| 152 | filtermapclass::iterator filter_end = filters.end();
|
---|
| 153 | while (filter_here != filter_end) {
|
---|
| 154 | assert ((*filter_here).second.f != NULL);
|
---|
| 155 | if (((*filter_here).second.f != NULL) &&
|
---|
| 156 | !(*filter_here).second.f->init(logout)) return false;
|
---|
| 157 |
|
---|
| 158 | filter_here++;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | // init the sources
|
---|
| 162 | sourcelistclass::iterator source_here = sources.begin();
|
---|
| 163 | sourcelistclass::iterator source_end = sources.end();
|
---|
| 164 | while (source_here != source_end) {
|
---|
| 165 | assert ((*source_here).s != NULL);
|
---|
| 166 | if (((*source_here).s != NULL) &&
|
---|
| 167 | !(*source_here).s->init(logout)) return false;
|
---|
| 168 |
|
---|
| 169 | source_here++;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
[166] | 172 | return true;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 |
|
---|
[186] | 176 | void collectserver::get_collectinfo (ColInfoResponse_t &reponse,
|
---|
| 177 | comerror_t &err, ostream &/*logout*/) {
|
---|
| 178 | reponse = collectinfo;
|
---|
| 179 | err = noError;
|
---|
| 180 | }
|
---|
[166] | 181 |
|
---|
[226] | 182 | void collectserver::get_filterinfo (InfoFiltersResponse_t &response,
|
---|
[220] | 183 | comerror_t &err, ostream &/*logout*/) {
|
---|
[226] | 184 | response.clear ();
|
---|
| 185 |
|
---|
| 186 | // get a list of filter names
|
---|
| 187 | filtermapclass::iterator filter_here = filters.begin();
|
---|
| 188 | filtermapclass::iterator filter_end = filters.end();
|
---|
| 189 | while (filter_here != filter_end) {
|
---|
| 190 | response.filterNames.insert ((*filter_here).first);
|
---|
| 191 | filter_here++;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | err = noError;
|
---|
[220] | 195 | }
|
---|
| 196 |
|
---|
[226] | 197 | void collectserver::get_filteroptions (const InfoFilterOptionsRequest_t &request,
|
---|
[220] | 198 | InfoFilterOptionsResponse_t &response,
|
---|
[226] | 199 | comerror_t &err, ostream &logout) {
|
---|
| 200 | outconvertclass text_t2ascii;
|
---|
| 201 |
|
---|
| 202 | filterclass *thisfilter = filters.getfilter(request.filterName);
|
---|
| 203 | if (thisfilter != NULL) {
|
---|
| 204 | thisfilter->get_filteroptions (response, err, logout);
|
---|
| 205 | } else {
|
---|
| 206 | response.clear ();
|
---|
| 207 | err = protocolError;
|
---|
| 208 | logout << text_t2ascii << "Protocol Error: filter options requested for non-existent\n"
|
---|
| 209 | << "filter \"" << request.filterName << "\".\n\n";
|
---|
| 210 | }
|
---|
[186] | 211 | }
|
---|
| 212 |
|
---|
[249] | 213 | void collectserver::filter (FilterRequest_t &request,
|
---|
[186] | 214 | FilterResponse_t &response,
|
---|
[226] | 215 | comerror_t &err, ostream &logout) {
|
---|
| 216 | outconvertclass text_t2ascii;
|
---|
| 217 |
|
---|
[249] | 218 | // translate any ".fc", ".pr" etc. stuff in the docSet
|
---|
| 219 | text_t translatedOID;
|
---|
[472] | 220 | text_tarray translatedOIDs;
|
---|
| 221 | text_tarray::iterator doc_here = request.docSet.begin();
|
---|
| 222 | text_tarray::iterator doc_end = request.docSet.end();
|
---|
[249] | 223 | while (doc_here != doc_end) {
|
---|
| 224 | if (needs_translating (*doc_here)) {
|
---|
| 225 | sourcelistclass::iterator source_here = sources.begin();
|
---|
| 226 | sourcelistclass::iterator source_end = sources.end();
|
---|
| 227 | while (source_here != source_end) {
|
---|
| 228 | assert ((*source_here).s != NULL);
|
---|
| 229 | if (((*source_here).s != NULL) &&
|
---|
| 230 | ((*source_here).s->translate_OID (*doc_here, translatedOID, err, logout))) {
|
---|
| 231 | if (err != noError) return;
|
---|
| 232 | break;
|
---|
| 233 | }
|
---|
| 234 | source_here++;
|
---|
| 235 | }
|
---|
[472] | 236 | translatedOIDs.push_back (translatedOID);
|
---|
[249] | 237 | } else {
|
---|
[472] | 238 | translatedOIDs.push_back (*doc_here);
|
---|
[249] | 239 | }
|
---|
| 240 | doc_here ++;
|
---|
| 241 | }
|
---|
| 242 | request.docSet = translatedOIDs;
|
---|
| 243 |
|
---|
[196] | 244 | response.clear();
|
---|
[650] | 245 |
|
---|
[226] | 246 | filterclass *thisfilter = filters.getfilter(request.filterName);
|
---|
| 247 | if (thisfilter != NULL) {
|
---|
| 248 | // filter the data
|
---|
| 249 | thisfilter->filter (request, response, err, logout);
|
---|
[191] | 250 |
|
---|
[226] | 251 | // fill in the metadata for each of the OIDs (if it is requested)
|
---|
| 252 | if (request.filterResultOptions & FRmetadata) {
|
---|
[466] | 253 | bool processed = false;
|
---|
[226] | 254 | ResultDocInfo_tarray::iterator resultdoc_here = response.docInfo.begin();
|
---|
| 255 | ResultDocInfo_tarray::iterator resultdoc_end = response.docInfo.end();
|
---|
| 256 | while (resultdoc_here != resultdoc_end) {
|
---|
| 257 | // try each of the sources in turn
|
---|
| 258 | sourcelistclass::iterator source_here = sources.begin();
|
---|
| 259 | sourcelistclass::iterator source_end = sources.end();
|
---|
| 260 | while (source_here != source_end) {
|
---|
| 261 | assert ((*source_here).s != NULL);
|
---|
| 262 | if (((*source_here).s != NULL) &&
|
---|
| 263 | ((*source_here).s->get_metadata(request.requestParams, request.refParams,
|
---|
[271] | 264 | request.getParents, request.fields,
|
---|
| 265 | (*resultdoc_here).OID, (*resultdoc_here).metadata,
|
---|
| 266 | err, logout))) {
|
---|
[226] | 267 | if (err != noError) return;
|
---|
[466] | 268 | processed = true;
|
---|
[226] | 269 | break;
|
---|
| 270 | }
|
---|
| 271 | source_here++;
|
---|
| 272 | }
|
---|
[466] | 273 | if (!processed) {
|
---|
| 274 | err = protocolError;
|
---|
| 275 | return;
|
---|
| 276 | }
|
---|
[226] | 277 | resultdoc_here++;
|
---|
| 278 | }
|
---|
| 279 | }
|
---|
[196] | 280 |
|
---|
[191] | 281 | } else {
|
---|
[226] | 282 | response.clear ();
|
---|
[196] | 283 | err = protocolError;
|
---|
[226] | 284 | logout << text_t2ascii << "Protocol Error: filter options requested for non-existent\n"
|
---|
| 285 | << "filter \"" << request.filterName << "\".\n\n";
|
---|
[191] | 286 | }
|
---|
[226] | 287 |
|
---|
[186] | 288 | err = noError;
|
---|
| 289 | }
|
---|
| 290 |
|
---|
[259] | 291 | void collectserver::get_document (const DocumentRequest_t &request,
|
---|
| 292 | DocumentResponse_t &response,
|
---|
| 293 | comerror_t &err, ostream &logout) {
|
---|
[196] | 294 |
|
---|
[259] | 295 | sourcelistclass::iterator source_here = sources.begin();
|
---|
| 296 | sourcelistclass::iterator source_end = sources.end();
|
---|
| 297 | while (source_here != source_end) {
|
---|
| 298 | assert ((*source_here).s != NULL);
|
---|
| 299 | if (((*source_here).s != NULL) &&
|
---|
| 300 | ((*source_here).s->get_document (request.OID, response.doc, err, logout))) {
|
---|
| 301 | if (err != noError) return;
|
---|
| 302 | break;
|
---|
| 303 | }
|
---|
| 304 | source_here++;
|
---|
| 305 | }
|
---|
| 306 | }
|
---|
[186] | 307 |
|
---|
[492] | 308 |
|
---|
| 309 | bool operator==(const collectserverptr &x, const collectserverptr &y) {
|
---|
| 310 | return (x.c == y.c);
|
---|
| 311 | }
|
---|
| 312 |
|
---|
| 313 | bool operator<(const collectserverptr &x, const collectserverptr &y) {
|
---|
| 314 | return (x.c < y.c);
|
---|
| 315 | }
|
---|
| 316 |
|
---|
| 317 |
|
---|
[166] | 318 | // thecollectserver remains the property of the calling code but
|
---|
| 319 | // should not be deleted until it is removed from this list.
|
---|
| 320 | void collectservermapclass::addcollectserver (collectserver *thecollectserver) {
|
---|
| 321 | // can't add a null collection server
|
---|
| 322 | assert (thecollectserver != NULL);
|
---|
| 323 | if (thecollectserver == NULL) return;
|
---|
| 324 |
|
---|
| 325 | // can't add an collection server with no collection name
|
---|
| 326 | assert (!(thecollectserver->get_collection_name()).empty());
|
---|
| 327 | if ((thecollectserver->get_collection_name()).empty()) return;
|
---|
| 328 |
|
---|
| 329 | collectserverptr cptr;
|
---|
| 330 | cptr.c = thecollectserver;
|
---|
| 331 | collectserverptrs[thecollectserver->get_collection_name()] = cptr;
|
---|
| 332 | }
|
---|
| 333 |
|
---|
| 334 | // getcollectserver will return NULL if the collectserver could not be found
|
---|
| 335 | collectserver *collectservermapclass::getcollectserver (const text_t &collection) {
|
---|
| 336 | // can't find a collection with no name
|
---|
| 337 | if (collection.empty()) return NULL;
|
---|
| 338 |
|
---|
| 339 | iterator here = collectserverptrs.find (collection);
|
---|
| 340 | if (here == collectserverptrs.end()) return NULL;
|
---|
| 341 |
|
---|
| 342 | return (*here).second.c;
|
---|
| 343 | }
|
---|