source: gsdl/trunk/runtime-src/src/recpt/cgiwrapper.cpp@ 19109

Last change on this file since 19109 was 19109, checked in by kjdon, 15 years ago

httpimg changed to httpweb, and default is now httpprefix/web. not /images or /gsdl/images

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 23.7 KB
Line 
1/**********************************************************************
2 *
3 * cgiwrapper.cpp -- output pages using the cgi protocol
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
26#include <stdio.h>
27#include <cstring>
28#ifdef __WIN32__
29#include <fcntl.h>
30#endif
31
32#include "gsdlconf.h"
33#include "cgiwrapper.h"
34#include "gsdlsitecfg.h"
35#include "maincfg.h"
36#include "fileutil.h"
37#include "cgiutils.h"
38#include <stdlib.h>
39#include <assert.h>
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
56
57#ifdef USE_FASTCGI
58// used to output the text from receptionist
59class fcgistreambuf : public streambuf {
60public:
61 fcgistreambuf ();
62 int sync ();
63 int overflow (int ch);
64 int underflow () {return EOF;}
65
66 void fcgisbreset() {fcgx_stream = NULL; other_ostream = NULL;};
67 void set_fcgx_stream(FCGX_Stream *newone) {fcgx_stream=newone;};
68 void set_other_ostream(ostream *newone) {other_ostream=newone;};
69
70private:
71 FCGX_Stream *fcgx_stream;
72 ostream *other_ostream;
73};
74
75fcgistreambuf::fcgistreambuf() {
76 fcgisbreset();
77 if (base() == ebuf()) allocate();
78 setp (base(), ebuf());
79};
80
81int fcgistreambuf::sync () {
82 if ((fcgx_stream != NULL) &&
83 (FCGX_PutStr (pbase(), out_waiting(), fcgx_stream) < 0)) {
84 fcgx_stream = NULL;
85 }
86
87 if (other_ostream != NULL) {
88 char *thepbase=pbase();
89 for (int i=0;i<out_waiting();++i) (*other_ostream).put(thepbase[i]);
90 }
91
92 setp (pbase(), epptr());
93
94 return 0;
95}
96
97int fcgistreambuf::overflow (int ch) {
98 if (sync () == EOF) return EOF;
99 if (ch != EOF) sputc (ch);
100 return 0;
101}
102
103#endif
104
105static void format_error_string (text_t &errorpage, const text_t &errortext, bool debug) {
106
107 errorpage.clear();
108
109 if (debug) {
110 errorpage += "\n";
111 errorpage += "ERROR: " + errortext;
112 errorpage += "\n";
113
114 } else {
115
116 errorpage += "Content-type: text/html\n\n";
117
118 errorpage += "<html>\n";
119 errorpage += "<head>\n";
120 errorpage += "<title>Error</title>\n";
121 errorpage += "</head>\n";
122 errorpage += "<body>\n";
123 errorpage += "<h2>Oops!</h2>\n";
124 errorpage += errortext;
125 errorpage += "</body>\n";
126 errorpage += "</html>\n";
127 }
128}
129
130static void page_errorcollect (const text_t &gsdlhome, text_t &errorpage, bool debug) {
131
132 text_t collecthome = filename_cat (gsdlhome, "collect");
133
134 text_t errortext = "No valid collections were found: Check that your collect directory\n";
135 errortext += "(" + collecthome + ") is readable and contains at least one valid collection.\n";
136 errortext += "Note that modelcol is NOT a valid collection.\n";
137 errortext += "If the path to your collect directory is wrong edit the 'gsdlhome' field\n";
138 errortext += "in your gsdlsite.cfg configuration file.\n";
139
140 format_error_string (errorpage, errortext, debug);
141}
142
143static void page_errorsitecfg (text_t &errorpage, bool debug, int mode) {
144
145 text_t errortext;
146
147 if (mode == 0) {
148 errortext += "The gsdlsite.cfg configuration file could not be found. This\n";
149 errortext += "file should contain configuration information relating to this\n";
150 errortext += "site's setup.\n";
151
152 } else if (mode == 1) {
153 errortext += "The gsdlsite.cfg configuration file does not contain a valid\n";
154 errortext += "gsdlhome entry.\n";
155 }
156
157 if (debug) {
158 errortext += "gsdlsite.cfg should reside in the directory from which the\n";
159 errortext += "library executable was run.\n";
160 } else {
161 errortext += "gsdlsite.cfg should reside in the same directory as the library\n";
162 errortext += "executable file.\n";
163 }
164
165 format_error_string (errorpage, errortext, debug);
166}
167
168
169static void page_errormaincfg (const text_t &gsdlhome, const text_t &collection,
170 bool debug, text_t &errorpage) {
171
172 text_t errortext;
173
174 if (collection.empty()) {
175 text_t main_cfg_file = filename_cat (gsdlhome, "etc", "main.cfg");
176 errortext += "The main.cfg configuration file could not be found. This file\n";
177 errortext += "should contain configuration information relating to the\n";
178 errortext += "setup of the interface. As this receptionist is not being run\n";
179 errortext += "in collection specific mode the file should reside at\n";
180 errortext += main_cfg_file + ".\n";
181 } else {
182 text_t collect_cfg_file = filename_cat (gsdlhome, "collect", collection, "etc", "collect.cfg");
183 text_t main_collect_cfg_file = filename_cat (gsdlhome, "etc", "collect.cfg");
184 text_t main_cfg_file = filename_cat (gsdlhome, "etc", "main.cfg");
185 errortext += "Either the collect.cfg or main.cfg configuration file could\n";
186 errortext += "not be found. This file should contain configuration information\n";
187 errortext += "relating to the setup of the interface. As this receptionist is\n";
188 errortext += "being run in collection specific mode the file should reside\n";
189 errortext += "at either " + collect_cfg_file + ",\n";
190 errortext += main_collect_cfg_file + " or " + main_cfg_file + ".\n";
191 }
192
193 format_error_string (errorpage, errortext, debug);
194}
195
196
197static void page_errorinit (const text_t &gsdlhome, bool debug, text_t &errorpage) {
198
199 text_t errortext = "An error occurred during the initialisation of the Greenstone Digital\n";
200 errortext += "Library software. It is likely that the software has not been setup\n";
201 errortext += "correctly.\n";
202
203 text_t error_file = filename_cat (gsdlhome, "etc", "error.txt");
204 char *efile = error_file.getcstr();
205 ifstream errin (efile);
206 delete []efile;
207 if (errin) {
208 errortext += "The error log, " + error_file + ", contains the\n";
209 errortext += "following information:\n\n";
210 if (!debug) errortext += "<pre>\n";
211
212 char c;
213 errin.get(c);
214 while (!errin.eof ()) {
215 errortext.push_back(c);
216 errin.get(c);
217 }
218
219 if (!debug) errortext += "</pre>\n";
220
221 errin.close();
222
223 } else {
224 errortext += "Please consult " + error_file + " for more information.\n";
225 }
226
227 format_error_string (errorpage, errortext, debug);
228}
229
230static void page_errorparseargs (const text_t &gsdlhome, bool debug, text_t &errorpage) {
231
232 text_t errortext = "An error occurred during the parsing of the cgi arguments.\n";
233
234 text_t error_file = filename_cat (gsdlhome, "etc", "error.txt");
235 char *efile = error_file.getcstr();
236 ifstream errin (efile);
237 delete []efile;
238 if (errin) {
239 errortext += "The error log, " + error_file + ", contains the\n";
240 errortext += "following information:\n\n";
241 if (!debug) errortext += "<pre>\n";
242
243 char c;
244 errin.get(c);
245 while (!errin.eof ()) {
246 errortext.push_back(c);
247 errin.get(c);
248 }
249 if (!debug) errortext += "</pre>\n";
250 errin.close();
251
252 } else {
253 errortext += "Please consult " + error_file + " for more information.\n";
254 }
255
256 format_error_string (errorpage, errortext, debug);
257}
258
259static void page_errorcgipage (const text_t &gsdlhome, bool debug, text_t &errorpage) {
260
261 text_t errortext = "An error occurred during the construction of the cgi page.\n";
262
263 text_t error_file = filename_cat (gsdlhome, "etc", "error.txt");
264 char *efile = error_file.getcstr();
265 ifstream errin (efile);
266 delete []efile;
267 if (errin) {
268 errortext += "The error log, " + error_file + ", contains the\n";
269 errortext += "following information:\n\n";
270 if (!debug) errortext += "<pre>\n";
271
272 char c;
273 errin.get(c);
274 while (!errin.eof ()) {
275 errortext.push_back(c);
276 errin.get(c);
277 }
278 if (!debug) errortext += "</pre>\n";
279 errin.close();
280
281 } else {
282 errortext += "Please consult " + error_file + " for more information.\n";
283 }
284
285 format_error_string (errorpage, errortext, debug);
286}
287
288static void print_debug_info (receptionist &recpt) {
289
290 outconvertclass text_t2ascii;
291 const recptconf &configinfo = recpt.get_configinfo ();
292 text_t etc_dir = filename_cat (configinfo.gsdlhome, "etc");
293
294 cout << "\n";
295 cout << text_t2ascii
296 << "------------------------------------------------------------\n"
297 << "Configuration and initialization completed successfully.\n"
298 << " Note that more debug information may be available in the\n"
299 << " initialization and error log error.txt in " << etc_dir << ".\n"
300 << "------------------------------------------------------------\n\n";
301
302 bool colspec = false;
303 if (configinfo.collection.empty()) {
304 cout << "Receptionist is running in \"general\" (i.e. not \"collection "
305 << "specific\") mode.\n";
306 } else {
307 cout << text_t2ascii
308 << "Receptionist is running in \"collection specific\" mode.\n"
309 << " collection=" << configinfo.collection << "\n"
310 << " collection directory=" << configinfo.collectdir << "\n";
311 colspec = true;
312 }
313
314 cout << text_t2ascii << " gsdlhome=" << configinfo.gsdlhome << "\n";
315 if (!configinfo.collecthome.empty())
316 cout << text_t2ascii << " collecthome=" << configinfo.collecthome << "\n";
317 if (!configinfo.dbhome.empty())
318 cout << text_t2ascii << " dbhome=" << configinfo.dbhome << "\n";
319 cout << text_t2ascii << " httpprefix=" << configinfo.httpprefix << "\n";
320 cout << text_t2ascii << " httpweb=" << configinfo.httpweb << "\n";
321 cout << text_t2ascii << " gwcgi=" << configinfo.gwcgi << "\n\n"
322 << " Note that unless gwcgi has been set from a configuration\n"
323 << " file it is dependent on environment variables set by your\n"
324 << " webserver. Therefore it may not have the same value when run\n"
325 << " from the command line as it would be when run from your\n"
326 << " web server.\n";
327 if (configinfo.usecookies)
328 cout << "cookies are enabled\n";
329 else
330 cout << "cookies are disabled\n";
331 if (configinfo.logcgiargs)
332 cout << "logging is enabled\n";
333 else
334 cout << "logging is disabled\n";
335 cout << "------------------------------------------------------------\n\n";
336
337 text_tset::const_iterator this_mfile = configinfo.macrofiles.begin();
338 text_tset::const_iterator end_mfile = configinfo.macrofiles.end();
339 cout << "Macro Files:\n"
340 << "------------\n";
341 text_t mfile;
342 bool found;
343 while (this_mfile != end_mfile) {
344 cout << text_t2ascii << *this_mfile;
345 int spaces = (22 - (*this_mfile).size());
346 if (spaces < 2) spaces = 2;
347 text_t outspaces;
348 for (int i = 0; i < spaces; ++i) outspaces.push_back (' ');
349 cout << text_t2ascii << outspaces;
350
351 found = false;
352 if (colspec) {
353 // collection specific - try collectdir/macros first
354 mfile = filename_cat (configinfo.collectdir, "macros", *this_mfile);
355 if (file_exists (mfile)) {
356 cout << text_t2ascii << "found (" << mfile << ")\n";
357 found = true;
358 }
359 }
360
361 if (!found) {
362 // try main macro directory
363 mfile = filename_cat (configinfo.gsdlhome, "macros", *this_mfile);
364 if (file_exists (mfile)) {
365 cout << text_t2ascii << "found (" << mfile << ")\n";
366 found = true;
367 }
368 }
369
370 if (!found)
371 cout << text_t2ascii << "NOT FOUND\n";
372
373 ++this_mfile;
374 }
375
376 cout << "------------------------------------------------------------\n\n"
377 << "Collections:\n"
378 << "------------\n"
379 << " Note that collections will only appear as \"running\" if\n"
380 << " their build.cfg files exist, are readable, contain a valid\n"
381 << " builddate field (i.e. > 0), and are in the collection's\n"
382 << " index directory (i.e. NOT the building directory)\n\n";
383
384 recptprotolistclass *protos = recpt.get_recptprotolist_ptr();
385 recptprotolistclass::iterator rprotolist_here = protos->begin();
386 recptprotolistclass::iterator rprotolist_end = protos->end();
387
388 bool is_z3950 = false;
389 bool found_valid_col = false;
390
391
392 while (rprotolist_here != rprotolist_end) {
393 comerror_t err;
394 if ((*rprotolist_here).p == NULL) continue;
395 else if (is_z3950==false &&
396 (*rprotolist_here).p->get_protocol_name(err) == "z3950proto") {
397 cout << "\nZ39.50 Servers: (always public)\n"
398 << "---------------\n";
399 is_z3950=true;
400 }
401
402 text_tarray collist;
403 (*rprotolist_here).p->get_collection_list (collist, err, cerr);
404 if (err == noError) {
405 text_tarray::iterator collist_here = collist.begin();
406 text_tarray::iterator collist_end = collist.end();
407
408 while (collist_here != collist_end) {
409
410 cout << text_t2ascii << *collist_here;
411
412 int spaces = (22 - (*collist_here).size());
413 if (spaces < 2) spaces = 2;
414 text_t outspaces;
415 for (int i = 0; i < spaces; ++i) outspaces.push_back (' ');
416 cout << text_t2ascii << outspaces;
417
418 ColInfoResponse_t *cinfo = recpt.get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, cerr);
419 if (cinfo != NULL) {
420 if (cinfo->isPublic) cout << "public ";
421 else cout << "private";
422
423 if (cinfo->buildDate > 0) {
424 cout << " running ";
425 found_valid_col = true;
426 } else {
427 cout << " not running";
428 }
429 }
430
431 cout << "\n";
432
433 ++collist_here;
434 }
435 }
436 is_z3950=false;
437 ++rprotolist_here;
438 } // end of while loop
439
440 if (!found_valid_col) {
441 cout << "WARNING: No \"running\" collections were found. You need to\n";
442 cout << " build one of the above collections\n";
443 }
444
445 cout << "\n------------------------------------------------------------\n";
446 cout << "------------------------------------------------------------\n\n";
447 cout << "receptionist running in command line debug mode\n";
448 cout << "enter cgi arguments as name=value pairs (e.g. 'a=p&p=home'):\n";
449
450}
451
452// cgiwrapper does everything necessary to output a page
453// using the cgi protocol. If this is being run for a particular
454// collection then "collection" should be set, otherwise it
455// should equal "".
456void cgiwrapper (receptionist &recpt, text_t collection) {
457 int numrequests = 0;
458 bool debug = false;
459 const recptconf &configinfo = recpt.get_configinfo ();
460
461 // find out whether this is being run as a cgi-script
462 // or a fastcgi script
463#ifdef USE_FASTCGI
464 fcgistreambuf outbuf;
465 int isfastcgi = !FCGX_IsCGI();
466 FCGX_Stream *fcgiin, *fcgiout, *fcgierr;
467 FCGX_ParamArray fcgienvp;
468#else
469 int isfastcgi = 0;
470#endif
471
472 // we need gsdlhome to do fileupload stuff, so moved this configure stuff before the get argstr stuff
473 // init stuff - we can't output error pages directly with
474 // fastcgi so the pages are stored until we can output them
475 text_t errorpage;
476 outconvertclass text_t2ascii;
477
478 // set defaults
479 int maxrequests = 10000;
480 recpt.configure ("collection", collection);
481 char *script_name = getenv("SCRIPT_NAME");
482 if (script_name != NULL) recpt.configure("gwcgi", script_name);
483 else recpt.configure("gwcgi", "/gsdl");
484
485 // read in the configuration files.
486 text_t gsdlhome;
487 text_t collecthome;
488 configurator gsdlconfigurator(&recpt);
489 if (!site_cfg_read (gsdlconfigurator, gsdlhome, collecthome, maxrequests)) {
490 // couldn't find the site configuration file
491 page_errorsitecfg (errorpage, debug, 0);
492 } else if (gsdlhome.empty()) {
493 // no gsdlhome in gsdlsite.cfg
494 page_errorsitecfg (errorpage, debug, 1);
495 } else if (!directory_exists(gsdlhome)) {
496 // gsdlhome not a valid directory
497 page_errorsitecfg (errorpage, debug, 1);
498 } else if (!main_cfg_read (recpt, gsdlhome, collecthome, collection)) {
499 // couldn't find the main configuration file
500 page_errormaincfg (gsdlhome, collection, debug, errorpage);
501 } else if (configinfo.collectinfo.empty() && false) { // commented out for corba
502 // don't have any collections
503 page_errorcollect (gsdlhome, errorpage, debug);
504 }
505
506 // set up the httpweb variable if it hasn't been defined yet
507 if (configinfo.httpweb.empty()) {
508 recpt.configure("httpweb", configinfo.httpprefix+"/web");
509 }
510
511 // get the query string if it is not being run as a fastcgi
512 // script
513 text_t argstr = g_EmptyText;
514 fileupload_tmap fileuploads;
515 cgiargsclass args;
516 char *aURIStr;
517 if (!isfastcgi) {
518 char *request_method_str = getenv("REQUEST_METHOD");
519 char *content_length_str = getenv("CONTENT_LENGTH");
520 if (request_method_str != NULL && strcmp(request_method_str, "POST") == 0 &&
521 content_length_str != NULL) {
522 // POST form data
523 long content_length = (content_length_str ? atoi(content_length_str) : 0);
524 if (content_length > 0) {
525#ifdef __WIN32__
526 // On Windows it is important that standard input be read in binary
527 // mode, otherwise end of line "<CR><LF>" is turned into <LF> only
528 // which breaks the MIME standard (and our parsing code!)
529
530 int result = _setmode( _fileno( stdin ), _O_BINARY );
531 if( result == -1 ) {
532 cerr << "Warning: Failed to set standard input to binary mode." << endl;
533 cerr << " Parsing of multi-part MIME will most likely fail" << endl;
534 }
535#endif
536
537 long length = content_length;
538 unsigned char * buffer = new unsigned char[content_length];
539
540 int chars_read = fread(buffer,1,content_length,stdin);
541
542 if (chars_read != content_length) {
543 cerr << "Warning: mismatch between CONTENT_LENGTH and data read from standard in" << endl;
544 }
545
546 argstr.setcarr((char *)buffer, content_length);
547
548 text_t content_type;
549 char *content_type_str = getenv("CONTENT_TYPE");
550 if (content_type_str) content_type = content_type_str;
551 argstr = parse_post_data(content_type, argstr, fileuploads, gsdlhome);
552 }
553 } else {
554 aURIStr = getenv("QUERY_STRING");
555 if ((request_method_str != NULL && strcmp(request_method_str, "GET") == 0)
556 || aURIStr != NULL) {
557 // GET form data
558 if (aURIStr != NULL) argstr = aURIStr;
559 } else {
560 // debugging from command line
561 debug = true;
562 }
563 }
564 }
565
566 if (debug) {
567 cout << "Configuring Greenstone...\n";
568 cout << flush;
569 }
570
571
572 if (errorpage.empty()) {
573
574 // initialise the library software
575 if (debug) {
576 cout << "Initializing...\n";
577 cout << flush;
578 }
579
580 text_t error_file = filename_cat (gsdlhome, "etc", "error.txt");
581 char *eout = error_file.getcstr();
582 ofstream errout (eout, ios::app);
583 delete []eout;
584 if (!recpt.init(errout)) {
585 // an error occurred during the initialisation
586 errout.close();
587 page_errorinit(gsdlhome, debug, errorpage);
588 }
589 errout.close();
590 }
591
592 if (debug && errorpage.empty()) {
593 // get query string from command line
594 print_debug_info (recpt);
595 char cinURIStr[1024];
596 cin.get(cinURIStr, 1024);
597 argstr = cinURIStr;
598 }
599
600 // cgi scripts only deal with one request
601 if (!isfastcgi) maxrequests = 1;
602
603 // Page-request loop. If this is not being run as a fastcgi
604 // process then only one request will be processed and then
605 // the process will exit.
606 while (numrequests < maxrequests) {
607#ifdef USE_FASTCGI
608 if (isfastcgi) {
609 if (FCGX_Accept(&fcgiin, &fcgiout, &fcgierr, &fcgienvp) < 0) break;
610
611 char *request_method_str = FCGX_GetParam ("REQUEST_METHOD", fcgienvp);
612 char *content_length_str = FCGX_GetParam ("CONTENT_LENGTH", fcgienvp);
613
614 if (request_method_str != NULL && strcmp(request_method_str, "POST") == 0 &&
615 content_length_str != NULL) {
616 // POST form data
617 int content_length = text_t(content_length_str).getint();
618 if (content_length > 0) {
619 argstr.clear();
620 int c;
621 do {
622 c = FCGX_GetChar (fcgiin);
623 if (c < 0) break;
624 argstr.push_back (c);
625 --content_length;
626 } while (content_length > 0);
627 }
628
629 } else {
630 // GET form data
631 aURIStr = FCGX_GetParam("QUERY_STRING", fcgienvp);
632 if (aURIStr != NULL) argstr = aURIStr;
633 else argstr = g_EmptyText;
634 }
635 }
636#endif
637
638 // get output streams ready
639#ifdef USE_FASTCGI
640 outbuf.fcgisbreset ();
641 if (isfastcgi) outbuf.set_fcgx_stream (fcgiout);
642 else outbuf.set_other_ostream (&cout);
643 ostream pageout (&outbuf);
644#else
645#define pageout cout
646#endif
647
648 // if using fastcgi we'll load environment into a map,
649 // otherwise simply pass empty map (can't get environment
650 // variables using getenv() while using FCGX versions
651 // of fastcgi - at least I can't ;-) - Stefan)
652 text_tmap fastcgienv;
653#ifdef USE_FASTCGI
654 if (isfastcgi) {
655 for(; *fcgienvp != NULL; ++fcgienvp) {
656 text_t fvalue = *fcgienvp;
657 text_t::const_iterator begin = fvalue.begin();
658 text_t::const_iterator end = fvalue.end();
659 text_t::const_iterator equals_sign = findchar (begin, end, '=');
660 if (equals_sign != end)
661 fastcgienv[substr(begin, equals_sign)] = substr(equals_sign+1, end);
662 }
663 }
664#endif
665
666 // temporarily need to configure gwcgi here when using fastcgi as I can't
667 // get it to pass the SCRIPT_NAME environment variable to the initial
668 // environment (if anyone can work out how to do this using the apache
669 // server, let me know). Note that this overrides the gwcgi field in
670 // site.cfg (which it shouldn't do) but I can't at present set gwcgi
671 // from site.cfg as I have old receptionists laying around that wouldn't
672 // appreciate it. The following 5 lines of code should be deleted once
673 // I either a: get the server to pass SCRIPT_NAME at initialization
674 // time or b: convert all the collections using old receptionists over
675 // to this version and uncomment gwcgi in the site.cfg file -- Stefan.
676#ifdef USE_FASTCGI
677 if (isfastcgi) {
678 recpt.configure("gwcgi", fastcgienv["SCRIPT_NAME"]);
679 }
680#endif
681
682
683 // if there has been no error so far, perform the production of the
684 // output page
685 if (errorpage.empty()) {
686 text_t error_file = filename_cat (gsdlhome, "etc", "error.txt");
687 char *eout = error_file.getcstr();
688 ofstream errout (eout, ios::app);
689 delete []eout;
690
691#if defined(__WIN32__) && defined(GSDL_USE_IOS_H)
692 // old Windows compilers (VC++4.2)
693 cerr = errout;
694#else
695 // can't do this anymore according to c++ standard...
696 // cerr = errout;
697 // ... but can do this instead
698 streambuf* errbuf = cerr.rdbuf(errout.rdbuf());
699#endif
700
701 // parse the cgi arguments and produce the resulting page if there
702 // has been no errors so far
703 if (!recpt.parse_cgi_args (argstr, fileuploads, args, errout, fastcgienv)) {
704 errout.close ();
705 page_errorparseargs(gsdlhome, debug, errorpage);
706 } else {
707 // produce the output page
708
709 if (!recpt.produce_cgi_page (args, pageout, errout, fastcgienv)) {
710 errout.close ();
711 page_errorcgipage(gsdlhome, debug, errorpage);
712 }
713 recpt.log_cgi_args (args, errout, fastcgienv);
714 errout.close ();
715 }
716
717#if !defined(__WIN32__) || !defined(GSDL_USE_IOS_H)
718 // restore the cerr buffer
719 cerr.rdbuf(errbuf);
720#endif
721 }
722 // clean up any files that were uploaded
723 fileupload_tmap::const_iterator this_file = fileuploads.begin();
724 fileupload_tmap::const_iterator end_file = fileuploads.end();
725 while (this_file != end_file)
726 {
727 if (file_exists((*this_file).second.tmp_name))
728 {
729 char *thefile = (*this_file).second.tmp_name.getcstr();
730 unlink(thefile);
731 delete [] thefile;
732 }
733 ++this_file;
734 }
735
736 // there was an error, output the error page
737 if (!errorpage.empty()) {
738 pageout << text_t2ascii << errorpage;
739 errorpage.clear();
740 numrequests = maxrequests; // make this the last page
741 }
742 pageout << flush;
743
744 // finish with the output streams
745#ifdef USE_FASTCGI
746 if (isfastcgi) FCGX_Finish();
747#endif
748
749 ++numrequests;
750 }
751
752 return;
753}
Note: See TracBrowser for help on using the repository browser.