[1284] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * cgiwrapper.cpp -- windows local library cgiwrapper
|
---|
| 4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
| 6 | * A component of the Greenstone digital library software
|
---|
| 7 | * from the New Zealand Digital Library Project at the
|
---|
| 8 | * University of Waikato, New Zealand.
|
---|
| 9 | *
|
---|
| 10 | * This program is free software; you can redistribute it and/or modify
|
---|
| 11 | * it under the terms of the GNU General Public License as published by
|
---|
| 12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | * (at your option) any later version.
|
---|
| 14 | *
|
---|
| 15 | * This program is distributed in the hope that it will be useful,
|
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | * GNU General Public License for more details.
|
---|
| 19 | *
|
---|
| 20 | * You should have received a copy of the GNU General Public License
|
---|
| 21 | * along with this program; if not, write to the Free Software
|
---|
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | *
|
---|
| 24 | *********************************************************************/
|
---|
| 25 |
|
---|
[1203] | 26 | #include "text_t.h"
|
---|
| 27 |
|
---|
[611] | 28 | #include <windows.h>
|
---|
| 29 | #include <string.h>
|
---|
| 30 | #include <stdio.h>
|
---|
| 31 | #include <stdlib.h>
|
---|
| 32 | #include <assert.h>
|
---|
| 33 | #include <direct.h>
|
---|
| 34 | #include "cgiwrapper.h"
|
---|
| 35 | #include "netio.h"
|
---|
| 36 | #include "wincgiutils.h"
|
---|
| 37 | #include "settings.h"
|
---|
[902] | 38 | #include "fileutil.h"
|
---|
[12761] | 39 | #include "parse.h"
|
---|
[611] | 40 |
|
---|
| 41 | #include "gsdlconf.h"
|
---|
| 42 | #include "recptconfig.h"
|
---|
| 43 |
|
---|
| 44 | #if defined (GSDL_USE_OBJECTSPACE)
|
---|
| 45 | #include <ospace\std\iostream>
|
---|
| 46 | #include <ospace\std\fstream>
|
---|
| 47 | #elif defined (GSDL_USE_IOS_H)
|
---|
| 48 | #include <iostream.h>
|
---|
| 49 | #include <fstream.h>
|
---|
| 50 | #else
|
---|
| 51 | #include <iostream>
|
---|
| 52 | #include <fstream>
|
---|
| 53 | #endif
|
---|
| 54 |
|
---|
| 55 | #include "receptionist.h"
|
---|
| 56 | #include "nullproto.h"
|
---|
| 57 |
|
---|
| 58 | // actions
|
---|
[902] | 59 | #include "statusaction.h"
|
---|
[611] | 60 | #include "pageaction.h"
|
---|
| 61 | #include "pingaction.h"
|
---|
| 62 | #include "queryaction.h"
|
---|
| 63 | #include "documentaction.h"
|
---|
[1193] | 64 | #include "tipaction.h"
|
---|
[902] | 65 | #include "authenaction.h"
|
---|
[611] | 66 | #include "usersaction.h"
|
---|
[14388] | 67 | #include "userdb.h"
|
---|
[902] | 68 | #include "extlinkaction.h"
|
---|
[1571] | 69 | #include "collectoraction.h"
|
---|
[2487] | 70 | #include "phindaction.h"
|
---|
[4291] | 71 | #include "configaction.h"
|
---|
[611] | 72 |
|
---|
[902] | 73 | // browsers
|
---|
| 74 | #include "vlistbrowserclass.h"
|
---|
| 75 | #include "hlistbrowserclass.h"
|
---|
| 76 | #include "datelistbrowserclass.h"
|
---|
| 77 | #include "invbrowserclass.h"
|
---|
| 78 | #include "pagedbrowserclass.h"
|
---|
| 79 | #include "htmlbrowserclass.h"
|
---|
[2487] | 80 | #include "phindbrowserclass.h"
|
---|
[902] | 81 |
|
---|
[611] | 82 | // the number of times the library has been accessed
|
---|
| 83 | int libaccessnum = 0;
|
---|
| 84 |
|
---|
| 85 | // used to output the text from receptionist
|
---|
| 86 | class textstreambuf : public streambuf
|
---|
| 87 | {
|
---|
| 88 | public:
|
---|
| 89 | textstreambuf ();
|
---|
| 90 | int sync ();
|
---|
| 91 | int overflow (int ch);
|
---|
| 92 | int underflow () {return EOF;}
|
---|
| 93 |
|
---|
| 94 | void tsbreset() {RInfo=NULL;casostr=NULL;}
|
---|
| 95 | void setrequestinfo (RequestInfoT *theRInfo) {RInfo=theRInfo;}
|
---|
| 96 | void cascadeoutput (ostream *thecasostr) {casostr=thecasostr;}
|
---|
| 97 |
|
---|
| 98 | private:
|
---|
| 99 | RequestInfoT *RInfo;
|
---|
| 100 | ostream *casostr;
|
---|
[1203] | 101 | #if !defined (GSDL_USE_IOS_H)
|
---|
| 102 | char buffer[256];
|
---|
| 103 | #endif
|
---|
[611] | 104 | };
|
---|
| 105 |
|
---|
| 106 | textstreambuf::textstreambuf() {
|
---|
| 107 | tsbreset();
|
---|
[1203] | 108 | #if !defined (GSDL_USE_IOS_H)
|
---|
| 109 | setp (&buffer[0], &buffer[255]);
|
---|
| 110 | #else
|
---|
[611] | 111 | if (base() == ebuf()) allocate();
|
---|
| 112 | setp (base(), ebuf());
|
---|
[1203] | 113 | #endif
|
---|
[611] | 114 | };
|
---|
| 115 |
|
---|
| 116 | int textstreambuf::sync () {
|
---|
| 117 | if ((RInfo != NULL) &&
|
---|
[1203] | 118 | (Send_String_N(pbase(), pptr()-pbase(), RInfo) < 0)) {
|
---|
[611] | 119 | RInfo = NULL;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | if (casostr != NULL) {
|
---|
| 123 | char *thepbase=pbase();
|
---|
[9598] | 124 | for (int i=0;i<(pptr()-pbase());++i) (*casostr).put(thepbase[i]);
|
---|
[611] | 125 | }
|
---|
| 126 |
|
---|
| 127 | setp (pbase(), epptr());
|
---|
| 128 |
|
---|
| 129 | return 0;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | int textstreambuf::overflow (int ch) {
|
---|
| 133 | if (sync () == EOF) return EOF;
|
---|
| 134 | if (ch != EOF) sputc (ch);
|
---|
| 135 | return 0;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 |
|
---|
| 139 | // used to output all the log and error messages
|
---|
| 140 | // from receptionist
|
---|
| 141 | class logstreambuf : public streambuf
|
---|
| 142 | {
|
---|
| 143 | public:
|
---|
| 144 | logstreambuf ();
|
---|
| 145 | int sync ();
|
---|
| 146 | int overflow (int ch);
|
---|
| 147 | int underflow () {return EOF;}
|
---|
[1203] | 148 |
|
---|
| 149 | #if !defined (GSDL_USE_IOS_H)
|
---|
| 150 | private:
|
---|
| 151 | char buffer[256];
|
---|
| 152 | #endif
|
---|
[611] | 153 | };
|
---|
| 154 |
|
---|
| 155 | logstreambuf::logstreambuf () {
|
---|
[1203] | 156 | #if !defined (GSDL_USE_IOS_H)
|
---|
| 157 | setp (&buffer[0], &buffer[255]);
|
---|
| 158 | #else
|
---|
[611] | 159 | if (base() == ebuf()) allocate();
|
---|
| 160 | setp (base(), ebuf());
|
---|
[1203] | 161 | #endif
|
---|
[611] | 162 | }
|
---|
| 163 |
|
---|
| 164 | int logstreambuf::sync () {
|
---|
[902] | 165 | if (gsdl_keep_log || gsdl_show_console) {
|
---|
[611] | 166 | log_message ("LOCAL LIB MESSAGE: ");
|
---|
[1203] | 167 | log_message_N (pbase(), pptr()-pbase());
|
---|
[611] | 168 | }
|
---|
| 169 |
|
---|
| 170 | setp (pbase(), epptr());
|
---|
| 171 | return 0;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | int logstreambuf::overflow (int ch) {
|
---|
| 175 | if (sync () == EOF) return EOF;
|
---|
| 176 | if (ch != EOF) sputc (ch);
|
---|
| 177 | return 0;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | static void page_errormaincfg (const text_t &gsdlhome, const text_t &collection) {
|
---|
| 181 |
|
---|
| 182 | if (collection.empty()) {
|
---|
| 183 | text_t message = "Error\n\n"
|
---|
| 184 | "The main.cfg configuration file could not be found. This file\n"
|
---|
| 185 | "should contain configuration information relating to the\n"
|
---|
| 186 | "setup of the interface. As this program is not being run\n"
|
---|
| 187 | "in collection specific mode the file should reside at\n" +
|
---|
| 188 | gsdlhome + "\\etc\\main.cfg.\n";
|
---|
| 189 |
|
---|
| 190 | MessageBox(NULL, message.getcstr(),
|
---|
| 191 | "Greenstone Digital Library Software"
|
---|
| 192 | ,MB_OK|MB_SYSTEMMODAL);
|
---|
| 193 | } else {
|
---|
| 194 | text_t message = "Neither the collect.cfg or main.cfg configuration files could\n"
|
---|
| 195 | "be found. This file should contain configuration information\n"
|
---|
| 196 | "relating to the setup of the interface. As this cgi script is\n"
|
---|
| 197 | "being run in collection specific mode the file should reside\n"
|
---|
| 198 | "at either " + gsdlhome + "\\collect\\" + collection + "\\etc\\collect.cfg,\n" +
|
---|
| 199 | gsdlhome + "\\etc\\collect.cfg or " + gsdlhome + "\\etc\\main.cfg.\n";
|
---|
| 200 |
|
---|
| 201 | MessageBox(NULL, message.getcstr(),
|
---|
| 202 | "Greenstone Digital Library Software"
|
---|
| 203 | ,MB_OK|MB_SYSTEMMODAL);
|
---|
| 204 | }
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | static void page_errorinit (const text_t &/*gsdlhome*/) {
|
---|
| 208 |
|
---|
| 209 | text_t message = "Error\n\n"
|
---|
| 210 | "An error occurred during the initialisation of the Greenstone Digital\n"
|
---|
| 211 | "Library software. It is likely that the software has not been setup\n"
|
---|
| 212 | "correctly.\n";
|
---|
| 213 |
|
---|
| 214 | MessageBox(NULL, message.getcstr(),
|
---|
| 215 | "Greenstone Digital Library Software"
|
---|
| 216 | ,MB_OK|MB_SYSTEMMODAL);
|
---|
| 217 | }
|
---|
| 218 |
|
---|
[2212] | 219 | static void page_errorparseargs (const text_t &/*gsdlhome*/) {
|
---|
[611] | 220 |
|
---|
| 221 | text_t message = "Error\n\n"
|
---|
| 222 | "An error occurred during the parsing of the cgi arguments.\n";
|
---|
| 223 |
|
---|
| 224 | MessageBox(NULL, message.getcstr(),
|
---|
| 225 | "Greenstone Digital Library Software"
|
---|
| 226 | ,MB_OK|MB_SYSTEMMODAL);
|
---|
| 227 | }
|
---|
| 228 |
|
---|
[2212] | 229 | static void page_errorcgipage (const text_t &/*gsdlhome*/) {
|
---|
[611] | 230 |
|
---|
| 231 | text_t message = "Error\n\n"
|
---|
| 232 | "An error occurred during the construction of the cgi page.\n";
|
---|
| 233 |
|
---|
| 234 | MessageBox(NULL, message.getcstr(),
|
---|
| 235 | "Greenstone Digital Library Software"
|
---|
| 236 | ,MB_OK|MB_SYSTEMMODAL);
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | // returns 0 if the directories can't be found
|
---|
| 240 | // and the user wants to quit (it returns 1
|
---|
| 241 | // if everything is ok)
|
---|
| 242 | int checkdir (const text_t &thedir) {
|
---|
| 243 | UINT curerrormode;
|
---|
| 244 | int drive = _getdrive();
|
---|
| 245 | char cwd[1024];
|
---|
| 246 | char rootpath[4];
|
---|
| 247 | UINT drivetype;
|
---|
| 248 | char *cstrthedir = thedir.getcstr();
|
---|
| 249 | int returnvalue = 1;
|
---|
| 250 |
|
---|
| 251 | // make sure no rude error messages are presented to the user
|
---|
| 252 | curerrormode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
|
---|
| 253 |
|
---|
| 254 | // get the drive name
|
---|
| 255 | if (thedir.size() >= 2 && thedir[1] == ':') {
|
---|
| 256 | if (thedir[0] >= 'a' && thedir[0] <= 'z') {
|
---|
| 257 | drive = thedir[0] - 'a' + 1;
|
---|
| 258 |
|
---|
| 259 | } else if (thedir[0] >= 'A' && thedir[0] <= 'Z') {
|
---|
| 260 | drive = thedir[0] - 'A' + 1;
|
---|
| 261 | }
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | // find the drive type
|
---|
| 265 | rootpath[0] = drive + 'A' - 1;
|
---|
| 266 | rootpath[1] = ':';
|
---|
| 267 | rootpath[2] = '\\';
|
---|
| 268 | rootpath[3] = '\0';
|
---|
| 269 | drivetype = GetDriveType (rootpath);
|
---|
| 270 |
|
---|
| 271 | // try and set this directory to be the current working
|
---|
| 272 | // directory
|
---|
| 273 | _getcwd(cwd, 1024);
|
---|
| 274 | while (_chdir(cstrthedir) != 0) {
|
---|
| 275 | // failed
|
---|
| 276 | if (drivetype == DRIVE_CDROM) {
|
---|
| 277 | // message to insert the cdrom
|
---|
| 278 | if (MessageBox (NULL,
|
---|
| 279 | "Please insert the Greenstone Digital Library\n"
|
---|
| 280 | "CD-ROM into the CD-ROM drive and press 'OK'.\n\n"
|
---|
| 281 | "If you don't have the CD-ROM press 'Cancel' to exit\n"
|
---|
| 282 | "this program.", "Greenstone Digital Library Software",
|
---|
| 283 | MB_OKCANCEL | MB_TASKMODAL) == IDCANCEL) {
|
---|
| 284 |
|
---|
| 285 | returnvalue = 0;
|
---|
| 286 | break;
|
---|
| 287 | }
|
---|
| 288 |
|
---|
| 289 | } else {
|
---|
| 290 | // message saying that the system was unable
|
---|
| 291 | // to find a certain directory
|
---|
| 292 | text_t message = "Failed to find the directory:\n\n" + thedir;
|
---|
| 293 | message += "\n\n"
|
---|
| 294 | "This directory is needed for the successful operation\n"
|
---|
| 295 | "of this software. Make sure it hasn't been deleted or\n"
|
---|
| 296 | "moved, and restart the software. You may need to\n"
|
---|
| 297 | "reinstall this software to correct the problem.";
|
---|
| 298 | char *cstrmessage = message.getcstr();
|
---|
| 299 |
|
---|
| 300 | MessageBox (NULL, cstrmessage, "Greenstone Digital Library Software",
|
---|
| 301 | MB_OK | MB_TASKMODAL);
|
---|
| 302 |
|
---|
[9636] | 303 | delete []cstrmessage;
|
---|
[611] | 304 |
|
---|
| 305 | returnvalue = 0;
|
---|
| 306 | break;
|
---|
| 307 | }
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | // revert to the previous error and cwd states
|
---|
| 311 | _chdir(cwd);
|
---|
| 312 | SetErrorMode(curerrormode);
|
---|
| 313 |
|
---|
| 314 | // free the allocated C string
|
---|
[9636] | 315 | delete []cstrthedir;
|
---|
[611] | 316 |
|
---|
| 317 | return returnvalue;
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 |
|
---|
| 321 | // c-string version of checkdir for the outside
|
---|
| 322 | // world
|
---|
| 323 | int cstrcheckdir (char *cstrthedir) {
|
---|
| 324 | return checkdir (cstrthedir);
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 |
|
---|
[6023] | 328 | receptionist recpt;
|
---|
| 329 | nullproto nproto;
|
---|
| 330 | collectset *cservers = NULL;
|
---|
| 331 |
|
---|
| 332 | textstreambuf textstream;
|
---|
| 333 | logstreambuf logstream;
|
---|
| 334 | DWORD lastlibaccesstime;
|
---|
| 335 | DWORD baseavailvirtual;
|
---|
| 336 | text_t current_gsdlhome;
|
---|
| 337 | colinfo_tmap translated_collectinfo;
|
---|
| 338 |
|
---|
| 339 | statusaction *astatusaction = NULL;
|
---|
| 340 | pageaction *apageaction = NULL;
|
---|
| 341 | pingaction *apingaction = NULL;
|
---|
| 342 | tipaction *atipaction = NULL;
|
---|
| 343 | queryaction *aqueryaction = NULL;
|
---|
| 344 | documentaction *adocumentaction = NULL;
|
---|
| 345 | usersaction *ausersaction = NULL;
|
---|
| 346 | extlinkaction *anextlinkaction = NULL;
|
---|
| 347 | collectoraction *acollectoraction = NULL;
|
---|
| 348 | authenaction *aauthenaction = NULL;
|
---|
| 349 | phindaction *aphindaction = NULL;
|
---|
| 350 | configaction *aconfigaction = NULL;
|
---|
| 351 | vlistbrowserclass *avlistbrowserclass = NULL;
|
---|
| 352 | hlistbrowserclass *ahlistbrowserclass = NULL;
|
---|
| 353 | datelistbrowserclass *adatelistbrowserclass = NULL;
|
---|
| 354 | invbrowserclass *ainvbrowserclass = NULL;
|
---|
| 355 | pagedbrowserclass *apagedbrowserclass = NULL;
|
---|
| 356 | htmlbrowserclass *ahtmlbrowserclass = NULL;
|
---|
| 357 | phindbrowserclass *aphindbrowserclass = NULL;
|
---|
| 358 |
|
---|
| 359 | // returns 1 if successful, 0 if unsuccessful (note that as well as being
|
---|
| 360 | // called when the server first starts up this function is called when the
|
---|
| 361 | // "restart library" button is pressed)
|
---|
| 362 | int gsdl_init (bool atStartup) {
|
---|
| 363 |
|
---|
| 364 | if (atStartup) {
|
---|
[1205] | 365 | #if defined (GSDL_USE_IOS_H)
|
---|
[6023] | 366 | cerr = &logstream;
|
---|
| 367 | cout = &textstream;
|
---|
[1205] | 368 | #else
|
---|
[6023] | 369 | cerr.rdbuf(&logstream);
|
---|
| 370 | cout.rdbuf(&textstream);
|
---|
[1205] | 371 | #endif
|
---|
[6023] | 372 | }
|
---|
[902] | 373 |
|
---|
[1615] | 374 | // collection should be set to "" unless in collection specific mode -
|
---|
| 375 | // changing this to the name of the collection should be all that's
|
---|
| 376 | // required to create a collection specific receptionist
|
---|
[611] | 377 | text_t collection = "";
|
---|
[2212] | 378 | text_tset gdbmhomes;
|
---|
[1739] | 379 | text_tset collections;
|
---|
[611] | 380 |
|
---|
[6023] | 381 | if (atStartup) {
|
---|
| 382 | // note the current time
|
---|
| 383 | lastlibaccesstime = GetTickCount();
|
---|
| 384 |
|
---|
| 385 | // before we do the init we should make sure
|
---|
| 386 | // that we can find the relevant directories
|
---|
| 387 | if (!checkdir (gsdl_gsdlhome + "\\")) return 0;
|
---|
| 388 | if (!checkdir (gsdl_gsdlhome + "\\macros\\")) return 0;
|
---|
| 389 | }
|
---|
[902] | 390 |
|
---|
[6023] | 391 | // deleting cservers clears all the collection servers
|
---|
| 392 | if (cservers != NULL) delete cservers;
|
---|
[902] | 393 |
|
---|
[6023] | 394 | cservers = new collectset();
|
---|
[1886] | 395 |
|
---|
[1739] | 396 | // get all collections from each gsdlhome (this relies
|
---|
| 397 | // on there not being more than one collection with the same
|
---|
| 398 | // name)
|
---|
| 399 | if (!collection.empty()) {
|
---|
| 400 | // collection specific receptionist - one collection, one gsdlhome
|
---|
| 401 | collections.insert (collection);
|
---|
[2212] | 402 | gdbmhomes.insert (gsdl_gdbmhome);
|
---|
[1739] | 403 | collectioninfo_t tmp;
|
---|
| 404 | tmp.gsdl_gsdlhome = gsdl_gsdlhome;
|
---|
| 405 | tmp.gsdl_gdbmhome = gsdl_gdbmhome;
|
---|
| 406 | translated_collectinfo[collection] = tmp;
|
---|
| 407 |
|
---|
| 408 | } else {
|
---|
| 409 |
|
---|
| 410 | text_tset::const_iterator colhere;
|
---|
| 411 | text_tset::const_iterator colend;
|
---|
| 412 | text_tset these_collections;
|
---|
| 413 |
|
---|
| 414 | // first volume gsdlhome's
|
---|
| 415 | colinfo_tmap::const_iterator this_info = gsdl_collectinfo.begin();
|
---|
| 416 | colinfo_tmap::const_iterator end_info = gsdl_collectinfo.end();
|
---|
[902] | 417 | while (this_info != end_info) {
|
---|
[2212] | 418 | if (gdbmhomes.find ((*this_info).second.gsdl_gdbmhome) == gdbmhomes.end()) {
|
---|
[1739] | 419 | these_collections.erase (these_collections.begin(), these_collections.end());
|
---|
| 420 | read_dir (filename_cat ((*this_info).second.gsdl_gsdlhome, "collect"), these_collections);
|
---|
| 421 | colhere = these_collections.begin();
|
---|
| 422 | colend = these_collections.end();
|
---|
| 423 | while (colhere != colend) {
|
---|
| 424 | if ((collections.find (*colhere)) == collections.end()) {
|
---|
| 425 | // make sure the build.cfg file is at gsdlhome (as it's possible that
|
---|
| 426 | // the collection appears at this gsdlhome only because it's gdbm
|
---|
| 427 | // file is installed here -- it's real gdbm will therefore be
|
---|
| 428 | // somewhere else).
|
---|
| 429 | text_t build_cfg = filename_cat ((*this_info).second.gsdl_gsdlhome, "collect",
|
---|
| 430 | *colhere, "index", "build.cfg");
|
---|
| 431 | if (file_exists (build_cfg)) {
|
---|
| 432 | collections.insert (*colhere);
|
---|
| 433 |
|
---|
| 434 | // since gsdl_collectinfo keys will be stuff like collection#1
|
---|
| 435 | // for a multiple volume collection we want to translate it
|
---|
| 436 | // so that the keys are the actual collection names
|
---|
| 437 | translated_collectinfo[*colhere] = (*this_info).second;
|
---|
| 438 | }
|
---|
| 439 | }
|
---|
[9598] | 440 | ++colhere;
|
---|
[1739] | 441 | }
|
---|
[2212] | 442 | gdbmhomes.insert ((*this_info).second.gsdl_gdbmhome);
|
---|
[902] | 443 | }
|
---|
[9598] | 444 | ++this_info;
|
---|
[902] | 445 | }
|
---|
[1739] | 446 |
|
---|
[2212] | 447 | // then if necessary the main gdbmhome (this should only happen if the
|
---|
| 448 | // gsdl.ini is a little screwed up and no volume gdbmhomes occurred)
|
---|
| 449 | if (gdbmhomes.find (gsdl_gdbmhome) == gdbmhomes.end()) {
|
---|
[1739] | 450 | these_collections.erase (these_collections.begin(), these_collections.end());
|
---|
[2212] | 451 | read_dir (filename_cat (gsdl_gdbmhome, "collect"), these_collections);
|
---|
[1739] | 452 | colhere = these_collections.begin();
|
---|
| 453 | colend = these_collections.end();
|
---|
| 454 | while (colhere != colend) {
|
---|
| 455 | collections.insert (*colhere);
|
---|
| 456 | collectioninfo_t tmp;
|
---|
| 457 | tmp.gsdl_gsdlhome = gsdl_gsdlhome;
|
---|
| 458 | tmp.gsdl_gdbmhome = gsdl_gdbmhome;
|
---|
| 459 | translated_collectinfo[*colhere] = tmp;
|
---|
[9598] | 460 | ++colhere;
|
---|
[1739] | 461 | }
|
---|
[2212] | 462 | gdbmhomes.insert (gsdl_gdbmhome);
|
---|
[1739] | 463 | }
|
---|
[902] | 464 | }
|
---|
| 465 |
|
---|
[1739] | 466 | text_tset::const_iterator thiscol = collections.begin();
|
---|
| 467 | text_tset::const_iterator endcol = collections.end();
|
---|
| 468 |
|
---|
[611] | 469 | while (thiscol != endcol) {
|
---|
| 470 |
|
---|
[1649] | 471 | // ignore the modelcol
|
---|
| 472 | if (*thiscol == "modelcol") {
|
---|
[9598] | 473 | ++thiscol;
|
---|
[1649] | 474 | continue;
|
---|
| 475 | }
|
---|
[611] | 476 |
|
---|
[1649] | 477 | // create collection server and add to null protocol
|
---|
[1739] | 478 | text_t this_gsdlhome = gsdl_gsdlhome;
|
---|
| 479 | text_t this_gdbmhome = gsdl_gdbmhome;
|
---|
| 480 | colinfo_tmap::const_iterator it = translated_collectinfo.find (*thiscol);
|
---|
| 481 | assert (it != translated_collectinfo.end());
|
---|
| 482 | this_gsdlhome = (*it).second.gsdl_gsdlhome;
|
---|
| 483 | this_gdbmhome = (*it).second.gsdl_gdbmhome;
|
---|
| 484 |
|
---|
[9117] | 485 | cservers->add_collection (*thiscol, this_gsdlhome);
|
---|
| 486 |
|
---|
[9598] | 487 | ++thiscol;
|
---|
[611] | 488 | }
|
---|
[1886] | 489 |
|
---|
| 490 | // set up the null protocol
|
---|
| 491 | nproto.set_collectset(cservers);
|
---|
[611] | 492 |
|
---|
[14388] | 493 | text_t userdbfile = filename_cat(gsdl_gsdlhome, "etc", "users.db");
|
---|
| 494 | userdbclass *udb = new userdbclass(userdbfile);
|
---|
| 495 |
|
---|
| 496 | text_t keydbfile = filename_cat(gsdl_gsdlhome, "etc", "key.db");
|
---|
| 497 | keydbclass *kdb = new keydbclass(keydbfile);
|
---|
| 498 |
|
---|
[611] | 499 | // add the protocol to the receptionist
|
---|
[6023] | 500 | if (atStartup) recpt.add_protocol (&nproto);
|
---|
[611] | 501 |
|
---|
| 502 | // the list of actions.
|
---|
[6023] | 503 | if (astatusaction == NULL) {
|
---|
| 504 | astatusaction = new statusaction();
|
---|
| 505 | astatusaction->set_receptionist (&recpt);
|
---|
| 506 | recpt.add_action (astatusaction);
|
---|
| 507 | }
|
---|
[611] | 508 |
|
---|
[6023] | 509 | if (apageaction == NULL) {
|
---|
| 510 | apageaction = new pageaction();
|
---|
| 511 | apageaction->set_receptionist (&recpt);
|
---|
| 512 | recpt.add_action (apageaction);
|
---|
| 513 | }
|
---|
[611] | 514 |
|
---|
[6023] | 515 | if (apingaction == NULL) {
|
---|
| 516 | apingaction = new pingaction();
|
---|
| 517 | recpt.add_action (apingaction);
|
---|
| 518 | }
|
---|
[611] | 519 |
|
---|
[6023] | 520 | if (atipaction == NULL) {
|
---|
| 521 | atipaction = new tipaction();
|
---|
| 522 | recpt.add_action (atipaction);
|
---|
| 523 | }
|
---|
[1193] | 524 |
|
---|
[6023] | 525 | if (aqueryaction == NULL) {
|
---|
| 526 | aqueryaction = new queryaction();
|
---|
| 527 | aqueryaction->set_receptionist (&recpt);
|
---|
| 528 | recpt.add_action (aqueryaction);
|
---|
| 529 | }
|
---|
[611] | 530 |
|
---|
[6023] | 531 | if (adocumentaction == NULL) {
|
---|
| 532 | adocumentaction = new documentaction();
|
---|
| 533 | adocumentaction->set_receptionist (&recpt);
|
---|
| 534 | recpt.add_action (adocumentaction);
|
---|
| 535 | }
|
---|
[611] | 536 |
|
---|
[6023] | 537 | if (ausersaction == NULL) {
|
---|
| 538 | ausersaction = new usersaction();
|
---|
[14388] | 539 | ausersaction->set_userdb(udb);
|
---|
[6023] | 540 | recpt.add_action (ausersaction);
|
---|
| 541 | }
|
---|
[902] | 542 |
|
---|
[6023] | 543 | if (anextlinkaction == NULL) {
|
---|
| 544 | anextlinkaction = new extlinkaction();
|
---|
| 545 | recpt.add_action (anextlinkaction);
|
---|
| 546 | }
|
---|
[902] | 547 |
|
---|
[6023] | 548 | if (acollectoraction == NULL) {
|
---|
| 549 | acollectoraction = new collectoraction();
|
---|
| 550 | acollectoraction->set_receptionist (&recpt);
|
---|
| 551 | recpt.add_action (acollectoraction);
|
---|
| 552 | }
|
---|
[611] | 553 |
|
---|
[6023] | 554 | if (aauthenaction == NULL) {
|
---|
| 555 | aauthenaction = new authenaction();
|
---|
[14388] | 556 | aauthenaction->set_userdb(udb);
|
---|
| 557 | aauthenaction->set_keydb(kdb);
|
---|
[6023] | 558 | aauthenaction->set_receptionist(&recpt);
|
---|
| 559 | recpt.add_action (aauthenaction);
|
---|
| 560 | }
|
---|
[902] | 561 |
|
---|
[6023] | 562 | if (aphindaction == NULL) {
|
---|
| 563 | aphindaction = new phindaction();
|
---|
| 564 | recpt.add_action (aphindaction);
|
---|
| 565 | }
|
---|
[4291] | 566 |
|
---|
[6023] | 567 | if (aconfigaction == NULL) {
|
---|
| 568 | aconfigaction = new configaction();
|
---|
| 569 | aconfigaction->set_receptionist(&recpt);
|
---|
| 570 | recpt.add_action (aconfigaction);
|
---|
| 571 | }
|
---|
[902] | 572 |
|
---|
[2487] | 573 |
|
---|
[902] | 574 | // list of browsers
|
---|
[6023] | 575 | if (avlistbrowserclass == NULL) {
|
---|
| 576 | avlistbrowserclass = new vlistbrowserclass();
|
---|
| 577 | recpt.add_browser (avlistbrowserclass);
|
---|
| 578 | recpt.setdefaultbrowser ("VList");
|
---|
| 579 | }
|
---|
[902] | 580 |
|
---|
[6023] | 581 | if (ahlistbrowserclass == NULL) {
|
---|
| 582 | ahlistbrowserclass = new hlistbrowserclass();
|
---|
| 583 | recpt.add_browser (ahlistbrowserclass);
|
---|
| 584 | }
|
---|
[902] | 585 |
|
---|
[6023] | 586 | if (adatelistbrowserclass == NULL) {
|
---|
| 587 | adatelistbrowserclass = new datelistbrowserclass();
|
---|
| 588 | recpt.add_browser (adatelistbrowserclass);
|
---|
| 589 | }
|
---|
[902] | 590 |
|
---|
[6023] | 591 | if (ainvbrowserclass == NULL) {
|
---|
| 592 | ainvbrowserclass = new invbrowserclass();
|
---|
| 593 | recpt.add_browser (ainvbrowserclass);
|
---|
| 594 | }
|
---|
[902] | 595 |
|
---|
[6023] | 596 | if (apagedbrowserclass == NULL) {
|
---|
| 597 | apagedbrowserclass = new pagedbrowserclass();
|
---|
| 598 | recpt.add_browser (apagedbrowserclass);
|
---|
| 599 | }
|
---|
[902] | 600 |
|
---|
[6023] | 601 | if (ahtmlbrowserclass == NULL) {
|
---|
| 602 | ahtmlbrowserclass = new htmlbrowserclass();
|
---|
| 603 | recpt.add_browser (ahtmlbrowserclass);
|
---|
| 604 | }
|
---|
[2487] | 605 |
|
---|
[6023] | 606 | if (aphindbrowserclass == NULL) {
|
---|
| 607 | aphindbrowserclass = new phindbrowserclass();;
|
---|
| 608 | recpt.add_browser (aphindbrowserclass);
|
---|
| 609 | }
|
---|
[611] | 610 |
|
---|
| 611 | // set defaults
|
---|
[902] | 612 | recpt.configure ("gsdlhome", gsdl_gsdlhome);
|
---|
[2212] | 613 | recpt.configure ("gdbmhome", gsdl_gdbmhome);
|
---|
[611] | 614 | recpt.configure ("collection", collection);
|
---|
| 615 |
|
---|
| 616 | int maxrequests = 1;
|
---|
[902] | 617 |
|
---|
[1739] | 618 | // configure collections (and receptionist) with collectinfo stuff
|
---|
[902] | 619 | // different from the default
|
---|
[1739] | 620 | colinfo_tmap::const_iterator this_info = translated_collectinfo.begin();
|
---|
| 621 | colinfo_tmap::const_iterator end_info = translated_collectinfo.end();
|
---|
| 622 |
|
---|
[902] | 623 | while (this_info != end_info) {
|
---|
[1739] | 624 | text_tarray tmpconf;
|
---|
| 625 | tmpconf.push_back ((*this_info).first);
|
---|
| 626 | tmpconf.push_back ((*this_info).second.gsdl_gsdlhome);
|
---|
| 627 | tmpconf.push_back ((*this_info).second.gsdl_gdbmhome);
|
---|
| 628 | recpt.configure ("collectinfo", tmpconf);
|
---|
[9598] | 629 | ++this_info;
|
---|
[611] | 630 | }
|
---|
| 631 |
|
---|
[2212] | 632 | // read in config files of each gdbmhome (in no particular order)
|
---|
[902] | 633 | // those read in last will override those read earlier
|
---|
| 634 | // collections being used together in this way should be
|
---|
[1193] | 635 | // careful not to have main.cfg files that might
|
---|
[902] | 636 | // screw with each other.
|
---|
[2212] | 637 | text_tset::const_iterator thome = gdbmhomes.begin();
|
---|
| 638 | text_tset::const_iterator ehome = gdbmhomes.end();
|
---|
[902] | 639 | while (thome != ehome) {
|
---|
[1011] | 640 | if (!main_cfg_read (recpt, *thome, collection)) {
|
---|
[902] | 641 | // couldn't find the main configuration file
|
---|
| 642 | page_errormaincfg (*thome, collection);
|
---|
| 643 | return 0;
|
---|
| 644 | }
|
---|
[9598] | 645 | ++thome;
|
---|
[902] | 646 | }
|
---|
| 647 |
|
---|
[2343] | 648 | // w32server relies on gwcgi being set to "gsdl"
|
---|
| 649 | recpt.configure ("gwcgi", "gsdl");
|
---|
[611] | 650 |
|
---|
| 651 | // initialise the library software
|
---|
| 652 | if (!recpt.init(cerr)) {
|
---|
| 653 | // an error occurred during the initialisation
|
---|
[902] | 654 | page_errorinit(gsdl_gsdlhome);
|
---|
[611] | 655 | return 0;
|
---|
| 656 | }
|
---|
| 657 |
|
---|
| 658 | // get memory information
|
---|
| 659 | MEMORYSTATUS memstatus;
|
---|
| 660 | memstatus.dwLength = sizeof(MEMORYSTATUS);
|
---|
| 661 | GlobalMemoryStatus(&memstatus);
|
---|
| 662 | baseavailvirtual = memstatus.dwAvailVirtual; // save for later comparison
|
---|
[1886] | 663 |
|
---|
[611] | 664 | return 1;
|
---|
| 665 | }
|
---|
| 666 |
|
---|
| 667 |
|
---|
[2286] | 668 | static void rememberpref (const text_t &tailstr) {
|
---|
| 669 | gsdl_enterlib = tailstr;
|
---|
[611] | 670 | }
|
---|
| 671 |
|
---|
| 672 |
|
---|
[2286] | 673 | static void send_file_from_disk(text_t filename,
|
---|
[611] | 674 | RequestInfoT *RInfo,
|
---|
[2286] | 675 | RequestFieldsT *RFields) {
|
---|
[611] | 676 |
|
---|
[2286] | 677 | // select appropriate mime type from file extension
|
---|
| 678 | text_t ext;
|
---|
| 679 | text_t::const_iterator end = filename.end();
|
---|
| 680 | text_t::const_iterator it = filename.begin();
|
---|
| 681 | text_t::const_iterator lastdot = end;
|
---|
| 682 | while ((it = findchar(it, end, '.')) != end) {
|
---|
| 683 | lastdot = it;
|
---|
[9598] | 684 | ++it;
|
---|
[611] | 685 | }
|
---|
[2286] | 686 | if (lastdot < end) ext = substr(lastdot+1, end);
|
---|
[611] | 687 |
|
---|
[2286] | 688 | text_t mime = "unknown";
|
---|
| 689 | int len = ext.size();
|
---|
[2997] | 690 | if (len == 2) {
|
---|
| 691 | if ((ext[0] == 'p' || ext[0] == 'P') &&
|
---|
| 692 | (ext[1] == 's' || ext[1] == 'S'))
|
---|
| 693 | mime = "application/postscript";
|
---|
| 694 | } else if (len == 3) {
|
---|
[2286] | 695 | if ((ext[0] == 'g' || ext[0] == 'G') &&
|
---|
| 696 | (ext[1] == 'i' || ext[1] == 'I') &&
|
---|
| 697 | (ext[2] == 'f' || ext[2] == 'F')) {
|
---|
| 698 | mime = "image/gif";
|
---|
| 699 | } else if ((ext[0] == 'j' || ext[0] == 'J') &&
|
---|
| 700 | (ext[1] == 'p' || ext[1] == 'P') &&
|
---|
| 701 | (ext[2] == 'g' || ext[2] == 'G')) {
|
---|
| 702 | mime = "image/jpeg";
|
---|
| 703 | } else if ((ext[0] == 'h' || ext[0] == 'H') &&
|
---|
| 704 | (ext[1] == 't' || ext[1] == 'T') &&
|
---|
| 705 | (ext[2] == 'm' || ext[2] == 'M')) {
|
---|
| 706 | mime = "text/html";
|
---|
[2293] | 707 | } else if ((ext[0] == 'p' || ext[0] == 'P') &&
|
---|
| 708 | (ext[1] == 'd' || ext[1] == 'D') &&
|
---|
| 709 | (ext[2] == 'f' || ext[2] == 'F')) {
|
---|
| 710 | mime = "application/pdf";
|
---|
[2997] | 711 | } else if ((ext[0] == 'p' || ext[0] == 'P') &&
|
---|
| 712 | (ext[1] == 'n' || ext[1] == 'N') &&
|
---|
| 713 | (ext[2] == 'g' || ext[2] == 'G')) {
|
---|
| 714 | mime = "image/png";
|
---|
[2293] | 715 | } else if ((ext[0] == 'd' || ext[0] == 'D') &&
|
---|
| 716 | (ext[1] == 'o' || ext[1] == 'O') &&
|
---|
| 717 | (ext[2] == 'c' || ext[2] == 'C')) {
|
---|
| 718 | mime = "application/msword";
|
---|
| 719 | } else if ((ext[0] == 'r' || ext[0] == 'R') &&
|
---|
| 720 | (ext[1] == 't' || ext[1] == 'T') &&
|
---|
| 721 | (ext[2] == 'f' || ext[2] == 'F')) {
|
---|
| 722 | mime = "application/rtf";
|
---|
[2997] | 723 | } else if ((ext[0] == 'x' || ext[0] == 'X') &&
|
---|
| 724 | (ext[1] == 'l' || ext[1] == 'L') &&
|
---|
| 725 | (ext[2] == 's' || ext[2] == 'S')) {
|
---|
| 726 | mime = "application/vnd.ms-excel";
|
---|
| 727 | } else if ((ext[0] == 'p' || ext[0] == 'P') &&
|
---|
| 728 | (ext[1] == 'p' || ext[1] == 'P') &&
|
---|
| 729 | (ext[2] == 'T' || ext[2] == 'T')) {
|
---|
| 730 | mime = "application/vnd.ms-powerpoint";
|
---|
[11055] | 731 | } else if ((ext[0] == 'm' || ext[0] == 'M') &&
|
---|
| 732 | (ext[1] == 'p' || ext[1] == 'P') &&
|
---|
| 733 | (ext[2] == '3')) {
|
---|
| 734 | mime = "audio/mpeg";
|
---|
[2286] | 735 | }
|
---|
| 736 | } else if (len == 4) {
|
---|
| 737 | if ((ext[0] == 'j' || ext[0] == 'J') &&
|
---|
| 738 | (ext[1] == 'p' || ext[1] == 'P') &&
|
---|
| 739 | (ext[2] == 'e' || ext[2] == 'E') &&
|
---|
| 740 | (ext[3] == 'g' || ext[3] == 'G')) {
|
---|
| 741 | mime = "image/jpeg";
|
---|
| 742 | } else if ((ext[0] == 'h' || ext[0] == 'H') &&
|
---|
| 743 | (ext[1] == 't' || ext[1] == 'T') &&
|
---|
| 744 | (ext[2] == 'm' || ext[2] == 'M') &&
|
---|
| 745 | (ext[3] == 'l' || ext[3] == 'L')) {
|
---|
| 746 | mime = "text/html";
|
---|
| 747 | }
|
---|
| 748 | }
|
---|
[611] | 749 |
|
---|
[2286] | 750 | // try to open the file
|
---|
| 751 | filename = filename_cat (current_gsdlhome, filename);
|
---|
[7519] | 752 | /* Feb 2002 - handle files with spaces in their name. */
|
---|
[3020] | 753 | text_t::iterator space_start;
|
---|
| 754 | space_start=findword(filename.begin(),filename.end(),"%20");
|
---|
[7519] | 755 | while (space_start != filename.end()) {
|
---|
[3020] | 756 | // we found a space...
|
---|
| 757 | text_t::iterator after_space=space_start+3;
|
---|
| 758 | text_t new_filename=substr(filename.begin(), space_start);
|
---|
| 759 | new_filename += " ";
|
---|
| 760 | new_filename += substr(after_space,filename.end());
|
---|
| 761 | filename=new_filename;
|
---|
[7519] | 762 | space_start=findword(filename.begin(),filename.end(),"%20");
|
---|
[3020] | 763 | }
|
---|
| 764 |
|
---|
[2286] | 765 | char *filenamec = filename.getcstr();
|
---|
[12761] | 766 | TranslateEscapeString(filenamec); // Resolve any %xx values
|
---|
[2286] | 767 | FILE *thefile = fopen(filenamec, "rb");
|
---|
[9636] | 768 | delete []filenamec;
|
---|
[611] | 769 | if (thefile == NULL) {
|
---|
| 770 | log_message("file not found\n");
|
---|
| 771 | send_retrieve_error(404, "File not found",
|
---|
| 772 | "Could not find the local file requested", RInfo);
|
---|
| 773 | return;
|
---|
| 774 | }
|
---|
[2286] | 775 | int nr;
|
---|
[611] | 776 | char buffer[2048];
|
---|
| 777 | // send back required information
|
---|
[2286] | 778 | char *mimec = mime.getcstr();
|
---|
| 779 | if (send_header(mimec, RInfo) >= 0) {
|
---|
[3810] | 780 | if (RFields->MethodStr != "HEAD") {
|
---|
[611] | 781 | for (;;) {
|
---|
| 782 | nr = fread(buffer, 1, 2048, thefile);
|
---|
| 783 | if (nr <= 0) break;
|
---|
| 784 | if (SendData(RInfo->ClientSocket,
|
---|
| 785 | (BYTE *)buffer, nr,
|
---|
| 786 | RInfo->ThreadNum) < 0) break;
|
---|
| 787 | }
|
---|
| 788 | }
|
---|
| 789 | }
|
---|
[9636] | 790 | delete []mimec;
|
---|
[611] | 791 | fclose(thefile);
|
---|
| 792 | }
|
---|
| 793 |
|
---|
[2286] | 794 | static void handle_library_request(const text_t &argstr, RequestInfoT *RInfo,
|
---|
[611] | 795 | RequestFieldsT *RequestFields) {
|
---|
| 796 |
|
---|
| 797 | // parse the cgi arguments and produce the resulting page if there
|
---|
[2286] | 798 | // have been no errors so far
|
---|
[611] | 799 | cgiargsclass args;
|
---|
[12527] | 800 | fileupload_tmap fileuploads;
|
---|
[902] | 801 | text_tmap empty; // don't use this (it's for fastcgi on unix)
|
---|
[12527] | 802 | if (!recpt.parse_cgi_args (argstr, fileuploads, args, cerr, empty)) {
|
---|
[902] | 803 | page_errorparseargs(gsdl_gsdlhome);
|
---|
[611] | 804 | return;
|
---|
| 805 | }
|
---|
[1739] | 806 |
|
---|
| 807 | colinfo_tmap::const_iterator it = translated_collectinfo.find (args["c"]);
|
---|
| 808 | if (it != translated_collectinfo.end()) {
|
---|
| 809 | current_gsdlhome = (*it).second.gsdl_gsdlhome;
|
---|
| 810 | } else {
|
---|
| 811 | current_gsdlhome = gsdl_gsdlhome;
|
---|
| 812 | }
|
---|
| 813 |
|
---|
[611] | 814 | // produce cgi header
|
---|
| 815 | response_t response;
|
---|
| 816 | text_t response_data;
|
---|
| 817 |
|
---|
[902] | 818 | recpt.get_cgihead_info (args, response, response_data, cerr, empty);
|
---|
[611] | 819 |
|
---|
| 820 | if (response == location) {
|
---|
| 821 | // location response
|
---|
[902] | 822 | response_data = "@" + recpt.expandmacros (response_data, args, cerr);
|
---|
| 823 | char *response_data_c = response_data.getcstr();
|
---|
| 824 | send_header(response_data_c, RInfo);
|
---|
[9636] | 825 | delete []response_data_c;
|
---|
[902] | 826 | return;
|
---|
[611] | 827 | } else if (response == content) {
|
---|
| 828 | // content response
|
---|
[902] | 829 | char *response_data_c = response_data.getcstr();
|
---|
| 830 | if (send_header(response_data_c, RInfo) < 0) {
|
---|
[9636] | 831 | delete []response_data_c;
|
---|
[902] | 832 | return;
|
---|
| 833 | }
|
---|
[9636] | 834 | delete []response_data_c;
|
---|
[9138] | 835 | }
|
---|
| 836 | else if (response == undecided_location) {
|
---|
| 837 | // We know this is a relocation request but at the moment we don't know exactly where to
|
---|
| 838 | // Just output the start of the header and wait until later to output the target location
|
---|
| 839 | // Used for the "I'm feeling lucky" functionality
|
---|
| 840 | cout << "HTTP/1.0 302 Relocation\r\n";
|
---|
| 841 | cout << "Server: GSDL\r\n";
|
---|
| 842 | cout << "Content-type: text/html \r\n";
|
---|
| 843 | }
|
---|
| 844 | else {
|
---|
[611] | 845 | // unknown response
|
---|
| 846 | cerr << "Error: get_cgihead_info returned an unknown response type.\n";
|
---|
| 847 | return;
|
---|
| 848 | }
|
---|
| 849 |
|
---|
| 850 | textstream.tsbreset();
|
---|
| 851 | textstream.setrequestinfo (RInfo);
|
---|
| 852 | if (!recpt.produce_content (args, cout, cerr)) {
|
---|
[902] | 853 | page_errorcgipage(gsdl_gsdlhome);
|
---|
[611] | 854 | return;
|
---|
| 855 | }
|
---|
[902] | 856 | recpt.log_cgi_args (args, cerr, empty);
|
---|
[611] | 857 |
|
---|
| 858 | cout << flush;
|
---|
| 859 | cerr << flush;
|
---|
| 860 |
|
---|
[9598] | 861 | ++libaccessnum;
|
---|
[611] | 862 | }
|
---|
| 863 |
|
---|
[2286] | 864 | static void handle_server_request(text_t &tailstr,
|
---|
[611] | 865 | RequestInfoT *RequestInfo,
|
---|
| 866 | RequestFieldsT *RequestFields) {
|
---|
| 867 |
|
---|
[2286] | 868 | text_t argstr;
|
---|
| 869 |
|
---|
[611] | 870 | // do any url adjustments necessary
|
---|
[2286] | 871 | if (tailstr.empty() || tailstr == "/") {
|
---|
[2343] | 872 | tailstr = "/gsdl";
|
---|
[2286] | 873 | }
|
---|
| 874 |
|
---|
| 875 | text_t::const_iterator begin = tailstr.begin();
|
---|
| 876 | text_t::const_iterator end = tailstr.end();
|
---|
[611] | 877 |
|
---|
| 878 | // test to see if this is a library request or a local
|
---|
| 879 | // file request
|
---|
[2343] | 880 | if ((tailstr == "/gsdl") ||
|
---|
| 881 | ((tailstr.size() > 5) && (substr(begin, begin+6) == "/gsdl?"))) {
|
---|
[2286] | 882 |
|
---|
[611] | 883 | // library request
|
---|
| 884 |
|
---|
[2286] | 885 | // argstr is the bit after the '?'
|
---|
[2343] | 886 | if (tailstr != "/gsdl") {
|
---|
| 887 | argstr = substr(begin+6, end);
|
---|
[2286] | 888 | }
|
---|
| 889 |
|
---|
[611] | 890 | // log the difference in access times
|
---|
| 891 | DWORD thislibaccesstime = GetTickCount();
|
---|
[2286] | 892 | if (gsdl_keep_log || gsdl_show_console) {
|
---|
| 893 | char logstr[256];
|
---|
| 894 | sprintf(logstr, "DELTA LIB ACCESS TIME: %i\n", (int)(thislibaccesstime - lastlibaccesstime));
|
---|
| 895 | log_message (logstr);
|
---|
[611] | 896 | }
|
---|
| 897 | lastlibaccesstime = thislibaccesstime;
|
---|
| 898 |
|
---|
| 899 | // log this request
|
---|
[2286] | 900 | if (gsdl_keep_log || gsdl_show_console) {
|
---|
| 901 | text_t logstr = "LOCAL LIB: " + tailstr + "\n";
|
---|
| 902 | char *logstrc = logstr.getcstr();
|
---|
| 903 | log_message (logstrc);
|
---|
[9636] | 904 | delete []logstrc;
|
---|
[611] | 905 | }
|
---|
| 906 |
|
---|
[2286] | 907 | handle_library_request (argstr, RequestInfo, RequestFields);
|
---|
[611] | 908 |
|
---|
| 909 | // remember the preferences
|
---|
[2286] | 910 | // rememberpref (tailstr);
|
---|
[611] | 911 |
|
---|
| 912 | // log memory information
|
---|
[2286] | 913 | if (gsdl_keep_log || gsdl_show_console) {
|
---|
[611] | 914 | MEMORYSTATUS memstatus;
|
---|
| 915 | memstatus.dwLength = sizeof(MEMORYSTATUS);
|
---|
| 916 | GlobalMemoryStatus(&memstatus);
|
---|
[2286] | 917 | char logstr[256];
|
---|
| 918 | sprintf (logstr, "BDELTA AVAIL VIRTUAL: %i K\n",
|
---|
[611] | 919 | (int)((baseavailvirtual - memstatus.dwAvailVirtual)/1024));
|
---|
[2286] | 920 | log_message (logstr);
|
---|
[611] | 921 | }
|
---|
| 922 |
|
---|
| 923 | } else {
|
---|
| 924 | // local file
|
---|
[2286] | 925 | if (gsdl_keep_log || gsdl_show_console) {
|
---|
| 926 | text_t logstr = "LOCAL FILE: " + tailstr + "\n";
|
---|
| 927 | char *logstrc = logstr.getcstr();
|
---|
| 928 | log_message (logstrc);
|
---|
[9636] | 929 | delete []logstrc;
|
---|
[611] | 930 | }
|
---|
| 931 | send_file_from_disk (tailstr, RequestInfo, RequestFields);
|
---|
| 932 | }
|
---|
| 933 | }
|
---|
| 934 |
|
---|
[2280] | 935 | int ExamineURIStr(text_t &URIStr, RequestInfoT *RequestInfo,
|
---|
[611] | 936 | RequestFieldsT *RequestFields)
|
---|
| 937 | {
|
---|
[2286] | 938 | text_t protocol, machine, rest;
|
---|
| 939 | int port;
|
---|
[1624] | 940 |
|
---|
| 941 | if (RequestFields->ContentLength > 0) {
|
---|
| 942 | // POST data
|
---|
[2280] | 943 | URIStr.push_back('?');
|
---|
[9598] | 944 | for (int i = 0; i < RequestFields->ContentLength; ++i) {
|
---|
[2286] | 945 | URIStr.push_back(RequestFields->Content[i]);
|
---|
| 946 | }
|
---|
[1624] | 947 | }
|
---|
[2280] | 948 |
|
---|
[2286] | 949 | if (parse_url(URIStr, protocol, machine, &port, rest)!=http_ok) {
|
---|
| 950 | // Alter local file request to address 'gsdl'
|
---|
| 951 | if (*(URIStr.begin()) != '/') URIStr = "http://gsdl/" + URIStr;
|
---|
| 952 | else URIStr = "http://gsdl" + URIStr;
|
---|
| 953 | parse_url(URIStr, protocol, machine, &port, rest);
|
---|
[611] | 954 | }
|
---|
| 955 |
|
---|
[2286] | 956 | if (machine == "gsdl") {
|
---|
[611] | 957 | // a local file request
|
---|
| 958 | handle_server_request(rest, RequestInfo, RequestFields);
|
---|
| 959 |
|
---|
| 960 | } else {
|
---|
| 961 | send_retrieve_error(404, "File not found",
|
---|
| 962 | "Could not find the local file requested", RequestInfo);
|
---|
| 963 | }
|
---|
| 964 |
|
---|
| 965 | return 1;
|
---|
| 966 | }
|
---|