source: branches/z3950-branch/gsdl/src/recpt/cgiwrapper.cpp@ 1168

Last change on this file since 1168 was 1168, checked in by johnmcp, 24 years ago

added proper config file parsing for z39.50 servers, and minor changes
to pageaction (minor bug when display collections from >1 proto) and
cgiwrapper (announces which collections are z39.50 servers).

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