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