[144] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * cgiwrapper.cpp -- output pages using the cgi protocol
|
---|
| 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.
|
---|
[144] | 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 | *
|
---|
[144] | 24 | *********************************************************************/
|
---|
| 25 |
|
---|
[12794] | 26 | #include <stdio.h>
|
---|
[18882] | 27 | #include <cstring>
|
---|
[12794] | 28 | #ifdef __WIN32__
|
---|
| 29 | #include <fcntl.h>
|
---|
| 30 | #endif
|
---|
| 31 |
|
---|
[144] | 32 | #include "gsdlconf.h"
|
---|
| 33 | #include "cgiwrapper.h"
|
---|
[15402] | 34 | #include "gsdlsitecfg.h"
|
---|
| 35 | #include "maincfg.h"
|
---|
[963] | 36 | #include "fileutil.h"
|
---|
[12514] | 37 | #include "cgiutils.h"
|
---|
[144] | 38 | #include <stdlib.h>
|
---|
[872] | 39 | #include <assert.h>
|
---|
[144] | 40 |
|
---|
| 41 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
| 42 | # include <ospace/std/iostream>
|
---|
| 43 | # include <ospace/std/fstream>
|
---|
| 44 | #elif defined(GSDL_USE_IOS_H)
|
---|
| 45 | # include <iostream.h>
|
---|
| 46 | # include <fstream.h>
|
---|
| 47 | #else
|
---|
| 48 | # include <iostream>
|
---|
| 49 | # include <fstream>
|
---|
| 50 | #endif
|
---|
| 51 |
|
---|
| 52 | #ifdef USE_FASTCGI
|
---|
| 53 | #include "fcgiapp.h"
|
---|
| 54 | #endif
|
---|
| 55 |
|
---|
[22142] | 56 | #include "authenaction.h"
|
---|
| 57 | #include "browseaction.h"
|
---|
| 58 | #include "collectoraction.h"
|
---|
| 59 | #include "depositoraction.h"
|
---|
| 60 | #include "documentaction.h"
|
---|
| 61 | #include "dynamicclassifieraction.h"
|
---|
| 62 | #include "extlinkaction.h"
|
---|
| 63 | #include "pageaction.h"
|
---|
| 64 | #ifdef ENABLE_MGPP
|
---|
| 65 | #include "phindaction.h"
|
---|
| 66 | #endif
|
---|
| 67 | #include "pingaction.h"
|
---|
| 68 | #include "queryaction.h"
|
---|
[387] | 69 |
|
---|
[22142] | 70 | #if defined(USE_SQLITE)
|
---|
| 71 | #include "sqlqueryaction.h"
|
---|
| 72 | #endif
|
---|
| 73 |
|
---|
[28973] | 74 | #if defined(GSDL_USE_GTI_ACTION)
|
---|
| 75 | #include "gtiaction.h"
|
---|
| 76 | #endif
|
---|
| 77 |
|
---|
[24958] | 78 | #if defined(USE_RSS)
|
---|
| 79 | #include "rssaction.h"
|
---|
| 80 | #endif
|
---|
| 81 |
|
---|
[22142] | 82 | #include "tipaction.h"
|
---|
| 83 | #include "statusaction.h"
|
---|
| 84 | #include "usersaction.h"
|
---|
| 85 | #include "configaction.h"
|
---|
| 86 |
|
---|
| 87 | #include "vlistbrowserclass.h"
|
---|
| 88 | #include "hlistbrowserclass.h"
|
---|
| 89 | #include "datelistbrowserclass.h"
|
---|
| 90 | #include "invbrowserclass.h"
|
---|
| 91 | #include "pagedbrowserclass.h"
|
---|
| 92 | #include "htmlbrowserclass.h"
|
---|
| 93 | #include "phindbrowserclass.h"
|
---|
| 94 |
|
---|
| 95 |
|
---|
[144] | 96 | #ifdef USE_FASTCGI
|
---|
| 97 | // used to output the text from receptionist
|
---|
| 98 | class fcgistreambuf : public streambuf {
|
---|
| 99 | public:
|
---|
| 100 | fcgistreambuf ();
|
---|
| 101 | int sync ();
|
---|
| 102 | int overflow (int ch);
|
---|
| 103 | int underflow () {return EOF;}
|
---|
| 104 |
|
---|
| 105 | void fcgisbreset() {fcgx_stream = NULL; other_ostream = NULL;};
|
---|
| 106 | void set_fcgx_stream(FCGX_Stream *newone) {fcgx_stream=newone;};
|
---|
| 107 | void set_other_ostream(ostream *newone) {other_ostream=newone;};
|
---|
| 108 |
|
---|
| 109 | private:
|
---|
| 110 | FCGX_Stream *fcgx_stream;
|
---|
| 111 | ostream *other_ostream;
|
---|
| 112 | };
|
---|
| 113 |
|
---|
| 114 | fcgistreambuf::fcgistreambuf() {
|
---|
| 115 | fcgisbreset();
|
---|
| 116 | if (base() == ebuf()) allocate();
|
---|
| 117 | setp (base(), ebuf());
|
---|
| 118 | };
|
---|
| 119 |
|
---|
| 120 | int fcgistreambuf::sync () {
|
---|
| 121 | if ((fcgx_stream != NULL) &&
|
---|
| 122 | (FCGX_PutStr (pbase(), out_waiting(), fcgx_stream) < 0)) {
|
---|
| 123 | fcgx_stream = NULL;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | if (other_ostream != NULL) {
|
---|
| 127 | char *thepbase=pbase();
|
---|
[9620] | 128 | for (int i=0;i<out_waiting();++i) (*other_ostream).put(thepbase[i]);
|
---|
[144] | 129 | }
|
---|
| 130 |
|
---|
| 131 | setp (pbase(), epptr());
|
---|
| 132 |
|
---|
| 133 | return 0;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | int fcgistreambuf::overflow (int ch) {
|
---|
| 137 | if (sync () == EOF) return EOF;
|
---|
| 138 | if (ch != EOF) sputc (ch);
|
---|
| 139 | return 0;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | #endif
|
---|
| 143 |
|
---|
[1089] | 144 | static void format_error_string (text_t &errorpage, const text_t &errortext, bool debug) {
|
---|
[144] | 145 |
|
---|
[1089] | 146 | errorpage.clear();
|
---|
[144] | 147 |
|
---|
[1089] | 148 | if (debug) {
|
---|
| 149 | errorpage += "\n";
|
---|
| 150 | errorpage += "ERROR: " + errortext;
|
---|
| 151 | errorpage += "\n";
|
---|
| 152 |
|
---|
| 153 | } else {
|
---|
| 154 |
|
---|
| 155 | errorpage += "Content-type: text/html\n\n";
|
---|
| 156 |
|
---|
| 157 | errorpage += "<html>\n";
|
---|
| 158 | errorpage += "<head>\n";
|
---|
| 159 | errorpage += "<title>Error</title>\n";
|
---|
| 160 | errorpage += "</head>\n";
|
---|
| 161 | errorpage += "<body>\n";
|
---|
| 162 | errorpage += "<h2>Oops!</h2>\n";
|
---|
| 163 | errorpage += errortext;
|
---|
| 164 | errorpage += "</body>\n";
|
---|
| 165 | errorpage += "</html>\n";
|
---|
| 166 | }
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | static void page_errorcollect (const text_t &gsdlhome, text_t &errorpage, bool debug) {
|
---|
| 170 |
|
---|
[16310] | 171 | text_t collecthome = filename_cat (gsdlhome, "collect");
|
---|
[1089] | 172 |
|
---|
| 173 | text_t errortext = "No valid collections were found: Check that your collect directory\n";
|
---|
[16310] | 174 | errortext += "(" + collecthome + ") is readable and contains at least one valid collection.\n";
|
---|
[1089] | 175 | errortext += "Note that modelcol is NOT a valid collection.\n";
|
---|
| 176 | errortext += "If the path to your collect directory is wrong edit the 'gsdlhome' field\n";
|
---|
| 177 | errortext += "in your gsdlsite.cfg configuration file.\n";
|
---|
| 178 |
|
---|
| 179 | format_error_string (errorpage, errortext, debug);
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | static void page_errorsitecfg (text_t &errorpage, bool debug, int mode) {
|
---|
| 183 |
|
---|
| 184 | text_t errortext;
|
---|
| 185 |
|
---|
[963] | 186 | if (mode == 0) {
|
---|
[1090] | 187 | errortext += "The gsdlsite.cfg configuration file could not be found. This\n";
|
---|
| 188 | errortext += "file should contain configuration information relating to this\n";
|
---|
| 189 | errortext += "site's setup.\n";
|
---|
| 190 |
|
---|
[963] | 191 | } else if (mode == 1) {
|
---|
[1090] | 192 | errortext += "The gsdlsite.cfg configuration file does not contain a valid\n";
|
---|
| 193 | errortext += "gsdlhome entry.\n";
|
---|
[155] | 194 | }
|
---|
[1089] | 195 |
|
---|
[1090] | 196 | if (debug) {
|
---|
| 197 | errortext += "gsdlsite.cfg should reside in the directory from which the\n";
|
---|
| 198 | errortext += "library executable was run.\n";
|
---|
| 199 | } else {
|
---|
| 200 | errortext += "gsdlsite.cfg should reside in the same directory as the library\n";
|
---|
| 201 | errortext += "executable file.\n";
|
---|
| 202 | }
|
---|
| 203 |
|
---|
[1089] | 204 | format_error_string (errorpage, errortext, debug);
|
---|
[155] | 205 | }
|
---|
[144] | 206 |
|
---|
[155] | 207 |
|
---|
| 208 | static void page_errormaincfg (const text_t &gsdlhome, const text_t &collection,
|
---|
[1089] | 209 | bool debug, text_t &errorpage) {
|
---|
[155] | 210 |
|
---|
[1089] | 211 | text_t errortext;
|
---|
| 212 |
|
---|
[144] | 213 | if (collection.empty()) {
|
---|
[963] | 214 | text_t main_cfg_file = filename_cat (gsdlhome, "etc", "main.cfg");
|
---|
[1089] | 215 | errortext += "The main.cfg configuration file could not be found. This file\n";
|
---|
| 216 | errortext += "should contain configuration information relating to the\n";
|
---|
| 217 | errortext += "setup of the interface. As this receptionist is not being run\n";
|
---|
| 218 | errortext += "in collection specific mode the file should reside at\n";
|
---|
| 219 | errortext += main_cfg_file + ".\n";
|
---|
[144] | 220 | } else {
|
---|
[963] | 221 | text_t collect_cfg_file = filename_cat (gsdlhome, "collect", collection, "etc", "collect.cfg");
|
---|
| 222 | text_t main_collect_cfg_file = filename_cat (gsdlhome, "etc", "collect.cfg");
|
---|
| 223 | text_t main_cfg_file = filename_cat (gsdlhome, "etc", "main.cfg");
|
---|
[1089] | 224 | errortext += "Either the collect.cfg or main.cfg configuration file could\n";
|
---|
| 225 | errortext += "not be found. This file should contain configuration information\n";
|
---|
| 226 | errortext += "relating to the setup of the interface. As this receptionist is\n";
|
---|
| 227 | errortext += "being run in collection specific mode the file should reside\n";
|
---|
| 228 | errortext += "at either " + collect_cfg_file + ",\n";
|
---|
| 229 | errortext += main_collect_cfg_file + " or " + main_cfg_file + ".\n";
|
---|
[144] | 230 | }
|
---|
[1089] | 231 |
|
---|
| 232 | format_error_string (errorpage, errortext, debug);
|
---|
[144] | 233 | }
|
---|
| 234 |
|
---|
| 235 |
|
---|
[1089] | 236 | static void page_errorinit (const text_t &gsdlhome, bool debug, text_t &errorpage) {
|
---|
[150] | 237 |
|
---|
[1089] | 238 | text_t errortext = "An error occurred during the initialisation of the Greenstone Digital\n";
|
---|
| 239 | errortext += "Library software. It is likely that the software has not been setup\n";
|
---|
| 240 | errortext += "correctly.\n";
|
---|
[144] | 241 |
|
---|
[2939] | 242 | text_t error_file = filename_cat (gsdlhome, "etc", "error.txt");
|
---|
[23389] | 243 | // This is all commented out because I think it's a really bad idea
|
---|
| 244 | // The error.txt file may be very large, causing out of memory problems and even crashing the machine in extreme
|
---|
| 245 | // cases where multiple processes are causing this type of error (e.g. automated processes that try to "hack"
|
---|
| 246 | // the Greenstone site by supplying values such as site URLs for the CGI arguments -- this has happened)
|
---|
| 247 | // Also, the error.txt may contain information that shouldn't be exposed (such as usage or query information)
|
---|
| 248 | // Maybe this should be configurable through a main.cfg configuration setting, but I don't think it's worth it
|
---|
| 249 | // The only people who should need the contents of this file should have access to it through the file system
|
---|
| 250 | // I think you can also view the contents of this file through the statusaction if you have a suitable login
|
---|
| 251 | // char *efile = error_file.getcstr();
|
---|
| 252 | // ifstream errin (efile);
|
---|
| 253 | // delete []efile;
|
---|
| 254 | // if (errin) {
|
---|
| 255 | // errortext += "The error log, " + error_file + ", contains the\n";
|
---|
| 256 | // errortext += "following information:\n\n";
|
---|
| 257 | // if (!debug) errortext += "<pre>\n";
|
---|
[155] | 258 |
|
---|
[23389] | 259 | // char c;
|
---|
| 260 | // errin.get(c);
|
---|
| 261 | // while (!errin.eof ()) {
|
---|
| 262 | // errortext.push_back(c);
|
---|
| 263 | // errin.get(c);
|
---|
| 264 | // }
|
---|
[155] | 265 |
|
---|
[23389] | 266 | // if (!debug) errortext += "</pre>\n";
|
---|
[155] | 267 |
|
---|
[23389] | 268 | // errin.close();
|
---|
[155] | 269 |
|
---|
[23389] | 270 | // } else {
|
---|
[2939] | 271 | errortext += "Please consult " + error_file + " for more information.\n";
|
---|
[23389] | 272 | // }
|
---|
[155] | 273 |
|
---|
[1089] | 274 | format_error_string (errorpage, errortext, debug);
|
---|
[150] | 275 | }
|
---|
| 276 |
|
---|
[1089] | 277 | static void page_errorparseargs (const text_t &gsdlhome, bool debug, text_t &errorpage) {
|
---|
[150] | 278 |
|
---|
[1089] | 279 | text_t errortext = "An error occurred during the parsing of the cgi arguments.\n";
|
---|
[150] | 280 |
|
---|
[2939] | 281 | text_t error_file = filename_cat (gsdlhome, "etc", "error.txt");
|
---|
[23389] | 282 | // This is all commented out because I think it's a really bad idea
|
---|
| 283 | // The error.txt file may be very large, causing out of memory problems and even crashing the machine in extreme
|
---|
| 284 | // cases where multiple processes are causing this type of error (e.g. automated processes that try to "hack"
|
---|
| 285 | // the Greenstone site by supplying values such as site URLs for the CGI arguments -- this has happened)
|
---|
| 286 | // Also, the error.txt may contain information that shouldn't be exposed (such as usage or query information)
|
---|
| 287 | // Maybe this should be configurable through a main.cfg configuration setting, but I don't think it's worth it
|
---|
| 288 | // The only people who should need the contents of this file should have access to it through the file system
|
---|
| 289 | // I think you can also view the contents of this file through the statusaction if you have a suitable login
|
---|
| 290 | // char *efile = error_file.getcstr();
|
---|
| 291 | // ifstream errin (efile);
|
---|
| 292 | // delete []efile;
|
---|
| 293 | // if (errin) {
|
---|
| 294 | // errortext += "The error log, " + error_file + ", contains the\n";
|
---|
| 295 | // errortext += "following information:\n\n";
|
---|
| 296 | // if (!debug) errortext += "<pre>\n";
|
---|
[150] | 297 |
|
---|
[23389] | 298 | // char c;
|
---|
| 299 | // errin.get(c);
|
---|
| 300 | // while (!errin.eof ()) {
|
---|
| 301 | // errortext.push_back(c);
|
---|
| 302 | // errin.get(c);
|
---|
| 303 | // }
|
---|
| 304 | // if (!debug) errortext += "</pre>\n";
|
---|
| 305 | // errin.close();
|
---|
[155] | 306 |
|
---|
[23389] | 307 | // } else {
|
---|
[1089] | 308 | errortext += "Please consult " + error_file + " for more information.\n";
|
---|
[23389] | 309 | // }
|
---|
[155] | 310 |
|
---|
[1089] | 311 | format_error_string (errorpage, errortext, debug);
|
---|
[144] | 312 | }
|
---|
| 313 |
|
---|
[1089] | 314 | static void page_errorcgipage (const text_t &gsdlhome, bool debug, text_t &errorpage) {
|
---|
[144] | 315 |
|
---|
[1089] | 316 | text_t errortext = "An error occurred during the construction of the cgi page.\n";
|
---|
[155] | 317 |
|
---|
[2939] | 318 | text_t error_file = filename_cat (gsdlhome, "etc", "error.txt");
|
---|
[23389] | 319 | // This is all commented out because I think it's a really bad idea
|
---|
| 320 | // The error.txt file may be very large, causing out of memory problems and even crashing the machine in extreme
|
---|
| 321 | // cases where multiple processes are causing this type of error (e.g. automated processes that try to "hack"
|
---|
| 322 | // the Greenstone site by supplying values such as site URLs for the CGI arguments -- this has happened)
|
---|
| 323 | // Also, the error.txt may contain information that shouldn't be exposed (such as usage or query information)
|
---|
| 324 | // Maybe this should be configurable through a main.cfg configuration setting, but I don't think it's worth it
|
---|
| 325 | // The only people who should need the contents of this file should have access to it through the file system
|
---|
| 326 | // I think you can also view the contents of this file through the statusaction if you have a suitable login
|
---|
| 327 | // char *efile = error_file.getcstr();
|
---|
| 328 | // ifstream errin (efile);
|
---|
| 329 | // delete []efile;
|
---|
| 330 | // if (errin) {
|
---|
| 331 | // errortext += "The error log, " + error_file + ", contains the\n";
|
---|
| 332 | // errortext += "following information:\n\n";
|
---|
| 333 | // if (!debug) errortext += "<pre>\n";
|
---|
[155] | 334 |
|
---|
[23389] | 335 | // char c;
|
---|
| 336 | // errin.get(c);
|
---|
| 337 | // while (!errin.eof ()) {
|
---|
| 338 | // errortext.push_back(c);
|
---|
| 339 | // errin.get(c);
|
---|
| 340 | // }
|
---|
| 341 | // if (!debug) errortext += "</pre>\n";
|
---|
| 342 | // errin.close();
|
---|
[155] | 343 |
|
---|
[23389] | 344 | // } else {
|
---|
[1089] | 345 | errortext += "Please consult " + error_file + " for more information.\n";
|
---|
[23389] | 346 | // }
|
---|
[155] | 347 |
|
---|
[1089] | 348 | format_error_string (errorpage, errortext, debug);
|
---|
[155] | 349 | }
|
---|
| 350 |
|
---|
[1089] | 351 | static void print_debug_info (receptionist &recpt) {
|
---|
[155] | 352 |
|
---|
| 353 | outconvertclass text_t2ascii;
|
---|
[1864] | 354 | const recptconf &configinfo = recpt.get_configinfo ();
|
---|
[1089] | 355 | text_t etc_dir = filename_cat (configinfo.gsdlhome, "etc");
|
---|
[144] | 356 |
|
---|
[1089] | 357 | cout << "\n";
|
---|
| 358 | cout << text_t2ascii
|
---|
| 359 | << "------------------------------------------------------------\n"
|
---|
| 360 | << "Configuration and initialization completed successfully.\n"
|
---|
| 361 | << " Note that more debug information may be available in the\n"
|
---|
[2939] | 362 | << " initialization and error log error.txt in " << etc_dir << ".\n"
|
---|
[1089] | 363 | << "------------------------------------------------------------\n\n";
|
---|
[144] | 364 |
|
---|
[1089] | 365 | bool colspec = false;
|
---|
| 366 | if (configinfo.collection.empty()) {
|
---|
[16310] | 367 | cout << "Receptionist is running in \"general\" (i.e. not \"collection "
|
---|
[1097] | 368 | << "specific\") mode.\n";
|
---|
[1089] | 369 | } else {
|
---|
| 370 | cout << text_t2ascii
|
---|
[1097] | 371 | << "Receptionist is running in \"collection specific\" mode.\n"
|
---|
[1089] | 372 | << " collection=" << configinfo.collection << "\n"
|
---|
| 373 | << " collection directory=" << configinfo.collectdir << "\n";
|
---|
| 374 | colspec = true;
|
---|
[144] | 375 | }
|
---|
[1089] | 376 |
|
---|
[16310] | 377 | cout << text_t2ascii << " gsdlhome=" << configinfo.gsdlhome << "\n";
|
---|
| 378 | if (!configinfo.collecthome.empty())
|
---|
| 379 | cout << text_t2ascii << " collecthome=" << configinfo.collecthome << "\n";
|
---|
[15589] | 380 | if (!configinfo.dbhome.empty())
|
---|
[16310] | 381 | cout << text_t2ascii << " dbhome=" << configinfo.dbhome << "\n";
|
---|
| 382 | cout << text_t2ascii << " httpprefix=" << configinfo.httpprefix << "\n";
|
---|
[19109] | 383 | cout << text_t2ascii << " httpweb=" << configinfo.httpweb << "\n";
|
---|
[16310] | 384 | cout << text_t2ascii << " gwcgi=" << configinfo.gwcgi << "\n\n"
|
---|
[1089] | 385 | << " Note that unless gwcgi has been set from a configuration\n"
|
---|
[1097] | 386 | << " file it is dependent on environment variables set by your\n"
|
---|
| 387 | << " webserver. Therefore it may not have the same value when run\n"
|
---|
[1089] | 388 | << " from the command line as it would be when run from your\n"
|
---|
| 389 | << " web server.\n";
|
---|
| 390 | if (configinfo.usecookies)
|
---|
| 391 | cout << "cookies are enabled\n";
|
---|
| 392 | else
|
---|
| 393 | cout << "cookies are disabled\n";
|
---|
| 394 | if (configinfo.logcgiargs)
|
---|
| 395 | cout << "logging is enabled\n";
|
---|
| 396 | else
|
---|
| 397 | cout << "logging is disabled\n";
|
---|
| 398 | cout << "------------------------------------------------------------\n\n";
|
---|
[144] | 399 |
|
---|
[1089] | 400 | text_tset::const_iterator this_mfile = configinfo.macrofiles.begin();
|
---|
| 401 | text_tset::const_iterator end_mfile = configinfo.macrofiles.end();
|
---|
| 402 | cout << "Macro Files:\n"
|
---|
| 403 | << "------------\n";
|
---|
| 404 | text_t mfile;
|
---|
| 405 | bool found;
|
---|
| 406 | while (this_mfile != end_mfile) {
|
---|
| 407 | cout << text_t2ascii << *this_mfile;
|
---|
| 408 | int spaces = (22 - (*this_mfile).size());
|
---|
| 409 | if (spaces < 2) spaces = 2;
|
---|
| 410 | text_t outspaces;
|
---|
[9620] | 411 | for (int i = 0; i < spaces; ++i) outspaces.push_back (' ');
|
---|
[1089] | 412 | cout << text_t2ascii << outspaces;
|
---|
| 413 |
|
---|
| 414 | found = false;
|
---|
| 415 | if (colspec) {
|
---|
| 416 | // collection specific - try collectdir/macros first
|
---|
| 417 | mfile = filename_cat (configinfo.collectdir, "macros", *this_mfile);
|
---|
| 418 | if (file_exists (mfile)) {
|
---|
| 419 | cout << text_t2ascii << "found (" << mfile << ")\n";
|
---|
| 420 | found = true;
|
---|
| 421 | }
|
---|
[155] | 422 | }
|
---|
[1089] | 423 |
|
---|
| 424 | if (!found) {
|
---|
| 425 | // try main macro directory
|
---|
| 426 | mfile = filename_cat (configinfo.gsdlhome, "macros", *this_mfile);
|
---|
| 427 | if (file_exists (mfile)) {
|
---|
| 428 | cout << text_t2ascii << "found (" << mfile << ")\n";
|
---|
| 429 | found = true;
|
---|
| 430 | }
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 | if (!found)
|
---|
| 434 | cout << text_t2ascii << "NOT FOUND\n";
|
---|
| 435 |
|
---|
[9620] | 436 | ++this_mfile;
|
---|
[144] | 437 | }
|
---|
[1089] | 438 |
|
---|
| 439 | cout << "------------------------------------------------------------\n\n"
|
---|
| 440 | << "Collections:\n"
|
---|
| 441 | << "------------\n"
|
---|
[1097] | 442 | << " Note that collections will only appear as \"running\" if\n"
|
---|
[1089] | 443 | << " their build.cfg files exist, are readable, contain a valid\n"
|
---|
| 444 | << " builddate field (i.e. > 0), and are in the collection's\n"
|
---|
| 445 | << " index directory (i.e. NOT the building directory)\n\n";
|
---|
| 446 |
|
---|
| 447 | recptprotolistclass *protos = recpt.get_recptprotolist_ptr();
|
---|
| 448 | recptprotolistclass::iterator rprotolist_here = protos->begin();
|
---|
| 449 | recptprotolistclass::iterator rprotolist_end = protos->end();
|
---|
[1347] | 450 |
|
---|
| 451 | bool is_z3950 = false;
|
---|
[1276] | 452 | bool found_valid_col = false;
|
---|
[1347] | 453 |
|
---|
[2113] | 454 |
|
---|
[1089] | 455 | while (rprotolist_here != rprotolist_end) {
|
---|
[2113] | 456 | comerror_t err;
|
---|
[1347] | 457 | if ((*rprotolist_here).p == NULL) continue;
|
---|
| 458 | else if (is_z3950==false &&
|
---|
[2113] | 459 | (*rprotolist_here).p->get_protocol_name(err) == "z3950proto") {
|
---|
[1347] | 460 | cout << "\nZ39.50 Servers: (always public)\n"
|
---|
| 461 | << "---------------\n";
|
---|
| 462 | is_z3950=true;
|
---|
| 463 | }
|
---|
[1089] | 464 |
|
---|
[1347] | 465 | text_tarray collist;
|
---|
| 466 | (*rprotolist_here).p->get_collection_list (collist, err, cerr);
|
---|
| 467 | if (err == noError) {
|
---|
| 468 | text_tarray::iterator collist_here = collist.begin();
|
---|
| 469 | text_tarray::iterator collist_end = collist.end();
|
---|
| 470 |
|
---|
| 471 | while (collist_here != collist_end) {
|
---|
| 472 |
|
---|
| 473 | cout << text_t2ascii << *collist_here;
|
---|
| 474 |
|
---|
| 475 | int spaces = (22 - (*collist_here).size());
|
---|
| 476 | if (spaces < 2) spaces = 2;
|
---|
| 477 | text_t outspaces;
|
---|
[9620] | 478 | for (int i = 0; i < spaces; ++i) outspaces.push_back (' ');
|
---|
[1347] | 479 | cout << text_t2ascii << outspaces;
|
---|
| 480 |
|
---|
[1270] | 481 | ColInfoResponse_t *cinfo = recpt.get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, cerr);
|
---|
| 482 | if (cinfo != NULL) {
|
---|
| 483 | if (cinfo->isPublic) cout << "public ";
|
---|
[1089] | 484 | else cout << "private";
|
---|
| 485 |
|
---|
[1276] | 486 | if (cinfo->buildDate > 0) {
|
---|
| 487 | cout << " running ";
|
---|
| 488 | found_valid_col = true;
|
---|
| 489 | } else {
|
---|
| 490 | cout << " not running";
|
---|
| 491 | }
|
---|
[1089] | 492 | }
|
---|
| 493 |
|
---|
| 494 | cout << "\n";
|
---|
| 495 |
|
---|
[9620] | 496 | ++collist_here;
|
---|
[1089] | 497 | }
|
---|
| 498 | }
|
---|
[1347] | 499 | is_z3950=false;
|
---|
[9620] | 500 | ++rprotolist_here;
|
---|
[1347] | 501 | } // end of while loop
|
---|
[1354] | 502 |
|
---|
[1276] | 503 | if (!found_valid_col) {
|
---|
| 504 | cout << "WARNING: No \"running\" collections were found. You need to\n";
|
---|
| 505 | cout << " build one of the above collections\n";
|
---|
| 506 | }
|
---|
| 507 |
|
---|
| 508 | cout << "\n------------------------------------------------------------\n";
|
---|
[1089] | 509 | cout << "------------------------------------------------------------\n\n";
|
---|
| 510 | cout << "receptionist running in command line debug mode\n";
|
---|
| 511 | cout << "enter cgi arguments as name=value pairs (e.g. 'a=p&p=home'):\n";
|
---|
| 512 |
|
---|
| 513 | }
|
---|
| 514 |
|
---|
[22142] | 515 |
|
---|
| 516 |
|
---|
| 517 |
|
---|
[25560] | 518 | void add_all_actions(receptionist& recpt, userdbclass* udb, keydbclass* kdb, isPersistentEnum isPersistentVal)
|
---|
[22142] | 519 | {
|
---|
| 520 | // the list of actions.
|
---|
| 521 |
|
---|
| 522 | #ifdef GSDL_USE_TIP_ACTION
|
---|
| 523 | tipaction* atipaction = new tipaction();
|
---|
| 524 | recpt.add_action (atipaction);
|
---|
| 525 | #endif
|
---|
| 526 |
|
---|
| 527 | #ifdef GSDL_USE_STATUS_ACTION
|
---|
| 528 | statusaction *astatusaction = new statusaction();
|
---|
| 529 | astatusaction->set_receptionist (&recpt);
|
---|
| 530 | recpt.add_action (astatusaction);
|
---|
| 531 | #endif
|
---|
| 532 |
|
---|
| 533 | pageaction *apageaction = new pageaction();
|
---|
| 534 | apageaction->set_receptionist (&recpt);
|
---|
| 535 | recpt.add_action (apageaction);
|
---|
| 536 |
|
---|
| 537 | #ifdef GSDL_USE_PING_ACTION
|
---|
| 538 | recpt.add_action (new pingaction());
|
---|
| 539 | #endif
|
---|
| 540 |
|
---|
[25560] | 541 | ispersistentaction *aIsPersistentAction = new ispersistentaction(isPersistentVal);
|
---|
| 542 | recpt.add_action (aIsPersistentAction);
|
---|
| 543 |
|
---|
[24958] | 544 | #if defined(USE_RSS)
|
---|
| 545 | rssaction *arssaction = new rssaction();
|
---|
| 546 | recpt.add_action (arssaction);
|
---|
| 547 | #endif
|
---|
| 548 |
|
---|
[22142] | 549 | queryaction *aqueryaction = new queryaction();
|
---|
[27172] | 550 | aqueryaction->set_userdb(udb);
|
---|
[22142] | 551 | aqueryaction->set_receptionist (&recpt);
|
---|
| 552 | recpt.add_action (aqueryaction);
|
---|
| 553 |
|
---|
| 554 | #if defined(USE_SQLITE)
|
---|
| 555 | sqlqueryaction *asqlqueryaction = new sqlqueryaction();
|
---|
| 556 | asqlqueryaction->set_receptionist (&recpt);
|
---|
| 557 | recpt.add_action (asqlqueryaction);
|
---|
| 558 | #endif
|
---|
| 559 |
|
---|
| 560 | documentaction *adocumentaction = new documentaction();
|
---|
| 561 | adocumentaction->set_receptionist (&recpt);
|
---|
| 562 | recpt.add_action (adocumentaction);
|
---|
| 563 |
|
---|
| 564 | #ifdef GSDL_USE_USERS_ACTION
|
---|
| 565 | usersaction *ausersaction = new usersaction();
|
---|
| 566 | ausersaction->set_userdb(udb);
|
---|
| 567 | recpt.add_action (ausersaction);
|
---|
| 568 | #endif
|
---|
| 569 |
|
---|
| 570 | #ifdef GSDL_USE_EXTLINK_ACTION
|
---|
| 571 | extlinkaction *aextlinkaction = new extlinkaction();
|
---|
| 572 | aextlinkaction->set_receptionist(&recpt);
|
---|
| 573 | recpt.add_action (aextlinkaction);
|
---|
| 574 | #endif
|
---|
| 575 |
|
---|
| 576 | #ifdef GSDL_USE_AUTHEN_ACTION
|
---|
| 577 | authenaction *aauthenaction = new authenaction();
|
---|
| 578 | aauthenaction->set_userdb(udb);
|
---|
| 579 | aauthenaction->set_keydb(kdb);
|
---|
| 580 | aauthenaction->set_receptionist(&recpt);
|
---|
| 581 | recpt.add_action (aauthenaction);
|
---|
| 582 | #endif
|
---|
| 583 |
|
---|
| 584 | #ifdef GSDL_USE_COLLECTOR_ACTION
|
---|
| 585 | collectoraction *acollectoraction = new collectoraction();
|
---|
| 586 | acollectoraction->set_receptionist (&recpt);
|
---|
| 587 | recpt.add_action(acollectoraction);
|
---|
| 588 | #endif
|
---|
| 589 |
|
---|
| 590 | #ifdef GSDL_USE_DEPOSITOR_ACTION
|
---|
| 591 | depositoraction *adepositoraction = new depositoraction();
|
---|
| 592 | adepositoraction->set_receptionist (&recpt);
|
---|
| 593 | recpt.add_action(adepositoraction);
|
---|
| 594 | #endif
|
---|
| 595 |
|
---|
| 596 | #ifdef GSDL_USE_BROWSE_ACTION
|
---|
| 597 | browseaction *abrowseaction = new browseaction();
|
---|
| 598 | abrowseaction->set_receptionist (&recpt);
|
---|
| 599 | recpt.add_action(abrowseaction);
|
---|
| 600 | #endif
|
---|
| 601 |
|
---|
| 602 | #ifdef GSDL_USE_PHIND_ACTION
|
---|
| 603 | // Phind uses MPPP,do we also need to check if ENABLE_MGPP is set??
|
---|
| 604 | phindaction *aphindaction = new phindaction();
|
---|
| 605 | recpt.add_action(aphindaction);
|
---|
| 606 | #endif
|
---|
| 607 |
|
---|
| 608 | #ifdef GSDL_USE_GTI_ACTION
|
---|
| 609 | gtiaction *agtiaction = new gtiaction();
|
---|
| 610 | agtiaction->set_receptionist(&recpt);
|
---|
| 611 | recpt.add_action(agtiaction);
|
---|
| 612 | #endif
|
---|
| 613 |
|
---|
| 614 | dynamicclassifieraction *adynamicclassifieraction = new dynamicclassifieraction();
|
---|
| 615 | adynamicclassifieraction->set_receptionist(&recpt);
|
---|
| 616 | recpt.add_action(adynamicclassifieraction);
|
---|
| 617 |
|
---|
| 618 | #if defined(USE_MYSQL) || defined(USE_ACCESS)
|
---|
| 619 | orderaction *aorderaction = new orderaction();
|
---|
| 620 | aorderaction->set_receptionist(&recpt);
|
---|
| 621 | recpt.add_action(aorderaction);
|
---|
| 622 | #endif
|
---|
| 623 |
|
---|
| 624 | // action that allows collections to be added, released etc. when server
|
---|
| 625 | // is persistent (e.g. fastcgi or when Greenstone is configured as an
|
---|
| 626 | // Apache module). Presumably this includes Windows server.exe as well
|
---|
| 627 |
|
---|
| 628 | // Want to always include it in list of actions even if compiling
|
---|
| 629 | // Greenstone to be used in a non-persistent way (e.g. library.cgi).
|
---|
| 630 | // This is so the e-variable that is formed is consistent between the
|
---|
| 631 | // persisent executable and the non-persistent executable
|
---|
| 632 | //
|
---|
| 633 |
|
---|
| 634 | configaction *aconfigaction = new configaction();
|
---|
| 635 | aconfigaction->set_receptionist(&recpt);
|
---|
| 636 | recpt.add_action(aconfigaction);
|
---|
| 637 | }
|
---|
| 638 |
|
---|
| 639 |
|
---|
| 640 |
|
---|
| 641 | void add_all_browsers(receptionist& recpt)
|
---|
| 642 | {
|
---|
| 643 | // list of browsers
|
---|
| 644 | vlistbrowserclass *avlistbrowserclass = new vlistbrowserclass();
|
---|
| 645 | avlistbrowserclass->set_receptionist(&recpt);
|
---|
| 646 | recpt.add_browser (avlistbrowserclass);
|
---|
| 647 | recpt.setdefaultbrowser ("VList");
|
---|
| 648 |
|
---|
| 649 | hlistbrowserclass *ahlistbrowserclass = new hlistbrowserclass();
|
---|
| 650 | ahlistbrowserclass->set_receptionist(&recpt);
|
---|
| 651 | recpt.add_browser (ahlistbrowserclass);
|
---|
| 652 |
|
---|
| 653 | #ifdef GSDL_USE_DATELIST_BROWSER
|
---|
| 654 | datelistbrowserclass *adatelistbrowserclass = new datelistbrowserclass();
|
---|
| 655 | recpt.add_browser (adatelistbrowserclass);
|
---|
| 656 | #endif
|
---|
| 657 |
|
---|
| 658 | invbrowserclass *ainvbrowserclass = new invbrowserclass();
|
---|
| 659 | recpt.add_browser (ainvbrowserclass);
|
---|
| 660 |
|
---|
| 661 | #ifdef GSDL_USE_PAGED_BROWSER
|
---|
| 662 | pagedbrowserclass *apagedbrowserclass = new pagedbrowserclass();
|
---|
| 663 | recpt.add_browser (apagedbrowserclass);
|
---|
| 664 | #endif
|
---|
| 665 |
|
---|
| 666 | #ifdef GSDL_USE_HTML_BROWSER
|
---|
| 667 | htmlbrowserclass *ahtmlbrowserclass = new htmlbrowserclass();
|
---|
| 668 | recpt.add_browser (ahtmlbrowserclass);
|
---|
| 669 | #endif
|
---|
| 670 |
|
---|
| 671 | #ifdef GSDL_USE_PHIND_BROWSER
|
---|
| 672 | phindbrowserclass *aphindbrowserclass = new phindbrowserclass();;
|
---|
| 673 | recpt.add_browser (aphindbrowserclass);
|
---|
| 674 | #endif
|
---|
| 675 | }
|
---|
| 676 |
|
---|
| 677 |
|
---|
[1089] | 678 | // cgiwrapper does everything necessary to output a page
|
---|
| 679 | // using the cgi protocol. If this is being run for a particular
|
---|
| 680 | // collection then "collection" should be set, otherwise it
|
---|
| 681 | // should equal "".
|
---|
| 682 | void cgiwrapper (receptionist &recpt, text_t collection) {
|
---|
| 683 | int numrequests = 0;
|
---|
| 684 | bool debug = false;
|
---|
[1864] | 685 | const recptconf &configinfo = recpt.get_configinfo ();
|
---|
[1089] | 686 |
|
---|
[144] | 687 | // find out whether this is being run as a cgi-script
|
---|
| 688 | // or a fastcgi script
|
---|
| 689 | #ifdef USE_FASTCGI
|
---|
[1089] | 690 | fcgistreambuf outbuf;
|
---|
[144] | 691 | int isfastcgi = !FCGX_IsCGI();
|
---|
| 692 | FCGX_Stream *fcgiin, *fcgiout, *fcgierr;
|
---|
| 693 | FCGX_ParamArray fcgienvp;
|
---|
| 694 | #else
|
---|
| 695 | int isfastcgi = 0;
|
---|
| 696 | #endif
|
---|
| 697 |
|
---|
[12514] | 698 | // we need gsdlhome to do fileupload stuff, so moved this configure stuff before the get argstr stuff
|
---|
[1089] | 699 | // init stuff - we can't output error pages directly with
|
---|
| 700 | // fastcgi so the pages are stored until we can output them
|
---|
| 701 | text_t errorpage;
|
---|
| 702 | outconvertclass text_t2ascii;
|
---|
| 703 |
|
---|
| 704 | // set defaults
|
---|
| 705 | int maxrequests = 10000;
|
---|
| 706 | recpt.configure ("collection", collection);
|
---|
| 707 | char *script_name = getenv("SCRIPT_NAME");
|
---|
| 708 | if (script_name != NULL) recpt.configure("gwcgi", script_name);
|
---|
[2344] | 709 | else recpt.configure("gwcgi", "/gsdl");
|
---|
[1089] | 710 |
|
---|
| 711 | // read in the configuration files.
|
---|
| 712 | text_t gsdlhome;
|
---|
[16310] | 713 | text_t collecthome;
|
---|
[15402] | 714 | configurator gsdlconfigurator(&recpt);
|
---|
[16310] | 715 | if (!site_cfg_read (gsdlconfigurator, gsdlhome, collecthome, maxrequests)) {
|
---|
[1089] | 716 | // couldn't find the site configuration file
|
---|
| 717 | page_errorsitecfg (errorpage, debug, 0);
|
---|
| 718 | } else if (gsdlhome.empty()) {
|
---|
| 719 | // no gsdlhome in gsdlsite.cfg
|
---|
| 720 | page_errorsitecfg (errorpage, debug, 1);
|
---|
[2344] | 721 | } else if (!directory_exists(gsdlhome)) {
|
---|
| 722 | // gsdlhome not a valid directory
|
---|
| 723 | page_errorsitecfg (errorpage, debug, 1);
|
---|
[16310] | 724 | } else if (!main_cfg_read (recpt, gsdlhome, collecthome, collection)) {
|
---|
[1089] | 725 | // couldn't find the main configuration file
|
---|
| 726 | page_errormaincfg (gsdlhome, collection, debug, errorpage);
|
---|
[2344] | 727 | } else if (configinfo.collectinfo.empty() && false) { // commented out for corba
|
---|
[1089] | 728 | // don't have any collections
|
---|
| 729 | page_errorcollect (gsdlhome, errorpage, debug);
|
---|
[144] | 730 | }
|
---|
[19109] | 731 |
|
---|
| 732 | // set up the httpweb variable if it hasn't been defined yet
|
---|
| 733 | if (configinfo.httpweb.empty()) {
|
---|
| 734 | recpt.configure("httpweb", configinfo.httpprefix+"/web");
|
---|
| 735 | }
|
---|
| 736 |
|
---|
[12514] | 737 | // get the query string if it is not being run as a fastcgi
|
---|
| 738 | // script
|
---|
| 739 | text_t argstr = g_EmptyText;
|
---|
| 740 | fileupload_tmap fileuploads;
|
---|
| 741 | cgiargsclass args;
|
---|
| 742 | char *aURIStr;
|
---|
| 743 | if (!isfastcgi) {
|
---|
| 744 | char *request_method_str = getenv("REQUEST_METHOD");
|
---|
| 745 | char *content_length_str = getenv("CONTENT_LENGTH");
|
---|
| 746 | if (request_method_str != NULL && strcmp(request_method_str, "POST") == 0 &&
|
---|
| 747 | content_length_str != NULL) {
|
---|
| 748 | // POST form data
|
---|
| 749 | long content_length = (content_length_str ? atoi(content_length_str) : 0);
|
---|
| 750 | if (content_length > 0) {
|
---|
[12794] | 751 | #ifdef __WIN32__
|
---|
| 752 | // On Windows it is important that standard input be read in binary
|
---|
| 753 | // mode, otherwise end of line "<CR><LF>" is turned into <LF> only
|
---|
| 754 | // which breaks the MIME standard (and our parsing code!)
|
---|
| 755 |
|
---|
| 756 | int result = _setmode( _fileno( stdin ), _O_BINARY );
|
---|
| 757 | if( result == -1 ) {
|
---|
| 758 | cerr << "Warning: Failed to set standard input to binary mode." << endl;
|
---|
| 759 | cerr << " Parsing of multi-part MIME will most likely fail" << endl;
|
---|
| 760 | }
|
---|
| 761 | #endif
|
---|
| 762 |
|
---|
[12514] | 763 | long length = content_length;
|
---|
| 764 | unsigned char * buffer = new unsigned char[content_length];
|
---|
[12794] | 765 |
|
---|
| 766 | int chars_read = fread(buffer,1,content_length,stdin);
|
---|
| 767 |
|
---|
| 768 | if (chars_read != content_length) {
|
---|
| 769 | cerr << "Warning: mismatch between CONTENT_LENGTH and data read from standard in" << endl;
|
---|
| 770 | }
|
---|
| 771 |
|
---|
[12514] | 772 | argstr.setcarr((char *)buffer, content_length);
|
---|
[12794] | 773 |
|
---|
[12514] | 774 | text_t content_type;
|
---|
| 775 | char *content_type_str = getenv("CONTENT_TYPE");
|
---|
| 776 | if (content_type_str) content_type = content_type_str;
|
---|
| 777 | argstr = parse_post_data(content_type, argstr, fileuploads, gsdlhome);
|
---|
| 778 | }
|
---|
| 779 | } else {
|
---|
| 780 | aURIStr = getenv("QUERY_STRING");
|
---|
| 781 | if ((request_method_str != NULL && strcmp(request_method_str, "GET") == 0)
|
---|
| 782 | || aURIStr != NULL) {
|
---|
| 783 | // GET form data
|
---|
| 784 | if (aURIStr != NULL) argstr = aURIStr;
|
---|
[30373] | 785 | //kjdon a get form is not unicode
|
---|
| 786 | argstr.setencoding(1);
|
---|
[12514] | 787 | } else {
|
---|
| 788 | // debugging from command line
|
---|
| 789 | debug = true;
|
---|
| 790 | }
|
---|
| 791 | }
|
---|
| 792 | }
|
---|
[144] | 793 |
|
---|
[12514] | 794 | if (debug) {
|
---|
| 795 | cout << "Configuring Greenstone...\n";
|
---|
| 796 | cout << flush;
|
---|
| 797 | }
|
---|
| 798 |
|
---|
| 799 |
|
---|
[1089] | 800 | if (errorpage.empty()) {
|
---|
| 801 |
|
---|
| 802 | // initialise the library software
|
---|
[1097] | 803 | if (debug) {
|
---|
| 804 | cout << "Initializing...\n";
|
---|
| 805 | cout << flush;
|
---|
| 806 | }
|
---|
[1089] | 807 |
|
---|
[2939] | 808 | text_t error_file = filename_cat (gsdlhome, "etc", "error.txt");
|
---|
| 809 | char *eout = error_file.getcstr();
|
---|
| 810 | ofstream errout (eout, ios::app);
|
---|
[7438] | 811 | delete []eout;
|
---|
[2939] | 812 | if (!recpt.init(errout)) {
|
---|
[1089] | 813 | // an error occurred during the initialisation
|
---|
[2939] | 814 | errout.close();
|
---|
[1089] | 815 | page_errorinit(gsdlhome, debug, errorpage);
|
---|
| 816 | }
|
---|
[2939] | 817 | errout.close();
|
---|
[1089] | 818 | }
|
---|
| 819 |
|
---|
| 820 | if (debug && errorpage.empty()) {
|
---|
| 821 | // get query string from command line
|
---|
| 822 | print_debug_info (recpt);
|
---|
| 823 | char cinURIStr[1024];
|
---|
| 824 | cin.get(cinURIStr, 1024);
|
---|
| 825 | argstr = cinURIStr;
|
---|
| 826 | }
|
---|
| 827 |
|
---|
| 828 | // cgi scripts only deal with one request
|
---|
| 829 | if (!isfastcgi) maxrequests = 1;
|
---|
| 830 |
|
---|
[144] | 831 | // Page-request loop. If this is not being run as a fastcgi
|
---|
| 832 | // process then only one request will be processed and then
|
---|
| 833 | // the process will exit.
|
---|
| 834 | while (numrequests < maxrequests) {
|
---|
| 835 | #ifdef USE_FASTCGI
|
---|
| 836 | if (isfastcgi) {
|
---|
| 837 | if (FCGX_Accept(&fcgiin, &fcgiout, &fcgierr, &fcgienvp) < 0) break;
|
---|
[1248] | 838 |
|
---|
| 839 | char *request_method_str = FCGX_GetParam ("REQUEST_METHOD", fcgienvp);
|
---|
| 840 | char *content_length_str = FCGX_GetParam ("CONTENT_LENGTH", fcgienvp);
|
---|
| 841 |
|
---|
| 842 | if (request_method_str != NULL && strcmp(request_method_str, "POST") == 0 &&
|
---|
| 843 | content_length_str != NULL) {
|
---|
| 844 | // POST form data
|
---|
| 845 | int content_length = text_t(content_length_str).getint();
|
---|
| 846 | if (content_length > 0) {
|
---|
| 847 | argstr.clear();
|
---|
| 848 | int c;
|
---|
| 849 | do {
|
---|
| 850 | c = FCGX_GetChar (fcgiin);
|
---|
| 851 | if (c < 0) break;
|
---|
| 852 | argstr.push_back (c);
|
---|
[9620] | 853 | --content_length;
|
---|
[1248] | 854 | } while (content_length > 0);
|
---|
| 855 | }
|
---|
| 856 |
|
---|
| 857 | } else {
|
---|
| 858 | // GET form data
|
---|
| 859 | aURIStr = FCGX_GetParam("QUERY_STRING", fcgienvp);
|
---|
| 860 | if (aURIStr != NULL) argstr = aURIStr;
|
---|
[7438] | 861 | else argstr = g_EmptyText;
|
---|
[1248] | 862 | }
|
---|
[144] | 863 | }
|
---|
| 864 | #endif
|
---|
| 865 |
|
---|
| 866 | // get output streams ready
|
---|
| 867 | #ifdef USE_FASTCGI
|
---|
| 868 | outbuf.fcgisbreset ();
|
---|
| 869 | if (isfastcgi) outbuf.set_fcgx_stream (fcgiout);
|
---|
| 870 | else outbuf.set_other_ostream (&cout);
|
---|
| 871 | ostream pageout (&outbuf);
|
---|
| 872 | #else
|
---|
| 873 | #define pageout cout
|
---|
| 874 | #endif
|
---|
[155] | 875 |
|
---|
[872] | 876 | // if using fastcgi we'll load environment into a map,
|
---|
| 877 | // otherwise simply pass empty map (can't get environment
|
---|
| 878 | // variables using getenv() while using FCGX versions
|
---|
| 879 | // of fastcgi - at least I can't ;-) - Stefan)
|
---|
| 880 | text_tmap fastcgienv;
|
---|
| 881 | #ifdef USE_FASTCGI
|
---|
| 882 | if (isfastcgi) {
|
---|
[9620] | 883 | for(; *fcgienvp != NULL; ++fcgienvp) {
|
---|
[872] | 884 | text_t fvalue = *fcgienvp;
|
---|
| 885 | text_t::const_iterator begin = fvalue.begin();
|
---|
| 886 | text_t::const_iterator end = fvalue.end();
|
---|
| 887 | text_t::const_iterator equals_sign = findchar (begin, end, '=');
|
---|
| 888 | if (equals_sign != end)
|
---|
| 889 | fastcgienv[substr(begin, equals_sign)] = substr(equals_sign+1, end);
|
---|
| 890 | }
|
---|
| 891 | }
|
---|
| 892 | #endif
|
---|
| 893 |
|
---|
| 894 | // temporarily need to configure gwcgi here when using fastcgi as I can't
|
---|
| 895 | // get it to pass the SCRIPT_NAME environment variable to the initial
|
---|
| 896 | // environment (if anyone can work out how to do this using the apache
|
---|
| 897 | // server, let me know). Note that this overrides the gwcgi field in
|
---|
| 898 | // site.cfg (which it shouldn't do) but I can't at present set gwcgi
|
---|
| 899 | // from site.cfg as I have old receptionists laying around that wouldn't
|
---|
| 900 | // appreciate it. The following 5 lines of code should be deleted once
|
---|
| 901 | // I either a: get the server to pass SCRIPT_NAME at initialization
|
---|
| 902 | // time or b: convert all the collections using old receptionists over
|
---|
| 903 | // to this version and uncomment gwcgi in the site.cfg file -- Stefan.
|
---|
| 904 | #ifdef USE_FASTCGI
|
---|
| 905 | if (isfastcgi) {
|
---|
| 906 | recpt.configure("gwcgi", fastcgienv["SCRIPT_NAME"]);
|
---|
| 907 | }
|
---|
| 908 | #endif
|
---|
| 909 |
|
---|
| 910 |
|
---|
[1860] | 911 | // if there has been no error so far, perform the production of the
|
---|
| 912 | // output page
|
---|
[155] | 913 | if (errorpage.empty()) {
|
---|
[2939] | 914 | text_t error_file = filename_cat (gsdlhome, "etc", "error.txt");
|
---|
[963] | 915 | char *eout = error_file.getcstr();
|
---|
[1255] | 916 | ofstream errout (eout, ios::app);
|
---|
[7438] | 917 | delete []eout;
|
---|
[3006] | 918 |
|
---|
[3026] | 919 | #if defined(__WIN32__) && defined(GSDL_USE_IOS_H)
|
---|
| 920 | // old Windows compilers (VC++4.2)
|
---|
| 921 | cerr = errout;
|
---|
| 922 | #else
|
---|
[3006] | 923 | // can't do this anymore according to c++ standard...
|
---|
[3381] | 924 | // cerr = errout;
|
---|
[3006] | 925 | // ... but can do this instead
|
---|
[3396] | 926 | streambuf* errbuf = cerr.rdbuf(errout.rdbuf());
|
---|
[3026] | 927 | #endif
|
---|
[3006] | 928 |
|
---|
[155] | 929 | // parse the cgi arguments and produce the resulting page if there
|
---|
| 930 | // has been no errors so far
|
---|
[12514] | 931 | if (!recpt.parse_cgi_args (argstr, fileuploads, args, errout, fastcgienv)) {
|
---|
[155] | 932 | errout.close ();
|
---|
[1089] | 933 | page_errorparseargs(gsdlhome, debug, errorpage);
|
---|
[155] | 934 | } else {
|
---|
[1860] | 935 | // produce the output page
|
---|
| 936 |
|
---|
[872] | 937 | if (!recpt.produce_cgi_page (args, pageout, errout, fastcgienv)) {
|
---|
[155] | 938 | errout.close ();
|
---|
[1089] | 939 | page_errorcgipage(gsdlhome, debug, errorpage);
|
---|
[155] | 940 | }
|
---|
[872] | 941 | recpt.log_cgi_args (args, errout, fastcgienv);
|
---|
[1089] | 942 | errout.close ();
|
---|
[155] | 943 | }
|
---|
[3381] | 944 |
|
---|
| 945 | #if !defined(__WIN32__) || !defined(GSDL_USE_IOS_H)
|
---|
| 946 | // restore the cerr buffer
|
---|
| 947 | cerr.rdbuf(errbuf);
|
---|
| 948 | #endif
|
---|
[155] | 949 | }
|
---|
[12514] | 950 | // clean up any files that were uploaded
|
---|
| 951 | fileupload_tmap::const_iterator this_file = fileuploads.begin();
|
---|
| 952 | fileupload_tmap::const_iterator end_file = fileuploads.end();
|
---|
| 953 | while (this_file != end_file)
|
---|
| 954 | {
|
---|
| 955 | if (file_exists((*this_file).second.tmp_name))
|
---|
| 956 | {
|
---|
| 957 | char *thefile = (*this_file).second.tmp_name.getcstr();
|
---|
| 958 | unlink(thefile);
|
---|
| 959 | delete [] thefile;
|
---|
| 960 | }
|
---|
| 961 | ++this_file;
|
---|
| 962 | }
|
---|
| 963 |
|
---|
[155] | 964 | // there was an error, output the error page
|
---|
| 965 | if (!errorpage.empty()) {
|
---|
| 966 | pageout << text_t2ascii << errorpage;
|
---|
| 967 | errorpage.clear();
|
---|
| 968 | numrequests = maxrequests; // make this the last page
|
---|
| 969 | }
|
---|
| 970 | pageout << flush;
|
---|
[144] | 971 |
|
---|
| 972 | // finish with the output streams
|
---|
| 973 | #ifdef USE_FASTCGI
|
---|
| 974 | if (isfastcgi) FCGX_Finish();
|
---|
| 975 | #endif
|
---|
| 976 |
|
---|
[9620] | 977 | ++numrequests;
|
---|
[144] | 978 | }
|
---|
| 979 |
|
---|
| 980 | return;
|
---|
| 981 | }
|
---|