source: trunk/gsdl/src/recpt/cgiwrapper.cpp@ 12525

Last change on this file since 12525 was 12514, checked in by kjdon, 18 years ago

Added Stefan's fileupload code to replace use of cgicc by depositor.

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