[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"
|
---|
[28888] | 38 | #include "securitytools.h"
|
---|
[108] | 39 | #include <assert.h>
|
---|
[150] | 40 | #include <time.h>
|
---|
[3007] | 41 | #include <stdio.h> // for open()
|
---|
| 42 | #include <fcntl.h> // for open() flags
|
---|
[2608] | 43 | // following 2 are for printing Last-Modified http header.
|
---|
[2386] | 44 | #include <sys/stat.h>
|
---|
| 45 | #include <time.h>
|
---|
| 46 |
|
---|
[1170] | 47 | #if defined (GSDL_USE_IOS_H)
|
---|
[463] | 48 | #include <fstream.h>
|
---|
[1170] | 49 | #else
|
---|
| 50 | #include <fstream>
|
---|
| 51 | #endif
|
---|
[108] | 52 |
|
---|
[526] | 53 | void recptconf::clear () {
|
---|
| 54 | gsdlhome.clear();
|
---|
[16310] | 55 | collecthome.clear();
|
---|
[15589] | 56 | dbhome.clear();
|
---|
[806] | 57 | collectinfo.erase(collectinfo.begin(), collectinfo.end());
|
---|
[526] | 58 | collection.clear();
|
---|
| 59 | collectdir.clear();
|
---|
| 60 | httpprefix.clear();
|
---|
[19109] | 61 | httpweb.clear();
|
---|
[526] | 62 | gwcgi.clear();
|
---|
| 63 | macrofiles.erase(macrofiles.begin(), macrofiles.end());
|
---|
| 64 | saveconf.clear();
|
---|
| 65 | usecookies = false;
|
---|
| 66 | logcgiargs = false;
|
---|
[1779] | 67 | LogDateFormat = LocalTime;
|
---|
[530] | 68 |
|
---|
[1762] | 69 | maintainer.clear();
|
---|
| 70 | MailServer.clear();
|
---|
| 71 | LogEvents = Disabled;
|
---|
| 72 | EmailEvents = Disabled;
|
---|
| 73 | EmailUserEvents = false;
|
---|
| 74 |
|
---|
[1856] | 75 | languages.erase(languages.begin(), languages.end());
|
---|
| 76 | encodings.erase(encodings.begin(), encodings.end());
|
---|
| 77 |
|
---|
[5018] | 78 | site_auth = false;
|
---|
[4905] | 79 | HomePageType = "images";
|
---|
| 80 | HomePageCols = 3;
|
---|
| 81 |
|
---|
[530] | 82 | // these default page parameters can always be overriden
|
---|
| 83 | // in the configuration file
|
---|
| 84 | pageparams.erase(pageparams.begin(), pageparams.end());
|
---|
| 85 | pageparams["c"] = "";
|
---|
| 86 | pageparams["l"] = "en";
|
---|
| 87 |
|
---|
| 88 | #ifdef MACROPRECEDENCE
|
---|
| 89 | macroprecedence = MACROPRECEDENCE;
|
---|
| 90 | #else
|
---|
| 91 | macroprecedence.clear();
|
---|
| 92 | #endif
|
---|
[526] | 93 | }
|
---|
| 94 |
|
---|
[19109] | 95 |
|
---|
[1270] | 96 | void collectioninfo_t::clear () {
|
---|
| 97 | gsdl_gsdlhome.clear();
|
---|
[15589] | 98 | gsdl_dbhome.clear();
|
---|
[526] | 99 |
|
---|
[1270] | 100 | info_loaded = false;
|
---|
| 101 | info.clear();
|
---|
| 102 | }
|
---|
[526] | 103 |
|
---|
[1856] | 104 | void languageinfo_t::clear () {
|
---|
| 105 | longname.clear();
|
---|
| 106 | defaultencoding.clear();
|
---|
| 107 | }
|
---|
| 108 |
|
---|
[388] | 109 | receptionist::receptionist () {
|
---|
| 110 | // create a list of cgi arguments
|
---|
| 111 | // this must be done before the configuration
|
---|
| 112 |
|
---|
| 113 | cgiarginfo ainfo;
|
---|
| 114 |
|
---|
| 115 | ainfo.shortname = "e";
|
---|
| 116 | ainfo.longname = "compressed arguments";
|
---|
| 117 | ainfo.multiplechar = true;
|
---|
| 118 | ainfo.defaultstatus = cgiarginfo::good;
|
---|
[7421] | 119 | ainfo.argdefault = g_EmptyText;
|
---|
[388] | 120 | ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 121 | argsinfo.addarginfo (NULL, ainfo);
|
---|
| 122 |
|
---|
| 123 | ainfo.shortname = "a";
|
---|
| 124 | ainfo.longname = "action";
|
---|
| 125 | ainfo.multiplechar = true;
|
---|
| 126 | ainfo.defaultstatus = cgiarginfo::none;
|
---|
[7421] | 127 | ainfo.argdefault = g_EmptyText;
|
---|
[388] | 128 | ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 129 | argsinfo.addarginfo (NULL, ainfo);
|
---|
| 130 |
|
---|
| 131 | // w=western
|
---|
| 132 | ainfo.shortname = "w";
|
---|
| 133 | ainfo.longname = "encoding";
|
---|
| 134 | ainfo.multiplechar = true;
|
---|
[1856] | 135 | ainfo.defaultstatus = cgiarginfo::none;
|
---|
[7421] | 136 | ainfo.argdefault = g_EmptyText;
|
---|
[388] | 137 | ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 138 | argsinfo.addarginfo (NULL, ainfo);
|
---|
| 139 |
|
---|
| 140 | ainfo.shortname = "nw";
|
---|
| 141 | ainfo.longname = "new encoding";
|
---|
| 142 | ainfo.multiplechar = true;
|
---|
| 143 | ainfo.defaultstatus = cgiarginfo::none;
|
---|
[7421] | 144 | ainfo.argdefault = g_EmptyText;
|
---|
[388] | 145 | ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 146 | argsinfo.addarginfo (NULL, ainfo);
|
---|
| 147 |
|
---|
| 148 | ainfo.shortname = "c";
|
---|
| 149 | ainfo.longname = "collection";
|
---|
| 150 | ainfo.multiplechar = true;
|
---|
| 151 | ainfo.defaultstatus = cgiarginfo::none;
|
---|
[7421] | 152 | ainfo.argdefault = g_EmptyText;
|
---|
[388] | 153 | ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 154 | argsinfo.addarginfo (NULL, ainfo);
|
---|
| 155 |
|
---|
| 156 | // the interface language name should use the ISO 639
|
---|
| 157 | // standard
|
---|
| 158 | ainfo.shortname = "l";
|
---|
| 159 | ainfo.longname = "interface language";
|
---|
| 160 | ainfo.multiplechar = true;
|
---|
| 161 | ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 162 | ainfo.argdefault = "en";
|
---|
| 163 | ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 164 | argsinfo.addarginfo (NULL, ainfo);
|
---|
[1856] | 165 |
|
---|
| 166 | ainfo.shortname = "nl";
|
---|
| 167 | ainfo.longname = "new language";
|
---|
| 168 | ainfo.multiplechar = false;
|
---|
| 169 | ainfo.defaultstatus = cgiarginfo::none;
|
---|
| 170 | ainfo.argdefault = "0";
|
---|
| 171 | ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 172 | argsinfo.addarginfo (NULL, ainfo);
|
---|
| 173 |
|
---|
[463] | 174 | // the GSDL_UID (cookie)
|
---|
| 175 | ainfo.shortname = "z";
|
---|
| 176 | ainfo.longname = "gsdl uid";
|
---|
| 177 | ainfo.multiplechar = true;
|
---|
| 178 | ainfo.defaultstatus = cgiarginfo::none;
|
---|
[7421] | 179 | ainfo.argdefault = g_EmptyText;
|
---|
[463] | 180 | ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 181 | argsinfo.addarginfo (NULL, ainfo);
|
---|
[530] | 182 | }
|
---|
[463] | 183 |
|
---|
[530] | 184 |
|
---|
| 185 | void receptionist::add_action (action *theaction) {
|
---|
| 186 | // make sure we have an action to add
|
---|
| 187 | if (theaction == NULL) return;
|
---|
| 188 |
|
---|
| 189 | // add this action to the list of actions
|
---|
| 190 | actions.addaction(theaction);
|
---|
| 191 |
|
---|
| 192 | // add the cgi arguments from this action
|
---|
[12509] | 193 | argsinfo.addarginfo (NULL, *(theaction->getargsinfo()));
|
---|
[388] | 194 | }
|
---|
| 195 |
|
---|
| 196 |
|
---|
[649] | 197 | void receptionist::add_browser (browserclass *thebrowser) {
|
---|
| 198 | // make sure we have a browser to add
|
---|
| 199 | if (thebrowser == NULL) return;
|
---|
| 200 |
|
---|
| 201 | // add this browser to the list of browsers
|
---|
| 202 | browsers.addbrowser(thebrowser);
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 |
|
---|
| 206 | void receptionist::setdefaultbrowser (const text_t &browsername) {
|
---|
| 207 | browsers.setdefaultbrowser (browsername);
|
---|
| 208 | }
|
---|
| 209 |
|
---|
| 210 |
|
---|
[165] | 211 | // configure should be called for each line in the
|
---|
| 212 | // configuration files to configure the receptionist and everything
|
---|
| 213 | // it contains. The configuration should take place after everything
|
---|
| 214 | // has been added but before the initialisation.
|
---|
[5017] | 215 |
|
---|
[165] | 216 | void receptionist::configure (const text_t &key, const text_tarray &cfgline) {
|
---|
| 217 | // configure the receptionist
|
---|
[1870] | 218 |
|
---|
[5017] | 219 |
|
---|
| 220 |
|
---|
[165] | 221 | if (cfgline.size() >= 1) {
|
---|
[388] | 222 | cgiarginfo *info = NULL;
|
---|
[2561] | 223 | if (key == "gsdlhome") {
|
---|
| 224 | configinfo.gsdlhome = cfgline[0];
|
---|
[15589] | 225 | if (configinfo.dbhome.empty()) configinfo.dbhome = cfgline[0];
|
---|
[2561] | 226 | }
|
---|
[16310] | 227 | else if (key == "collecthome") configinfo.collecthome = cfgline[0];
|
---|
[15589] | 228 | else if (key == "gdbmhome") configinfo.dbhome = cfgline[0];
|
---|
[388] | 229 | else if (key == "collection") {
|
---|
| 230 | configinfo.collection = cfgline[0];
|
---|
| 231 | // also need to set the default arg to this collection
|
---|
| 232 | if ((info = argsinfo.getarginfo("c")) != NULL) {
|
---|
| 233 | info->defaultstatus = cgiarginfo::good;
|
---|
| 234 | info->argdefault = cfgline[0];
|
---|
| 235 | }
|
---|
| 236 |
|
---|
[16310] | 237 | }
|
---|
| 238 | else if (key == "collectdir") configinfo.collectdir = cfgline[0];
|
---|
[297] | 239 | else if (key == "httpprefix") configinfo.httpprefix = cfgline[0];
|
---|
[19109] | 240 | else if (key == "httpweb") configinfo.httpweb = cfgline[0];
|
---|
[165] | 241 | else if (key == "gwcgi") configinfo.gwcgi = cfgline[0];
|
---|
[799] | 242 | else if (key == "macrofiles") {
|
---|
| 243 | // want to append to macrofiles (i.e. may be several config files
|
---|
| 244 | // contributing, maybe from several collections).
|
---|
| 245 | text_tarray::const_iterator here = cfgline.begin();
|
---|
| 246 | text_tarray::const_iterator end = cfgline.end();
|
---|
| 247 | while (here != end) {
|
---|
| 248 | configinfo.macrofiles.insert (*here);
|
---|
[7443] | 249 | ++here;
|
---|
[799] | 250 | }
|
---|
| 251 | }
|
---|
[165] | 252 | else if (key == "saveconf") configinfo.saveconf = cfgline[0];
|
---|
[526] | 253 | else if (key == "usecookies") configinfo.usecookies = (cfgline[0] == "true");
|
---|
| 254 | else if (key == "logcgiargs") configinfo.logcgiargs = (cfgline[0] == "true");
|
---|
[1762] | 255 | else if (key == "maintainer") configinfo.maintainer = cfgline[0];
|
---|
| 256 | else if (key == "MailServer") configinfo.MailServer = cfgline[0];
|
---|
[1779] | 257 | else if (key == "LogDateFormat") {
|
---|
| 258 | if (cfgline[0] == "UTCTime") configinfo.LogDateFormat = UTCTime;
|
---|
| 259 | else if (cfgline[0] == "Absolute") configinfo.LogDateFormat = Absolute;
|
---|
| 260 | }
|
---|
[1762] | 261 | else if (key == "LogEvents") {
|
---|
| 262 | if (cfgline[0] == "CollectorEvents") configinfo.LogEvents = CollectorEvents;
|
---|
| 263 | else if (cfgline[0] == "AllEvents") configinfo.LogEvents = AllEvents;
|
---|
| 264 | }
|
---|
| 265 | else if (key == "EmailEvents") {
|
---|
| 266 | if (cfgline[0] == "CollectorEvents") configinfo.EmailEvents = CollectorEvents;
|
---|
| 267 | else if (cfgline[0] == "AllEvents") configinfo.EmailEvents = AllEvents;
|
---|
| 268 | }
|
---|
| 269 | else if (key == "EmailUserEvents") configinfo.EmailUserEvents = (cfgline[0] == "true");
|
---|
[530] | 270 | else if (key == "pageparam") {
|
---|
| 271 | if (cfgline.size() >= 2) configinfo.pageparams[cfgline[0]] = cfgline[1];
|
---|
| 272 | else configinfo.pageparams[cfgline[0]] = "";
|
---|
| 273 | }
|
---|
| 274 | else if (key == "macroprecedence") configinfo.macroprecedence = cfgline[0];
|
---|
[799] | 275 | else if (key == "collectinfo") {
|
---|
[16310] | 276 | if (cfgline.size() == 3) {
|
---|
| 277 | // for backwards compatability with older collections that only use
|
---|
| 278 | // gsdlhome and dbhome
|
---|
[799] | 279 | collectioninfo_t cinfo;
|
---|
| 280 | cinfo.gsdl_gsdlhome = cfgline[1];
|
---|
[16310] | 281 | cinfo.gsdl_collecthome = filename_cat(cfgline[1],"collect");
|
---|
[15589] | 282 | cinfo.gsdl_dbhome = cfgline[2];
|
---|
[799] | 283 | configinfo.collectinfo[cfgline[0]] = cinfo;
|
---|
| 284 | }
|
---|
[16310] | 285 | else if (cfgline.size() >= 4) {
|
---|
| 286 | collectioninfo_t cinfo;
|
---|
| 287 | cinfo.gsdl_gsdlhome = cfgline[1];
|
---|
| 288 | cinfo.gsdl_collecthome = cfgline[2];
|
---|
| 289 | cinfo.gsdl_dbhome = cfgline[3];
|
---|
| 290 | configinfo.collectinfo[cfgline[0]] = cinfo;
|
---|
| 291 | }
|
---|
[799] | 292 | }
|
---|
[4905] | 293 |
|
---|
[5017] | 294 | // Read in the value for the site_auth directive either true or false
|
---|
| 295 | else if (key == "site_auth") configinfo.site_auth = (cfgline[0] == "true");
|
---|
| 296 |
|
---|
| 297 | else if (key == "site_group")
|
---|
| 298 | joinchar(cfgline,',',configinfo.site_group);
|
---|
| 299 |
|
---|
[4905] | 300 | else if (key == "SiteFormat") {
|
---|
| 301 | if (cfgline[0] == "HomePageType") {
|
---|
| 302 | configinfo.HomePageType = cfgline[1];
|
---|
| 303 | } else if (cfgline[0] == "HomePageCols") {
|
---|
| 304 | configinfo.HomePageCols = cfgline[1].getint();
|
---|
| 305 | }
|
---|
| 306 | }
|
---|
| 307 |
|
---|
[530] | 308 | else if (key == "cgiarg") {
|
---|
| 309 | // get shortname
|
---|
| 310 | bool seen_defaultstatus = false;
|
---|
| 311 | text_t subkey, subvalue;
|
---|
| 312 | text_t shortname;
|
---|
| 313 | text_t::const_iterator cfglinesub_here;
|
---|
| 314 | text_tarray::const_iterator cfgline_here = cfgline.begin();
|
---|
| 315 | text_tarray::const_iterator cfgline_end = cfgline.end();
|
---|
| 316 | while (cfgline_here != cfgline_end) {
|
---|
| 317 | cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
|
---|
| 318 | (*cfgline_here).end(), '=', subkey);
|
---|
| 319 | if (subkey == "shortname") {
|
---|
| 320 | shortname = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
| 321 | }
|
---|
[7443] | 322 | ++cfgline_here;
|
---|
[388] | 323 | }
|
---|
[530] | 324 |
|
---|
| 325 | // if we found the shortname process the line again filling in values
|
---|
| 326 | if (!shortname.empty()) {
|
---|
| 327 | cgiarginfo &chinfo = argsinfo[shortname];
|
---|
| 328 | chinfo.shortname = shortname; // in case this is a new argument
|
---|
| 329 |
|
---|
| 330 | cfgline_here = cfgline.begin();
|
---|
| 331 | while (cfgline_here != cfgline_end) {
|
---|
| 332 | cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
|
---|
| 333 | (*cfgline_here).end(), '=', subkey);
|
---|
| 334 | subvalue = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
| 335 |
|
---|
| 336 | if (subkey == "longname") chinfo.longname = subvalue;
|
---|
| 337 | else if (subkey == "multiplechar") chinfo.multiplechar = (subvalue == "true");
|
---|
[22196] | 338 | else if (subkey == "multiplevalue") chinfo.multiplevalue = (subvalue == "true");
|
---|
[530] | 339 | else if (subkey == "defaultstatus") {
|
---|
| 340 | seen_defaultstatus = true;
|
---|
| 341 | if (subvalue == "none") chinfo.defaultstatus = cgiarginfo::none;
|
---|
| 342 | else if (subvalue == "weak") chinfo.defaultstatus = cgiarginfo::weak;
|
---|
| 343 | else if (subvalue == "good") chinfo.defaultstatus = cgiarginfo::good;
|
---|
| 344 | else if (subvalue == "config") chinfo.defaultstatus = cgiarginfo::config;
|
---|
| 345 | else if (subvalue == "imperative") chinfo.defaultstatus = cgiarginfo::imperative;
|
---|
| 346 | }
|
---|
| 347 | else if (subkey == "argdefault") {
|
---|
| 348 | chinfo.argdefault = subvalue;
|
---|
| 349 | if (!seen_defaultstatus) chinfo.defaultstatus = cgiarginfo::config;
|
---|
| 350 | }
|
---|
| 351 | else if (subkey == "savedarginfo") {
|
---|
| 352 | if (subvalue == "mustnot") chinfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 353 | else if (subvalue == "can") chinfo.savedarginfo = cgiarginfo::can;
|
---|
| 354 | else if (subvalue == "must") chinfo.savedarginfo = cgiarginfo::must;
|
---|
| 355 | }
|
---|
| 356 |
|
---|
[7443] | 357 | ++cfgline_here;
|
---|
[530] | 358 | }
|
---|
| 359 | }
|
---|
[1856] | 360 |
|
---|
| 361 | } else if (key == "Encoding") {
|
---|
| 362 |
|
---|
[1870] | 363 | configure_encoding (cfgline);
|
---|
| 364 |
|
---|
[1856] | 365 | } else if (key == "Language") {
|
---|
[1870] | 366 | text_t subkey, subvalue, shortname;
|
---|
| 367 | languageinfo_t lang;
|
---|
[1856] | 368 | text_t::const_iterator cfglinesub_here;
|
---|
| 369 | text_tarray::const_iterator cfgline_here = cfgline.begin();
|
---|
| 370 | text_tarray::const_iterator cfgline_end = cfgline.end();
|
---|
| 371 | while (cfgline_here != cfgline_end) {
|
---|
| 372 | cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
|
---|
| 373 | (*cfgline_here).end(), '=', subkey);
|
---|
| 374 | if (subkey == "shortname") {
|
---|
| 375 | shortname = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
| 376 | } else if (subkey == "longname") {
|
---|
[1870] | 377 | lang.longname = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
[1856] | 378 | } else if (subkey == "default_encoding") {
|
---|
[1870] | 379 | lang.defaultencoding = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
[1856] | 380 | }
|
---|
[7443] | 381 | ++cfgline_here;
|
---|
[1856] | 382 | }
|
---|
| 383 | if (!shortname.empty()) {
|
---|
[1870] | 384 | if (lang.longname.empty()) lang.longname = shortname;
|
---|
[1856] | 385 | configinfo.languages[shortname] = lang;
|
---|
| 386 | }
|
---|
[388] | 387 | }
|
---|
[165] | 388 | }
|
---|
[530] | 389 |
|
---|
[165] | 390 | // configure the actions
|
---|
| 391 | actionptrmap::iterator actionhere = actions.begin ();
|
---|
| 392 | actionptrmap::iterator actionend = actions.end ();
|
---|
[108] | 393 |
|
---|
[165] | 394 | while (actionhere != actionend) {
|
---|
| 395 | assert ((*actionhere).second.a != NULL);
|
---|
| 396 | if ((*actionhere).second.a != NULL)
|
---|
| 397 | (*actionhere).second.a->configure(key, cfgline);
|
---|
[108] | 398 |
|
---|
[7421] | 399 | ++actionhere;
|
---|
[165] | 400 | }
|
---|
[108] | 401 |
|
---|
[165] | 402 | // configure the protocols
|
---|
| 403 | recptprotolistclass::iterator protohere = protocols.begin ();
|
---|
| 404 | recptprotolistclass::iterator protoend = protocols.end ();
|
---|
[108] | 405 |
|
---|
[165] | 406 | while (protohere != protoend) {
|
---|
| 407 | assert ((*protohere).p != NULL);
|
---|
[2113] | 408 | comerror_t err;
|
---|
[165] | 409 | if ((*protohere).p != NULL)
|
---|
[2113] | 410 | (*protohere).p->configure(key, cfgline, err);
|
---|
[165] | 411 |
|
---|
[7443] | 412 | ++protohere;
|
---|
[155] | 413 | }
|
---|
[649] | 414 |
|
---|
| 415 | // configure the browsers
|
---|
| 416 | browserptrmap::iterator browserhere = browsers.begin ();
|
---|
| 417 | browserptrmap::iterator browserend = browsers.end ();
|
---|
| 418 |
|
---|
| 419 | while (browserhere != browserend) {
|
---|
| 420 | assert ((*browserhere).second.b != NULL);
|
---|
| 421 | if ((*browserhere).second.b != NULL)
|
---|
| 422 | (*browserhere).second.b->configure(key, cfgline);
|
---|
| 423 |
|
---|
[7443] | 424 | ++browserhere;
|
---|
[649] | 425 | }
|
---|
[108] | 426 | }
|
---|
| 427 |
|
---|
[649] | 428 |
|
---|
[165] | 429 | void receptionist::configure (const text_t &key, const text_t &value) {
|
---|
| 430 | text_tarray cfgline;
|
---|
| 431 | cfgline.push_back (value);
|
---|
| 432 | configure(key, cfgline);
|
---|
| 433 | }
|
---|
| 434 |
|
---|
| 435 |
|
---|
[1870] | 436 | // init should be called after all the actions and protocols have been
|
---|
| 437 | // added to the receptionist and after everything has been configured but
|
---|
| 438 | // before any pages are created. It returns true on success and false on
|
---|
| 439 | // failure. If false is returned getpage should not be called (without
|
---|
| 440 | // producing meaningless output), instead an error page should be produced
|
---|
| 441 | // by the calling code.
|
---|
[150] | 442 | bool receptionist::init (ostream &logout) {
|
---|
[1870] | 443 |
|
---|
[165] | 444 | // first configure collectdir
|
---|
| 445 | if (!configinfo.collection.empty()) {
|
---|
[16310] | 446 |
|
---|
[165] | 447 | // collection specific mode
|
---|
[16310] | 448 |
|
---|
| 449 | text_t collectdir = configinfo.gsdlhome;
|
---|
| 450 |
|
---|
[165] | 451 | if (!configinfo.collectdir.empty()) {
|
---|
| 452 | // has already been configured
|
---|
[16310] | 453 | collectdir = configinfo.collectdir;
|
---|
[165] | 454 | } else {
|
---|
[16310] | 455 |
|
---|
[165] | 456 | // decide where collectdir is by searching for collect.cfg
|
---|
| 457 | // look in $GSDLHOME/collect/collection-name/etc/collect.cfg and
|
---|
| 458 | // then $GSDLHOME/etc/collect.cfg
|
---|
[16310] | 459 | collectdir = filename_cat (configinfo.gsdlhome, "collect");
|
---|
| 460 | collectdir = filename_cat (collectdir, configinfo.collection);
|
---|
| 461 | text_t filename = filename_cat (collectdir, "etc");
|
---|
[165] | 462 | filename = filename_cat (filename, "collect.cfg");
|
---|
[16310] | 463 |
|
---|
| 464 | if (!file_exists(filename)) collectdir = configinfo.gsdlhome;
|
---|
| 465 | }
|
---|
[418] | 466 |
|
---|
[16310] | 467 | configure("collectdir", collectdir);
|
---|
| 468 |
|
---|
[165] | 469 | }
|
---|
[16310] | 470 | else {
|
---|
[165] | 471 |
|
---|
[16310] | 472 | text_t collecthome;
|
---|
| 473 | if (configinfo.collecthome.empty()) {
|
---|
| 474 | collecthome = filename_cat(configinfo.gsdlhome,"collect");
|
---|
| 475 | }
|
---|
| 476 | else {
|
---|
| 477 | collecthome = configinfo.collecthome;
|
---|
| 478 | }
|
---|
| 479 |
|
---|
| 480 | configure("collecthome", collecthome);
|
---|
| 481 |
|
---|
| 482 | // for backwards compatability collectdir set to gsdlhome
|
---|
| 483 | // (possible it could now be removed)
|
---|
| 484 | configure("collectdir", configinfo.gsdlhome);
|
---|
| 485 | }
|
---|
| 486 |
|
---|
| 487 |
|
---|
[155] | 488 | // read in the macro files
|
---|
| 489 | if (!read_macrofiles (logout)) return false;
|
---|
[108] | 490 |
|
---|
[165] | 491 | // there must be at least one action defined
|
---|
| 492 | if (actions.empty()) {
|
---|
| 493 | logout << "Error: no actions have been added to the receptionist\n";
|
---|
| 494 | return false;
|
---|
| 495 | }
|
---|
| 496 |
|
---|
[649] | 497 | // there must be at least one browser defined
|
---|
| 498 | if (browsers.empty()) {
|
---|
| 499 | logout << "Error: no browsers have been added to the receptionist\n";
|
---|
| 500 | return false;
|
---|
| 501 | }
|
---|
| 502 |
|
---|
[155] | 503 | // create a saveconf string if there isn't one already
|
---|
[165] | 504 | if (configinfo.saveconf.empty())
|
---|
| 505 | configinfo.saveconf = create_save_conf_str (argsinfo, logout);
|
---|
[108] | 506 |
|
---|
[155] | 507 | // check the saveconf string
|
---|
[165] | 508 | if (!check_save_conf_str (configinfo.saveconf, argsinfo, logout))
|
---|
[155] | 509 | return false;
|
---|
| 510 |
|
---|
| 511 | // set a random seed
|
---|
| 512 | srand (time(NULL));
|
---|
| 513 |
|
---|
[1762] | 514 | // if maintainer email address is something dodgy (for now I'll define
|
---|
| 515 | // dodgy as being anything that doesn't contain '@') disable EmailEvents
|
---|
[1778] | 516 | // and EmailUserEvents (we don't strictly need to disable EmailUserEvents
|
---|
| 517 | // in this case but we will as it seems likely that MailServer will also
|
---|
| 518 | // be screwed up if maintainer is).
|
---|
[1762] | 519 | text_t::const_iterator maintainer_end = configinfo.maintainer.end ();
|
---|
[2937] | 520 | text_t::const_iterator maintainer_here = findchar ((text_t::const_iterator)configinfo.maintainer.begin(),
|
---|
[1762] | 521 | maintainer_end, '@');
|
---|
| 522 | if (maintainer_here == maintainer_end) {
|
---|
| 523 | configinfo.EmailEvents = Disabled;
|
---|
| 524 | configinfo.EmailUserEvents = Disabled;
|
---|
| 525 | } else {
|
---|
| 526 | // if MailServer isn't set it should default to mail.maintainer-domain
|
---|
| 527 | if (configinfo.MailServer.empty()) {
|
---|
[1778] | 528 | configinfo.MailServer = "mail." + substr (maintainer_here+1, maintainer_end);
|
---|
[1762] | 529 | }
|
---|
| 530 | }
|
---|
| 531 |
|
---|
[165] | 532 | // init the actions
|
---|
| 533 | actionptrmap::iterator actionhere = actions.begin ();
|
---|
| 534 | actionptrmap::iterator actionend = actions.end ();
|
---|
| 535 | while (actionhere != actionend) {
|
---|
| 536 | if (((*actionhere).second.a == NULL) ||
|
---|
| 537 | !(*actionhere).second.a->init(logout)) return false;
|
---|
[7421] | 538 | ++actionhere;
|
---|
[165] | 539 | }
|
---|
| 540 |
|
---|
| 541 | // init the protocols
|
---|
| 542 | recptprotolistclass::iterator protohere = protocols.begin ();
|
---|
| 543 | recptprotolistclass::iterator protoend = protocols.end ();
|
---|
| 544 | while (protohere != protoend) {
|
---|
[2113] | 545 | comerror_t err;
|
---|
[165] | 546 | if (((*protohere).p == NULL) ||
|
---|
[2113] | 547 | !(*protohere).p->init(err, logout)) return false;
|
---|
[7443] | 548 | ++protohere;
|
---|
[165] | 549 | }
|
---|
| 550 |
|
---|
[649] | 551 | // init the browsers
|
---|
| 552 | browserptrmap::iterator browserhere = browsers.begin ();
|
---|
| 553 | browserptrmap::iterator browserend = browsers.end ();
|
---|
| 554 | while (browserhere != browserend) {
|
---|
| 555 | if (((*browserhere).second.b == NULL) ||
|
---|
| 556 | !(*browserhere).second.b->init(logout)) return false;
|
---|
[7443] | 557 | ++browserhere;
|
---|
[649] | 558 | }
|
---|
| 559 |
|
---|
[146] | 560 | return true;
|
---|
[108] | 561 | }
|
---|
| 562 |
|
---|
[1856] | 563 | // get the default encoding for the given language - if it fails for any
|
---|
| 564 | // reason return ""
|
---|
| 565 | text_t receptionist::get_default_encoding (const text_t &language) {
|
---|
| 566 |
|
---|
| 567 | // make sure language is valid
|
---|
| 568 | if (configinfo.languages.find(language) == configinfo.languages.end()) return "";
|
---|
[108] | 569 |
|
---|
[1856] | 570 | text_t default_encoding = configinfo.languages[language].defaultencoding;
|
---|
| 571 |
|
---|
| 572 | // make sure the encoding is valid
|
---|
[10563] | 573 | if (converters.find(default_encoding) == converters.end()) {
|
---|
| 574 | // we don't support the encoding specified as default for this language
|
---|
| 575 | if (configinfo.encodings.size()==1) {
|
---|
| 576 | // only 1 encoding specified in main.cfg, so use it
|
---|
| 577 | return configinfo.encodings.begin()->second;
|
---|
| 578 | }
|
---|
| 579 | return "";
|
---|
| 580 | }
|
---|
[1856] | 581 |
|
---|
| 582 | return default_encoding;
|
---|
| 583 | }
|
---|
| 584 |
|
---|
[155] | 585 | // parse_cgi_args parses cgi arguments into an argument class.
|
---|
| 586 | // This function should be called for each page request. It returns false
|
---|
| 587 | // if there was a major problem with the cgi arguments.
|
---|
[12509] | 588 | bool receptionist::parse_cgi_args (const text_t &argstr,
|
---|
| 589 | fileupload_tmap &fileuploads,
|
---|
| 590 | cgiargsclass &args,
|
---|
[864] | 591 | ostream &logout, text_tmap &fcgienv) {
|
---|
[155] | 592 |
|
---|
| 593 | // get an initial list of cgi arguments
|
---|
| 594 | args.clear();
|
---|
[776] | 595 | split_cgi_args (argsinfo, argstr, args);
|
---|
[30374] | 596 |
|
---|
[155] | 597 | // expand the compressed argument (if there was one)
|
---|
[165] | 598 | if (!expand_save_args (argsinfo, configinfo.saveconf, args, logout)) return false;
|
---|
[30374] | 599 |
|
---|
[155] | 600 | // add the defaults
|
---|
| 601 | add_default_args (argsinfo, args, logout);
|
---|
[30374] | 602 |
|
---|
[12509] | 603 | // add any file upload arguments
|
---|
| 604 | add_fileupload_args(argsinfo, args, fileuploads, logout);
|
---|
[30374] | 605 |
|
---|
[463] | 606 | // get the cookie
|
---|
[864] | 607 | if (configinfo.usecookies) get_cookie(args["z"], fcgienv);
|
---|
[362] | 608 |
|
---|
[1856] | 609 | // if we're changing languages, set the encoding to the default for the new language
|
---|
| 610 | if (args["nl"] == "1") {
|
---|
| 611 | args["nw"] = get_default_encoding(args["l"]);
|
---|
| 612 | }
|
---|
| 613 |
|
---|
[362] | 614 | // get the input encoding
|
---|
[1856] | 615 | // if encoding isn't set, set it to the default for the current language
|
---|
| 616 | if ((args.getarg("w") == NULL) || args["w"].empty()) {
|
---|
| 617 | args["w"] = get_default_encoding(args["l"]);
|
---|
| 618 | }
|
---|
| 619 |
|
---|
[362] | 620 | text_t &arg_w = args["w"];
|
---|
[1856] | 621 |
|
---|
[362] | 622 | inconvertclass defaultinconvert;
|
---|
| 623 | inconvertclass *inconvert = converters.get_inconverter (arg_w);
|
---|
| 624 | if (inconvert == NULL) inconvert = &defaultinconvert;
|
---|
| 625 |
|
---|
| 626 | // see if the next page will have a different encoding
|
---|
| 627 | if (args.getarg("nw") != NULL) arg_w = args["nw"];
|
---|
[30374] | 628 |
|
---|
[362] | 629 | // convert arguments which aren't in unicode to unicode
|
---|
| 630 | args_tounicode (args, *inconvert);
|
---|
[30374] | 631 |
|
---|
[362] | 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()) {
|
---|
[31980] | 998 | //headers["content-encoding"] = args["w"];
|
---|
[7347] | 999 | response_data += "; charset=" + args["w"];
|
---|
| 1000 | } else {
|
---|
| 1001 | // default to utf-8
|
---|
[31980] | 1002 | //headers["content-encoding"] = "utf-8";
|
---|
[7347] | 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;
|
---|
[31731] | 1107 |
|
---|
[248] | 1108 | if (compress_save_args (argsinfo, configinfo.saveconf, args,
|
---|
[362] | 1109 | compressed_args, *outconverter, logout))
|
---|
[31731] | 1110 | return compressed_args;
|
---|
[362] | 1111 |
|
---|
[7421] | 1112 | return g_EmptyText;
|
---|
[108] | 1113 | }
|
---|
[155] | 1114 |
|
---|
| 1115 |
|
---|
| 1116 | // will read in all the macro files. If one is not found an
|
---|
| 1117 | // error message will be written to logout and the method will
|
---|
| 1118 | // return false.
|
---|
| 1119 | bool receptionist::read_macrofiles (ostream &logout) {
|
---|
| 1120 | outconvertclass text_t2ascii;
|
---|
| 1121 |
|
---|
| 1122 | // redirect the error output to logout
|
---|
[789] | 1123 | ostream *savedlogout = disp.setlogout (&logout);
|
---|
[155] | 1124 |
|
---|
[6022] | 1125 | // unload any macros that were previously loaded - this allows us to call
|
---|
| 1126 | // this function a second time to reload all the macro files (useful for
|
---|
| 1127 | // reading in changed macro files in server versions of greenstone)
|
---|
| 1128 | disp.unloaddefaultmacros();
|
---|
| 1129 |
|
---|
[155] | 1130 | // load up the default macro files, the collection directory
|
---|
| 1131 | // is searched first for the file (if this is being used in
|
---|
[799] | 1132 | // collection specific mode) and then the main directory(s)
|
---|
[165] | 1133 | text_t colmacrodir = filename_cat (configinfo.collectdir, "macros");
|
---|
[799] | 1134 |
|
---|
[1089] | 1135 | text_tset maindirs;
|
---|
[165] | 1136 | text_t gsdlmacrodir = filename_cat (configinfo.gsdlhome, "macros");
|
---|
[1089] | 1137 | maindirs.insert (gsdlmacrodir);
|
---|
[799] | 1138 | colinfo_tmap::iterator colhere = configinfo.collectinfo.begin();
|
---|
| 1139 | colinfo_tmap::iterator colend = configinfo.collectinfo.end();
|
---|
| 1140 | while (colhere != colend) {
|
---|
[1270] | 1141 | if (!((*colhere).second.gsdl_gsdlhome).empty()) {
|
---|
| 1142 | gsdlmacrodir = filename_cat ((*colhere).second.gsdl_gsdlhome, "macros");
|
---|
| 1143 | maindirs.insert (gsdlmacrodir);
|
---|
| 1144 | }
|
---|
[7421] | 1145 | ++colhere;
|
---|
[799] | 1146 | }
|
---|
| 1147 |
|
---|
| 1148 | text_tset::iterator arrhere = configinfo.macrofiles.begin();
|
---|
| 1149 | text_tset::iterator arrend = configinfo.macrofiles.end();
|
---|
[155] | 1150 | text_t filename;
|
---|
| 1151 | while (arrhere != arrend) {
|
---|
[799] | 1152 | bool foundfile = false;
|
---|
[155] | 1153 |
|
---|
| 1154 | // try in the collection directory if this is being
|
---|
| 1155 | // run in collection specific mode
|
---|
[165] | 1156 | if (!configinfo.collection.empty()) {
|
---|
[155] | 1157 | filename = filename_cat (colmacrodir, *arrhere);
|
---|
[799] | 1158 | if (file_exists (filename)) {
|
---|
| 1159 | disp.loaddefaultmacros(filename);
|
---|
| 1160 | foundfile = true;
|
---|
| 1161 | }
|
---|
[155] | 1162 | }
|
---|
| 1163 |
|
---|
| 1164 | // if we haven't found the macro file yet try in
|
---|
[799] | 1165 | // the main macro directory(s)
|
---|
| 1166 | // if file is found in more than one main directory
|
---|
| 1167 | // we'll load all copies
|
---|
| 1168 | if (!foundfile) {
|
---|
[1089] | 1169 | text_tset::const_iterator dirhere = maindirs.begin();
|
---|
| 1170 | text_tset::const_iterator dirend = maindirs.end();
|
---|
[799] | 1171 | while (dirhere != dirend) {
|
---|
| 1172 | filename = filename_cat (*dirhere, *arrhere);
|
---|
| 1173 | if (file_exists (filename)) {
|
---|
| 1174 | disp.loaddefaultmacros(filename);
|
---|
| 1175 | foundfile = true;
|
---|
| 1176 | }
|
---|
[7421] | 1177 | ++dirhere;
|
---|
[799] | 1178 | }
|
---|
[155] | 1179 | }
|
---|
| 1180 |
|
---|
| 1181 | // see if we found the file or not
|
---|
[799] | 1182 | if (!foundfile) {
|
---|
[155] | 1183 | logout << text_t2ascii
|
---|
| 1184 | << "Error: the macro file \"" << *arrhere << "\" could not be found.\n";
|
---|
[165] | 1185 | if (configinfo.collection.empty()) {
|
---|
[799] | 1186 | text_t dirs;
|
---|
| 1187 | joinchar (maindirs, ", ", dirs);
|
---|
| 1188 | logout << text_t2ascii
|
---|
| 1189 | << "It should be in either of the following directories ("
|
---|
| 1190 | << dirs << ").\n\n";
|
---|
| 1191 |
|
---|
[155] | 1192 | } else {
|
---|
| 1193 | logout << text_t2ascii
|
---|
| 1194 | << "It should be in either " << colmacrodir << " or in "
|
---|
| 1195 | << gsdlmacrodir << ".\n\n";
|
---|
| 1196 | }
|
---|
[10636] | 1197 | // don't crap out if a macro file is missing
|
---|
| 1198 | //disp.setlogout (savedlogout);
|
---|
| 1199 | //return false;
|
---|
[155] | 1200 | }
|
---|
[7421] | 1201 | ++arrhere;
|
---|
[155] | 1202 | }
|
---|
| 1203 |
|
---|
| 1204 | // success
|
---|
[789] | 1205 |
|
---|
| 1206 | // reset logout to what it was
|
---|
| 1207 | disp.setlogout (savedlogout);
|
---|
[155] | 1208 | return true;
|
---|
| 1209 | }
|
---|
| 1210 |
|
---|
| 1211 |
|
---|
[7390] | 1212 |
|
---|
| 1213 |
|
---|
| 1214 | // Go through the list of macro files looking to see
|
---|
| 1215 | // if any exist in the collectoin specific area. If they
|
---|
| 1216 | // do then read them in and add them to the set of existing
|
---|
| 1217 | // current macros
|
---|
| 1218 |
|
---|
| 1219 | void receptionist::read_collection_macrofiles (const text_t& collection, ostream &logout)
|
---|
| 1220 | {
|
---|
| 1221 | outconvertclass text_t2ascii;
|
---|
| 1222 |
|
---|
[9615] | 1223 | // disp.unloadcollectionmacros();
|
---|
[7390] | 1224 |
|
---|
| 1225 | // redirect the error output to logout
|
---|
| 1226 | ostream *savedlogout = disp.setlogout (&logout);
|
---|
| 1227 |
|
---|
| 1228 | text_t colmacrodir
|
---|
[16310] | 1229 | = filename_cat (configinfo.collecthome,collection, "macros");
|
---|
[7390] | 1230 |
|
---|
[7509] | 1231 | if (directory_exists (colmacrodir)) {
|
---|
[7390] | 1232 |
|
---|
| 1233 | text_tset::iterator arrhere = configinfo.macrofiles.begin();
|
---|
| 1234 | text_tset::iterator arrend = configinfo.macrofiles.end();
|
---|
| 1235 | text_t filename;
|
---|
| 1236 | while (arrhere != arrend) {
|
---|
| 1237 |
|
---|
| 1238 | filename = filename_cat (colmacrodir, *arrhere);
|
---|
| 1239 | if (file_exists (filename)) {
|
---|
| 1240 | disp.loadcollectionmacros(filename);
|
---|
| 1241 | }
|
---|
| 1242 |
|
---|
[7421] | 1243 | ++arrhere;
|
---|
[7390] | 1244 | }
|
---|
| 1245 | }
|
---|
| 1246 |
|
---|
| 1247 | // reset logout to what it was
|
---|
| 1248 | disp.setlogout (savedlogout);
|
---|
| 1249 | }
|
---|
| 1250 |
|
---|
| 1251 |
|
---|
| 1252 |
|
---|
| 1253 |
|
---|
[155] | 1254 | // check_mainargs will check all the main arguments. If a major
|
---|
| 1255 | // error is found it will return false and no cgi page should
|
---|
| 1256 | // be created using the arguments.
|
---|
[4974] | 1257 |
|
---|
[799] | 1258 | bool receptionist::check_mainargs (cgiargsclass &args, ostream &logout) {
|
---|
[5017] | 1259 |
|
---|
| 1260 | if(configinfo.site_auth)
|
---|
| 1261 | {
|
---|
| 1262 | args["uan"] = "1";
|
---|
| 1263 | args["ug"] = configinfo.site_group;
|
---|
| 1264 | }
|
---|
| 1265 |
|
---|
| 1266 |
|
---|
| 1267 | // if this receptionist is running in collection dependant mode
|
---|
| 1268 | // then it should always set the collection argument to the
|
---|
| 1269 | // collection
|
---|
| 1270 | if (!configinfo.collection.empty()) args["c"] = configinfo.collection;
|
---|
| 1271 |
|
---|
| 1272 | // if current collection uses ccscols make sure
|
---|
| 1273 | // "ccs" argument is set and make "cc" default to
|
---|
| 1274 | // all collections in "ccs"
|
---|
| 1275 | if (args["a"] != "config" && !args["c"].empty()) {
|
---|
| 1276 |
|
---|
| 1277 | text_t &arg_c = args["c"];
|
---|
| 1278 | recptproto *collectproto = protocols.getrecptproto (arg_c, logout);
|
---|
| 1279 | if (collectproto == NULL) {
|
---|
| 1280 | // oops, this collection isn't valid
|
---|
| 1281 | outconvertclass text_t2ascii;
|
---|
| 1282 | logout << text_t2ascii << "ERROR: Invalid collection: " << arg_c << "\n";
|
---|
[5512] | 1283 | // args["c"].clear();
|
---|
[5017] | 1284 |
|
---|
| 1285 | } else {
|
---|
| 1286 |
|
---|
| 1287 | ColInfoResponse_t *cinfo = get_collectinfo_ptr (collectproto, arg_c, logout);
|
---|
| 1288 |
|
---|
[5024] | 1289 | if(cinfo->authenticate == "collection")
|
---|
[5017] | 1290 | {
|
---|
| 1291 | args["uan"] = "1";
|
---|
| 1292 | args["ug"] = cinfo->auth_group;
|
---|
| 1293 | }
|
---|
| 1294 |
|
---|
| 1295 |
|
---|
[1270] | 1296 | if (cinfo != NULL) {
|
---|
[5017] | 1297 | if (!cinfo->ccsCols.empty()) {
|
---|
| 1298 | args["ccs"] = 1;
|
---|
| 1299 | if (args["cc"].empty()) {
|
---|
| 1300 | text_tarray::const_iterator col_here = cinfo->ccsCols.begin();
|
---|
| 1301 | text_tarray::const_iterator col_end = cinfo->ccsCols.end();
|
---|
| 1302 | bool first = true;
|
---|
| 1303 | while (col_here != col_end) {
|
---|
| 1304 | // make sure it's a valid collection
|
---|
| 1305 | if (protocols.getrecptproto (*col_here, logout) != NULL) {
|
---|
| 1306 | if (!first) args["cc"].push_back (',');
|
---|
| 1307 | args["cc"] += *col_here;
|
---|
| 1308 | first = false;
|
---|
| 1309 | }
|
---|
[7421] | 1310 | ++col_here;
|
---|
[1268] | 1311 | }
|
---|
[904] | 1312 | }
|
---|
[799] | 1313 | }
|
---|
[1270] | 1314 | } else {
|
---|
| 1315 | logout << "ERROR (receptionist::check_mainargs): get_collectinfo_ptr returned NULL\n";
|
---|
[799] | 1316 | }
|
---|
| 1317 | }
|
---|
| 1318 | }
|
---|
| 1319 |
|
---|
[155] | 1320 | // argument "v" can only be 0 or 1. Use the default value
|
---|
| 1321 | // if it is out of range
|
---|
| 1322 | int arg_v = args.getintarg ("v");
|
---|
| 1323 | if (arg_v != 0 && arg_v != 1) {
|
---|
| 1324 | cgiarginfo *vinfo = argsinfo.getarginfo ("v");
|
---|
| 1325 | if (vinfo != NULL) args["v"] = vinfo->argdefault;
|
---|
| 1326 | }
|
---|
| 1327 |
|
---|
| 1328 | // argument "f" can only be 0 or 1. Use the default value
|
---|
| 1329 | // if it is out of range
|
---|
| 1330 | int arg_f = args.getintarg ("f");
|
---|
| 1331 | if (arg_f != 0 && arg_f != 1) {
|
---|
| 1332 | cgiarginfo *finfo = argsinfo.getarginfo ("f");
|
---|
| 1333 | if (finfo != NULL) args["f"] = finfo->argdefault;
|
---|
| 1334 | }
|
---|
| 1335 |
|
---|
| 1336 | return true;
|
---|
| 1337 | }
|
---|
[173] | 1338 |
|
---|
[712] | 1339 | // translate_OIDs translates the "d" and "cl" arguments to their correct values
|
---|
[669] | 1340 | // if they use the tricky ".fc", ".lc" type syntax.
|
---|
[649] | 1341 | void receptionist::translate_OIDs (cgiargsclass &args, recptproto *collectproto,
|
---|
| 1342 | ostream &logout) {
|
---|
[438] | 1343 |
|
---|
| 1344 | FilterResponse_t response;
|
---|
| 1345 | FilterRequest_t request;
|
---|
| 1346 | comerror_t err;
|
---|
| 1347 | text_t &arg_d = args["d"];
|
---|
| 1348 | text_t &arg_cl = args["cl"];
|
---|
| 1349 | text_t &collection = args["c"];
|
---|
| 1350 |
|
---|
| 1351 | // do a call to translate OIDs if required
|
---|
| 1352 | request.filterName = "NullFilter";
|
---|
| 1353 | request.filterResultOptions = FROID;
|
---|
[649] | 1354 | if (!arg_d.empty() && needs_translating (arg_d)) {
|
---|
[468] | 1355 | request.docSet.push_back (arg_d);
|
---|
[438] | 1356 | collectproto->filter (collection, request, response, err, logout);
|
---|
| 1357 | arg_d = response.docInfo[0].OID;
|
---|
| 1358 | request.clear();
|
---|
| 1359 | }
|
---|
| 1360 | // we'll also check here that the "cl" argument has a "classify" doctype
|
---|
| 1361 | // (in case ".fc" or ".lc" have screwed up)
|
---|
| 1362 | if (needs_translating (arg_cl)) {
|
---|
[649] | 1363 | request.fields.insert ("doctype");
|
---|
[468] | 1364 | request.docSet.push_back (arg_cl);
|
---|
[438] | 1365 | request.filterResultOptions = FRmetadata;
|
---|
| 1366 | collectproto->filter (collection, request, response, err, logout);
|
---|
[30307] | 1367 | // set to original value (without .xx stuff) if doctype isn't "classify" or if no doctype
|
---|
| 1368 | if (response.docInfo[0].metadata["doctype"].values.size() == 0 || response.docInfo[0].metadata["doctype"].values[0] != "classify")
|
---|
[438] | 1369 | strip_suffix (arg_cl);
|
---|
| 1370 | else
|
---|
| 1371 | arg_cl = response.docInfo[0].OID;
|
---|
| 1372 | }
|
---|
| 1373 | }
|
---|
| 1374 |
|
---|
[456] | 1375 | // prepare_page sets up page parameters, sets display macros
|
---|
| 1376 | // and opens the page ready for output
|
---|
[760] | 1377 | void receptionist::prepare_page (action *a, cgiargsclass &args,
|
---|
| 1378 | outconvertclass &outconvert,
|
---|
| 1379 | ostream &logout) {
|
---|
[173] | 1380 | // set up page parameters
|
---|
| 1381 | text_t pageparams;
|
---|
| 1382 | bool first = true;
|
---|
[512] | 1383 |
|
---|
[530] | 1384 | text_tmap::iterator params_here = configinfo.pageparams.begin();
|
---|
| 1385 | text_tmap::iterator params_end = configinfo.pageparams.end();
|
---|
| 1386 | while (params_here != params_end) {
|
---|
[8470] | 1387 | // page params are those from main.cfg (eg pageparam v 0) plus
|
---|
| 1388 | // two defaults set in recptconf.clear() (c="" and l=en)
|
---|
| 1389 | // This used to check if the current value of the page param
|
---|
| 1390 | // == the default value, then don't add in it the list
|
---|
| 1391 | // but if l=en, and there is a macro with [l=en], then it doesn't
|
---|
| 1392 | // find it.
|
---|
| 1393 | // so now all page params will go into the list. I assume this will
|
---|
| 1394 | // mean more attempts to find each macro, but nothing worsee than
|
---|
| 1395 | // that. --kjdon
|
---|
| 1396 | //if (args[(*params_here).first] != (*params_here).second) {
|
---|
[8486] | 1397 | if (first)
|
---|
| 1398 | first = false;
|
---|
| 1399 | else
|
---|
| 1400 | pageparams += ",";
|
---|
| 1401 |
|
---|
[530] | 1402 | pageparams += (*params_here).first;
|
---|
| 1403 | pageparams += "=";
|
---|
| 1404 | pageparams += args[(*params_here).first];
|
---|
[8470] | 1405 | // }
|
---|
[530] | 1406 |
|
---|
[7421] | 1407 | ++params_here;
|
---|
[530] | 1408 | }
|
---|
| 1409 |
|
---|
[418] | 1410 |
|
---|
[173] | 1411 | // open the page
|
---|
[530] | 1412 | disp.openpage(pageparams, configinfo.macroprecedence);
|
---|
[173] | 1413 |
|
---|
[9615] | 1414 | disp.unloadcollectionmacros();
|
---|
| 1415 |
|
---|
[9032] | 1416 | text_t collection = args["c"];
|
---|
| 1417 | if (!collection.empty()) {
|
---|
| 1418 | read_collection_macrofiles(collection,logout);
|
---|
| 1419 | }
|
---|
| 1420 |
|
---|
[173] | 1421 | // define external macros for each action
|
---|
| 1422 | actionptrmap::iterator actionhere = actions.begin ();
|
---|
| 1423 | actionptrmap::iterator actionend = actions.end ();
|
---|
| 1424 |
|
---|
| 1425 | while (actionhere != actionend) {
|
---|
| 1426 | assert ((*actionhere).second.a != NULL);
|
---|
[1860] | 1427 | if ((*actionhere).second.a != NULL) {
|
---|
[760] | 1428 | (*actionhere).second.a->define_external_macros (disp, args, &protocols, logout);
|
---|
[1860] | 1429 | }
|
---|
[7421] | 1430 | ++actionhere;
|
---|
[173] | 1431 | }
|
---|
| 1432 |
|
---|
[7390] | 1433 |
|
---|
[173] | 1434 | // define internal macros for the current action
|
---|
[760] | 1435 | a->define_internal_macros (disp, args, &protocols, logout);
|
---|
[512] | 1436 |
|
---|
| 1437 | // define general macros. the defining of general macros is done here so that
|
---|
| 1438 | // the last possible version of the cgi arguments are used
|
---|
[760] | 1439 | define_general_macros (args, outconvert, logout);
|
---|
[173] | 1440 | }
|
---|
| 1441 |
|
---|
[19259] | 1442 |
|
---|
[760] | 1443 | void receptionist::define_general_macros (cgiargsclass &args, outconvertclass &/*outconvert*/,
|
---|
| 1444 | ostream &logout) {
|
---|
[456] | 1445 |
|
---|
| 1446 | text_t &collection = args["c"];
|
---|
| 1447 |
|
---|
[7421] | 1448 | disp.setmacro ("gsdlhome", displayclass::defaultpackage, dm_safe(configinfo.gsdlhome));
|
---|
| 1449 | disp.setmacro ("gwcgi", displayclass::defaultpackage, configinfo.gwcgi);
|
---|
[19109] | 1450 | disp.setmacro ("httpweb", displayclass::defaultpackage, configinfo.httpweb);
|
---|
[7421] | 1451 | disp.setmacro ("httpprefix", displayclass::defaultpackage, configinfo.httpprefix);
|
---|
[1860] | 1452 |
|
---|
[24106] | 1453 | // This perhaps should be done with gsdl_getenv() which takes the
|
---|
| 1454 | // 'fcgienv' parameter (for fast-cgi), however if changed to this, this
|
---|
| 1455 | // additional parameter would need to be passed into here (not sure how
|
---|
| 1456 | // that would effect any virtual inheritence going on), or else moved
|
---|
| 1457 | // higher up the calling to chain to, e.g., produce_cgi_page()
|
---|
| 1458 |
|
---|
| 1459 | char* remote_addr = getenv("REMOTE_ADDR");
|
---|
| 1460 |
|
---|
| 1461 | if (remote_addr != NULL) {
|
---|
| 1462 | text_t remote_addr_t(remote_addr);
|
---|
| 1463 | disp.setmacro ("remoteAddr", displayclass::defaultpackage, remote_addr_t);
|
---|
| 1464 | }
|
---|
| 1465 |
|
---|
| 1466 | char* remote_host = getenv("REMOTE_HOST");
|
---|
| 1467 | if (remote_host != NULL) {
|
---|
| 1468 | text_t remote_host_t(remote_host);
|
---|
| 1469 | disp.setmacro ("remoteHost", displayclass::defaultpackage, remote_host_t);
|
---|
| 1470 | }
|
---|
| 1471 | else {
|
---|
| 1472 | // setting this to "unknown" is easier to deal with in format/macro
|
---|
| 1473 | // statements, rather than testing for _remoteHost_
|
---|
| 1474 | disp.setmacro ("remoteHost", displayclass::defaultpackage, "unknown");
|
---|
| 1475 | }
|
---|
| 1476 |
|
---|
| 1477 |
|
---|
[864] | 1478 | text_t compressedoptions = get_compressed_arg(args, logout);
|
---|
[7421] | 1479 | disp.setmacro ("compressedoptions", displayclass::defaultpackage, dm_safe(compressedoptions));
|
---|
[28912] | 1480 | //disp.setmacro ("compressedoptionsUrlsafe", displayclass::defaultpackage, encodeForURL(dm_safe(compressedoptions))); // seems to be unnecessary after testing e=hack or e=hack<collect>... or e=...<collect>hack in a live server
|
---|
| 1481 |
|
---|
[864] | 1482 | // need a decoded version of compressedoptions for use within forms
|
---|
| 1483 | // as browsers encode values from forms before sending to server
|
---|
| 1484 | // (e.g. %25 becomes %2525)
|
---|
[13463] | 1485 | decode_cgi_arg (compressedoptions);
|
---|
[31731] | 1486 |
|
---|
[13463] | 1487 | if (args["w"] == "utf-8") { // if the encoding was utf-8, then compressed options was utf-8, and we need unicode.
|
---|
| 1488 | // if encoding wasn't utf-8, then compressed opotions may be screwed up, but seems to work for 8 bit encodings?
|
---|
| 1489 | compressedoptions = to_uni(compressedoptions);
|
---|
| 1490 | }
|
---|
[173] | 1491 |
|
---|
[31731] | 1492 | // does it need to be dm_safed? this breaks depositor when there is _ in filename
|
---|
| 1493 | //text_t dmacrovalue = dm_safe(compressedoptions);
|
---|
| 1494 | text_t dmacrovalue = compressedoptions;
|
---|
| 1495 |
|
---|
[28888] | 1496 | disp.setmacro ("decodedcompressedoptions", displayclass::defaultpackage, dmacrovalue);
|
---|
| 1497 | disp.setmacro ("decodedcompressedoptionsAttrsafe", displayclass::defaultpackage, encodeForHTMLAttr(dmacrovalue));
|
---|
[31731] | 1498 | // the old version was dm_safed, so make a dm safe version in case we need it
|
---|
| 1499 | disp.setmacro ("decodedcompressedoptionsAttrDmsafe", displayclass::defaultpackage, encodeForHTMLAttr(dm_safe(dmacrovalue)));
|
---|
[28888] | 1500 |
|
---|
[1305] | 1501 | #if defined (__WIN32__)
|
---|
[7421] | 1502 | disp.setmacro ("win32", displayclass::defaultpackage, "1");
|
---|
[1305] | 1503 | #endif
|
---|
| 1504 |
|
---|
[173] | 1505 | // set _cgiargX_ macros for each cgi argument
|
---|
| 1506 | cgiargsclass::const_iterator argshere = args.begin();
|
---|
| 1507 | cgiargsclass::const_iterator argsend = args.end();
|
---|
| 1508 | while (argshere != argsend) {
|
---|
[28888] | 1509 |
|
---|
| 1510 | text_t macrovalue = (*argshere).second.value; // and stays like that if ((*argshere).first == "hp")
|
---|
| 1511 |
|
---|
[512] | 1512 | if (((*argshere).first == "q") ||
|
---|
| 1513 | ((*argshere).first == "qa") ||
|
---|
| 1514 | ((*argshere).first == "qtt") ||
|
---|
| 1515 | ((*argshere).first == "qty") ||
|
---|
| 1516 | ((*argshere).first == "qp") ||
|
---|
| 1517 | ((*argshere).first == "qpl") ||
|
---|
| 1518 | ((*argshere).first == "qr") ||
|
---|
[28888] | 1519 | ((*argshere).first == "q2")) {
|
---|
| 1520 |
|
---|
[263] | 1521 | // need to escape special characters from query string
|
---|
[28888] | 1522 | macrovalue = html_safe(macrovalue);
|
---|
| 1523 |
|
---|
| 1524 | } else if ((*argshere).first == "hp") {
|
---|
| 1525 | if(!isValidURLProtocol(macrovalue)) {
|
---|
| 1526 | macrovalue = encodeForURL(macrovalue); // URL has invalid protocol like javascript:, so URL encode it
|
---|
| 1527 | }
|
---|
[5020] | 1528 | }
|
---|
[28888] | 1529 | else {
|
---|
| 1530 | macrovalue = dm_safe(macrovalue);
|
---|
| 1531 | }
|
---|
| 1532 |
|
---|
| 1533 | // set the default value for the macro
|
---|
| 1534 | disp.setmacro ("cgiarg" + (*argshere).first, displayclass::defaultpackage, macrovalue);
|
---|
| 1535 |
|
---|
| 1536 | // set macros for the encoded versions of the same value. Uses the functions in securitytools.h
|
---|
| 1537 | // https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet
|
---|
| 1538 |
|
---|
| 1539 | text_t htmlsafe = encodeForHTML(macrovalue);
|
---|
| 1540 | text_t attrsafe = encodeForHTMLAttr(macrovalue);
|
---|
| 1541 | text_t urlsafe = encodeForURL(macrovalue);
|
---|
[28898] | 1542 | text_t jssafe = encodeForJavascript(macrovalue); // with default setting will return \\x and \\u for macro files
|
---|
[28899] | 1543 | text_t csssafe = encodeForCSS(macrovalue); // not yet used anywhere, but is available for use in macros
|
---|
| 1544 | text_t sqlsafe = encodeForSQL(macrovalue);
|
---|
[28888] | 1545 |
|
---|
| 1546 | disp.setmacro ("cgiarg" + (*argshere).first + "Htmlsafe", displayclass::defaultpackage, htmlsafe);
|
---|
| 1547 | disp.setmacro ("cgiarg" + (*argshere).first + "Attrsafe", displayclass::defaultpackage, attrsafe);
|
---|
[28899] | 1548 | disp.setmacro ("cgiarg" + (*argshere).first + "Urlsafe", displayclass::defaultpackage, urlsafe);
|
---|
[28888] | 1549 | disp.setmacro ("cgiarg" + (*argshere).first + "Jssafe", displayclass::defaultpackage, jssafe);
|
---|
| 1550 | disp.setmacro ("cgiarg" + (*argshere).first + "Csssafe", displayclass::defaultpackage, csssafe);
|
---|
[28899] | 1551 | disp.setmacro ("cgiarg" + (*argshere).first + "Sqlsafe", displayclass::defaultpackage, sqlsafe);
|
---|
[28888] | 1552 |
|
---|
| 1553 |
|
---|
[7421] | 1554 | ++argshere;
|
---|
[173] | 1555 | }
|
---|
[456] | 1556 |
|
---|
| 1557 | // set collection specific macros
|
---|
[760] | 1558 | if (!collection.empty()) {
|
---|
| 1559 | recptproto *collectproto = protocols.getrecptproto (collection, logout);
|
---|
| 1560 | if (collectproto != NULL) {
|
---|
| 1561 | FilterResponse_t response;
|
---|
| 1562 | text_tset metadata;
|
---|
[7420] | 1563 | get_info ("collection", collection, args["l"], metadata, false,
|
---|
[760] | 1564 | collectproto, response, logout);
|
---|
| 1565 |
|
---|
| 1566 | if (!response.docInfo[0].metadata.empty()) {
|
---|
| 1567 | MetadataInfo_tmap::const_iterator here = response.docInfo[0].metadata.begin();
|
---|
| 1568 | MetadataInfo_tmap::const_iterator end = response.docInfo[0].metadata.end();
|
---|
| 1569 | while (here != end) {
|
---|
| 1570 | if (((*here).first != "haschildren") && ((*here).first != "hasnext") &&
|
---|
| 1571 | ((*here).first != "hasprevious")) {
|
---|
[2773] | 1572 | // check for args in form name:lang
|
---|
[7421] | 1573 | text_t name = g_EmptyText;
|
---|
| 1574 | text_t lang = g_EmptyText;
|
---|
[2773] | 1575 | bool colonfound=false;
|
---|
| 1576 | text_t::const_iterator a = (*here).first.begin();
|
---|
| 1577 | text_t::const_iterator b = (*here).first.end();
|
---|
| 1578 | while (a !=b) {
|
---|
| 1579 | if (*a==':') {
|
---|
| 1580 | colonfound=true;
|
---|
| 1581 | }
|
---|
| 1582 | else {
|
---|
| 1583 | if (colonfound)
|
---|
| 1584 | lang.push_back(*a);
|
---|
| 1585 | else name.push_back(*a);
|
---|
| 1586 | }
|
---|
[7421] | 1587 | ++a;
|
---|
[2773] | 1588 | }
|
---|
| 1589 | if (!lang.empty()) {
|
---|
| 1590 | if (args["l"]==lang) {
|
---|
[9931] | 1591 | disp.setcollectionmacro(displayclass::defaultpackage, name, "", (*here).second.values[0]);
|
---|
[2773] | 1592 | }
|
---|
| 1593 | }
|
---|
| 1594 | else { // the default one
|
---|
[9931] | 1595 | disp.setcollectionmacro(displayclass::defaultpackage, (*here).first, "", (*here).second.values[0]);
|
---|
[2773] | 1596 | }
|
---|
[760] | 1597 | }
|
---|
[7421] | 1598 | ++here;
|
---|
[456] | 1599 | }
|
---|
| 1600 | }
|
---|
[1860] | 1601 |
|
---|
| 1602 | text_t iconcollection;
|
---|
[7421] | 1603 | disp.expandstring (displayclass::defaultpackage, "_iconcollection_", iconcollection);
|
---|
[1860] | 1604 | if (!iconcollection.empty())
|
---|
| 1605 | {
|
---|
[1877] | 1606 | ColInfoResponse_t cinfo;
|
---|
| 1607 | comerror_t err;
|
---|
| 1608 | collectproto->get_collectinfo (collection, cinfo, err, logout);
|
---|
| 1609 | if (iconcollection[0]=='/' && !cinfo.httpdomain.empty())
|
---|
[1860] | 1610 | {
|
---|
| 1611 | // local but with full path
|
---|
| 1612 | iconcollection = "http://" + cinfo.httpdomain + iconcollection;
|
---|
[7421] | 1613 | disp.setmacro("iconcollection", displayclass::defaultpackage, iconcollection);
|
---|
[1860] | 1614 | }
|
---|
| 1615 | }
|
---|
[456] | 1616 | }
|
---|
| 1617 | }
|
---|
[19259] | 1618 |
|
---|
[9931] | 1619 | if (!collection.empty()) {
|
---|
| 1620 | ColInfoResponse_t cinfo;
|
---|
| 1621 | comerror_t err;
|
---|
| 1622 | recptproto *collectproto = protocols.getrecptproto (collection, logout);
|
---|
| 1623 | if (collectproto != NULL) {
|
---|
| 1624 | collectproto->get_collectinfo (collection, cinfo, err, logout);
|
---|
[19259] | 1625 |
|
---|
| 1626 |
|
---|
| 1627 | // This part of the code used to use "cinfo.httpprefix" regardless
|
---|
| 1628 | // of the value it contained. Since
|
---|
| 1629 | // this can come back with an empty (in the case of gsdl_mod), the
|
---|
| 1630 | // URL produced was invalid.
|
---|
| 1631 | //
|
---|
| 1632 | // Changed to test for empty first, and use configinfo.httpprefix as
|
---|
| 1633 | // a "backup"
|
---|
| 1634 | //
|
---|
| 1635 | // Point to consider: since configinfo.httpprefix has been offically
|
---|
| 1636 | // set as "httpprefix" in macros, it seems to make more sense to use
|
---|
| 1637 | // always use that version and not the cinfo version at all.
|
---|
| 1638 |
|
---|
| 1639 | text_t httpprefix
|
---|
| 1640 | = (!cinfo.httpprefix.empty()) ? cinfo.httpprefix : configinfo.httpprefix;
|
---|
| 1641 |
|
---|
[9931] | 1642 | text_t httpcollection;
|
---|
| 1643 | if (!cinfo.httpdomain.empty()) httpcollection = "http://";
|
---|
[19259] | 1644 | httpcollection += cinfo.httpdomain + httpprefix + "/collect/"
|
---|
[28912] | 1645 | + encodeForURL(collection);
|
---|
[9931] | 1646 | disp.setmacro ("httpcollection", displayclass::defaultpackage,
|
---|
| 1647 | httpcollection);
|
---|
[19259] | 1648 |
|
---|
[9931] | 1649 | // as of gsdl 2.53, collect.cfg can specify macros
|
---|
| 1650 | if (cinfo.collection_macros.size() > 0) {
|
---|
[11964] | 1651 | collectionmeta_map::const_iterator this_macro=cinfo.collection_macros.begin();
|
---|
| 1652 | collectionmeta_map::const_iterator done_macro=cinfo.collection_macros.end();
|
---|
[9931] | 1653 | while (this_macro != done_macro) {
|
---|
[10931] | 1654 | text_t package = "Global";
|
---|
| 1655 | text_t macroname = this_macro->first;
|
---|
| 1656 | // if this macro name is AAA:bbb then extract the package name
|
---|
| 1657 | text_t::const_iterator thischar, donechar;
|
---|
| 1658 | thischar = macroname.begin();
|
---|
| 1659 | donechar = macroname.end();
|
---|
| 1660 | while (thischar < donechar) {
|
---|
| 1661 | if (*thischar == ':') {
|
---|
| 1662 | package = substr(macroname.begin(),thischar);
|
---|
| 1663 | macroname = substr(thischar+1,donechar);
|
---|
| 1664 | break;
|
---|
| 1665 | }
|
---|
| 1666 | ++thischar;
|
---|
| 1667 | }
|
---|
[9931] | 1668 |
|
---|
[11964] | 1669 | text_tmap params_map = this_macro->second;
|
---|
| 1670 | text_tmap::const_iterator this_param = params_map.begin();
|
---|
| 1671 | text_tmap::const_iterator done_param = params_map.end();
|
---|
| 1672 | while (this_param != done_param) {
|
---|
| 1673 | disp.setcollectionmacro(package,
|
---|
| 1674 | macroname,
|
---|
| 1675 | this_param->first,
|
---|
| 1676 | this_param->second);
|
---|
| 1677 | ++this_param;
|
---|
| 1678 | }
|
---|
| 1679 |
|
---|
[9931] | 1680 | ++this_macro;
|
---|
| 1681 | }
|
---|
| 1682 | } // col macros
|
---|
| 1683 | } // collectproto != NULL
|
---|
| 1684 | }
|
---|
| 1685 |
|
---|
[173] | 1686 | }
|
---|
[1270] | 1687 |
|
---|
| 1688 | // gets collection info from cache if found or
|
---|
| 1689 | // calls collection server (and updates cache)
|
---|
| 1690 | // returns NULL if there's an error
|
---|
| 1691 | ColInfoResponse_t *receptionist::get_collectinfo_ptr (recptproto *collectproto,
|
---|
| 1692 | const text_t &collection,
|
---|
| 1693 | ostream &logout) {
|
---|
| 1694 |
|
---|
| 1695 | // check the cache
|
---|
| 1696 | colinfo_tmap::iterator it = configinfo.collectinfo.find (collection);
|
---|
| 1697 | if ((it != configinfo.collectinfo.end()) && ((*it).second.info_loaded)) {
|
---|
| 1698 | // found it
|
---|
| 1699 | return &((*it).second.info);
|
---|
| 1700 | }
|
---|
| 1701 |
|
---|
| 1702 | // not cached, get info from collection server
|
---|
| 1703 | if (collectproto == NULL) {
|
---|
| 1704 | logout << "ERROR: receptionist::get_collectinfo_ptr passed null collectproto\n";
|
---|
| 1705 | return NULL;
|
---|
| 1706 | }
|
---|
| 1707 |
|
---|
| 1708 | comerror_t err;
|
---|
| 1709 | if (it == configinfo.collectinfo.end()) {
|
---|
| 1710 | collectioninfo_t cinfo;
|
---|
| 1711 | collectproto->get_collectinfo (collection, cinfo.info, err, logout);
|
---|
| 1712 | if (err != noError) {
|
---|
| 1713 | outconvertclass text_t2ascii;
|
---|
| 1714 | logout << text_t2ascii << "ERROR (receptionist::getcollectinfo_ptr): \""
|
---|
| 1715 | << get_comerror_string (err) << "\"while getting collectinfo\n";
|
---|
| 1716 | return NULL;
|
---|
| 1717 | }
|
---|
| 1718 | cinfo.info_loaded = true;
|
---|
| 1719 | configinfo.collectinfo[collection] = cinfo;
|
---|
| 1720 | return &(configinfo.collectinfo[collection].info);
|
---|
| 1721 | } else {
|
---|
| 1722 | collectproto->get_collectinfo (collection, (*it).second.info, err, logout);
|
---|
| 1723 | if (err != noError) {
|
---|
| 1724 | outconvertclass text_t2ascii;
|
---|
| 1725 | logout << text_t2ascii << "ERROR (receptionist::getcollectinfo_ptr): \""
|
---|
| 1726 | << get_comerror_string (err) << "\"while getting collectinfo\n";
|
---|
| 1727 | return NULL;
|
---|
| 1728 | }
|
---|
| 1729 | (*it).second.info_loaded = true;
|
---|
| 1730 | return &((*it).second.info);
|
---|
| 1731 | }
|
---|
| 1732 | }
|
---|
[1860] | 1733 |
|
---|
[2218] | 1734 | // removes a collection from the cache so that the next
|
---|
| 1735 | // call to get_collectinfo_ptr() for that collection will
|
---|
| 1736 | // retrieve the collection info from the collection server
|
---|
| 1737 | void receptionist::uncache_collection (const text_t &collection) {
|
---|
| 1738 |
|
---|
| 1739 | colinfo_tmap::iterator it = configinfo.collectinfo.find (collection);
|
---|
| 1740 | if ((it != configinfo.collectinfo.end()) && ((*it).second.info_loaded)) {
|
---|
| 1741 |
|
---|
| 1742 | (*it).second.info_loaded = false;
|
---|
| 1743 |
|
---|
| 1744 | }
|
---|
| 1745 | }
|
---|
| 1746 |
|
---|
[1870] | 1747 | // Handles an "Encoding" line from a configuration file - note that the
|
---|
| 1748 | // configinfo.encodings map is a bit of a hack (to be fixed when the
|
---|
| 1749 | // configuration files are tidied up).
|
---|
| 1750 | void receptionist::configure_encoding (const text_tarray &cfgline) {
|
---|
[1860] | 1751 |
|
---|
[1870] | 1752 | text_t subkey, subvalue, shortname, longname, mapfile;
|
---|
[1927] | 1753 | int multibyte = 0;
|
---|
[1870] | 1754 | text_t::const_iterator cfglinesub_here;
|
---|
| 1755 | text_tarray::const_iterator cfgline_here = cfgline.begin();
|
---|
| 1756 | text_tarray::const_iterator cfgline_end = cfgline.end();
|
---|
| 1757 | while (cfgline_here != cfgline_end) {
|
---|
[1927] | 1758 | if (*cfgline_here == "multibyte") {
|
---|
| 1759 | multibyte = 1;
|
---|
| 1760 | } else {
|
---|
| 1761 | cfglinesub_here = getdelimitstr((*cfgline_here).begin(),
|
---|
| 1762 | (*cfgline_here).end(), '=', subkey);
|
---|
| 1763 | if (subkey == "shortname") {
|
---|
| 1764 | shortname = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
| 1765 | } else if (subkey == "longname") {
|
---|
| 1766 | longname = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
| 1767 | } else if (subkey == "map") {
|
---|
| 1768 | mapfile = substr (cfglinesub_here, (*cfgline_here).end());
|
---|
| 1769 | }
|
---|
[1870] | 1770 | }
|
---|
[7443] | 1771 | ++cfgline_here;
|
---|
[1870] | 1772 | }
|
---|
| 1773 | if (!shortname.empty()) {
|
---|
| 1774 | if (longname.empty()) longname = shortname;
|
---|
| 1775 |
|
---|
| 1776 | // add the converter
|
---|
| 1777 | if (shortname == "utf-8") {
|
---|
| 1778 | utf8inconvertclass *utf8inconvert = new utf8inconvertclass();
|
---|
| 1779 | utf8outconvertclass *utf8outconvert = new utf8outconvertclass();
|
---|
| 1780 | utf8outconvert->set_rzws(1);
|
---|
| 1781 | add_converter (shortname, utf8inconvert, utf8outconvert);
|
---|
| 1782 | configinfo.encodings[longname] = shortname;
|
---|
| 1783 |
|
---|
[9674] | 1784 | } else if (shortname == "utf-16be") {
|
---|
[3668] | 1785 | // we use the default input converter as this shouldn't ever be used
|
---|
| 1786 | // for converting from unicode...
|
---|
| 1787 | inconvertclass *inconverter = new inconvertclass();
|
---|
| 1788 | utf16outconvertclass *outconverter = new utf16outconvertclass();
|
---|
| 1789 | add_converter (shortname, inconverter, outconverter);
|
---|
| 1790 | configinfo.encodings[longname] = shortname;
|
---|
| 1791 |
|
---|
[1870] | 1792 | } else if (!mapfile.empty()) {
|
---|
| 1793 |
|
---|
| 1794 | if (mapfile == "8859_1.ump") {
|
---|
| 1795 | // iso-8859-1 is a special case as it'll always be supported by the
|
---|
| 1796 | // standard converter class and therefore doesn't need to use its
|
---|
| 1797 | // mapping file
|
---|
| 1798 | inconvertclass *inconvert = new inconvertclass();
|
---|
| 1799 | rzwsoutconvertclass *outconvert = new rzwsoutconvertclass();
|
---|
| 1800 | outconvert->set_rzws(1);
|
---|
| 1801 | add_converter (shortname, inconvert, outconvert);
|
---|
| 1802 | configinfo.encodings[longname] = shortname;
|
---|
| 1803 |
|
---|
| 1804 | } else {
|
---|
| 1805 | text_t to_uc_map = filename_cat(configinfo.gsdlhome, "mappings", "to_uc", mapfile);
|
---|
| 1806 | text_t from_uc_map = filename_cat(configinfo.gsdlhome, "mappings", "from_uc", mapfile);
|
---|
| 1807 | if (file_exists(to_uc_map) && file_exists(from_uc_map)) {
|
---|
| 1808 |
|
---|
| 1809 | mapinconvertclass *mapinconvert = new mapinconvertclass();
|
---|
| 1810 | mapinconvert->setmapfile (to_uc_map, 0x003F);
|
---|
[1927] | 1811 | mapinconvert->set_multibyte (multibyte);
|
---|
[1870] | 1812 | mapoutconvertclass *mapoutconvert = new mapoutconvertclass();
|
---|
| 1813 | mapoutconvert->setmapfile (from_uc_map, 0x3F);
|
---|
[1927] | 1814 | mapoutconvert->set_multibyte (multibyte);
|
---|
[1870] | 1815 | mapoutconvert->set_rzws(1);
|
---|
| 1816 | add_converter (shortname, mapinconvert, mapoutconvert);
|
---|
| 1817 | configinfo.encodings[longname] = shortname;
|
---|
| 1818 | }
|
---|
| 1819 | }
|
---|
| 1820 | }
|
---|
| 1821 | }
|
---|
| 1822 | }
|
---|