/********************************************************************** * * cgiwrapper.cpp -- output pages using the cgi protocol * Copyright (C) 1999 The New Zealand Digital Library Project * * PUT COPYRIGHT NOTICE HERE * * $Id: cgiwrapper.cpp 248 1999-04-30 01:59:44Z sjboddie $ * *********************************************************************/ /* $Log$ Revision 1.12 1999/04/30 01:59:40 sjboddie lots of stuff - getting documentaction working (documentaction replaces old browseaction) Revision 1.11 1999/03/25 03:12:01 sjboddie subjectbrowseaction was replaced with browseaction Revision 1.10 1999/03/05 03:53:54 sjboddie fixed some bugs Revision 1.9 1999/03/04 22:38:21 sjboddie Added subjectbrowseaction. - Doesn't do anything yet. Revision 1.8 1999/02/28 20:00:13 rjmcnab Fixed a few things. Revision 1.7 1999/02/21 22:33:53 rjmcnab Lots of stuff :-) Revision 1.6 1999/02/12 02:40:17 sjboddie Added page action Revision 1.5 1999/02/11 01:24:04 rjmcnab Fixed a few compiler warnings. Revision 1.4 1999/02/08 01:28:01 rjmcnab Got the receptionist producing something using the statusaction. Revision 1.3 1999/02/05 10:42:44 rjmcnab Continued working on receptionist Revision 1.2 1999/02/04 10:00:56 rjmcnab Developed the idea of an "action" and having them define the cgi arguments which they need and how those cgi arguments function. Revision 1.1 1999/02/04 01:16:17 rjmcnab Initial revision. Revision 1.5 1999/01/19 01:38:18 rjmcnab Made the source more portable. Revision 1.4 1999/01/12 01:51:04 rjmcnab Standard header. */ #include "gsdlconf.h" #include "cgiwrapper.h" #include "recptconfig.h" #include "action.h" #include "statusaction.h" #include "pageaction.h" #include "pingaction.h" #include "queryaction.h" #include "documentaction.h" #include #if defined(GSDL_USE_OBJECTSPACE) # include # include #elif defined(GSDL_USE_IOS_H) # include # include #else # include # include #endif #ifdef USE_FASTCGI #include "fcgiapp.h" #endif // Note: site.h would not be needed if we could // dynamically find out gsdlhome. #include "site.h" #ifdef USE_FASTCGI // used to output the text from receptionist class fcgistreambuf : public streambuf { public: fcgistreambuf (); int sync (); int overflow (int ch); int underflow () {return EOF;} void fcgisbreset() {fcgx_stream = NULL; other_ostream = NULL;}; void set_fcgx_stream(FCGX_Stream *newone) {fcgx_stream=newone;}; void set_other_ostream(ostream *newone) {other_ostream=newone;}; private: FCGX_Stream *fcgx_stream; ostream *other_ostream; }; fcgistreambuf::fcgistreambuf() { fcgisbreset(); if (base() == ebuf()) allocate(); setp (base(), ebuf()); }; int fcgistreambuf::sync () { if ((fcgx_stream != NULL) && (FCGX_PutStr (pbase(), out_waiting(), fcgx_stream) < 0)) { fcgx_stream = NULL; } if (other_ostream != NULL) { char *thepbase=pbase(); for (int i=0;i> cinURIStr; argstr = cinURIStr; } maxrequests = 1; } // Page-request loop. If this is not being run as a fastcgi // process then only one request will be processed and then // the process will exit. while (numrequests < maxrequests) { #ifdef USE_FASTCGI if (isfastcgi) { if (FCGX_Accept(&fcgiin, &fcgiout, &fcgierr, &fcgienvp) < 0) break; aURIStr = FCGX_GetParam("QUERY_STRING", fcgienvp); if (aURIStr != NULL) argstr = aURIStr; else argstr = ""; } #endif // get output streams ready #ifdef USE_FASTCGI outbuf.fcgisbreset (); if (isfastcgi) outbuf.set_fcgx_stream (fcgiout); else outbuf.set_other_ostream (&cout); ostream pageout (&outbuf); #else #define pageout cout #endif if (errorpage.empty()) { ofstream errout (GSDL_GSDLHOME "/etc/errout.txt"); cerr = errout; // parse the cgi arguments and produce the resulting page if there // has been no errors so far if (!recpt.parse_cgi_args (argstr, args, errout)) { errout.close (); page_errorparseargs(GSDL_GSDLHOME, errorpage); } else { if (!recpt.produce_cgi_page (args, pageout, errout)) { errout.close (); page_errorcgipage(GSDL_GSDLHOME, errorpage); } else { errout.close (); } } } // there was an error, output the error page if (!errorpage.empty()) { pageout << text_t2ascii << errorpage; errorpage.clear(); numrequests = maxrequests; // make this the last page } pageout << flush; // finish with the output streams #ifdef USE_FASTCGI if (isfastcgi) FCGX_Finish(); #endif numrequests++; } return; }