[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"
|
---|
| 31 | #include "fileutil.h"
|
---|
[155] | 32 | #include "cgiutils.h"
|
---|
[263] | 33 | #include "htmlutils.h"
|
---|
[1148] | 34 | #include "gsdltools.h"
|
---|
[1779] | 35 | #include "gsdltimes.h"
|
---|
[248] | 36 | #include "OIDtools.h"
|
---|
[108] | 37 | #include <assert.h>
|
---|
[150] | 38 | #include <time.h>
|
---|
[3007] | 39 | #include <stdio.h> // for open()
|
---|
| 40 | #include <fcntl.h> // for open() flags
|
---|
[2608] | 41 | // following 2 are for printing Last-Modified http header.
|
---|
[2386] | 42 | #include <sys/stat.h>
|
---|
| 43 | #include <time.h>
|
---|
| 44 |
|
---|
[1170] | 45 | #if defined (GSDL_USE_IOS_H)
|
---|
[463] | 46 | #include <fstream.h>
|
---|
[1170] | 47 | #else
|
---|
| 48 | #include <fstream>
|
---|
| 49 | #endif
|
---|
[108] | 50 |
|
---|
[526] | 51 | void recptconf::clear () {
|
---|
| 52 | gsdlhome.clear();
|
---|
[799] | 53 | gdbmhome.clear();
|
---|
[806] | 54 | collectinfo.erase(collectinfo.begin(), collectinfo.end());
|
---|
[526] | 55 | collection.clear();
|
---|
| 56 | collectdir.clear();
|
---|
| 57 | httpprefix.clear();
|
---|
[1193] | 58 | httpimg = "/images";
|
---|
[526] | 59 | gwcgi.clear();
|
---|
| 60 | macrofiles.erase(macrofiles.begin(), macrofiles.end());
|
---|
| 61 | saveconf.clear();
|
---|
| 62 | usecookies = false;
|
---|
| 63 | logcgiargs = false;
|
---|
[1779] | 64 | LogDateFormat = LocalTime;
|
---|
[530] | 65 |
|
---|
[1762] | 66 | maintainer.clear();
|
---|
| 67 | MailServer.clear();
|
---|
| 68 | LogEvents = Disabled;
|
---|
| 69 | EmailEvents = Disabled;
|
---|
| 70 | EmailUserEvents = false;
|
---|
| 71 |
|
---|
[1856] | 72 | languages.erase(languages.begin(), languages.end());
|
---|
| 73 | encodings.erase(encodings.begin(), encodings.end());
|
---|
| 74 |
|
---|
[530] | 75 | // these default page parameters can always be overriden
|
---|
| 76 | // in the configuration file
|
---|
| 77 | pageparams.erase(pageparams.begin(), pageparams.end());
|
---|
| 78 | pageparams["c"] = "";
|
---|
| 79 | pageparams["l"] = "en";
|
---|
| 80 |
|
---|
| 81 | #ifdef MACROPRECEDENCE
|
---|
| 82 | macroprecedence = MACROPRECEDENCE;
|
---|
| 83 | #else
|
---|
| 84 | macroprecedence.clear();
|
---|
| 85 | #endif
|
---|
[526] | 86 | }
|
---|
| 87 |
|
---|
[1270] | 88 | void collectioninfo_t::clear () {
|
---|
| 89 | gsdl_gsdlhome.clear();
|
---|
| 90 | gsdl_gdbmhome.clear();
|
---|
[526] | 91 |
|
---|
[1270] | 92 | info_loaded = false;
|
---|
| 93 | info.clear();
|
---|
| 94 | }
|
---|
[526] | 95 |
|
---|
[1856] | 96 | void languageinfo_t::clear () {
|
---|
| 97 | longname.clear();
|
---|
| 98 | defaultencoding.clear();
|
---|
| 99 | }
|
---|
| 100 |
|
---|
[388] | 101 | receptionist::receptionist () {
|
---|
| 102 | // create a list of cgi arguments
|
---|
| 103 | // this must be done before the configuration
|
---|
| 104 |
|
---|
| 105 | cgiarginfo ainfo;
|
---|
| 106 |
|
---|
| 107 | ainfo.shortname = "e";
|
---|
| 108 | ainfo.longname = "compressed arguments";
|
---|
| 109 | ainfo.multiplechar = true;
|
---|
| 110 | ainfo.defaultstatus = cgiarginfo::good;
|
---|
| 111 | ainfo.argdefault = "";
|
---|
| 112 | ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 113 | argsinfo.addarginfo (NULL, ainfo);
|
---|
| 114 |
|
---|
| 115 | ainfo.shortname = "a";
|
---|
| 116 | ainfo.longname = "action";
|
---|
| 117 | ainfo.multiplechar = true;
|
---|
| 118 | ainfo.defaultstatus = cgiarginfo::none;
|
---|
| 119 | ainfo.argdefault = "";
|
---|
| 120 | ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 121 | argsinfo.addarginfo (NULL, ainfo);
|
---|
| 122 |
|
---|
| 123 | // w=western
|
---|
| 124 | ainfo.shortname = "w";
|
---|
| 125 | ainfo.longname = "encoding";
|
---|
| 126 | ainfo.multiplechar = true;
|
---|
[1856] | 127 | ainfo.defaultstatus = cgiarginfo::none;
|
---|
| 128 | ainfo.argdefault = "";
|
---|
[388] | 129 | ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 130 | argsinfo.addarginfo (NULL, ainfo);
|
---|
| 131 |
|
---|
| 132 | ainfo.shortname = "nw";
|
---|
| 133 | ainfo.longname = "new encoding";
|
---|
| 134 | ainfo.multiplechar = true;
|
---|
| 135 | ainfo.defaultstatus = cgiarginfo::none;
|
---|
| 136 | ainfo.argdefault = "";
|
---|
| 137 | ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 138 | argsinfo.addarginfo (NULL, ainfo);
|
---|
| 139 |
|
---|
| 140 | ainfo.shortname = "c";
|
---|
| 141 | ainfo.longname = "collection";
|
---|
| 142 | ainfo.multiplechar = true;
|
---|
| 143 | ainfo.defaultstatus = cgiarginfo::none;
|
---|
| 144 | ainfo.argdefault = "";
|
---|
| 145 | ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 146 | argsinfo.addarginfo (NULL, ainfo);
|
---|
| 147 |
|
---|
| 148 | // the interface language name should use the ISO 639
|
---|
| 149 | // standard
|
---|
| 150 | ainfo.shortname = "l";
|
---|
| 151 | ainfo.longname = "interface language";
|
---|
| 152 | ainfo.multiplechar = true;
|
---|
| 153 | ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 154 | ainfo.argdefault = "en";
|
---|
| 155 | ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 156 | argsinfo.addarginfo (NULL, ainfo);
|
---|
[1856] | 157 |
|
---|
| 158 | ainfo.shortname = "nl";
|
---|
| 159 | ainfo.longname = "new language";
|
---|
| 160 | ainfo.multiplechar = false;
|
---|
| 161 | ainfo.defaultstatus = cgiarginfo::none;
|
---|
| 162 | ainfo.argdefault = "0";
|
---|
| 163 | ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 164 | argsinfo.addarginfo (NULL, ainfo);
|
---|
| 165 |
|
---|
[463] | 166 | // the GSDL_UID (cookie)
|
---|
| 167 | ainfo.shortname = "z";
|
---|
| 168 | ainfo.longname = "gsdl uid";
|
---|
| 169 | ainfo.multiplechar = true;
|
---|
| 170 | ainfo.defaultstatus = cgiarginfo::none;
|
---|
| 171 | ainfo.argdefault = "";
|
---|
| 172 | ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 173 | argsinfo.addarginfo (NULL, ainfo);
|
---|
[530] | 174 | }
|
---|
[463] | 175 |
|
---|
[530] | 176 |
|
---|
| 177 | void receptionist::add_action (action *theaction) {
|
---|
| 178 | // make sure we have an action to add
|
---|
| 179 | if (theaction == NULL) return;
|
---|
| 180 |
|
---|
| 181 | // add this action to the list of actions
|
---|
| 182 | actions.addaction(theaction);
|
---|
| 183 |
|
---|
| 184 | // add the cgi arguments from this action
|
---|
| 185 | argsinfo.addarginfo (NULL, theaction->getargsinfo());
|
---|
[388] | 186 | }
|
---|
| 187 |
|
---|
| 188 |
|
---|
[649] | 189 | void receptionist::add_browser (browserclass *thebrowser) {
|
---|
| 190 | // make sure we have a browser to add
|
---|
| 191 | if (thebrowser == NULL) return;
|
---|
| 192 |
|
---|
| 193 | // add this browser to the list of browsers
|
---|
| 194 | browsers.addbrowser(thebrowser);
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 |
|
---|
| 198 | void receptionist::setdefaultbrowser (const text_t &browsername) {
|
---|
| 199 | browsers.setdefaultbrowser (browsername);
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 |
|
---|
[165] | 203 | // configure should be called for each line in the
|
---|
| 204 | // configuration files to configure the receptionist and everything
|
---|
| 205 | // it contains. The configuration should take place after everything
|
---|
| 206 | // has been added but before the initialisation.
|
---|
| 207 | void receptionist::configure (const text_t &key, const text_tarray &cfgline) {
|
---|
| 208 | // configure the receptionist
|
---|
[1870] | 209 |
|
---|
[165] | 210 | if (cfgline.size() >= 1) {
|
---|
[388] | 211 | cgiarginfo *info = NULL;
|
---|
[2561] | 212 | if (key == "gsdlhome") {
|
---|
| 213 | configinfo.gsdlhome = cfgline[0];
|
---|
| 214 | if (configinfo.gdbmhome.empty()) configinfo.gdbmhome = cfgline[0];
|
---|
| 215 | }
|
---|
[2212] | 216 | else if (key == "gdbmhome") configinfo.gdbmhome = cfgline[0];
|
---|
[388] | 217 | else if (key == "collection") {
|
---|
| 218 | configinfo.collection = cfgline[0];
|
---|
| 219 | // also need to set the default arg to this collection
|
---|
| 220 | if ((info = argsinfo.getarginfo("c")) != NULL) {
|
---|
| 221 | info->defaultstatus = cgiarginfo::good;
|
---|
| 222 | info->argdefault = cfgline[0];
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | } else if (key == "collectdir") configinfo.collectdir = cfgline[0];
|
---|
[297] | 226 | else if (key == "httpprefix") configinfo.httpprefix = cfgline[0];
|
---|
[165] | 227 | else if (key == "httpimg") configinfo.httpimg = cfgline[0];
|
---|
| 228 | else if (key == "gwcgi") configinfo.gwcgi = cfgline[0];
|
---|
[799] | 229 | else if (key == "macrofiles") {
|
---|
| 230 | // want to append to macrofiles (i.e. may be several config files
|
---|
| 231 | // contributing, maybe from several collections).
|
---|
| 232 | text_tarray::const_iterator here = cfgline.begin();
|
---|
| 233 | text_tarray::const_iterator end = cfgline.end();
|
---|
| 234 | while (here != end) {
|
---|
| 235 | configinfo.macrofiles.insert (*here);
|
---|
| 236 | here ++;
|
---|
| 237 | }
|
---|
| 238 | }
|
---|
[165] | 239 | else if (key == "saveconf") configinfo.saveconf = cfgline[0];
|
---|
[526] | 240 | else if (key == "usecookies") configinfo.usecookies = (cfgline[0] == "true");
|
---|
| 241 | else if (key == "logcgiargs") configinfo.logcgiargs = (cfgline[0] == "true");
|
---|
[1762] | 242 | else if (key == "maintainer") configinfo.maintainer = cfgline[0];
|
---|
| 243 | else if (key == "MailServer") configinfo.MailServer = cfgline[0];
|
---|
[1779] | 244 | else if (key == "LogDateFormat") {
|
---|
| 245 | if (cfgline[0] == "UTCTime") configinfo.LogDateFormat = UTCTime;
|
---|
| 246 | else if (cfgline[0] == "Absolute") configinfo.LogDateFormat = Absolute;
|
---|
| 247 | }
|
---|
[1762] | 248 | else if (key == "LogEvents") {
|
---|
| 249 | if (cfgline[0] == "CollectorEvents") configinfo.LogEvents = CollectorEvents;
|
---|
| 250 | else if (cfgline[0] == "AllEvents") configinfo.LogEvents = AllEvents;
|
---|
| 251 | }
|
---|
| 252 | else if (key == "EmailEvents") {
|
---|
| 253 | if (cfgline[0] == "CollectorEvents") configinfo.EmailEvents = CollectorEvents;
|
---|
| 254 | else if (cfgline[0] == "AllEvents") configinfo.EmailEvents = AllEvents;
|
---|
| 255 | }
|
---|
| 256 | else if (key == "EmailUserEvents") configinfo.EmailUserEvents = (cfgline[0] == "true");
|
---|
[530] | 257 | else if (key == "pageparam") {
|
---|
| 258 | if (cfgline.size() >= 2) configinfo.pageparams[cfgline[0]] = cfgline[1];
|
---|
| 259 | else configinfo.pageparams[cfgline[0]] = "";
|
---|
| 260 | }
|
---|
| 261 | else if (key == "macroprecedence") configinfo.macroprecedence = cfgline[0];
|
---|
[799] | 262 | else if (key == "collectinfo") {
|
---|
| 263 | if (cfgline.size() >= 3) {
|
---|
| 264 | collectioninfo_t cinfo;
|
---|
| 265 | cinfo.gsdl_gsdlhome = cfgline[1];
|
---|
| 266 | cinfo.gsdl_gdbmhome = cfgline[2];
|
---|
| 267 | configinfo.collectinfo[cfgline[0]] = cinfo;
|
---|
| 268 | }
|
---|
| 269 | }
|
---|
[530] | 270 |
|
---|
| 271 | else if (key == "cgiarg") {
|
---|
| 272 | // get shortname
|
---|
| 273 | bool seen_defaultstatus = false;
|
---|
| 274 | text_t subkey, subvalue;
|
---|
| 275 | text_t shortname;
|
---|
| 276 | text_t::const_iterator cfglinesub_here;
|
---|
| 277 | text_tarray::const_iterator cfgline_here = cfgline.begin();
|
---|
| 278 | text_tarray::const_iterator cfgline_end = cfgline.end();
|
---|
| 279 | while (cfgline_here != cfgline_end) {
|
---|
| 280 | cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
|
---|
| 281 | (*cfgline_here).end(), '=', subkey);
|
---|
| 282 | if (subkey == "shortname") {
|
---|
| 283 | shortname = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
| 284 | }
|
---|
| 285 | cfgline_here++;
|
---|
[388] | 286 | }
|
---|
[530] | 287 |
|
---|
| 288 | // if we found the shortname process the line again filling in values
|
---|
| 289 | if (!shortname.empty()) {
|
---|
| 290 | cgiarginfo &chinfo = argsinfo[shortname];
|
---|
| 291 | chinfo.shortname = shortname; // in case this is a new argument
|
---|
| 292 |
|
---|
| 293 | cfgline_here = cfgline.begin();
|
---|
| 294 | while (cfgline_here != cfgline_end) {
|
---|
| 295 | cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
|
---|
| 296 | (*cfgline_here).end(), '=', subkey);
|
---|
| 297 | subvalue = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
| 298 |
|
---|
| 299 | if (subkey == "longname") chinfo.longname = subvalue;
|
---|
| 300 | else if (subkey == "multiplechar") chinfo.multiplechar = (subvalue == "true");
|
---|
| 301 | else if (subkey == "defaultstatus") {
|
---|
| 302 | seen_defaultstatus = true;
|
---|
| 303 | if (subvalue == "none") chinfo.defaultstatus = cgiarginfo::none;
|
---|
| 304 | else if (subvalue == "weak") chinfo.defaultstatus = cgiarginfo::weak;
|
---|
| 305 | else if (subvalue == "good") chinfo.defaultstatus = cgiarginfo::good;
|
---|
| 306 | else if (subvalue == "config") chinfo.defaultstatus = cgiarginfo::config;
|
---|
| 307 | else if (subvalue == "imperative") chinfo.defaultstatus = cgiarginfo::imperative;
|
---|
| 308 | }
|
---|
| 309 | else if (subkey == "argdefault") {
|
---|
| 310 | chinfo.argdefault = subvalue;
|
---|
| 311 | if (!seen_defaultstatus) chinfo.defaultstatus = cgiarginfo::config;
|
---|
| 312 | }
|
---|
| 313 | else if (subkey == "savedarginfo") {
|
---|
| 314 | if (subvalue == "mustnot") chinfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 315 | else if (subvalue == "can") chinfo.savedarginfo = cgiarginfo::can;
|
---|
| 316 | else if (subvalue == "must") chinfo.savedarginfo = cgiarginfo::must;
|
---|
| 317 | }
|
---|
| 318 |
|
---|
| 319 | cfgline_here++;
|
---|
| 320 | }
|
---|
| 321 | }
|
---|
[1856] | 322 |
|
---|
| 323 | } else if (key == "Encoding") {
|
---|
| 324 |
|
---|
[1870] | 325 | configure_encoding (cfgline);
|
---|
| 326 |
|
---|
[1856] | 327 | } else if (key == "Language") {
|
---|
[1870] | 328 | text_t subkey, subvalue, shortname;
|
---|
| 329 | languageinfo_t lang;
|
---|
[1856] | 330 | text_t::const_iterator cfglinesub_here;
|
---|
| 331 | text_tarray::const_iterator cfgline_here = cfgline.begin();
|
---|
| 332 | text_tarray::const_iterator cfgline_end = cfgline.end();
|
---|
| 333 | while (cfgline_here != cfgline_end) {
|
---|
| 334 | cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
|
---|
| 335 | (*cfgline_here).end(), '=', subkey);
|
---|
| 336 | if (subkey == "shortname") {
|
---|
| 337 | shortname = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
| 338 | } else if (subkey == "longname") {
|
---|
[1870] | 339 | lang.longname = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
[1856] | 340 | } else if (subkey == "default_encoding") {
|
---|
[1870] | 341 | lang.defaultencoding = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
[1856] | 342 | }
|
---|
| 343 | cfgline_here++;
|
---|
| 344 | }
|
---|
| 345 | if (!shortname.empty()) {
|
---|
[1870] | 346 | if (lang.longname.empty()) lang.longname = shortname;
|
---|
[1856] | 347 | configinfo.languages[shortname] = lang;
|
---|
| 348 | }
|
---|
[388] | 349 | }
|
---|
[165] | 350 | }
|
---|
[530] | 351 |
|
---|
[165] | 352 | // configure the actions
|
---|
| 353 | actionptrmap::iterator actionhere = actions.begin ();
|
---|
| 354 | actionptrmap::iterator actionend = actions.end ();
|
---|
[108] | 355 |
|
---|
[165] | 356 | while (actionhere != actionend) {
|
---|
| 357 | assert ((*actionhere).second.a != NULL);
|
---|
| 358 | if ((*actionhere).second.a != NULL)
|
---|
| 359 | (*actionhere).second.a->configure(key, cfgline);
|
---|
[108] | 360 |
|
---|
[165] | 361 | actionhere++;
|
---|
| 362 | }
|
---|
[108] | 363 |
|
---|
[165] | 364 | // configure the protocols
|
---|
| 365 | recptprotolistclass::iterator protohere = protocols.begin ();
|
---|
| 366 | recptprotolistclass::iterator protoend = protocols.end ();
|
---|
[108] | 367 |
|
---|
[165] | 368 | while (protohere != protoend) {
|
---|
| 369 | assert ((*protohere).p != NULL);
|
---|
[2113] | 370 | comerror_t err;
|
---|
[165] | 371 | if ((*protohere).p != NULL)
|
---|
[2113] | 372 | (*protohere).p->configure(key, cfgline, err);
|
---|
[165] | 373 |
|
---|
| 374 | protohere++;
|
---|
[155] | 375 | }
|
---|
[649] | 376 |
|
---|
| 377 | // configure the browsers
|
---|
| 378 | browserptrmap::iterator browserhere = browsers.begin ();
|
---|
| 379 | browserptrmap::iterator browserend = browsers.end ();
|
---|
| 380 |
|
---|
| 381 | while (browserhere != browserend) {
|
---|
| 382 | assert ((*browserhere).second.b != NULL);
|
---|
| 383 | if ((*browserhere).second.b != NULL)
|
---|
| 384 | (*browserhere).second.b->configure(key, cfgline);
|
---|
| 385 |
|
---|
| 386 | browserhere++;
|
---|
| 387 | }
|
---|
[108] | 388 | }
|
---|
| 389 |
|
---|
[649] | 390 |
|
---|
[165] | 391 | void receptionist::configure (const text_t &key, const text_t &value) {
|
---|
| 392 | text_tarray cfgline;
|
---|
| 393 | cfgline.push_back (value);
|
---|
| 394 | configure(key, cfgline);
|
---|
| 395 | }
|
---|
| 396 |
|
---|
| 397 |
|
---|
[1870] | 398 | // init should be called after all the actions and protocols have been
|
---|
| 399 | // added to the receptionist and after everything has been configured but
|
---|
| 400 | // before any pages are created. It returns true on success and false on
|
---|
| 401 | // failure. If false is returned getpage should not be called (without
|
---|
| 402 | // producing meaningless output), instead an error page should be produced
|
---|
| 403 | // by the calling code.
|
---|
[150] | 404 | bool receptionist::init (ostream &logout) {
|
---|
[1870] | 405 |
|
---|
[165] | 406 | // first configure collectdir
|
---|
| 407 | text_t thecollectdir = configinfo.gsdlhome;
|
---|
| 408 | if (!configinfo.collection.empty()) {
|
---|
| 409 | // collection specific mode
|
---|
| 410 | if (!configinfo.collectdir.empty()) {
|
---|
| 411 | // has already been configured
|
---|
| 412 | thecollectdir = configinfo.collectdir;
|
---|
| 413 | } else {
|
---|
| 414 | // decide where collectdir is by searching for collect.cfg
|
---|
| 415 | // look in $GSDLHOME/collect/collection-name/etc/collect.cfg and
|
---|
| 416 | // then $GSDLHOME/etc/collect.cfg
|
---|
[189] | 417 | thecollectdir = filename_cat (configinfo.gsdlhome, "collect");
|
---|
[165] | 418 | thecollectdir = filename_cat (thecollectdir, configinfo.collection);
|
---|
| 419 | text_t filename = filename_cat (thecollectdir, "etc");
|
---|
| 420 | filename = filename_cat (filename, "collect.cfg");
|
---|
[418] | 421 |
|
---|
[165] | 422 | if (!file_exists(filename)) thecollectdir = configinfo.gsdlhome;
|
---|
| 423 | }
|
---|
| 424 | }
|
---|
| 425 | configure("collectdir", thecollectdir);
|
---|
| 426 |
|
---|
[155] | 427 | // read in the macro files
|
---|
| 428 | if (!read_macrofiles (logout)) return false;
|
---|
[108] | 429 |
|
---|
[165] | 430 | // there must be at least one action defined
|
---|
| 431 | if (actions.empty()) {
|
---|
| 432 | logout << "Error: no actions have been added to the receptionist\n";
|
---|
| 433 | return false;
|
---|
| 434 | }
|
---|
| 435 |
|
---|
[649] | 436 | // there must be at least one browser defined
|
---|
| 437 | if (browsers.empty()) {
|
---|
| 438 | logout << "Error: no browsers have been added to the receptionist\n";
|
---|
| 439 | return false;
|
---|
| 440 | }
|
---|
| 441 |
|
---|
[155] | 442 | // create a saveconf string if there isn't one already
|
---|
[165] | 443 | if (configinfo.saveconf.empty())
|
---|
| 444 | configinfo.saveconf = create_save_conf_str (argsinfo, logout);
|
---|
[108] | 445 |
|
---|
[155] | 446 | // check the saveconf string
|
---|
[165] | 447 | if (!check_save_conf_str (configinfo.saveconf, argsinfo, logout))
|
---|
[155] | 448 | return false;
|
---|
| 449 |
|
---|
| 450 | // set a random seed
|
---|
| 451 | srand (time(NULL));
|
---|
| 452 |
|
---|
[1762] | 453 | // if maintainer email address is something dodgy (for now I'll define
|
---|
| 454 | // dodgy as being anything that doesn't contain '@') disable EmailEvents
|
---|
[1778] | 455 | // and EmailUserEvents (we don't strictly need to disable EmailUserEvents
|
---|
| 456 | // in this case but we will as it seems likely that MailServer will also
|
---|
| 457 | // be screwed up if maintainer is).
|
---|
[1762] | 458 | text_t::const_iterator maintainer_end = configinfo.maintainer.end ();
|
---|
[2937] | 459 | text_t::const_iterator maintainer_here = findchar ((text_t::const_iterator)configinfo.maintainer.begin(),
|
---|
[1762] | 460 | maintainer_end, '@');
|
---|
| 461 | if (maintainer_here == maintainer_end) {
|
---|
| 462 | configinfo.EmailEvents = Disabled;
|
---|
| 463 | configinfo.EmailUserEvents = Disabled;
|
---|
| 464 | } else {
|
---|
| 465 | // if MailServer isn't set it should default to mail.maintainer-domain
|
---|
| 466 | if (configinfo.MailServer.empty()) {
|
---|
[1778] | 467 | configinfo.MailServer = "mail." + substr (maintainer_here+1, maintainer_end);
|
---|
[1762] | 468 | }
|
---|
| 469 | }
|
---|
| 470 |
|
---|
[165] | 471 | // init the actions
|
---|
| 472 | actionptrmap::iterator actionhere = actions.begin ();
|
---|
| 473 | actionptrmap::iterator actionend = actions.end ();
|
---|
| 474 | while (actionhere != actionend) {
|
---|
| 475 | if (((*actionhere).second.a == NULL) ||
|
---|
| 476 | !(*actionhere).second.a->init(logout)) return false;
|
---|
| 477 | actionhere++;
|
---|
| 478 | }
|
---|
| 479 |
|
---|
| 480 | // init the protocols
|
---|
| 481 | recptprotolistclass::iterator protohere = protocols.begin ();
|
---|
| 482 | recptprotolistclass::iterator protoend = protocols.end ();
|
---|
| 483 | while (protohere != protoend) {
|
---|
[2113] | 484 | comerror_t err;
|
---|
[165] | 485 | if (((*protohere).p == NULL) ||
|
---|
[2113] | 486 | !(*protohere).p->init(err, logout)) return false;
|
---|
[165] | 487 | protohere++;
|
---|
| 488 | }
|
---|
| 489 |
|
---|
[649] | 490 | // init the browsers
|
---|
| 491 | browserptrmap::iterator browserhere = browsers.begin ();
|
---|
| 492 | browserptrmap::iterator browserend = browsers.end ();
|
---|
| 493 | while (browserhere != browserend) {
|
---|
| 494 | if (((*browserhere).second.b == NULL) ||
|
---|
| 495 | !(*browserhere).second.b->init(logout)) return false;
|
---|
| 496 | browserhere++;
|
---|
| 497 | }
|
---|
| 498 |
|
---|
[146] | 499 | return true;
|
---|
[108] | 500 | }
|
---|
| 501 |
|
---|
[1856] | 502 | // get the default encoding for the given language - if it fails for any
|
---|
| 503 | // reason return ""
|
---|
| 504 | text_t receptionist::get_default_encoding (const text_t &language) {
|
---|
| 505 |
|
---|
| 506 | // make sure language is valid
|
---|
| 507 | if (configinfo.languages.find(language) == configinfo.languages.end()) return "";
|
---|
[108] | 508 |
|
---|
[1856] | 509 | text_t default_encoding = configinfo.languages[language].defaultencoding;
|
---|
| 510 |
|
---|
| 511 | // make sure the encoding is valid
|
---|
[1870] | 512 | if (converters.find(default_encoding) == converters.end()) return "";
|
---|
[1856] | 513 |
|
---|
| 514 | return default_encoding;
|
---|
| 515 | }
|
---|
| 516 |
|
---|
[155] | 517 | // parse_cgi_args parses cgi arguments into an argument class.
|
---|
| 518 | // This function should be called for each page request. It returns false
|
---|
| 519 | // if there was a major problem with the cgi arguments.
|
---|
| 520 | bool receptionist::parse_cgi_args (const text_t &argstr, cgiargsclass &args,
|
---|
[864] | 521 | ostream &logout, text_tmap &fcgienv) {
|
---|
[155] | 522 |
|
---|
| 523 | // get an initial list of cgi arguments
|
---|
| 524 | args.clear();
|
---|
[776] | 525 | split_cgi_args (argsinfo, argstr, args);
|
---|
[155] | 526 |
|
---|
| 527 | // expand the compressed argument (if there was one)
|
---|
[165] | 528 | if (!expand_save_args (argsinfo, configinfo.saveconf, args, logout)) return false;
|
---|
[155] | 529 |
|
---|
| 530 | // add the defaults
|
---|
| 531 | add_default_args (argsinfo, args, logout);
|
---|
| 532 |
|
---|
[463] | 533 | // get the cookie
|
---|
[864] | 534 | if (configinfo.usecookies) get_cookie(args["z"], fcgienv);
|
---|
[362] | 535 |
|
---|
[1856] | 536 | // if we're changing languages, set the encoding to the default for the new language
|
---|
| 537 | if (args["nl"] == "1") {
|
---|
| 538 | args["nw"] = get_default_encoding(args["l"]);
|
---|
| 539 | }
|
---|
| 540 |
|
---|
[362] | 541 | // get the input encoding
|
---|
[1856] | 542 | // if encoding isn't set, set it to the default for the current language
|
---|
| 543 | if ((args.getarg("w") == NULL) || args["w"].empty()) {
|
---|
| 544 | args["w"] = get_default_encoding(args["l"]);
|
---|
| 545 | }
|
---|
| 546 |
|
---|
[362] | 547 | text_t &arg_w = args["w"];
|
---|
[1856] | 548 |
|
---|
[362] | 549 | inconvertclass defaultinconvert;
|
---|
| 550 | inconvertclass *inconvert = converters.get_inconverter (arg_w);
|
---|
| 551 | if (inconvert == NULL) inconvert = &defaultinconvert;
|
---|
| 552 |
|
---|
| 553 | // see if the next page will have a different encoding
|
---|
| 554 | if (args.getarg("nw") != NULL) arg_w = args["nw"];
|
---|
| 555 |
|
---|
| 556 | // convert arguments which aren't in unicode to unicode
|
---|
| 557 | args_tounicode (args, *inconvert);
|
---|
| 558 |
|
---|
| 559 |
|
---|
| 560 | // decide on the output conversion class (needed for checking the external
|
---|
| 561 | // cgi arguments)
|
---|
| 562 | rzwsoutconvertclass defaultoutconverter;
|
---|
| 563 | rzwsoutconvertclass *outconverter = converters.get_outconverter (arg_w);
|
---|
| 564 | if (outconverter == NULL) outconverter = &defaultoutconverter;
|
---|
| 565 | outconverter->reset();
|
---|
| 566 |
|
---|
[155] | 567 | // check the main cgi arguments
|
---|
| 568 | if (!check_mainargs (args, logout)) return false;
|
---|
| 569 |
|
---|
| 570 | // check the arguments for the action
|
---|
| 571 | action *a = actions.getaction (args["a"]);
|
---|
| 572 | if (a != NULL) {
|
---|
[261] | 573 | if (!a->check_cgiargs (argsinfo, args, logout)) return false;
|
---|
[155] | 574 | } else {
|
---|
| 575 | // the action was not found!!
|
---|
[1856] | 576 | outconvertclass text_t2ascii;
|
---|
[155] | 577 | logout << text_t2ascii << "Error: the action \"" << args["a"]
|
---|
| 578 | << "\" could not be found.\n";
|
---|
| 579 | return false;
|
---|
| 580 | }
|
---|
| 581 |
|
---|
[362] | 582 | // check external cgi arguments for each action
|
---|
| 583 | actionptrmap::iterator actionhere = actions.begin ();
|
---|
| 584 | actionptrmap::iterator actionend = actions.end ();
|
---|
| 585 | while (actionhere != actionend) {
|
---|
| 586 | assert ((*actionhere).second.a != NULL);
|
---|
| 587 | if ((*actionhere).second.a != NULL) {
|
---|
| 588 | if (!(*actionhere).second.a->check_external_cgiargs (argsinfo, args, *outconverter,
|
---|
| 589 | configinfo.saveconf, logout))
|
---|
| 590 | return false;
|
---|
| 591 | }
|
---|
| 592 | actionhere++;
|
---|
| 593 | }
|
---|
[165] | 594 |
|
---|
[362] | 595 | // the action might have changed but we will assume that
|
---|
| 596 | // the cgiargs were checked properly when the change was made
|
---|
[165] | 597 |
|
---|
[155] | 598 | return true;
|
---|
| 599 | }
|
---|
| 600 |
|
---|
[463] | 601 | // returns true if cookie already existed, false
|
---|
| 602 | // if it was generated
|
---|
[864] | 603 | bool receptionist::get_cookie (text_t &cookie, text_tmap &fcgienv) {
|
---|
[155] | 604 |
|
---|
[864] | 605 | text_t cookiestring = gsdl_getenv ("HTTP_COOKIE", fcgienv);
|
---|
[463] | 606 |
|
---|
[864] | 607 | text_t::const_iterator end = cookiestring.end();
|
---|
[2937] | 608 | text_t::const_iterator here = findchar ((text_t::const_iterator)cookiestring.begin(), end, 'G');
|
---|
[864] | 609 |
|
---|
| 610 | while (here+9 < end) {
|
---|
[463] | 611 |
|
---|
| 612 | if (substr(here, here+8) == "GSDL_UID") {
|
---|
| 613 | cookie = substr (here+9, findchar (here+9, end, ';'));
|
---|
| 614 | return true;
|
---|
| 615 | }
|
---|
[2937] | 616 | here = findchar ((text_t::const_iterator)cookiestring.begin(), end, 'G');
|
---|
[463] | 617 | }
|
---|
| 618 |
|
---|
[526] | 619 | cookie.clear();
|
---|
[864] | 620 | text_t host = gsdl_getenv("REMOTE_ADDR", fcgienv);
|
---|
[463] | 621 | time_t ttime = time(NULL);
|
---|
[864] | 622 | if (!host.empty()) {
|
---|
[463] | 623 | cookie += host;
|
---|
| 624 | cookie.push_back ('-');
|
---|
| 625 | }
|
---|
| 626 | cookie += text_t(ttime);
|
---|
| 627 |
|
---|
| 628 | return false;
|
---|
| 629 | }
|
---|
| 630 |
|
---|
| 631 | // as above but just tests if cookie exists
|
---|
[864] | 632 | bool receptionist::get_cookie (text_tmap &fcgienv) {
|
---|
[463] | 633 |
|
---|
[864] | 634 | text_t c = gsdl_getenv("HTTP_COOKIE", fcgienv);
|
---|
| 635 | if (!c.empty()) {
|
---|
[463] | 636 | text_t cookiestring = c;
|
---|
| 637 |
|
---|
| 638 | text_t::const_iterator end = cookiestring.end();
|
---|
[2937] | 639 | text_t::const_iterator here = findchar ((text_t::const_iterator)cookiestring.begin(), end, 'G');
|
---|
[864] | 640 |
|
---|
| 641 | while (here+9 < end) {
|
---|
| 642 | if (substr(here, here+8) == "GSDL_UID") return true;
|
---|
[2937] | 643 | here = findchar ((text_t::const_iterator)cookiestring.begin(), end, 'G');
|
---|
[864] | 644 | }
|
---|
[463] | 645 | }
|
---|
| 646 | return false;
|
---|
| 647 | }
|
---|
| 648 |
|
---|
[864] | 649 | bool receptionist::log_cgi_args (cgiargsclass &args, ostream &logout, text_tmap &fcgienv) {
|
---|
[463] | 650 |
|
---|
[526] | 651 | // see if we want to log the cgi arguments
|
---|
| 652 | if (!configinfo.logcgiargs) return true;
|
---|
| 653 |
|
---|
[864] | 654 | text_t host = gsdl_getenv ("REMOTE_HOST", fcgienv);
|
---|
[935] | 655 | text_t script_name = gsdl_getenv ("SCRIPT_NAME", fcgienv);
|
---|
[864] | 656 | if (host.empty()) host = gsdl_getenv ("REMOTE_ADDR", fcgienv);
|
---|
| 657 | text_t browser = gsdl_getenv ("HTTP_USER_AGENT", fcgienv);
|
---|
[463] | 658 |
|
---|
| 659 | cgiargsclass::const_iterator args_here = args.begin();
|
---|
| 660 | cgiargsclass::const_iterator args_end = args.end();
|
---|
| 661 |
|
---|
| 662 | text_t argstr;
|
---|
| 663 | bool first = true;
|
---|
| 664 | while (args_here != args_end) {
|
---|
| 665 | if (!first) argstr += ", ";
|
---|
| 666 | argstr += (*args_here).first + "=" + (*args_here).second.value;
|
---|
| 667 | first = false;
|
---|
| 668 | args_here ++;
|
---|
| 669 | }
|
---|
| 670 |
|
---|
[2212] | 671 | text_t logfile = filename_cat (configinfo.gdbmhome, "etc", "usage.txt");
|
---|
[595] | 672 |
|
---|
[935] | 673 | text_t logstr = script_name;
|
---|
| 674 | logstr += " " + host;
|
---|
[595] | 675 | logstr += " [";
|
---|
[1779] | 676 | if (configinfo.LogDateFormat == UTCTime) {
|
---|
| 677 | logstr += get_date (false);
|
---|
| 678 | } else if (configinfo.LogDateFormat == Absolute) {
|
---|
| 679 | time_t ttime = time(NULL);
|
---|
| 680 | logstr += ttime;
|
---|
| 681 | } else {
|
---|
| 682 | // LocalTime
|
---|
| 683 | logstr += get_date (true);
|
---|
| 684 | }
|
---|
[595] | 685 | logstr += "] (" + argstr + ") \"";
|
---|
| 686 | logstr += browser;
|
---|
| 687 | logstr += "\"\n";
|
---|
| 688 |
|
---|
| 689 | return append_logstr (logfile, logstr, logout);
|
---|
| 690 | }
|
---|
| 691 |
|
---|
| 692 | bool receptionist::append_logstr (const text_t &filename, const text_t &logstr,
|
---|
| 693 | ostream &logout) {
|
---|
| 694 |
|
---|
| 695 | utf8outconvertclass text_t2utf8;
|
---|
| 696 | char *lfile = filename.getcstr();
|
---|
[1170] | 697 |
|
---|
[3154] | 698 | int fd = open(lfile, O_WRONLY | O_APPEND);
|
---|
[463] | 699 |
|
---|
[3007] | 700 | if (fd == -1) {
|
---|
[463] | 701 | logout << "Error: Couldn't open file " << lfile << "\n";
|
---|
| 702 | delete lfile;
|
---|
| 703 | return false;
|
---|
[595] | 704 | }
|
---|
[463] | 705 |
|
---|
[595] | 706 | // lock_val is set to 0 if file is locked successfully
|
---|
| 707 | int lock_val = 1;
|
---|
[606] | 708 | GSDL_LOCK_FILE (fd);
|
---|
[595] | 709 | if (lock_val == 0) {
|
---|
[3036] | 710 | text_t tmp_log_str(logstr); // so we don't pass a const to setinput...
|
---|
| 711 | text_t2utf8.setinput(&tmp_log_str);
|
---|
[3007] | 712 | char *buffer=new char[logstr.size()];
|
---|
| 713 | size_t num_chars;
|
---|
| 714 | convertclass::status_t status;
|
---|
| 715 | text_t2utf8.convert(buffer, logstr.size(), num_chars, status);
|
---|
| 716 | // ignore status - assume it is "finished" as buffer is big enough
|
---|
| 717 | write(fd, buffer, num_chars);
|
---|
[606] | 718 | GSDL_UNLOCK_FILE (fd);
|
---|
[3007] | 719 | delete buffer;
|
---|
[606] | 720 | } else {
|
---|
[595] | 721 | logout << "Error: Couldn't lock file " << lfile << "\n";
|
---|
[3007] | 722 | close(fd);
|
---|
[606] | 723 | delete lfile;
|
---|
| 724 | return false;
|
---|
| 725 | }
|
---|
[595] | 726 |
|
---|
[3007] | 727 | close(fd);
|
---|
[463] | 728 |
|
---|
| 729 | delete lfile;
|
---|
| 730 | return true;
|
---|
| 731 | }
|
---|
| 732 |
|
---|
[799] | 733 | text_t receptionist::expandmacros (const text_t &astring, cgiargsclass &args,
|
---|
| 734 | ostream &logout) {
|
---|
| 735 | text_t outstring;
|
---|
| 736 | outconvertclass text_t2ascii;
|
---|
| 737 |
|
---|
| 738 | action *a = actions.getaction (args["a"]);
|
---|
| 739 | prepare_page (a, args, text_t2ascii, logout);
|
---|
| 740 | disp.expandstring ("Global", astring, outstring);
|
---|
| 741 | return outstring;
|
---|
| 742 | }
|
---|
| 743 |
|
---|
[155] | 744 | // produce_cgi_page will call get_cgihead_info and
|
---|
[145] | 745 | // produce_content in the appropriate way to output a cgi header and
|
---|
[155] | 746 | // the page content (if needed). If a page could not be created it
|
---|
| 747 | // will return false
|
---|
| 748 | bool receptionist::produce_cgi_page (cgiargsclass &args, ostream &contentout,
|
---|
[864] | 749 | ostream &logout, text_tmap &fcgienv) {
|
---|
[155] | 750 | outconvertclass text_t2ascii;
|
---|
[108] | 751 |
|
---|
[155] | 752 | response_t response;
|
---|
| 753 | text_t response_data;
|
---|
[108] | 754 |
|
---|
[155] | 755 | // produce cgi header
|
---|
[864] | 756 | get_cgihead_info (args, response, response_data, logout, fcgienv);
|
---|
[155] | 757 | if (response == location) {
|
---|
[769] | 758 | // location response (url may contain macros!!)
|
---|
[799] | 759 | response_data = expandmacros (response_data, args, logout);
|
---|
| 760 | contentout << text_t2ascii << "Location: " << response_data << "\n\n";
|
---|
[463] | 761 | contentout << flush;
|
---|
[155] | 762 | return true;
|
---|
| 763 | } else if (response == content) {
|
---|
| 764 | // content response
|
---|
[2386] | 765 |
|
---|
| 766 | // use the later of build.cfg and collect.cfg modification times
|
---|
[2608] | 767 | // as the Last-Modified: header, for caching values
|
---|
[2386] | 768 | struct stat file_info;
|
---|
| 769 | time_t latest=0;
|
---|
| 770 |
|
---|
| 771 | text_t collectname="";
|
---|
| 772 | collectname=args["c"];
|
---|
| 773 | if (collectname != "") {
|
---|
[2608] | 774 | text_t collectdir=filename_cat(configinfo.gsdlhome,"collect");
|
---|
| 775 | collectdir=filename_cat(collectdir,collectname);
|
---|
[2386] | 776 | text_t buildcfg=filename_cat(collectdir,"index");
|
---|
| 777 | buildcfg=filename_cat(buildcfg,"build.cfg");
|
---|
| 778 | char *buildcfg_ptr=buildcfg.getcstr();
|
---|
| 779 | text_t collectcfg=filename_cat(collectdir,"etc");
|
---|
| 780 | collectcfg=filename_cat(collectcfg,"collect.cfg");
|
---|
| 781 | char *collectcfg_ptr=collectcfg.getcstr();
|
---|
| 782 |
|
---|
| 783 | if (stat(buildcfg_ptr, &file_info)) {
|
---|
| 784 | // we got an error. Currently don't handle error :(
|
---|
| 785 | // logout <<
|
---|
| 786 | } else {
|
---|
| 787 | latest=file_info.st_mtime;
|
---|
| 788 | }
|
---|
| 789 |
|
---|
| 790 | if (stat(collectcfg_ptr, &file_info)) {
|
---|
| 791 | // error - unhandled for now
|
---|
| 792 | } else {
|
---|
| 793 | if (latest<file_info.st_mtime) latest=file_info.st_mtime;
|
---|
| 794 | }
|
---|
| 795 | delete buildcfg_ptr;
|
---|
| 796 | delete collectcfg_ptr;
|
---|
| 797 |
|
---|
| 798 | if (latest>0) {
|
---|
| 799 | // print out modified time, "DDD, dd MMM YYYY hh:mm:ss" format
|
---|
| 800 | // c library takes care of mem for this string... (has \n at end!!!!)
|
---|
[2660] | 801 | // latest is currently local time, convert to UTC.
|
---|
| 802 | struct tm* utc_latest;
|
---|
| 803 | utc_latest=gmtime(&latest);
|
---|
| 804 | contentout << "Last-Modified: " << asctime(utc_latest);
|
---|
[2386] | 805 | }
|
---|
[3007] | 806 | } // end of collection != ""
|
---|
[2386] | 807 |
|
---|
[2957] | 808 | /*
|
---|
| 809 | // This block of code should prevent the users browser from caching
|
---|
| 810 | // the page. It may be useful to uncomment this code and comment out
|
---|
| 811 | // that directly above (which sets a "Last-Modified" header) when
|
---|
| 812 | // doing interface development work where a given page may be
|
---|
| 813 | // changing often.
|
---|
| 814 |
|
---|
| 815 | contentout << "Expires: Mon, 26 Jul 1997 05:00:00 GMT\n"; // date in the past
|
---|
| 816 | tm *tm_ptr = NULL;
|
---|
| 817 | time_t t = time(NULL);
|
---|
| 818 | tm_ptr = gmtime (&t);
|
---|
| 819 | if (tm_ptr != NULL) {
|
---|
| 820 | char *timestr = new char[128];
|
---|
| 821 | strftime (timestr, 128, "%a, %d %b %Y %H:%M:%S", tm_ptr);
|
---|
| 822 | contentout << "Last-Modified: " << timestr << " GMT\n"; // always modified
|
---|
| 823 | delete timestr;
|
---|
| 824 | }
|
---|
| 825 | contentout << "Cache-Control: no-cache, must-revalidate\n"; // HTTP/1.1
|
---|
| 826 | contentout << "Pragma: no-cache\n"; // HTTP/1.0
|
---|
| 827 | */
|
---|
| 828 |
|
---|
[155] | 829 | contentout << text_t2ascii << "Content-type: " << response_data << "\n\n";
|
---|
| 830 | } else {
|
---|
| 831 | // unknown response
|
---|
| 832 | logout << "Error: get_cgihead_info returned an unknown response type.\n";
|
---|
| 833 | return false;
|
---|
| 834 | }
|
---|
| 835 |
|
---|
| 836 | // produce cgi page
|
---|
| 837 | if (!produce_content (args, contentout, logout)) return false;
|
---|
| 838 |
|
---|
| 839 | // flush contentout
|
---|
| 840 | contentout << flush;
|
---|
| 841 | return true;
|
---|
[108] | 842 | }
|
---|
| 843 |
|
---|
| 844 |
|
---|
[145] | 845 | // get_cgihead_info determines the cgi header information for
|
---|
| 846 | // a set of cgi arguments. If response contains location then
|
---|
| 847 | // response_data contains the redirect address. If reponse
|
---|
| 848 | // contains content then reponse_data contains the content-type.
|
---|
| 849 | // Note that images can now be produced by the receptionist.
|
---|
[146] | 850 | void receptionist::get_cgihead_info (cgiargsclass &args, response_t &response,
|
---|
[864] | 851 | text_t &response_data, ostream &logout,
|
---|
| 852 | text_tmap &fcgienv) {
|
---|
[155] | 853 | outconvertclass text_t2ascii;
|
---|
| 854 |
|
---|
| 855 | // get the action
|
---|
| 856 | action *a = actions.getaction (args["a"]);
|
---|
| 857 | if (a != NULL) {
|
---|
[760] | 858 | a->get_cgihead_info (args, &protocols, response, response_data, logout);
|
---|
[155] | 859 |
|
---|
| 860 | } else {
|
---|
| 861 | // the action was not found!!
|
---|
| 862 | logout << text_t2ascii << "Error receptionist::get_cgihead_info: the action \""
|
---|
| 863 | << args["a"] << "\" could not be found.\n";
|
---|
| 864 | response = content;
|
---|
| 865 | response_data = "text/html";
|
---|
| 866 | }
|
---|
[388] | 867 |
|
---|
| 868 | // add the encoding information
|
---|
| 869 | if (response == content) {
|
---|
[1870] | 870 | if (converters.find(args["w"]) != converters.end()) {
|
---|
| 871 | response_data += "; charset=" + args["w"];
|
---|
[388] | 872 | } else {
|
---|
[1856] | 873 | // default to latin 1
|
---|
| 874 | response_data += "; charset=ISO-8859-1";
|
---|
[388] | 875 | }
|
---|
[463] | 876 |
|
---|
| 877 | // add cookie if required
|
---|
[864] | 878 | if (configinfo.usecookies && !get_cookie(fcgienv))
|
---|
[463] | 879 | response_data += "\nSet-Cookie: GSDL_UID=" + args["z"]
|
---|
| 880 | + "; expires=25-Dec-37 00:00:00 GMT";
|
---|
[388] | 881 | }
|
---|
[108] | 882 | }
|
---|
| 883 |
|
---|
| 884 |
|
---|
[145] | 885 | // produce the page content
|
---|
[155] | 886 | bool receptionist::produce_content (cgiargsclass &args, ostream &contentout,
|
---|
[145] | 887 | ostream &logout) {
|
---|
[1170] | 888 |
|
---|
[155] | 889 | // decide on the output conversion class
|
---|
[165] | 890 | text_t &arg_w = args["w"];
|
---|
| 891 | rzwsoutconvertclass defaultoutconverter;
|
---|
| 892 | rzwsoutconvertclass *outconverter = converters.get_outconverter (arg_w);
|
---|
| 893 | if (outconverter == NULL) outconverter = &defaultoutconverter;
|
---|
| 894 | outconverter->reset();
|
---|
[155] | 895 |
|
---|
[799] | 896 |
|
---|
[760] | 897 | recptproto *collectproto = protocols.getrecptproto (args["c"], logout);
|
---|
| 898 | if (collectproto != NULL) {
|
---|
[669] | 899 | // get browsers to process OID
|
---|
| 900 | text_t OID = args["d"];
|
---|
| 901 | if (OID.empty()) OID = args["cl"];
|
---|
| 902 | if (!OID.empty()) {
|
---|
| 903 | text_tset metadata;
|
---|
| 904 | text_tarray OIDs;
|
---|
| 905 | OIDs.push_back (OID);
|
---|
| 906 | if (!is_top(OID)) OIDs.push_back (OID + ".pr");
|
---|
| 907 | FilterResponse_t response;
|
---|
| 908 | metadata.insert ("childtype");
|
---|
| 909 | if (get_info (OIDs, args["c"], metadata, false, collectproto, response, logout)) {
|
---|
[712] | 910 | text_t classifytype;
|
---|
[731] | 911 | if (!response.docInfo[0].metadata["childtype"].values[0].empty())
|
---|
| 912 | classifytype = response.docInfo[0].metadata["childtype"].values[0];
|
---|
| 913 | else if (!is_top (OID)) {
|
---|
| 914 | if (!response.docInfo[1].metadata["childtype"].values[0].empty())
|
---|
| 915 | classifytype = response.docInfo[1].metadata["childtype"].values[0];
|
---|
[712] | 916 | }
|
---|
[669] | 917 | browserclass *b = browsers.getbrowser (classifytype);
|
---|
| 918 | b->processOID (args, collectproto, logout);
|
---|
| 919 | }
|
---|
| 920 | }
|
---|
[760] | 921 |
|
---|
[712] | 922 | // translate "d" and "cl" arguments if required
|
---|
[669] | 923 | translate_OIDs (args, collectproto, logout);
|
---|
[649] | 924 | }
|
---|
[760] | 925 |
|
---|
[155] | 926 | // produce the page using the desired action
|
---|
| 927 | action *a = actions.getaction (args["a"]);
|
---|
| 928 | if (a != NULL) {
|
---|
[760] | 929 | if (a->uses_display(args)) prepare_page (a, args, (*outconverter), logout);
|
---|
| 930 | if (!a->do_action (args, &protocols, &browsers, disp, (*outconverter), contentout, logout))
|
---|
[155] | 931 | return false;
|
---|
| 932 | } else {
|
---|
| 933 | // the action was not found!!
|
---|
[165] | 934 | outconvertclass text_t2ascii;
|
---|
| 935 |
|
---|
[155] | 936 | logout << text_t2ascii << "Error receptionist::produce_content: the action \""
|
---|
| 937 | << args["a"] << "\" could not be found.\n";
|
---|
| 938 |
|
---|
[165] | 939 | contentout << (*outconverter)
|
---|
| 940 | << "<html>\n"
|
---|
| 941 | << "<head>\n"
|
---|
| 942 | << "<title>Error</title>\n"
|
---|
| 943 | << "</head>\n"
|
---|
| 944 | << "<body>\n"
|
---|
| 945 | << "<h2>Oops!</h2>\n"
|
---|
| 946 | << "Undefined Page. The action \""
|
---|
| 947 | << args["a"] << "\" could not be found.\n"
|
---|
| 948 | << "</body>\n"
|
---|
| 949 | << "</html>\n";
|
---|
[155] | 950 | }
|
---|
| 951 | return true;
|
---|
[108] | 952 | }
|
---|
| 953 |
|
---|
| 954 |
|
---|
[145] | 955 | // returns the compressed argument ("e") corresponding to the argument
|
---|
| 956 | // list. This can be used to save preferences between sessions.
|
---|
[362] | 957 | text_t receptionist::get_compressed_arg (cgiargsclass &args, ostream &logout) {
|
---|
| 958 | // decide on the output conversion class
|
---|
| 959 | text_t &arg_w = args["w"];
|
---|
| 960 | rzwsoutconvertclass defaultoutconverter;
|
---|
| 961 | rzwsoutconvertclass *outconverter = converters.get_outconverter (arg_w);
|
---|
| 962 | if (outconverter == NULL) outconverter = &defaultoutconverter;
|
---|
| 963 | outconverter->reset();
|
---|
| 964 |
|
---|
[248] | 965 | text_t compressed_args;
|
---|
| 966 | if (compress_save_args (argsinfo, configinfo.saveconf, args,
|
---|
[362] | 967 | compressed_args, *outconverter, logout))
|
---|
[248] | 968 | return compressed_args;
|
---|
[362] | 969 |
|
---|
| 970 | return "";
|
---|
[108] | 971 | }
|
---|
[155] | 972 |
|
---|
| 973 |
|
---|
| 974 | // will read in all the macro files. If one is not found an
|
---|
| 975 | // error message will be written to logout and the method will
|
---|
| 976 | // return false.
|
---|
| 977 | bool receptionist::read_macrofiles (ostream &logout) {
|
---|
| 978 | outconvertclass text_t2ascii;
|
---|
| 979 |
|
---|
| 980 | // redirect the error output to logout
|
---|
[789] | 981 | ostream *savedlogout = disp.setlogout (&logout);
|
---|
[155] | 982 |
|
---|
| 983 | // load up the default macro files, the collection directory
|
---|
| 984 | // is searched first for the file (if this is being used in
|
---|
[799] | 985 | // collection specific mode) and then the main directory(s)
|
---|
[165] | 986 | text_t colmacrodir = filename_cat (configinfo.collectdir, "macros");
|
---|
[799] | 987 |
|
---|
[1089] | 988 | text_tset maindirs;
|
---|
[165] | 989 | text_t gsdlmacrodir = filename_cat (configinfo.gsdlhome, "macros");
|
---|
[1089] | 990 | maindirs.insert (gsdlmacrodir);
|
---|
[799] | 991 | colinfo_tmap::iterator colhere = configinfo.collectinfo.begin();
|
---|
| 992 | colinfo_tmap::iterator colend = configinfo.collectinfo.end();
|
---|
| 993 | while (colhere != colend) {
|
---|
[1270] | 994 | if (!((*colhere).second.gsdl_gsdlhome).empty()) {
|
---|
| 995 | gsdlmacrodir = filename_cat ((*colhere).second.gsdl_gsdlhome, "macros");
|
---|
| 996 | maindirs.insert (gsdlmacrodir);
|
---|
| 997 | }
|
---|
[799] | 998 | colhere ++;
|
---|
| 999 | }
|
---|
| 1000 |
|
---|
| 1001 | text_tset::iterator arrhere = configinfo.macrofiles.begin();
|
---|
| 1002 | text_tset::iterator arrend = configinfo.macrofiles.end();
|
---|
[155] | 1003 | text_t filename;
|
---|
| 1004 | while (arrhere != arrend) {
|
---|
[799] | 1005 | bool foundfile = false;
|
---|
[155] | 1006 |
|
---|
| 1007 | // try in the collection directory if this is being
|
---|
| 1008 | // run in collection specific mode
|
---|
[165] | 1009 | if (!configinfo.collection.empty()) {
|
---|
[155] | 1010 | filename = filename_cat (colmacrodir, *arrhere);
|
---|
[799] | 1011 | if (file_exists (filename)) {
|
---|
| 1012 | disp.loaddefaultmacros(filename);
|
---|
| 1013 | foundfile = true;
|
---|
| 1014 | }
|
---|
[155] | 1015 | }
|
---|
| 1016 |
|
---|
| 1017 | // if we haven't found the macro file yet try in
|
---|
[799] | 1018 | // the main macro directory(s)
|
---|
| 1019 | // if file is found in more than one main directory
|
---|
| 1020 | // we'll load all copies
|
---|
| 1021 | if (!foundfile) {
|
---|
[1089] | 1022 | text_tset::const_iterator dirhere = maindirs.begin();
|
---|
| 1023 | text_tset::const_iterator dirend = maindirs.end();
|
---|
[799] | 1024 | while (dirhere != dirend) {
|
---|
| 1025 | filename = filename_cat (*dirhere, *arrhere);
|
---|
| 1026 | if (file_exists (filename)) {
|
---|
| 1027 | disp.loaddefaultmacros(filename);
|
---|
| 1028 | foundfile = true;
|
---|
| 1029 | }
|
---|
| 1030 | dirhere ++;
|
---|
| 1031 | }
|
---|
[155] | 1032 | }
|
---|
| 1033 |
|
---|
| 1034 | // see if we found the file or not
|
---|
[799] | 1035 | if (!foundfile) {
|
---|
[155] | 1036 | logout << text_t2ascii
|
---|
| 1037 | << "Error: the macro file \"" << *arrhere << "\" could not be found.\n";
|
---|
[165] | 1038 | if (configinfo.collection.empty()) {
|
---|
[799] | 1039 | text_t dirs;
|
---|
| 1040 | joinchar (maindirs, ", ", dirs);
|
---|
| 1041 | logout << text_t2ascii
|
---|
| 1042 | << "It should be in either of the following directories ("
|
---|
| 1043 | << dirs << ").\n\n";
|
---|
| 1044 |
|
---|
[155] | 1045 | } else {
|
---|
| 1046 | logout << text_t2ascii
|
---|
| 1047 | << "It should be in either " << colmacrodir << " or in "
|
---|
| 1048 | << gsdlmacrodir << ".\n\n";
|
---|
| 1049 | }
|
---|
[789] | 1050 | // reset logout to what it was
|
---|
| 1051 | disp.setlogout (savedlogout);
|
---|
[155] | 1052 | return false;
|
---|
| 1053 | }
|
---|
| 1054 | arrhere++;
|
---|
| 1055 | }
|
---|
| 1056 |
|
---|
| 1057 | // success
|
---|
[789] | 1058 |
|
---|
| 1059 | // reset logout to what it was
|
---|
| 1060 | disp.setlogout (savedlogout);
|
---|
[155] | 1061 | return true;
|
---|
| 1062 | }
|
---|
| 1063 |
|
---|
| 1064 |
|
---|
| 1065 | // check_mainargs will check all the main arguments. If a major
|
---|
| 1066 | // error is found it will return false and no cgi page should
|
---|
| 1067 | // be created using the arguments.
|
---|
[799] | 1068 | bool receptionist::check_mainargs (cgiargsclass &args, ostream &logout) {
|
---|
[155] | 1069 | // if this receptionist is running in collection dependant mode
|
---|
| 1070 | // then it should always set the collection argument to the
|
---|
| 1071 | // collection
|
---|
[165] | 1072 | if (!configinfo.collection.empty()) args["c"] = configinfo.collection;
|
---|
[155] | 1073 |
|
---|
[864] | 1074 | // if current collection uses ccscols make sure
|
---|
| 1075 | // "ccs" argument is set and make "cc" default to
|
---|
| 1076 | // all collections in "ccs"
|
---|
| 1077 | if (!args["c"].empty()) {
|
---|
| 1078 |
|
---|
| 1079 | text_t &arg_c = args["c"];
|
---|
| 1080 | recptproto *collectproto = protocols.getrecptproto (arg_c, logout);
|
---|
[1268] | 1081 | if (collectproto == NULL) {
|
---|
| 1082 | // oops, this collection isn't valid
|
---|
| 1083 | outconvertclass text_t2ascii;
|
---|
| 1084 | logout << text_t2ascii << "ERROR: Invalid collection: " << arg_c << "\n";
|
---|
| 1085 | args["c"].clear();
|
---|
[864] | 1086 |
|
---|
[1268] | 1087 | } else {
|
---|
| 1088 |
|
---|
[1270] | 1089 | ColInfoResponse_t *cinfo = get_collectinfo_ptr (collectproto, arg_c, logout);
|
---|
[1268] | 1090 |
|
---|
[1270] | 1091 | if (cinfo != NULL) {
|
---|
| 1092 | if (!cinfo->ccsCols.empty()) {
|
---|
| 1093 | args["ccs"] = 1;
|
---|
| 1094 | if (args["cc"].empty()) {
|
---|
| 1095 | text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
|
---|
| 1096 | text_tarray::const_iterator col_end = cinfo->ccsCols.end();
|
---|
| 1097 | bool first = true;
|
---|
| 1098 | while (col_here != col_end) {
|
---|
| 1099 | // make sure it's a valid collection
|
---|
| 1100 | if (protocols.getrecptproto (*col_here, logout) != NULL) {
|
---|
| 1101 | if (!first) args["cc"].push_back (',');
|
---|
| 1102 | args["cc"] += *col_here;
|
---|
| 1103 | first = false;
|
---|
| 1104 | }
|
---|
| 1105 | col_here ++;
|
---|
[1268] | 1106 | }
|
---|
[904] | 1107 | }
|
---|
[799] | 1108 | }
|
---|
[1270] | 1109 | } else {
|
---|
| 1110 | logout << "ERROR (receptionist::check_mainargs): get_collectinfo_ptr returned NULL\n";
|
---|
[799] | 1111 | }
|
---|
| 1112 | }
|
---|
| 1113 | }
|
---|
| 1114 |
|
---|
[155] | 1115 | // argument "v" can only be 0 or 1. Use the default value
|
---|
| 1116 | // if it is out of range
|
---|
| 1117 | int arg_v = args.getintarg ("v");
|
---|
| 1118 | if (arg_v != 0 && arg_v != 1) {
|
---|
| 1119 | cgiarginfo *vinfo = argsinfo.getarginfo ("v");
|
---|
| 1120 | if (vinfo != NULL) args["v"] = vinfo->argdefault;
|
---|
| 1121 | }
|
---|
| 1122 |
|
---|
| 1123 | // argument "f" can only be 0 or 1. Use the default value
|
---|
| 1124 | // if it is out of range
|
---|
| 1125 | int arg_f = args.getintarg ("f");
|
---|
| 1126 | if (arg_f != 0 && arg_f != 1) {
|
---|
| 1127 | cgiarginfo *finfo = argsinfo.getarginfo ("f");
|
---|
| 1128 | if (finfo != NULL) args["f"] = finfo->argdefault;
|
---|
| 1129 | }
|
---|
| 1130 |
|
---|
| 1131 | return true;
|
---|
| 1132 | }
|
---|
[173] | 1133 |
|
---|
[712] | 1134 | // translate_OIDs translates the "d" and "cl" arguments to their correct values
|
---|
[669] | 1135 | // if they use the tricky ".fc", ".lc" type syntax.
|
---|
[649] | 1136 | void receptionist::translate_OIDs (cgiargsclass &args, recptproto *collectproto,
|
---|
| 1137 | ostream &logout) {
|
---|
[438] | 1138 |
|
---|
| 1139 | FilterResponse_t response;
|
---|
| 1140 | FilterRequest_t request;
|
---|
| 1141 | comerror_t err;
|
---|
| 1142 | text_t &arg_d = args["d"];
|
---|
| 1143 | text_t &arg_cl = args["cl"];
|
---|
| 1144 | text_t &collection = args["c"];
|
---|
| 1145 |
|
---|
| 1146 | // do a call to translate OIDs if required
|
---|
| 1147 | request.filterName = "NullFilter";
|
---|
| 1148 | request.filterResultOptions = FROID;
|
---|
[649] | 1149 | if (!arg_d.empty() && needs_translating (arg_d)) {
|
---|
[468] | 1150 | request.docSet.push_back (arg_d);
|
---|
[438] | 1151 | collectproto->filter (collection, request, response, err, logout);
|
---|
| 1152 | arg_d = response.docInfo[0].OID;
|
---|
| 1153 | request.clear();
|
---|
| 1154 | }
|
---|
| 1155 | // we'll also check here that the "cl" argument has a "classify" doctype
|
---|
| 1156 | // (in case ".fc" or ".lc" have screwed up)
|
---|
| 1157 | if (needs_translating (arg_cl)) {
|
---|
[649] | 1158 | request.fields.insert ("doctype");
|
---|
[468] | 1159 | request.docSet.push_back (arg_cl);
|
---|
[438] | 1160 | request.filterResultOptions = FRmetadata;
|
---|
| 1161 | collectproto->filter (collection, request, response, err, logout);
|
---|
| 1162 | // set to original value (without .xx stuff) if doctype isn't "classify"
|
---|
[649] | 1163 | if (response.docInfo[0].metadata["doctype"].values[0] != "classify")
|
---|
[438] | 1164 | strip_suffix (arg_cl);
|
---|
| 1165 | else
|
---|
| 1166 | arg_cl = response.docInfo[0].OID;
|
---|
| 1167 | }
|
---|
| 1168 | }
|
---|
| 1169 |
|
---|
[456] | 1170 | // prepare_page sets up page parameters, sets display macros
|
---|
| 1171 | // and opens the page ready for output
|
---|
[760] | 1172 | void receptionist::prepare_page (action *a, cgiargsclass &args,
|
---|
| 1173 | outconvertclass &outconvert,
|
---|
| 1174 | ostream &logout) {
|
---|
[173] | 1175 | // set up page parameters
|
---|
| 1176 | text_t pageparams;
|
---|
| 1177 | bool first = true;
|
---|
[512] | 1178 |
|
---|
[530] | 1179 | text_tmap::iterator params_here = configinfo.pageparams.begin();
|
---|
| 1180 | text_tmap::iterator params_end = configinfo.pageparams.end();
|
---|
| 1181 | while (params_here != params_end) {
|
---|
| 1182 | if (args[(*params_here).first] != (*params_here).second) {
|
---|
| 1183 | if (!first) pageparams += ",";
|
---|
| 1184 | first = false;
|
---|
| 1185 | pageparams += (*params_here).first;
|
---|
| 1186 | pageparams += "=";
|
---|
| 1187 | pageparams += args[(*params_here).first];
|
---|
| 1188 | }
|
---|
| 1189 |
|
---|
| 1190 | params_here++;
|
---|
| 1191 | }
|
---|
| 1192 |
|
---|
[418] | 1193 |
|
---|
[173] | 1194 | // open the page
|
---|
[530] | 1195 | disp.openpage(pageparams, configinfo.macroprecedence);
|
---|
[173] | 1196 |
|
---|
| 1197 | // define external macros for each action
|
---|
| 1198 | actionptrmap::iterator actionhere = actions.begin ();
|
---|
| 1199 | actionptrmap::iterator actionend = actions.end ();
|
---|
| 1200 |
|
---|
| 1201 | while (actionhere != actionend) {
|
---|
| 1202 | assert ((*actionhere).second.a != NULL);
|
---|
[1860] | 1203 | if ((*actionhere).second.a != NULL) {
|
---|
[760] | 1204 | (*actionhere).second.a->define_external_macros (disp, args, &protocols, logout);
|
---|
[1860] | 1205 | }
|
---|
[173] | 1206 | actionhere++;
|
---|
| 1207 | }
|
---|
| 1208 |
|
---|
| 1209 | // define internal macros for the current action
|
---|
[760] | 1210 | a->define_internal_macros (disp, args, &protocols, logout);
|
---|
[512] | 1211 |
|
---|
| 1212 | // define general macros. the defining of general macros is done here so that
|
---|
| 1213 | // the last possible version of the cgi arguments are used
|
---|
[760] | 1214 | define_general_macros (args, outconvert, logout);
|
---|
[173] | 1215 | }
|
---|
| 1216 |
|
---|
[760] | 1217 | void receptionist::define_general_macros (cgiargsclass &args, outconvertclass &/*outconvert*/,
|
---|
| 1218 | ostream &logout) {
|
---|
[456] | 1219 |
|
---|
| 1220 | text_t &collection = args["c"];
|
---|
| 1221 |
|
---|
[1148] | 1222 | disp.setmacro ("gsdlhome", "Global", dm_safe(configinfo.gsdlhome));
|
---|
[173] | 1223 | disp.setmacro ("gwcgi", "Global", configinfo.gwcgi);
|
---|
| 1224 | disp.setmacro ("httpimg", "Global", configinfo.httpimg);
|
---|
[297] | 1225 | disp.setmacro ("httpprefix", "Global", configinfo.httpprefix);
|
---|
[1860] | 1226 |
|
---|
| 1227 | if (!collection.empty()) {
|
---|
| 1228 | // DB // ****
|
---|
| 1229 | ColInfoResponse_t cinfo;
|
---|
| 1230 | comerror_t err;
|
---|
| 1231 | recptproto *collectproto = protocols.getrecptproto (collection, logout);
|
---|
| 1232 | if (collectproto != NULL) {
|
---|
| 1233 | collectproto->get_collectinfo (collection, cinfo, err, logout);
|
---|
[1877] | 1234 | text_t httpcollection;
|
---|
| 1235 | if (!cinfo.httpdomain.empty()) httpcollection = "http://";
|
---|
| 1236 | httpcollection += cinfo.httpdomain + cinfo.httpprefix + "/collect/" + collection;
|
---|
[1860] | 1237 | disp.setmacro ("httpcollection", "Global", httpcollection);
|
---|
| 1238 | }
|
---|
| 1239 | }
|
---|
| 1240 |
|
---|
[864] | 1241 | text_t compressedoptions = get_compressed_arg(args, logout);
|
---|
[935] | 1242 | disp.setmacro ("compressedoptions", "Global", dm_safe(compressedoptions));
|
---|
[864] | 1243 | // need a decoded version of compressedoptions for use within forms
|
---|
| 1244 | // as browsers encode values from forms before sending to server
|
---|
| 1245 | // (e.g. %25 becomes %2525)
|
---|
| 1246 | decode_cgi_arg (compressedoptions);
|
---|
[935] | 1247 | disp.setmacro ("decodedcompressedoptions", "Global", dm_safe(compressedoptions));
|
---|
[173] | 1248 |
|
---|
[1305] | 1249 | #if defined (__WIN32__)
|
---|
| 1250 | disp.setmacro ("win32", "Global", "1");
|
---|
| 1251 | #endif
|
---|
| 1252 |
|
---|
[173] | 1253 | // set _cgiargX_ macros for each cgi argument
|
---|
| 1254 | cgiargsclass::const_iterator argshere = args.begin();
|
---|
| 1255 | cgiargsclass::const_iterator argsend = args.end();
|
---|
| 1256 | while (argshere != argsend) {
|
---|
[512] | 1257 | if (((*argshere).first == "q") ||
|
---|
| 1258 | ((*argshere).first == "qa") ||
|
---|
| 1259 | ((*argshere).first == "qtt") ||
|
---|
| 1260 | ((*argshere).first == "qty") ||
|
---|
| 1261 | ((*argshere).first == "qp") ||
|
---|
| 1262 | ((*argshere).first == "qpl") ||
|
---|
| 1263 | ((*argshere).first == "qr") ||
|
---|
| 1264 | ((*argshere).first == "q2"))
|
---|
[263] | 1265 | // need to escape special characters from query string
|
---|
[512] | 1266 | disp.setmacro ("cgiarg" + (*argshere).first,
|
---|
| 1267 | "Global", html_safe((*argshere).second.value));
|
---|
[263] | 1268 | else
|
---|
[935] | 1269 | disp.setmacro ("cgiarg" + (*argshere).first, "Global", dm_safe((*argshere).second.value));
|
---|
[173] | 1270 | argshere ++;
|
---|
| 1271 | }
|
---|
[456] | 1272 |
|
---|
[864] | 1273 | // display text right to left if language is arabic (and if browser can support it)
|
---|
| 1274 | if (args["l"] == "ar")
|
---|
| 1275 | disp.setmacro ("htmlextra", "Global", " dir=rtl");
|
---|
| 1276 |
|
---|
[456] | 1277 | // set collection specific macros
|
---|
[760] | 1278 | if (!collection.empty()) {
|
---|
| 1279 | recptproto *collectproto = protocols.getrecptproto (collection, logout);
|
---|
| 1280 | if (collectproto != NULL) {
|
---|
| 1281 | FilterResponse_t response;
|
---|
| 1282 | text_tset metadata;
|
---|
| 1283 | get_info ("collection", collection, metadata, false,
|
---|
| 1284 | collectproto, response, logout);
|
---|
| 1285 |
|
---|
| 1286 | if (!response.docInfo[0].metadata.empty()) {
|
---|
| 1287 | MetadataInfo_tmap::const_iterator here = response.docInfo[0].metadata.begin();
|
---|
| 1288 | MetadataInfo_tmap::const_iterator end = response.docInfo[0].metadata.end();
|
---|
| 1289 | while (here != end) {
|
---|
| 1290 | if (((*here).first != "haschildren") && ((*here).first != "hasnext") &&
|
---|
| 1291 | ((*here).first != "hasprevious")) {
|
---|
[2773] | 1292 | // check for args in form name:lang
|
---|
| 1293 | text_t name = "";
|
---|
| 1294 | text_t lang = "";
|
---|
| 1295 | bool colonfound=false;
|
---|
| 1296 | text_t::const_iterator a = (*here).first.begin();
|
---|
| 1297 | text_t::const_iterator b = (*here).first.end();
|
---|
| 1298 | while (a !=b) {
|
---|
| 1299 | if (*a==':') {
|
---|
| 1300 | colonfound=true;
|
---|
| 1301 | }
|
---|
| 1302 | else {
|
---|
| 1303 | if (colonfound)
|
---|
| 1304 | lang.push_back(*a);
|
---|
| 1305 | else name.push_back(*a);
|
---|
| 1306 | }
|
---|
| 1307 | a++;
|
---|
| 1308 | }
|
---|
| 1309 | if (!lang.empty()) {
|
---|
| 1310 | if (args["l"]==lang) {
|
---|
| 1311 | disp.setmacro (name, "Global", (*here).second.values[0]);
|
---|
| 1312 | }
|
---|
| 1313 | }
|
---|
| 1314 | else { // the default one
|
---|
| 1315 | disp.setmacro ((*here).first, "Global", (*here).second.values[0]);
|
---|
| 1316 | }
|
---|
[760] | 1317 | }
|
---|
| 1318 | here ++;
|
---|
[456] | 1319 | }
|
---|
| 1320 | }
|
---|
[1860] | 1321 |
|
---|
| 1322 | text_t iconcollection;
|
---|
| 1323 | disp.expandstring ("Global", "_iconcollection_", iconcollection);
|
---|
| 1324 | if (!iconcollection.empty())
|
---|
| 1325 | {
|
---|
[1877] | 1326 | ColInfoResponse_t cinfo;
|
---|
| 1327 | comerror_t err;
|
---|
| 1328 | collectproto->get_collectinfo (collection, cinfo, err, logout);
|
---|
| 1329 | if (iconcollection[0]=='/' && !cinfo.httpdomain.empty())
|
---|
[1860] | 1330 | {
|
---|
| 1331 | // local but with full path
|
---|
| 1332 | iconcollection = "http://" + cinfo.httpdomain + iconcollection;
|
---|
[1877] | 1333 | disp.setmacro("iconcollection", "Global", iconcollection);
|
---|
[1860] | 1334 | }
|
---|
| 1335 | }
|
---|
[456] | 1336 | }
|
---|
| 1337 | }
|
---|
[173] | 1338 | }
|
---|
[1270] | 1339 |
|
---|
| 1340 | // gets collection info from cache if found or
|
---|
| 1341 | // calls collection server (and updates cache)
|
---|
| 1342 | // returns NULL if there's an error
|
---|
| 1343 | ColInfoResponse_t *receptionist::get_collectinfo_ptr (recptproto *collectproto,
|
---|
| 1344 | const text_t &collection,
|
---|
| 1345 | ostream &logout) {
|
---|
| 1346 |
|
---|
| 1347 | // check the cache
|
---|
| 1348 | colinfo_tmap::iterator it = configinfo.collectinfo.find (collection);
|
---|
| 1349 | if ((it != configinfo.collectinfo.end()) && ((*it).second.info_loaded)) {
|
---|
| 1350 | // found it
|
---|
| 1351 | return &((*it).second.info);
|
---|
| 1352 | }
|
---|
| 1353 |
|
---|
| 1354 | // not cached, get info from collection server
|
---|
| 1355 | if (collectproto == NULL) {
|
---|
| 1356 | logout << "ERROR: receptionist::get_collectinfo_ptr passed null collectproto\n";
|
---|
| 1357 | return NULL;
|
---|
| 1358 | }
|
---|
| 1359 |
|
---|
| 1360 | comerror_t err;
|
---|
| 1361 | if (it == configinfo.collectinfo.end()) {
|
---|
| 1362 | collectioninfo_t cinfo;
|
---|
| 1363 | collectproto->get_collectinfo (collection, cinfo.info, err, logout);
|
---|
| 1364 | if (err != noError) {
|
---|
| 1365 | outconvertclass text_t2ascii;
|
---|
| 1366 | logout << text_t2ascii << "ERROR (receptionist::getcollectinfo_ptr): \""
|
---|
| 1367 | << get_comerror_string (err) << "\"while getting collectinfo\n";
|
---|
| 1368 | return NULL;
|
---|
| 1369 | }
|
---|
| 1370 | cinfo.info_loaded = true;
|
---|
| 1371 | configinfo.collectinfo[collection] = cinfo;
|
---|
| 1372 | return &(configinfo.collectinfo[collection].info);
|
---|
| 1373 | } else {
|
---|
| 1374 | collectproto->get_collectinfo (collection, (*it).second.info, err, logout);
|
---|
| 1375 | if (err != noError) {
|
---|
| 1376 | outconvertclass text_t2ascii;
|
---|
| 1377 | logout << text_t2ascii << "ERROR (receptionist::getcollectinfo_ptr): \""
|
---|
| 1378 | << get_comerror_string (err) << "\"while getting collectinfo\n";
|
---|
| 1379 | return NULL;
|
---|
| 1380 | }
|
---|
| 1381 | (*it).second.info_loaded = true;
|
---|
| 1382 | return &((*it).second.info);
|
---|
| 1383 | }
|
---|
| 1384 | }
|
---|
[1860] | 1385 |
|
---|
[2218] | 1386 | // removes a collection from the cache so that the next
|
---|
| 1387 | // call to get_collectinfo_ptr() for that collection will
|
---|
| 1388 | // retrieve the collection info from the collection server
|
---|
| 1389 | void receptionist::uncache_collection (const text_t &collection) {
|
---|
| 1390 |
|
---|
| 1391 | colinfo_tmap::iterator it = configinfo.collectinfo.find (collection);
|
---|
| 1392 | if ((it != configinfo.collectinfo.end()) && ((*it).second.info_loaded)) {
|
---|
| 1393 |
|
---|
| 1394 | (*it).second.info_loaded = false;
|
---|
| 1395 |
|
---|
| 1396 | }
|
---|
| 1397 | }
|
---|
| 1398 |
|
---|
[1870] | 1399 | // Handles an "Encoding" line from a configuration file - note that the
|
---|
| 1400 | // configinfo.encodings map is a bit of a hack (to be fixed when the
|
---|
| 1401 | // configuration files are tidied up).
|
---|
| 1402 | void receptionist::configure_encoding (const text_tarray &cfgline) {
|
---|
[1860] | 1403 |
|
---|
[1870] | 1404 | text_t subkey, subvalue, shortname, longname, mapfile;
|
---|
[1927] | 1405 | int multibyte = 0;
|
---|
[1870] | 1406 | text_t::const_iterator cfglinesub_here;
|
---|
| 1407 | text_tarray::const_iterator cfgline_here = cfgline.begin();
|
---|
| 1408 | text_tarray::const_iterator cfgline_end = cfgline.end();
|
---|
| 1409 | while (cfgline_here != cfgline_end) {
|
---|
[1927] | 1410 | if (*cfgline_here == "multibyte") {
|
---|
| 1411 | multibyte = 1;
|
---|
| 1412 | } else {
|
---|
| 1413 | cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
|
---|
| 1414 | (*cfgline_here).end(), '=', subkey);
|
---|
| 1415 | if (subkey == "shortname") {
|
---|
| 1416 | shortname = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
| 1417 | } else if (subkey == "longname") {
|
---|
| 1418 | longname = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
| 1419 | } else if (subkey == "map") {
|
---|
| 1420 | mapfile = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
| 1421 | }
|
---|
[1870] | 1422 | }
|
---|
| 1423 | cfgline_here++;
|
---|
| 1424 | }
|
---|
| 1425 | if (!shortname.empty()) {
|
---|
| 1426 | if (longname.empty()) longname = shortname;
|
---|
| 1427 |
|
---|
| 1428 | // add the converter
|
---|
| 1429 | if (shortname == "utf-8") {
|
---|
| 1430 | utf8inconvertclass *utf8inconvert = new utf8inconvertclass();
|
---|
| 1431 | utf8outconvertclass *utf8outconvert = new utf8outconvertclass();
|
---|
| 1432 | utf8outconvert->set_rzws(1);
|
---|
| 1433 | add_converter (shortname, utf8inconvert, utf8outconvert);
|
---|
| 1434 | configinfo.encodings[longname] = shortname;
|
---|
| 1435 |
|
---|
| 1436 | } else if (!mapfile.empty()) {
|
---|
| 1437 |
|
---|
| 1438 | if (mapfile == "8859_1.ump") {
|
---|
| 1439 | // iso-8859-1 is a special case as it'll always be supported by the
|
---|
| 1440 | // standard converter class and therefore doesn't need to use its
|
---|
| 1441 | // mapping file
|
---|
| 1442 | inconvertclass *inconvert = new inconvertclass();
|
---|
| 1443 | rzwsoutconvertclass *outconvert = new rzwsoutconvertclass();
|
---|
| 1444 | outconvert->set_rzws(1);
|
---|
| 1445 | add_converter (shortname, inconvert, outconvert);
|
---|
| 1446 | configinfo.encodings[longname] = shortname;
|
---|
| 1447 |
|
---|
| 1448 | } else {
|
---|
| 1449 | text_t to_uc_map = filename_cat(configinfo.gsdlhome, "mappings", "to_uc", mapfile);
|
---|
| 1450 | text_t from_uc_map = filename_cat(configinfo.gsdlhome, "mappings", "from_uc", mapfile);
|
---|
| 1451 | if (file_exists(to_uc_map) && file_exists(from_uc_map)) {
|
---|
| 1452 |
|
---|
| 1453 | mapinconvertclass *mapinconvert = new mapinconvertclass();
|
---|
| 1454 | mapinconvert->setmapfile (to_uc_map, 0x003F);
|
---|
[1927] | 1455 | mapinconvert->set_multibyte (multibyte);
|
---|
[1870] | 1456 | mapoutconvertclass *mapoutconvert = new mapoutconvertclass();
|
---|
| 1457 | mapoutconvert->setmapfile (from_uc_map, 0x3F);
|
---|
[1927] | 1458 | mapoutconvert->set_multibyte (multibyte);
|
---|
[1870] | 1459 | mapoutconvert->set_rzws(1);
|
---|
| 1460 | add_converter (shortname, mapinconvert, mapoutconvert);
|
---|
| 1461 | configinfo.encodings[longname] = shortname;
|
---|
| 1462 | }
|
---|
| 1463 | }
|
---|
| 1464 | }
|
---|
| 1465 | }
|
---|
| 1466 | }
|
---|