[108] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * receptionist.cpp -- a web interface for the gsdl
|
---|
| 4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
[533] | 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.
|
---|
[108] | 9 | *
|
---|
[533] | 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 | *
|
---|
[108] | 24 | *********************************************************************/
|
---|
| 25 |
|
---|
[2379] | 26 | // following line required to get fstream.filedesc() on darwin (Mac OS X)
|
---|
[2386] | 27 | // gcc 2.91 automatically defines this in stream.h
|
---|
[2379] | 28 | #define _STREAM_COMPAT 1
|
---|
| 29 |
|
---|
[108] | 30 | #include "receptionist.h"
|
---|
[15418] | 31 | #include "recptprototools.h"
|
---|
[108] | 32 | #include "fileutil.h"
|
---|
[155] | 33 | #include "cgiutils.h"
|
---|
[263] | 34 | #include "htmlutils.h"
|
---|
[1148] | 35 | #include "gsdltools.h"
|
---|
[1779] | 36 | #include "gsdltimes.h"
|
---|
[248] | 37 | #include "OIDtools.h"
|
---|
[108] | 38 | #include <assert.h>
|
---|
[150] | 39 | #include <time.h>
|
---|
[3007] | 40 | #include <stdio.h> // for open()
|
---|
| 41 | #include <fcntl.h> // for open() flags
|
---|
[2608] | 42 | // following 2 are for printing Last-Modified http header.
|
---|
[2386] | 43 | #include <sys/stat.h>
|
---|
| 44 | #include <time.h>
|
---|
| 45 |
|
---|
[1170] | 46 | #if defined (GSDL_USE_IOS_H)
|
---|
[463] | 47 | #include <fstream.h>
|
---|
[1170] | 48 | #else
|
---|
| 49 | #include <fstream>
|
---|
| 50 | #endif
|
---|
[108] | 51 |
|
---|
[526] | 52 | void recptconf::clear () {
|
---|
| 53 | gsdlhome.clear();
|
---|
[16310] | 54 | collecthome.clear();
|
---|
[15589] | 55 | dbhome.clear();
|
---|
[806] | 56 | collectinfo.erase(collectinfo.begin(), collectinfo.end());
|
---|
[526] | 57 | collection.clear();
|
---|
| 58 | collectdir.clear();
|
---|
| 59 | httpprefix.clear();
|
---|
[19109] | 60 | httpweb.clear();
|
---|
[526] | 61 | gwcgi.clear();
|
---|
| 62 | macrofiles.erase(macrofiles.begin(), macrofiles.end());
|
---|
| 63 | saveconf.clear();
|
---|
| 64 | usecookies = false;
|
---|
| 65 | logcgiargs = false;
|
---|
[1779] | 66 | LogDateFormat = LocalTime;
|
---|
[530] | 67 |
|
---|
[1762] | 68 | maintainer.clear();
|
---|
| 69 | MailServer.clear();
|
---|
| 70 | LogEvents = Disabled;
|
---|
| 71 | EmailEvents = Disabled;
|
---|
| 72 | EmailUserEvents = false;
|
---|
| 73 |
|
---|
[1856] | 74 | languages.erase(languages.begin(), languages.end());
|
---|
| 75 | encodings.erase(encodings.begin(), encodings.end());
|
---|
| 76 |
|
---|
[5018] | 77 | site_auth = false;
|
---|
[4905] | 78 | HomePageType = "images";
|
---|
| 79 | HomePageCols = 3;
|
---|
| 80 |
|
---|
[530] | 81 | // these default page parameters can always be overriden
|
---|
| 82 | // in the configuration file
|
---|
| 83 | pageparams.erase(pageparams.begin(), pageparams.end());
|
---|
| 84 | pageparams["c"] = "";
|
---|
| 85 | pageparams["l"] = "en";
|
---|
| 86 |
|
---|
| 87 | #ifdef MACROPRECEDENCE
|
---|
| 88 | macroprecedence = MACROPRECEDENCE;
|
---|
| 89 | #else
|
---|
| 90 | macroprecedence.clear();
|
---|
| 91 | #endif
|
---|
[526] | 92 | }
|
---|
| 93 |
|
---|
[19109] | 94 |
|
---|
[1270] | 95 | void collectioninfo_t::clear () {
|
---|
| 96 | gsdl_gsdlhome.clear();
|
---|
[15589] | 97 | gsdl_dbhome.clear();
|
---|
[526] | 98 |
|
---|
[1270] | 99 | info_loaded = false;
|
---|
| 100 | info.clear();
|
---|
| 101 | }
|
---|
[526] | 102 |
|
---|
[1856] | 103 | void languageinfo_t::clear () {
|
---|
| 104 | longname.clear();
|
---|
| 105 | defaultencoding.clear();
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[388] | 108 | receptionist::receptionist () {
|
---|
| 109 | // create a list of cgi arguments
|
---|
| 110 | // this must be done before the configuration
|
---|
| 111 |
|
---|
| 112 | cgiarginfo ainfo;
|
---|
| 113 |
|
---|
| 114 | ainfo.shortname = "e";
|
---|
| 115 | ainfo.longname = "compressed arguments";
|
---|
| 116 | ainfo.multiplechar = true;
|
---|
| 117 | ainfo.defaultstatus = cgiarginfo::good;
|
---|
[7421] | 118 | ainfo.argdefault = g_EmptyText;
|
---|
[388] | 119 | ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 120 | argsinfo.addarginfo (NULL, ainfo);
|
---|
| 121 |
|
---|
| 122 | ainfo.shortname = "a";
|
---|
| 123 | ainfo.longname = "action";
|
---|
| 124 | ainfo.multiplechar = true;
|
---|
| 125 | ainfo.defaultstatus = cgiarginfo::none;
|
---|
[7421] | 126 | ainfo.argdefault = g_EmptyText;
|
---|
[388] | 127 | ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 128 | argsinfo.addarginfo (NULL, ainfo);
|
---|
| 129 |
|
---|
| 130 | // w=western
|
---|
| 131 | ainfo.shortname = "w";
|
---|
| 132 | ainfo.longname = "encoding";
|
---|
| 133 | ainfo.multiplechar = true;
|
---|
[1856] | 134 | ainfo.defaultstatus = cgiarginfo::none;
|
---|
[7421] | 135 | ainfo.argdefault = g_EmptyText;
|
---|
[388] | 136 | ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 137 | argsinfo.addarginfo (NULL, ainfo);
|
---|
| 138 |
|
---|
| 139 | ainfo.shortname = "nw";
|
---|
| 140 | ainfo.longname = "new encoding";
|
---|
| 141 | ainfo.multiplechar = true;
|
---|
| 142 | ainfo.defaultstatus = cgiarginfo::none;
|
---|
[7421] | 143 | ainfo.argdefault = g_EmptyText;
|
---|
[388] | 144 | ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 145 | argsinfo.addarginfo (NULL, ainfo);
|
---|
| 146 |
|
---|
| 147 | ainfo.shortname = "c";
|
---|
| 148 | ainfo.longname = "collection";
|
---|
| 149 | ainfo.multiplechar = true;
|
---|
| 150 | ainfo.defaultstatus = cgiarginfo::none;
|
---|
[7421] | 151 | ainfo.argdefault = g_EmptyText;
|
---|
[388] | 152 | ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 153 | argsinfo.addarginfo (NULL, ainfo);
|
---|
| 154 |
|
---|
| 155 | // the interface language name should use the ISO 639
|
---|
| 156 | // standard
|
---|
| 157 | ainfo.shortname = "l";
|
---|
| 158 | ainfo.longname = "interface language";
|
---|
| 159 | ainfo.multiplechar = true;
|
---|
| 160 | ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 161 | ainfo.argdefault = "en";
|
---|
| 162 | ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 163 | argsinfo.addarginfo (NULL, ainfo);
|
---|
[1856] | 164 |
|
---|
| 165 | ainfo.shortname = "nl";
|
---|
| 166 | ainfo.longname = "new language";
|
---|
| 167 | ainfo.multiplechar = false;
|
---|
| 168 | ainfo.defaultstatus = cgiarginfo::none;
|
---|
| 169 | ainfo.argdefault = "0";
|
---|
| 170 | ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 171 | argsinfo.addarginfo (NULL, ainfo);
|
---|
| 172 |
|
---|
[463] | 173 | // the GSDL_UID (cookie)
|
---|
| 174 | ainfo.shortname = "z";
|
---|
| 175 | ainfo.longname = "gsdl uid";
|
---|
| 176 | ainfo.multiplechar = true;
|
---|
| 177 | ainfo.defaultstatus = cgiarginfo::none;
|
---|
[7421] | 178 | ainfo.argdefault = g_EmptyText;
|
---|
[463] | 179 | ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 180 | argsinfo.addarginfo (NULL, ainfo);
|
---|
[530] | 181 | }
|
---|
[463] | 182 |
|
---|
[530] | 183 |
|
---|
| 184 | void receptionist::add_action (action *theaction) {
|
---|
| 185 | // make sure we have an action to add
|
---|
| 186 | if (theaction == NULL) return;
|
---|
| 187 |
|
---|
| 188 | // add this action to the list of actions
|
---|
| 189 | actions.addaction(theaction);
|
---|
| 190 |
|
---|
| 191 | // add the cgi arguments from this action
|
---|
[12509] | 192 | argsinfo.addarginfo (NULL, *(theaction->getargsinfo()));
|
---|
[388] | 193 | }
|
---|
| 194 |
|
---|
| 195 |
|
---|
[649] | 196 | void receptionist::add_browser (browserclass *thebrowser) {
|
---|
| 197 | // make sure we have a browser to add
|
---|
| 198 | if (thebrowser == NULL) return;
|
---|
| 199 |
|
---|
| 200 | // add this browser to the list of browsers
|
---|
| 201 | browsers.addbrowser(thebrowser);
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 |
|
---|
| 205 | void receptionist::setdefaultbrowser (const text_t &browsername) {
|
---|
| 206 | browsers.setdefaultbrowser (browsername);
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 |
|
---|
[165] | 210 | // configure should be called for each line in the
|
---|
| 211 | // configuration files to configure the receptionist and everything
|
---|
| 212 | // it contains. The configuration should take place after everything
|
---|
| 213 | // has been added but before the initialisation.
|
---|
[5017] | 214 |
|
---|
[165] | 215 | void receptionist::configure (const text_t &key, const text_tarray &cfgline) {
|
---|
| 216 | // configure the receptionist
|
---|
[1870] | 217 |
|
---|
[5017] | 218 |
|
---|
| 219 |
|
---|
[165] | 220 | if (cfgline.size() >= 1) {
|
---|
[388] | 221 | cgiarginfo *info = NULL;
|
---|
[2561] | 222 | if (key == "gsdlhome") {
|
---|
| 223 | configinfo.gsdlhome = cfgline[0];
|
---|
[15589] | 224 | if (configinfo.dbhome.empty()) configinfo.dbhome = cfgline[0];
|
---|
[2561] | 225 | }
|
---|
[16310] | 226 | else if (key == "collecthome") configinfo.collecthome = cfgline[0];
|
---|
[15589] | 227 | else if (key == "gdbmhome") configinfo.dbhome = cfgline[0];
|
---|
[388] | 228 | else if (key == "collection") {
|
---|
| 229 | configinfo.collection = cfgline[0];
|
---|
| 230 | // also need to set the default arg to this collection
|
---|
| 231 | if ((info = argsinfo.getarginfo("c")) != NULL) {
|
---|
| 232 | info->defaultstatus = cgiarginfo::good;
|
---|
| 233 | info->argdefault = cfgline[0];
|
---|
| 234 | }
|
---|
| 235 |
|
---|
[16310] | 236 | }
|
---|
| 237 | else if (key == "collectdir") configinfo.collectdir = cfgline[0];
|
---|
[297] | 238 | else if (key == "httpprefix") configinfo.httpprefix = cfgline[0];
|
---|
[19109] | 239 | else if (key == "httpweb") configinfo.httpweb = cfgline[0];
|
---|
[165] | 240 | else if (key == "gwcgi") configinfo.gwcgi = cfgline[0];
|
---|
[799] | 241 | else if (key == "macrofiles") {
|
---|
| 242 | // want to append to macrofiles (i.e. may be several config files
|
---|
| 243 | // contributing, maybe from several collections).
|
---|
| 244 | text_tarray::const_iterator here = cfgline.begin();
|
---|
| 245 | text_tarray::const_iterator end = cfgline.end();
|
---|
| 246 | while (here != end) {
|
---|
| 247 | configinfo.macrofiles.insert (*here);
|
---|
[7443] | 248 | ++here;
|
---|
[799] | 249 | }
|
---|
| 250 | }
|
---|
[165] | 251 | else if (key == "saveconf") configinfo.saveconf = cfgline[0];
|
---|
[526] | 252 | else if (key == "usecookies") configinfo.usecookies = (cfgline[0] == "true");
|
---|
| 253 | else if (key == "logcgiargs") configinfo.logcgiargs = (cfgline[0] == "true");
|
---|
[1762] | 254 | else if (key == "maintainer") configinfo.maintainer = cfgline[0];
|
---|
| 255 | else if (key == "MailServer") configinfo.MailServer = cfgline[0];
|
---|
[1779] | 256 | else if (key == "LogDateFormat") {
|
---|
| 257 | if (cfgline[0] == "UTCTime") configinfo.LogDateFormat = UTCTime;
|
---|
| 258 | else if (cfgline[0] == "Absolute") configinfo.LogDateFormat = Absolute;
|
---|
| 259 | }
|
---|
[1762] | 260 | else if (key == "LogEvents") {
|
---|
| 261 | if (cfgline[0] == "CollectorEvents") configinfo.LogEvents = CollectorEvents;
|
---|
| 262 | else if (cfgline[0] == "AllEvents") configinfo.LogEvents = AllEvents;
|
---|
| 263 | }
|
---|
| 264 | else if (key == "EmailEvents") {
|
---|
| 265 | if (cfgline[0] == "CollectorEvents") configinfo.EmailEvents = CollectorEvents;
|
---|
| 266 | else if (cfgline[0] == "AllEvents") configinfo.EmailEvents = AllEvents;
|
---|
| 267 | }
|
---|
| 268 | else if (key == "EmailUserEvents") configinfo.EmailUserEvents = (cfgline[0] == "true");
|
---|
[530] | 269 | else if (key == "pageparam") {
|
---|
| 270 | if (cfgline.size() >= 2) configinfo.pageparams[cfgline[0]] = cfgline[1];
|
---|
| 271 | else configinfo.pageparams[cfgline[0]] = "";
|
---|
| 272 | }
|
---|
| 273 | else if (key == "macroprecedence") configinfo.macroprecedence = cfgline[0];
|
---|
[799] | 274 | else if (key == "collectinfo") {
|
---|
[16310] | 275 | if (cfgline.size() == 3) {
|
---|
| 276 | // for backwards compatability with older collections that only use
|
---|
| 277 | // gsdlhome and dbhome
|
---|
[799] | 278 | collectioninfo_t cinfo;
|
---|
| 279 | cinfo.gsdl_gsdlhome = cfgline[1];
|
---|
[16310] | 280 | cinfo.gsdl_collecthome = filename_cat(cfgline[1],"collect");
|
---|
[15589] | 281 | cinfo.gsdl_dbhome = cfgline[2];
|
---|
[799] | 282 | configinfo.collectinfo[cfgline[0]] = cinfo;
|
---|
| 283 | }
|
---|
[16310] | 284 | else if (cfgline.size() >= 4) {
|
---|
| 285 | collectioninfo_t cinfo;
|
---|
| 286 | cinfo.gsdl_gsdlhome = cfgline[1];
|
---|
| 287 | cinfo.gsdl_collecthome = cfgline[2];
|
---|
| 288 | cinfo.gsdl_dbhome = cfgline[3];
|
---|
| 289 | configinfo.collectinfo[cfgline[0]] = cinfo;
|
---|
| 290 | }
|
---|
[799] | 291 | }
|
---|
[4905] | 292 |
|
---|
[5017] | 293 | // Read in the value for the site_auth directive either true or false
|
---|
| 294 | else if (key == "site_auth") configinfo.site_auth = (cfgline[0] == "true");
|
---|
| 295 |
|
---|
| 296 | else if (key == "site_group")
|
---|
| 297 | joinchar(cfgline,',',configinfo.site_group);
|
---|
| 298 |
|
---|
[4905] | 299 | else if (key == "SiteFormat") {
|
---|
| 300 | if (cfgline[0] == "HomePageType") {
|
---|
| 301 | configinfo.HomePageType = cfgline[1];
|
---|
| 302 | } else if (cfgline[0] == "HomePageCols") {
|
---|
| 303 | configinfo.HomePageCols = cfgline[1].getint();
|
---|
| 304 | }
|
---|
| 305 | }
|
---|
| 306 |
|
---|
[530] | 307 | else if (key == "cgiarg") {
|
---|
| 308 | // get shortname
|
---|
| 309 | bool seen_defaultstatus = false;
|
---|
| 310 | text_t subkey, subvalue;
|
---|
| 311 | text_t shortname;
|
---|
| 312 | text_t::const_iterator cfglinesub_here;
|
---|
| 313 | text_tarray::const_iterator cfgline_here = cfgline.begin();
|
---|
| 314 | text_tarray::const_iterator cfgline_end = cfgline.end();
|
---|
| 315 | while (cfgline_here != cfgline_end) {
|
---|
| 316 | cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
|
---|
| 317 | (*cfgline_here).end(), '=', subkey);
|
---|
| 318 | if (subkey == "shortname") {
|
---|
| 319 | shortname = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
| 320 | }
|
---|
[7443] | 321 | ++cfgline_here;
|
---|
[388] | 322 | }
|
---|
[530] | 323 |
|
---|
| 324 | // if we found the shortname process the line again filling in values
|
---|
| 325 | if (!shortname.empty()) {
|
---|
| 326 | cgiarginfo &chinfo = argsinfo[shortname];
|
---|
| 327 | chinfo.shortname = shortname; // in case this is a new argument
|
---|
| 328 |
|
---|
| 329 | cfgline_here = cfgline.begin();
|
---|
| 330 | while (cfgline_here != cfgline_end) {
|
---|
| 331 | cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
|
---|
| 332 | (*cfgline_here).end(), '=', subkey);
|
---|
| 333 | subvalue = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
| 334 |
|
---|
| 335 | if (subkey == "longname") chinfo.longname = subvalue;
|
---|
| 336 | else if (subkey == "multiplechar") chinfo.multiplechar = (subvalue == "true");
|
---|
[22196] | 337 | else if (subkey == "multiplevalue") chinfo.multiplevalue = (subvalue == "true");
|
---|
[530] | 338 | else if (subkey == "defaultstatus") {
|
---|
| 339 | seen_defaultstatus = true;
|
---|
| 340 | if (subvalue == "none") chinfo.defaultstatus = cgiarginfo::none;
|
---|
| 341 | else if (subvalue == "weak") chinfo.defaultstatus = cgiarginfo::weak;
|
---|
| 342 | else if (subvalue == "good") chinfo.defaultstatus = cgiarginfo::good;
|
---|
| 343 | else if (subvalue == "config") chinfo.defaultstatus = cgiarginfo::config;
|
---|
| 344 | else if (subvalue == "imperative") chinfo.defaultstatus = cgiarginfo::imperative;
|
---|
| 345 | }
|
---|
| 346 | else if (subkey == "argdefault") {
|
---|
| 347 | chinfo.argdefault = subvalue;
|
---|
| 348 | if (!seen_defaultstatus) chinfo.defaultstatus = cgiarginfo::config;
|
---|
| 349 | }
|
---|
| 350 | else if (subkey == "savedarginfo") {
|
---|
| 351 | if (subvalue == "mustnot") chinfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 352 | else if (subvalue == "can") chinfo.savedarginfo = cgiarginfo::can;
|
---|
| 353 | else if (subvalue == "must") chinfo.savedarginfo = cgiarginfo::must;
|
---|
| 354 | }
|
---|
| 355 |
|
---|
[7443] | 356 | ++cfgline_here;
|
---|
[530] | 357 | }
|
---|
| 358 | }
|
---|
[1856] | 359 |
|
---|
| 360 | } else if (key == "Encoding") {
|
---|
| 361 |
|
---|
[1870] | 362 | configure_encoding (cfgline);
|
---|
| 363 |
|
---|
[1856] | 364 | } else if (key == "Language") {
|
---|
[1870] | 365 | text_t subkey, subvalue, shortname;
|
---|
| 366 | languageinfo_t lang;
|
---|
[1856] | 367 | text_t::const_iterator cfglinesub_here;
|
---|
| 368 | text_tarray::const_iterator cfgline_here = cfgline.begin();
|
---|
| 369 | text_tarray::const_iterator cfgline_end = cfgline.end();
|
---|
| 370 | while (cfgline_here != cfgline_end) {
|
---|
| 371 | cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
|
---|
| 372 | (*cfgline_here).end(), '=', subkey);
|
---|
| 373 | if (subkey == "shortname") {
|
---|
| 374 | shortname = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
| 375 | } else if (subkey == "longname") {
|
---|
[1870] | 376 | lang.longname = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
[1856] | 377 | } else if (subkey == "default_encoding") {
|
---|
[1870] | 378 | lang.defaultencoding = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
[1856] | 379 | }
|
---|
[7443] | 380 | ++cfgline_here;
|
---|
[1856] | 381 | }
|
---|
| 382 | if (!shortname.empty()) {
|
---|
[1870] | 383 | if (lang.longname.empty()) lang.longname = shortname;
|
---|
[1856] | 384 | configinfo.languages[shortname] = lang;
|
---|
| 385 | }
|
---|
[388] | 386 | }
|
---|
[165] | 387 | }
|
---|
[530] | 388 |
|
---|
[165] | 389 | // configure the actions
|
---|
| 390 | actionptrmap::iterator actionhere = actions.begin ();
|
---|
| 391 | actionptrmap::iterator actionend = actions.end ();
|
---|
[108] | 392 |
|
---|
[165] | 393 | while (actionhere != actionend) {
|
---|
| 394 | assert ((*actionhere).second.a != NULL);
|
---|
| 395 | if ((*actionhere).second.a != NULL)
|
---|
| 396 | (*actionhere).second.a->configure(key, cfgline);
|
---|
[108] | 397 |
|
---|
[7421] | 398 | ++actionhere;
|
---|
[165] | 399 | }
|
---|
[108] | 400 |
|
---|
[165] | 401 | // configure the protocols
|
---|
| 402 | recptprotolistclass::iterator protohere = protocols.begin ();
|
---|
| 403 | recptprotolistclass::iterator protoend = protocols.end ();
|
---|
[108] | 404 |
|
---|
[165] | 405 | while (protohere != protoend) {
|
---|
| 406 | assert ((*protohere).p != NULL);
|
---|
[2113] | 407 | comerror_t err;
|
---|
[165] | 408 | if ((*protohere).p != NULL)
|
---|
[2113] | 409 | (*protohere).p->configure(key, cfgline, err);
|
---|
[165] | 410 |
|
---|
[7443] | 411 | ++protohere;
|
---|
[155] | 412 | }
|
---|
[649] | 413 |
|
---|
| 414 | // configure the browsers
|
---|
| 415 | browserptrmap::iterator browserhere = browsers.begin ();
|
---|
| 416 | browserptrmap::iterator browserend = browsers.end ();
|
---|
| 417 |
|
---|
| 418 | while (browserhere != browserend) {
|
---|
| 419 | assert ((*browserhere).second.b != NULL);
|
---|
| 420 | if ((*browserhere).second.b != NULL)
|
---|
| 421 | (*browserhere).second.b->configure(key, cfgline);
|
---|
| 422 |
|
---|
[7443] | 423 | ++browserhere;
|
---|
[649] | 424 | }
|
---|
[108] | 425 | }
|
---|
| 426 |
|
---|
[649] | 427 |
|
---|
[165] | 428 | void receptionist::configure (const text_t &key, const text_t &value) {
|
---|
| 429 | text_tarray cfgline;
|
---|
| 430 | cfgline.push_back (value);
|
---|
| 431 | configure(key, cfgline);
|
---|
| 432 | }
|
---|
| 433 |
|
---|
| 434 |
|
---|
[1870] | 435 | // init should be called after all the actions and protocols have been
|
---|
| 436 | // added to the receptionist and after everything has been configured but
|
---|
| 437 | // before any pages are created. It returns true on success and false on
|
---|
| 438 | // failure. If false is returned getpage should not be called (without
|
---|
| 439 | // producing meaningless output), instead an error page should be produced
|
---|
| 440 | // by the calling code.
|
---|
[150] | 441 | bool receptionist::init (ostream &logout) {
|
---|
[1870] | 442 |
|
---|
[165] | 443 | // first configure collectdir
|
---|
| 444 | if (!configinfo.collection.empty()) {
|
---|
[16310] | 445 |
|
---|
[165] | 446 | // collection specific mode
|
---|
[16310] | 447 |
|
---|
| 448 | text_t collectdir = configinfo.gsdlhome;
|
---|
| 449 |
|
---|
[165] | 450 | if (!configinfo.collectdir.empty()) {
|
---|
| 451 | // has already been configured
|
---|
[16310] | 452 | collectdir = configinfo.collectdir;
|
---|
[165] | 453 | } else {
|
---|
[16310] | 454 |
|
---|
[165] | 455 | // decide where collectdir is by searching for collect.cfg
|
---|
| 456 | // look in $GSDLHOME/collect/collection-name/etc/collect.cfg and
|
---|
| 457 | // then $GSDLHOME/etc/collect.cfg
|
---|
[16310] | 458 | collectdir = filename_cat (configinfo.gsdlhome, "collect");
|
---|
| 459 | collectdir = filename_cat (collectdir, configinfo.collection);
|
---|
| 460 | text_t filename = filename_cat (collectdir, "etc");
|
---|
[165] | 461 | filename = filename_cat (filename, "collect.cfg");
|
---|
[16310] | 462 |
|
---|
| 463 | if (!file_exists(filename)) collectdir = configinfo.gsdlhome;
|
---|
| 464 | }
|
---|
[418] | 465 |
|
---|
[16310] | 466 | configure("collectdir", collectdir);
|
---|
| 467 |
|
---|
[165] | 468 | }
|
---|
[16310] | 469 | else {
|
---|
[165] | 470 |
|
---|
[16310] | 471 | text_t collecthome;
|
---|
| 472 | if (configinfo.collecthome.empty()) {
|
---|
| 473 | collecthome = filename_cat(configinfo.gsdlhome,"collect");
|
---|
| 474 | }
|
---|
| 475 | else {
|
---|
| 476 | collecthome = configinfo.collecthome;
|
---|
| 477 | }
|
---|
| 478 |
|
---|
| 479 | configure("collecthome", collecthome);
|
---|
| 480 |
|
---|
| 481 | // for backwards compatability collectdir set to gsdlhome
|
---|
| 482 | // (possible it could now be removed)
|
---|
| 483 | configure("collectdir", configinfo.gsdlhome);
|
---|
| 484 | }
|
---|
| 485 |
|
---|
| 486 |
|
---|
[155] | 487 | // read in the macro files
|
---|
| 488 | if (!read_macrofiles (logout)) return false;
|
---|
[108] | 489 |
|
---|
[165] | 490 | // there must be at least one action defined
|
---|
| 491 | if (actions.empty()) {
|
---|
| 492 | logout << "Error: no actions have been added to the receptionist\n";
|
---|
| 493 | return false;
|
---|
| 494 | }
|
---|
| 495 |
|
---|
[649] | 496 | // there must be at least one browser defined
|
---|
| 497 | if (browsers.empty()) {
|
---|
| 498 | logout << "Error: no browsers have been added to the receptionist\n";
|
---|
| 499 | return false;
|
---|
| 500 | }
|
---|
| 501 |
|
---|
[155] | 502 | // create a saveconf string if there isn't one already
|
---|
[165] | 503 | if (configinfo.saveconf.empty())
|
---|
| 504 | configinfo.saveconf = create_save_conf_str (argsinfo, logout);
|
---|
[108] | 505 |
|
---|
[155] | 506 | // check the saveconf string
|
---|
[165] | 507 | if (!check_save_conf_str (configinfo.saveconf, argsinfo, logout))
|
---|
[155] | 508 | return false;
|
---|
| 509 |
|
---|
| 510 | // set a random seed
|
---|
| 511 | srand (time(NULL));
|
---|
| 512 |
|
---|
[1762] | 513 | // if maintainer email address is something dodgy (for now I'll define
|
---|
| 514 | // dodgy as being anything that doesn't contain '@') disable EmailEvents
|
---|
[1778] | 515 | // and EmailUserEvents (we don't strictly need to disable EmailUserEvents
|
---|
| 516 | // in this case but we will as it seems likely that MailServer will also
|
---|
| 517 | // be screwed up if maintainer is).
|
---|
[1762] | 518 | text_t::const_iterator maintainer_end = configinfo.maintainer.end ();
|
---|
[2937] | 519 | text_t::const_iterator maintainer_here = findchar ((text_t::const_iterator)configinfo.maintainer.begin(),
|
---|
[1762] | 520 | maintainer_end, '@');
|
---|
| 521 | if (maintainer_here == maintainer_end) {
|
---|
| 522 | configinfo.EmailEvents = Disabled;
|
---|
| 523 | configinfo.EmailUserEvents = Disabled;
|
---|
| 524 | } else {
|
---|
| 525 | // if MailServer isn't set it should default to mail.maintainer-domain
|
---|
| 526 | if (configinfo.MailServer.empty()) {
|
---|
[1778] | 527 | configinfo.MailServer = "mail." + substr (maintainer_here+1, maintainer_end);
|
---|
[1762] | 528 | }
|
---|
| 529 | }
|
---|
| 530 |
|
---|
[165] | 531 | // init the actions
|
---|
| 532 | actionptrmap::iterator actionhere = actions.begin ();
|
---|
| 533 | actionptrmap::iterator actionend = actions.end ();
|
---|
| 534 | while (actionhere != actionend) {
|
---|
| 535 | if (((*actionhere).second.a == NULL) ||
|
---|
| 536 | !(*actionhere).second.a->init(logout)) return false;
|
---|
[7421] | 537 | ++actionhere;
|
---|
[165] | 538 | }
|
---|
| 539 |
|
---|
| 540 | // init the protocols
|
---|
| 541 | recptprotolistclass::iterator protohere = protocols.begin ();
|
---|
| 542 | recptprotolistclass::iterator protoend = protocols.end ();
|
---|
| 543 | while (protohere != protoend) {
|
---|
[2113] | 544 | comerror_t err;
|
---|
[165] | 545 | if (((*protohere).p == NULL) ||
|
---|
[2113] | 546 | !(*protohere).p->init(err, logout)) return false;
|
---|
[7443] | 547 | ++protohere;
|
---|
[165] | 548 | }
|
---|
| 549 |
|
---|
[649] | 550 | // init the browsers
|
---|
| 551 | browserptrmap::iterator browserhere = browsers.begin ();
|
---|
| 552 | browserptrmap::iterator browserend = browsers.end ();
|
---|
| 553 | while (browserhere != browserend) {
|
---|
| 554 | if (((*browserhere).second.b == NULL) ||
|
---|
| 555 | !(*browserhere).second.b->init(logout)) return false;
|
---|
[7443] | 556 | ++browserhere;
|
---|
[649] | 557 | }
|
---|
| 558 |
|
---|
[146] | 559 | return true;
|
---|
[108] | 560 | }
|
---|
| 561 |
|
---|
[1856] | 562 | // get the default encoding for the given language - if it fails for any
|
---|
| 563 | // reason return ""
|
---|
| 564 | text_t receptionist::get_default_encoding (const text_t &language) {
|
---|
| 565 |
|
---|
| 566 | // make sure language is valid
|
---|
| 567 | if (configinfo.languages.find(language) == configinfo.languages.end()) return "";
|
---|
[108] | 568 |
|
---|
[1856] | 569 | text_t default_encoding = configinfo.languages[language].defaultencoding;
|
---|
| 570 |
|
---|
| 571 | // make sure the encoding is valid
|
---|
[10563] | 572 | if (converters.find(default_encoding) == converters.end()) {
|
---|
| 573 | // we don't support the encoding specified as default for this language
|
---|
| 574 | if (configinfo.encodings.size()==1) {
|
---|
| 575 | // only 1 encoding specified in main.cfg, so use it
|
---|
| 576 | return configinfo.encodings.begin()->second;
|
---|
| 577 | }
|
---|
| 578 | return "";
|
---|
| 579 | }
|
---|
[1856] | 580 |
|
---|
| 581 | return default_encoding;
|
---|
| 582 | }
|
---|
| 583 |
|
---|
[155] | 584 | // parse_cgi_args parses cgi arguments into an argument class.
|
---|
| 585 | // This function should be called for each page request. It returns false
|
---|
| 586 | // if there was a major problem with the cgi arguments.
|
---|
[12509] | 587 | bool receptionist::parse_cgi_args (const text_t &argstr,
|
---|
| 588 | fileupload_tmap &fileuploads,
|
---|
| 589 | cgiargsclass &args,
|
---|
[864] | 590 | ostream &logout, text_tmap &fcgienv) {
|
---|
[155] | 591 |
|
---|
| 592 | // get an initial list of cgi arguments
|
---|
| 593 | args.clear();
|
---|
[776] | 594 | split_cgi_args (argsinfo, argstr, args);
|
---|
[155] | 595 |
|
---|
| 596 | // expand the compressed argument (if there was one)
|
---|
[165] | 597 | if (!expand_save_args (argsinfo, configinfo.saveconf, args, logout)) return false;
|
---|
[155] | 598 |
|
---|
| 599 | // add the defaults
|
---|
| 600 | add_default_args (argsinfo, args, logout);
|
---|
| 601 |
|
---|
[12509] | 602 | // add any file upload arguments
|
---|
| 603 | add_fileupload_args(argsinfo, args, fileuploads, logout);
|
---|
| 604 |
|
---|
[463] | 605 | // get the cookie
|
---|
[864] | 606 | if (configinfo.usecookies) get_cookie(args["z"], fcgienv);
|
---|
[362] | 607 |
|
---|
[1856] | 608 | // if we're changing languages, set the encoding to the default for the new language
|
---|
| 609 | if (args["nl"] == "1") {
|
---|
| 610 | args["nw"] = get_default_encoding(args["l"]);
|
---|
| 611 | }
|
---|
| 612 |
|
---|
[362] | 613 | // get the input encoding
|
---|
[1856] | 614 | // if encoding isn't set, set it to the default for the current language
|
---|
| 615 | if ((args.getarg("w") == NULL) || args["w"].empty()) {
|
---|
| 616 | args["w"] = get_default_encoding(args["l"]);
|
---|
| 617 | }
|
---|
| 618 |
|
---|
[362] | 619 | text_t &arg_w = args["w"];
|
---|
[1856] | 620 |
|
---|
[362] | 621 | inconvertclass defaultinconvert;
|
---|
| 622 | inconvertclass *inconvert = converters.get_inconverter (arg_w);
|
---|
| 623 | if (inconvert == NULL) inconvert = &defaultinconvert;
|
---|
| 624 |
|
---|
| 625 | // see if the next page will have a different encoding
|
---|
| 626 | if (args.getarg("nw") != NULL) arg_w = args["nw"];
|
---|
| 627 |
|
---|
| 628 | // convert arguments which aren't in unicode to unicode
|
---|
| 629 | args_tounicode (args, *inconvert);
|
---|
| 630 |
|
---|
| 631 |
|
---|
| 632 | // decide on the output conversion class (needed for checking the external
|
---|
| 633 | // cgi arguments)
|
---|
| 634 | rzwsoutconvertclass defaultoutconverter;
|
---|
| 635 | rzwsoutconvertclass *outconverter = converters.get_outconverter (arg_w);
|
---|
| 636 | if (outconverter == NULL) outconverter = &defaultoutconverter;
|
---|
| 637 | outconverter->reset();
|
---|
| 638 |
|
---|
[155] | 639 | // check the main cgi arguments
|
---|
| 640 | if (!check_mainargs (args, logout)) return false;
|
---|
| 641 |
|
---|
| 642 | // check the arguments for the action
|
---|
| 643 | action *a = actions.getaction (args["a"]);
|
---|
| 644 | if (a != NULL) {
|
---|
[3546] | 645 | if (!a->check_cgiargs (argsinfo, args, &protocols, logout)) return false;
|
---|
[155] | 646 | } else {
|
---|
| 647 | // the action was not found!!
|
---|
[1856] | 648 | outconvertclass text_t2ascii;
|
---|
[155] | 649 | logout << text_t2ascii << "Error: the action \"" << args["a"]
|
---|
| 650 | << "\" could not be found.\n";
|
---|
| 651 | return false;
|
---|
| 652 | }
|
---|
| 653 |
|
---|
[362] | 654 | // check external cgi arguments for each action
|
---|
| 655 | actionptrmap::iterator actionhere = actions.begin ();
|
---|
| 656 | actionptrmap::iterator actionend = actions.end ();
|
---|
| 657 | while (actionhere != actionend) {
|
---|
| 658 | assert ((*actionhere).second.a != NULL);
|
---|
| 659 | if ((*actionhere).second.a != NULL) {
|
---|
| 660 | if (!(*actionhere).second.a->check_external_cgiargs (argsinfo, args, *outconverter,
|
---|
| 661 | configinfo.saveconf, logout))
|
---|
| 662 | return false;
|
---|
| 663 | }
|
---|
[7421] | 664 | ++actionhere;
|
---|
[362] | 665 | }
|
---|
[165] | 666 |
|
---|
[362] | 667 | // the action might have changed but we will assume that
|
---|
| 668 | // the cgiargs were checked properly when the change was made
|
---|
[165] | 669 |
|
---|
[155] | 670 | return true;
|
---|
| 671 | }
|
---|
| 672 |
|
---|
| 673 |
|
---|
[20856] | 674 | // Returns true if cookie already existed, false if it was generated
|
---|
| 675 | bool receptionist::get_cookie (text_t &cookie, text_tmap &fcgienv)
|
---|
| 676 | {
|
---|
| 677 | // See if we can get the GSDL_UID cookie
|
---|
[864] | 678 | text_t cookiestring = gsdl_getenv ("HTTP_COOKIE", fcgienv);
|
---|
[20856] | 679 | if (!cookiestring.empty()) // This should really be handled by the findword function...
|
---|
[18824] | 680 | {
|
---|
[20856] | 681 | // Check if the cookie contains GSDL_UID
|
---|
| 682 | text_t gsdl_uid = "GSDL_UID=";
|
---|
[20858] | 683 | text_t::iterator gsdl_uid_start = findword(cookiestring.begin(), cookiestring.end(), gsdl_uid);
|
---|
[20856] | 684 | if (gsdl_uid_start != cookiestring.end())
|
---|
| 685 | {
|
---|
| 686 | // Yes, so extract its value
|
---|
| 687 | cookie = substr(gsdl_uid_start + gsdl_uid.size(), findchar(gsdl_uid_start + gsdl_uid.size(), cookiestring.end(), ';'));
|
---|
| 688 | return true;
|
---|
[463] | 689 | }
|
---|
| 690 | }
|
---|
| 691 |
|
---|
[20856] | 692 | // Generate a new key "[host]-[epoch time]", e.g. test.com-1256764496
|
---|
[526] | 693 | cookie.clear();
|
---|
[864] | 694 | text_t host = gsdl_getenv("REMOTE_ADDR", fcgienv);
|
---|
[463] | 695 | time_t ttime = time(NULL);
|
---|
[20856] | 696 | if (!host.empty())
|
---|
| 697 | {
|
---|
[463] | 698 | cookie += host;
|
---|
| 699 | cookie.push_back ('-');
|
---|
| 700 | }
|
---|
| 701 | cookie += text_t(ttime);
|
---|
[20856] | 702 |
|
---|
[463] | 703 | return false;
|
---|
| 704 | }
|
---|
| 705 |
|
---|
| 706 |
|
---|
[20856] | 707 | // Same as above but just tests if cookie exists
|
---|
| 708 | bool receptionist::get_cookie (text_tmap &fcgienv)
|
---|
| 709 | {
|
---|
| 710 | text_t cookie_jar = "";
|
---|
| 711 | return get_cookie(cookie_jar, fcgienv);
|
---|
[463] | 712 | }
|
---|
| 713 |
|
---|
[20856] | 714 |
|
---|
[864] | 715 | bool receptionist::log_cgi_args (cgiargsclass &args, ostream &logout, text_tmap &fcgienv) {
|
---|
[463] | 716 |
|
---|
[526] | 717 | // see if we want to log the cgi arguments
|
---|
| 718 | if (!configinfo.logcgiargs) return true;
|
---|
| 719 |
|
---|
[864] | 720 | text_t host = gsdl_getenv ("REMOTE_HOST", fcgienv);
|
---|
[935] | 721 | text_t script_name = gsdl_getenv ("SCRIPT_NAME", fcgienv);
|
---|
[864] | 722 | if (host.empty()) host = gsdl_getenv ("REMOTE_ADDR", fcgienv);
|
---|
| 723 | text_t browser = gsdl_getenv ("HTTP_USER_AGENT", fcgienv);
|
---|
[463] | 724 |
|
---|
| 725 | cgiargsclass::const_iterator args_here = args.begin();
|
---|
| 726 | cgiargsclass::const_iterator args_end = args.end();
|
---|
| 727 |
|
---|
| 728 | text_t argstr;
|
---|
| 729 | bool first = true;
|
---|
| 730 | while (args_here != args_end) {
|
---|
| 731 | if (!first) argstr += ", ";
|
---|
| 732 | argstr += (*args_here).first + "=" + (*args_here).second.value;
|
---|
| 733 | first = false;
|
---|
[7443] | 734 | ++args_here;
|
---|
[463] | 735 | }
|
---|
| 736 |
|
---|
[15589] | 737 | text_t logfile = filename_cat (configinfo.dbhome, "etc", "usage.txt");
|
---|
[595] | 738 |
|
---|
[935] | 739 | text_t logstr = script_name;
|
---|
| 740 | logstr += " " + host;
|
---|
[595] | 741 | logstr += " [";
|
---|
[1779] | 742 | if (configinfo.LogDateFormat == UTCTime) {
|
---|
| 743 | logstr += get_date (false);
|
---|
| 744 | } else if (configinfo.LogDateFormat == Absolute) {
|
---|
| 745 | time_t ttime = time(NULL);
|
---|
| 746 | logstr += ttime;
|
---|
| 747 | } else {
|
---|
| 748 | // LocalTime
|
---|
| 749 | logstr += get_date (true);
|
---|
| 750 | }
|
---|
[595] | 751 | logstr += "] (" + argstr + ") \"";
|
---|
| 752 | logstr += browser;
|
---|
| 753 | logstr += "\"\n";
|
---|
| 754 |
|
---|
| 755 | return append_logstr (logfile, logstr, logout);
|
---|
| 756 | }
|
---|
| 757 |
|
---|
| 758 | bool receptionist::append_logstr (const text_t &filename, const text_t &logstr,
|
---|
| 759 | ostream &logout) {
|
---|
| 760 |
|
---|
| 761 | char *lfile = filename.getcstr();
|
---|
[1170] | 762 |
|
---|
[24895] | 763 | int fd = open(lfile, O_CREAT | O_WRONLY | O_APPEND, 0777);
|
---|
| 764 | //int fd = open(lfile, O_CREAT | O_RDWR | O_APPEND, 0777);
|
---|
[463] | 765 |
|
---|
[3007] | 766 | if (fd == -1) {
|
---|
[463] | 767 | logout << "Error: Couldn't open file " << lfile << "\n";
|
---|
[7421] | 768 | delete []lfile;
|
---|
[463] | 769 | return false;
|
---|
[595] | 770 | }
|
---|
[463] | 771 |
|
---|
[595] | 772 | // lock_val is set to 0 if file is locked successfully
|
---|
| 773 | int lock_val = 1;
|
---|
[606] | 774 | GSDL_LOCK_FILE (fd);
|
---|
[595] | 775 | if (lock_val == 0) {
|
---|
[23365] | 776 | // Write the string out in UTF-8
|
---|
| 777 | text_t tmp_log_str_utf8 = to_utf8(logstr);
|
---|
| 778 | char *buffer = tmp_log_str_utf8.getcstr();
|
---|
| 779 | size_t num_chars = tmp_log_str_utf8.size();
|
---|
[3007] | 780 | write(fd, buffer, num_chars);
|
---|
[606] | 781 | GSDL_UNLOCK_FILE (fd);
|
---|
[7421] | 782 | delete []buffer;
|
---|
[606] | 783 | } else {
|
---|
[595] | 784 | logout << "Error: Couldn't lock file " << lfile << "\n";
|
---|
[3007] | 785 | close(fd);
|
---|
[7421] | 786 | delete []lfile;
|
---|
[606] | 787 | return false;
|
---|
| 788 | }
|
---|
[595] | 789 |
|
---|
[3007] | 790 | close(fd);
|
---|
[463] | 791 |
|
---|
[7421] | 792 | delete []lfile;
|
---|
[463] | 793 | return true;
|
---|
| 794 | }
|
---|
| 795 |
|
---|
[799] | 796 | text_t receptionist::expandmacros (const text_t &astring, cgiargsclass &args,
|
---|
| 797 | ostream &logout) {
|
---|
| 798 | text_t outstring;
|
---|
| 799 | outconvertclass text_t2ascii;
|
---|
| 800 |
|
---|
| 801 | action *a = actions.getaction (args["a"]);
|
---|
[22231] | 802 | if (a != NULL)
|
---|
| 803 | {
|
---|
| 804 | prepare_page (a, args, text_t2ascii, logout);
|
---|
| 805 | }
|
---|
[7421] | 806 | disp.expandstring (displayclass::defaultpackage, astring, outstring);
|
---|
[799] | 807 | return outstring;
|
---|
| 808 | }
|
---|
| 809 |
|
---|
[155] | 810 | // produce_cgi_page will call get_cgihead_info and
|
---|
[145] | 811 | // produce_content in the appropriate way to output a cgi header and
|
---|
[155] | 812 | // the page content (if needed). If a page could not be created it
|
---|
| 813 | // will return false
|
---|
| 814 | bool receptionist::produce_cgi_page (cgiargsclass &args, ostream &contentout,
|
---|
[864] | 815 | ostream &logout, text_tmap &fcgienv) {
|
---|
[155] | 816 | outconvertclass text_t2ascii;
|
---|
[108] | 817 |
|
---|
[155] | 818 | response_t response;
|
---|
| 819 | text_t response_data;
|
---|
[108] | 820 |
|
---|
[155] | 821 | // produce cgi header
|
---|
[864] | 822 | get_cgihead_info (args, response, response_data, logout, fcgienv);
|
---|
[155] | 823 | if (response == location) {
|
---|
[769] | 824 | // location response (url may contain macros!!)
|
---|
[799] | 825 | response_data = expandmacros (response_data, args, logout);
|
---|
[16819] | 826 |
|
---|
[799] | 827 | contentout << text_t2ascii << "Location: " << response_data << "\n\n";
|
---|
[463] | 828 | contentout << flush;
|
---|
[16819] | 829 |
|
---|
[155] | 830 | return true;
|
---|
| 831 | } else if (response == content) {
|
---|
| 832 | // content response
|
---|
[2386] | 833 |
|
---|
[3663] | 834 | #ifdef GSDL_NOCACHE
|
---|
| 835 | contentout << "Expires: Mon, 26 Jul 1997 05:00:00 GMT\n"; // date in the past
|
---|
| 836 | tm *tm_ptr = NULL;
|
---|
| 837 | time_t t = time(NULL);
|
---|
| 838 | tm_ptr = gmtime (&t);
|
---|
| 839 | if (tm_ptr != NULL) {
|
---|
| 840 | char *timestr = new char[128];
|
---|
| 841 | strftime (timestr, 128, "%a, %d %b %Y %H:%M:%S", tm_ptr);
|
---|
| 842 | contentout << "Last-Modified: " << timestr << " GMT\n"; // always modified
|
---|
[7443] | 843 | delete []timestr;
|
---|
[3663] | 844 | }
|
---|
| 845 | contentout << "Cache-Control: no-cache, must-revalidate\n"; // HTTP/1.1
|
---|
| 846 | contentout << "Pragma: no-cache\n"; // HTTP/1.0
|
---|
| 847 |
|
---|
| 848 | #else
|
---|
| 849 |
|
---|
[2386] | 850 | // use the later of build.cfg and collect.cfg modification times
|
---|
[2608] | 851 | // as the Last-Modified: header, for caching values
|
---|
[2386] | 852 | struct stat file_info;
|
---|
| 853 | time_t latest=0;
|
---|
| 854 |
|
---|
| 855 | text_t collectname="";
|
---|
| 856 | collectname=args["c"];
|
---|
| 857 | if (collectname != "") {
|
---|
[16310] | 858 |
|
---|
| 859 | text_t collecthome;
|
---|
| 860 | if (!configinfo.collecthome.empty()) {
|
---|
| 861 | collecthome = configinfo.collecthome;
|
---|
| 862 | }
|
---|
| 863 | else {
|
---|
| 864 | collecthome=filename_cat(configinfo.gsdlhome,"collect");
|
---|
| 865 | }
|
---|
| 866 | text_t collectdir=filename_cat(collecthome,collectname);
|
---|
| 867 |
|
---|
[2386] | 868 | text_t buildcfg=filename_cat(collectdir,"index");
|
---|
| 869 | buildcfg=filename_cat(buildcfg,"build.cfg");
|
---|
| 870 | char *buildcfg_ptr=buildcfg.getcstr();
|
---|
| 871 | text_t collectcfg=filename_cat(collectdir,"etc");
|
---|
| 872 | collectcfg=filename_cat(collectcfg,"collect.cfg");
|
---|
| 873 | char *collectcfg_ptr=collectcfg.getcstr();
|
---|
| 874 |
|
---|
| 875 | if (stat(buildcfg_ptr, &file_info)) {
|
---|
| 876 | // we got an error. Currently don't handle error :(
|
---|
| 877 | // logout <<
|
---|
| 878 | } else {
|
---|
| 879 | latest=file_info.st_mtime;
|
---|
| 880 | }
|
---|
| 881 |
|
---|
| 882 | if (stat(collectcfg_ptr, &file_info)) {
|
---|
| 883 | // error - unhandled for now
|
---|
| 884 | } else {
|
---|
| 885 | if (latest<file_info.st_mtime) latest=file_info.st_mtime;
|
---|
| 886 | }
|
---|
[7421] | 887 | delete []buildcfg_ptr;
|
---|
| 888 | delete []collectcfg_ptr;
|
---|
[2386] | 889 |
|
---|
| 890 | if (latest>0) {
|
---|
| 891 | // print out modified time, "DDD, dd MMM YYYY hh:mm:ss" format
|
---|
| 892 | // c library takes care of mem for this string... (has \n at end!!!!)
|
---|
[2660] | 893 | // latest is currently local time, convert to UTC.
|
---|
| 894 | struct tm* utc_latest;
|
---|
| 895 | utc_latest=gmtime(&latest);
|
---|
| 896 | contentout << "Last-Modified: " << asctime(utc_latest);
|
---|
[2386] | 897 | }
|
---|
[3007] | 898 | } // end of collection != ""
|
---|
[2386] | 899 |
|
---|
[3663] | 900 | #endif
|
---|
[2957] | 901 |
|
---|
[155] | 902 | contentout << text_t2ascii << "Content-type: " << response_data << "\n\n";
|
---|
[7594] | 903 | }
|
---|
| 904 | else if (response == undecided_location) {
|
---|
| 905 | // Wait until later to output the target location
|
---|
| 906 | // Used for the "I'm feeling lucky" functionality
|
---|
| 907 | }
|
---|
| 908 | else {
|
---|
[155] | 909 | // unknown response
|
---|
| 910 | logout << "Error: get_cgihead_info returned an unknown response type.\n";
|
---|
| 911 | return false;
|
---|
| 912 | }
|
---|
| 913 |
|
---|
| 914 | // produce cgi page
|
---|
| 915 | if (!produce_content (args, contentout, logout)) return false;
|
---|
| 916 |
|
---|
| 917 | // flush contentout
|
---|
| 918 | contentout << flush;
|
---|
| 919 | return true;
|
---|
[108] | 920 | }
|
---|
| 921 |
|
---|
| 922 |
|
---|
[145] | 923 | // get_cgihead_info determines the cgi header information for
|
---|
| 924 | // a set of cgi arguments. If response contains location then
|
---|
| 925 | // response_data contains the redirect address. If reponse
|
---|
| 926 | // contains content then reponse_data contains the content-type.
|
---|
| 927 | // Note that images can now be produced by the receptionist.
|
---|
[7347] | 928 | // Note also, alternative for get_cgihead_info below which
|
---|
| 929 | // stores the information in a text_tmap so it is more easily digested
|
---|
| 930 |
|
---|
[146] | 931 | void receptionist::get_cgihead_info (cgiargsclass &args, response_t &response,
|
---|
[864] | 932 | text_t &response_data, ostream &logout,
|
---|
| 933 | text_tmap &fcgienv) {
|
---|
[155] | 934 | outconvertclass text_t2ascii;
|
---|
| 935 |
|
---|
| 936 | // get the action
|
---|
| 937 | action *a = actions.getaction (args["a"]);
|
---|
| 938 | if (a != NULL) {
|
---|
[760] | 939 | a->get_cgihead_info (args, &protocols, response, response_data, logout);
|
---|
[155] | 940 |
|
---|
| 941 | } else {
|
---|
| 942 | // the action was not found!!
|
---|
| 943 | logout << text_t2ascii << "Error receptionist::get_cgihead_info: the action \""
|
---|
| 944 | << args["a"] << "\" could not be found.\n";
|
---|
| 945 | response = content;
|
---|
| 946 | response_data = "text/html";
|
---|
| 947 | }
|
---|
[388] | 948 |
|
---|
| 949 | // add the encoding information
|
---|
| 950 | if (response == content) {
|
---|
[1870] | 951 | if (converters.find(args["w"]) != converters.end()) {
|
---|
| 952 | response_data += "; charset=" + args["w"];
|
---|
[388] | 953 | } else {
|
---|
[1856] | 954 | // default to latin 1
|
---|
| 955 | response_data += "; charset=ISO-8859-1";
|
---|
[388] | 956 | }
|
---|
[463] | 957 |
|
---|
| 958 | // add cookie if required
|
---|
[864] | 959 | if (configinfo.usecookies && !get_cookie(fcgienv))
|
---|
[463] | 960 | response_data += "\nSet-Cookie: GSDL_UID=" + args["z"]
|
---|
[18818] | 961 | + "; expires=Fri, 25-Dec-2037 00:00:00 GMT";
|
---|
[388] | 962 | }
|
---|
[108] | 963 | }
|
---|
| 964 |
|
---|
| 965 |
|
---|
[7347] | 966 | // Alternative version of get_cgihead_info, stores fielded infomation
|
---|
| 967 | // in text_tmap rather than concatenated string
|
---|
| 968 | void receptionist::get_cgihead_info (cgiargsclass &args, text_tmap &headers,
|
---|
| 969 | ostream &logout, text_tmap &fcgienv) {
|
---|
| 970 |
|
---|
| 971 | response_t response;
|
---|
| 972 | text_t response_data;
|
---|
| 973 |
|
---|
| 974 | // get the action
|
---|
| 975 | action *a = actions.getaction (args["a"]);
|
---|
| 976 | if (a != NULL) {
|
---|
| 977 | a->get_cgihead_info (args, &protocols, response, response_data, logout);
|
---|
| 978 |
|
---|
| 979 | } else {
|
---|
| 980 | // the action was not found!!
|
---|
| 981 | outconvertclass text_t2ascii;
|
---|
| 982 | logout << text_t2ascii << "Error receptionist::get_cgihead_info: the action \""
|
---|
| 983 | << args["a"] << "\" could not be found.\n";
|
---|
| 984 | response = content;
|
---|
| 985 | response_data = "text/html";
|
---|
| 986 | }
|
---|
| 987 |
|
---|
| 988 | if (response == location) {
|
---|
| 989 | response_data = expandmacros(response_data, args, logout);
|
---|
| 990 | headers["Location"] = response_data;
|
---|
| 991 | return;
|
---|
| 992 | }
|
---|
| 993 |
|
---|
| 994 | // add the encoding information
|
---|
| 995 | if (response == content) {
|
---|
| 996 |
|
---|
| 997 | if (converters.find(args["w"]) != converters.end()) {
|
---|
| 998 | headers["content-encoding"] = args["w"];
|
---|
| 999 | response_data += "; charset=" + args["w"];
|
---|
| 1000 | } else {
|
---|
| 1001 | // default to utf-8
|
---|
| 1002 | headers["content-encoding"] = "utf-8";
|
---|
| 1003 | response_data += "; charset=utf-8";
|
---|
| 1004 | }
|
---|
| 1005 |
|
---|
| 1006 | headers["content-type"] = response_data;
|
---|
| 1007 |
|
---|
| 1008 | }
|
---|
| 1009 |
|
---|
| 1010 | }
|
---|
| 1011 |
|
---|
| 1012 |
|
---|
| 1013 |
|
---|
[145] | 1014 | // produce the page content
|
---|
[155] | 1015 | bool receptionist::produce_content (cgiargsclass &args, ostream &contentout,
|
---|
[145] | 1016 | ostream &logout) {
|
---|
[1170] | 1017 |
|
---|
[155] | 1018 | // decide on the output conversion class
|
---|
[165] | 1019 | text_t &arg_w = args["w"];
|
---|
| 1020 | rzwsoutconvertclass defaultoutconverter;
|
---|
| 1021 | rzwsoutconvertclass *outconverter = converters.get_outconverter (arg_w);
|
---|
| 1022 | if (outconverter == NULL) outconverter = &defaultoutconverter;
|
---|
| 1023 | outconverter->reset();
|
---|
[155] | 1024 |
|
---|
[3668] | 1025 | // needed for 16-bit unicode only - big endian marker 0xfeff (RFC 2781)
|
---|
[9674] | 1026 | if (arg_w=="utf-16be") {
|
---|
[3668] | 1027 | contentout << '\xfe' << '\xff' ;
|
---|
| 1028 | }
|
---|
[799] | 1029 |
|
---|
[760] | 1030 | recptproto *collectproto = protocols.getrecptproto (args["c"], logout);
|
---|
| 1031 | if (collectproto != NULL) {
|
---|
[669] | 1032 | // get browsers to process OID
|
---|
| 1033 | text_t OID = args["d"];
|
---|
| 1034 | if (OID.empty()) OID = args["cl"];
|
---|
| 1035 | if (!OID.empty()) {
|
---|
| 1036 | text_tset metadata;
|
---|
| 1037 | text_tarray OIDs;
|
---|
| 1038 | OIDs.push_back (OID);
|
---|
| 1039 | if (!is_top(OID)) OIDs.push_back (OID + ".pr");
|
---|
| 1040 | FilterResponse_t response;
|
---|
| 1041 | metadata.insert ("childtype");
|
---|
[7420] | 1042 | if (get_info (OIDs, args["c"], args["l"], metadata, false, collectproto, response, logout)) {
|
---|
[712] | 1043 | text_t classifytype;
|
---|
[731] | 1044 | if (!response.docInfo[0].metadata["childtype"].values[0].empty())
|
---|
| 1045 | classifytype = response.docInfo[0].metadata["childtype"].values[0];
|
---|
| 1046 | else if (!is_top (OID)) {
|
---|
[6479] | 1047 | // not sure why this is occasionally not set, but it will
|
---|
| 1048 | // cause a segfault... possibly if built with no_text? jrm21
|
---|
| 1049 | if (response.docInfo[1].metadata.find("childtype")
|
---|
| 1050 | == response.docInfo[1].metadata.end()) {
|
---|
| 1051 | cerr << "receptionist: no childtype element in metadata map!"
|
---|
| 1052 | << endl;
|
---|
| 1053 | } else {
|
---|
| 1054 | if (!response.docInfo[1].metadata["childtype"].values[0].empty())
|
---|
| 1055 | classifytype = response.docInfo[1].metadata["childtype"].values[0];
|
---|
| 1056 | }
|
---|
[712] | 1057 | }
|
---|
[669] | 1058 | browserclass *b = browsers.getbrowser (classifytype);
|
---|
| 1059 | b->processOID (args, collectproto, logout);
|
---|
| 1060 | }
|
---|
| 1061 | }
|
---|
[760] | 1062 |
|
---|
[712] | 1063 | // translate "d" and "cl" arguments if required
|
---|
[669] | 1064 | translate_OIDs (args, collectproto, logout);
|
---|
[649] | 1065 | }
|
---|
[760] | 1066 |
|
---|
[155] | 1067 | // produce the page using the desired action
|
---|
| 1068 | action *a = actions.getaction (args["a"]);
|
---|
| 1069 | if (a != NULL) {
|
---|
[760] | 1070 | if (a->uses_display(args)) prepare_page (a, args, (*outconverter), logout);
|
---|
| 1071 | if (!a->do_action (args, &protocols, &browsers, disp, (*outconverter), contentout, logout))
|
---|
[155] | 1072 | return false;
|
---|
| 1073 | } else {
|
---|
| 1074 | // the action was not found!!
|
---|
[165] | 1075 | outconvertclass text_t2ascii;
|
---|
| 1076 |
|
---|
[155] | 1077 | logout << text_t2ascii << "Error receptionist::produce_content: the action \""
|
---|
| 1078 | << args["a"] << "\" could not be found.\n";
|
---|
| 1079 |
|
---|
[165] | 1080 | contentout << (*outconverter)
|
---|
| 1081 | << "<html>\n"
|
---|
| 1082 | << "<head>\n"
|
---|
| 1083 | << "<title>Error</title>\n"
|
---|
| 1084 | << "</head>\n"
|
---|
| 1085 | << "<body>\n"
|
---|
| 1086 | << "<h2>Oops!</h2>\n"
|
---|
| 1087 | << "Undefined Page. The action \""
|
---|
| 1088 | << args["a"] << "\" could not be found.\n"
|
---|
| 1089 | << "</body>\n"
|
---|
| 1090 | << "</html>\n";
|
---|
[155] | 1091 | }
|
---|
| 1092 | return true;
|
---|
[108] | 1093 | }
|
---|
| 1094 |
|
---|
| 1095 |
|
---|
[145] | 1096 | // returns the compressed argument ("e") corresponding to the argument
|
---|
| 1097 | // list. This can be used to save preferences between sessions.
|
---|
[362] | 1098 | text_t receptionist::get_compressed_arg (cgiargsclass &args, ostream &logout) {
|
---|
| 1099 | // decide on the output conversion class
|
---|
| 1100 | text_t &arg_w = args["w"];
|
---|
| 1101 | rzwsoutconvertclass defaultoutconverter;
|
---|
| 1102 | rzwsoutconvertclass *outconverter = converters.get_outconverter (arg_w);
|
---|
| 1103 | if (outconverter == NULL) outconverter = &defaultoutconverter;
|
---|
| 1104 | outconverter->reset();
|
---|
| 1105 |
|
---|
[248] | 1106 | text_t compressed_args;
|
---|
| 1107 | if (compress_save_args (argsinfo, configinfo.saveconf, args,
|
---|
[362] | 1108 | compressed_args, *outconverter, logout))
|
---|
[248] | 1109 | return compressed_args;
|
---|
[362] | 1110 |
|
---|
[7421] | 1111 | return g_EmptyText;
|
---|
[108] | 1112 | }
|
---|
[155] | 1113 |
|
---|
| 1114 |
|
---|
| 1115 | // will read in all the macro files. If one is not found an
|
---|
| 1116 | // error message will be written to logout and the method will
|
---|
| 1117 | // return false.
|
---|
| 1118 | bool receptionist::read_macrofiles (ostream &logout) {
|
---|
| 1119 | outconvertclass text_t2ascii;
|
---|
| 1120 |
|
---|
| 1121 | // redirect the error output to logout
|
---|
[789] | 1122 | ostream *savedlogout = disp.setlogout (&logout);
|
---|
[155] | 1123 |
|
---|
[6022] | 1124 | // unload any macros that were previously loaded - this allows us to call
|
---|
| 1125 | // this function a second time to reload all the macro files (useful for
|
---|
| 1126 | // reading in changed macro files in server versions of greenstone)
|
---|
| 1127 | disp.unloaddefaultmacros();
|
---|
| 1128 |
|
---|
[155] | 1129 | // load up the default macro files, the collection directory
|
---|
| 1130 | // is searched first for the file (if this is being used in
|
---|
[799] | 1131 | // collection specific mode) and then the main directory(s)
|
---|
[165] | 1132 | text_t colmacrodir = filename_cat (configinfo.collectdir, "macros");
|
---|
[799] | 1133 |
|
---|
[1089] | 1134 | text_tset maindirs;
|
---|
[165] | 1135 | text_t gsdlmacrodir = filename_cat (configinfo.gsdlhome, "macros");
|
---|
[1089] | 1136 | maindirs.insert (gsdlmacrodir);
|
---|
[799] | 1137 | colinfo_tmap::iterator colhere = configinfo.collectinfo.begin();
|
---|
| 1138 | colinfo_tmap::iterator colend = configinfo.collectinfo.end();
|
---|
| 1139 | while (colhere != colend) {
|
---|
[1270] | 1140 | if (!((*colhere).second.gsdl_gsdlhome).empty()) {
|
---|
| 1141 | gsdlmacrodir = filename_cat ((*colhere).second.gsdl_gsdlhome, "macros");
|
---|
| 1142 | maindirs.insert (gsdlmacrodir);
|
---|
| 1143 | }
|
---|
[7421] | 1144 | ++colhere;
|
---|
[799] | 1145 | }
|
---|
| 1146 |
|
---|
| 1147 | text_tset::iterator arrhere = configinfo.macrofiles.begin();
|
---|
| 1148 | text_tset::iterator arrend = configinfo.macrofiles.end();
|
---|
[155] | 1149 | text_t filename;
|
---|
| 1150 | while (arrhere != arrend) {
|
---|
[799] | 1151 | bool foundfile = false;
|
---|
[155] | 1152 |
|
---|
| 1153 | // try in the collection directory if this is being
|
---|
| 1154 | // run in collection specific mode
|
---|
[165] | 1155 | if (!configinfo.collection.empty()) {
|
---|
[155] | 1156 | filename = filename_cat (colmacrodir, *arrhere);
|
---|
[799] | 1157 | if (file_exists (filename)) {
|
---|
| 1158 | disp.loaddefaultmacros(filename);
|
---|
| 1159 | foundfile = true;
|
---|
| 1160 | }
|
---|
[155] | 1161 | }
|
---|
| 1162 |
|
---|
| 1163 | // if we haven't found the macro file yet try in
|
---|
[799] | 1164 | // the main macro directory(s)
|
---|
| 1165 | // if file is found in more than one main directory
|
---|
| 1166 | // we'll load all copies
|
---|
| 1167 | if (!foundfile) {
|
---|
[1089] | 1168 | text_tset::const_iterator dirhere = maindirs.begin();
|
---|
| 1169 | text_tset::const_iterator dirend = maindirs.end();
|
---|
[799] | 1170 | while (dirhere != dirend) {
|
---|
| 1171 | filename = filename_cat (*dirhere, *arrhere);
|
---|
| 1172 | if (file_exists (filename)) {
|
---|
| 1173 | disp.loaddefaultmacros(filename);
|
---|
| 1174 | foundfile = true;
|
---|
| 1175 | }
|
---|
[7421] | 1176 | ++dirhere;
|
---|
[799] | 1177 | }
|
---|
[155] | 1178 | }
|
---|
| 1179 |
|
---|
| 1180 | // see if we found the file or not
|
---|
[799] | 1181 | if (!foundfile) {
|
---|
[155] | 1182 | logout << text_t2ascii
|
---|
| 1183 | << "Error: the macro file \"" << *arrhere << "\" could not be found.\n";
|
---|
[165] | 1184 | if (configinfo.collection.empty()) {
|
---|
[799] | 1185 | text_t dirs;
|
---|
| 1186 | joinchar (maindirs, ", ", dirs);
|
---|
| 1187 | logout << text_t2ascii
|
---|
| 1188 | << "It should be in either of the following directories ("
|
---|
| 1189 | << dirs << ").\n\n";
|
---|
| 1190 |
|
---|
[155] | 1191 | } else {
|
---|
| 1192 | logout << text_t2ascii
|
---|
| 1193 | << "It should be in either " << colmacrodir << " or in "
|
---|
| 1194 | << gsdlmacrodir << ".\n\n";
|
---|
| 1195 | }
|
---|
[10636] | 1196 | // don't crap out if a macro file is missing
|
---|
| 1197 | //disp.setlogout (savedlogout);
|
---|
| 1198 | //return false;
|
---|
[155] | 1199 | }
|
---|
[7421] | 1200 | ++arrhere;
|
---|
[155] | 1201 | }
|
---|
| 1202 |
|
---|
| 1203 | // success
|
---|
[789] | 1204 |
|
---|
| 1205 | // reset logout to what it was
|
---|
| 1206 | disp.setlogout (savedlogout);
|
---|
[155] | 1207 | return true;
|
---|
| 1208 | }
|
---|
| 1209 |
|
---|
| 1210 |
|
---|
[7390] | 1211 |
|
---|
| 1212 |
|
---|
| 1213 | // Go through the list of macro files looking to see
|
---|
| 1214 | // if any exist in the collectoin specific area. If they
|
---|
| 1215 | // do then read them in and add them to the set of existing
|
---|
| 1216 | // current macros
|
---|
| 1217 |
|
---|
| 1218 | void receptionist::read_collection_macrofiles (const text_t& collection, ostream &logout)
|
---|
| 1219 | {
|
---|
| 1220 | outconvertclass text_t2ascii;
|
---|
| 1221 |
|
---|
[9615] | 1222 | // disp.unloadcollectionmacros();
|
---|
[7390] | 1223 |
|
---|
| 1224 | // redirect the error output to logout
|
---|
| 1225 | ostream *savedlogout = disp.setlogout (&logout);
|
---|
| 1226 |
|
---|
| 1227 | text_t colmacrodir
|
---|
[16310] | 1228 | = filename_cat (configinfo.collecthome,collection, "macros");
|
---|
[7390] | 1229 |
|
---|
[7509] | 1230 | if (directory_exists (colmacrodir)) {
|
---|
[7390] | 1231 |
|
---|
| 1232 | text_tset::iterator arrhere = configinfo.macrofiles.begin();
|
---|
| 1233 | text_tset::iterator arrend = configinfo.macrofiles.end();
|
---|
| 1234 | text_t filename;
|
---|
| 1235 | while (arrhere != arrend) {
|
---|
| 1236 |
|
---|
| 1237 | filename = filename_cat (colmacrodir, *arrhere);
|
---|
| 1238 | if (file_exists (filename)) {
|
---|
| 1239 | disp.loadcollectionmacros(filename);
|
---|
| 1240 | }
|
---|
| 1241 |
|
---|
[7421] | 1242 | ++arrhere;
|
---|
[7390] | 1243 | }
|
---|
| 1244 | }
|
---|
| 1245 |
|
---|
| 1246 | // reset logout to what it was
|
---|
| 1247 | disp.setlogout (savedlogout);
|
---|
| 1248 | }
|
---|
| 1249 |
|
---|
| 1250 |
|
---|
| 1251 |
|
---|
| 1252 |
|
---|
[155] | 1253 | // check_mainargs will check all the main arguments. If a major
|
---|
| 1254 | // error is found it will return false and no cgi page should
|
---|
| 1255 | // be created using the arguments.
|
---|
[4974] | 1256 |
|
---|
[799] | 1257 | bool receptionist::check_mainargs (cgiargsclass &args, ostream &logout) {
|
---|
[5017] | 1258 |
|
---|
| 1259 | if(configinfo.site_auth)
|
---|
| 1260 | {
|
---|
| 1261 | args["uan"] = "1";
|
---|
| 1262 | args["ug"] = configinfo.site_group;
|
---|
| 1263 | }
|
---|
| 1264 |
|
---|
| 1265 |
|
---|
| 1266 | // if this receptionist is running in collection dependant mode
|
---|
| 1267 | // then it should always set the collection argument to the
|
---|
| 1268 | // collection
|
---|
| 1269 | if (!configinfo.collection.empty()) args["c"] = configinfo.collection;
|
---|
| 1270 |
|
---|
| 1271 | // if current collection uses ccscols make sure
|
---|
| 1272 | // "ccs" argument is set and make "cc" default to
|
---|
| 1273 | // all collections in "ccs"
|
---|
| 1274 | if (args["a"] != "config" && !args["c"].empty()) {
|
---|
| 1275 |
|
---|
| 1276 | text_t &arg_c = args["c"];
|
---|
| 1277 | recptproto *collectproto = protocols.getrecptproto (arg_c, logout);
|
---|
| 1278 | if (collectproto == NULL) {
|
---|
| 1279 | // oops, this collection isn't valid
|
---|
| 1280 | outconvertclass text_t2ascii;
|
---|
| 1281 | logout << text_t2ascii << "ERROR: Invalid collection: " << arg_c << "\n";
|
---|
[5512] | 1282 | // args["c"].clear();
|
---|
[5017] | 1283 |
|
---|
| 1284 | } else {
|
---|
| 1285 |
|
---|
| 1286 | ColInfoResponse_t *cinfo = get_collectinfo_ptr (collectproto, arg_c, logout);
|
---|
| 1287 |
|
---|
[5024] | 1288 | if(cinfo->authenticate == "collection")
|
---|
[5017] | 1289 | {
|
---|
| 1290 | args["uan"] = "1";
|
---|
| 1291 | args["ug"] = cinfo->auth_group;
|
---|
| 1292 | }
|
---|
| 1293 |
|
---|
| 1294 |
|
---|
[1270] | 1295 | if (cinfo != NULL) {
|
---|
[5017] | 1296 | if (!cinfo->ccsCols.empty()) {
|
---|
| 1297 | args["ccs"] = 1;
|
---|
| 1298 | if (args["cc"].empty()) {
|
---|
| 1299 | text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
|
---|
| 1300 | text_tarray::const_iterator col_end = cinfo->ccsCols.end();
|
---|
| 1301 | bool first = true;
|
---|
| 1302 | while (col_here != col_end) {
|
---|
| 1303 | // make sure it's a valid collection
|
---|
| 1304 | if (protocols.getrecptproto (*col_here, logout) != NULL) {
|
---|
| 1305 | if (!first) args["cc"].push_back (',');
|
---|
| 1306 | args["cc"] += *col_here;
|
---|
| 1307 | first = false;
|
---|
| 1308 | }
|
---|
[7421] | 1309 | ++col_here;
|
---|
[1268] | 1310 | }
|
---|
[904] | 1311 | }
|
---|
[799] | 1312 | }
|
---|
[1270] | 1313 | } else {
|
---|
| 1314 | logout << "ERROR (receptionist::check_mainargs): get_collectinfo_ptr returned NULL\n";
|
---|
[799] | 1315 | }
|
---|
| 1316 | }
|
---|
| 1317 | }
|
---|
| 1318 |
|
---|
[155] | 1319 | // argument "v" can only be 0 or 1. Use the default value
|
---|
| 1320 | // if it is out of range
|
---|
| 1321 | int arg_v = args.getintarg ("v");
|
---|
| 1322 | if (arg_v != 0 && arg_v != 1) {
|
---|
| 1323 | cgiarginfo *vinfo = argsinfo.getarginfo ("v");
|
---|
| 1324 | if (vinfo != NULL) args["v"] = vinfo->argdefault;
|
---|
| 1325 | }
|
---|
| 1326 |
|
---|
| 1327 | // argument "f" can only be 0 or 1. Use the default value
|
---|
| 1328 | // if it is out of range
|
---|
| 1329 | int arg_f = args.getintarg ("f");
|
---|
| 1330 | if (arg_f != 0 && arg_f != 1) {
|
---|
| 1331 | cgiarginfo *finfo = argsinfo.getarginfo ("f");
|
---|
| 1332 | if (finfo != NULL) args["f"] = finfo->argdefault;
|
---|
| 1333 | }
|
---|
| 1334 |
|
---|
| 1335 | return true;
|
---|
| 1336 | }
|
---|
[173] | 1337 |
|
---|
[712] | 1338 | // translate_OIDs translates the "d" and "cl" arguments to their correct values
|
---|
[669] | 1339 | // if they use the tricky ".fc", ".lc" type syntax.
|
---|
[649] | 1340 | void receptionist::translate_OIDs (cgiargsclass &args, recptproto *collectproto,
|
---|
| 1341 | ostream &logout) {
|
---|
[438] | 1342 |
|
---|
| 1343 | FilterResponse_t response;
|
---|
| 1344 | FilterRequest_t request;
|
---|
| 1345 | comerror_t err;
|
---|
| 1346 | text_t &arg_d = args["d"];
|
---|
| 1347 | text_t &arg_cl = args["cl"];
|
---|
| 1348 | text_t &collection = args["c"];
|
---|
| 1349 |
|
---|
| 1350 | // do a call to translate OIDs if required
|
---|
| 1351 | request.filterName = "NullFilter";
|
---|
| 1352 | request.filterResultOptions = FROID;
|
---|
[649] | 1353 | if (!arg_d.empty() && needs_translating (arg_d)) {
|
---|
[468] | 1354 | request.docSet.push_back (arg_d);
|
---|
[438] | 1355 | collectproto->filter (collection, request, response, err, logout);
|
---|
| 1356 | arg_d = response.docInfo[0].OID;
|
---|
| 1357 | request.clear();
|
---|
| 1358 | }
|
---|
| 1359 | // we'll also check here that the "cl" argument has a "classify" doctype
|
---|
| 1360 | // (in case ".fc" or ".lc" have screwed up)
|
---|
| 1361 | if (needs_translating (arg_cl)) {
|
---|
[649] | 1362 | request.fields.insert ("doctype");
|
---|
[468] | 1363 | request.docSet.push_back (arg_cl);
|
---|
[438] | 1364 | request.filterResultOptions = FRmetadata;
|
---|
| 1365 | collectproto->filter (collection, request, response, err, logout);
|
---|
| 1366 | // set to original value (without .xx stuff) if doctype isn't "classify"
|
---|
[649] | 1367 | if (response.docInfo[0].metadata["doctype"].values[0] != "classify")
|
---|
[438] | 1368 | strip_suffix (arg_cl);
|
---|
| 1369 | else
|
---|
| 1370 | arg_cl = response.docInfo[0].OID;
|
---|
| 1371 | }
|
---|
| 1372 | }
|
---|
| 1373 |
|
---|
[456] | 1374 | // prepare_page sets up page parameters, sets display macros
|
---|
| 1375 | // and opens the page ready for output
|
---|
[760] | 1376 | void receptionist::prepare_page (action *a, cgiargsclass &args,
|
---|
| 1377 | outconvertclass &outconvert,
|
---|
| 1378 | ostream &logout) {
|
---|
[173] | 1379 | // set up page parameters
|
---|
| 1380 | text_t pageparams;
|
---|
| 1381 | bool first = true;
|
---|
[512] | 1382 |
|
---|
[530] | 1383 | text_tmap::iterator params_here = configinfo.pageparams.begin();
|
---|
| 1384 | text_tmap::iterator params_end = configinfo.pageparams.end();
|
---|
| 1385 | while (params_here != params_end) {
|
---|
[8470] | 1386 | // page params are those from main.cfg (eg pageparam v 0) plus
|
---|
| 1387 | // two defaults set in recptconf.clear() (c="" and l=en)
|
---|
| 1388 | // This used to check if the current value of the page param
|
---|
| 1389 | // == the default value, then don't add in it the list
|
---|
| 1390 | // but if l=en, and there is a macro with [l=en], then it doesn't
|
---|
| 1391 | // find it.
|
---|
| 1392 | // so now all page params will go into the list. I assume this will
|
---|
| 1393 | // mean more attempts to find each macro, but nothing worsee than
|
---|
| 1394 | // that. --kjdon
|
---|
| 1395 | //if (args[(*params_here).first] != (*params_here).second) {
|
---|
[8486] | 1396 | if (first)
|
---|
| 1397 | first = false;
|
---|
| 1398 | else
|
---|
| 1399 | pageparams += ",";
|
---|
| 1400 |
|
---|
[530] | 1401 | pageparams += (*params_here).first;
|
---|
| 1402 | pageparams += "=";
|
---|
| 1403 | pageparams += args[(*params_here).first];
|
---|
[8470] | 1404 | // }
|
---|
[530] | 1405 |
|
---|
[7421] | 1406 | ++params_here;
|
---|
[530] | 1407 | }
|
---|
| 1408 |
|
---|
[418] | 1409 |
|
---|
[173] | 1410 | // open the page
|
---|
[530] | 1411 | disp.openpage(pageparams, configinfo.macroprecedence);
|
---|
[173] | 1412 |
|
---|
[9615] | 1413 | disp.unloadcollectionmacros();
|
---|
| 1414 |
|
---|
[9032] | 1415 | text_t collection = args["c"];
|
---|
| 1416 | if (!collection.empty()) {
|
---|
| 1417 | read_collection_macrofiles(collection,logout);
|
---|
| 1418 | }
|
---|
| 1419 |
|
---|
[173] | 1420 | // define external macros for each action
|
---|
| 1421 | actionptrmap::iterator actionhere = actions.begin ();
|
---|
| 1422 | actionptrmap::iterator actionend = actions.end ();
|
---|
| 1423 |
|
---|
| 1424 | while (actionhere != actionend) {
|
---|
| 1425 | assert ((*actionhere).second.a != NULL);
|
---|
[1860] | 1426 | if ((*actionhere).second.a != NULL) {
|
---|
[760] | 1427 | (*actionhere).second.a->define_external_macros (disp, args, &protocols, logout);
|
---|
[1860] | 1428 | }
|
---|
[7421] | 1429 | ++actionhere;
|
---|
[173] | 1430 | }
|
---|
| 1431 |
|
---|
[7390] | 1432 |
|
---|
[173] | 1433 | // define internal macros for the current action
|
---|
[760] | 1434 | a->define_internal_macros (disp, args, &protocols, logout);
|
---|
[512] | 1435 |
|
---|
| 1436 | // define general macros. the defining of general macros is done here so that
|
---|
| 1437 | // the last possible version of the cgi arguments are used
|
---|
[760] | 1438 | define_general_macros (args, outconvert, logout);
|
---|
[173] | 1439 | }
|
---|
| 1440 |
|
---|
[19259] | 1441 |
|
---|
[760] | 1442 | void receptionist::define_general_macros (cgiargsclass &args, outconvertclass &/*outconvert*/,
|
---|
| 1443 | ostream &logout) {
|
---|
[456] | 1444 |
|
---|
| 1445 | text_t &collection = args["c"];
|
---|
| 1446 |
|
---|
[7421] | 1447 | disp.setmacro ("gsdlhome", displayclass::defaultpackage, dm_safe(configinfo.gsdlhome));
|
---|
| 1448 | disp.setmacro ("gwcgi", displayclass::defaultpackage, configinfo.gwcgi);
|
---|
[19109] | 1449 | disp.setmacro ("httpweb", displayclass::defaultpackage, configinfo.httpweb);
|
---|
[7421] | 1450 | disp.setmacro ("httpprefix", displayclass::defaultpackage, configinfo.httpprefix);
|
---|
[1860] | 1451 |
|
---|
[24106] | 1452 | // This perhaps should be done with gsdl_getenv() which takes the
|
---|
| 1453 | // 'fcgienv' parameter (for fast-cgi), however if changed to this, this
|
---|
| 1454 | // additional parameter would need to be passed into here (not sure how
|
---|
| 1455 | // that would effect any virtual inheritence going on), or else moved
|
---|
| 1456 | // higher up the calling to chain to, e.g., produce_cgi_page()
|
---|
| 1457 |
|
---|
| 1458 | char* remote_addr = getenv("REMOTE_ADDR");
|
---|
| 1459 |
|
---|
| 1460 | if (remote_addr != NULL) {
|
---|
| 1461 | text_t remote_addr_t(remote_addr);
|
---|
| 1462 | disp.setmacro ("remoteAddr", displayclass::defaultpackage, remote_addr_t);
|
---|
| 1463 | }
|
---|
| 1464 |
|
---|
| 1465 | char* remote_host = getenv("REMOTE_HOST");
|
---|
| 1466 | if (remote_host != NULL) {
|
---|
| 1467 | text_t remote_host_t(remote_host);
|
---|
| 1468 | disp.setmacro ("remoteHost", displayclass::defaultpackage, remote_host_t);
|
---|
| 1469 | }
|
---|
| 1470 | else {
|
---|
| 1471 | // setting this to "unknown" is easier to deal with in format/macro
|
---|
| 1472 | // statements, rather than testing for _remoteHost_
|
---|
| 1473 | disp.setmacro ("remoteHost", displayclass::defaultpackage, "unknown");
|
---|
| 1474 | }
|
---|
| 1475 |
|
---|
| 1476 |
|
---|
[864] | 1477 | text_t compressedoptions = get_compressed_arg(args, logout);
|
---|
[7421] | 1478 | disp.setmacro ("compressedoptions", displayclass::defaultpackage, dm_safe(compressedoptions));
|
---|
[864] | 1479 | // need a decoded version of compressedoptions for use within forms
|
---|
| 1480 | // as browsers encode values from forms before sending to server
|
---|
| 1481 | // (e.g. %25 becomes %2525)
|
---|
[13463] | 1482 | decode_cgi_arg (compressedoptions);
|
---|
| 1483 | if (args["w"] == "utf-8") { // if the encoding was utf-8, then compressed options was utf-8, and we need unicode.
|
---|
| 1484 | // if encoding wasn't utf-8, then compressed opotions may be screwed up, but seems to work for 8 bit encodings?
|
---|
| 1485 | compressedoptions = to_uni(compressedoptions);
|
---|
| 1486 | }
|
---|
| 1487 | disp.setmacro ("decodedcompressedoptions", displayclass::defaultpackage, dm_safe(compressedoptions));
|
---|
[173] | 1488 |
|
---|
[1305] | 1489 | #if defined (__WIN32__)
|
---|
[7421] | 1490 | disp.setmacro ("win32", displayclass::defaultpackage, "1");
|
---|
[1305] | 1491 | #endif
|
---|
| 1492 |
|
---|
[173] | 1493 | // set _cgiargX_ macros for each cgi argument
|
---|
| 1494 | cgiargsclass::const_iterator argshere = args.begin();
|
---|
| 1495 | cgiargsclass::const_iterator argsend = args.end();
|
---|
| 1496 | while (argshere != argsend) {
|
---|
[512] | 1497 | if (((*argshere).first == "q") ||
|
---|
| 1498 | ((*argshere).first == "qa") ||
|
---|
| 1499 | ((*argshere).first == "qtt") ||
|
---|
| 1500 | ((*argshere).first == "qty") ||
|
---|
| 1501 | ((*argshere).first == "qp") ||
|
---|
| 1502 | ((*argshere).first == "qpl") ||
|
---|
| 1503 | ((*argshere).first == "qr") ||
|
---|
| 1504 | ((*argshere).first == "q2"))
|
---|
[263] | 1505 | // need to escape special characters from query string
|
---|
[512] | 1506 | disp.setmacro ("cgiarg" + (*argshere).first,
|
---|
[7421] | 1507 | displayclass::defaultpackage, html_safe((*argshere).second.value));
|
---|
[5020] | 1508 | else if ((*argshere).first == "hp") {
|
---|
[7421] | 1509 | disp.setmacro ("cgiarg" + (*argshere).first, displayclass::defaultpackage, (*argshere).second.value);
|
---|
[5020] | 1510 | } else {
|
---|
[7421] | 1511 | disp.setmacro ("cgiarg" + (*argshere).first, displayclass::defaultpackage, dm_safe((*argshere).second.value));
|
---|
[5020] | 1512 | }
|
---|
[7421] | 1513 | ++argshere;
|
---|
[173] | 1514 | }
|
---|
[456] | 1515 |
|
---|
| 1516 | // set collection specific macros
|
---|
[760] | 1517 | if (!collection.empty()) {
|
---|
| 1518 | recptproto *collectproto = protocols.getrecptproto (collection, logout);
|
---|
| 1519 | if (collectproto != NULL) {
|
---|
| 1520 | FilterResponse_t response;
|
---|
| 1521 | text_tset metadata;
|
---|
[7420] | 1522 | get_info ("collection", collection, args["l"], metadata, false,
|
---|
[760] | 1523 | collectproto, response, logout);
|
---|
| 1524 |
|
---|
| 1525 | if (!response.docInfo[0].metadata.empty()) {
|
---|
| 1526 | MetadataInfo_tmap::const_iterator here = response.docInfo[0].metadata.begin();
|
---|
| 1527 | MetadataInfo_tmap::const_iterator end = response.docInfo[0].metadata.end();
|
---|
| 1528 | while (here != end) {
|
---|
| 1529 | if (((*here).first != "haschildren") && ((*here).first != "hasnext") &&
|
---|
| 1530 | ((*here).first != "hasprevious")) {
|
---|
[2773] | 1531 | // check for args in form name:lang
|
---|
[7421] | 1532 | text_t name = g_EmptyText;
|
---|
| 1533 | text_t lang = g_EmptyText;
|
---|
[2773] | 1534 | bool colonfound=false;
|
---|
| 1535 | text_t::const_iterator a = (*here).first.begin();
|
---|
| 1536 | text_t::const_iterator b = (*here).first.end();
|
---|
| 1537 | while (a !=b) {
|
---|
| 1538 | if (*a==':') {
|
---|
| 1539 | colonfound=true;
|
---|
| 1540 | }
|
---|
| 1541 | else {
|
---|
| 1542 | if (colonfound)
|
---|
| 1543 | lang.push_back(*a);
|
---|
| 1544 | else name.push_back(*a);
|
---|
| 1545 | }
|
---|
[7421] | 1546 | ++a;
|
---|
[2773] | 1547 | }
|
---|
| 1548 | if (!lang.empty()) {
|
---|
| 1549 | if (args["l"]==lang) {
|
---|
[9931] | 1550 | disp.setcollectionmacro(displayclass::defaultpackage, name, "", (*here).second.values[0]);
|
---|
[2773] | 1551 | }
|
---|
| 1552 | }
|
---|
| 1553 | else { // the default one
|
---|
[9931] | 1554 | disp.setcollectionmacro(displayclass::defaultpackage, (*here).first, "", (*here).second.values[0]);
|
---|
[2773] | 1555 | }
|
---|
[760] | 1556 | }
|
---|
[7421] | 1557 | ++here;
|
---|
[456] | 1558 | }
|
---|
| 1559 | }
|
---|
[1860] | 1560 |
|
---|
| 1561 | text_t iconcollection;
|
---|
[7421] | 1562 | disp.expandstring (displayclass::defaultpackage, "_iconcollection_", iconcollection);
|
---|
[1860] | 1563 | if (!iconcollection.empty())
|
---|
| 1564 | {
|
---|
[1877] | 1565 | ColInfoResponse_t cinfo;
|
---|
| 1566 | comerror_t err;
|
---|
| 1567 | collectproto->get_collectinfo (collection, cinfo, err, logout);
|
---|
| 1568 | if (iconcollection[0]=='/' && !cinfo.httpdomain.empty())
|
---|
[1860] | 1569 | {
|
---|
| 1570 | // local but with full path
|
---|
| 1571 | iconcollection = "http://" + cinfo.httpdomain + iconcollection;
|
---|
[7421] | 1572 | disp.setmacro("iconcollection", displayclass::defaultpackage, iconcollection);
|
---|
[1860] | 1573 | }
|
---|
| 1574 | }
|
---|
[456] | 1575 | }
|
---|
| 1576 | }
|
---|
[19259] | 1577 |
|
---|
[9931] | 1578 | if (!collection.empty()) {
|
---|
| 1579 | ColInfoResponse_t cinfo;
|
---|
| 1580 | comerror_t err;
|
---|
| 1581 | recptproto *collectproto = protocols.getrecptproto (collection, logout);
|
---|
| 1582 | if (collectproto != NULL) {
|
---|
| 1583 | collectproto->get_collectinfo (collection, cinfo, err, logout);
|
---|
[19259] | 1584 |
|
---|
| 1585 |
|
---|
| 1586 | // This part of the code used to use "cinfo.httpprefix" regardless
|
---|
| 1587 | // of the value it contained. Since
|
---|
| 1588 | // this can come back with an empty (in the case of gsdl_mod), the
|
---|
| 1589 | // URL produced was invalid.
|
---|
| 1590 | //
|
---|
| 1591 | // Changed to test for empty first, and use configinfo.httpprefix as
|
---|
| 1592 | // a "backup"
|
---|
| 1593 | //
|
---|
| 1594 | // Point to consider: since configinfo.httpprefix has been offically
|
---|
| 1595 | // set as "httpprefix" in macros, it seems to make more sense to use
|
---|
| 1596 | // always use that version and not the cinfo version at all.
|
---|
| 1597 |
|
---|
| 1598 | text_t httpprefix
|
---|
| 1599 | = (!cinfo.httpprefix.empty()) ? cinfo.httpprefix : configinfo.httpprefix;
|
---|
| 1600 |
|
---|
[9931] | 1601 | text_t httpcollection;
|
---|
| 1602 | if (!cinfo.httpdomain.empty()) httpcollection = "http://";
|
---|
[19259] | 1603 | httpcollection += cinfo.httpdomain + httpprefix + "/collect/"
|
---|
[9931] | 1604 | + collection;
|
---|
| 1605 | disp.setmacro ("httpcollection", displayclass::defaultpackage,
|
---|
| 1606 | httpcollection);
|
---|
[19259] | 1607 |
|
---|
[9931] | 1608 | // as of gsdl 2.53, collect.cfg can specify macros
|
---|
| 1609 | if (cinfo.collection_macros.size() > 0) {
|
---|
[11964] | 1610 | collectionmeta_map::const_iterator this_macro=cinfo.collection_macros.begin();
|
---|
| 1611 | collectionmeta_map::const_iterator done_macro=cinfo.collection_macros.end();
|
---|
[9931] | 1612 | while (this_macro != done_macro) {
|
---|
[10931] | 1613 | text_t package = "Global";
|
---|
| 1614 | text_t macroname = this_macro->first;
|
---|
| 1615 | // if this macro name is AAA:bbb then extract the package name
|
---|
| 1616 | text_t::const_iterator thischar, donechar;
|
---|
| 1617 | thischar = macroname.begin();
|
---|
| 1618 | donechar = macroname.end();
|
---|
| 1619 | while (thischar < donechar) {
|
---|
| 1620 | if (*thischar == ':') {
|
---|
| 1621 | package = substr(macroname.begin(),thischar);
|
---|
| 1622 | macroname = substr(thischar+1,donechar);
|
---|
| 1623 | break;
|
---|
| 1624 | }
|
---|
| 1625 | ++thischar;
|
---|
| 1626 | }
|
---|
[9931] | 1627 |
|
---|
[11964] | 1628 | text_tmap params_map = this_macro->second;
|
---|
| 1629 | text_tmap::const_iterator this_param = params_map.begin();
|
---|
| 1630 | text_tmap::const_iterator done_param = params_map.end();
|
---|
| 1631 | while (this_param != done_param) {
|
---|
| 1632 | disp.setcollectionmacro(package,
|
---|
| 1633 | macroname,
|
---|
| 1634 | this_param->first,
|
---|
| 1635 | this_param->second);
|
---|
| 1636 | ++this_param;
|
---|
| 1637 | }
|
---|
| 1638 |
|
---|
[9931] | 1639 | ++this_macro;
|
---|
| 1640 | }
|
---|
| 1641 | } // col macros
|
---|
| 1642 | } // collectproto != NULL
|
---|
| 1643 | }
|
---|
| 1644 |
|
---|
[173] | 1645 | }
|
---|
[1270] | 1646 |
|
---|
| 1647 | // gets collection info from cache if found or
|
---|
| 1648 | // calls collection server (and updates cache)
|
---|
| 1649 | // returns NULL if there's an error
|
---|
| 1650 | ColInfoResponse_t *receptionist::get_collectinfo_ptr (recptproto *collectproto,
|
---|
| 1651 | const text_t &collection,
|
---|
| 1652 | ostream &logout) {
|
---|
| 1653 |
|
---|
| 1654 | // check the cache
|
---|
| 1655 | colinfo_tmap::iterator it = configinfo.collectinfo.find (collection);
|
---|
| 1656 | if ((it != configinfo.collectinfo.end()) && ((*it).second.info_loaded)) {
|
---|
| 1657 | // found it
|
---|
| 1658 | return &((*it).second.info);
|
---|
| 1659 | }
|
---|
| 1660 |
|
---|
| 1661 | // not cached, get info from collection server
|
---|
| 1662 | if (collectproto == NULL) {
|
---|
| 1663 | logout << "ERROR: receptionist::get_collectinfo_ptr passed null collectproto\n";
|
---|
| 1664 | return NULL;
|
---|
| 1665 | }
|
---|
| 1666 |
|
---|
| 1667 | comerror_t err;
|
---|
| 1668 | if (it == configinfo.collectinfo.end()) {
|
---|
| 1669 | collectioninfo_t cinfo;
|
---|
| 1670 | collectproto->get_collectinfo (collection, cinfo.info, err, logout);
|
---|
| 1671 | if (err != noError) {
|
---|
| 1672 | outconvertclass text_t2ascii;
|
---|
| 1673 | logout << text_t2ascii << "ERROR (receptionist::getcollectinfo_ptr): \""
|
---|
| 1674 | << get_comerror_string (err) << "\"while getting collectinfo\n";
|
---|
| 1675 | return NULL;
|
---|
| 1676 | }
|
---|
| 1677 | cinfo.info_loaded = true;
|
---|
| 1678 | configinfo.collectinfo[collection] = cinfo;
|
---|
| 1679 | return &(configinfo.collectinfo[collection].info);
|
---|
| 1680 | } else {
|
---|
| 1681 | collectproto->get_collectinfo (collection, (*it).second.info, err, logout);
|
---|
| 1682 | if (err != noError) {
|
---|
| 1683 | outconvertclass text_t2ascii;
|
---|
| 1684 | logout << text_t2ascii << "ERROR (receptionist::getcollectinfo_ptr): \""
|
---|
| 1685 | << get_comerror_string (err) << "\"while getting collectinfo\n";
|
---|
| 1686 | return NULL;
|
---|
| 1687 | }
|
---|
| 1688 | (*it).second.info_loaded = true;
|
---|
| 1689 | return &((*it).second.info);
|
---|
| 1690 | }
|
---|
| 1691 | }
|
---|
[1860] | 1692 |
|
---|
[2218] | 1693 | // removes a collection from the cache so that the next
|
---|
| 1694 | // call to get_collectinfo_ptr() for that collection will
|
---|
| 1695 | // retrieve the collection info from the collection server
|
---|
| 1696 | void receptionist::uncache_collection (const text_t &collection) {
|
---|
| 1697 |
|
---|
| 1698 | colinfo_tmap::iterator it = configinfo.collectinfo.find (collection);
|
---|
| 1699 | if ((it != configinfo.collectinfo.end()) && ((*it).second.info_loaded)) {
|
---|
| 1700 |
|
---|
| 1701 | (*it).second.info_loaded = false;
|
---|
| 1702 |
|
---|
| 1703 | }
|
---|
| 1704 | }
|
---|
| 1705 |
|
---|
[1870] | 1706 | // Handles an "Encoding" line from a configuration file - note that the
|
---|
| 1707 | // configinfo.encodings map is a bit of a hack (to be fixed when the
|
---|
| 1708 | // configuration files are tidied up).
|
---|
| 1709 | void receptionist::configure_encoding (const text_tarray &cfgline) {
|
---|
[1860] | 1710 |
|
---|
[1870] | 1711 | text_t subkey, subvalue, shortname, longname, mapfile;
|
---|
[1927] | 1712 | int multibyte = 0;
|
---|
[1870] | 1713 | text_t::const_iterator cfglinesub_here;
|
---|
| 1714 | text_tarray::const_iterator cfgline_here = cfgline.begin();
|
---|
| 1715 | text_tarray::const_iterator cfgline_end = cfgline.end();
|
---|
| 1716 | while (cfgline_here != cfgline_end) {
|
---|
[1927] | 1717 | if (*cfgline_here == "multibyte") {
|
---|
| 1718 | multibyte = 1;
|
---|
| 1719 | } else {
|
---|
| 1720 | cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
|
---|
| 1721 | (*cfgline_here).end(), '=', subkey);
|
---|
| 1722 | if (subkey == "shortname") {
|
---|
| 1723 | shortname = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
| 1724 | } else if (subkey == "longname") {
|
---|
| 1725 | longname = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
| 1726 | } else if (subkey == "map") {
|
---|
| 1727 | mapfile = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
| 1728 | }
|
---|
[1870] | 1729 | }
|
---|
[7443] | 1730 | ++cfgline_here;
|
---|
[1870] | 1731 | }
|
---|
| 1732 | if (!shortname.empty()) {
|
---|
| 1733 | if (longname.empty()) longname = shortname;
|
---|
| 1734 |
|
---|
| 1735 | // add the converter
|
---|
| 1736 | if (shortname == "utf-8") {
|
---|
| 1737 | utf8inconvertclass *utf8inconvert = new utf8inconvertclass();
|
---|
| 1738 | utf8outconvertclass *utf8outconvert = new utf8outconvertclass();
|
---|
| 1739 | utf8outconvert->set_rzws(1);
|
---|
| 1740 | add_converter (shortname, utf8inconvert, utf8outconvert);
|
---|
| 1741 | configinfo.encodings[longname] = shortname;
|
---|
| 1742 |
|
---|
[9674] | 1743 | } else if (shortname == "utf-16be") {
|
---|
[3668] | 1744 | // we use the default input converter as this shouldn't ever be used
|
---|
| 1745 | // for converting from unicode...
|
---|
| 1746 | inconvertclass *inconverter = new inconvertclass();
|
---|
| 1747 | utf16outconvertclass *outconverter = new utf16outconvertclass();
|
---|
| 1748 | add_converter (shortname, inconverter, outconverter);
|
---|
| 1749 | configinfo.encodings[longname] = shortname;
|
---|
| 1750 |
|
---|
[1870] | 1751 | } else if (!mapfile.empty()) {
|
---|
| 1752 |
|
---|
| 1753 | if (mapfile == "8859_1.ump") {
|
---|
| 1754 | // iso-8859-1 is a special case as it'll always be supported by the
|
---|
| 1755 | // standard converter class and therefore doesn't need to use its
|
---|
| 1756 | // mapping file
|
---|
| 1757 | inconvertclass *inconvert = new inconvertclass();
|
---|
| 1758 | rzwsoutconvertclass *outconvert = new rzwsoutconvertclass();
|
---|
| 1759 | outconvert->set_rzws(1);
|
---|
| 1760 | add_converter (shortname, inconvert, outconvert);
|
---|
| 1761 | configinfo.encodings[longname] = shortname;
|
---|
| 1762 |
|
---|
| 1763 | } else {
|
---|
| 1764 | text_t to_uc_map = filename_cat(configinfo.gsdlhome, "mappings", "to_uc", mapfile);
|
---|
| 1765 | text_t from_uc_map = filename_cat(configinfo.gsdlhome, "mappings", "from_uc", mapfile);
|
---|
| 1766 | if (file_exists(to_uc_map) && file_exists(from_uc_map)) {
|
---|
| 1767 |
|
---|
| 1768 | mapinconvertclass *mapinconvert = new mapinconvertclass();
|
---|
| 1769 | mapinconvert->setmapfile (to_uc_map, 0x003F);
|
---|
[1927] | 1770 | mapinconvert->set_multibyte (multibyte);
|
---|
[1870] | 1771 | mapoutconvertclass *mapoutconvert = new mapoutconvertclass();
|
---|
| 1772 | mapoutconvert->setmapfile (from_uc_map, 0x3F);
|
---|
[1927] | 1773 | mapoutconvert->set_multibyte (multibyte);
|
---|
[1870] | 1774 | mapoutconvert->set_rzws(1);
|
---|
| 1775 | add_converter (shortname, mapinconvert, mapoutconvert);
|
---|
| 1776 | configinfo.encodings[longname] = shortname;
|
---|
| 1777 | }
|
---|
| 1778 | }
|
---|
| 1779 | }
|
---|
| 1780 | }
|
---|
| 1781 | }
|
---|